diff --git a/src/changelly.js b/src/changelly.js index f5b7794..313280b 100644 --- a/src/changelly.js +++ b/src/changelly.js @@ -8,6 +8,12 @@ const { checkSwapService } = require('./checkSwapService.js') const CHANGELLY_CACHE = './cache/chRaw.json' +const CURRENCY_CODE_TRANSCRIPTION = { + // exchangeCurrencyCode: edgeCurrencyCode + // should be opposite / mirror of exchage-plugins + 'USDT20': 'USDT' +} + let changelly if (config.changellyApiKey && config.changellyApiSecret) { changelly = new Changelly( @@ -76,14 +82,26 @@ async function fetchChangelly (swapFuncParams: SwapFuncParams) { for (const tx of result.result) { if (tx.status === 'finished') { + // check if we need to change currencyCode so that rate API will return an actual value + let inputCurrency = tx.currencyFrom.toUpperCase() + let outputCurrency = tx.currencyTo.toUpperCase() + if (CURRENCY_CODE_TRANSCRIPTION[inputCurrency]) { + console.log('translating ', inputCurrency, ' to ', CURRENCY_CODE_TRANSCRIPTION[inputCurrency]) + inputCurrency = CURRENCY_CODE_TRANSCRIPTION[inputCurrency] + } + if (CURRENCY_CODE_TRANSCRIPTION[outputCurrency]) { + console.log('translating ', outputCurrency, ' to ', CURRENCY_CODE_TRANSCRIPTION[outputCurrency]) + outputCurrency = CURRENCY_CODE_TRANSCRIPTION[outputCurrency] + } + const ssTx: StandardTx = { status: 'complete', inputTXID: tx.payinHash, inputAddress: tx.payinAddress, - inputCurrency: tx.currencyFrom.toUpperCase(), + inputCurrency, inputAmount: tx.amountExpectedFrom, outputAddress: tx.payoutAddress, - outputCurrency: tx.currencyTo.toUpperCase(), + outputCurrency, outputAmount: tx.amountExpectedTo, timestamp: tx.createdAt } diff --git a/src/changenow.js b/src/changenow.js index 1adaee6..ab97208 100644 --- a/src/changenow.js +++ b/src/changenow.js @@ -8,6 +8,12 @@ const { checkSwapService } = require('./checkSwapService.js') const CHANGENOW_CACHE = './cache/cnRaw.json' +const CURRENCY_CODE_TRANSCRIPTION = { + // exchangeCurrencyCode: edgeCurrencyCode + // should be opposite / mirror of exchage-plugins + 'USDTERC20': 'USDT' +} + async function doChangenow (swapFuncParams: SwapFuncParams) { return checkSwapService(fetchChangenow, CHANGENOW_CACHE, @@ -43,15 +49,25 @@ async function fetchChangenow (swapFuncParams: SwapFuncParams) { if (tx.status === 'finished') { const date = new Date(tx.updatedAt) const timestamp = date.getTime() / 1000 + let inputCurrency = tx.fromCurrency.toUpperCase() + let outputCurrency = tx.toCurrency.toUpperCase() + if (CURRENCY_CODE_TRANSCRIPTION[inputCurrency]) { + console.log('translating ', inputCurrency, ' to ', CURRENCY_CODE_TRANSCRIPTION[inputCurrency]) + inputCurrency = CURRENCY_CODE_TRANSCRIPTION[inputCurrency] + } + if (CURRENCY_CODE_TRANSCRIPTION[outputCurrency]) { + console.log('translating ', outputCurrency, ' to ', CURRENCY_CODE_TRANSCRIPTION[outputCurrency]) + outputCurrency = CURRENCY_CODE_TRANSCRIPTION[outputCurrency] + } const ssTx: StandardTx = { status: 'complete', inputTXID: tx.payinHash, inputAddress: tx.payinAddress, - inputCurrency: tx.fromCurrency.toUpperCase(), + inputCurrency, inputAmount: tx.amountSend, outputAddress: tx.payoutAddress, - outputCurrency: tx.toCurrency.toUpperCase(), + outputCurrency, outputAmount: tx.amountReceive.toString(), timestamp }