Skip to content

Commit

Permalink
Merge pull request #345 from EdgeApp/matthew/lifi-parent-token-address
Browse files Browse the repository at this point in the history
Add unique parent token addresses
  • Loading branch information
peachbits authored Oct 4, 2024
2 parents 7c8a878 + bbaded6 commit 78ebad1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- added: (LI.FI) Added unique parent contract addresses

## 2.8.1 (2024-10-02)

- fixed: POL currency code transcriptions for `letsexchange` and `changenow`
Expand Down
37 changes: 33 additions & 4 deletions src/swap/defi/lifi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,32 @@ const MAX_SLIPPAGE = '0.05'
const LIFI_SERVERS_DEFAULT = ['https://li.quest']
const EXPIRATION_MS = 1000 * 60
const EXCHANGE_INFO_UPDATE_FREQ_MS = 60000
const PARENT_TOKEN_CONTRACT_ADDRESS =
'0x0000000000000000000000000000000000000000'

// https://li.quest/v1/chains
const getParentTokenContractAddress = (pluginId: string): string => {
switch (pluginId) {
// chainType UTXO
case 'bitcoin': {
return 'bitcoin'
}

// chainType SVM
case 'solana': {
return '11111111111111111111111111111111'
}

// chainType EVM
case 'celo': {
return '0x471EcE3750Da237f93B8E339c536989b8978a438'
}
case 'metis': {
return '0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000'
}
default: {
return '0x0000000000000000000000000000000000000000'
}
}
}

export const INVALID_CURRENCY_CODES: InvalidCurrencyCodes = {
from: {},
Expand All @@ -83,6 +107,7 @@ const MAINNET_CODE_TRANSCRIPTION: StringMap = {
fuse: 'FUS',
gnosis: 'DAI',
harmony: 'ONE',
metis: 'METIS',
moonbeam: 'MOO',
moonriver: 'MOR',
okexchain: 'OKT',
Expand Down Expand Up @@ -206,7 +231,9 @@ export function makeLifiPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
let fromContractAddress
let sendingToken = false
if (fromCurrencyCode === fromWallet.currencyInfo.currencyCode) {
fromContractAddress = PARENT_TOKEN_CONTRACT_ADDRESS
fromContractAddress = getParentTokenContractAddress(
fromWallet.currencyInfo.pluginId
)
} else {
sendingToken = true
fromContractAddress = fromToken?.networkLocation?.contractAddress
Expand All @@ -215,7 +242,9 @@ export function makeLifiPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
const toToken = toWallet.currencyConfig.allTokens[toTokenId ?? '']
let toContractAddress
if (toCurrencyCode === toWallet.currencyInfo.currencyCode) {
toContractAddress = PARENT_TOKEN_CONTRACT_ADDRESS
toContractAddress = getParentTokenContractAddress(
toWallet.currencyInfo.pluginId
)
} else {
toContractAddress = toToken?.networkLocation?.contractAddress
}
Expand Down

0 comments on commit 78ebad1

Please sign in to comment.