Skip to content

Commit

Permalink
Merge pull request #321 from EdgeApp/paul/fixMemos
Browse files Browse the repository at this point in the history
Remove use of legacy memos
  • Loading branch information
paullinator authored Apr 5, 2024
2 parents 46d3f87 + 2726499 commit 6054f1e
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

- added: Login info to testconfig for testpartners.ts
- changed: Change Lifi and Thorchain DA to use variable quotes
- fixed: LiFi and Thorchain/DA memo handling
- fixed: Memo handling by DEX plugins
- fixed: Letsexchange orderUri

## 2.3.1 (2024-03-29)

Expand Down
2 changes: 1 addition & 1 deletion src/swap/central/letsexchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const asInitOptions = asObject({
affiliateId: asOptional(asString)
})

const orderUri = 'https://letsexchange.io/?exchangeId='
const orderUri = 'https://letsexchange.io/?transactionId='
const uri = 'https://api.letsexchange.io/api/v1/'

const expirationMs = 1000 * 60
Expand Down
2 changes: 1 addition & 1 deletion src/swap/defi/defiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const getEvmApprovalData = async (params: {
gasPrice: '20'
}
)
return approveTx.data != null ? approveTx.data.replace('0x', '') : undefined
return approveTx.data != null ? approveTx.data.replace(/^0x/, '') : undefined
}

export const getEvmTokenData = async (params: {
Expand Down
2 changes: 1 addition & 1 deletion src/swap/defi/lifi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,11 @@ export function makeLifiPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
tokenId: request.fromTokenId,
spendTargets: [
{
memo: data,
nativeAmount: fromNativeAmount,
publicAddress: approvalAddress
}
],
memos: [{ type: 'hex', value: data.replace(/^0x/, '') }],
networkFeeOption: 'custom',
customNetworkFee: {
// XXX Hack. Lifi doesn't properly estimate ethereum gas limits. Increase by 40%
Expand Down
7 changes: 5 additions & 2 deletions src/swap/defi/thorchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,6 @@ export function makeThorchainPlugin(
vaultAddress: thorAddress,
memo
})
memo = memo.replace('0x', '')

// Token transactions send no ETH (or other EVM mainnet coin)
ethNativeAmount = '0'
Expand All @@ -581,6 +580,7 @@ export function makeThorchainPlugin(
} else {
memo = Buffer.from(memo).toString('hex')
}
memo = memo.replace(/^0x/, '')
} else if (fromWallet.currencyInfo.pluginId === 'thorchainrune') {
const makeTxParams: MakeTxParams = {
type: 'MakeTxDeposit',
Expand Down Expand Up @@ -625,9 +625,12 @@ export function makeThorchainPlugin(
expirationDate: new Date(Date.now() + EXPIRATION_MS)
}
} else {
// For UTXO chains, we send the memo as text which gets
// encoded by the plugins
memoType = 'text'
// Cannot yet do tokens on non-EVM chains

if (fromTokenId != null) {
// Cannot yet do tokens on utxo chains
throw new SwapCurrencyError(swapInfo, request)
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/swap/defi/thorchainDa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ export function makeThorchainDaPlugin(
// throw new SwapCurrencyError(swapInfo, request)
// }

const memoType: EdgeMemo['type'] = 'hex'
let memoType: EdgeMemo['type'] = 'hex'
let memo = calldata.tcMemo ?? calldata.memo ?? ''

log.warn(memo)
Expand Down Expand Up @@ -396,8 +396,10 @@ export function makeThorchainDaPlugin(
} else {
memo = Buffer.from(memo).toString('hex')
}
memo = memo.replace(/^0x/, '')
} else {
// Cannot yet do tokens on non-EVM chains
memoType = 'text'
if (fromMainnetCode !== fromCurrencyCode) {
throw new SwapCurrencyError(swapInfo, request)
}
Expand Down Expand Up @@ -446,8 +448,7 @@ export function makeThorchainDaPlugin(
assetAction: {
assetActionType: 'swap'
},
memos:
memo == null ? [] : [{ type: memoType, value: memo.replace('0x', '') }],
memos: memo == null ? undefined : [{ type: memoType, value: memo }],
savedAction: {
actionType: 'swap',
swapInfo,
Expand Down
5 changes: 4 additions & 1 deletion src/swap/defi/uni-v2-based/plugins/spookySwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,17 @@ export function makeSpookySwapPlugin(
tokenId: request.fromTokenId,
spendTargets: [
{
memo: swapTx.data,
nativeAmount:
swapTxs.length === 2 && i === 0
? '0' // approval transactions don't have a value
: amountToSwap,
publicAddress: swapTx.to
}
],
memos:
swapTx.data != null
? [{ type: 'hex', value: swapTx.data.replace(/^0x/, '') }]
: undefined,
customNetworkFee: {
gasPrice:
swapTx.gasPrice != null
Expand Down
5 changes: 4 additions & 1 deletion src/swap/defi/uni-v2-based/plugins/tombSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,17 @@ export function makeTombSwapPlugin(
tokenId: request.fromTokenId,
spendTargets: [
{
memo: swapTx.data,
nativeAmount:
swapTxs.length === 2 && i === 0
? '0' // approval transactions don't have a value
: amountToSwap,
publicAddress: swapTx.to
}
],
memos:
swapTx.data != null
? [{ type: 'hex', value: swapTx.data.replace(/^0x/, '') }]
: undefined,
customNetworkFee: {
gasPrice:
swapTx.gasPrice != null
Expand Down
5 changes: 4 additions & 1 deletion src/swap/defi/uni-v2-based/plugins/velodrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,17 @@ export function makeVelodromePlugin(
tokenId: request.fromTokenId,
spendTargets: [
{
memo: swapTx.data,
nativeAmount:
swapTxs.length === 2 && i === 0
? '0' // approval transactions don't have a value
: amountToSwap,
publicAddress: swapTx.to
}
],
memos:
swapTx.data != null
? [{ type: 'hex', value: swapTx.data.replace(/^0x/, '') }]
: undefined,
customNetworkFee: {
gasPrice:
swapTx.gasPrice != null
Expand Down

0 comments on commit 6054f1e

Please sign in to comment.