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

Add country and exchange type info #197

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b2cdf17
Add comments to config definition
samholmes Jan 6, 2025
aa136dc
Upgrade cleaners@^0.3.17
samholmes Jan 7, 2025
3c0dab2
Factor out `processBanxaTx` function
samholmes Jan 8, 2025
6ce79fe
Factor out `processBitaccessTx` function
samholmes Jan 8, 2025
09ee5f9
Factor out `processBitrefillTx` function
samholmes Jan 8, 2025
4c71b75
Factor out `processBitsOfGoldTx` function
samholmes Jan 8, 2025
4e58d50
Factor out `processBityTx` function
samholmes Jan 8, 2025
2174a46
Factor out `processChangeHeroTx` function
samholmes Jan 8, 2025
f56cdee
Factor out `processChangellyTx` function
samholmes Jan 8, 2025
8836a0a
Factor out `processChangeNowTx` function
samholmes Jan 8, 2025
665a2a1
Factor out `processCoinSwitchTx` function
samholmes Jan 8, 2025
c9421a2
Factor out `processExolixTx` function
samholmes Jan 8, 2025
8cc5299
Factor out `processFaastTx` function
samholmes Jan 8, 2025
67d38b2
Factor out `processFoxExchangeTx` function
samholmes Jan 8, 2025
b36286e
Factor out `processGodexTx` function
samholmes Jan 8, 2025
70f5062
Factor out `processIoniaGiftCardsTx` function
samholmes Jan 9, 2025
876c834
Factor out `processIoniaVisaRewardsTx` function
samholmes Jan 9, 2025
ee2ad54
Factor out `processKadoTx` function
samholmes Jan 9, 2025
9d42811
Factor out `processLetsExchangeTx` function
samholmes Jan 9, 2025
054a487
Factor out `processLibertyxTx` function
samholmes Jan 9, 2025
821e148
Factor out `processLifiTx` function
samholmes Jan 9, 2025
4731352
Factor out `processMoonpayTx` function
samholmes Jan 9, 2025
997c870
Factor out `processPaybisTx` function
samholmes Jan 9, 2025
4ea37e2
Factor out `processPaytrieTx` function
samholmes Jan 9, 2025
e6a0fab
Factor out `processSafelloTx` function
samholmes Jan 9, 2025
b68d227
Factor out `processShapeshiftTx` function
samholmes Jan 9, 2025
e87e4c0
Factor out `processSideshiftTx` function
samholmes Jan 9, 2025
6874a28
Factor out `processSimplexTx` function
samholmes Jan 9, 2025
b34df04
Factor out `processSwapuzTx` function
samholmes Jan 9, 2025
d215f69
Factor out `processSwitchainTx` function
samholmes Jan 9, 2025
7f57ddf
Factor out `processThorchainTx` function
samholmes Jan 9, 2025
8dc2663
Factor out `processTransakTx` function
samholmes Jan 9, 2025
aebf68e
Factor out `processWyreTx` function
samholmes Jan 9, 2025
a635086
Factor out `processXanpoolTx` function
samholmes Jan 9, 2025
9e41364
Add direction and exchangeType to StandardTx
samholmes Jan 10, 2025
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: 21 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
{
}
"cSpell.words": [
"banxa",
"Bitrefill",
"Bity",
"Changelly",
"Faast",
"godex",
"Kado",
"Libertyx",
"Lifi",
"Paybis",
"Paytrie",
"Safello",
"Sideshift",
"Swapuz",
"Switchain",
"Transak",
"Wyre",
"Xanpool"
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"biggystring": "^4.1.3",
"body-parser": "^1.19.0",
"cleaner-config": "^0.1.10",
"cleaners": "^0.3.13",
"cleaners": "^0.3.17",
"commander": "^6.1.0",
"cors": "^2.8.5",
"csv-stringify": "^6.2.0",
Expand Down
14 changes: 12 additions & 2 deletions src/bin/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,12 @@ async function migration(): Promise<void> {
cleanedShapeshiftTx.timestamp * 1000
).toISOString(),
usdValue: -1,
rawTx: tx
rawTx: tx,
// IDK what to do here...
countryCode: null,
direction: null,
exchangeType: 'swap',
paymentType: null
}
return await standardTxReformat(
newTx,
Expand Down Expand Up @@ -196,7 +201,12 @@ async function migration(): Promise<void> {
isoDate,
timestamp,
usdValue: -1,
rawTx: undefined
rawTx: undefined,
// IDK what to do here...
countryCode: null,
direction: null,
exchangeType: 'swap',
paymentType: null
}
return await standardTxReformat(
newTx,
Expand Down
4 changes: 4 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ export const asConfig = asObject({
),
httpPort: asOptional(asNumber, 8008),
bog: asOptional(asObject({ apiKey: asString }), { apiKey: '' }),

/** Only run specific appIds (e.g. edge, coinhub, etc) */
soloAppIds: asOptional(asArray(asString), null),
/** Only run specific partnerIds (e.g. moonpay, paybis, etc) */
soloPartnerIds: asOptional(asArray(asString), null),

timeoutOverrideMins: asOptional(asNumber, 1200),
cacheLookbackMonths: asOptional(asNumber, 24)
})
Expand Down
148 changes: 103 additions & 45 deletions src/partners/banxa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Response } from 'node-fetch'

