Support ZEC

This commit is contained in:
Josh Harvey 2017-06-24 01:33:10 +03:00
parent 9b51565303
commit 45e6e2b82d
10 changed files with 105 additions and 47 deletions

View file

@ -155,27 +155,34 @@ function fetchData () {
return machineLoader.getMachineNames()
.then(machineList => ({
currencies: massageCurrencies(currencies),
cryptoCurrencies: [{crypto: 'BTC', display: 'Bitcoin'}, {crypto: 'ETH', display: 'Ethereum'}],
cryptoCurrencies: [
{crypto: 'BTC', display: 'Bitcoin'},
{crypto: 'ETH', display: 'Ethereum'},
{crypto: 'ZEC', display: 'Zcash'}
],
languages: languages,
countries,
accounts: [
{code: 'bitpay', display: 'Bitpay', class: 'ticker', cryptos: ['BTC']},
{code: 'kraken', display: 'Kraken', class: 'ticker', cryptos: ['BTC', 'ETH']},
{code: 'kraken', display: 'Kraken', class: 'ticker', cryptos: ['BTC', 'ETH', 'ZEC']},
{code: 'bitstamp', display: 'Bitstamp', class: 'ticker', cryptos: ['BTC']},
{code: 'coinbase', display: 'Coinbase', class: 'ticker', cryptos: ['BTC', 'ETH']},
{code: 'bitcoind', display: 'bitcoind', class: 'wallet', cryptos: ['BTC']},
{code: 'bitgo', display: 'BitGo', class: 'wallet', cryptos: ['BTC']},
{code: 'geth', display: 'geth', class: 'wallet', cryptos: ['ETH']},
{code: 'mock-wallet', display: 'Mock wallet', class: 'wallet', cryptos: ['BTC', 'ETH']},
{code: 'no-exchange', display: 'No exchange', class: 'exchange', cryptos: ['BTC', 'ETH']},
{code: 'mock-exchange', display: 'Mock exchange', class: 'exchange', cryptos: ['BTC', 'ETH']},
{code: 'zcashd', display: 'zcashd', class: 'wallet', cryptos: ['ZEC']},
{code: 'bitstamp', display: 'Bitstamp', class: 'exchange', cryptos: ['BTC']},
{code: 'kraken', display: 'Kraken', class: 'exchange', cryptos: ['BTC', 'ETH', 'ZEC']},
{code: 'mock-wallet', display: 'Mock wallet', class: 'wallet', cryptos: ['BTC', 'ETH', 'ZEC']},
{code: 'no-exchange', display: 'No exchange', class: 'exchange', cryptos: ['BTC', 'ETH', 'ZEC']},
{code: 'mock-exchange', display: 'Mock exchange', class: 'exchange', cryptos: ['BTC', 'ETH', 'ZEC']},
{code: 'mock-sms', display: 'Mock SMS', class: 'sms'},
{code: 'mock-id-verify', display: 'Mock ID verifier', class: 'idVerifier'},
{code: 'twilio', display: 'Twilio', class: 'sms'},
{code: 'mailjet', display: 'Mailjet', class: 'email'},
{code: 'all-zero-conf', display: 'All pass', class: 'zeroConf'},
{code: 'blockcypher', display: 'Blockcypher', class: 'zeroConf', cryptos: ['BTC']},
{code: 'mock-zero-conf', display: 'Mock 0-conf', class: 'zeroConf', cryptos: ['BTC']}
{code: 'mock-zero-conf', display: 'Mock 0-conf', class: 'zeroConf', cryptos: ['BTC', 'ZEC']}
],
machines: machineList.map(machine => ({machine: machine.deviceId, display: machine.name}))
}))

View file

@ -1,19 +1,28 @@
const coins = {
BTC: {unitScale: 8},
ETH: {unitScale: 18}
ETH: {unitScale: 18},
ZEC: {unitScale: 8}
}
const cryptoDisplays = [
{cryptoCode: 'BTC', display: 'Bitcoin'},
{cryptoCode: 'ETH', display: 'Ethereum'}
{cryptoCode: 'ETH', display: 'Ethereum'},
{cryptoCode: 'ZEC', display: 'Zcash'}
]
module.exports = {coins, cryptoDisplays, buildUrl}
module.exports = {coins, cryptoDisplays, buildUrl, unitScale}
function buildUrl (cryptoCode, address) {
switch (cryptoCode) {
case 'BTC': return `bitcoin:${address}`
case 'ETH': return `ethereum:${address}`
case 'ZEC': return `zcash:${address}`
default: throw new Error(`Unsupported crypto: ${cryptoCode}`)
}
}
function unitScale (cryptoCode) {
const scaleRec = coins[cryptoCode]
if (!scaleRec) throw new Error(`Unsupported crypto: ${cryptoCode}`)
return scaleRec.unitScale
}

View file

@ -1,17 +1,27 @@
var BigNumber = require('bignumber.js')
const BigNumber = require('bignumber.js')
var TEN = new BigNumber(10)
const coinUtils = require('../../coin-utils')
var UNIT_SCALES = {
BTC: 8,
ETH: 18
const TEN = new BigNumber(10)
const PAIRS = {
BTC: {
USD: 'XXBTZUSD',
EUR: 'XXBTZEUR'
},
ETH: {
USD: 'XETHZUSD',
EUR: 'XETHZEUR'
},
ZEC: {
USD: 'XZECZUSD',
EUR: 'XZECZEUR'
}
}
function unitScale (cryptoCoin) {
return UNIT_SCALES[cryptoCoin]
}
module.exports = {PAIRS, toUnit}
exports.toUnit = function toUnit (cryptoAtoms, cryptoCoin) {
var scale = TEN.pow(unitScale(cryptoCoin))
function toUnit (cryptoAtoms, cryptoCoin) {
var scale = TEN.pow(coinUtils.unitScale(cryptoCoin))
return cryptoAtoms.div(scale)
}

View file

@ -1,16 +1,7 @@
const Kraken = require('kraken-api')
const coinmath = require('../common/kraken')
const common = require('../common/kraken')
var PAIRS = {
BTC: {
USD: 'XXBTZUSD',
EUR: 'XXBTZEUR'
},
ETH: {
USD: 'XETHZUSD',
EUR: 'XETHZEUR'
}
}
var PAIRS = common.PAIRS
module.exports = {buy, sell}
@ -23,8 +14,8 @@ function sell (account, cryptoAtoms, fiatCode, cryptoCode) {
}
function trade (account, type, cryptoAtoms, fiatCode, cryptoCode) {
const kraken = new Kraken(account.key, account.secret)
const amount = coinmath.toUnit(cryptoAtoms, cryptoCode)
const kraken = new Kraken(account.apiKey, account.privateKey)
const amount = common.toUnit(cryptoAtoms, cryptoCode)
if (amount.lte('0.01')) {
const err = new Error('Order size too small')

View file

@ -2,20 +2,12 @@ const axios = require('axios')
const _ = require('lodash/fp')
const BN = require('../../../bn')
const common = require('../../common/kraken')
exports.NAME = 'Kraken'
exports.SUPPORTED_MODULES = ['ticker']
const PAIRS = {
BTC: {
USD: 'XXBTZUSD',
EUR: 'XXBTZEUR'
},
ETH: {
USD: 'XETHZUSD',
EUR: 'XETHZEUR'
}
}
const PAIRS = common.PAIRS
function findCurrency (fxRates, fiatCode) {
const rates = _.find(_.matchesProperty('code', fiatCode), fxRates)

View file

@ -15,6 +15,7 @@ function balance (account, cryptoCode) {
.then(() => {
if (cryptoCode === 'BTC') return BN(1e8 * 10)
if (cryptoCode === 'ETH') return BN(1e18 * 10)
if (cryptoCode === 'ZEC') return BN(1e8 * 10)
throw new Error('Unsupported crypto: ' + cryptoCode)
})
}
@ -24,6 +25,7 @@ function pendingBalance (account, cryptoCode) {
.then(() => {
if (cryptoCode === 'BTC') return BN(1e8 * 10.1)
if (cryptoCode === 'ETH') return BN(1e18 * 10.1)
if (cryptoCode === 'ZEC') return BN(1e8 * 10.1)
throw new Error('Unsupported crypto: ' + cryptoCode)
})
}
@ -33,16 +35,18 @@ function confirmedBalance (account, cryptoCode) {
.then(() => {
if (cryptoCode === 'BTC') return BN(1e8 * 10)
if (cryptoCode === 'ETH') return BN(1e18 * 10)
if (cryptoCode === 'ZEC') return BN(1e8 * 10)
throw new Error('Unsupported crypto: ' + cryptoCode)
})
}
// Note: This makes it easier to test insufficient funds errors
let sendCount = 0
let sendCount = 100
function isInsufficient (cryptoAtoms, cryptoCode) {
if (cryptoCode === 'BTC') return cryptoAtoms.gt(1e5 * 10 * sendCount)
if (cryptoCode === 'ETH') return cryptoAtoms.gt(1e18 * 0.25 * sendCount)
if (cryptoCode === 'ZEC') return cryptoAtoms.gt(1e5 * 0.25 * sendCount)
throw new Error('Unsupported crypto: ' + cryptoCode)
}