Skip to content

Commit

Permalink
Fix WSOL redemption (#781)
Browse files Browse the repository at this point in the history
* dont override for "native"

* handle WSOL properly

* handle WSOL in tokenTransfer

* compare addresses correctly
  • Loading branch information
artursapek authored Jan 21, 2025
1 parent 4be2f8c commit b205b60
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions connect/src/protocols/tokenBridge/tokenTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
canonicalAddress,
deserialize,
isNative,
isSameToken,
isTokenId,
isTokenTransferDetails,
isTransactionIdentifier,
Expand Down Expand Up @@ -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`,
Expand Down Expand Up @@ -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") {
Expand Down

0 comments on commit b205b60

Please sign in to comment.