feat: change to generic ERC-20 ABI json file
fix: coinUtils rename import
This commit is contained in:
parent
dff407e30e
commit
8e099e3283
36 changed files with 364 additions and 249 deletions
|
|
@ -1,32 +0,0 @@
|
|||
const PAIRS = {
|
||||
BTC: {
|
||||
USD: 'XXBTZUSD',
|
||||
EUR: 'XXBTZEUR'
|
||||
},
|
||||
ETH: {
|
||||
USD: 'XETHZUSD',
|
||||
EUR: 'XETHZEUR'
|
||||
},
|
||||
ZEC: {
|
||||
USD: 'XZECZUSD',
|
||||
EUR: 'XZECZEUR'
|
||||
},
|
||||
LTC: {
|
||||
USD: 'XLTCZUSD',
|
||||
EUR: 'XLTCZEUR'
|
||||
},
|
||||
DASH: {
|
||||
USD: 'DASHUSD',
|
||||
EUR: 'DASHEUR'
|
||||
},
|
||||
BCH: {
|
||||
USD: 'BCHUSD',
|
||||
EUR: 'BCHEUR'
|
||||
},
|
||||
USDT: {
|
||||
USD: 'USDTZUSD',
|
||||
EUR: 'USDTEUR'
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {PAIRS}
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -1,3 +0,0 @@
|
|||
const USDT = require('./abi/usdt.json')
|
||||
|
||||
module.exports = { USDT }
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
const common = require('../../common/bitstamp')
|
||||
const { utils } = require('lamassu-coins')
|
||||
|
||||
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
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
const common = require('../../common/itbit')
|
||||
const { utils } = require('lamassu-coins')
|
||||
|
||||
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')
|
||||
})
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
// 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')
|
||||
|
||||
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()
|
||||
})
|
||||
})
|
||||
}
|
||||
282
lib/plugins/tokens/erc20.abi.json
Normal file
282
lib/plugins/tokens/erc20.abi.json
Normal file
|
|
@ -0,0 +1,282 @@
|
|||
[
|
||||
{
|
||||
"constant":true,
|
||||
"inputs":[
|
||||
|
||||
],
|
||||
"name":"name",
|
||||
"outputs":[
|
||||
{
|
||||
"name":"",
|
||||
"type":"string"
|
||||
}
|
||||
],
|
||||
"payable":false,
|
||||
"type":"function"
|
||||
},
|
||||
{
|
||||
"constant":false,
|
||||
"inputs":[
|
||||
{
|
||||
"name":"_spender",
|
||||
"type":"address"
|
||||
},
|
||||
{
|
||||
"name":"_value",
|
||||
"type":"uint256"
|
||||
}
|
||||
],
|
||||
"name":"approve",
|
||||
"outputs":[
|
||||
{
|
||||
"name":"success",
|
||||
"type":"bool"
|
||||
}
|
||||
],
|
||||
"payable":false,
|
||||
"type":"function"
|
||||
},
|
||||
{
|
||||
"constant":true,
|
||||
"inputs":[
|
||||
|
||||
],
|
||||
"name":"totalSupply",
|
||||
"outputs":[
|
||||
{
|
||||
"name":"",
|
||||
"type":"uint256"
|
||||
}
|
||||
],
|
||||
"payable":false,
|
||||
"type":"function"
|
||||
},
|
||||
{
|
||||
"constant":false,
|
||||
"inputs":[
|
||||
{
|
||||
"name":"_from",
|
||||
"type":"address"
|
||||
},
|
||||
{
|
||||
"name":"_to",
|
||||
"type":"address"
|
||||
},
|
||||
{
|
||||
"name":"_value",
|
||||
"type":"uint256"
|
||||
}
|
||||
],
|
||||
"name":"transferFrom",
|
||||
"outputs":[
|
||||
{
|
||||
"name":"success",
|
||||
"type":"bool"
|
||||
}
|
||||
],
|
||||
"payable":false,
|
||||
"type":"function"
|
||||
},
|
||||
{
|
||||
"constant":true,
|
||||
"inputs":[
|
||||
|
||||
],
|
||||
"name":"decimals",
|
||||
"outputs":[
|
||||
{
|
||||
"name":"",
|
||||
"type":"uint256"
|
||||
}
|
||||
],
|
||||
"payable":false,
|
||||
"type":"function"
|
||||
},
|
||||
{
|
||||
"constant":true,
|
||||
"inputs":[
|
||||
|
||||
],
|
||||
"name":"version",
|
||||
"outputs":[
|
||||
{
|
||||
"name":"",
|
||||
"type":"string"
|
||||
}
|
||||
],
|
||||
"payable":false,
|
||||
"type":"function"
|
||||
},
|
||||
{
|
||||
"constant":true,
|
||||
"inputs":[
|
||||
{
|
||||
"name":"_owner",
|
||||
"type":"address"
|
||||
}
|
||||
],
|
||||
"name":"balanceOf",
|
||||
"outputs":[
|
||||
{
|
||||
"name":"balance",
|
||||
"type":"uint256"
|
||||
}
|
||||
],
|
||||
"payable":false,
|
||||
"type":"function"
|
||||
},
|
||||
{
|
||||
"constant":true,
|
||||
"inputs":[
|
||||
|
||||
],
|
||||
"name":"symbol",
|
||||
"outputs":[
|
||||
{
|
||||
"name":"",
|
||||
"type":"string"
|
||||
}
|
||||
],
|
||||
"payable":false,
|
||||
"type":"function"
|
||||
},
|
||||
{
|
||||
"constant":false,
|
||||
"inputs":[
|
||||
{
|
||||
"name":"_to",
|
||||
"type":"address"
|
||||
},
|
||||
{
|
||||
"name":"_value",
|
||||
"type":"uint256"
|
||||
}
|
||||
],
|
||||
"name":"transfer",
|
||||
"outputs":[
|
||||
{
|
||||
"name":"success",
|
||||
"type":"bool"
|
||||
}
|
||||
],
|
||||
"payable":false,
|
||||
"type":"function"
|
||||
},
|
||||
{
|
||||
"constant":false,
|
||||
"inputs":[
|
||||
{
|
||||
"name":"_spender",
|
||||
"type":"address"
|
||||
},
|
||||
{
|
||||
"name":"_value",
|
||||
"type":"uint256"
|
||||
},
|
||||
{
|
||||
"name":"_extraData",
|
||||
"type":"bytes"
|
||||
}
|
||||
],
|
||||
"name":"approveAndCall",
|
||||
"outputs":[
|
||||
{
|
||||
"name":"success",
|
||||
"type":"bool"
|
||||
}
|
||||
],
|
||||
"payable":false,
|
||||
"type":"function"
|
||||
},
|
||||
{
|
||||
"constant":true,
|
||||
"inputs":[
|
||||
{
|
||||
"name":"_owner",
|
||||
"type":"address"
|
||||
},
|
||||
{
|
||||
"name":"_spender",
|
||||
"type":"address"
|
||||
}
|
||||
],
|
||||
"name":"allowance",
|
||||
"outputs":[
|
||||
{
|
||||
"name":"remaining",
|
||||
"type":"uint256"
|
||||
}
|
||||
],
|
||||
"payable":false,
|
||||
"type":"function"
|
||||
},
|
||||
{
|
||||
"inputs":[
|
||||
{
|
||||
"name":"_initialAmount",
|
||||
"type":"uint256"
|
||||
},
|
||||
{
|
||||
"name":"_tokenName",
|
||||
"type":"string"
|
||||
},
|
||||
{
|
||||
"name":"_decimalUnits",
|
||||
"type":"uint8"
|
||||
},
|
||||
{
|
||||
"name":"_tokenSymbol",
|
||||
"type":"string"
|
||||
}
|
||||
],
|
||||
"type":"constructor"
|
||||
},
|
||||
{
|
||||
"payable":false,
|
||||
"type":"fallback"
|
||||
},
|
||||
{
|
||||
"anonymous":false,
|
||||
"inputs":[
|
||||
{
|
||||
"indexed":true,
|
||||
"name":"_from",
|
||||
"type":"address"
|
||||
},
|
||||
{
|
||||
"indexed":true,
|
||||
"name":"_to",
|
||||
"type":"address"
|
||||
},
|
||||
{
|
||||
"indexed":false,
|
||||
"name":"_value",
|
||||
"type":"uint256"
|
||||
}
|
||||
],
|
||||
"name":"Transfer",
|
||||
"type":"event"
|
||||
},
|
||||
{
|
||||
"anonymous":false,
|
||||
"inputs":[
|
||||
{
|
||||
"indexed":true,
|
||||
"name":"_owner",
|
||||
"type":"address"
|
||||
},
|
||||
{
|
||||
"indexed":true,
|
||||
"name":"_spender",
|
||||
"type":"address"
|
||||
},
|
||||
{
|
||||
"indexed":false,
|
||||
"name":"_value",
|
||||
"type":"uint256"
|
||||
}
|
||||
],
|
||||
"name":"Approval",
|
||||
"type":"event"
|
||||
}
|
||||
]
|
||||
3
lib/plugins/tokens/index.js
Normal file
3
lib/plugins/tokens/index.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
const ERC20 = require('./erc20.abi')
|
||||
|
||||
module.exports = { ERC20 }
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
const _ = require('lodash/fp')
|
||||
const jsonRpc = require('../../common/json-rpc')
|
||||
|
||||
const blockchainUtils = require('../../../coin-utils')
|
||||
const blockchainUtils = require('../../../blockchain-utils')
|
||||
const BN = require('../../../bn')
|
||||
const E = require('../../../error')
|
||||
const { utils } = require('lamassu-coins')
|
||||
const { utils: coinUtils } = require('lamassu-coins')
|
||||
|
||||
const cryptoRec = utils.getCryptoCurrency('BCH')
|
||||
const configPath = utils.configPath(cryptoRec, blockchainUtils.blockchainDir())
|
||||
const cryptoRec = coinUtils.getCryptoCurrency('BCH')
|
||||
const configPath = coinUtils.configPath(cryptoRec, blockchainUtils.blockchainDir())
|
||||
const unitScale = cryptoRec.unitScale
|
||||
|
||||
function rpcConfig () {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
const _ = require('lodash/fp')
|
||||
const jsonRpc = require('../../common/json-rpc')
|
||||
|
||||
const blockchainUtils = require('../../../coin-utils')
|
||||
const blockchainUtils = require('../../../blockchain-utils')
|
||||
const BN = require('../../../bn')
|
||||
const E = require('../../../error')
|
||||
const { utils } = require('lamassu-coins')
|
||||
const { utils: coinUtils } = require('lamassu-coins')
|
||||
|
||||
const cryptoRec = utils.getCryptoCurrency('BTC')
|
||||
const configPath = utils.configPath(cryptoRec, blockchainUtils.blockchainDir())
|
||||
const cryptoRec = coinUtils.getCryptoCurrency('BTC')
|
||||
const configPath = coinUtils.configPath(cryptoRec, blockchainUtils.blockchainDir())
|
||||
const unitScale = cryptoRec.unitScale
|
||||
|
||||
function rpcConfig () {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
const _ = require('lodash/fp')
|
||||
const jsonRpc = require('../../common/json-rpc')
|
||||
|
||||
const { utils } = require('lamassu-coins')
|
||||
const { utils: coinUtils } = require('lamassu-coins')
|
||||
|
||||
const blockchainUtils = require('../../../coin-utils')
|
||||
const blockchainUtils = require('../../../blockchain-utils')
|
||||
const BN = require('../../../bn')
|
||||
const E = require('../../../error')
|
||||
|
||||
const cryptoRec = utils.getCryptoCurrency('DASH')
|
||||
const configPath = utils.configPath(cryptoRec, blockchainUtils.blockchainDir())
|
||||
const cryptoRec = coinUtils.getCryptoCurrency('DASH')
|
||||
const configPath = coinUtils.configPath(cryptoRec, blockchainUtils.blockchainDir())
|
||||
const unitScale = cryptoRec.unitScale
|
||||
|
||||
function rpcConfig () {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ const util = require('ethereumjs-util')
|
|||
const coins = require('lamassu-coins')
|
||||
const pify = require('pify')
|
||||
const BN = require('../../../bn')
|
||||
const erc20ABIs = require('../../erc20')
|
||||
const ABI = require('../../tokens')
|
||||
|
||||
const NAME = 'geth'
|
||||
exports.SUPPORTED_MODULES = ['wallet']
|
||||
|
|
@ -84,7 +84,7 @@ const confirmedBalance = (address, cryptoCode) => _balance(false, address, crypt
|
|||
|
||||
function _balance (includePending, address, cryptoCode) {
|
||||
if (coins.utils.getCryptoCurrency(cryptoCode).type === 'erc-20') {
|
||||
const contract = web3.eth.contract(erc20ABIs[cryptoCode]).at(coins.utils.getErc20Token(cryptoCode).contractAddress)
|
||||
const contract = web3.eth.contract(ABI.ERC20).at(coins.utils.getErc20Token(cryptoCode).contractAddress)
|
||||
return contract.balanceOf(address.toLowerCase())
|
||||
}
|
||||
const block = includePending ? 'pending' : undefined
|
||||
|
|
@ -98,7 +98,7 @@ function generateTx (toAddress, wallet, amount, includesFee, cryptoCode) {
|
|||
}
|
||||
|
||||
function generateContractTx (_toAddress, wallet, amount, includesFee, cryptoCode) {
|
||||
const contract = web3.eth.contract(erc20ABIs[cryptoCode]).at(coins.utils.getErc20Token(cryptoCode).contractAddress)
|
||||
const contract = web3.eth.contract(ABI.ERC20).at(coins.utils.getErc20Token(cryptoCode).contractAddress)
|
||||
|
||||
const fromAddress = '0x' + wallet.getAddress().toString('hex')
|
||||
const toAddress = _toAddress.toLowerCase()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
const base = require('./base')
|
||||
|
||||
const { utils } = require('lamassu-coins')
|
||||
const cryptoRec = utils.getCryptoCurrency('ETH')
|
||||
const { utils: coinUtils } = require('lamassu-coins')
|
||||
const cryptoRec = coinUtils.getCryptoCurrency('ETH')
|
||||
const defaultPort = cryptoRec.defaultPort
|
||||
|
||||
base.connect(`http://localhost:${defaultPort}`)
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
const _ = require('lodash/fp')
|
||||
const jsonRpc = require('../../common/json-rpc')
|
||||
|
||||
const { utils } = require('lamassu-coins')
|
||||
const { utils: coinUtils } = require('lamassu-coins')
|
||||
|
||||
const blockchainUtils = require('../../../coin-utils')
|
||||
const blockchainUtils = require('../../../blockchain-utils')
|
||||
const BN = require('../../../bn')
|
||||
const E = require('../../../error')
|
||||
|
||||
const cryptoRec = utils.getCryptoCurrency('LTC')
|
||||
const configPath = utils.configPath(cryptoRec, blockchainUtils.blockchainDir())
|
||||
const cryptoRec = coinUtils.getCryptoCurrency('LTC')
|
||||
const configPath = coinUtils.configPath(cryptoRec, blockchainUtils.blockchainDir())
|
||||
const unitScale = cryptoRec.unitScale
|
||||
|
||||
function rpcConfig () {
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ const lnd = require('lnd-async')
|
|||
|
||||
const BN = require('../../../bn')
|
||||
const E = require('../../../error')
|
||||
const { utils } = require('lamassu-coins')
|
||||
const { utils: coinUtils } = require('lamassu-coins')
|
||||
const options = require('../../../options')
|
||||
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
const cryptoRec = utils.getCryptoCurrency('BTC')
|
||||
const cryptoRec = coinUtils.getCryptoCurrency('BTC')
|
||||
const unitScale = cryptoRec.unitScale
|
||||
|
||||
module.exports = {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
const BN = require('../../../bn')
|
||||
const E = require('../../../error')
|
||||
const { utils } = require('lamassu-coins')
|
||||
const { utils: coinUtils } = require('lamassu-coins')
|
||||
|
||||
const NAME = 'FakeWallet'
|
||||
|
||||
|
|
@ -12,7 +12,7 @@ const CONFIRM_TIME = AUTHORIZE_TIME + 120 * SECONDS
|
|||
let t0
|
||||
|
||||
function _balance (cryptoCode) {
|
||||
const cryptoRec = utils.getCryptoCurrency(cryptoCode)
|
||||
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
||||
const unitScale = cryptoRec.unitScale
|
||||
return BN(10).shift(unitScale).round()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@ const _ = require('lodash/fp')
|
|||
const pRetry = require('p-retry')
|
||||
const jsonRpc = require('../../common/json-rpc')
|
||||
|
||||
const { utils } = require('lamassu-coins')
|
||||
const { utils: coinUtils } = require('lamassu-coins')
|
||||
|
||||
const blockchainUtils = require('../../../coin-utils')
|
||||
const blockchainUtils = require('../../../blockchain-utils')
|
||||
const BN = require('../../../bn')
|
||||
const E = require('../../../error')
|
||||
|
||||
const cryptoRec = utils.getCryptoCurrency('ZEC')
|
||||
const configPath = utils.configPath(cryptoRec, blockchainUtils.blockchainDir())
|
||||
const cryptoRec = coinUtils.getCryptoCurrency('ZEC')
|
||||
const configPath = coinUtils.configPath(cryptoRec, blockchainUtils.blockchainDir())
|
||||
const unitScale = cryptoRec.unitScale
|
||||
|
||||
function rpcConfig () {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue