Skip to content

Commit 96bc023

Browse files
committed
Add country, direction, and exchangeType to StandardTx
1 parent edfeb19 commit 96bc023

36 files changed

+679
-41
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"cSpell.words": [
3+
"banxa",
34
"Bitrefill",
45
"Bity",
56
"Changelly",

src/partners/banxa.ts

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Response } from 'node-fetch'
1313

1414
import {
1515
EDGE_APP_START_DATE,
16+
FiatPaymentType,
1617
PartnerPlugin,
1718
PluginParams,
1819
PluginResult,
@@ -32,6 +33,7 @@ export const asBanxaParams = asObject({
3233
})
3334
})
3435

36+
type BanxaStatus = ReturnType<typeof asBanxaStatus>
3537
const asBanxaStatus = asMaybe(
3638
asValue(
3739
'complete',
@@ -44,15 +46,18 @@ const asBanxaStatus = asMaybe(
4446
'other'
4547
)
4648

49+
type BanxaTx = ReturnType<typeof asBanxaTx>
4750
const asBanxaTx = asObject({
4851
id: asString,
4952
status: asBanxaStatus,
5053
created_at: asString,
54+
country: asString,
5155
fiat_amount: asNumber,
5256
fiat_code: asString,
5357
coin_amount: asNumber,
5458
coin_code: asString,
5559
order_type: asString,
60+
payment_type: asString,
5661
wallet_address: asMaybe(asString, '')
5762
})
5863

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

70-
type BanxaTx = ReturnType<typeof asBanxaTx>
71-
type BanxaStatus = ReturnType<typeof asBanxaStatus>
72-
7375
const statusMap: { [key in BanxaStatus]: Status } = {
7476
complete: 'complete',
7577
expired: 'expired',
@@ -263,13 +265,21 @@ export function processBanxaTx(rawTx: unknown): StandardTx {
263265
payoutAddress = banxaTx.wallet_address
264266
}
265267

268+
const direction = banxaTx.order_type === 'CRYPTO-SELL' ? 'sell' : 'buy'
269+
270+
const paymentType = getFiatPaymentType(banxaTx)
271+
266272
const standardTx: StandardTx = {
267273
status: statusMap[banxaTx.status],
268274
orderId: banxaTx.id,
275+
countryCode: banxaTx.country,
269276
depositTxid: undefined,
270277
depositAddress: undefined,
271278
depositCurrency: inputCurrency,
272279
depositAmount: inputAmount,
280+
direction,
281+
exchangeType: 'fiat',
282+
paymentType,
273283
payoutTxid: undefined,
274284
payoutAddress,
275285
payoutCurrency: outputCurrency,
@@ -282,3 +292,45 @@ export function processBanxaTx(rawTx: unknown): StandardTx {
282292

283293
return standardTx
284294
}
295+
296+
function getFiatPaymentType(tx: BanxaTx): FiatPaymentType {
297+
switch (tx.payment_type) {
298+
case 'AusPost Retail':
299+
return 'auspost'
300+
case 'BPay':
301+
return 'bpay'
302+
case 'Blueshyft Online':
303+
return 'blueshyft'
304+
case 'POLi Transfer':
305+
return 'poli'
306+
case 'Sofort Transfer':
307+
return 'sofort'
308+
case 'Checkout Credit Card':
309+
case 'WorldPay Credit Card':
310+
return 'credit'
311+
case 'ClearJunction Fast Pay':
312+
case 'ClearJunction Sell Fast Pay':
313+
return 'fasterpayments'
314+
case 'ClearJunction Sepa':
315+
case 'Ten31 Sepa':
316+
return 'sepa'
317+
case 'DCBank Interac':
318+
case 'DCBank Interac Sell':
319+
return 'interac'
320+
case 'Enumis Transfer':
321+
return 'fasterpayments'
322+
case 'Monoova Sell':
323+
return 'banktransfer'
324+
case 'NPP PayID':
325+
case 'PayID via Monoova':
326+
return 'payid'
327+
case 'WorldPay ApplePay':
328+
return 'applepay'
329+
case 'WorldPay GooglePay':
330+
return 'googlepay'
331+
case 'iDEAL Transfer':
332+
return 'ideal'
333+
default:
334+
throw new Error(`Unknown payment method: ${tx.payment_type} for ${tx.id}`)
335+
}
336+
}

src/partners/bitaccess.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
asObject,
55
asOptional,
66
asString,
7-
asUnknown
7+
asUnknown,
8+
asValue
89
} from 'cleaners'
910
import crypto from 'crypto'
1011
import fetch from 'node-fetch'
@@ -13,11 +14,13 @@ import { PartnerPlugin, PluginParams, PluginResult, StandardTx } from '../types'
1314
import { datelog } from '../util'
1415

1516
const asBitaccessTx = asObject({
17+
trade_type: asValue<['buy', 'sell']>('buy', 'sell'),
1618
transaction_id: asString,
1719
tx_hash: asOptional(asString),
1820
deposit_address: asString,
1921
deposit_currency: asString,
2022
deposit_amount: asNumber,
23+
location_address: asString,
2124
withdrawal_address: asOptional(asString),
2225
withdrawal_currency: asString,
2326
withdrawal_amount: asNumber,
@@ -132,13 +135,19 @@ export function processBitaccessTx(rawTx: unknown): StandardTx {
132135
payoutTxid = tx.tx_hash
133136
}
134137

138+
const countryCode = parseLocationAddressForCountryCode(tx.location_address)
139+
135140
const standardTx: StandardTx = {
136141
status: 'complete',
137142
orderId: tx.transaction_id,
143+
countryCode,
138144
depositTxid,
139145
depositAddress: tx.deposit_address,
140146
depositCurrency: tx.deposit_currency.toUpperCase(),
141147
depositAmount: tx.deposit_amount,
148+
direction: tx.trade_type,
149+
exchangeType: 'fiat',
150+
paymentType: 'cash',
142151
payoutTxid,
143152
payoutAddress: tx.withdrawal_address,
144153
payoutCurrency: tx.withdrawal_currency.toUpperCase(),
@@ -150,3 +159,11 @@ export function processBitaccessTx(rawTx: unknown): StandardTx {
150159
}
151160
return standardTx
152161
}
162+
163+
function parseLocationAddressForCountryCode(location: string): string {
164+
const parts = location.split(', ')
165+
if (parts.length !== 4 || parts[3].length > 3) {
166+
throw new Error(`Unexpected location address: ${location}`)
167+
}
168+
return parts[3]
169+
}

src/partners/bitrefill.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const asBitrefillTx = asObject({
2121
satoshiPrice: asOptional(asNumber),
2222
value: asString,
2323
currency: asString,
24+
country: asString,
2425
coinCurrency: asString,
2526
receivedPaymentAltcoin: asOptional(asNumber),
2627
orderId: asString,
@@ -146,10 +147,14 @@ export function processBitrefillTx(rawTx: unknown): StandardTx {
146147
const standardTx: StandardTx = {
147148
status: 'complete',
148149
orderId: tx.orderId,
150+
countryCode: tx.country.toUpperCase(),
149151
depositTxid: undefined,
150152
depositAddress: undefined,
151153
depositCurrency: inputCurrency,
152154
depositAmount,
155+
direction: 'sell',
156+
exchangeType: 'fiat',
157+
paymentType: 'giftcard',
153158
payoutTxid: undefined,
154159
payoutAddress: undefined,
155160
payoutCurrency: tx.currency,

src/partners/bitsofgold.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { asArray, asNumber, asObject, asString, asUnknown } from 'cleaners'
1+
import {
2+
asArray,
3+
asMaybe,
4+
asNumber,
5+
asObject,
6+
asString,
7+
asUnknown,
8+
asValue
9+
} from 'cleaners'
210
import fetch from 'node-fetch'
311

412
import { PartnerPlugin, PluginParams, PluginResult, StandardTx } from '../types'
@@ -106,13 +114,23 @@ export function processBitsOfGoldTx(rawTx: unknown): StandardTx {
106114
payoutAmount = data.fiat_amount
107115
}
108116

117+
const direction = asMaybe(asValue('buy', 'sell'), undefined)(bogTx.type)
118+
119+
if (direction == null) {
120+
throw new Error(`Invalid direction ${bogTx.type}`)
121+
}
122+
109123
const standardTx: StandardTx = {
110124
status: 'complete',
111125
orderId: bogTx.id,
126+
countryCode: null,
112127
depositTxid: undefined,
113128
depositAddress: undefined,
114129
depositCurrency,
115130
depositAmount,
131+
direction,
132+
exchangeType: 'fiat',
133+
paymentType: data.fiat_type === 'ILS' ? 'israelibank' : 'sepa',
116134
payoutTxid: undefined,
117135
payoutAddress: undefined,
118136
payoutCurrency,

src/partners/bity.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,29 @@ export const bity: PartnerPlugin = {
158158
export function processBityTx(rawTx: unknown): StandardTx {
159159
const tx = asBityTx(rawTx)
160160

161+
// Assume that one currency is EUR and that's the only fiat currency supported
162+
// by Bity.
163+
if (
164+
tx.input.currency.toUpperCase() !== 'EUR' &&
165+
tx.output.currency.toUpperCase() !== 'EUR'
166+
) {
167+
throw new Error(
168+
`Unknown fiat currency ${tx.input.currency} or ${tx.output.currency}`
169+
)
170+
}
171+
const direction = tx.input.currency.toUpperCase() === 'EUR' ? 'buy' : 'sell'
172+
161173
const standardTx: StandardTx = {
162174
status: 'complete',
163175
orderId: tx.id,
176+
countryCode: null,
164177
depositTxid: undefined,
165178
depositAddress: undefined,
166179
depositCurrency: tx.input.currency.toUpperCase(),
167180
depositAmount: safeParseFloat(tx.input.amount),
181+
direction,
182+
exchangeType: 'fiat',
183+
paymentType: 'sepa',
168184
payoutTxid: undefined,
169185
payoutAddress: undefined,
170186
payoutCurrency: tx.output.currency.toUpperCase(),

src/partners/changehero.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,14 @@ export function processChangeHeroTx(rawTx: unknown): StandardTx {
164164
const standardTx: StandardTx = {
165165
status: statusMap[tx.status],
166166
orderId: tx.id,
167+
countryCode: null,
167168
depositTxid: tx.payinHash,
168169
depositAddress: tx.payinAddress,
169170
depositCurrency: tx.currencyFrom.toUpperCase(),
170171
depositAmount: safeParseFloat(tx.amountFrom),
172+
direction: null,
173+
exchangeType: 'swap',
174+
paymentType: null,
171175
payoutTxid: tx.payoutHash,
172176
payoutAddress: tx.payoutAddress,
173177
payoutCurrency: tx.currencyTo.toUpperCase(),

src/partners/changelly.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,14 @@ export function processChangellyTx(rawTx: unknown): StandardTx {
176176
const standardTx: StandardTx = {
177177
status: 'complete',
178178
orderId: tx.id,
179+
countryCode: null,
179180
depositTxid: tx.payinHash,
180181
depositAddress: tx.payinAddress,
181182
depositCurrency: tx.currencyFrom.toUpperCase(),
182183
depositAmount: safeParseFloat(tx.amountFrom),
184+
direction: null,
185+
exchangeType: 'swap',
186+
paymentType: null,
183187
payoutTxid: tx.payoutHash,
184188
payoutAddress: tx.payoutAddress,
185189
payoutCurrency: tx.currencyTo.toUpperCase(),

src/partners/changenow.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,14 @@ export function processChangeNowTx(rawTx: unknown): StandardTx {
147147
const standardTx: StandardTx = {
148148
status: statusMap[tx.status],
149149
orderId: tx.requestId,
150+
countryCode: null,
150151
depositTxid: tx.payin.hash,
151152
depositAddress: tx.payin.address,
152153
depositCurrency: tx.payin.currency.toUpperCase(),
153154
depositAmount: tx.payin.amount ?? tx.payin.expectedAmount ?? 0,
155+
direction: null,
156+
exchangeType: 'swap',
157+
paymentType: null,
154158
payoutTxid: tx.payout.hash,
155159
payoutAddress: tx.payout.address,
156160
payoutCurrency: tx.payout.currency.toUpperCase(),

src/partners/coinswitch.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,14 @@ export function processCoinSwitchTx(rawTx: unknown): StandardTx {
112112
const standardTx: StandardTx = {
113113
status: 'complete',
114114
orderId: tx.orderId,
115+
countryCode: null,
115116
depositTxid,
116117
depositAddress: tx.exchangeAddress.address,
117118
depositCurrency: tx.depositCoin.toUpperCase(),
118119
depositAmount: tx.depositCoinAmount,
120+
direction: null,
121+
exchangeType: 'swap',
122+
paymentType: null,
119123
payoutTxid,
120124
payoutAddress: tx.destinationAddress.address,
121125
payoutCurrency: tx.destinationCoin.toUpperCase(),

0 commit comments

Comments
 (0)