diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f50d0cafc0..7cd18423691 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - changed: Allow light accounts to buy up to $50 worth of crypto at a time - fixed: Plaid bank linking with Kado - fixed: Remove red error when deep linking into Edge with no URL path +- fixed: Unstaking tokens from Thorchain savers - removed: USPs a/b/c/d test experiment - always uses default USPs ## 4.4.0 (2024-04-09) diff --git a/src/plugins/stake-plugins/thorchainSavers/tcSaversPlugin.ts b/src/plugins/stake-plugins/thorchainSavers/tcSaversPlugin.ts index 23bf34fcbfd..d8a70a4fba7 100644 --- a/src/plugins/stake-plugins/thorchainSavers/tcSaversPlugin.ts +++ b/src/plugins/stake-plugins/thorchainSavers/tcSaversPlugin.ts @@ -298,7 +298,14 @@ export const makeTcSaversPlugin = async (opts: EdgeGuiPluginOptions): Promise { await updateInboundAddresses(opts) @@ -583,13 +590,18 @@ const stakeRequest = async (opts: EdgeGuiPluginOptions, request: ChangeQuoteRequ if (!isToken && lt(addressBalance, nativeAmount)) { // Easy check to see if primary address doesn't have enough funds + if (isEvm) { + // EVM chains only have one address, so if there aren't enough funds in + // the primary address then we don't have enough funds at all + throw new InsufficientFundsError({ tokenId: null }) + } needsFundingPrimary = true } else { try { const estimateTx = await wallet.makeSpend(spendInfo) networkFee = estimateTx.parentNetworkFee ?? estimateTx.networkFee } catch (e: unknown) { - if (asMaybeInsufficientFundsError(e) != null && !isToken) { + if (!isEvm && asMaybeInsufficientFundsError(e) != null) { needsFundingPrimary = true } else { throw e @@ -877,7 +889,9 @@ const unstakeRequestInner = async (opts: EdgeGuiPluginOptions, request: ChangeQu } const spendInfo: EdgeSpendInfo = { - tokenId, + // For unstaking we always send just the mainnet coin since we are only sending a message + // to the Thorchain pool to withdraw the funds + tokenId: null, spendTargets: [{ publicAddress: poolAddress, nativeAmount: sendNativeAmount }], otherParams: { enableRbf: false, outputSort: 'targets', utxoSourceAddress, forceChangeAddress }, assetAction: { assetActionType: 'unstakeOrder' }, @@ -911,6 +925,12 @@ const unstakeRequestInner = async (opts: EdgeGuiPluginOptions, request: ChangeQu } if (lt(balanceToCheck, sendNativeAmount)) { + // Easy check to see if primary address doesn't have enough funds + if (isEvm) { + // EVM chains only have one address, so if there aren't enough funds in + // the primary address then we don't have enough funds at all + throw new InsufficientFundsError({ tokenId: null }) + } // Easy check to see if primary address doesn't have enough funds needsFundingPrimary = true } else { @@ -919,7 +939,7 @@ const unstakeRequestInner = async (opts: EdgeGuiPluginOptions, request: ChangeQu const estimateTx = await wallet.makeSpend(spendInfo) networkFee = estimateTx.networkFee } catch (e: unknown) { - if (asMaybeInsufficientFundsError(e) != null) { + if (!isEvm && asMaybeInsufficientFundsError(e) != null) { needsFundingPrimary = true } else { throw e @@ -1022,13 +1042,6 @@ const unstakeRequestInner = async (opts: EdgeGuiPluginOptions, request: ChangeQu } } -const changeQuoteFuncs = { - stake: stakeRequest, - unstake: unstakeRequest, - claim: unstakeRequest, - unstakeExact: unstakeRequest -} - const headers = { 'Content-Type': 'application/json' }