-
Notifications
You must be signed in to change notification settings - Fork 67
/
calculations.test.ts
74 lines (53 loc) · 2.37 KB
/
calculations.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import BigNumber from 'bignumber.js'
import { amountFromRay } from 'blockchain/utils'
import { SECONDS_PER_YEAR } from 'features/dsr/utils/constants'
import { calculateBreakeven, calculateEarnings, calculateYield } from 'helpers/earn/calculations'
// TODO: [Mocha -> Jest] Rewrite in Jest compatible format.
describe.skip('Yield Calculations', () => {
let stabilityFee: BigNumber
let multiply: BigNumber
let precision: number
beforeAll(() => {
stabilityFee = amountFromRay(new BigNumber('1000000000015850933588756013'))
.pow(SECONDS_PER_YEAR)
.minus(1)
multiply = new BigNumber(50)
precision = 6
})
it('Should return correct value for 7 days period', () => {
const startPrice = new BigNumber('202.157596054852200175')
const endPrice = new BigNumber('202.164207670283362946')
const result = calculateYield(startPrice, endPrice, stabilityFee, 7, multiply)
const expected = new BigNumber('0.060767268119203480765725028777122528')
expect(result.toFixed(precision)).toBe(expected.toFixed(precision))
})
it('Should return correct value for 30 days period', () => {
const startPrice = new BigNumber('202.077662061032449692')
const endPrice = new BigNumber('202.164207670283362946')
const result = calculateYield(startPrice, endPrice, stabilityFee, 30, multiply)
const expected = new BigNumber('0.236036362226332613195601087768901528')
expect(result.toFixed(precision)).toBe(expected.toFixed(precision))
})
})
describe('Breakeven Calculations', () => {
const precision = 6
it('Should return correct breakeven amount', () => {
const depositAmount = new BigNumber(100000)
const apy = new BigNumber(0.1) // 10%
const entryFees = new BigNumber(4000)
const result = calculateBreakeven({ depositAmount, entryFees, apy })
const expected = new BigNumber(146.0) // days
expect(result.toFixed(precision)).toBe(expected.toFixed(precision))
})
})
describe('Earnings Calculations', () => {
const precision = 6
it('Should return correct earnings and net value positions', () => {
const depositAmount = new BigNumber(100000)
const apy = new BigNumber(0.1) // 10%
const days = new BigNumber(30)
const { netValue: result } = calculateEarnings({ depositAmount, apy, days })
const expected = new BigNumber(100821.917808)
expect(result.toFixed(precision)).toBe(expected.toFixed(precision))
})
})