Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
swansontec committed Apr 23, 2024
2 parents 9d6eb32 + f6b38b6 commit 88ec399
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
35 changes: 24 additions & 11 deletions src/plugins/stake-plugins/thorchainSavers/tcSaversPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,14 @@ export const makeTcSaversPlugin = async (opts: EdgeGuiPluginOptions): Promise<St
throw new Error('pluginId mismatch between request and policy')
}

return await changeQuoteFuncs[action](opts, request)
switch (action) {
case 'stake':
return await stakeRequest(opts, request)
case 'unstake':
case 'claim':
case 'unstakeExact':
return await unstakeRequest(opts, request)
}
},
async fetchStakePosition(request: StakePositionRequest): Promise<StakePosition> {
await updateInboundAddresses(opts)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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' },
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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'
}
Expand Down

0 comments on commit 88ec399

Please sign in to comment.