Skip to content

Commit

Permalink
Merge pull request #893 from CrypticaScriptura/usdt-backport
Browse files Browse the repository at this point in the history
LAM-801 fix: backport USDT ratchet fix
  • Loading branch information
RafaelTaranto authored Jan 10, 2023
2 parents f50c1ca + a8a2a68 commit 5052580
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
10 changes: 4 additions & 6 deletions lib/tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ function mergeTx (oldTx, updateTx) {
const bills = _.unionBy(_.get('id'), oldTx.bills, updateTx.bills)
const cryptoCode = oldTx.cryptoCode
const mergedTx = _.defaults(oldTx, updateTx)
const cashInFee = mergedTx.cashInFee ? BN(mergedTx.cashInFee) : BN(0)
// BACKWARDS_COMPATIBILITY 8.1
// servers before 8.1 expect a cashInFeeCrypto field
const cashInFeeCrypto = BN(0)

const cashInNewFields = () => ({
bills,
fiat: updateTx.fiat ? oldTx.fiat.add(updateTx.fiat) : oldTx.fiat,
cryptoAtoms: truncateCrypto(
_.reduce((acc, v) => acc.add(toCrypto(mergedTx, BN(v.fiat).minus(v.cashInFee))), BN(0), bills),
cryptoCode),
cashInFeeCrypto: truncateCrypto(toCrypto(mergedTx, cashInFee), cryptoCode)
cashInFeeCrypto: cashInFeeCrypto
})

const cashOutNewFields = () => ({
Expand Down Expand Up @@ -172,20 +174,16 @@ function createBillDeprecated (bill, exchangeRate, tx) {
const atomRate = exchangeRate.div(unitScaleFactor)
const fiatCode = tx.fiatCode
const cashInFee = applyCashInFee ? tx.cashInFee : BN(0)
const cashInFeeCrypto = truncateCrypto(cashInFee.div(atomRate), cryptoCode)
const cryptoAtoms = truncateCrypto(BN(bill).div(atomRate), cryptoCode)
const cryptoAtomsAfterFee = truncateCrypto(cryptoAtoms.sub(cashInFeeCrypto), cryptoCode)
const deviceTime = Date.now()

return {
id: uuid.v4(),
fiat: BN(bill),
fiatCode,
cryptoAtoms,
cryptoAtomsAfterFee,
cryptoCode,
cashInFee,
cashInFeeCrypto,
cashInTxsId: tx.id,
deviceTime
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "lamassu-machine",
"license": "Unlicense",
"version": "8.0.4",
"version": "8.0.6",
"dependencies": {
"@fczbkk/uuid4": "^3.0.0",
"@lamassu/coins": "1.2.0",
Expand Down

0 comments on commit 5052580

Please sign in to comment.