Skip to content

Commit

Permalink
merge coins before splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
artursapek committed Oct 28, 2024
1 parent 649e7c0 commit b2aa65b
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions platforms/sui/protocols/cctp/src/circleBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,19 @@ export class SuiCircleBridge<N extends Network, C extends SuiChains>
recipient.chain,
)!;

const [usdcStruct] = await SuiPlatform.getCoins(this.provider, sender, this.usdcId);
const [primaryCoin, ...mergeCoins] = await SuiPlatform.getCoins(this.provider, sender, this.usdcId);

if (!usdcStruct) {
if (primaryCoin === undefined) {
throw new Error('No USDC in wallet');
}

// It thinks balance is not a property when it is
// Maybe need to update SDK?
/* @ts-ignore */
if (usdcStruct.balance < amount) {
throw new Error('Amount exceeds USDC balance');
const primaryCoinInput = tx.object(primaryCoin.coinObjectId);
if (mergeCoins.length > 0) {
tx.mergeCoins(primaryCoinInput, mergeCoins.map((coin) => tx.object(coin.coinObjectId)));
}

const [coin] = tx.splitCoins(
usdcStruct.coinObjectId,
primaryCoinInput,
[amount]
);

Expand Down

0 comments on commit b2aa65b

Please sign in to comment.