Skip to content

Commit

Permalink
Use the value derived from the smart contract method instead of the p…
Browse files Browse the repository at this point in the history
…opulated 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.
  • Loading branch information
peachbits committed Oct 31, 2023
1 parent 5ca552f commit 090ce6a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/swap/defi/uni-v2-based/plugins/spookySwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
],
Expand Down
7 changes: 5 additions & 2 deletions src/swap/defi/uni-v2-based/plugins/tombSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
],
Expand Down
7 changes: 5 additions & 2 deletions src/swap/defi/uni-v2-based/plugins/velodrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
],
Expand Down

0 comments on commit 090ce6a

Please sign in to comment.