From b205b60fea37501d92dbd8d0f9e836b64953c55f Mon Sep 17 00:00:00 2001 From: Artur Sapek Date: Tue, 21 Jan 2025 11:43:50 -0500 Subject: [PATCH] Fix WSOL redemption (#781) * dont override for "native" * handle WSOL properly * handle WSOL in tokenTransfer * compare addresses correctly --- connect/src/protocols/tokenBridge/tokenTransfer.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/connect/src/protocols/tokenBridge/tokenTransfer.ts b/connect/src/protocols/tokenBridge/tokenTransfer.ts index f8dad4a1f..2bd9c7ce2 100644 --- a/connect/src/protocols/tokenBridge/tokenTransfer.ts +++ b/connect/src/protocols/tokenBridge/tokenTransfer.ts @@ -25,6 +25,7 @@ import { canonicalAddress, deserialize, isNative, + isSameToken, isTokenId, isTokenTransferDetails, isTransactionIdentifier, @@ -820,9 +821,9 @@ export namespace TokenTransfer { // or the transaction could fail if the account does not have enough lamports if (dstToken.chain === "Solana") { const nativeWrappedTokenId = await dstChain.getNativeWrappedTokenId(); + const isNativeSol = (isNative(dstToken.address) || isSameToken(dstToken, nativeWrappedTokenId)); if ( - dstToken.address === nativeWrappedTokenId.address && - destAmountLessFee < solanaMinBalanceForRentExemptAccount + isNativeSol && destAmountLessFee < solanaMinBalanceForRentExemptAccount ) { throw new Error( `Destination amount must be at least ${solanaMinBalanceForRentExemptAccount} lamports`, @@ -860,9 +861,12 @@ export namespace TokenTransfer { dstChain, _transfer.token, ); - // TODO: If the token is native, no need to overwrite the destination address check for native - //if (!destinationToken.address.equals((await dstChain.getNativeWrappedTokenId()).address)) - _transfer.to = await dstChain.getTokenAccount(_transfer.to.address, destinationToken.address); + if (isNative(destinationToken.address)) { + const nativeWrappedTokenId = await dstChain.getNativeWrappedTokenId(); + _transfer.to = await dstChain.getTokenAccount(_transfer.to.address, nativeWrappedTokenId.address); + } else { + _transfer.to = await dstChain.getTokenAccount(_transfer.to.address, destinationToken.address) + } } if (_transfer.to.chain === "Sei") {