Skip to content

Commit

Permalink
chore: complete transfer (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
SGiaccobasso authored Jan 28, 2025
1 parent a5292eb commit 839fe26
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
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,7 +91,7 @@ export function useInterchainTransferMutation(
destinationChain: config.destinationChainName,
destinationAddress: destinationAddress,
gas: config.gas.toString() ?? "0",
coinObjectId: coinObjectId,
coinType: coinType,
});
txHash = await signAndExecuteTransaction({
transaction: sendTokenTxJSON,
Expand Down
28 changes: 8 additions & 20 deletions apps/maestro/src/server/routers/sui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export const suiRouter = router({
destinationChain: z.string(),
destinationAddress: z.string(),
gas: z.string(),
coinObjectId: z.string(),
coinType: z.string(),
})
)
.mutation(async ({ input }) => {
Expand All @@ -225,8 +225,12 @@ export const suiRouter = router({

// Split coins for gas
const Gas = tx.splitCoins(tx.gas, [BigInt(input.gas)]);
// keep from the object id everything before the first :
const coinObjectId = input.coinObjectId.split(":")[0];

const coins = await suiClient.getCoins({
owner: input.sender,
coinType: input.coinType,
});
const coinObjectId = coins.data[0].coinObjectId;

// Split token to transfer to the destination chain
const Coin = tx.splitCoins(coinObjectId, [BigInt(input.amount)]);
Expand All @@ -235,22 +239,6 @@ export const suiRouter = router({
target: `${chainConfig.contracts.ITS.address}::token_id::from_u256`,
arguments: [input.tokenId],
});
console.log(
"chainConfig.contracts.Example.objects.ItsSingleton",
chainConfig.contracts.Example.objects.ItsSingleton
);
console.log(
"chainConfig.contracts.ITS.objects.ITS",
chainConfig.contracts.ITS.objects.ITS
);
console.log(
"chainConfig.contracts.AxelarGateway.objects.Gateway",
chainConfig.contracts.AxelarGateway.objects.Gateway
);
console.log(
"chainConfig.contracts.GasService.objects.GasService",
chainConfig.contracts.GasService.objects.GasService
);

await txBuilder.moveCall({
target: `${chainConfig.contracts.Example.address}::its::send_interchain_transfer_call`,
Expand All @@ -269,7 +257,7 @@ export const suiRouter = router({
"0x",
CLOCK_PACKAGE_ID,
],
typeArguments: [input.coinObjectId],
typeArguments: [input.coinType],
});

const tx2 = await buildTx(input.sender, txBuilder);
Expand Down

0 comments on commit 839fe26

Please sign in to comment.