Skip to content

Commit

Permalink
Move EVM data to EdgeMemo
Browse files Browse the repository at this point in the history
  • Loading branch information
peachbits committed Sep 15, 2023
1 parent 85911ca commit 37f6143
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 18 deletions.
9 changes: 8 additions & 1 deletion src/swap/defi/defiUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EdgeCurrencyInfo, EdgeMetaToken } from 'edge-core-js/types'
import { EdgeCurrencyInfo, EdgeMemo, EdgeMetaToken } from 'edge-core-js/types'
import { ethers } from 'ethers'

import abi from './abi/THORCHAIN_SWAP_ABI'
Expand Down Expand Up @@ -139,3 +139,10 @@ export const getEvmTokenData = async (params: {
if (tx.data == null) throw new Error('No data in tx object')
return tx.data
}

export const makeDataEdgeMemo = (data: string): EdgeMemo => ({
type: 'hex',
value: data,
hidden: true,
memoName: 'data'
})
6 changes: 3 additions & 3 deletions src/swap/defi/lifi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
promiseWithTimeout
} from '../../util/utils'
import { asNumberString, EdgeSwapRequestPlugin, StringMap } from '../types'
import { getEvmApprovalData } from './defiUtils'
import { getEvmApprovalData, makeDataEdgeMemo } from './defiUtils'