import {
EDGE_APP_START_DATE,
FiatPaymentType,
PartnerPlugin,
PluginParams,
PluginResult,
Expand All @@ -32,6 +33,7 @@ export const asBanxaParams = asObject({
})
})

type BanxaStatus = ReturnType<typeof asBanxaStatus>
const asBanxaStatus = asMaybe(
asValue(
'complete',
Expand All @@ -44,15 +46,18 @@ const asBanxaStatus = asMaybe(
'other'
)

type BanxaTx = ReturnType<typeof asBanxaTx>
const asBanxaTx = asObject({
id: asString,
status: asBanxaStatus,
created_at: asString,
country: asString,
fiat_amount: asNumber,
fiat_code: asString,
coin_amount: asNumber,
coin_code: asString,
order_type: asString,
payment_type: asString,
wallet_address: asMaybe(asString, '')
})

Expand All @@ -67,9 +72,6 @@ const PAGE_LIMIT = 100
const ONE_DAY_MS = 1000 * 60 * 60 * 24
const ROLLBACK = ONE_DAY_MS * 7 // 7 days

type BanxaTx = ReturnType<typeof asBanxaTx>
type BanxaStatus = ReturnType<typeof asBanxaStatus>

const statusMap: { [key in BanxaStatus]: Status } = {
complete: 'complete',
expired: 'expired',
Expand Down Expand Up @@ -202,61 +204,33 @@ async function fetchBanxaAPI(
return await retryFetch(`${partnerUrl}${apiQuery}`, { headers: headers })
}

function processBanxaOrders(rawtxs, ssFormatTxs): void {
function processBanxaOrders(
rawtxs: unknown[],
ssFormatTxs: StandardTx[]
): void {
let numComplete = 0
let newestIsoDate = new Date(0).toISOString()
let oldestIsoDate = new Date(9999999999999).toISOString()
for (const rawTx of rawtxs) {
let tx: BanxaTx
let standardTx: StandardTx
try {
tx = asBanxaTx(rawTx)
standardTx = processBanxaTx(rawTx)
} catch (e) {
datelog(String(e))
throw e
}
if (tx.status === 'complete') {
numComplete++
}
const { isoDate, timestamp } = smartIsoDateFromTimestamp(tx.created_at)

if (isoDate > newestIsoDate) {
newestIsoDate = isoDate
}
if (isoDate < oldestIsoDate) {
oldestIsoDate = isoDate
ssFormatTxs.push(standardTx)

if (standardTx.status === 'complete') {
numComplete++
}
// Flip the amounts if the order is a SELL
let payoutAddress
let inputAmount = tx.fiat_amount
let inputCurrency = tx.fiat_code
let outputAmount = tx.coin_amount
let outputCurrency = tx.coin_code
if (tx.order_type === 'CRYPTO-SELL') {
inputAmount = tx.coin_amount
inputCurrency = tx.coin_code
outputAmount = tx.fiat_amount
outputCurrency = tx.fiat_code
} else {
payoutAddress = tx.wallet_address
if (standardTx.isoDate > newestIsoDate) {
newestIsoDate = standardTx.isoDate
}

const ssTx: StandardTx = {
status: statusMap[tx.status],
orderId: tx.id,
depositTxid: undefined,
depositAddress: undefined,
depositCurrency: inputCurrency,
depositAmount: inputAmount,
payoutTxid: undefined,
payoutAddress,
payoutCurrency: outputCurrency,
payoutAmount: outputAmount,
timestamp,
isoDate,
usdValue: -1,
rawTx
if (standardTx.isoDate < oldestIsoDate) {
oldestIsoDate = standardTx.isoDate
}
ssFormatTxs.push(ssTx)
}
if (rawtxs.length > 1) {
datelog(
Expand All @@ -271,3 +245,87 @@ function processBanxaOrders(rawtxs, ssFormatTxs): void {
datelog(`BANXA: Processed ${rawtxs.length}`)
}
}

export function processBanxaTx(rawTx: unknown): StandardTx {
const banxaTx: BanxaTx = asBanxaTx(rawTx)
const { isoDate, timestamp } = smartIsoDateFromTimestamp(banxaTx.created_at)

// Flip the amounts if the order is a SELL
let payoutAddress
let inputAmount = banxaTx.fiat_amount
let inputCurrency = banxaTx.fiat_code
let outputAmount = banxaTx.coin_amount
let outputCurrency = banxaTx.coin_code
if (banxaTx.order_type === 'CRYPTO-SELL') {
inputAmount = banxaTx.coin_amount
inputCurrency = banxaTx.coin_code
outputAmount = banxaTx.fiat_amount
outputCurrency = banxaTx.fiat_code
} else {
payoutAddress = banxaTx.wallet_address
}

const direction = banxaTx.order_type === 'CRYPTO-SELL' ? 'sell' : 'buy'

const paymentType = getFiatPaymentType(banxaTx)

const standardTx: StandardTx = {
status: statusMap[banxaTx.status],
orderId: banxaTx.id,
countryCode: banxaTx.country,
depositTxid: undefined,
depositAddress: undefined,
depositCurrency: inputCurrency,
depositAmount: inputAmount,
direction,
exchangeType: 'fiat',
paymentType,
payoutTxid: undefined,
payoutAddress,
payoutCurrency: outputCurrency,
payoutAmount: outputAmount,
timestamp,
isoDate,
usdValue: -1,
rawTx
}

return standardTx
}

function getFiatPaymentType(tx: BanxaTx): FiatPaymentType {
switch (tx.payment_type) {
case 'AusPost Retail':
case 'BPay':
case 'Blueshyft Online':
case 'POLi Transfer':
case 'Sofort Transfer':
return 'directtobank'
case 'Checkout Credit Card':
case 'WorldPay Credit Card':
return 'credit'
case 'ClearJunction Fast Pay':
case 'ClearJunction Sell Fast Pay':
return 'fasterpayments'
case 'ClearJunction Sepa':
case 'Ten31 Sepa':
return 'sepa'
case 'DCBank Interac':
case 'DCBank Interac Sell':
return 'interac'
case 'Enumis Transfer':
return 'wire'
case 'Monoova Sell':
case 'NPP PayID':
case 'PayID via Monoova':
return 'payid'
case 'WorldPay ApplePay':
return 'applepay'
case 'WorldPay GooglePay':
return 'googlepay'
case 'iDEAL Transfer':
return 'ideal'
default:
throw new Error(`Unknown payment method: ${tx.payment_type} for ${tx.id}`)
}
}
Loading