Skip to content

Commit

Permalink
feat: fix transfer from sui remote chain to evm origin chain
Browse files Browse the repository at this point in the history
  • Loading branch information
npty committed Feb 20, 2025
1 parent 98d023b commit 2b25045
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
11 changes: 2 additions & 9 deletions apps/maestro/src/server/routers/sui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,24 +192,17 @@ export const suiRouter = router({
});
const coinObjectId = coins.data[0].coinObjectId;

// Split token to transfer to the destination chain
const Coin = tx.splitCoins(coinObjectId, [BigInt(input.amount)]);

const coinMetadata = await suiClient.getCoinMetadata({
coinType: input.coinType,
});

if (!coinMetadata) {
throw new Error(`Coin metadata not found for ${input.coinType}`);
}
// Split token to transfer to the destination chain
const Coin = tx.splitCoins(coinObjectId, [BigInt(input.amount)]);

const { Example, AxelarGateway, GasService, ITS } = chainConfig.contracts;

const TokenId = await getTokenId(
txBuilder,
input.tokenId,
ITS,
coinMetadata
);

await txBuilder.moveCall({
Expand Down
31 changes: 25 additions & 6 deletions apps/maestro/src/server/routers/sui/utils/txUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { TxBuilder } from "@axelar-network/axelar-cgp-sui";
import { CoinMetadata } from "@mysten/sui/client";

import { suiClient } from "~/lib/clients/suiClient";
import { suiServiceBaseUrl } from "./utils";
Expand All @@ -19,13 +18,28 @@ export function setupTxBuilder(sender: string) {

export async function getTokenId(
txBuilder: TxBuilder,
tokenType: string,
tokenId: string,
ITS: any,
coinMetadata: CoinMetadata
) {
const [TokenId] = await txBuilder.moveCall({
const [TokenId] = await txBuilder.moveCall({
target: `${ITS.address}::token_id::from_u256`,
arguments: [
tokenId.toString(),
],
})

return TokenId;
}

export async function getTokenIdByCoinMetadata(
txBuilder: TxBuilder,
coinType: string,
ITS: any,
coinMetadata: any,
) {
const [TokenId] = await txBuilder.moveCall({
target: `${ITS.address}::token_id::from_info`,
typeArguments: [tokenType],
typeArguments: [coinType],
arguments: [
coinMetadata.name,
coinMetadata.symbol,
Expand All @@ -49,7 +63,12 @@ export async function deployRemoteInterchainToken(
const { Example, ITS, AxelarGateway, GasService } = chainConfig.contracts;
const gas = txBuilder.tx.splitCoins(txBuilder.tx.gas, [feeUnitAmount]);

const TokenId = await getTokenId(txBuilder, tokenType, ITS, coinMetadata);
const TokenId = await getTokenIdByCoinMetadata(
txBuilder,
tokenType,
ITS,
coinMetadata
);

await txBuilder.moveCall({
target: `${Example.address}::its::deploy_remote_interchain_token`,
Expand Down

0 comments on commit 2b25045

Please sign in to comment.