Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jon/fix/matic-pol #343

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

- fixed: POL currency code transcriptions for `letsexchange` and `changenow`

## 2.9.0 (2024-09-27)

- added: Add Maya Protocol
Expand Down
41 changes: 26 additions & 15 deletions src/swap/central/changenow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import {
import {
checkInvalidCodes,
checkWhitelistedMainnetCodes,
CurrencyCodeTranscriptionMap,
ensureInFuture,
getCodes,
getCodesWithTranscription,
getMaxSwappable,
InvalidCurrencyCodes,
Expand Down Expand Up @@ -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 {
Expand All @@ -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',
Expand All @@ -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,
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 @@ -112,7 +112,7 @@ const MAINNET_CODE_TRANSCRIPTION = {
osmosis: 'OSMO',
piratechain: 'ARRR',
polkadot: 'DOT',
polygon: 'MATIC',
polygon: 'POL',
pulsechain: 'PLS',
qtum: 'QTUM',
ravencoin: 'RVN',
Expand Down
Loading