chore: server code formatting
This commit is contained in:
parent
aedabcbdee
commit
68517170e2
234 changed files with 9824 additions and 6195 deletions
|
|
@ -2,31 +2,41 @@ const BN = require('./bn')
|
|||
const configManager = require('./new-config-manager')
|
||||
const { utils: coinUtils } = require('@lamassu/coins')
|
||||
|
||||
function truncateCrypto (cryptoAtoms, cryptoCode) {
|
||||
function truncateCrypto(cryptoAtoms, cryptoCode) {
|
||||
const DECIMAL_PLACES = 6
|
||||
if (cryptoAtoms.eq(0)) return cryptoAtoms
|
||||
|
||||
const scale = coinUtils.getCryptoCurrency(cryptoCode).unitScale
|
||||
const scaleFactor = BN(10).pow(scale)
|
||||
|
||||
return new BN(cryptoAtoms).integerValue(BN.ROUND_DOWN).div(scaleFactor)
|
||||
.decimalPlaces(DECIMAL_PLACES).times(scaleFactor)
|
||||
return new BN(cryptoAtoms)
|
||||
.integerValue(BN.ROUND_DOWN)
|
||||
.div(scaleFactor)
|
||||
.decimalPlaces(DECIMAL_PLACES)
|
||||
.times(scaleFactor)
|
||||
}
|
||||
|
||||
function fiatToCrypto (tx, rec, deviceId, config) {
|
||||
function fiatToCrypto(tx, rec, deviceId, config) {
|
||||
const usableFiat = rec.fiat - rec.cashInFee
|
||||
|
||||
const commissions = configManager.getCommissions(tx.cryptoCode, deviceId, config)
|
||||
const commissions = configManager.getCommissions(
|
||||
tx.cryptoCode,
|
||||
deviceId,
|
||||
config,
|
||||
)
|
||||
const tickerRate = new BN(tx.rawTickerPrice)
|
||||
const discount = getDiscountRate(tx.discount, commissions[tx.direction])
|
||||
const rate = tickerRate.times(discount).decimalPlaces(5)
|
||||
const unitScale = coinUtils.getCryptoCurrency(tx.cryptoCode).unitScale
|
||||
const unitScaleFactor = new BN(10).pow(unitScale)
|
||||
|
||||
return truncateCrypto(new BN(usableFiat).div(rate.div(unitScaleFactor)), tx.cryptoCode)
|
||||
return truncateCrypto(
|
||||
new BN(usableFiat).div(rate.div(unitScaleFactor)),
|
||||
tx.cryptoCode,
|
||||
)
|
||||
}
|
||||
|
||||
function getDiscountRate (discount, commission) {
|
||||
function getDiscountRate(discount, commission) {
|
||||
const bnDiscount = discount ? new BN(discount) : new BN(0)
|
||||
const bnCommission = new BN(commission)
|
||||
const percentageDiscount = new BN(1).minus(bnDiscount.div(100))
|
||||
|
|
@ -36,5 +46,5 @@ function getDiscountRate (discount, commission) {
|
|||
|
||||
module.exports = {
|
||||
fiatToCrypto,
|
||||
getDiscountRate
|
||||
getDiscountRate,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue