-
Notifications
You must be signed in to change notification settings - Fork 67
/
manageMultiplyVaultAdjustPositionValidations.test.ts
125 lines (103 loc) · 4.44 KB
/
manageMultiplyVaultAdjustPositionValidations.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import BigNumber from 'bignumber.js'
import { mockManageMultiplyVault$ } from 'helpers/mocks/manageMultiplyVault.mock'
import { mockedStopLossTrigger } from 'helpers/mocks/stopLoss.mock'
import { getStateUnpacker } from 'helpers/testHelpers'
import { zero } from 'helpers/zero'
import { of } from 'rxjs'
import { legacyToggle } from './legacyToggle'
// TODO: [Mocha -> Jest] Rewrite in Jest compatible format.
describe.skip('manageVaultAdjustPositionValidations', () => {
beforeAll(() => {
// TODO: remove after mainnet deployment
window.location.search = ['?network=goerli'] as any
})
afterAll(() => {
window.location.search = [] as any
})
// TO DO, calculations are off at current price
it('validates if required collateralization ratio is putting vault at risk, danger or exceeding day yield', () => {
const requiredCollRatioYield = new BigNumber('1.49')
const requiredCollRatioDanger = new BigNumber('1.75')
const requiredCollRatioWarning = new BigNumber('2.25')
const state = getStateUnpacker(mockManageMultiplyVault$())
state().updateRequiredCollRatio!(requiredCollRatioYield)
expect(state().errorMessages).toEqual(['generateAmountExceedsDaiYieldFromTotalCollateral'])
state().updateRequiredCollRatio!(requiredCollRatioDanger)
expect(state().warningMessages).toEqual([
'vaultWillBeAtRiskLevelDanger',
'vaultWillBeAtRiskLevelWarningAtNextPrice',
])
state().updateRequiredCollRatio!(requiredCollRatioWarning)
expect(state().warningMessages).toEqual(['vaultWillBeAtRiskLevelWarning'])
})
it('validates if required collateralization ratio is putting vault at risk, danger or exceeds dai yield from total collateral at next price', () => {
const requiredCollRatioYieldNextPrice = new BigNumber('1.6')
const requiredCollRatioDangerNextPrice = new BigNumber('1.85')
const requiredCollRatioWarningNextPrice = new BigNumber('2.3')
const state = getStateUnpacker(
mockManageMultiplyVault$({
vault: {
collateral: new BigNumber('25'),
},
priceInfo: {
collateralChangePercentage: new BigNumber('-0.1'),
},
}),
)
state().updateRequiredCollRatio!(requiredCollRatioYieldNextPrice)
expect(state().errorMessages).toEqual([
'generateAmountExceedsDaiYieldFromTotalCollateralAtNextPrice',
])
state().updateRequiredCollRatio!(requiredCollRatioDangerNextPrice)
expect(state().warningMessages).toEqual([
'vaultWillBeAtRiskLevelDangerAtNextPrice',
'vaultWillBeAtRiskLevelWarning',
])
state().updateRequiredCollRatio!(requiredCollRatioWarningNextPrice)
expect(state().warningMessages).toEqual(['vaultWillBeAtRiskLevelWarningAtNextPrice'])
})
it(`validates if adjust action doesn't exceeds debt ceiling, debt floor`, () => {
const requiredCollRatioExceeds = new BigNumber('1.75')
const requiredCollRatioBelow = new BigNumber('150')
const state = getStateUnpacker(
mockManageMultiplyVault$({
ilkData: {
debtCeiling: new BigNumber('8000500'),
debtFloor: new BigNumber('2000'),
},
vault: {
collateral: new BigNumber('3'),
debt: new BigNumber('500'),
ilk: 'ETH-A',
},
}),
)
state().updateRequiredCollRatio!(requiredCollRatioExceeds)
expect(state().errorMessages).toEqual(['generateAmountExceedsDebtCeiling'])
state().updateRequiredCollRatio!(requiredCollRatioBelow)
expect(state().errorMessages).toEqual(['debtWillBeLessThanDebtFloor'])
})
it('validates if vault has no collateral and can`t progress on adjust position', () => {
const state = getStateUnpacker(
mockManageMultiplyVault$({
vault: {
collateral: zero,
},
}),
)
expect(state().errorMessages).toEqual([])
legacyToggle(state())
expect(state().errorMessages).toEqual(['hasToDepositCollateralOnEmptyVault'])
expect(state().canProgress).toEqual(false)
})
it('validates if next coll ratio is below stop loss level', () => {
localStorage.setItem('features', '{"Automation":true}')
const requiredCollRatioBelowStopLoss = new BigNumber(2)
const state = getStateUnpacker(
mockManageMultiplyVault$({ _automationTriggersData$: of(mockedStopLossTrigger) }),
)
state().updateRequiredCollRatio!(requiredCollRatioBelowStopLoss)
expect(state().errorMessages).toEqual(['afterCollRatioBelowStopLossRatio'])
expect(state().canProgress).toEqual(false)
})
})