Skip to content

Commit 94f6f69

Browse files
committed
AutomaticTokenBridge xfers to Solana must be greater than rent-exempt amount
1 parent d9a0d9a commit 94f6f69

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

connect/src/protocols/tokenBridge/tokenTransfer.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,9 @@ export namespace TokenTransfer {
671671
),
672672
);
673673

674-
// The expected destination gas can be pulled from the destination token bridge
674+
// TODO: consider moving these solana specific checks to its protocol implementation
675+
const solanaMinBalanceForRentExemptAccount = 890880n;
676+
675677
let destinationNativeGas = 0n;
676678
if (transfer.nativeGas) {
677679
const dtb = await dstChain.getAutomaticTokenBridge();
@@ -692,12 +694,34 @@ export namespace TokenTransfer {
692694
)}>${amount.fmt(maxNativeAmountIn, dstDecimals)}`,
693695
);
694696

697+
// when native gas is requested on solana, the amount must be at least the rent-exempt amount
698+
// or the transaction could fail if the account does not have enough lamports
699+
if (dstChain.chain === "Solana" && _destinationNativeGas < solanaMinBalanceForRentExemptAccount) {
700+
throw new Error(
701+
`Native gas amount must be at least ${solanaMinBalanceForRentExemptAccount} lamports`,
702+
);
703+
}
704+
695705
destinationNativeGas = _destinationNativeGas;
696706
}
697707

698708
const destAmountLessFee =
699709
amount.units(dstAmountReceivable) - dstNativeGasAmountRequested - amount.units(feeAmountDest);
700710

711+
// when sending wsol to solana, the amount must be at least the rent-exempt amount
712+
// or the transaction could fail if the account does not have enough lamports
713+
if (dstToken.chain === "Solana") {
714+
const nativeWrappedTokenId = await dstChain.getNativeWrappedTokenId();
715+
if (
716+
dstToken.address === nativeWrappedTokenId.address &&
717+
destAmountLessFee < solanaMinBalanceForRentExemptAccount
718+
) {
719+
throw new Error(
720+
`Destination amount must be at least ${solanaMinBalanceForRentExemptAccount} lamports`,
721+
);
722+
}
723+
}
724+
701725
return {
702726
sourceToken: {
703727
token: srcToken,

connect/src/routes/tokenBridge/automatic.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export class AutomaticTokenBridgeRoute<N extends Network>
183183
// the maxSwapAmount is in destination chain decimals
184184
const maxSwapAmount = await dtb.maxSwapAmount(request.destination.id.address);
185185
const scale = 10000;
186-
const scaledGasPercent = BigInt(params.options.nativeGas * scale);
186+
const scaledGasPercent = BigInt(Math.floor(params.options.nativeGas * scale));
187187
const dstNativeGasUnits = (maxSwapAmount * scaledGasPercent) / BigInt(scale);
188188
const dstNativeGasAmount = amount.fromBaseUnits(
189189
dstNativeGasUnits,

0 commit comments

Comments
 (0)