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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- `yarn build` or `npm run build`
- Rename `config.json.sample` to `config.json` and enter relevant API keys
- If only interested in submitting your own exchange reporting plugin:
- Come up with a prefix for your organization (eg ShapeShift = "SS", "BitRefill" = "BR"), and create a [prefix]Raw.json file in the `cache` folder and enter an empty object.
- Come up with a prefix for your organization (eg ShapeShift = "SS", "BitRefill" = "BR"), and create a [prefix]Raw.json file in the `cache` folder and enter an object with an empty `"txs": []` array.
- In the `src` folder create a file `myOrganization.js` with the code to fetch transactions from your API and format transactions to match the `StandardTx` type (can view in `checkSwapService.js` file)
- In `reporter.js` import the transaction fetching procedure from your `myOrganization.js` file and include near the top of the `main` function. Also make sure you have your organization's transactions printed out with `printTxDataMap` in the `report` method (in `reporter.js`).
- When in doubt, look at how other teams have implemented their reporting procedure. If you have any further questions please feel free to reach out to the Edge team at our `dev` Slack channel:
Expand Down
4 changes: 3 additions & 1 deletion config.json.sample
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@
"switchainApiKey" : "",
"transak_api_secret": "xxx",
"coinMarketCapExcludeLookup": ["USD", "EUR", "GBP"],
"coinApiExcludeLookup": ["USD", "EUR", "GBP"]
"coinApiExcludeLookup": ["USD", "EUR", "GBP"],
"sideShiftAffiliateId": "",
"sideShiftAffiliateSecret": ""
}
15 changes: 15 additions & 0 deletions src/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const { doBanxa } = require('./banxa.js')
const { doBity } = require('./bity.js')
const { doSwitchain } = require('./switchain.js')
const { doPaytrie } = require('./paytrie.js')
const { doSideShift } = require('./sideshift.js')
const { bns } = require('biggystring')
const config = require('../config.json')
const { sprintf } = require('sprintf-js')
Expand All @@ -45,6 +46,10 @@ async function main (swapFuncParams: SwapFuncParams) {
console.error('doShapeShift failed')
return {}
})
const rXai = await doSideShift(swapFuncParams).catch(e => {
console.error('doSideShift failed')
return {}
})
const rLbx = await doLibertyX(swapFuncParams).catch(e => {
console.error('doLibertyX failed')
return {}
Expand Down Expand Up @@ -116,6 +121,7 @@ async function main (swapFuncParams: SwapFuncParams) {
printTxDataMap('CHA', rCha)
printTxDataMap('FAA', rFaa)
printTxDataMap('SSH', rSsh)
printTxDataMap('XAI', rXai)
printTxDataMap('LBX', rLbx)
printTxDataMap('BIT', rBit)
printTxDataMap('TOT', rTl)
Expand Down Expand Up @@ -274,6 +280,9 @@ async function report (argv: Array<any>) {
const ssResults = config.shapeShiftToken
? await doSummaryFunction(doShapeShift)
: {}
const xaiResults = config.sideShiftAffiliateId
? await doSummaryFunction(doSideShift)
: {}
const faResults = config.faastAffiliateId
? await doSummaryFunction(doFaast)
: {}
Expand Down Expand Up @@ -329,6 +338,7 @@ async function report (argv: Array<any>) {
combineResults(results, chResults)
combineResults(results, faResults)
combineResults(results, ssResults)
combineResults(results, xaiResults)
combineResults(results, tlResults)
combineResults(results, foxResults)
combineResults(results, csResults)
Expand Down Expand Up @@ -360,6 +370,11 @@ async function report (argv: Array<any>) {
console.log('\n***** Shapeshift Monthly *****')
printTxDataMap('SSH', ssResults.monthly)

console.log('\n***** SideShift.ai Daily *****')
printTxDataMap('XAI', xaiResults.daily)
console.log('\n***** SideShift.ai Monthly *****')
printTxDataMap('XAI', xaiResults.monthly)

console.log('\n***** Coinswitch Daily *****')
printTxDataMap('CS', csResults.daily)
console.log('\n***** Coinswitch Monthly *****')
Expand Down
104 changes: 104 additions & 0 deletions src/sideshift.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// @flow

import type {StandardTx, SwapFuncParams} from './checkSwapService'

const {checkSwapService} = require('./checkSwapService.js')
const js = require('jsonfile')
const fetch = require('node-fetch')
const crypto = require('crypto')

const confFileName = './config.json'
const config = js.readFileSync(confFileName)

const SIDESHIFT_CACHE = './cache/xaiRaw.json'
const PAGE_LIMIT = 500
const TRANSACTIONS_TO_FETCH = 1500

type SideShiftTransaction = {
id: string,
depositAddress: {
address: string
},
depositAsset: string,
depositMin: number,
depositMax: number,
settleAddress: {
address: string
},
settleAsset: string,
settleAmount: number,
createdAt: string
}

async function doSideShift (swapFuncParams: SwapFuncParams) {
return checkSwapService(fetchSideShift,
SIDESHIFT_CACHE,
'XAI',
swapFuncParams)
}

function affiliateSignature (affiliateId: string, affiliateSecret: string, time: number): string {
return crypto.createHmac('sha1', affiliateSecret)
.update(affiliateId + time)
.digest('hex')
}

async function fetchSideShift (swapFuncParams: SwapFuncParams) {
if (!swapFuncParams.useCache) {
console.log('Fetching SideShift.ai...')
}
let diskCache = {txs: []}
try {
diskCache = js.readFileSync(SIDESHIFT_CACHE)
} catch (e) {
console.log(e)
}

const newTransactions: StandardTx[] = []
let offset = 0

while (1 && !swapFuncParams.useCache) {
const time = Date.now()
const signature = affiliateSignature(config.sideShiftAffiliateId, config.sideShiftAffiliateSecret, time)

try {
const url = `https://sideshift.ai/api/affiliate/completedOrders?limit=${PAGE_LIMIT}&offset=${offset}&affiliateId=${config.sideShiftAffiliateId}&time=${time}&signature=${signature}`
const transactions: SideShiftTransaction[] = await fetch(url)
.then(response => response.json())

for (const tx of transactions) {
const timestamp = new Date(tx.createdAt).getTime() / 1000
const xaiTx: StandardTx = {
status: 'complete',
inputTXID: tx.id,
inputAddress: tx.depositAddress.address,
inputCurrency: tx.depositAsset.toUpperCase(),
inputAmount: tx.depositMin,
outputAddress: tx.settleAddress.address,
outputCurrency: tx.settleAsset.toUpperCase(),
outputAmount: tx.settleAmount.toString(),
timestamp
}
newTransactions.push(xaiTx)
}

if (transactions.length < PAGE_LIMIT) {
break
}
} catch (e) {
console.log(e)
break
}
if (offset > TRANSACTIONS_TO_FETCH) {
break
}
offset += PAGE_LIMIT
}

return {
diskCache,
newTransactions
}
}

module.exports = {doSideShift}