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 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 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
1db8d3d
Fix bitsofgold payoutAmount
samholmes Feb 18, 2025
e11585b
Fix QUERY_LOOKBACK units
samholmes Feb 18, 2025
6c04130
fixup! Factor out `processKadoTx` function
samholmes Feb 18, 2025
8950ed8
fixup! Add direction and exchangeType to StandardTx
samholmes Feb 18, 2025
85c85d1
fixup! Factor out processLifiTx function
samholmes Feb 18, 2025
32e7e5a
Fix rawTx for kado and lifi
samholmes Feb 18, 2025
28efd5f
Add sell direction to moonpay
samholmes Feb 18, 2025
8ed90e2
Include related rawTxs for thorchain
samholmes Feb 18, 2025
575027c
fixup! Add direction and exchangeType to StandardTx
samholmes Feb 18, 2025
ce82950
Remove deprecated migration.ts
samholmes Feb 18, 2025
d5c35f6
fixup! Add direction and exchangeType to StandardTx
samholmes Feb 18, 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
Prev Previous commit
Next Next commit
Factor out processBitrefillTx function
  • Loading branch information
samholmes committed Jan 8, 2025
commit 09ee5f901ed67d0ced91cb70243e6ccd7f4cf787
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{
}
"cSpell.words": ["Bitrefill"]
}
93 changes: 52 additions & 41 deletions src/partners/bitrefill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ const asBitrefillTx = asObject({
usdPrice: asNumber
})

const asRawBitrefillTx = asObject({
// Partial type for Bitrefill txs for pre-processing
const asPreBitrefillTx = asObject({
expired: asBoolean,
paymentReceived: asBoolean,
sent: asBoolean,
status: asString
})

Expand Down Expand Up @@ -66,7 +70,7 @@ export async function queryBitrefill(
Authorization:
'Basic ' + Buffer.from(username + ':' + password).toString('base64')
}
const ssFormatTxs: StandardTx[] = []
const standardTxs: StandardTx[] = []

let url = `https://api.bitrefill.com/v1/orders/`
let count = 0
Expand All @@ -83,46 +87,15 @@ export async function queryBitrefill(
break
}
const txs = jsonObj.orders
for (const rawtx of txs) {
if (asRawBitrefillTx(rawtx).status === 'unpaid') {
for (const rawTx of txs) {
// Pre-process the tx to see if it's meets criteria for inclusion:
const preTx = asPreBitrefillTx(rawTx)
if (preTx.status === 'unpaid') {
continue
}
const tx = asBitrefillTx(rawtx)
if (tx.paymentReceived && !tx.expired && tx.sent) {
const timestamp = tx.invoiceTime / 1000

let inputAmountStr = tx.satoshiPrice?.toString()
const inputCurrency: string = tx.coinCurrency.toUpperCase()
if (typeof multipliers[inputCurrency] !== 'string') {
datelog(inputCurrency + ' has no multipliers')
break
}
if (typeof inputCurrency === 'string' && inputCurrency !== 'BTC') {
inputAmountStr = tx.receivedPaymentAltcoin?.toString()
}
if (inputAmountStr == null) {
break
}
const inputAmountNum = safeParseFloat(
div(inputAmountStr, multipliers[inputCurrency], 8)
)
const ssTx: StandardTx = {
status: 'complete',
orderId: tx.orderId,
depositTxid: undefined,
depositAddress: undefined,
depositCurrency: inputCurrency,
depositAmount: inputAmountNum,
payoutTxid: undefined,
payoutAddress: undefined,
payoutCurrency: tx.currency,
payoutAmount: parseInt(tx.value),
timestamp,
isoDate: new Date(tx.invoiceTime).toISOString(),
usdValue: tx.usdPrice,
rawTx: rawtx
}
ssFormatTxs.push(ssTx)
if (preTx.paymentReceived && !preTx.expired && preTx.sent) {
const standardTx = processBitrefillTx(rawTx)
standardTxs.push(standardTx)
}
}

Expand All @@ -139,7 +112,7 @@ export async function queryBitrefill(
}
const out: PluginResult = {
settings: {},
transactions: ssFormatTxs
transactions: standardTxs
}
return out
}
Expand All @@ -151,3 +124,41 @@ export const bitrefill: PartnerPlugin = {
pluginName: 'Bitrefill',
pluginId: 'bitrefill'
}

export function processBitrefillTx(rawTx: unknown): StandardTx {
const tx = asBitrefillTx(rawTx)
const timestamp = tx.invoiceTime / 1000

const inputCurrency: string = tx.coinCurrency.toUpperCase()
if (typeof multipliers[inputCurrency] !== 'string') {
throw new Error(inputCurrency + ' has no multipliers')
}
let depositAmountStr = tx.satoshiPrice?.toString()
if (typeof inputCurrency === 'string' && inputCurrency !== 'BTC') {
depositAmountStr = tx.receivedPaymentAltcoin?.toString()
}
if (depositAmountStr == null) {
throw new Error(`Missing depositAmount for tx: ${tx.orderId}`)
}
const depositAmount = safeParseFloat(
div(depositAmountStr, multipliers[inputCurrency], 8)
)
const standardTx: StandardTx = {
status: 'complete',
orderId: tx.orderId,
depositTxid: undefined,
depositAddress: undefined,
depositCurrency: inputCurrency,
depositAmount,
payoutTxid: undefined,
payoutAddress: undefined,
payoutCurrency: tx.currency,
payoutAmount: parseInt(tx.value),
timestamp,
isoDate: new Date(tx.invoiceTime).toISOString(),
usdValue: tx.usdPrice,
rawTx
}

return standardTx
}