Skip to content
Open
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
22 changes: 20 additions & 2 deletions src/changelly.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
}
Expand Down
20 changes: 18 additions & 2 deletions src/changenow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down