Skip to content

Commit f7d992e

Browse files
authored
TB route: source token quote fix (#813)
* TB route: source token quote fix Set the quote source token to the input token * fix relay fee
1 parent 9bcdbaa commit f7d992e

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

connect/src/protocols/tokenBridge/tokenTransfer.ts

+18-11
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,11 @@ export namespace TokenTransfer {
562562
lookup.address as UniversalAddress,
563563
);
564564
const destWrappedNative = await dstTb.getWrappedNative();
565-
if (canonicalAddress({ chain: dstChain.chain, address: destWrappedNative }) === canonicalAddress({ chain: dstChain.chain, address: nativeAddress })) {
566-
return { chain: dstChain.chain, address: 'native' }
565+
if (
566+
canonicalAddress({ chain: dstChain.chain, address: destWrappedNative }) ===
567+
canonicalAddress({ chain: dstChain.chain, address: nativeAddress })
568+
) {
569+
return { chain: dstChain.chain, address: "native" };
567570
}
568571
return { chain: dstChain.chain, address: nativeAddress };
569572
}
@@ -744,7 +747,7 @@ export namespace TokenTransfer {
744747
if (!transfer.automatic) {
745748
return {
746749
sourceToken: {
747-
token: srcTokenId,
750+
token: transfer.token,
748751
amount: amount.units(srcAmountTruncated),
749752
},
750753
destinationToken: { token: dstToken, amount: amount.units(dstAmountReceivable) },
@@ -821,10 +824,8 @@ export namespace TokenTransfer {
821824
// or the transaction could fail if the account does not have enough lamports
822825
if (dstToken.chain === "Solana") {
823826
const nativeWrappedTokenId = await dstChain.getNativeWrappedTokenId();
824-
const isNativeSol = (isNative(dstToken.address) || isSameToken(dstToken, nativeWrappedTokenId));
825-
if (
826-
isNativeSol && destAmountLessFee < solanaMinBalanceForRentExemptAccount
827-
) {
827+
const isNativeSol = isNative(dstToken.address) || isSameToken(dstToken, nativeWrappedTokenId);
828+
if (isNativeSol && destAmountLessFee < solanaMinBalanceForRentExemptAccount) {
828829
throw new Error(
829830
`Destination amount must be at least ${solanaMinBalanceForRentExemptAccount} lamports`,
830831
);
@@ -833,11 +834,11 @@ export namespace TokenTransfer {
833834

834835
return {
835836
sourceToken: {
836-
token: srcTokenId,
837+
token: transfer.token,
837838
amount: amount.units(srcAmountTruncated),
838839
},
839840
destinationToken: { token: dstToken, amount: destAmountLessFee },
840-
relayFee: { token: srcTokenId, amount: fee },
841+
relayFee: { token: dstToken, amount: amount.units(feeAmountDest) },
841842
destinationNativeGas,
842843
warnings: warnings.length > 0 ? warnings : undefined,
843844
eta,
@@ -863,9 +864,15 @@ export namespace TokenTransfer {
863864
);
864865
if (isNative(destinationToken.address)) {
865866
const nativeWrappedTokenId = await dstChain.getNativeWrappedTokenId();
866-
_transfer.to = await dstChain.getTokenAccount(_transfer.to.address, nativeWrappedTokenId.address);
867+
_transfer.to = await dstChain.getTokenAccount(
868+
_transfer.to.address,
869+
nativeWrappedTokenId.address,
870+
);
867871
} else {
868-
_transfer.to = await dstChain.getTokenAccount(_transfer.to.address, destinationToken.address)
872+
_transfer.to = await dstChain.getTokenAccount(
873+
_transfer.to.address,
874+
destinationToken.address,
875+
);
869876
}
870877
}
871878

0 commit comments

Comments
 (0)