Skip to content

Commit

Permalink
Merge branch 'main' into env/testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
alanrsoares committed Nov 29, 2023
2 parents 2ac543b + dc2c919 commit ed5b9df
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 109 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-rocks-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@axelarjs/api": patch
---

feat: migrate recent transactions event mapping for interchain transfers and token deployments
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { CONTRACT_METHODS, type ContractMethod } from "./types";

export const CONTRACT_METHODS_LABELS: Partial<Record<ContractMethod, string>> =
{
sendToken: "Send Token",
StandardizedTokenDeployed: "Token Deployed",
InterchainTransfer: "Interchain Transfer",
InterchainTokenDeploymentStarted: "Token Deployment",
};

type Props = {
Expand All @@ -18,7 +18,7 @@ type Props = {

const RecentTransactionsTabs: FC<Props> = ({ maxTransactions = 10 }) => {
const [contractMethod, setContractMethod] =
useState<ContractMethod>("sendToken");
useState<ContractMethod>("InterchainTransfer");

const { address } = useAccount();

Expand All @@ -44,13 +44,13 @@ const RecentTransactionsTabs: FC<Props> = ({ maxTransactions = 10 }) => {
</Card.Title>
<div className="hidden w-[90vw] min-w-max max-w-4xl grid-cols-2 gap-4 md:grid">
<RecentTransactionsList
contractMethod="sendToken"
contractMethod="InterchainTransfer"
senderAddress={address}
title="Transfers"
maxTransactions={maxTransactions}
/>
<RecentTransactionsList
contractMethod="StandardizedTokenDeployed"
contractMethod="InterchainTokenDeploymentStarted"
senderAddress={address}
title="Token Deployments"
maxTransactions={maxTransactions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const TransactionItem: FC<{
<div className="avatar placeholder">
<div className="bg-neutral-focus text-neutral-content w-12 rounded-full">
<span className="text-xl">
{contractMethod === "sendToken" ? "ST" : "TD"}
{contractMethod === "InterchainTransfer" ? "IT" : "TD"}
</span>
</div>
</div>
Expand All @@ -131,9 +131,15 @@ const TransactionItem: FC<{
className="hover:text-primary hover:cursor-pointer"
href={`/interchain-tokens/${tx.event.tokenId}`}
>
{tx.event.name}{" "}
{tx.event.event === "InterchainTransfer"
? tx.event.name
: tx.event.tokenName}{" "}
<span className="text-neutral opacity-50 dark:text-white">
({tx.event.symbol})
(
{tx.event.event === "InterchainTransfer"
? tx.event.symbol
: tx.event.tokenSymbol}
)
</span>
</Link>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,24 @@ const TransactionRow: FC<{
return (
<Table.Row>
<Table.Cell className="from-base-300 via-base-300/70 to-base-300/25 sticky left-0 bg-gradient-to-r md:bg-none">
{tx.event?.name}{" "}
<span className="opacity-75">({tx.event?.symbol})</span>
{tx.event?.event === "InterchainTransfer"
? tx.event?.name
: tx.event?.tokenName}{" "}
<span className="opacity-75">
(
{tx.event?.event === "InterchainTransfer"
? tx.event?.symbol
: tx.event?.tokenSymbol}
)
</span>
</Table.Cell>
<Table.Cell>
<Link
href={`/recent-transactions/${tx.hash}`}
className="group flex items-center gap-2"
>
<>
{maskAddress(tx.hash as `0x${string}`)}
{maskAddress(tx.hash)}
<ExternalLinkIcon
size="16"
className="text-accent opacity-0 transition-opacity group-hover:opacity-100"
Expand All @@ -183,9 +191,7 @@ const TransactionRow: FC<{
</Link>
</Table.Cell>
<Table.Cell>
<Link href={`/block/${tx.blockHash}`}>
{maskAddress(tx.blockHash as `0x${string}`)}
</Link>
<Link href={`/block/${tx.blockHash}`}>{maskAddress(tx.blockHash)}</Link>
</Table.Cell>
<Table.Cell>{new Date(tx.timestamp * 1000).toLocaleString()}</Table.Cell>
</Table.Row>
Expand Down
4 changes: 2 additions & 2 deletions apps/maestro/src/features/RecentTransactions/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const CONTRACT_METHODS = [
"sendToken",
"StandardizedTokenDeployed",
"InterchainTransfer",
"InterchainTokenDeploymentStarted",
] as const;

export type ContractMethod = (typeof CONTRACT_METHODS)[number];
2 changes: 1 addition & 1 deletion apps/maestro/src/pages/recent-transactions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Page from "~/ui/layouts/Page";

const RecentTransactionsPage = () => {
const [contractMethod, setContractMethod] =
useState<ContractMethod>("sendToken");
useState<ContractMethod>("InterchainTransfer");

const { address } = useAccount();

Expand Down
70 changes: 18 additions & 52 deletions apps/maestro/src/server/routers/gmp/getRecentTransactions.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,39 @@
import { type ContractMethod, type SearchGMPResponseData } from "@axelarjs/api";
import type { ContractMethod, SearchGMPResponseData } from "@axelarjs/api";

import { TRPCError } from "@trpc/server";
import { z } from "zod";

import { NEXT_PUBLIC_INTERCHAIN_TOKEN_SERVICE_ADDRESS } from "~/config/env";
import { hex40Literal, hex64Literal } from "~/lib/utils/validation";
import { hex40Literal } from "~/lib/utils/validation";
import { publicProcedure } from "~/server/trpc";

const INPUT_SCHEMA = z.object({
pageSize: z.number().optional().default(20),
page: z.number().optional().default(0),
senderAddress: hex40Literal().optional(),
contractMethod: z.union([
z.literal("sendToken"),
z.literal("StandardizedTokenDeployed"),
z.literal("InterchainTransfer"),
z.literal("InterchainTokenDeploymentStarted"),
]),
});

export type RecentTransactionsInput = z.infer<typeof INPUT_SCHEMA>;

const OUTPUT_SCHEMA = z.array(
z.object({
hash: z.string(),
blockHash: z.string(),
status: z.string(),
timestamp: z.number(),
event: z
.union([
z.object({
event: z.literal("TokenSent"),
symbol: z.string(),
amount: z.string(),
destinationAddress: hex40Literal(),
tokenId: hex64Literal(),
decimals: z.number(),
name: z.string(),
destinationChain: z.string(),
contract_address: hex40Literal(),
}),
z.object({
event: z.literal("StandardizedTokenDeployed"),
mintAmount: z.string(),
symbol: z.string(),
tokenId: hex64Literal(),
mintTo: hex40Literal(),
decimals: z.number(),
name: z.string(),
}),
])
.optional(),
})
);

export type RecentTransactionsOutput = z.infer<typeof OUTPUT_SCHEMA>;
export type RecentTransactionsOutput = {
hash: `0x${string}`;
blockHash: `0x${string}`;
status: string;
timestamp: number;
event?:
| NonNullable<SearchGMPResponseData["interchain_transfer"]>
| NonNullable<SearchGMPResponseData["interchain_token_deployment_started"]>;
}[];

/**
* Get the most recent transactions for the current user
*/
export const getRecentTransactions = publicProcedure
.input(INPUT_SCHEMA)
.output(OUTPUT_SCHEMA)
.meta({
openapi: {
summary: "Get the most recent transactions for the current user",
method: "GET",
path: "/gmp/recent-transactions",
tags: ["gmp"],
},
})
.query(async ({ input, ctx }) => {
try {
const response = await ctx.services.gmp.searchGMP({
Expand All @@ -85,7 +51,7 @@ export const getRecentTransactions = publicProcedure
blockHash: call.blockHash,
timestamp: call.block_timestamp,
event: extractEvent(tx, input.contractMethod),
}));
})) as RecentTransactionsOutput;
} catch (error) {
if (error instanceof TRPCError) {
throw error;
Expand All @@ -103,10 +69,10 @@ function extractEvent(
contractMethod: ContractMethod
) {
switch (contractMethod) {
case "sendToken":
return response.token_sent;
case "StandardizedTokenDeployed":
return response.token_deployed;
case "InterchainTransfer":
return response.interchain_transfer;
case "InterchainTokenDeploymentStarted":
return response.interchain_token_deployment_started;
default:
return undefined;
}
Expand Down
67 changes: 27 additions & 40 deletions packages/api/src/gmp/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ type BaseGMPParams = {
export const VALID_CONTRACT_METHODS = [
"callContract",
"callContractWithToken",
"sendToken",
"StandardizedTokenDeployed",
"RemoteStandardizedTokenAndManagerDeploymentInitialized",
"InterchainTransfer",
"InterchainTokenDeploymentStarted",
] as const;

export type ContractMethod = (typeof VALID_CONTRACT_METHODS)[number];
Expand Down Expand Up @@ -98,40 +97,6 @@ type SearchGMPCall = {
};
};

export type TokenDeployedEvent = {
event: "StandardizedTokenDeployed";
mintAmount: string;
symbol: string;
tokenId: `0x${string}`;
mintTo: `0x${string}`;
decimals: number;
name: string;
};

export type TokenSentEvent = {
event: "TokenSent";
symbol: string;
amount: string;
destinationAddress: `0x${string}`;
tokenId: `0x${string}`;
decimals: number;
name: string;
destinationChain: string;
contract_address: `0x${string}`;
};

export type RemoteStandardizedTokenAndManagerDeploymentInitializedEvent = {
event: "RemoteStandardizedTokenAndManagerDeploymentInitialized";
tokenId: `0x${string}`;
tokenSymbol: string;
gasValue: string;
tokenDecimals: number;
tokenName: string;
destinationChain: string;
distributor: `0x${string}`;
operator: `0x${string}`;
};

type GMPTokenInfo = {
token_price: {
usd: number;
Expand Down Expand Up @@ -220,6 +185,29 @@ export type SearchGMPGasPaid = {
destination_chain_type: string;
};

type InterchainTransferEvent = {
event: "InterchainTransfer";
symbol: string;
amount: string;
destinationAddress: `0x${string}`;
tokenId: `0x${string}`;
decimals: number;
name: string;
destinationChain: string;
contract_address: `0x${string}`;
id: string;
};

type InterchainTokenDeploymentStartedEvent = {
event: "InterchainTokenDeploymentStarted";
tokenId: `0x${string}`;
tokenSymbol: string;
tokenDecimals: number;
tokenName: string;
destinationChain: string;
distributor: `0x${string}`;
};

export type SearchGMPResponseData = {
call: SearchGMPCall;
fees: SearchGMPFees;
Expand All @@ -228,9 +216,8 @@ export type SearchGMPResponseData = {
is_invalid_destination_chain: boolean;
is_call_from_relayer: boolean;
is_invalid_call: boolean;
token_sent?: TokenSentEvent;
token_deployed?: TokenDeployedEvent;
token_deployment_initialized?: RemoteStandardizedTokenAndManagerDeploymentInitializedEvent;
interchain_transfer?: InterchainTransferEvent;
interchain_token_deployment_started?: InterchainTokenDeploymentStartedEvent;
};

export type SearchGMPResponse = BaseGMPResponse<{
Expand Down

0 comments on commit ed5b9df

Please sign in to comment.