chore: replace imports to point to lamassu-coins module
This commit is contained in:
parent
70495deb67
commit
3423e2ddd0
30 changed files with 230 additions and 175 deletions
|
|
@ -4,7 +4,8 @@ const settingsLoader = require('./settings-loader')
|
|||
const configManager = require('./config-manager')
|
||||
const wallet = require('../wallet')
|
||||
const ticker = require('../ticker')
|
||||
const coinUtils = require('../coin-utils')
|
||||
const { utils } = require('lamassu-coins')
|
||||
// const coinUtils = require('../coin-utils')
|
||||
const machineLoader = require('../machine-loader')
|
||||
|
||||
module.exports = {getFunding}
|
||||
|
|
@ -40,14 +41,14 @@ function fetchMachines () {
|
|||
}
|
||||
|
||||
function computeCrypto (cryptoCode, _balance) {
|
||||
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
||||
const cryptoRec = utils.getCryptoCurrency(cryptoCode)
|
||||
const unitScale = cryptoRec.unitScale
|
||||
|
||||
return BN(_balance).shift(-unitScale).round(5)
|
||||
}
|
||||
|
||||
function computeFiat (rate, cryptoCode, _balance) {
|
||||
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
||||
const cryptoRec = utils.getCryptoCurrency(cryptoCode)
|
||||
const unitScale = cryptoRec.unitScale
|
||||
|
||||
return BN(_balance).shift(-unitScale).mul(rate).round(5)
|
||||
|
|
@ -61,9 +62,9 @@ function getFunding (_cryptoCode) {
|
|||
const cryptoCode = _cryptoCode || cryptoCodes[0]
|
||||
const fiatCode = config.fiatCurrency
|
||||
const pareCoins = c => _.includes(c.cryptoCode, cryptoCodes)
|
||||
const cryptoCurrencies = coinUtils.cryptoCurrencies()
|
||||
const cryptoCurrencies = utils.cryptoCurrencies()
|
||||
const cryptoDisplays = _.filter(pareCoins, cryptoCurrencies)
|
||||
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
||||
const cryptoRec = utils.getCryptoCurrency(cryptoCode)
|
||||
|
||||
if (!cryptoRec) throw new Error(`Unsupported coin: ${cryptoCode}`)
|
||||
|
||||
|
|
@ -81,7 +82,7 @@ function getFunding (_cryptoCode) {
|
|||
const pending = fundingRec.fundingPendingBalance
|
||||
const fiatPending = computeFiat(rate, cryptoCode, pending)
|
||||
const fundingAddress = fundingRec.fundingAddress
|
||||
const fundingAddressUrl = coinUtils.buildUrl(cryptoCode, fundingAddress)
|
||||
const fundingAddressUrl = utils.buildUrl(cryptoCode, fundingAddress)
|
||||
|
||||
return {
|
||||
cryptoCode,
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
const path = require('path')
|
||||
|
||||
const coinUtils = require('../coin-utils')
|
||||
const { utils } = require('lamassu-coins')
|
||||
// const coinUtils = require('../coin-utils')
|
||||
|
||||
const common = require('./common')
|
||||
|
||||
module.exports = {setup}
|
||||
|
||||
const coinRec = coinUtils.getCryptoCurrency('BTC')
|
||||
const coinRec = utils.getCryptoCurrency('BTC')
|
||||
|
||||
function setup (dataDir) {
|
||||
common.firewall([coinRec.defaultPort])
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
const path = require('path')
|
||||
|
||||
const coinUtils = require('../coin-utils')
|
||||
const { utils } = require('lamassu-coins')
|
||||
// const coinUtils = require('../coin-utils')
|
||||
|
||||
const common = require('./common')
|
||||
|
||||
module.exports = {setup}
|
||||
|
||||
const coinRec = coinUtils.getCryptoCurrency('BCH')
|
||||
const coinRec = utils.getCryptoCurrency('BCH')
|
||||
|
||||
function setup (dataDir) {
|
||||
common.firewall([coinRec.defaultPort])
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
const path = require('path')
|
||||
|
||||
const coinUtils = require('../coin-utils')
|
||||
const { utils } = require('lamassu-coins')
|
||||
// const coinUtils = require('../coin-utils')
|
||||
|
||||
const common = require('./common')
|
||||
|
||||
module.exports = {setup}
|
||||
|
||||
const coinRec = coinUtils.getCryptoCurrency('DASH')
|
||||
const coinRec = utils.getCryptoCurrency('DASH')
|
||||
|
||||
function setup (dataDir) {
|
||||
common.firewall([coinRec.defaultPort])
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
const coinUtils = require('../coin-utils')
|
||||
const { utils } = require('lamassu-coins')
|
||||
// const coinUtils = require('../coin-utils')
|
||||
|
||||
const common = require('./common')
|
||||
|
||||
module.exports = {setup}
|
||||
|
||||
function setup (dataDir) {
|
||||
const coinRec = coinUtils.getCryptoCurrency('ETH')
|
||||
const coinRec = utils.getCryptoCurrency('ETH')
|
||||
common.firewall([coinRec.defaultPort])
|
||||
const cmd = `/usr/local/bin/${coinRec.daemon} --datadir "${dataDir}" --syncmode="fast" --cache 2048 --maxpeers 40 --rpc`
|
||||
common.writeSupervisorConfig(coinRec, cmd)
|
||||
|
|
|
|||
|
|
@ -7,12 +7,13 @@ const makeDir = require('make-dir')
|
|||
const inquirer = require('inquirer')
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
const { utils } = require('lamassu-coins')
|
||||
const coinUtils = require('../coin-utils')
|
||||
|
||||
const common = require('./common')
|
||||
const doVolume = require('./do-volume')
|
||||
|
||||
const cryptos = coinUtils.cryptoCurrencies()
|
||||
const cryptos = utils.cryptoCurrencies()
|
||||
|
||||
const logger = common.logger
|
||||
|
||||
|
|
@ -28,7 +29,7 @@ const PLUGINS = {
|
|||
module.exports = {run}
|
||||
|
||||
function installedVolumeFilePath (crypto) {
|
||||
return path.resolve(coinUtils.cryptoDir(crypto), '.installed')
|
||||
return path.resolve(utils.cryptoDir(crypto, coinUtils.blockchainDir()), '.installed')
|
||||
}
|
||||
|
||||
function isInstalledVolume (crypto) {
|
||||
|
|
@ -73,7 +74,7 @@ function processCryptos (codes) {
|
|||
|
||||
function setupCrypto (crypto) {
|
||||
logger.info(`Installing ${crypto.display}...`)
|
||||
const cryptoDir = coinUtils.cryptoDir(crypto)
|
||||
const cryptoDir = utils.cryptoDir(crypto, coinUtils.blockchainDir())
|
||||
makeDir.sync(cryptoDir)
|
||||
const cryptoPlugin = plugin(crypto)
|
||||
const oldDir = process.cwd()
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
const path = require('path')
|
||||
|
||||
const coinUtils = require('../coin-utils')
|
||||
const { utils } = require('lamassu-coins')
|
||||
// const coinUtils = require('../coin-utils')
|
||||
|
||||
const common = require('./common')
|
||||
|
||||
module.exports = {setup}
|
||||
|
||||
const coinRec = coinUtils.getCryptoCurrency('LTC')
|
||||
const coinRec = utils.getCryptoCurrency('LTC')
|
||||
|
||||
function setup (dataDir) {
|
||||
common.firewall([coinRec.defaultPort])
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
const path = require('path')
|
||||
|
||||
const coinUtils = require('../coin-utils')
|
||||
const { utils } = require('lamassu-coins')
|
||||
// const coinUtils = require('../coin-utils')
|
||||
|
||||
const common = require('./common')
|
||||
|
||||
|
|
@ -12,7 +13,7 @@ const logger = common.logger
|
|||
function setup (dataDir) {
|
||||
es('sudo apt-get update')
|
||||
es('sudo apt-get install libgomp1 -y')
|
||||
const coinRec = coinUtils.getCryptoCurrency('ZEC')
|
||||
const coinRec = utils.getCryptoCurrency('ZEC')
|
||||
|
||||
common.firewall([coinRec.defaultPort])
|
||||
logger.info('Fetching Zcash proofs, will take a while...')
|
||||
|
|
|
|||
|
|
@ -1,111 +1,7 @@
|
|||
const path = require('path')
|
||||
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
const options = require('./options')
|
||||
|
||||
const CRYPTO_CURRENCIES = [
|
||||
{
|
||||
cryptoCode: 'BTC',
|
||||
display: 'Bitcoin',
|
||||
code: 'bitcoin',
|
||||
configFile: 'bitcoin.conf',
|
||||
daemon: 'bitcoind',
|
||||
defaultPort: 8332,
|
||||
unitScale: 8,
|
||||
displayScale: 5
|
||||
},
|
||||
{
|
||||
cryptoCode: 'ETH',
|
||||
display: 'Ethereum',
|
||||
code: 'ethereum',
|
||||
configFile: 'geth.conf',
|
||||
daemon: 'geth',
|
||||
defaultPort: 8545,
|
||||
unitScale: 18,
|
||||
displayScale: 15
|
||||
},
|
||||
{
|
||||
cryptoCode: 'LTC',
|
||||
display: 'Litecoin',
|
||||
code: 'litecoin',
|
||||
configFile: 'litecoin.conf',
|
||||
daemon: 'litecoind',
|
||||
defaultPort: 9332,
|
||||
unitScale: 8,
|
||||
displayScale: 5
|
||||
},
|
||||
{
|
||||
cryptoCode: 'DASH',
|
||||
display: 'Dash',
|
||||
code: 'dash',
|
||||
configFile: 'dash.conf',
|
||||
daemon: 'dashd',
|
||||
defaultPort: 9998,
|
||||
unitScale: 8,
|
||||
displayScale: 5
|
||||
},
|
||||
{
|
||||
cryptoCode: 'ZEC',
|
||||
display: 'Zcash',
|
||||
code: 'zcash',
|
||||
configFile: 'zcash.conf',
|
||||
daemon: 'zcashd',
|
||||
defaultPort: 8232,
|
||||
unitScale: 8,
|
||||
displayScale: 5
|
||||
},
|
||||
{
|
||||
cryptoCode: 'BCH',
|
||||
display: 'Bitcoin Cash',
|
||||
code: 'bitcoincash',
|
||||
configFile: 'bitcoincash.conf',
|
||||
daemon: 'bitcoincashd',
|
||||
defaultPort: 8335,
|
||||
unitScale: 8,
|
||||
displayScale: 5
|
||||
}
|
||||
]
|
||||
|
||||
module.exports = { buildUrl, cryptoDir, blockchainDir, configPath, cryptoCurrencies, getCryptoCurrency, toUnit }
|
||||
|
||||
function getCryptoCurrency (cryptoCode) {
|
||||
const cryptoCurrency = _.find(['cryptoCode', cryptoCode], CRYPTO_CURRENCIES)
|
||||
if (!cryptoCurrency) throw new Error(`Unsupported crypto: ${cryptoCode}`)
|
||||
return cryptoCurrency
|
||||
}
|
||||
|
||||
function cryptoCurrencies () {
|
||||
return CRYPTO_CURRENCIES
|
||||
}
|
||||
|
||||
function buildUrl (cryptoCode, address) {
|
||||
switch (cryptoCode) {
|
||||
case 'BTC': return `bitcoin:${address}`
|
||||
case 'ETH': return `ethereum:${address}`
|
||||
case 'ZEC': return `zcash:${address}`
|
||||
case 'LTC': return `litecoin:${address}`
|
||||
case 'DASH': return `dash:${address}`
|
||||
case 'BCH': return `${address}`
|
||||
default: throw new Error(`Unsupported crypto: ${cryptoCode}`)
|
||||
}
|
||||
}
|
||||
|
||||
function blockchainDir () {
|
||||
return options.blockchainDir
|
||||
}
|
||||
|
||||
function cryptoDir (cryptoRec) {
|
||||
const code = cryptoRec.code
|
||||
return path.resolve(blockchainDir(), code)
|
||||
}
|
||||
|
||||
function configPath (cryptoRec) {
|
||||
return path.resolve(cryptoDir(cryptoRec), cryptoRec.configFile)
|
||||
}
|
||||
|
||||
function toUnit (cryptoAtoms, cryptoCode) {
|
||||
const cryptoRec = getCryptoCurrency(cryptoCode)
|
||||
const unitScale = cryptoRec.unitScale
|
||||
return cryptoAtoms.shift(-unitScale)
|
||||
}
|
||||
module.exports = { blockchainDir }
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
const BN = require('./bn')
|
||||
const configManager = require('./new-config-manager')
|
||||
const coinUtils = require('./coin-utils')
|
||||
const { utils } = require('lamassu-coins')
|
||||
|
||||
function truncateCrypto (cryptoAtoms, cryptoCode) {
|
||||
const DECIMAL_PLACES = 3
|
||||
if (cryptoAtoms.eq(0)) return cryptoAtoms
|
||||
|
||||
const scale = coinUtils.getCryptoCurrency(cryptoCode).displayScale
|
||||
const scale = utils.getCryptoCurrency(cryptoCode).displayScale
|
||||
const scaleFactor = BN(10).pow(scale)
|
||||
|
||||
return BN(cryptoAtoms).truncated().div(scaleFactor)
|
||||
|
|
@ -20,7 +20,7 @@ function fiatToCrypto (tx, rec, deviceId, config) {
|
|||
const tickerRate = BN(tx.rawTickerPrice)
|
||||
const discount = getDiscountRate(tx.discount, commissions[tx.direction])
|
||||
const rate = tickerRate.mul(discount).round(5)
|
||||
const unitScale = coinUtils.getCryptoCurrency(tx.cryptoCode).unitScale
|
||||
const unitScale = utils.getCryptoCurrency(tx.cryptoCode).unitScale
|
||||
const unitScaleFactor = BN(10).pow(unitScale)
|
||||
|
||||
return truncateCrypto(BN(usableFiat).div(rate.div(unitScaleFactor)), tx.cryptoCode)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
const _ = require('lodash/fp')
|
||||
const uuid = require('uuid')
|
||||
const { COINS } = require('../lib/new-admin/config/coins')
|
||||
const { COINS } = require('lamassu-coins')
|
||||
// const { COINS } = require('../lib/new-admin/config/coins')
|
||||
const { scopedValue } = require('./admin/config-manager')
|
||||
|
||||
const GLOBAL = 'global'
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
const { COINS, ALL_CRYPTOS } = require('lamassu-coins')
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
const { ALL } = require('../../plugins/common/ccxt')
|
||||
const { COINS, ALL_CRYPTOS } = require('./coins')
|
||||
|
||||
const { BTC, BCH, DASH, ETH, LTC, ZEC } = COINS
|
||||
const { bitpay, coinbase, itbit, bitstamp, kraken } = ALL
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
const _ = require('lodash/fp')
|
||||
|
||||
const { COIN_LIST: coins } = require('./coins')
|
||||
const { COIN_LIST: coins } = require('lamassu-coins')
|
||||
// const { COIN_LIST: coins } = require('./coins')
|
||||
const { ACCOUNT_LIST: accounts } = require('./accounts')
|
||||
|
||||
const countries = require('../../../data/countries.json')
|
||||
|
|
|
|||
|
|
@ -4,17 +4,17 @@ const settingsLoader = require('../../new-settings-loader')
|
|||
const configManager = require('../../new-config-manager')
|
||||
const wallet = require('../../wallet')
|
||||
const ticker = require('../../ticker')
|
||||
const coinUtils = require('../../coin-utils')
|
||||
const { utils } = require('lamassu-coins')
|
||||
|
||||
function computeCrypto (cryptoCode, _balance) {
|
||||
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
||||
const cryptoRec = utils.getCryptoCurrency(cryptoCode)
|
||||
const unitScale = cryptoRec.unitScale
|
||||
|
||||
return BN(_balance).shift(-unitScale).round(5)
|
||||
}
|
||||
|
||||
function computeFiat (rate, cryptoCode, _balance) {
|
||||
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
||||
const cryptoRec = utils.getCryptoCurrency(cryptoCode)
|
||||
const unitScale = cryptoRec.unitScale
|
||||
|
||||
return BN(_balance).shift(-unitScale).mul(rate).round(5)
|
||||
|
|
@ -35,7 +35,7 @@ function getSingleCoinFunding (settings, fiatCode, cryptoCode) {
|
|||
const pending = fundingRec.fundingPendingBalance
|
||||
const fiatPending = computeFiat(rate, cryptoCode, pending)
|
||||
const fundingAddress = fundingRec.fundingAddress
|
||||
const fundingAddressUrl = coinUtils.buildUrl(cryptoCode, fundingAddress)
|
||||
const fundingAddressUrl = utils.buildUrl(cryptoCode, fundingAddress)
|
||||
|
||||
return {
|
||||
cryptoCode,
|
||||
|
|
@ -58,7 +58,7 @@ function getFunding () {
|
|||
const cryptoCodes = configManager.getAllCryptoCurrencies(settings.config)
|
||||
const fiatCode = configManager.getGlobalLocale(settings.config).fiatCurrency
|
||||
const pareCoins = c => _.includes(c.cryptoCode, cryptoCodes)
|
||||
const cryptoCurrencies = coinUtils.cryptoCurrencies()
|
||||
const cryptoCurrencies = utils.cryptoCurrencies()
|
||||
const cryptoDisplays = _.filter(pareCoins, cryptoCurrencies)
|
||||
|
||||
const promises = cryptoDisplays.map(it => getSingleCoinFunding(settings, fiatCode, it.cryptoCode))
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ const email = require('./email')
|
|||
const cashOutHelper = require('./cash-out/cash-out-helper')
|
||||
const machineLoader = require('./machine-loader')
|
||||
const customers = require('./customers')
|
||||
const coinUtils = require('./coin-utils')
|
||||
const commissionMath = require('./commission-math')
|
||||
const promoCodes = require('./promo-codes')
|
||||
|
||||
|
|
@ -27,6 +26,8 @@ const { cassetteMaxCapacity } = require('./constants')
|
|||
|
||||
const notifier = require('./notifier')
|
||||
|
||||
const { utils } = require('lamassu-coins')
|
||||
|
||||
const mapValuesWithKey = _.mapValues.convert({
|
||||
cap: false
|
||||
})
|
||||
|
|
@ -203,7 +204,7 @@ function plugins (settings, deviceId) {
|
|||
const cashInFee = BN(commissions.fixedFee)
|
||||
const cashInCommission = BN(commissions.cashIn)
|
||||
const cashOutCommission = _.isNumber(commissions.cashOut) ? BN(commissions.cashOut) : null
|
||||
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
||||
const cryptoRec = utils.getCryptoCurrency(cryptoCode)
|
||||
|
||||
return {
|
||||
cryptoCode,
|
||||
|
|
@ -334,7 +335,7 @@ function plugins (settings, deviceId) {
|
|||
|
||||
const lowBalanceMargin = BN(1.03)
|
||||
|
||||
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
||||
const cryptoRec = utils.getCryptoCurrency(cryptoCode)
|
||||
const unitScale = cryptoRec.unitScale
|
||||
const shiftedRate = rate.shift(-unitScale)
|
||||
const fiatTransferBalance = balance.mul(shiftedRate).div(lowBalanceMargin)
|
||||
|
|
|
|||
46
lib/plugins/exchange/bitstamp/bitstamp.js
Normal file
46
lib/plugins/exchange/bitstamp/bitstamp.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
const common = require('../../common/bitstamp')
|
||||
const { utils } = require('lamassu-coins')
|
||||
// const coinUtils = require('../../../coin-utils')
|
||||
|
||||
function buy (account, cryptoAtoms, fiatCode, cryptoCode) {
|
||||
return trade('buy', account, cryptoAtoms, fiatCode, cryptoCode)
|
||||
}
|
||||
|
||||
function sell (account, cryptoAtoms, fiatCode, cryptoCode) {
|
||||
return trade('sell', account, cryptoAtoms, fiatCode, cryptoCode)
|
||||
}
|
||||
|
||||
function handleErrors (data) {
|
||||
if (!data.reason || !data.reason.__all__) return data
|
||||
|
||||
const err = new Error(data.reason.__all__[0])
|
||||
|
||||
if (data.reason.__all__[0].indexOf('Minimum order size is') === 0) {
|
||||
err.name = 'orderTooSmall'
|
||||
}
|
||||
|
||||
throw err
|
||||
}
|
||||
|
||||
function trade (type, account, cryptoAtoms, _fiatCode, cryptoCode) {
|
||||
const fiatCode = _fiatCode === 'USD' ? 'USD' : 'EUR'
|
||||
|
||||
try {
|
||||
const market = common.buildMarket(fiatCode, cryptoCode)
|
||||
const options = {amount: utils.toUnit(cryptoAtoms, cryptoCode).toFixed(8)}
|
||||
|
||||
return common.authRequest(account, '/' + type + '/market/' + market, options)
|
||||
.catch(e => {
|
||||
if (e.response) handleErrors(e.response.data)
|
||||
throw e
|
||||
})
|
||||
.then(handleErrors)
|
||||
} catch (e) {
|
||||
return Promise.reject(e)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
buy,
|
||||
sell
|
||||
}
|
||||
46
lib/plugins/exchange/itbit/itbit.js
Normal file
46
lib/plugins/exchange/itbit/itbit.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
const common = require('../../common/itbit')
|
||||
const { utils } = require('lamassu-coins')
|
||||
// const coinUtils = require('../../../coin-utils')
|
||||
|
||||
exports.buy = function (account, cryptoAtoms, fiatCode, cryptoCode) {
|
||||
return trade('buy', account, cryptoAtoms, fiatCode, cryptoCode)
|
||||
}
|
||||
|
||||
exports.sell = function (account, cryptoAtoms, fiatCode, cryptoCode) {
|
||||
return trade('sell', account, cryptoAtoms, fiatCode, cryptoCode)
|
||||
}
|
||||
|
||||
function trade (type, account, cryptoAtoms, fiatCode, cryptoCode) {
|
||||
try {
|
||||
const instrument = common.buildMarket(fiatCode, cryptoCode)
|
||||
const cryptoAmount = utils.toUnit(cryptoAtoms, cryptoCode)
|
||||
|
||||
return calculatePrice(type, instrument, cryptoAmount)
|
||||
.then(price => {
|
||||
const args = {
|
||||
side: type,
|
||||
type: 'limit',
|
||||
currency: cryptoCode,
|
||||
amount: cryptoAmount.toFixed(4),
|
||||
price: price.toFixed(2),
|
||||
instrument: instrument
|
||||
}
|
||||
return common.authRequest(account, 'POST', '/wallets/' + account.walletId + '/orders', args)
|
||||
})
|
||||
} catch (e) {
|
||||
return Promise.reject(e)
|
||||
}
|
||||
}
|
||||
|
||||
function calculatePrice (type, tickerSymbol, amount) {
|
||||
return common.request('GET', '/markets/' + tickerSymbol + '/order_book')
|
||||
.then(orderBook => {
|
||||
const book = type == 'buy' ? 'asks' : 'bids'
|
||||
let collected = 0.0
|
||||
for (const entry of orderBook[book]) {
|
||||
collected += parseFloat(entry[1])
|
||||
if (collected >= amount) return parseFloat(entry[0])
|
||||
}
|
||||
throw new Error('Insufficient market depth')
|
||||
})
|
||||
}
|
||||
45
lib/plugins/exchange/kraken/kraken.js
Normal file
45
lib/plugins/exchange/kraken/kraken.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// Note: Using DeX3/npm-kraken-api to adjust timeout time
|
||||
const Kraken = require('kraken-api')
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
const common = require('../../common/kraken')
|
||||
const { utils } = require('lamassu-coins')
|
||||
// const coinUtils = require('../../../coin-utils')
|
||||
|
||||
var PAIRS = common.PAIRS
|
||||
|
||||
module.exports = {buy, sell}
|
||||
|
||||
function buy (account, cryptoAtoms, fiatCode, cryptoCode) {
|
||||
return trade(account, 'buy', cryptoAtoms, fiatCode, cryptoCode)
|
||||
}
|
||||
|
||||
function sell (account, cryptoAtoms, fiatCode, cryptoCode) {
|
||||
return trade(account, 'sell', cryptoAtoms, fiatCode, cryptoCode)
|
||||
}
|
||||
|
||||
function trade (account, type, cryptoAtoms, fiatCode, cryptoCode) {
|
||||
const kraken = new Kraken(account.apiKey, account.privateKey, {timeout: 30000})
|
||||
const amount = utils.toUnit(cryptoAtoms, cryptoCode)
|
||||
const amountStr = amount.toFixed(6)
|
||||
|
||||
const pair = _.includes(fiatCode, ['USD', 'EUR'])
|
||||
? PAIRS[cryptoCode][fiatCode]
|
||||
: PAIRS[cryptoCode]['EUR']
|
||||
|
||||
var orderInfo = {
|
||||
pair,
|
||||
type,
|
||||
ordertype: 'market',
|
||||
volume: amountStr,
|
||||
expiretm: '+60'
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
kraken.api('AddOrder', orderInfo, (error, response) => {
|
||||
if (error) return reject(error)
|
||||
|
||||
return resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
@ -3,10 +3,11 @@ const jsonRpc = require('../../common/json-rpc')
|
|||
|
||||
const BN = require('../../../bn')
|
||||
const E = require('../../../error')
|
||||
const coinUtils = require('../../../coin-utils')
|
||||
const { utils } = require('lamassu-coins')
|
||||
// const coinUtils = require('../../../coin-utils')
|
||||
|
||||
const cryptoRec = coinUtils.getCryptoCurrency('BCH')
|
||||
const configPath = coinUtils.configPath(cryptoRec)
|
||||
const cryptoRec = utils.getCryptoCurrency('BCH')
|
||||
const configPath = utils.configPath(cryptoRec)
|
||||
const unitScale = cryptoRec.unitScale
|
||||
|
||||
function rpcConfig () {
|
||||
|
|
|
|||
|
|
@ -3,10 +3,11 @@ const jsonRpc = require('../../common/json-rpc')
|
|||
|
||||
const BN = require('../../../bn')
|
||||
const E = require('../../../error')
|
||||
const coinUtils = require('../../../coin-utils')
|
||||
const { utils } = require('lamassu-coins')
|
||||
// const coinUtils = require('../../../coin-utils')
|
||||
|
||||
const cryptoRec = coinUtils.getCryptoCurrency('BTC')
|
||||
const configPath = coinUtils.configPath(cryptoRec)
|
||||
const cryptoRec = utils.getCryptoCurrency('BTC')
|
||||
const configPath = utils.configPath(cryptoRec)
|
||||
const unitScale = cryptoRec.unitScale
|
||||
|
||||
function rpcConfig () {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
const _ = require('lodash/fp')
|
||||
const jsonRpc = require('../../common/json-rpc')
|
||||
|
||||
const coinUtils = require('../../../coin-utils')
|
||||
const { utils } = require('lamassu-coins')
|
||||
// const coinUtils = require('../../../coin-utils')
|
||||
|
||||
const BN = require('../../../bn')
|
||||
const E = require('../../../error')
|
||||
|
||||
const cryptoRec = coinUtils.getCryptoCurrency('DASH')
|
||||
const configPath = coinUtils.configPath(cryptoRec)
|
||||
const cryptoRec = utils.getCryptoCurrency('DASH')
|
||||
const configPath = utils.configPath(cryptoRec)
|
||||
const unitScale = cryptoRec.unitScale
|
||||
|
||||
function rpcConfig () {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
const base = require('./base')
|
||||
|
||||
const coinUtils = require('../../../coin-utils')
|
||||
const cryptoRec = coinUtils.getCryptoCurrency('ETH')
|
||||
const { utils } = require('lamassu-coins')
|
||||
// const coinUtils = require('../../../coin-utils')
|
||||
const cryptoRec = utils.getCryptoCurrency('ETH')
|
||||
const defaultPort = cryptoRec.defaultPort
|
||||
|
||||
base.connect(`http://localhost:${defaultPort}`)
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
const _ = require('lodash/fp')
|
||||
const jsonRpc = require('../../common/json-rpc')
|
||||
|
||||
const coinUtils = require('../../../coin-utils')
|
||||
const { utils } = require('lamassu-coins')
|
||||
// const coinUtils = require('../../../coin-utils')
|
||||
|
||||
const BN = require('../../../bn')
|
||||
const E = require('../../../error')
|
||||
|
||||
const cryptoRec = coinUtils.getCryptoCurrency('LTC')
|
||||
const configPath = coinUtils.configPath(cryptoRec)
|
||||
const cryptoRec = utils.getCryptoCurrency('LTC')
|
||||
const configPath = utils.configPath(cryptoRec)
|
||||
const unitScale = cryptoRec.unitScale
|
||||
|
||||
function rpcConfig () {
|
||||
|
|
|
|||
|
|
@ -2,12 +2,13 @@ const lnd = require('lnd-async')
|
|||
|
||||
const BN = require('../../../bn')
|
||||
const E = require('../../../error')
|
||||
const coinUtils = require('../../../coin-utils')
|
||||
const { utils } = require('lamassu-coins')
|
||||
// const coinUtils = require('../../../coin-utils')
|
||||
const options = require('../../../options')
|
||||
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
const cryptoRec = coinUtils.getCryptoCurrency('BTC')
|
||||
const cryptoRec = utils.getCryptoCurrency('BTC')
|
||||
const unitScale = cryptoRec.unitScale
|
||||
|
||||
module.exports = {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
const BN = require('../../../bn')
|
||||
const E = require('../../../error')
|
||||
const coinUtils = require('../../../coin-utils')
|
||||
const { utils } = require('lamassu-coins')
|
||||
// const coinUtils = require('../../../coin-utils')
|
||||
|
||||
const NAME = 'FakeWallet'
|
||||
|
||||
|
|
@ -12,7 +13,7 @@ const CONFIRM_TIME = AUTHORIZE_TIME + 120 * SECONDS
|
|||
let t0
|
||||
|
||||
function _balance (cryptoCode) {
|
||||
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
||||
const cryptoRec = utils.getCryptoCurrency(cryptoCode)
|
||||
const unitScale = cryptoRec.unitScale
|
||||
return BN(10).shift(unitScale).round()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,14 @@ const _ = require('lodash/fp')
|
|||
const pRetry = require('p-retry')
|
||||
const jsonRpc = require('../../common/json-rpc')
|
||||
|
||||
const coinUtils = require('../../../coin-utils')
|
||||
const { utils } = require('lamassu-coins')
|
||||
// const coinUtils = require('../../../coin-utils')
|
||||
|
||||
const BN = require('../../../bn')
|
||||
const E = require('../../../error')
|
||||
|
||||
const cryptoRec = coinUtils.getCryptoCurrency('ZEC')
|
||||
const configPath = coinUtils.configPath(cryptoRec)
|
||||
const cryptoRec = utils.getCryptoCurrency('ZEC')
|
||||
const configPath = utils.configPath(cryptoRec)
|
||||
const unitScale = cryptoRec.unitScale
|
||||
|
||||
function rpcConfig () {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { makeStyles, Box } from '@material-ui/core'
|
||||
import BigNumber from 'bignumber.js'
|
||||
import { utils } from 'lamassu-coins'
|
||||
import * as R from 'ramda'
|
||||
import React from 'react'
|
||||
|
||||
|
|
@ -7,7 +8,7 @@ import DataTable from 'src/components/tables/DataTable'
|
|||
import { H3, H4, Label1, Label2, P } from 'src/components/typography'
|
||||
import { ReactComponent as TxInIcon } from 'src/styling/icons/direction/cash-in.svg'
|
||||
import { ReactComponent as TxOutIcon } from 'src/styling/icons/direction/cash-out.svg'
|
||||
import { toUnit } from 'src/utils/coin'
|
||||
// import { toUnit } from 'src/utils/coin'
|
||||
import { ifNotNull } from 'src/utils/nullCheck'
|
||||
import { formatDate } from 'src/utils/timezones'
|
||||
|
||||
|
|
@ -103,9 +104,9 @@ const TransactionsList = ({ customer, data, loading, locale }) => {
|
|||
textAlign: 'right',
|
||||
view: it => (
|
||||
<>
|
||||
{`${toUnit(new BigNumber(it.cryptoAtoms), it.cryptoCode).toFormat(
|
||||
5
|
||||
)} `}
|
||||
{`${utils
|
||||
.toUnit(new BigNumber(it.cryptoAtoms), it.cryptoCode)
|
||||
.toFormat(5)} `}
|
||||
<Label2 inline>{it.cryptoCode}</Label2>
|
||||
</>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { makeStyles } from '@material-ui/core/styles'
|
|||
import BigNumber from 'bignumber.js'
|
||||
import classnames from 'classnames'
|
||||
import gql from 'graphql-tag'
|
||||
import { utils } from 'lamassu-coins'
|
||||
import moment from 'moment'
|
||||
import QRCode from 'qrcode.react'
|
||||
import * as R from 'ramda'
|
||||
|
|
@ -22,7 +23,7 @@ import {
|
|||
} from 'src/components/typography'
|
||||
import CopyToClipboard from 'src/pages/Transactions/CopyToClipboard'
|
||||
import { primaryColor } from 'src/styling/variables'
|
||||
import { formatCryptoAddress } from 'src/utils/coin'
|
||||
// import { formatCryptoAddress } from 'src/utils/coin'
|
||||
|
||||
import styles from './Funding.styles'
|
||||
|
||||
|
|
@ -52,7 +53,7 @@ const GET_FUNDING = gql`
|
|||
`
|
||||
|
||||
const formatAddress = (cryptoCode = '', address = '') =>
|
||||
formatCryptoAddress(cryptoCode, address).replace(/(.{4})/g, '$1 ')
|
||||
utils.formatCryptoAddress(cryptoCode, address).replace(/(.{4})/g, '$1 ')
|
||||
const sumReducer = (acc, value) => acc.plus(value)
|
||||
const formatNumber = it => new BigNumber(it).toFormat(2)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import BigNumber from 'bignumber.js'
|
|||
import FileSaver from 'file-saver'
|
||||
import gql from 'graphql-tag'
|
||||
import JSZip from 'jszip'
|
||||
import { utils } from 'lamassu-coins'
|
||||
import moment from 'moment'
|
||||
import * as R from 'ramda'
|
||||
import React, { memo } from 'react'
|
||||
|
|
@ -22,7 +23,7 @@ import { ReactComponent as Download } from 'src/styling/icons/button/download/zo
|
|||
import { ReactComponent as TxInIcon } from 'src/styling/icons/direction/cash-in.svg'
|
||||
import { ReactComponent as TxOutIcon } from 'src/styling/icons/direction/cash-out.svg'
|
||||
import { URI } from 'src/utils/apollo'
|
||||
import { toUnit, formatCryptoAddress } from 'src/utils/coin'
|
||||
// import { toUnit, formatCryptoAddress } from 'src/utils/coin'
|
||||
import { onlyFirstToUpper } from 'src/utils/string'
|
||||
|
||||
import CopyToClipboard from './CopyToClipboard'
|
||||
|
|
@ -53,7 +54,7 @@ const TX_SUMMARY = gql`
|
|||
`
|
||||
|
||||
const formatAddress = (cryptoCode = '', address = '') =>
|
||||
formatCryptoAddress(cryptoCode, address).replace(/(.{5})/g, '$1 ')
|
||||
utils.formatCryptoAddress(cryptoCode, address).replace(/(.{5})/g, '$1 ')
|
||||
|
||||
const Label = ({ children }) => {
|
||||
const classes = useStyles()
|
||||
|
|
@ -70,7 +71,7 @@ const DetailsRow = ({ it: tx }) => {
|
|||
})
|
||||
|
||||
const fiat = Number.parseFloat(tx.fiat)
|
||||
const crypto = toUnit(new BigNumber(tx.cryptoAtoms), tx.cryptoCode)
|
||||
const crypto = utils.toUnit(new BigNumber(tx.cryptoAtoms), tx.cryptoCode)
|
||||
const commissionPercentage = Number.parseFloat(tx.commissionPercentage, 2)
|
||||
const commission = Number(fiat * commissionPercentage).toFixed(2)
|
||||
const discount = tx.discount ? `-${tx.discount}%` : null
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { useQuery } from '@apollo/react-hooks'
|
|||
import { makeStyles } from '@material-ui/core'
|
||||
import BigNumber from 'bignumber.js'
|
||||
import gql from 'graphql-tag'
|
||||
import { utils } from 'lamassu-coins'
|
||||
import * as R from 'ramda'
|
||||
import React from 'react'
|
||||
import { useHistory } from 'react-router-dom'
|
||||
|
|
@ -12,7 +13,6 @@ import DataTable from 'src/components/tables/DataTable'
|
|||
import { ReactComponent as TxInIcon } from 'src/styling/icons/direction/cash-in.svg'
|
||||
import { ReactComponent as TxOutIcon } from 'src/styling/icons/direction/cash-out.svg'
|
||||
import { ReactComponent as CustomerLinkIcon } from 'src/styling/icons/month arrows/right.svg'
|
||||
import { toUnit, formatCryptoAddress } from 'src/utils/coin'
|
||||
import { formatDate } from 'src/utils/timezones'
|
||||
|
||||
import DetailsRow from './DetailsCard'
|
||||
|
|
@ -139,13 +139,13 @@ const Transactions = () => {
|
|||
textAlign: 'right',
|
||||
size: 'sm',
|
||||
view: it =>
|
||||
`${toUnit(new BigNumber(it.cryptoAtoms), it.cryptoCode).toFormat(5)} ${
|
||||
it.cryptoCode
|
||||
}`
|
||||
`${utils
|
||||
.toUnit(new BigNumber(it.cryptoAtoms), it.cryptoCode)
|
||||
.toFormat(5)} ${it.cryptoCode}`
|
||||
},
|
||||
{
|
||||
header: 'Address',
|
||||
view: it => formatCryptoAddress(it.cryptoCode, it.toAddress),
|
||||
view: it => utils.formatCryptoAddress(it.cryptoCode, it.toAddress),
|
||||
className: classes.overflowTd,
|
||||
size: 'sm',
|
||||
width: 140
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue