From 090ce6a439d269a1b249c13151b4662612f8999f Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 31 Oct 2023 12:35:17 -0700 Subject: [PATCH] Use the value derived from the smart contract method instead of the populated Ethers transaction The value field cannot be relied upon for token transactions since, generally, this field is used for mainnet ETH amount. Instead, we should use the amount we pass to Ethers as the nativeAmount. We also need to account for the fact that in the case where there are two transactions the first one is a 0 amount approval tx and only the second one needs the amount. --- src/swap/defi/uni-v2-based/plugins/spookySwap.ts | 7 +++++-- src/swap/defi/uni-v2-based/plugins/tombSwap.ts | 7 +++++-- src/swap/defi/uni-v2-based/plugins/velodrome.ts | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/swap/defi/uni-v2-based/plugins/spookySwap.ts b/src/swap/defi/uni-v2-based/plugins/spookySwap.ts index 033d1b69..138f73b9 100644 --- a/src/swap/defi/uni-v2-based/plugins/spookySwap.ts +++ b/src/swap/defi/uni-v2-based/plugins/spookySwap.ts @@ -104,14 +104,17 @@ export function makeSpookySwapPlugin( const fromAddress = (await fromWallet.getReceiveAddress()).publicAddress // toEdgeUnsignedTxs - const edgeSpendInfos = swapTxs.map(swapTx => { + const edgeSpendInfos = swapTxs.map((swapTx, i) => { // Convert to our spendInfo const edgeSpendInfo: EdgeSpendInfo = { currencyCode: request.fromCurrencyCode, // what is being sent out, only if token. Blank if not token spendTargets: [ { memo: swapTx.data, - nativeAmount: swapTx.value != null ? swapTx.value.toString() : '0', // biggy/number string integer + nativeAmount: + swapTxs.length === 2 && i === 0 + ? '0' // approval transactions don't have a value + : amountToSwap, publicAddress: swapTx.to } ], diff --git a/src/swap/defi/uni-v2-based/plugins/tombSwap.ts b/src/swap/defi/uni-v2-based/plugins/tombSwap.ts index 1cfe0df5..420aaec0 100644 --- a/src/swap/defi/uni-v2-based/plugins/tombSwap.ts +++ b/src/swap/defi/uni-v2-based/plugins/tombSwap.ts @@ -104,14 +104,17 @@ export function makeTombSwapPlugin( const fromAddress = (await fromWallet.getReceiveAddress()).publicAddress // toEdgeUnsignedTxs - const edgeSpendInfos = swapTxs.map(swapTx => { + const edgeSpendInfos = swapTxs.map((swapTx, i) => { // Convert to our spendInfo const edgeSpendInfo: EdgeSpendInfo = { currencyCode: request.fromCurrencyCode, // what is being sent out, only if token. Blank if not token spendTargets: [ { memo: swapTx.data, - nativeAmount: swapTx.value != null ? swapTx.value.toString() : '0', // biggy/number string integer + nativeAmount: + swapTxs.length === 2 && i === 0 + ? '0' // approval transactions don't have a value + : amountToSwap, publicAddress: swapTx.to } ], diff --git a/src/swap/defi/uni-v2-based/plugins/velodrome.ts b/src/swap/defi/uni-v2-based/plugins/velodrome.ts index 950e08b0..c09929fc 100644 --- a/src/swap/defi/uni-v2-based/plugins/velodrome.ts +++ b/src/swap/defi/uni-v2-based/plugins/velodrome.ts @@ -117,14 +117,17 @@ export function makeVelodromePlugin( ) const fromAddress = (await fromWallet.getReceiveAddress()).publicAddress // toEdgeUnsignedTxs - const edgeSpendInfos = swapTxs.map(swapTx => { + const edgeSpendInfos = swapTxs.map((swapTx, i) => { // Convert to our spendInfo const edgeSpendInfo: EdgeSpendInfo = { currencyCode: request.fromCurrencyCode, // what is being sent out, only if token. Blank if not token spendTargets: [ { memo: swapTx.data, - nativeAmount: swapTx.value != null ? swapTx.value.toString() : '0', // biggy/number string integer + nativeAmount: + swapTxs.length === 2 && i === 0 + ? '0' // approval transactions don't have a value + : amountToSwap, publicAddress: swapTx.to } ],