Skip to content

Commit

Permalink
chore: upgraded contracts and flow support part 9
Browse files Browse the repository at this point in the history
  • Loading branch information
SGiaccobasso committed Jan 20, 2025
1 parent 3c29149 commit f6ad38e
Show file tree
Hide file tree
Showing 109 changed files with 3,643 additions and 2,718 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { INTERCHAIN_TOKEN_FACTORY_ENCODERS } from "@axelarjs/evm";
import {
INTERCHAIN_TOKEN_FACTORY_ENCODERS,
INTERCHAIN_TOKEN_SERVICE_ENCODERS,
} from "@axelarjs/evm";
import { invariant, throttle } from "@axelarjs/utils";
import { useCallback, useEffect, useMemo, useState } from "react";

Expand All @@ -8,11 +11,11 @@ import { useWaitForTransactionReceipt } from "wagmi";
import { NEXT_PUBLIC_NETWORK_ENV } from "~/config/env";
import useDeployToken from "~/features/suiHooks/useDeployToken";
import {
useReadInterchainTokenFactoryInterchainTokenAddress,
useReadInterchainTokenFactoryInterchainTokenId,
useSimulateInterchainTokenFactoryMulticall,
useWriteInterchainTokenFactoryMulticall,
} from "~/lib/contracts/InterchainTokenFactory.hooks";
import { useReadInterchainTokenServiceInterchainTokenAddress } from "~/lib/contracts/InterchainTokenService.hooks";
import {
decodeDeploymentMessageId,
type DeploymentMessageId,
Expand All @@ -22,8 +25,7 @@ import { trpc } from "~/lib/trpc";
import { isValidEVMAddress } from "~/lib/utils/validation";
import type { EstimateGasFeeMultipleChainsOutput } from "~/server/routers/axelarjsSDK";
import { RecordInterchainTokenDeploymentInput } from "~/server/routers/interchainToken/recordInterchainTokenDeployment";
// import { deployToken } from "~/server/routers/sui/ITSFunctions";
import { useEVMChainConfigsQuery } from "~/services/axelarscan/hooks";
import { useAllChainConfigsQuery } from "~/services/axelarscan/hooks";
import type { DeployAndRegisterTransactionState } from "../InterchainTokenDeployment.state";

export interface UseDeployAndRegisterInterchainTokenInput {
Expand All @@ -50,12 +52,13 @@ export function useDeployAndRegisterRemoteInterchainTokenMutation(
const { address: deployerAddress } = useAccount();
const chainId = useChainId();
const { deployToken } = useDeployToken();
const { computed } = useEVMChainConfigsQuery();
const { combinedComputed } = useAllChainConfigsQuery();

// TODO: remove when axelarscan's api is ready
const updatedComputed = {
...computed,
...combinedComputed,
indexedByChainId: {
...computed.indexedByChainId,
...combinedComputed.indexedByChainId,
...(NEXT_PUBLIC_NETWORK_ENV === "mainnet"
? {
id: "sui",
Expand Down Expand Up @@ -145,7 +148,7 @@ export function useDeployAndRegisterRemoteInterchainTokenMutation(
}),
},
indexedById: {
...computed.indexedById,
...combinedComputed.indexedById,
sui:
NEXT_PUBLIC_NETWORK_ENV === "mainnet"
? {
Expand Down Expand Up @@ -236,7 +239,7 @@ export function useDeployAndRegisterRemoteInterchainTokenMutation(
},
},
wagmiChains: [
...computed.wagmiChains,
...combinedComputed.wagmiChains,
{
id: NEXT_PUBLIC_NETWORK_ENV === "mainnet" ? 101 : 103,
name: NEXT_PUBLIC_NETWORK_ENV === "mainnet" ? "Sui" : "Sui Testnet",
Expand Down Expand Up @@ -300,15 +303,15 @@ export function useDeployAndRegisterRemoteInterchainTokenMutation(
});

const { data: tokenAddress } =
useReadInterchainTokenFactoryInterchainTokenAddress({
args: INTERCHAIN_TOKEN_FACTORY_ENCODERS.interchainTokenAddress.args({
salt: input?.salt as `0x${string}`,
deployer: deployerAddress,
useReadInterchainTokenServiceInterchainTokenAddress({
args: INTERCHAIN_TOKEN_SERVICE_ENCODERS.interchainTokenAddress.args({
tokenId: tokenId as `0x${string}`,
}),
query: {
enabled: Boolean(tokenId && input?.salt && deployerAddress),
enabled: Boolean(tokenId),
},
});

const { destinationChainNames } = useMemo(() => {
const index = updatedComputed.indexedById;
type IndexedChainId = keyof typeof index;
Expand All @@ -326,9 +329,9 @@ export function useDeployAndRegisterRemoteInterchainTokenMutation(
};
}, [
chainId,
updatedComputed.indexedById,
input?.destinationChainIds,
input?.sourceChainId,
updatedComputed.indexedById,
]);

const multicallArgs = useMemo(() => {
Expand Down Expand Up @@ -356,16 +359,14 @@ export function useDeployAndRegisterRemoteInterchainTokenMutation(
return [deployTxData];
}

const registerTxData = destinationChainNames.map((destinationChain, i) => {
const registerData =
INTERCHAIN_TOKEN_FACTORY_ENCODERS.deployRemoteInterchainToken.data({
...commonArgs,
originalChainName: "",
destinationChain,
gasValue: input.remoteDeploymentGasFees?.gasFees?.[i].fee ?? 0n,
});
return registerData;
});
const registerTxData = destinationChainNames.map((destinationChain, i) =>
INTERCHAIN_TOKEN_FACTORY_ENCODERS.deployRemoteInterchainToken.data({
...commonArgs,
originalChainName: "",
destinationChain,
gasValue: input.remoteDeploymentGasFees?.gasFees?.[i].fee ?? 0n,
})
);

return [deployTxData, ...registerTxData];
}, [input, tokenId, destinationChainNames]);
Expand Down Expand Up @@ -413,7 +414,7 @@ export function useDeployAndRegisterRemoteInterchainTokenMutation(
setRecordDeploymentArgs({
kind: "interchain",
deploymentMessageId: `${txHash}-${txIndex}`,
tokenId,
tokenId: tokenId as string,
tokenAddress,
deployerAddress,
salt: input.salt,
Expand Down Expand Up @@ -475,7 +476,7 @@ export function useDeployAndRegisterRemoteInterchainTokenMutation(

return await recordDeploymentAsync({
kind: "interchain",
tokenId,
tokenId: tokenId as string,
deployerAddress,
tokenAddress,
tokenName: input.tokenName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { EVMChainConfig, VMChainConfig } from "@axelarjs/api/axelarscan";
import { Maybe } from "@axelarjs/utils";
import { useEffect, useState } from "react";

Expand All @@ -10,22 +11,28 @@ import {
import { useBalance, useChainId } from "~/lib/hooks";
import { toNumericString } from "~/lib/utils/bigint";
import { useEstimateGasFeeMultipleChainsQuery } from "~/services/axelarjsSDK/hooks";
import { useEVMChainConfigsQuery } from "~/services/axelarscan/hooks";
import { useAllChainConfigsQuery } from "~/services/axelarscan/hooks";
import { useInterchainTokenDeploymentStateContainer } from "../../InterchainTokenDeployment.state";

type ChainConfig = EVMChainConfig | VMChainConfig;

export type UseStep2ChainSelectionStateProps = {
selectedChains: Set<string>;
};

export function useStep2ChainSelectionState() {
const { data: evmChains } = useEVMChainConfigsQuery();
const { allChains } = useAllChainConfigsQuery();
const chainId = useChainId();
const userBalance = useBalance();
const [isDeploying, setIsDeploying] = useState(false);
const [totalGasFee, setTotalGasFee] = useState(formatEther(0n));
const [sourceChainId, setSourceChainId] = useState(
evmChains?.find((evmChain) => evmChain.chain_id === chainId)?.id as string
);

const [sourceChainId, setSourceChainId] = useState<string>(() => {
const chain = allChains?.find(
(chain: ChainConfig) => chain.chain_id === chainId
);
return chain?.id || "";
});

const { state: rootState } = useInterchainTokenDeploymentStateContainer();

Expand Down Expand Up @@ -53,20 +60,20 @@ export function useStep2ChainSelectionState() {
};

useEffect(() => {
const candidateChain = evmChains?.find(
(evmChain) => evmChain.chain_id === chainId
const candidateChain = allChains?.find(
(chain) => chain.chain_id === chainId
);
if (!candidateChain || candidateChain.chain_name === sourceChainId) return;

setSourceChainId(candidateChain.chain_name);
}, [evmChains, chainId, sourceChainId]);
}, [allChains, chainId, sourceChainId]);

return {
state: {
isDeploying,
totalGasFee,
sourceChainId,
evmChains,
chains: allChains,
isEstimatingGasFees: isRemoteDeploymentGasFeeLoading,
hasGasFeesEstimationError: isRemoteDeploymentGasFeeError,
remoteDeploymentGasFees,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export const Step2: FC = () => {

const chainId = useChainId();

const sourceChain = state.evmChains.find((x) => x.chain_id === chainId);
// Handle both EVM and VM chains
const sourceChain = state.chains.find((chain) => chain.chain_id === chainId);

const [validDestinationChainIds, erroredDestinationChainIds] = useMemo(
() =>
Expand Down Expand Up @@ -172,9 +173,8 @@ export const Step2: FC = () => {
]
);

const eligibleChains = useMemo(
() => state.evmChains?.filter((chain) => chain.chain_id !== chainId),
[state.evmChains, chainId]
const eligibleChains = state.chains.filter(
(chain) => chain.chain_id !== chainId
);

const formSubmitRef = useRef<ComponentRef<"button">>(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { NEXT_PUBLIC_NETWORK_ENV, shouldDisableSend } from "~/config/env";
import { useAccount, useChainId, useSwitchChain } from "~/lib/hooks";
import { useInterchainTokenBalanceForOwnerQuery } from "~/services/interchainToken/hooks";
import BigNumberText from "~/ui/components/BigNumberText";
import { ChainIcon } from "~/ui/components/EVMChainsDropdown";
import { ChainIcon } from "~/ui/components/ChainsDropdown";
import { AcceptInterchainTokenOwnership } from "../AcceptInterchainTokenOwnership";
import ManageInterchainToken from "../ManageInterchainToken/ManageInterchainToken";
import { SendInterchainToken } from "../SendInterchainToken";
Expand Down Expand Up @@ -156,7 +156,7 @@ export const RegisteredInterchainTokenCard: FC<Props> = (props) => {
balance={BigInt(balance.tokenBalance)}
isTokenOwner={balance.isTokenOwner}
isTokenPendingOnwer={balance.isTokenPendingOwner}
isTokenMinter={balance.isTokenMinter}
isTokenMinter={balance.isTokenMinter as boolean}
hasPendingOwner={balance.hasPendingOwner}
tokenId={props.tokenId}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Card, cn, Indicator } from "@axelarjs/ui";
import { type FC } from "react";

import { ChainIcon } from "~/ui/components/EVMChainsDropdown";
import { ChainIcon } from "~/ui/components/ChainsDropdown";
import { GMPStatusIndicator } from "~/ui/compounds/GMPTxStatusMonitor";
import type { TokenInfo } from "./types";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { parseUnits, TransactionExecutionError } from "viem";
import { useChainId } from "~/lib/hooks";
import { logger } from "~/lib/logger";
import { preventNonNumericInput } from "~/lib/utils/validation";
import EVMChainsDropdown from "~/ui/components/EVMChainsDropdown";
import ChainsDropdown from "~/ui/components/ChainsDropdown";
import { useMintInterchainTokenState } from "./MintInterchainToken.state";

type FormState = {
Expand Down Expand Up @@ -95,7 +95,7 @@ export const MintInterchainToken: FC = () => {
<>
<Dialog.Title className="flex">
<span>Mint interchain tokens on</span>
<EVMChainsDropdown disabled compact />
<ChainsDropdown disabled compact />
</Dialog.Title>
<form
className="flex flex-1 flex-col justify-between gap-4"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EVMChainConfig } from "@axelarjs/api";
import { EVMChainConfig, VMChainConfig } from "@axelarjs/api";
import { Alert, Button } from "@axelarjs/ui";
import { toast } from "@axelarjs/ui/toaster";
import { useCallback, useEffect, useMemo, type FC } from "react";
Expand All @@ -15,15 +15,15 @@ import {
import { logger } from "~/lib/logger";
import { handleTransactionResult } from "~/lib/transactions/handlers";
import { trpc } from "~/lib/trpc";
import { useEVMChainConfigsQuery } from "~/services/axelarscan/hooks";
import { useAllChainConfigsQuery } from "~/services/axelarscan/hooks";
import useRegisterRemoteCanonicalTokens from "./hooks/useRegisterRemoteCanonicalTokens";
import useRegisterRemoteInterchainTokens from "./hooks/useRegisterRemoteInterchainTokens";

export type RegisterRemoteTokensProps = {
tokenAddress: string;
chainIds: number[];
originChainId?: number;
originChain?: EVMChainConfig;
originChain?: EVMChainConfig | VMChainConfig;
userGasBalance: GetBalanceReturnType | undefined;
gasFees: bigint[] | undefined;
onTxStateChange?: (status: TransactionState) => void;
Expand All @@ -37,15 +37,15 @@ export const RegisterRemoteTokens: FC<RegisterRemoteTokensProps> = (props) => {
const { mutateAsync: recordRemoteTokenDeployment } =
trpc.interchainToken.recordRemoteTokensDeployment.useMutation();

const { computed } = useEVMChainConfigsQuery();
const { combinedComputed } = useAllChainConfigsQuery();

const baseRemoteTokens = props.chainIds.map((chainId) => ({
chainId,
address: props.tokenAddress,
tokenAddress: props.tokenAddress,
deploymentStatus: "pending",
deploymentTxHash: "0x",
axelarChainId: computed.indexedByChainId[chainId].id,
axelarChainId: combinedComputed.indexedByChainId[chainId].id,
}));

const onReceipt = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "~/lib/contracts/InterchainTokenFactory.hooks";
import { useChainId } from "~/lib/hooks";
import { useEstimateGasFeeMultipleChainsQuery } from "~/services/axelarjsSDK/hooks";
import { useEVMChainConfigsQuery } from "~/services/axelarscan/hooks";
import { useAllChainConfigsQuery } from "~/services/axelarscan/hooks";
import { useInterchainTokenDetailsQuery } from "~/services/interchainToken/hooks";

export type RegisterRemoteCanonicalTokensInput = {
Expand All @@ -24,24 +24,25 @@ export type RegisterRemoteCanonicalTokensInput = {
export default function useRegisterRemoteCanonicalTokens(
input: RegisterRemoteCanonicalTokensInput
) {
const { computed } = useEVMChainConfigsQuery();
const { combinedComputed } = useAllChainConfigsQuery();

const chainId = useChainId();

const destinationChains = useMemo(
() =>
input.chainIds
.map((chainId) => computed.indexedByChainId[chainId])
.map((chainId) => combinedComputed.indexedByChainId[chainId])
.filter(Boolean),
[input.chainIds, computed.indexedByChainId]
[input.chainIds, combinedComputed.indexedByChainId]
);

const destinationChainIds = destinationChains.map(
(chain) => chain.chain_name
);

const sourceChain = useMemo(
() => computed.indexedByChainId[chainId],
[chainId, computed.indexedByChainId]
() => combinedComputed.indexedByChainId[chainId],
[chainId, combinedComputed.indexedByChainId]
);

const { data: tokenDetails } = useInterchainTokenDetailsQuery({
Expand Down
Loading

0 comments on commit f6ad38e

Please sign in to comment.