Skip to content

Commit

Permalink
Merge pull request #313 from EdgeApp/matthew/newMainnets
Browse files Browse the repository at this point in the history
Audit and whitelist plugins across centralized swap partners
  • Loading branch information
peachbits authored Feb 9, 2024
2 parents 609e016 + 3ad30a9 commit a535b36
Show file tree
Hide file tree
Showing 10 changed files with 439 additions and 76 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- added: Mainnet codes for Arbitrum, Axelar, Base, and Cosmos Hub
- changed: (CEX) Only allow quotes with known mainnet network codes

## 2.0.2 (2023-02-01)

- fixed: Do not crash at load time if `BigInt` is not present.
Expand Down
66 changes: 47 additions & 19 deletions src/swap/central/changehero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {

import {
checkInvalidCodes,
checkWhitelistedMainnetCodes,
CurrencyCodeTranscriptionMap,
getCodesWithTranscription,
getMaxSwappable,
Expand All @@ -45,30 +46,61 @@ const asInitOptions = asObject({
})

const MAINNET_CODE_TRANSCRIPTION: StringMap = {
ethereum: 'ethereum',
binancesmartchain: 'binance_smart_chain',
solana: 'solana',
algorand: 'algorand',
arbitrum: 'arbitrum',
avalanche: 'avalanche_(c-chain)',
// axelar:
base: 'base',
binance: 'binance_dex',
binancesmartchain: 'binance_smart_chain',
bitcoin: 'bitcoin',
bitcoincash: 'bitcoin_cash',
// bitcoingold:
bitcoinsv: 'bitcoin_sv',
bitcoin: 'bitcoin',
tron: 'tron',
polygon: 'polygon',
// celo:
// coreum:
// cosmoshub:
dash: 'dash',
digibyte: 'digibyte',
dogecoin: 'doge',
polkadot: 'polkadot',
// eboost:
// eos:
ethereum: 'ethereum',
ethereumclassic: 'ethereum_classic',
optimism: 'optimism',
// ethereumpow:
fantom: 'ftm',
// feathercoin:
// filecoin:
// filecoinfevm:
// fio:
// groestlcoin:
hedera: 'hedera',
// liberland:
litecoin: 'litecoin',
qtum: 'qtum',
stellar: 'stellar',
monero: 'monero',
optimism: 'optimism',
// osmosis:
// piratechain:
polkadot: 'polkadot',
polygon: 'polygon',
// pulsechain:
qtum: 'qtum',
// ravencoin:
ripple: 'ripple',
// rsk:
// smartcash:
solana: 'solana',
stellar: 'stellar',
// telos:
tezos: 'tezos',
// thorchainrune:
tron: 'tron',
// ufo:
// vertcoin:
// wax:
zcash: 'zcash'
// zcoin:
// zksync:
}

const CURRENCY_CODE_TRANSCRIPTION: CurrencyCodeTranscriptionMap = {
Expand Down Expand Up @@ -163,15 +195,6 @@ export function makeChangeHeroPlugin(
getAddress(request.toWallet)
])

// Supported chains must be whitelisted
if (
MAINNET_CODE_TRANSCRIPTION[request.fromWallet.currencyInfo.pluginId] ==
null ||
MAINNET_CODE_TRANSCRIPTION[request.toWallet.currencyInfo.pluginId] == null
) {
throw new SwapCurrencyError(swapInfo, request)
}

const {
fromCurrencyCode,
toCurrencyCode,
Expand Down Expand Up @@ -345,6 +368,11 @@ export function makeChangeHeroPlugin(
async fetchSwapQuote(req: EdgeSwapRequest): Promise<EdgeSwapQuote> {
const request = convertRequest(req)
checkInvalidCodes(INVALID_CURRENCY_CODES, request, swapInfo)
checkWhitelistedMainnetCodes(
MAINNET_CODE_TRANSCRIPTION,
request,
swapInfo
)

const newRequest = await getMaxSwappable(getFixedQuote, request)
const swapOrder = await getFixedQuote(newRequest)
Expand Down
63 changes: 61 additions & 2 deletions src/swap/central/changenow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {

import {
checkInvalidCodes,
checkWhitelistedMainnetCodes,
ensureInFuture,
getCodesWithTranscription,
getMaxSwappable,
Expand Down Expand Up @@ -61,8 +62,61 @@ const INVALID_CURRENCY_CODES: InvalidCurrencyCodes = {
// Network names that don't match parent network currency code
// See https://changenow.io/currencies for list of supported currencies
const MAINNET_CODE_TRANSCRIPTION = {
binancesmartchain: 'BSC',
pulsechain: 'PULSE'
algorand: 'algo',
arbitrum: 'arbitrum',
avalanche: 'avaxc',
// axelar:
base: 'base',
binance: 'bnb',
binancesmartchain: 'bsc',
bitcoin: 'btc',
bitcoincash: 'bch',
bitcoingold: 'btg',
bitcoinsv: 'bsv',
celo: 'celo',
// coreum:
cosmoshub: 'atom',
dash: 'dash',
digibyte: 'dgb',
dogecoin: 'doge',
// eboost:
eos: 'eos',
ethereum: 'eth',
ethereumclassic: 'etc',
ethereumpow: 'ethw',
fantom: 'ftm',
// feathercoin:
filecoin: 'fil',
// filecoinfevm:
fio: 'fio',
// groestlcoin:
hedera: 'hbar',
// liberland:
litecoin: 'ltc',
monero: 'xmr',
optimism: 'op',
osmosis: 'osmo',
// piratechain:
polkadot: 'dot',
polygon: 'matic',
pulsechain: 'pulse',
qtum: 'qtum',
ravencoin: 'rvn',
ripple: 'xrp',
// rsk:
// smartcash:
solana: 'sol',
stellar: 'xlm',
// telos:
tezos: 'xtz',
// thorchainrune:
tron: 'trx',
// ufo:
// vertcoin:
wax: 'waxp',
zcash: 'zec',
zcoin: 'firo',
zksync: 'zksync'
}

export function makeChangeNowPlugin(
Expand Down Expand Up @@ -344,6 +398,11 @@ export function makeChangeNowPlugin(
const request = convertRequest(req)

checkInvalidCodes(INVALID_CURRENCY_CODES, request, swapInfo)
checkWhitelistedMainnetCodes(
MAINNET_CODE_TRANSCRIPTION,
request,
swapInfo
)

const newRequest = await getMaxSwappable(
fetchSwapQuoteInner,
Expand Down
75 changes: 64 additions & 11 deletions src/swap/central/exolix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {

import {
checkInvalidCodes,
checkWhitelistedMainnetCodes,
getCodesWithTranscription,
getMaxSwappable,
InvalidCurrencyCodes,
Expand All @@ -44,23 +45,70 @@ const asInitOptions = asObject({
})

const INVALID_CURRENCY_CODES: InvalidCurrencyCodes = {
from: {
binancesmartchain: 'allCodes',
ethereum: ['MATIC'],
optimism: 'allCodes',
polygon: 'allCodes'
},
from: {},
to: {
binancesmartchain: 'allCodes',
ethereum: ['MATIC'],
optimism: 'allCodes',
polygon: 'allCodes',
zcash: ['ZEC']
}
}

// See https://exolix.com/currencies for list of supported currencies
const MAINNET_CODE_TRANSCRIPTION = {}
const MAINNET_CODE_TRANSCRIPTION = {
algorand: 'ALGO',
arbitrum: 'ARBITRUM',
avalanche: 'AVAXC',
// axelar:
// base:
// binance:
binancesmartchain: 'BSC',
bitcoin: 'BTC',
bitcoincash: 'BCH',
// bitcoingold:
// bitcoinsv:
celo: 'CELO',
// coreum:
cosmoshub: 'ATOM',
dash: 'DASH',
digibyte: 'DGB',
dogecoin: 'DOGE',
// eboost:
eos: 'EOS',
ethereum: 'ETH',
ethereumclassic: 'ETC',
// ethereumpow:
fantom: 'FTM',
// feathercoin:
filecoin: 'FIL',
// filecoinfevm:
// fio:
// groestlcoin:
hedera: 'HBAR',
// liberland:
litecoin: 'LTC',
monero: 'XMR',
optimism: 'OPTIMISM',
osmosis: 'OSMO',
// piratechain:
polkadot: 'DOT',
// polygon:
// pulsechain:
qtum: 'QTUM',
ravencoin: 'RVN',
ripple: 'XRP',
// rsk:
// smartcash:
solana: 'SOL',
stellar: 'XLM',
telos: 'TELOS',
tezos: 'XTZ',
thorchainrune: 'RUNE',
tron: 'TRX',
// ufo:
// vertcoin:
// wax:
zcash: 'ZEC'
// zcoin:
// zksync:
}

const orderUri = 'https://exolix.com/transaction/'
const uri = 'https://exolix.com/api/v2/'
Expand Down Expand Up @@ -289,6 +337,11 @@ export function makeExolixPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
const request = convertRequest(req)

checkInvalidCodes(INVALID_CURRENCY_CODES, request, swapInfo)
checkWhitelistedMainnetCodes(
MAINNET_CODE_TRANSCRIPTION,
request,
swapInfo
)

const newRequest = await getMaxSwappable(
getFixedQuote,
Expand Down
Loading

0 comments on commit a535b36

Please sign in to comment.