const pluginId = 'lifi'
const swapInfo: EdgeSwapInfo = {
Expand Down Expand Up @@ -311,11 +311,11 @@ export function makeLifiPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
currencyCode: request.fromCurrencyCode,
spendTargets: [
{
memo: approvalData,
nativeAmount: '0',
publicAddress: fromContractAddress
}
],
memos: approvalData != null ? [makeDataEdgeMemo(approvalData)] : [],
networkFeeOption: 'custom',
customNetworkFee: {
gasPrice: gasPriceGwei
Expand All @@ -332,11 +332,11 @@ export function makeLifiPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
currencyCode: request.fromCurrencyCode,
spendTargets: [
{
memo: data,
nativeAmount: mul(transactionRequest.value, '1'),
publicAddress: approvalAddress
}
],
memos: [makeDataEdgeMemo(data)],
networkFeeOption: 'custom',
customNetworkFee: {
// XXX Hack. Lifi doesn't properly estimate ethereum gas limits. Increase by 40%
Expand Down
11 changes: 7 additions & 4 deletions src/swap/defi/thorchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ import {
QueryParams
} from '../../util/utils'
import { EdgeSwapRequestPlugin } from '../types'
import { getEvmApprovalData, getEvmTokenData } from './defiUtils'
import {
getEvmApprovalData,
getEvmTokenData,
makeDataEdgeMemo
} from './defiUtils'

const pluginId = 'thorchain'
const swapInfo: EdgeSwapInfo = {
Expand Down Expand Up @@ -564,11 +568,11 @@ export function makeThorchainPlugin(
currencyCode: request.fromCurrencyCode,
spendTargets: [
{
memo: approvalData,
nativeAmount: '0',
publicAddress: sourceTokenContractAddress
}
],
memos: [makeDataEdgeMemo(approvalData)],
metadata: {
name: 'Thorchain',
category: 'expense:Token Approval'
Expand All @@ -581,12 +585,11 @@ export function makeThorchainPlugin(
currencyCode: request.fromCurrencyCode,
spendTargets: [
{
memo,
nativeAmount: ethNativeAmount,
publicAddress
}
],

memos: [makeDataEdgeMemo(memo)],
swapData: {
isEstimate: false,
payoutAddress: toAddress,
Expand Down
11 changes: 7 additions & 4 deletions src/swap/defi/thorchainDa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ import {
} from '../../util/utils'
import { EdgeSwapRequestPlugin } from '../types'
import { abiMap } from './abi/abiMap'
import { getEvmApprovalData, getEvmTokenData } from './defiUtils'
import {
getEvmApprovalData,
getEvmTokenData,
makeDataEdgeMemo
} from './defiUtils'
import {
asExchangeInfo,
asInboundAddresses,
Expand Down Expand Up @@ -409,11 +413,11 @@ export function makeThorchainDaPlugin(
currencyCode: fromMainnetCode,
spendTargets: [
{
memo: approvalData,
nativeAmount: '0',
publicAddress: sourceTokenContractAddress
}
],
memos: [makeDataEdgeMemo(approvalData)],
metadata: {
name: 'Thorchain DEX Aggregator',
category: 'expense:Token Approval'
Expand All @@ -426,12 +430,11 @@ export function makeThorchainDaPlugin(
currencyCode: request.fromCurrencyCode,
spendTargets: [
{
memo,
nativeAmount: ethNativeAmount,
publicAddress
}
],

memos: [makeDataEdgeMemo(memo)],
swapData: {
isEstimate,
payoutAddress: toAddress,
Expand Down
8 changes: 6 additions & 2 deletions src/swap/defi/uni-v2-based/plugins/spookySwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import {
} from '../../../../swap-helpers'
import { convertRequest } from '../../../../util/utils'
import { EdgeSwapRequestPlugin } from '../../../types'
import { getInOutTokenAddresses, InOutTokenAddresses } from '../../defiUtils'
import {
getInOutTokenAddresses,
InOutTokenAddresses,
makeDataEdgeMemo
} from '../../defiUtils'
import {
getFtmProvider,
makeSpookySwapRouterContract,
Expand Down Expand Up @@ -113,7 +117,6 @@ export function makeSpookySwapPlugin(
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
publicAddress: swapTx.to
}
Expand All @@ -125,6 +128,7 @@ export function makeSpookySwapPlugin(
: '0',
gasLimit: swapTx.gasLimit?.toString() ?? '0'
},
memos: swapTx.data != null ? [makeDataEdgeMemo(swapTx.data)] : [],
networkFeeOption: 'custom',
swapData: {
isEstimate: false,
Expand Down
8 changes: 6 additions & 2 deletions src/swap/defi/uni-v2-based/plugins/tombSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import {
} from '../../../../swap-helpers'
import { convertRequest } from '../../../../util/utils'
import { EdgeSwapRequestPlugin } from '../../../types'
import { getInOutTokenAddresses, InOutTokenAddresses } from '../../defiUtils'
import {
getInOutTokenAddresses,
InOutTokenAddresses,
makeDataEdgeMemo
} from '../../defiUtils'
import {
getFtmProvider,
makeTombSwapRouterContract,
Expand Down Expand Up @@ -113,7 +117,6 @@ export function makeTombSwapPlugin(
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
publicAddress: swapTx.to
}
Expand All @@ -125,6 +128,7 @@ export function makeTombSwapPlugin(
: '0',
gasLimit: swapTx.gasLimit?.toString() ?? '0'
},
memos: swapTx.data != null ? [makeDataEdgeMemo(swapTx.data)] : [],
networkFeeOption: 'custom',
swapData: {
isEstimate: false,
Expand Down
4 changes: 2 additions & 2 deletions src/swap/defi/uni-v2-based/plugins/velodrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { convertRequest } from '../../../../util/utils'
import { EdgeSwapRequestPlugin } from '../../../types'
import VELODROME_V1_ROUTER_ABI from '../../abi/VELODROME_V1_ROUTER_ABI'
import WRAPPED_OPTIMISM_ETH_ABI from '../../abi/WRAPPED_OPTIMISM_ETH_ABI'
import { getInOutTokenAddresses } from '../../defiUtils'
import { getInOutTokenAddresses, makeDataEdgeMemo } from '../../defiUtils'
import { getSwapAmounts, getSwapTransactions } from '../uniV2Utils'

const swapInfo: EdgeSwapInfo = {
Expand Down Expand Up @@ -128,7 +128,6 @@ export function makeVelodromePlugin(
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
publicAddress: swapTx.to
}
Expand All @@ -140,6 +139,7 @@ export function makeVelodromePlugin(
: '0',
gasLimit: swapTx.gasLimit?.toString() ?? '0'
},
memos: swapTx.data != null ? [makeDataEdgeMemo(swapTx.data)] : [],
networkFeeOption: 'custom',
swapData: {
isEstimate: false,
Expand Down

0 comments on commit 37f6143

Please sign in to comment.