Skip to content

Commit

Permalink
Avoid processing a funding transaction on EVM chains for TC unstaking
Browse files Browse the repository at this point in the history
  • Loading branch information
samholmes committed Apr 19, 2024
1 parent 22ae30c commit 233e489
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/plugins/stake-plugins/thorchainSavers/tcSaversPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,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
Expand Down Expand Up @@ -918,6 +923,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 {
Expand All @@ -926,7 +937,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
Expand Down

0 comments on commit 233e489

Please sign in to comment.