Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(devnet-amplifier): complete ITS transfer flow between evm and sui #498

Merged
merged 12 commits into from
Feb 11, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export function useDeployAndRegisterRemoteInterchainTokenMutation(
const registerTxData = destinationChainNames.map((destinationChain, i) =>
INTERCHAIN_TOKEN_FACTORY_ENCODERS.deployRemoteInterchainToken.data({
...commonArgs,
originalChainName: "",
destinationChain,
gasValue: input.remoteDeploymentGasFees?.gasFees?.[i].fee ?? 0n,
})
Expand Down Expand Up @@ -278,8 +277,6 @@ export function useDeployAndRegisterRemoteInterchainTokenMutation(
kind: "interchain",
deploymentMessageId: result.deploymentMessageId,
tokenId: token.token_id?.id,
tokenAddress: result.tokenAddress,
tokenManagerAddress: result.tokenManagerAddress,
deployerAddress,
salt: input.salt,
tokenName: input.tokenName,
Expand All @@ -288,8 +285,9 @@ export function useDeployAndRegisterRemoteInterchainTokenMutation(
axelarChainId: input.sourceChainId,
originalMinterAddress: input.minterAddress,
destinationAxelarChainIds: input.destinationChainIds,
tokenManagerAddress: result.tokenManagerAddress,
tokenAddress: result.tokenAddress,
});

return result;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,14 @@ export const Step2: FC = () => {
rootActions.setTxState({
type: "deployed",
suiTx: result,
txHash: result.digest,
txHash: result.deploymentMessageId as string,
tokenAddress: result.tokenAddress,
// chainId: sourceChain.chain_id,
});
if (rootState.selectedChains.length > 0) {
addTransaction({
status: "submitted",
suiTx: result,
hash: result.digest,
hash: result.deploymentMessageId as string,
chainId: sourceChain.chain_id,
txType: "INTERCHAIN_DEPLOYMENT",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,13 @@ export default function useRegisterRemoteCanonicalTokens(

return INTERCHAIN_TOKEN_FACTORY_ENCODERS.deployRemoteCanonicalInterchainToken.data(
{
originalChain: sourceChain?.chain_name ?? "0x",
originalTokenAddress: tokenDetails.tokenAddress as `0x${string}`,
destinationChain: axelarChainId,
gasValue,
}
);
});
}, [destinationChainIds, gasFeesData, sourceChain?.chain_name, tokenDetails]);
}, [destinationChainIds, gasFeesData, tokenDetails]);

const totalGasFee = gasFeesData?.totalGasFee ?? 0n;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { INTERCHAIN_TOKEN_FACTORY_ENCODERS } from "@axelarjs/evm";
import { useMemo } from "react";

import { zeroAddress } from "viem";

import {
NEXT_PUBLIC_INTERCHAIN_DEPLOYMENT_EXECUTE_DATA,
NEXT_PUBLIC_INTERCHAIN_DEPLOYMENT_GAS_LIMIT,
Expand Down Expand Up @@ -67,13 +65,9 @@ export default function useRegisterRemoteInterchainTokens(
)
return [];

const minter = tokenDeployment.originalMinterAddress ?? zeroAddress;

return destinationChainIds.map((chainId, i) =>
INTERCHAIN_TOKEN_FACTORY_ENCODERS.deployRemoteInterchainToken.data({
salt: tokenDeployment.salt,
originalChainName: sourceChain?.chain_name ?? "",
minter: minter as `0x${string}`,
destinationChain: chainId,
gasValue: gasFeesData.gasFees[i].fee,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,12 @@ export const SendInterchainToken: FC<Props> = (props) => {
}, [actions, props.sourceChain, state.txState, txHash]);

const suiTxDigest = useMemo(() => {
console.log("MEMO@@@ state.txState", state.txState);
return state.txState.status === "submitted"
? state.txState.suiTx?.digest
: undefined;
}, [state.txState]);

useEffect(() => {
console.log("ENTERING USEEFF suiTxDigest", suiTxDigest);
async function trackTransaction() {
if (state.txState.status !== "submitted") return;
if (!state.txState.suiTx) return;
Expand All @@ -205,8 +203,6 @@ export const SendInterchainToken: FC<Props> = (props) => {
txType: "INTERCHAIN_TRANSFER",
});

console.log(" past if state.txState.suiTx", state.txState.suiTx);

await handleSuiTransactionComplete(state.txState.suiTx);
}

Expand Down Expand Up @@ -248,12 +244,6 @@ export const SendInterchainToken: FC<Props> = (props) => {
const handleSuiTransactionComplete = useCallback(
async (result: SuiTransactionBlockResponse) => {
// Check if transaction was successful
console.log(
"handleSuiTransactionComplete",
result,
"and result.effects.status.status ",
result.effects?.status?.status
);
if (result.effects?.status?.status === "success") {
await actions.refetchBalances();
resetForm();
Expand All @@ -275,11 +265,6 @@ export const SendInterchainToken: FC<Props> = (props) => {
}, [state.selectedToChain?.chain_type, props.sourceChain.chain_type]);

useEffect(() => {
console.log(
"chain_type",
state.selectedToChain?.chain_type,
props.sourceChain.chain_type
);
if (isEvmChainsOnly) {
setValue("destinationAddress", address ?? "", {
shouldValidate: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export function useInterchainTransferMutation(

const mutation = useMutation<void, unknown, UseSendInterchainTokenInput>({
mutationFn: async ({ amount, tokenId, destinationAddress, decimals }) => {
if (!(decimals && address && config.gas && tokenId && destinationAddress)) {
if (
!(decimals && address && config.gas && tokenId && destinationAddress)
) {
return;
}

Expand All @@ -80,7 +82,7 @@ export function useInterchainTransferMutation(
});
let txHash: any;
if (config.sourceChainName === "sui") {
const coinObjectId = await getCoinType(config.tokenAddress);
const coinType = await getCoinType(config.tokenAddress);
const sendTokenTxJSON = await getSendTokenTx({
sender: address,
tokenId: tokenId,
Expand All @@ -89,19 +91,20 @@ export function useInterchainTransferMutation(
destinationChain: config.destinationChainName,
destinationAddress: destinationAddress,
gas: config.gas.toString() ?? "0",
coinObjectId: coinObjectId,
coinType: coinType,
});
txHash = await signAndExecuteTransaction({
transaction: sendTokenTxJSON,
chain: "sui:testnet", //TODO: make this dynamic
});
} else {
const recipient = (destinationAddress ?? address) as `0x${string}`;
txHash = await transferAsync({
address: config.tokenAddress,
value: config.gas ?? 0n,
args: INTERCHAIN_TOKEN_ENCODERS.interchainTransfer.args({
destinationChain: config.destinationChainName,
recipient: address,
recipient,
amount: bnAmount,
metadata: "0x",
}),
Expand Down
4 changes: 1 addition & 3 deletions apps/maestro/src/features/suiHooks/useDeployToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,8 @@ export default function useTokenDeploy() {
const tokenManagerType = treasuryCapSendTokenResult
? "mint/burn"
: "lock/unlock";
// TODO:: handle txIndex properly
const txIndex = sendTokenResult?.events?.[0]?.id?.eventSeq ?? 0;
const txIndex = sendTokenResult?.events?.[3]?.id?.eventSeq ?? 0; // TODO: find the correct txIndex, it seems to be always 3
const deploymentMessageId = `${sendTokenResult?.digest}-${txIndex}`;

return {
...sendTokenResult,
deploymentMessageId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import {
createUseSimulateContract,
createUseWriteContract,
createUseSimulateContract,
} from "wagmi/codegen";

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
12 changes: 6 additions & 6 deletions apps/maestro/src/lib/contracts/InterchainToken.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

import {
createUseReadContract,
createUseWriteContract,
createUseSimulateContract,
createUseWatchContractEvent,
createUseWriteContract,
} from "wagmi/codegen";

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -518,14 +518,14 @@ export const useReadInterchainTokenNameHash =
* Wraps __{@link useReadContract}__ with `abi` set to __{@link interchainTokenAbi}__ and `functionName` set to `"nonces"`
*/
export const useReadInterchainTokenNonces = /*#__PURE__*/ createUseReadContract(
{ abi: interchainTokenAbi, functionName: "nonces" }
{ abi: interchainTokenAbi, functionName: "nonces" },
);

/**
* Wraps __{@link useReadContract}__ with `abi` set to __{@link interchainTokenAbi}__ and `functionName` set to `"symbol"`
*/
export const useReadInterchainTokenSymbol = /*#__PURE__*/ createUseReadContract(
{ abi: interchainTokenAbi, functionName: "symbol" }
{ abi: interchainTokenAbi, functionName: "symbol" },
);

/**
Expand Down Expand Up @@ -566,7 +566,7 @@ export const useWriteInterchainTokenApprove =
* Wraps __{@link useWriteContract}__ with `abi` set to __{@link interchainTokenAbi}__ and `functionName` set to `"burn"`
*/
export const useWriteInterchainTokenBurn = /*#__PURE__*/ createUseWriteContract(
{ abi: interchainTokenAbi, functionName: "burn" }
{ abi: interchainTokenAbi, functionName: "burn" },
);

/**
Expand All @@ -591,7 +591,7 @@ export const useWriteInterchainTokenIncreaseAllowance =
* Wraps __{@link useWriteContract}__ with `abi` set to __{@link interchainTokenAbi}__ and `functionName` set to `"init"`
*/
export const useWriteInterchainTokenInit = /*#__PURE__*/ createUseWriteContract(
{ abi: interchainTokenAbi, functionName: "init" }
{ abi: interchainTokenAbi, functionName: "init" },
);

/**
Expand All @@ -616,7 +616,7 @@ export const useWriteInterchainTokenInterchainTransferFrom =
* Wraps __{@link useWriteContract}__ with `abi` set to __{@link interchainTokenAbi}__ and `functionName` set to `"mint"`
*/
export const useWriteInterchainTokenMint = /*#__PURE__*/ createUseWriteContract(
{ abi: interchainTokenAbi, functionName: "mint" }
{ abi: interchainTokenAbi, functionName: "mint" },
);

/**
Expand Down
Loading