Skip to content

Commit

Permalink
Merge pull request #392 from ZIMkaRU/feature/show-taxable-payment-amo…
Browse files Browse the repository at this point in the history
…unts-in-tax-report

Show taxable payment amounts in tax report
  • Loading branch information
ezewer authored Jul 10, 2024
2 parents 00ba285 + c04636c commit ced562d
Show file tree
Hide file tree
Showing 15 changed files with 356 additions and 69 deletions.
6 changes: 4 additions & 2 deletions test/test-cases/additional-api-sync-mode-sqlite-test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ module.exports = (
'mtsSold',
'proceeds',
'cost',
'gainOrLoss'
'gainOrLoss',
'type'
])
})
})
Expand Down Expand Up @@ -484,7 +485,8 @@ module.exports = (
'mtsSold',
'proceeds',
'cost',
'gainOrLoss'
'gainOrLoss',
'type'
])
})
})
Expand Down
14 changes: 12 additions & 2 deletions workers/loc.api/sync/movements/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,12 @@ class Movements {
amountUsd,
subUserId,
_id,
exactUsdValue
exactUsdValue,

_isAirdropOnWallet,
_isMarginFundingPayment,
_isAffiliateRebate,
_isStakingPayments
} = ledger

return {
Expand All @@ -309,7 +314,12 @@ class Movements {
subUserId,
isLedgers: true,
_id,
exactUsdValue
exactUsdValue,

_isAirdropOnWallet,
_isMarginFundingPayment,
_isAffiliateRebate,
_isStakingPayments
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ const mockTradesForNextYear = [
}
]
const mockTrades = [
{
isAdditionalTrxMovements: true,
isTaxablePayment: true,
isMarginFundingPayment: true,
symbol: 'tEURUSD',
mtsCreate: Date.UTC(2023, 6, 23),
execAmount: 2.11,
execPrice: 1.05,
firstSymbPriceUsd: 1.05,
lastSymbPriceUsd: 1
},
{
symbol: 'tUSTEUR',
mtsCreate: Date.UTC(2023, 6, 21),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,70 +91,87 @@ describe('lookUpTrades helper for trx tax report', () => {
)

assert.isArray(saleTradesWithRealizedProfit)
assert.equal(saleTradesWithRealizedProfit.length, 7)
assert.equal(saleTradesWithRealizedProfit.length, 8)

testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 0, {
asset: 'EUR',
amount: 2.11,
mtsAcquired: Date.UTC(2023, 6, 23),
mtsSold: null,
proceeds: 2.2155,
cost: null,
gainOrLoss: 2.2155,
type: 'MARGIN_FUNDING_PAYMENT'
})
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 1, {
asset: 'UST',
amount: 100,
mtsAcquired: Date.UTC(2023, 5, 11),
mtsSold: Date.UTC(2023, 6, 21),
proceeds: 105,
cost: 111,
gainOrLoss: -6
gainOrLoss: -6,
type: 'EXCHANGE'
})
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 1, {
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 2, {
asset: 'ETH',
amount: 1,
mtsAcquired: Date.UTC(2023, 2, 23),
mtsSold: Date.UTC(2023, 5, 11),
proceeds: 3_110,
cost: 2_601,
gainOrLoss: 509
gainOrLoss: 509,
type: 'EXCHANGE'
})
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 2, {
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 3, {
asset: 'ETH',
amount: 1,
mtsAcquired: Date.UTC(2023, 2, 23),
mtsSold: Date.UTC(2023, 4, 22),
proceeds: 2_650,
cost: 2_601,
gainOrLoss: 49
gainOrLoss: 49,
type: 'EXCHANGE'
})
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 3, {
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 4, {
asset: 'ETH',
amount: 1,
mtsAcquired: Date.UTC(2023, 2, 23),
mtsSold: Date.UTC(2023, 4, 10),
proceeds: 2_000,
cost: 2_601,
gainOrLoss: -601
gainOrLoss: -601,
type: 'EXCHANGE'
})
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 4, {
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 5, {
asset: 'ETH',
amount: 2,
mtsAcquired: Date.UTC(2023, 2, 23),
mtsSold: Date.UTC(2023, 3, 10),
proceeds: 6_400,
cost: 5_202,
gainOrLoss: 1_198
gainOrLoss: 1_198,
type: 'EXCHANGE'
})
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 5, {
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 6, {
asset: 'BTC',
amount: 0.5,
mtsAcquired: Date.UTC(2023, 1, 5),
mtsSold: Date.UTC(2023, 2, 23),
proceeds: 25_000,
cost: 21_500,
gainOrLoss: 3_500
gainOrLoss: 3_500,
type: 'EXCHANGE'
})
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 6, {
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 7, {
asset: 'BTC',
amount: 2,
mtsAcquired: Date.UTC(2023, 1, 5),
mtsSold: Date.UTC(2023, 2, 3),
proceeds: 66_000,
cost: 86_000,
gainOrLoss: -20_000
gainOrLoss: -20_000,
type: 'EXCHANGE'
})
})

