From 96adca65ef4cdd977be789cdacf51b8b03365e33 Mon Sep 17 00:00:00 2001 From: Jon Tzeng Date: Fri, 27 Sep 2024 12:53:57 -0700 Subject: [PATCH 1/2] Fix changenow for POL, and any other changenow currency that doesn't match our currency code definitions --- src/swap/central/changenow.ts | 41 ++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/swap/central/changenow.ts b/src/swap/central/changenow.ts index 25c56428..e12ee06a 100644 --- a/src/swap/central/changenow.ts +++ b/src/swap/central/changenow.ts @@ -25,7 +25,9 @@ import { import { checkInvalidCodes, checkWhitelistedMainnetCodes, + CurrencyCodeTranscriptionMap, ensureInFuture, + getCodes, getCodesWithTranscription, getMaxSwappable, InvalidCurrencyCodes, @@ -128,6 +130,10 @@ const SPECIAL_MAINNET_CASES: { avalanche: new Map([[null, 'cchain']]) } +const CURRENCY_CODE_TRANSCRIPTION: CurrencyCodeTranscriptionMap = { + polygon: { POL: 'matic' } +} + export function makeChangeNowPlugin( opts: EdgeCorePluginOptions ): EdgeSwapPlugin { @@ -153,21 +159,26 @@ export function makeChangeNowPlugin( getAddress(request.toWallet) ]) - const { - fromCurrencyCode, - toCurrencyCode, - fromMainnetCode: defaultFromMainnetCode, - toMainnetCode: defaultToMainnetCode - } = getCodesWithTranscription(request, MAINNET_CODE_TRANSCRIPTION) - const fromMainnetCode = + // Get our currency codes + const { fromCurrencyCode, toCurrencyCode } = getCodes(request) + + // Get Changenow's codes for the request + const changenowCodes = getCodesWithTranscription( + request, + MAINNET_CODE_TRANSCRIPTION, + CURRENCY_CODE_TRANSCRIPTION + ) + // Modify special mainnet code cases + changenowCodes.fromMainnetCode = SPECIAL_MAINNET_CASES[request.fromWallet.currencyInfo.pluginId]?.get( request.fromTokenId - ) ?? defaultFromMainnetCode - const toMainnetCode = + ) ?? changenowCodes.fromMainnetCode + changenowCodes.toMainnetCode = SPECIAL_MAINNET_CASES[request.toWallet.currencyInfo.pluginId]?.get( request.toTokenId - ) ?? defaultToMainnetCode - const currencyString = `fromCurrency=${fromCurrencyCode}&toCurrency=${toCurrencyCode}&fromNetwork=${fromMainnetCode}&toNetwork=${toMainnetCode}` + ) ?? changenowCodes.toMainnetCode + + const currencyString = `fromCurrency=${changenowCodes.fromCurrencyCode}&toCurrency=${changenowCodes.toCurrencyCode}&fromNetwork=${changenowCodes.fromMainnetCode}&toNetwork=${changenowCodes.toMainnetCode}` async function createOrder( flow: 'fixed-rate' | 'standard', @@ -192,10 +203,10 @@ export function makeChangeNowPlugin( // Create order const orderBody = { - fromCurrency: fromCurrencyCode, - toCurrency: toCurrencyCode, - fromNetwork: fromMainnetCode, - toNetwork: toMainnetCode, + fromCurrency: changenowCodes.fromCurrencyCode, + toCurrency: changenowCodes.toCurrencyCode, + fromNetwork: changenowCodes.fromMainnetCode, + toNetwork: changenowCodes.toMainnetCode, fromAmount: isSelling ? largeDenomAmount : '', toAmount: isSelling ? '' : largeDenomAmount, type, From 6ddaad04267f357ab5c16bbced46325106028dd3 Mon Sep 17 00:00:00 2001 From: Jon Tzeng Date: Fri, 27 Sep 2024 13:02:33 -0700 Subject: [PATCH 2/2] Fix POL for letsexchange --- CHANGELOG.md | 2 ++ src/swap/central/letsexchange.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bca0930..a86539ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- fixed: POL currency code transcriptions for `letsexchange` and `changenow` + ## 2.9.0 (2024-09-27) - added: Add Maya Protocol diff --git a/src/swap/central/letsexchange.ts b/src/swap/central/letsexchange.ts index e1b805fd..a3bf4014 100644 --- a/src/swap/central/letsexchange.ts +++ b/src/swap/central/letsexchange.ts @@ -112,7 +112,7 @@ const MAINNET_CODE_TRANSCRIPTION = { osmosis: 'OSMO', piratechain: 'ARRR', polkadot: 'DOT', - polygon: 'MATIC', + polygon: 'POL', pulsechain: 'PLS', qtum: 'QTUM', ravencoin: 'RVN',