Expand Down Expand Up @@ -235,70 +252,87 @@ describe('lookUpTrades helper for trx tax report', () => {
)

assert.isArray(saleTradesWithRealizedProfit)
assert.equal(saleTradesWithRealizedProfit.length, 7)
assert.equal(saleTradesWithRealizedProfit.length, 8)

testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 0, {
asset: 'EUR',
amount: 2.11,
mtsAcquired: Date.UTC(2023, 6, 23),
mtsSold: null,
proceeds: 2.2155,
cost: null,
gainOrLoss: 2.2155,
type: 'MARGIN_FUNDING_PAYMENT'
})
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 1, {
asset: 'UST',
amount: 100,
mtsAcquired: Date.UTC(2023, 5, 11),
mtsSold: Date.UTC(2023, 6, 21),
proceeds: 105,
cost: 111,
gainOrLoss: -6
gainOrLoss: -6,
type: 'EXCHANGE'
})
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 1, {
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 2, {
asset: 'ETH',
amount: 1,
mtsAcquired: Date.UTC(2023, 2, 23),
mtsSold: Date.UTC(2023, 5, 11),
proceeds: 3_110,
cost: 2_601,
gainOrLoss: 509
gainOrLoss: 509,
type: 'EXCHANGE'
})
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 2, {
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 3, {
asset: 'ETH',
amount: 1,
mtsAcquired: Date.UTC(2023, 2, 23),
mtsSold: Date.UTC(2023, 4, 22),
proceeds: 2_650,
cost: 2_601,
gainOrLoss: 49
gainOrLoss: 49,
type: 'EXCHANGE'
})
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 3, {
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 4, {
asset: 'ETH',
amount: 1,
mtsAcquired: Date.UTC(2023, 2, 23),
mtsSold: Date.UTC(2023, 4, 10),
proceeds: 2_000,
cost: 2_601,
gainOrLoss: -601
gainOrLoss: -601,
type: 'EXCHANGE'
})
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 4, {
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 5, {
asset: 'ETH',
amount: 2,
mtsAcquired: Date.UTC(2023, 2, 23),
mtsSold: Date.UTC(2023, 3, 10),
proceeds: 6_400,
cost: 5_202,
gainOrLoss: 1_198
gainOrLoss: 1_198,
type: 'EXCHANGE'
})
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 5, {
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 6, {
asset: 'BTC',
amount: 0.5,
mtsAcquired: Date.UTC(2023, 0, 10),
mtsSold: Date.UTC(2023, 2, 23),
proceeds: 25_000,
cost: 10_000,
gainOrLoss: 15_000
gainOrLoss: 15_000,
type: 'EXCHANGE'
})
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 6, {
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 7, {
asset: 'BTC',
amount: 2,
mtsAcquired: Date.UTC(2023, 0, 10),
mtsSold: Date.UTC(2023, 2, 3),
proceeds: 66_000,
cost: 40_000,
gainOrLoss: 26_000
gainOrLoss: 26_000,
type: 'EXCHANGE'
})
})

Expand Down Expand Up @@ -339,7 +373,8 @@ describe('lookUpTrades helper for trx tax report', () => {
mtsSold: Date.UTC(2024, 3, 27),
proceeds: 196,
cost: 222,
gainOrLoss: -26
gainOrLoss: -26,
type: 'EXCHANGE'
})
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 1, {
asset: 'BTC',
Expand All @@ -348,7 +383,8 @@ describe('lookUpTrades helper for trx tax report', () => {
mtsSold: Date.UTC(2024, 2, 17),
proceeds: 305_000,
cost: 220_275,
gainOrLoss: 84_725
gainOrLoss: 84_725,
type: 'EXCHANGE'
})
})

Expand Down Expand Up @@ -389,7 +425,8 @@ describe('lookUpTrades helper for trx tax report', () => {
mtsSold: Date.UTC(2024, 3, 27),
proceeds: 196,
cost: 222,
gainOrLoss: -26
gainOrLoss: -26,
type: 'EXCHANGE'
})
testSaleTradesWithRealizedProfit(saleTradesWithRealizedProfit, 1, {
asset: 'BTC',
Expand All @@ -398,7 +435,8 @@ describe('lookUpTrades helper for trx tax report', () => {
mtsSold: Date.UTC(2024, 2, 17),
proceeds: 305_000,
cost: 215_000,
gainOrLoss: 90_000
gainOrLoss: 90_000,
type: 'EXCHANGE'
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ module.exports = (arr, index, props) => {
mtsSold,
proceeds,
cost,
gainOrLoss
gainOrLoss,
type
} = props ?? {}

assert.isObject(trade)
Expand All @@ -22,12 +23,26 @@ module.exports = (arr, index, props) => {
assert.equal(trade.amount, amount)
assert.isNumber(trade.mtsAcquired)
assert.equal(trade.mtsAcquired, mtsAcquired)
assert.isNumber(trade.mtsSold)
assert.equal(trade.mtsSold, mtsSold)

if (mtsSold === null) {
assert.isNull(trade.mtsSold)
} else {
assert.isNumber(trade.mtsSold)
assert.equal(trade.mtsSold, mtsSold)
}

assert.isNumber(trade.proceeds)
assert.equal(trade.proceeds, proceeds)
assert.isNumber(trade.cost)
assert.equal(trade.cost, cost)

if (cost === null) {
assert.isNull(trade.cost)
} else {
assert.isNumber(trade.cost)
assert.equal(trade.cost, cost)
}

assert.isNumber(trade.gainOrLoss)
assert.equal(trade.gainOrLoss, gainOrLoss)
assert.isString(trade.type)
assert.equal(trade.type, type)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

const TrxPriceCalculator = require('./trx.price.calculator')

module.exports = (symbol, trxPriceCalculator) => {
if (trxPriceCalculator?.kindOfCcyForTriangulation === TrxPriceCalculator.IS_FOREX_CCY_FOR_TRIANGULATION) {
const symbSeparator = (
symbol.length > 3 ||
TrxPriceCalculator.CRYPTO_CCY_FOR_TRIANGULATION > 3
)
? ':'
: ''

return `t${TrxPriceCalculator.CRYPTO_CCY_FOR_TRIANGULATION}${symbSeparator}${symbol}`
}

const symbSeparator = symbol.length > 3
? ':'
: ''

return `t${symbol}${symbSeparator}USD`
}
Loading

0 comments on commit ced562d

Please sign in to comment.