@defisaver/automation-sdk 3.2.5 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/.babelrc +3 -3
  2. package/.editorconfig +9 -9
  3. package/.env.dev +4 -4
  4. package/.eslintignore +6 -6
  5. package/.eslintrc.js +39 -39
  6. package/.mocharc.json +4 -4
  7. package/.nvmrc +1 -1
  8. package/README.md +46 -46
  9. package/cjs/abis/Erc20.json +223 -223
  10. package/cjs/abis/SubStorage.json +21 -21
  11. package/cjs/abis/UniMulticall.json +17 -17
  12. package/cjs/abis/index.d.ts +9 -9
  13. package/cjs/abis/index.js +30 -30
  14. package/cjs/abis/legacy_AaveV2Subscriptions.json +8 -8
  15. package/cjs/abis/legacy_AuthCheck.json +8 -8
  16. package/cjs/abis/legacy_CompoundV2Subscriptions.json +9 -9
  17. package/cjs/abis/legacy_MakerSubscriptions.json +9 -9
  18. package/cjs/automation/private/Automation.d.ts +12 -12
  19. package/cjs/automation/private/Automation.js +42 -42
  20. package/cjs/automation/private/LegacyAutomation.d.ts +25 -25
  21. package/cjs/automation/private/LegacyAutomation.js +118 -118
  22. package/cjs/automation/private/LegacyProtocol.d.ts +22 -22
  23. package/cjs/automation/private/LegacyProtocol.js +41 -41
  24. package/cjs/automation/private/LegacyProtocol.test.d.ts +1 -1
  25. package/cjs/automation/private/LegacyProtocol.test.js +25 -25
  26. package/cjs/automation/private/Protocol.d.ts +22 -22
  27. package/cjs/automation/private/Protocol.js +41 -41
  28. package/cjs/automation/private/Protocol.test.d.ts +1 -1
  29. package/cjs/automation/private/Protocol.test.js +25 -25
  30. package/cjs/automation/private/StrategiesAutomation.d.ts +33 -33
  31. package/cjs/automation/private/StrategiesAutomation.js +189 -189
  32. package/cjs/automation/private/StrategiesAutomation.test.d.ts +1 -1
  33. package/cjs/automation/private/StrategiesAutomation.test.js +671 -671
  34. package/cjs/automation/public/ArbitrumStrategies.d.ts +5 -5
  35. package/cjs/automation/public/ArbitrumStrategies.js +13 -13
  36. package/cjs/automation/public/BaseStrategies.d.ts +5 -5
  37. package/cjs/automation/public/BaseStrategies.js +13 -13
  38. package/cjs/automation/public/EthereumStrategies.d.ts +5 -5
  39. package/cjs/automation/public/EthereumStrategies.js +13 -13
  40. package/cjs/automation/public/OptimismStrategies.d.ts +5 -5
  41. package/cjs/automation/public/OptimismStrategies.js +13 -13
  42. package/cjs/automation/public/Strategies.test.d.ts +1 -1
  43. package/cjs/automation/public/Strategies.test.js +61 -61
  44. package/cjs/automation/public/legacy/LegacyAaveAutomation.d.ts +6 -6
  45. package/cjs/automation/public/legacy/LegacyAaveAutomation.js +20 -20
  46. package/cjs/automation/public/legacy/LegacyCompoundAutomation.d.ts +6 -6
  47. package/cjs/automation/public/legacy/LegacyCompoundAutomation.js +20 -20
  48. package/cjs/automation/public/legacy/LegacyMakerAutomation.d.ts +6 -6
  49. package/cjs/automation/public/legacy/LegacyMakerAutomation.js +20 -20
  50. package/cjs/configuration.d.ts +1 -1
  51. package/cjs/configuration.js +12 -12
  52. package/cjs/constants/index.d.ts +28 -28
  53. package/cjs/constants/index.js +674 -564
  54. package/cjs/index.d.ts +23 -23
  55. package/cjs/index.js +65 -65
  56. package/cjs/services/contractService.d.ts +12 -12
  57. package/cjs/services/contractService.js +54 -54
  58. package/cjs/services/ethereumService.d.ts +7 -7
  59. package/cjs/services/ethereumService.js +49 -49
  60. package/cjs/services/ethereumService.test.d.ts +1 -1
  61. package/cjs/services/ethereumService.test.js +242 -242
  62. package/cjs/services/strategiesService.d.ts +2 -2
  63. package/cjs/services/strategiesService.js +944 -898
  64. package/cjs/services/strategiesService.test.d.ts +1 -1
  65. package/cjs/services/strategiesService.test.js +110 -110
  66. package/cjs/services/strategySubService.d.ts +113 -111
  67. package/cjs/services/strategySubService.js +328 -314
  68. package/cjs/services/strategySubService.test.d.ts +1 -1
  69. package/cjs/services/strategySubService.test.js +1058 -936
  70. package/cjs/services/subDataService.d.ts +282 -261
  71. package/cjs/services/subDataService.js +740 -683
  72. package/cjs/services/subDataService.test.d.ts +1 -1
  73. package/cjs/services/subDataService.test.js +1458 -1282
  74. package/cjs/services/triggerService.d.ts +268 -249
  75. package/cjs/services/triggerService.js +509 -473
  76. package/cjs/services/triggerService.test.d.ts +1 -1
  77. package/cjs/services/triggerService.test.js +1139 -1045
  78. package/cjs/services/utils.d.ts +30 -30
  79. package/cjs/services/utils.js +182 -182
  80. package/cjs/services/utils.test.d.ts +1 -1
  81. package/cjs/services/utils.test.js +376 -376
  82. package/cjs/types/contracts/generated/Erc20.d.ts +53 -53
  83. package/cjs/types/contracts/generated/Erc20.js +5 -5
  84. package/cjs/types/contracts/generated/Legacy_AaveV2Subscriptions.d.ts +129 -129
  85. package/cjs/types/contracts/generated/Legacy_AaveV2Subscriptions.js +5 -5
  86. package/cjs/types/contracts/generated/Legacy_AuthCheck.d.ts +20 -20
  87. package/cjs/types/contracts/generated/Legacy_AuthCheck.js +5 -5
  88. package/cjs/types/contracts/generated/Legacy_CompoundV2Subscriptions.d.ts +128 -128
  89. package/cjs/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +5 -5
  90. package/cjs/types/contracts/generated/Legacy_MakerSubscriptions.d.ts +246 -246
  91. package/cjs/types/contracts/generated/Legacy_MakerSubscriptions.js +5 -5
  92. package/cjs/types/contracts/generated/SubStorage.d.ts +114 -114
  93. package/cjs/types/contracts/generated/SubStorage.js +5 -5
  94. package/cjs/types/contracts/generated/UniMulticall.d.ts +55 -55
  95. package/cjs/types/contracts/generated/UniMulticall.js +5 -5
  96. package/cjs/types/contracts/generated/index.d.ts +7 -7
  97. package/cjs/types/contracts/generated/index.js +2 -2
  98. package/cjs/types/contracts/generated/types.d.ts +54 -54
  99. package/cjs/types/contracts/generated/types.js +2 -2
  100. package/cjs/types/enums.d.ts +253 -226
  101. package/cjs/types/enums.js +279 -252
  102. package/cjs/types/index.d.ts +264 -248
  103. package/cjs/types/index.js +2 -2
  104. package/esm/abis/Erc20.json +223 -223
  105. package/esm/abis/SubStorage.json +21 -21
  106. package/esm/abis/UniMulticall.json +17 -17
  107. package/esm/abis/index.d.ts +9 -9
  108. package/esm/abis/index.js +18 -18
  109. package/esm/abis/legacy_AaveV2Subscriptions.json +8 -8
  110. package/esm/abis/legacy_AuthCheck.json +8 -8
  111. package/esm/abis/legacy_CompoundV2Subscriptions.json +9 -9
  112. package/esm/abis/legacy_MakerSubscriptions.json +9 -9
  113. package/esm/automation/private/Automation.d.ts +12 -12
  114. package/esm/automation/private/Automation.js +39 -39
  115. package/esm/automation/private/LegacyAutomation.d.ts +25 -25
  116. package/esm/automation/private/LegacyAutomation.js +112 -112
  117. package/esm/automation/private/LegacyProtocol.d.ts +22 -22
  118. package/esm/automation/private/LegacyProtocol.js +38 -38
  119. package/esm/automation/private/LegacyProtocol.test.d.ts +1 -1
  120. package/esm/automation/private/LegacyProtocol.test.js +20 -20
  121. package/esm/automation/private/Protocol.d.ts +22 -22
  122. package/esm/automation/private/Protocol.js +38 -38
  123. package/esm/automation/private/Protocol.test.d.ts +1 -1
  124. package/esm/automation/private/Protocol.test.js +20 -20
  125. package/esm/automation/private/StrategiesAutomation.d.ts +33 -33
  126. package/esm/automation/private/StrategiesAutomation.js +183 -183
  127. package/esm/automation/private/StrategiesAutomation.test.d.ts +1 -1
  128. package/esm/automation/private/StrategiesAutomation.test.js +666 -666
  129. package/esm/automation/public/ArbitrumStrategies.d.ts +5 -5
  130. package/esm/automation/public/ArbitrumStrategies.js +7 -7
  131. package/esm/automation/public/BaseStrategies.d.ts +5 -5
  132. package/esm/automation/public/BaseStrategies.js +7 -7
  133. package/esm/automation/public/EthereumStrategies.d.ts +5 -5
  134. package/esm/automation/public/EthereumStrategies.js +7 -7
  135. package/esm/automation/public/OptimismStrategies.d.ts +5 -5
  136. package/esm/automation/public/OptimismStrategies.js +7 -7
  137. package/esm/automation/public/Strategies.test.d.ts +1 -1
  138. package/esm/automation/public/Strategies.test.js +56 -56
  139. package/esm/automation/public/legacy/LegacyAaveAutomation.d.ts +6 -6
  140. package/esm/automation/public/legacy/LegacyAaveAutomation.js +14 -14
  141. package/esm/automation/public/legacy/LegacyCompoundAutomation.d.ts +6 -6
  142. package/esm/automation/public/legacy/LegacyCompoundAutomation.js +14 -14
  143. package/esm/automation/public/legacy/LegacyMakerAutomation.d.ts +6 -6
  144. package/esm/automation/public/legacy/LegacyMakerAutomation.js +14 -14
  145. package/esm/configuration.d.ts +1 -1
  146. package/esm/configuration.js +7 -7
  147. package/esm/constants/index.d.ts +28 -28
  148. package/esm/constants/index.js +668 -558
  149. package/esm/index.d.ts +23 -23
  150. package/esm/index.js +23 -23
  151. package/esm/services/contractService.d.ts +12 -12
  152. package/esm/services/contractService.js +45 -45
  153. package/esm/services/ethereumService.d.ts +7 -7
  154. package/esm/services/ethereumService.js +41 -41
  155. package/esm/services/ethereumService.test.d.ts +1 -1
  156. package/esm/services/ethereumService.test.js +237 -237
  157. package/esm/services/strategiesService.d.ts +2 -2
  158. package/esm/services/strategiesService.js +914 -868
  159. package/esm/services/strategiesService.test.d.ts +1 -1
  160. package/esm/services/strategiesService.test.js +108 -108
  161. package/esm/services/strategySubService.d.ts +113 -111
  162. package/esm/services/strategySubService.js +299 -285
  163. package/esm/services/strategySubService.test.d.ts +1 -1
  164. package/esm/services/strategySubService.test.js +1030 -908
  165. package/esm/services/subDataService.d.ts +282 -261
  166. package/esm/services/subDataService.js +734 -677
  167. package/esm/services/subDataService.test.d.ts +1 -1
  168. package/esm/services/subDataService.test.js +1430 -1254
  169. package/esm/services/triggerService.d.ts +268 -249
  170. package/esm/services/triggerService.js +480 -444
  171. package/esm/services/triggerService.test.d.ts +1 -1
  172. package/esm/services/triggerService.test.js +1114 -1020
  173. package/esm/services/utils.d.ts +30 -30
  174. package/esm/services/utils.js +131 -131
  175. package/esm/services/utils.test.d.ts +1 -1
  176. package/esm/services/utils.test.js +348 -348
  177. package/esm/types/contracts/generated/Erc20.d.ts +53 -53
  178. package/esm/types/contracts/generated/Erc20.js +4 -4
  179. package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.d.ts +129 -129
  180. package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.js +4 -4
  181. package/esm/types/contracts/generated/Legacy_AuthCheck.d.ts +20 -20
  182. package/esm/types/contracts/generated/Legacy_AuthCheck.js +4 -4
  183. package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.d.ts +128 -128
  184. package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +4 -4
  185. package/esm/types/contracts/generated/Legacy_MakerSubscriptions.d.ts +246 -246
  186. package/esm/types/contracts/generated/Legacy_MakerSubscriptions.js +4 -4
  187. package/esm/types/contracts/generated/SubStorage.d.ts +114 -114
  188. package/esm/types/contracts/generated/SubStorage.js +4 -4
  189. package/esm/types/contracts/generated/UniMulticall.d.ts +55 -55
  190. package/esm/types/contracts/generated/UniMulticall.js +4 -4
  191. package/esm/types/contracts/generated/index.d.ts +7 -7
  192. package/esm/types/contracts/generated/index.js +1 -1
  193. package/esm/types/contracts/generated/types.d.ts +54 -54
  194. package/esm/types/contracts/generated/types.js +1 -1
  195. package/esm/types/enums.d.ts +253 -226
  196. package/esm/types/enums.js +276 -249
  197. package/esm/types/index.d.ts +264 -248
  198. package/esm/types/index.js +1 -1
  199. package/package.json +60 -60
  200. package/scripts/generateContractTypes.js +39 -39
  201. package/src/abis/Erc20.json +222 -222
  202. package/src/abis/SubStorage.json +21 -21
  203. package/src/abis/UniMulticall.json +17 -17
  204. package/src/abis/index.ts +28 -28
  205. package/src/abis/legacy_AaveV2Subscriptions.json +7 -7
  206. package/src/abis/legacy_AuthCheck.json +7 -7
  207. package/src/abis/legacy_CompoundV2Subscriptions.json +8 -8
  208. package/src/abis/legacy_MakerSubscriptions.json +8 -8
  209. package/src/automation/private/Automation.ts +44 -44
  210. package/src/automation/private/LegacyAutomation.ts +135 -135
  211. package/src/automation/private/LegacyProtocol.test.ts +23 -23
  212. package/src/automation/private/LegacyProtocol.ts +51 -51
  213. package/src/automation/private/Protocol.test.ts +23 -23
  214. package/src/automation/private/Protocol.ts +51 -51
  215. package/src/automation/private/StrategiesAutomation.test.ts +663 -663
  216. package/src/automation/private/StrategiesAutomation.ts +254 -254
  217. package/src/automation/public/ArbitrumStrategies.ts +10 -10
  218. package/src/automation/public/BaseStrategies.ts +10 -10
  219. package/src/automation/public/EthereumStrategies.ts +10 -10
  220. package/src/automation/public/OptimismStrategies.ts +10 -10
  221. package/src/automation/public/Strategies.test.ts +49 -49
  222. package/src/automation/public/legacy/LegacyAaveAutomation.ts +20 -20
  223. package/src/automation/public/legacy/LegacyCompoundAutomation.ts +20 -20
  224. package/src/automation/public/legacy/LegacyMakerAutomation.ts +20 -20
  225. package/src/configuration.ts +8 -8
  226. package/src/constants/index.ts +702 -593
  227. package/src/index.ts +39 -39
  228. package/src/services/contractService.ts +77 -77
  229. package/src/services/ethereumService.test.ts +257 -257
  230. package/src/services/ethereumService.ts +69 -69
  231. package/src/services/strategiesService.test.ts +105 -105
  232. package/src/services/strategiesService.ts +1216 -1158
  233. package/src/services/strategySubService.test.ts +1250 -1122
  234. package/src/services/strategySubService.ts +685 -648
  235. package/src/services/subDataService.test.ts +1546 -1387
  236. package/src/services/subDataService.ts +1024 -934
  237. package/src/services/triggerService.test.ts +1234 -1130
  238. package/src/services/triggerService.ts +659 -602
  239. package/src/services/utils.test.ts +430 -430
  240. package/src/services/utils.ts +162 -162
  241. package/src/types/enums.ts +273 -246
  242. package/src/types/index.ts +333 -312
  243. package/tsconfig.esm.json +8 -8
  244. package/tsconfig.json +22 -22
@@ -1,1130 +1,1234 @@
1
- import { expect } from 'chai';
2
- import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
3
- import * as web3Utils from 'web3-utils';
4
-
5
- import { ChainId, OrderType, RatioState } from '../types/enums';
6
- import type { EthereumAddress, TriggerData } from '../types';
7
-
8
- import '../configuration';
9
- import {
10
- aaveV2RatioTrigger,
11
- aaveV3QuotePriceTrigger,
12
- aaveV3QuotePriceWithMaximumGasPriceTrigger,
13
- aaveV3RatioTrigger,
14
- cBondsRebondTrigger,
15
- chainlinkPriceTrigger,
16
- compoundV2RatioTrigger,
17
- compoundV3RatioTrigger,
18
- curveUsdBorrowRateTrigger,
19
- curveUsdSoftLiquidationTrigger,
20
- exchangeOffchainPriceTrigger,
21
- exchangeTimestampTrigger,
22
- liquityDebtInFrontTrigger,
23
- makerRatioTrigger,
24
- morphoAaveV2RatioTrigger,
25
- sparkQuotePriceTrigger,
26
- sparkRatioTrigger,
27
- trailingStopTrigger,
28
- liquityDebtInFrontWithLimitTrigger,
29
- crvUSDRatioTrigger,
30
- morphoBlueRatioTrigger,
31
- crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger,
32
- } from './triggerService';
33
-
34
- describe('Feature: triggerService.ts', () => {
35
-
36
- describe('When testing triggerService.chainlinkPriceTrigger', () => {
37
- describe('encode()', () => {
38
- const examples: Array<[[string], [EthereumAddress, string, RatioState]]> = [
39
- [
40
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000002794ca24000000000000000000000000000000000000000000000000000000000000000000'],
41
- [getAssetInfo('WETH', ChainId.Ethereum).address, '1700', RatioState.OVER]
42
- ],
43
- [
44
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000002c3ce1ec000000000000000000000000000000000000000000000000000000000000000001'],
45
- [getAssetInfo('WETH', ChainId.Ethereum).address, '1900', RatioState.UNDER]
46
- ],
47
- ];
48
-
49
- examples.forEach(([expected, actual]) => {
50
- it(`Given ${actual} should return expected value: ${expected}`, () => {
51
- expect(chainlinkPriceTrigger.encode(...actual)).to.eql(expected);
52
- });
53
- });
54
- });
55
-
56
- describe('decode()', () => {
57
- const examples: Array<[{ tokenAddr: EthereumAddress, price: string, state: RatioState}, TriggerData]> = [
58
- [
59
- { tokenAddr: getAssetInfo('WETH', ChainId.Ethereum).address, price: '1700', state: RatioState.OVER },
60
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000002794ca24000000000000000000000000000000000000000000000000000000000000000000'],
61
- ],
62
- [
63
- { tokenAddr: getAssetInfo('WETH', ChainId.Ethereum).address, price: '1900', state: RatioState.UNDER },
64
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000002c3ce1ec000000000000000000000000000000000000000000000000000000000000000001'],
65
- ],
66
- ];
67
-
68
- examples.forEach(([expected, actual]) => {
69
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
70
- expect(chainlinkPriceTrigger.decode(actual)).to.eql(expected);
71
- });
72
- });
73
- });
74
- });
75
-
76
- describe('When testing triggerService.trailingStopTrigger', () => {
77
- describe('encode()', () => {
78
- const examples: Array<[[string], [EthereumAddress, number, number]]> = [
79
- [
80
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000002cb417800000000000000000000000000000000000000000000000000000000000000000a'],
81
- [getAssetInfo('WETH', ChainId.Ethereum).address, 120, 10]
82
- ],
83
- [
84
- ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000002cb417800000000000000000000000000000000000000000000000000000000000000000c'],
85
- [getAssetInfo('DAI', ChainId.Ethereum).address, 120, 12]
86
- ],
87
- ];
88
-
89
- examples.forEach(([expected, actual]) => {
90
- it(`Given ${actual} should return expected value: ${expected}`, () => {
91
- expect(trailingStopTrigger.encode(...actual)).to.eql(expected);
92
- });
93
- });
94
- });
95
-
96
- describe('decode()', () => {
97
- const examples: Array<[{ triggerPercentage: number, tokenAddr: EthereumAddress, roundId: string }, TriggerData]> = [
98
- [
99
- { tokenAddr: getAssetInfo('WETH', ChainId.Ethereum).address, triggerPercentage: 120, roundId: '10' },
100
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000002cb417800000000000000000000000000000000000000000000000000000000000000000a'],
101
- ],
102
- [
103
- { tokenAddr: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address), triggerPercentage: 120, roundId: '12' },
104
- ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000002cb417800000000000000000000000000000000000000000000000000000000000000000c'],
105
- ],
106
- ];
107
-
108
- examples.forEach(([expected, actual]) => {
109
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
110
- expect(trailingStopTrigger.decode(actual)).to.eql(expected);
111
- });
112
- });
113
- });
114
- });
115
-
116
- describe('When testing triggerService.makerRatioTrigger', () => {
117
- describe('encode()', () => {
118
- const examples: Array<[[string], [number, number, RatioState]]> = [
119
- [
120
- ['0x0000000000000000000000000000000000000000000000000000000000000520000000000000000000000000000000000000000000000000122e0e0f2fc300000000000000000000000000000000000000000000000000000000000000000001'],
121
- [1312, 131, RatioState.UNDER]
122
- ],
123
- [
124
- ['0x000000000000000000000000000000000000000000000000000000000000a455000000000000000000000000000000000000000000000000200ec4c2d72700000000000000000000000000000000000000000000000000000000000000000000'],
125
- [42069, 231, RatioState.OVER]
126
- ],
127
- ];
128
-
129
- examples.forEach(([expected, actual]) => {
130
- it(`Given ${actual} should return expected value: ${expected}`, () => {
131
- expect(makerRatioTrigger.encode(...actual)).to.eql(expected);
132
- });
133
- });
134
- });
135
-
136
- describe('decode()', () => {
137
- const examples: Array<[{ vaultId: number, ratioState: number, ratio: number }, TriggerData]> = [
138
- [
139
- { vaultId: 1312, ratioState: RatioState.UNDER, ratio: 131 },
140
- ['0x0000000000000000000000000000000000000000000000000000000000000520000000000000000000000000000000000000000000000000122e0e0f2fc300000000000000000000000000000000000000000000000000000000000000000001'],
141
- ],
142
- [
143
- { vaultId: 42069, ratioState: RatioState.OVER, ratio: 231 },
144
- ['0x000000000000000000000000000000000000000000000000000000000000a455000000000000000000000000000000000000000000000000200ec4c2d72700000000000000000000000000000000000000000000000000000000000000000000'],
145
- ],
146
- ];
147
-
148
- examples.forEach(([expected, actual]) => {
149
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
150
- expect(makerRatioTrigger.decode(actual)).to.eql(expected);
151
- });
152
- });
153
- });
154
- });
155
-
156
- describe('When testing triggerService.aaveV3RatioTrigger', () => {
157
- describe('encode()', () => {
158
- const examples: Array<[[string], [owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
159
- [
160
- ['0x0000000000000000000000000039d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000000'],
161
- [web3Utils.toChecksumAddress('0x0039d218133AFaB8F2B819B1066c7E434Ad94E9c'), '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e', 120, RatioState.OVER]
162
- ],
163
- [
164
- ['0x0000000000000000000000000039d218ff3afab8f2b819b1066c7e434ad94e9f000000000000000000000000a97684ead0e402dc232d5a977953df7ecbab3cdb0000000000000000000000000000000000000000000000002c8c35fe210100000000000000000000000000000000000000000000000000000000000000000001'],
165
- [web3Utils.toChecksumAddress('0x0039d218ff3AFaB8F2B819B1066c7E434Ad94E9f'), '0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb', 321, RatioState.UNDER]
166
- ],
167
- ];
168
-
169
- examples.forEach(([expected, actual]) => {
170
- it(`Given ${actual} should return expected value: ${expected}`, () => {
171
- expect(aaveV3RatioTrigger.encode(...actual)).to.eql(expected);
172
- });
173
- });
174
- });
175
-
176
- describe('decode()', () => {
177
- const examples: Array<[{ owner: EthereumAddress, market: EthereumAddress, ratio: number, ratioState: RatioState }, TriggerData]> = [
178
- [
179
- { owner: web3Utils.toChecksumAddress('0x0039d218133AFaB8F2B819B1066c7E434Ad94E9c'), market: '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e', ratio: 120, ratioState: RatioState.OVER },
180
- ['0x0000000000000000000000000039d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000000'],
181
- ],
182
- [
183
- { owner: web3Utils.toChecksumAddress('0x0039d218ff3AFaB8F2B819B1066c7E434Ad94E9f'), market: '0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb', ratio: 321, ratioState: RatioState.UNDER },
184
- ['0x0000000000000000000000000039d218ff3afab8f2b819b1066c7e434ad94e9f000000000000000000000000a97684ead0e402dc232d5a977953df7ecbab3cdb0000000000000000000000000000000000000000000000002c8c35fe210100000000000000000000000000000000000000000000000000000000000000000001'],
185
- ],
186
- ];
187
-
188
- examples.forEach(([expected, actual]) => {
189
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
190
- expect(aaveV3RatioTrigger.decode(actual)).to.eql(expected);
191
- });
192
- });
193
- });
194
- });
195
-
196
- describe('When testing triggerService.morphoAaveV2RatioTrigger', () => {
197
- describe('encode()', () => {
198
- const examples: Array<[[string], [owner: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
199
- [
200
- ['0x0000000000000000000000000039d218133afab8f2b819b1066c7e434ad94e2c0000000000000000000000000000000000000000000000001eab7f4a799d00000000000000000000000000000000000000000000000000000000000000000001'],
201
- [web3Utils.toChecksumAddress('0x0039d218133AFaB8F2B819B1066c7E434Ad94E2c'), 221, RatioState.UNDER]
202
- ],
203
- [
204
- ['0x0000000000000000000000000032d218133afab8f2b819b1066c7e434ad94e2c0000000000000000000000000000000000000000000000003d3377a2837900000000000000000000000000000000000000000000000000000000000000000000'],
205
- [web3Utils.toChecksumAddress('0x0032d218133AFaB8F2B819B1066c7E434Ad94E2c'), 441, RatioState.OVER]
206
- ],
207
- ];
208
-
209
- examples.forEach(([expected, actual]) => {
210
- it(`Given ${actual} should return expected value: ${expected}`, () => {
211
- expect(morphoAaveV2RatioTrigger.encode(...actual)).to.eql(expected);
212
- });
213
- });
214
- });
215
-
216
- describe('decode()', () => {
217
- const examples: Array<[{ owner: EthereumAddress, ratio: number, ratioState: RatioState }, TriggerData]> = [
218
- [
219
- { owner: web3Utils.toChecksumAddress('0x0039d218133AFaB8F2B819B1066c7E434Ad94E2c'), ratio: 221, ratioState: RatioState.UNDER },
220
- ['0x0000000000000000000000000039d218133afab8f2b819b1066c7e434ad94e2c0000000000000000000000000000000000000000000000001eab7f4a799d00000000000000000000000000000000000000000000000000000000000000000001'],
221
- ],
222
- [
223
- { owner: web3Utils.toChecksumAddress('0x0032d218133AFaB8F2B819B1066c7E434Ad94E2c'), ratio: 441, ratioState: RatioState.OVER },
224
- ['0x0000000000000000000000000032d218133afab8f2b819b1066c7e434ad94e2c0000000000000000000000000000000000000000000000003d3377a2837900000000000000000000000000000000000000000000000000000000000000000000'],
225
- ],
226
- ];
227
-
228
- examples.forEach(([expected, actual]) => {
229
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
230
- expect(morphoAaveV2RatioTrigger.decode(actual)).to.eql(expected);
231
- });
232
- });
233
- });
234
- });
235
-
236
- describe('When testing triggerService.aaveV3QuotePriceTrigger', () => {
237
- describe('encode()', () => {
238
- const examples: Array<[[string], [baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState]]> = [
239
- [
240
- ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000009c400000000000000000000000000000000000000000000000000000000000000001'],
241
- [getAssetInfo('DAI', ChainId.Ethereum).address, getAssetInfo('WETH', ChainId.Ethereum).address, 0.0004, RatioState.UNDER]
242
- ],
243
- [
244
- ['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000fd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb900000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000000'],
245
- [getAssetInfo('WBTC', ChainId.Arbitrum).address, getAssetInfo('USDT', ChainId.Arbitrum).address, 0.00000023, RatioState.OVER]
246
- ],
247
- ];
248
-
249
- examples.forEach(([expected, actual]) => {
250
- it(`Given ${actual} should return expected value: ${expected}`, () => {
251
- expect(aaveV3QuotePriceTrigger.encode(...actual)).to.eql(expected);
252
- });
253
- });
254
- });
255
-
256
- describe('decode()', () => {
257
- const examples: Array<[{ baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: string, ratioState: RatioState }, TriggerData]> = [
258
- [
259
- {
260
- baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
261
- quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
262
- price: '0.0004',
263
- ratioState: RatioState.UNDER,
264
- },
265
- ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000009c400000000000000000000000000000000000000000000000000000000000000001'],
266
- ],
267
- [
268
- {
269
- baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
270
- quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('USDT', ChainId.Arbitrum).address),
271
- price: '0.00000023',
272
- ratioState: RatioState.OVER,
273
- },
274
- ['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000fd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb900000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000000'],
275
- ]
276
- ];
277
-
278
- examples.forEach(([expected, actual]) => {
279
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
280
- expect(aaveV3QuotePriceTrigger.decode(actual)).to.eql(expected);
281
- });
282
- });
283
- });
284
- });
285
-
286
- describe('When testing triggerService.aaveV3QuotePriceWithMaximumGasPriceTrigger', () => {
287
- describe('encode()', () => {
288
- const examples: Array<[TriggerData, [baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState, maximumGasPriceInGwei?: number]]> = [
289
- [
290
- [
291
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000009c400000000000000000000000000000000000000000000000000000000000000001',
292
- '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
293
- ],
294
- [getAssetInfo('DAI', ChainId.Ethereum).address, getAssetInfo('WETH', ChainId.Ethereum).address, 0.0004, RatioState.UNDER]
295
- ],
296
- [
297
- [
298
- '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000000',
299
- '0x00000000000000000000000000000000000000000000000000000002cb417800',
300
- ],
301
- [getAssetInfo('WBTC', ChainId.Ethereum).address, getAssetInfo('USDT', ChainId.Ethereum).address, 0.00000023, RatioState.OVER, 12]
302
- ],
303
- ];
304
-
305
- examples.forEach(([expected, actual]) => {
306
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
307
- expect(aaveV3QuotePriceWithMaximumGasPriceTrigger.encode(...actual)).to.eql(expected);
308
- });
309
- });
310
- });
311
-
312
- describe('decode()', () => {
313
- const examples: Array<[{ baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: string, ratioState: RatioState, maximumGasPrice: string }, TriggerData]> = [
314
- [
315
- {
316
- baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
317
- quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
318
- price: '0.0004',
319
- ratioState: RatioState.UNDER,
320
- maximumGasPrice: web3Utils.fromWei(MAXUINT, 'gwei')
321
- },
322
- [
323
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000009c400000000000000000000000000000000000000000000000000000000000000001',
324
- '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
325
- ],
326
- ],
327
- [
328
- {
329
- baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
330
- quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('USDT', ChainId.Ethereum).address),
331
- price: '0.00000023',
332
- ratioState: RatioState.OVER,
333
- maximumGasPrice: '12',
334
- },
335
- [
336
- '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000000',
337
- '0x00000000000000000000000000000000000000000000000000000002cb417800',
338
- ],
339
- ]
340
- ];
341
-
342
- examples.forEach(([expected, actual]) => {
343
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
344
- expect(aaveV3QuotePriceWithMaximumGasPriceTrigger.decode(actual)).to.eql(expected);
345
- });
346
- });
347
- });
348
- });
349
-
350
- describe('When testing triggerService.liquityRatioTrigger', () => {
351
- describe('encode()', () => {
352
- const examples: Array<[[string], [owner: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
353
- [
354
- ['0x0000000000000000000000000039d218133afab8f2b819b1066c7e434ad94e2c00000000000000000000000000000000000000000000000029c5ab0d65ed00000000000000000000000000000000000000000000000000000000000000000001'],
355
- [web3Utils.toChecksumAddress('0x0039d218133AFaB8F2B819B1066c7E434Ad94E2c'), 301, RatioState.UNDER]
356
- ],
357
- [
358
- ['0x0000000000000000000000000039d218133afab832b819b1066c7e434ad94e2c000000000000000000000000000000000000000000000000122e0e0f2fc300000000000000000000000000000000000000000000000000000000000000000000'],
359
- [web3Utils.toChecksumAddress('0x0039d218133AFaB832B819B1066c7E434Ad94E2c'), 131, RatioState.OVER]
360
- ],
361
- ];
362
-
363
- examples.forEach(([expected, actual]) => {
364
- it(`Given ${actual} should return expected value: ${expected}`, () => {
365
- expect(compoundV2RatioTrigger.encode(...actual)).to.eql(expected);
366
- });
367
- });
368
- });
369
-
370
- describe('decode()', () => {
371
- const examples: Array<[{ owner: EthereumAddress, ratioState: RatioState, ratio: number }, TriggerData]> = [
372
- [
373
- {
374
- owner: web3Utils.toChecksumAddress('0x0039d218133AFaB8F2B819B1066c7E434Ad94E2c'),
375
- ratio: 301,
376
- ratioState: RatioState.UNDER,
377
- },
378
- ['0x0000000000000000000000000039d218133afab8f2b819b1066c7e434ad94e2c00000000000000000000000000000000000000000000000029c5ab0d65ed00000000000000000000000000000000000000000000000000000000000000000001'],
379
- ],
380
- [
381
- {
382
- owner: web3Utils.toChecksumAddress('0x0039d218133AFaB832B819B1066c7E434Ad94E2c'),
383
- ratio: 131,
384
- ratioState: RatioState.OVER,
385
- },
386
- ['0x0000000000000000000000000039d218133afab832b819b1066c7e434ad94e2c000000000000000000000000000000000000000000000000122e0e0f2fc300000000000000000000000000000000000000000000000000000000000000000000'],
387
- ],
388
- ];
389
-
390
- examples.forEach(([expected, actual]) => {
391
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
392
- expect(compoundV2RatioTrigger.decode(actual)).to.eql(expected);
393
- });
394
- });
395
- });
396
- });
397
-
398
- describe('When testing triggerService.liquityDebtInFrontTrigger', () => {
399
- describe('encode()', () => {
400
- const examples: Array<[[string], [owner: EthereumAddress, debtInFrontMin: string]]> = [
401
- [
402
- ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000006e0be8c4995af80000'],
403
- [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'), '2030']
404
- ],
405
- [
406
- ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000004697f83e6356dd440000'],
407
- [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'), '333369']
408
- ],
409
- [
410
- ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf000000000000000000000000000000000000000000084595161401484a000000'],
411
- [web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'), '10000000']
412
- ],
413
- [
414
- ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf0000000000000000000000000000000000000000000000000000000000989680'],
415
- [web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'), '0.00000000001']
416
- ],
417
- [
418
- ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a0000000000000000000000000000000000000000019d971e4fe8401e74000000'],
419
- [web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'), '500000000']
420
- ],
421
- [
422
- ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a00000000000000000000000000000000000000000001a784379d99db42000000'],
423
- [web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'), '2000000']
424
- ],
425
- ];
426
-
427
- examples.forEach(([expected, actual]) => {
428
- it(`Given ${actual} should return expected value: ${expected}`, () => {
429
- expect(liquityDebtInFrontTrigger.encode(...actual)).to.eql(expected);
430
- expect(liquityDebtInFrontWithLimitTrigger.encode(...actual)).to.eql(expected);
431
- });
432
- });
433
- });
434
-
435
- describe('decode()', () => {
436
- const examples: Array<[{ owner: EthereumAddress, debtInFrontMin: string }, TriggerData]> = [
437
- [
438
- {
439
- owner: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'),
440
- debtInFrontMin: '2030',
441
- },
442
- ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000006e0be8c4995af80000'],
443
- ],
444
- [
445
- {
446
- owner: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'),
447
- debtInFrontMin: '333369',
448
- },
449
- ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000004697f83e6356dd440000'],
450
- ],
451
- [
452
- {
453
- owner: web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'),
454
- debtInFrontMin: '10000000',
455
- },
456
- ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf000000000000000000000000000000000000000000084595161401484a000000'],
457
- ],
458
- [
459
- {
460
- owner: web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'),
461
- debtInFrontMin: '0.00000000001',
462
- },
463
- ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf0000000000000000000000000000000000000000000000000000000000989680'],
464
- ],
465
- [
466
- {
467
- owner: web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'),
468
- debtInFrontMin: '500000000',
469
- },
470
- ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a0000000000000000000000000000000000000000019d971e4fe8401e74000000'],
471
- ],
472
- [
473
- {
474
- owner: web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'),
475
- debtInFrontMin: '2000000',
476
- },
477
- ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a00000000000000000000000000000000000000000001a784379d99db42000000'],
478
- ],
479
- ];
480
-
481
- examples.forEach(([expected, actual]) => {
482
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
483
- expect(liquityDebtInFrontTrigger.decode(actual)).to.eql(expected);
484
- expect(liquityDebtInFrontWithLimitTrigger.decode(actual)).to.eql(expected);
485
- });
486
- });
487
- });
488
- });
489
-
490
- describe('When testing triggerService.liquityV2DebtInFrontTrigger', () => {
491
- describe('encode()', () => {
492
- const examples: Array<[[string], [market: EthereumAddress, troveId: string, debtInFrontMin: string]]> = [
493
- [
494
- ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd1500000000000000000000000000000000000000000000006e0be8c4995af80000'],
495
- [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'), '123456789', '2030']
496
- ],
497
- [
498
- ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1000000000000000000000000000000000000000000004697f83e6356dd440000'],
499
- [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'), '987654321', '333369']
500
- ],
501
- [
502
- ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf00000000000000000000000000000000000000000000000000000000075bd924000000000000000000000000000000000000000000084595161401484a000000'],
503
- [web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'), '123459876', '10000000']
504
- ],
505
- [
506
- ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf000000000000000000000000000000000000000000000000000000002060d4950000000000000000000000000000000000000000000000000000000000989680'],
507
- [web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'), '543216789', '0.00000000001']
508
- ],
509
- [
510
- ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a000000000000000000000000000000000000000000000000000000003ade5ca20000000000000000000000000000000000000000019d971e4fe8401e74000000'],
511
- [web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'), '987651234', '500000000']
512
- ],
513
- ];
514
-
515
- examples.forEach(([expected, actual]) => {
516
- it(`Given ${actual} should return expected value: ${expected}`, () => {
517
- expect(liquityV2DebtInFrontTrigger.encode(...actual)).to.eql(expected);
518
- });
519
- });
520
- });
521
-
522
- describe('decode()', () => {
523
- const examples: Array<[{ market: EthereumAddress, troveId: string, debtInFrontMin: string }, TriggerData]> = [
524
- [
525
- {
526
- market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'),
527
- troveId: '123456789',
528
- debtInFrontMin: '2030',
529
- },
530
- ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd1500000000000000000000000000000000000000000000006e0be8c4995af80000'],
531
- ],
532
- [
533
- {
534
- market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'),
535
- troveId: '987654321',
536
- debtInFrontMin: '333369',
537
- },
538
- ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1000000000000000000000000000000000000000000004697f83e6356dd440000'],
539
- ], [
540
- {
541
- market: web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'),
542
- troveId: '123459876',
543
- debtInFrontMin: '10000000',
544
- },
545
- ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf00000000000000000000000000000000000000000000000000000000075bd924000000000000000000000000000000000000000000084595161401484a000000'],
546
- ], [
547
- {
548
- market: web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'),
549
- troveId: '543216789',
550
- debtInFrontMin: '0.00000000001',
551
- },
552
- ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf000000000000000000000000000000000000000000000000000000002060d4950000000000000000000000000000000000000000000000000000000000989680'],
553
- ], [
554
- {
555
- market: web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'),
556
- troveId: '987651234',
557
- debtInFrontMin: '500000000',
558
- },
559
- ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a000000000000000000000000000000000000000000000000000000003ade5ca20000000000000000000000000000000000000000019d971e4fe8401e74000000'],
560
- ]
561
- ];
562
-
563
- examples.forEach(([expected, actual]) => {
564
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
565
- expect(liquityV2DebtInFrontTrigger.decode(actual)).to.eql(expected);
566
- });
567
- });
568
- });
569
- });
570
-
571
- describe('When testing triggerService.liquityV2AdjustTimeTrigger', () => {
572
- describe('encode()', () => {
573
- const examples: Array<[[string], [market: EthereumAddress, troveId: string]]> = [
574
- [
575
- ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd15'],
576
- [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'), '123456789']
577
- ],
578
- [
579
- ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1'],
580
- [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'), '987654321']
581
- ],
582
- ];
583
-
584
- examples.forEach(([expected, actual]) => {
585
- it(`Given ${actual} should return expected value: ${expected}`, () => {
586
- expect(liquityV2AdjustTimeTrigger.encode(...actual)).to.eql(expected);
587
- });
588
- });
589
- });
590
-
591
- describe('decode()', () => {
592
- const examples: Array<[{ market: EthereumAddress, troveId: string }, TriggerData]> = [
593
- [
594
- {
595
- market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'),
596
- troveId: '123456789',
597
- },
598
- ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd15'],
599
- ],
600
- [
601
- {
602
- market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'),
603
- troveId: '987654321',
604
- },
605
- ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1'],
606
- ]
607
- ];
608
-
609
- examples.forEach(([expected, actual]) => {
610
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
611
- expect(liquityV2AdjustTimeTrigger.decode(actual)).to.eql(expected);
612
- });
613
- });
614
- });
615
- });
616
- describe('When testing triggerService.aaveV2RatioTrigger', () => {
617
- describe('encode()', () => {
618
- const examples: Array<[[string], [owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
619
- [
620
- ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c0000000000000000000000000249d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000000'],
621
- [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'), web3Utils.toChecksumAddress('0x0249d218133AFaB8F2B829B1066c7E434Ad94E2c'), 120, RatioState.OVER]
622
- ],
623
- ];
624
-
625
- examples.forEach(([expected, actual]) => {
626
- it(`Given ${actual} should return expected value: ${expected}`, () => {
627
- expect(aaveV2RatioTrigger.encode(...actual)).to.eql(expected);
628
- });
629
- });
630
- });
631
-
632
- describe('decode()', () => {
633
- const examples: Array<[{ owner: EthereumAddress, market: EthereumAddress, ratioState: RatioState, ratio: number }, TriggerData]> = [
634
- [
635
- {
636
- owner: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'),
637
- market: web3Utils.toChecksumAddress('0x0249d218133AFaB8F2B829B1066c7E434Ad94E2c'),
638
- ratio: 120,
639
- ratioState: RatioState.OVER,
640
- },
641
- ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c0000000000000000000000000249d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000000'],
642
- ],
643
- ];
644
-
645
- examples.forEach(([expected, actual]) => {
646
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
647
- expect(aaveV2RatioTrigger.decode(actual)).to.eql(expected);
648
- });
649
- });
650
- });
651
- });
652
-
653
- describe('When testing triggerService.cBondsRebondTrigger', () => {
654
- describe('encode()', () => {
655
- const examples: Array<[[string], [bondId: number | string]]> = [
656
- [
657
- ['0x0000000000000000000000000000000000000000000000000000000000000141'],
658
- [321]
659
- ],
660
- [
661
- ['0x000000000000000000000000000000000000000000000000000000000000002c'],
662
- [44]
663
- ],
664
- ];
665
-
666
- examples.forEach(([expected, actual]) => {
667
- it(`Given ${actual} should return expected value: ${expected}`, () => {
668
- expect(cBondsRebondTrigger.encode(...actual)).to.eql(expected);
669
- });
670
- });
671
- });
672
-
673
- describe('decode()', () => {
674
- const examples: Array<[{ bondId: string }, TriggerData]> = [
675
- [
676
- { bondId: '321' },
677
- ['0x0000000000000000000000000000000000000000000000000000000000000141'],
678
- ],
679
- [
680
- { bondId: '44' },
681
- ['0x000000000000000000000000000000000000000000000000000000000000002c'],
682
- ],
683
- ];
684
-
685
- examples.forEach(([expected, actual]) => {
686
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
687
- expect(cBondsRebondTrigger.decode(actual)).to.eql(expected);
688
- });
689
- });
690
- });
691
- });
692
-
693
- describe('When testing triggerService.compoundV3RatioTrigger', () => {
694
- describe('encode()', () => {
695
- const examples: Array<[[string], [owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
696
- [
697
- ['0x0000000000000000000000000049d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000213d218133afab8f2b829b1066c7e43cad94e2c000000000000000000000000000000000000000000000000245c1c1e5f8600000000000000000000000000000000000000000000000000000000000000000000'],
698
- [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B106633E434Ad94E2c'), web3Utils.toChecksumAddress('0x0213d218133AFaB8F2B829B1066c7E43cAd94E2c'), 262, RatioState.OVER]
699
- ],
700
- [
701
- ['0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000213d212133afab8f2b829b1066c7e43cad94e2c0000000000000000000000000000000000000000000000002def7b767e8b00000000000000000000000000000000000000000000000000000000000000000001'],
702
- [web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'), 331, RatioState.UNDER]
703
- ],
704
- ];
705
-
706
- examples.forEach(([expected, actual]) => {
707
- it(`Given ${actual} should return expected value: ${expected}`, () => {
708
- expect(compoundV3RatioTrigger.encode(...actual)).to.eql(expected);
709
- });
710
- });
711
- });
712
-
713
- describe('decode()', () => {
714
- const examples: Array<[{ owner: EthereumAddress, market: EthereumAddress, ratioState: RatioState, ratio: number }, TriggerData]> = [
715
- [
716
- {
717
- owner: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B106633E434Ad94E2c'),
718
- market: web3Utils.toChecksumAddress('0x0213d218133AFaB8F2B829B1066c7E43cAd94E2c'),
719
- ratio: 262,
720
- ratioState: RatioState.OVER,
721
- },
722
- ['0x0000000000000000000000000049d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000213d218133afab8f2b829b1066c7e43cad94e2c000000000000000000000000000000000000000000000000245c1c1e5f8600000000000000000000000000000000000000000000000000000000000000000000'],
723
- ],
724
- [
725
- {
726
- owner: web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'),
727
- market: web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
728
- ratio: 331,
729
- ratioState: RatioState.UNDER,
730
- },
731
- ['0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000213d212133afab8f2b829b1066c7e43cad94e2c0000000000000000000000000000000000000000000000002def7b767e8b00000000000000000000000000000000000000000000000000000000000000000001'],
732
- ],
733
- ];
734
-
735
- examples.forEach(([expected, actual]) => {
736
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
737
- expect(compoundV3RatioTrigger.decode(actual)).to.eql(expected);
738
- });
739
- });
740
- });
741
- });
742
-
743
- describe('When testing triggerService.exchangeTimestampTrigger', () => {
744
- describe('encode()', () => {
745
- const examples: Array<[[string], [timestamp: number, interval: number]]> = [
746
- [
747
- ['0x0000000000000000000000000000000000000000000000000000018adbcdf3c10000000000000000000000000000000000000000000000000000000077359fb8'],
748
- [1695904822209, 2000003000]
749
- ],
750
- [
751
- ['0x00000000000000000000000000000000000000000000000000000189ed59a4010000000000000000000000000000000000000000000000000000000011e378b8'],
752
- [1691904222209, 300120248]
753
- ],
754
- ];
755
-
756
- examples.forEach(([expected, actual]) => {
757
- it(`Given ${actual} should return expected value: ${expected}`, () => {
758
- expect(exchangeTimestampTrigger.encode(...actual)).to.eql(expected);
759
- });
760
- });
761
- });
762
-
763
- describe('decode()', () => {
764
- const examples: Array<[{ timestamp: number, interval: number }, TriggerData]> = [
765
- [
766
- {
767
- timestamp: 1695904822209, interval: 2000003000,
768
- },
769
- ['0x0000000000000000000000000000000000000000000000000000018adbcdf3c10000000000000000000000000000000000000000000000000000000077359fb8'],
770
- ],
771
- [
772
- {
773
- timestamp: 1691904222209, interval: 300120248,
774
- },
775
- ['0x00000000000000000000000000000000000000000000000000000189ed59a4010000000000000000000000000000000000000000000000000000000011e378b8'],
776
- ],
777
- ];
778
-
779
- examples.forEach(([expected, actual]) => {
780
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
781
- expect(exchangeTimestampTrigger.decode(actual)).to.eql(expected);
782
- });
783
- });
784
- });
785
- });
786
-
787
- describe('When testing triggerService.exchangeOffchainPriceTrigger', () => {
788
- describe('encode()', () => {
789
- const examples: Array<[[string], [targetPrice: string, goodUntil: number, orderType: OrderType, fromTokenDecimals: number, toTokenDecimals: number]]> = [
790
- [
791
- ['0x00000000000000000000000000000000000000000000000001b4fbd92b5f80000000000000000000000000000000000000000000000000000000018adbcdf3c10000000000000000000000000000000000000000000000000000000000000000'],
792
- ['0.123', 1695904822209, OrderType.TAKE_PROFIT, 12, 12]
793
- ],
794
- [
795
- ['0x00000000000000000000000000000000000000000000000000000000003432120000000000000000000000000000000000000000000000000000018adbbead990000000000000000000000000000000000000000000000000000000000000001'],
796
- ['3.42069', 1695903821209, OrderType.STOP_LOSS, 18, 6]
797
- ],
798
- ];
799
-
800
- examples.forEach(([expected, actual]) => {
801
- it(`Given ${actual} should return expected value: ${expected}`, () => {
802
- expect(exchangeOffchainPriceTrigger.encode(...actual)).to.eql(expected);
803
- });
804
- });
805
- });
806
-
807
- describe('decode()', () => {
808
- const examples: Array<[{ orderType: OrderType; targetPrice: string; goodUntil: any }, [TriggerData, number, number]]> = [
809
- [
810
- {
811
- orderType: OrderType.TAKE_PROFIT, targetPrice: '0.123', goodUntil: 1695904822209,
812
- },
813
- [
814
- ['0x00000000000000000000000000000000000000000000000001b4fbd92b5f80000000000000000000000000000000000000000000000000000000018adbcdf3c10000000000000000000000000000000000000000000000000000000000000000'],
815
- 12,
816
- 12,
817
- ],
818
- ],
819
- [
820
- {
821
- orderType: OrderType.STOP_LOSS, targetPrice: '3.42069', goodUntil: 1695903821209,
822
- },
823
- [
824
- ['0x00000000000000000000000000000000000000000000000000000000003432120000000000000000000000000000000000000000000000000000018adbbead990000000000000000000000000000000000000000000000000000000000000001'],
825
- 18,
826
- 6,
827
- ],
828
- ],
829
- ];
830
-
831
- examples.forEach(([expected, actual]) => {
832
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
833
- expect(exchangeOffchainPriceTrigger.decode(...actual)).to.eql(expected);
834
- });
835
- });
836
- });
837
- });
838
-
839
- describe('When testing triggerService.sparkRatioTrigger', () => {
840
- describe('encode()', () => {
841
- const examples: Array<[[string], [owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
842
- [
843
- ['0x0000000000000000000000000031d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000001131d218133afab8f2b819b1066c7e434ad94e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
844
- [web3Utils.toChecksumAddress('0x0031d218133AFaB8F2B819B1066c7E434Ad94E9c'), web3Utils.toChecksumAddress('0x1131d218133AFaB8F2B819B1066c7E434Ad94E9c'), 120, RatioState.UNDER]
845
- ],
846
- [
847
- ['0x0000000000000000000000000231d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000000131d218133afab8f2b819b1066c7e434ad94e9c000000000000000000000000000000000000000000000000200ec4c2d72700000000000000000000000000000000000000000000000000000000000000000000'],
848
- [web3Utils.toChecksumAddress('0x0231d218133AFaB8F2B819B1066c7E434Ad94E9c'), web3Utils.toChecksumAddress('0x0131d218133AFaB8F2B819B1066c7E434Ad94E9c'), 231, RatioState.OVER]
849
- ],
850
- ];
851
-
852
- examples.forEach(([expected, actual]) => {
853
- it(`Given ${actual} should return expected value: ${expected}`, () => {
854
- expect(sparkRatioTrigger.encode(...actual)).to.eql(expected);
855
- });
856
- });
857
- });
858
-
859
- describe('decode()', () => {
860
- const examples: Array<[{ owner: EthereumAddress, market: EthereumAddress, ratio: number, ratioState: RatioState }, TriggerData]> = [
861
- [
862
- { owner: web3Utils.toChecksumAddress('0x0031d218133AFaB8F2B819B1066c7E434Ad94E9c'), market: web3Utils.toChecksumAddress('0x1131d218133AFaB8F2B819B1066c7E434Ad94E9c'), ratio: 120, ratioState: RatioState.UNDER },
863
- ['0x0000000000000000000000000031d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000001131d218133afab8f2b819b1066c7e434ad94e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
864
- ],
865
- [
866
- { owner: web3Utils.toChecksumAddress('0x0231d218133AFaB8F2B819B1066c7E434Ad94E9c'), market: web3Utils.toChecksumAddress('0x0131d218133AFaB8F2B819B1066c7E434Ad94E9c'), ratio: 231, ratioState: RatioState.OVER },
867
- ['0x0000000000000000000000000231d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000000131d218133afab8f2b819b1066c7e434ad94e9c000000000000000000000000000000000000000000000000200ec4c2d72700000000000000000000000000000000000000000000000000000000000000000000'],
868
- ],
869
- ];
870
-
871
- examples.forEach(([expected, actual]) => {
872
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
873
- expect(sparkRatioTrigger.decode(actual)).to.eql(expected);
874
- });
875
- });
876
- });
877
- });
878
-
879
- describe('When testing triggerService.sparkQuotePriceTrigger', () => {
880
- describe('encode()', () => {
881
- const examples: Array<[[string], [baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState]]> = [
882
- [
883
- ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000000000000000000000000000000000000000a8ca0000000000000000000000000000000000000000000000000000000000000001'],
884
- [getAssetInfo('DAI', ChainId.Ethereum).address, getAssetInfo('wstETH', ChainId.Ethereum).address, 0.0004321, RatioState.UNDER]
885
- ],
886
- [
887
- ['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000186b70000000000000000000000000000000000000000000000000000000000000000'],
888
- [getAssetInfo('WBTC', ChainId.Arbitrum).address, getAssetInfo('USDC', ChainId.Arbitrum).address, 0.00100023, RatioState.OVER]
889
- ],
890
- ];
891
-
892
- examples.forEach(([expected, actual]) => {
893
- it(`Given ${actual} should return expected value: ${expected}`, () => {
894
- expect(sparkQuotePriceTrigger.encode(...actual)).to.eql(expected);
895
- });
896
- });
897
- });
898
-
899
- describe('decode()', () => {
900
- const examples: Array<[{ baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: string, ratioState: RatioState }, TriggerData]> = [
901
- [
902
- {
903
- baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
904
- quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Ethereum).address),
905
- price: '0.0004321',
906
- ratioState: RatioState.UNDER,
907
- },
908
- ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000000000000000000000000000000000000000a8ca0000000000000000000000000000000000000000000000000000000000000001'],
909
- ],
910
- [
911
- {
912
- baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
913
- quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
914
- price: '0.00100023',
915
- ratioState: RatioState.OVER,
916
- },
917
- ['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000186b70000000000000000000000000000000000000000000000000000000000000000'],
918
- ]
919
- ];
920
-
921
- examples.forEach(([expected, actual]) => {
922
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
923
- expect(sparkQuotePriceTrigger.decode(actual)).to.eql(expected);
924
- });
925
- });
926
- });
927
- });
928
-
929
- describe('When testing triggerService.curveUsdBorrowRateTrigger', () => {
930
- describe('encode()', () => {
931
- const examples: Array<[[string], [market: EthereumAddress, targetRate: string, rateState: RatioState]]> = [
932
- [
933
- ['0x0000000000000000000000000031d218133afab8c2b819b1066c7e434ad91e9c000000000000000000000000000000000000000000000000000000005c3744c40000000000000000000000000000000000000000000000000000000000000001'],
934
- [web3Utils.toChecksumAddress('0x0031d218133AFaB8c2B819B1066c7E434Ad91E9c'), '5', RatioState.UNDER]
935
- ],
936
- [
937
- ['0x0000000000000000000000000031d318133afab8c2b819b1066c7e434ad91e9c0000000000000000000000000000000000000000000000000000000037de1dae0000000000000000000000000000000000000000000000000000000000000000'],
938
- [web3Utils.toChecksumAddress('0x0031d318133AFaB8c2B819B1066c7E434Ad91E9c'), '3', RatioState.OVER]
939
- ],
940
- ];
941
-
942
- examples.forEach(([expected, actual]) => {
943
- it(`Given ${actual} should return expected value: ${expected}`, () => {
944
- expect(curveUsdBorrowRateTrigger.encode(...actual)).to.eql(expected);
945
- });
946
- });
947
- });
948
-
949
- describe('decode()', () => {
950
- const examples: Array<[{ market: EthereumAddress, targetRate: string, rateState: RatioState }, TriggerData]> = [
951
- [
952
- {
953
- market: web3Utils.toChecksumAddress('0x0031d218133AFaB8c2B819B1066c7E434Ad91E9c'),
954
- // Because of precision of reverse engineered rate we can't get exact number
955
- targetRate: '4.9999999977932344260462314517997495470601974794180145018256513213117735079327887085499910715825462',
956
- rateState: RatioState.UNDER,
957
- },
958
- ['0x0000000000000000000000000031d218133afab8c2b819b1066c7e434ad91e9c000000000000000000000000000000000000000000000000000000005c3744c40000000000000000000000000000000000000000000000000000000000000001'],
959
- ],
960
- [
961
- {
962
- market: web3Utils.toChecksumAddress('0x0031d318133AFaB8c2B819B1066c7E434Ad91E9c'),
963
- // Because of precision of reverse engineered rate we can't get exact number
964
- targetRate: '2.999999998802635853596007720123861222767915626254160712723033189270277420764438661596057080730334',
965
- rateState: RatioState.OVER,
966
- },
967
- ['0x0000000000000000000000000031d318133afab8c2b819b1066c7e434ad91e9c0000000000000000000000000000000000000000000000000000000037de1dae0000000000000000000000000000000000000000000000000000000000000000'],
968
- ],
969
- ];
970
-
971
- examples.forEach(([expected, actual]) => {
972
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
973
- expect(curveUsdBorrowRateTrigger.decode(actual)).to.eql(expected);
974
- });
975
- });
976
- });
977
- });
978
-
979
- describe('When testing triggerService.curveUsdSoftLiquidationTrigger', () => {
980
- describe('encode()', () => {
981
- const examples: Array<[[string], [market: EthereumAddress, market: EthereumAddress, percentage: string]]> = [
982
- [
983
- ['0x0000000000000000000000000031d218133afab8c2a819b1066c7e434ad91e9c0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000000b1a2bc2ec50000'],
984
- [web3Utils.toChecksumAddress('0x0031d218133AFaB8c2a819B1066c7E434Ad91E9c'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), '5']
985
- ],
986
- [
987
- ['0x0000000000000000000000000031d218233afab8c2a819b1066c7e434ad91e9c0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000000000000000000000000000001298a2e67f060000'],
988
- [web3Utils.toChecksumAddress('0x0031d218233AFaB8c2a819B1066c7E434Ad91E9c'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), '134']
989
- ],
990
- ];
991
-
992
- examples.forEach(([expected, actual]) => {
993
- it(`Given ${actual} should return expected value: ${expected}`, () => {
994
- expect(curveUsdSoftLiquidationTrigger.encode(...actual)).to.eql(expected);
995
- });
996
- });
997
- });
998
-
999
- describe('decode()', () => {
1000
- const examples: Array<[{ market: EthereumAddress, owner: EthereumAddress, percentage: string }, TriggerData]> = [
1001
- [
1002
- {
1003
- market: web3Utils.toChecksumAddress('0x0031d218133AFaB8c2a819B1066c7E434Ad91E9c'),
1004
- owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1005
- percentage: '5',
1006
- },
1007
- ['0x0000000000000000000000000031d218133afab8c2a819b1066c7e434ad91e9c0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000000b1a2bc2ec50000'],
1008
- ],
1009
- [
1010
- {
1011
- market: web3Utils.toChecksumAddress('0x0031d218233AFaB8c2a819B1066c7E434Ad91E9c'),
1012
- owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1013
- percentage: '134',
1014
- },
1015
- ['0x0000000000000000000000000031d218233afab8c2a819b1066c7e434ad91e9c0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000000000000000000000000000001298a2e67f060000'],
1016
- ],
1017
- ];
1018
-
1019
- examples.forEach(([expected, actual]) => {
1020
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1021
- expect(curveUsdSoftLiquidationTrigger.decode(actual)).to.eql(expected);
1022
- });
1023
- });
1024
- });
1025
- });
1026
- describe('When testing triggerService.crvUSDRatioTrigger', () => {
1027
- describe('encode()', () => {
1028
- const examples: Array<[[string], [owner: EthereumAddress, controller: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
1029
- [
1030
- ['0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
1031
- [web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), 120, RatioState.UNDER]
1032
- ],
1033
- [
1034
- ['0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d42196350000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
1035
- [web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), 200, RatioState.OVER]
1036
- ],
1037
- ];
1038
- examples.forEach(([expected, actual]) => {
1039
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1040
- expect(crvUSDRatioTrigger.encode(...actual)).to.eql(expected);
1041
- });
1042
- });
1043
- });
1044
- describe('decode()', () => {
1045
- const examples: Array<[{ owner: EthereumAddress, controller: EthereumAddress, ratio: number, ratioState: RatioState }, TriggerData]> = [
1046
- [
1047
- { owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), controller: web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), ratio: 120, ratioState: RatioState.UNDER },
1048
- ['0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
1049
- ],
1050
- [
1051
- { owner: web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), controller: web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), ratio: 200, ratioState: RatioState.OVER },
1052
- ['0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d42196350000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
1053
- ],
1054
- ];
1055
-
1056
- examples.forEach(([expected, actual]) => {
1057
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1058
- expect(crvUSDRatioTrigger.decode(actual)).to.eql(expected);
1059
- });
1060
- });
1061
- });
1062
- });
1063
-
1064
- describe('When testing triggerService.crvUsdHealthRatioTrigger', () => {
1065
- describe('encode()', () => {
1066
- const examples: Array<[[string], [owner: EthereumAddress, controller: EthereumAddress, ratioPercentage: number]]> = [
1067
- [
1068
- ['0x0000000000000000000000007a2af22ba3276108cd331c8985ef9528e10a871a000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000002c68af0bb140000'],
1069
- [web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'), web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), 20]
1070
- ]
1071
- ];
1072
- examples.forEach(([expected, actual]) => {
1073
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1074
- expect(crvUsdHealthRatioTrigger.encode(...actual)).to.eql(expected);
1075
- });
1076
- });
1077
- });
1078
- describe('decode()', () => {
1079
- const examples: Array<[{ owner: EthereumAddress, controller: EthereumAddress, ratio: number }, TriggerData]> = [
1080
- [
1081
- { owner: web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'), controller: web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), ratio: 20 },
1082
- ['0x0000000000000000000000007a2af22ba3276108cd331c8985ef9528e10a871a000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000002c68af0bb140000'],
1083
- ],
1084
- ];
1085
- examples.forEach(([expected, actual]) => {
1086
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1087
- expect(crvUsdHealthRatioTrigger.decode(actual)).to.eql(expected);
1088
- });
1089
- });
1090
- });
1091
- });
1092
-
1093
- describe('When testing triggerService.morphoBlueRatioTrigger', () => {
1094
- describe('encode()', () => {
1095
- const examples: Array<[[string], [marketId: string, owner: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
1096
- [
1097
- ['0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
1098
- ['0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), 120, RatioState.UNDER]
1099
- ],
1100
- [
1101
- ['0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
1102
- ['0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc', web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), 200, RatioState.OVER]
1103
- ],
1104
- ];
1105
- examples.forEach(([expected, actual]) => {
1106
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1107
- expect(morphoBlueRatioTrigger.encode(...actual)).to.eql(expected);
1108
- });
1109
- });
1110
- });
1111
- describe('decode()', () => {
1112
- const examples: Array<[{ marketId: string, owner: EthereumAddress, ratio: number, ratioState: RatioState }, TriggerData]> = [
1113
- [
1114
- { marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), ratio: 120, ratioState: RatioState.UNDER },
1115
- ['0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
1116
- ],
1117
- [
1118
- { marketId: '0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc', owner: web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), ratio: 200, ratioState: RatioState.OVER },
1119
- ['0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
1120
- ],
1121
- ];
1122
-
1123
- examples.forEach(([expected, actual]) => {
1124
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1125
- expect(morphoBlueRatioTrigger.decode(actual)).to.eql(expected);
1126
- });
1127
- });
1128
- });
1129
- });
1130
- });
1
+ import { expect } from 'chai';
2
+ import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
3
+ import * as web3Utils from 'web3-utils';
4
+
5
+ import { ChainId, OrderType, RatioState } from '../types/enums';
6
+ import type { EthereumAddress, TriggerData } from '../types';
7
+
8
+ import '../configuration';
9
+ import {
10
+ aaveV2RatioTrigger,
11
+ aaveV3QuotePriceTrigger,
12
+ aaveV3QuotePriceWithMaximumGasPriceTrigger,
13
+ aaveV3RatioTrigger,
14
+ cBondsRebondTrigger,
15
+ chainlinkPriceTrigger,
16
+ compoundV2RatioTrigger,
17
+ compoundV3RatioTrigger,
18
+ compoundV3PriceTrigger,
19
+ curveUsdBorrowRateTrigger,
20
+ curveUsdSoftLiquidationTrigger,
21
+ exchangeOffchainPriceTrigger,
22
+ exchangeTimestampTrigger,
23
+ liquityDebtInFrontTrigger,
24
+ makerRatioTrigger,
25
+ morphoAaveV2RatioTrigger,
26
+ sparkQuotePriceTrigger,
27
+ sparkRatioTrigger,
28
+ trailingStopTrigger,
29
+ liquityDebtInFrontWithLimitTrigger,
30
+ crvUSDRatioTrigger,
31
+ morphoBlueRatioTrigger,
32
+ crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger,
33
+ compoundV3PriceRangeTrigger,
34
+ } from './triggerService';
35
+
36
+ describe('Feature: triggerService.ts', () => {
37
+
38
+ describe('When testing triggerService.chainlinkPriceTrigger', () => {
39
+ describe('encode()', () => {
40
+ const examples: Array<[[string], [EthereumAddress, string, RatioState]]> = [
41
+ [
42
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000002794ca24000000000000000000000000000000000000000000000000000000000000000000'],
43
+ [getAssetInfo('WETH', ChainId.Ethereum).address, '1700', RatioState.OVER]
44
+ ],
45
+ [
46
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000002c3ce1ec000000000000000000000000000000000000000000000000000000000000000001'],
47
+ [getAssetInfo('WETH', ChainId.Ethereum).address, '1900', RatioState.UNDER]
48
+ ],
49
+ ];
50
+
51
+ examples.forEach(([expected, actual]) => {
52
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
53
+ expect(chainlinkPriceTrigger.encode(...actual)).to.eql(expected);
54
+ });
55
+ });
56
+ });
57
+
58
+ describe('decode()', () => {
59
+ const examples: Array<[{ tokenAddr: EthereumAddress, price: string, state: RatioState}, TriggerData]> = [
60
+ [
61
+ { tokenAddr: getAssetInfo('WETH', ChainId.Ethereum).address, price: '1700', state: RatioState.OVER },
62
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000002794ca24000000000000000000000000000000000000000000000000000000000000000000'],
63
+ ],
64
+ [
65
+ { tokenAddr: getAssetInfo('WETH', ChainId.Ethereum).address, price: '1900', state: RatioState.UNDER },
66
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000002c3ce1ec000000000000000000000000000000000000000000000000000000000000000001'],
67
+ ],
68
+ ];
69
+
70
+ examples.forEach(([expected, actual]) => {
71
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
72
+ expect(chainlinkPriceTrigger.decode(actual)).to.eql(expected);
73
+ });
74
+ });
75
+ });
76
+ });
77
+
78
+ describe('When testing triggerService.trailingStopTrigger', () => {
79
+ describe('encode()', () => {
80
+ const examples: Array<[[string], [EthereumAddress, number, number]]> = [
81
+ [
82
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000002cb417800000000000000000000000000000000000000000000000000000000000000000a'],
83
+ [getAssetInfo('WETH', ChainId.Ethereum).address, 120, 10]
84
+ ],
85
+ [
86
+ ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000002cb417800000000000000000000000000000000000000000000000000000000000000000c'],
87
+ [getAssetInfo('DAI', ChainId.Ethereum).address, 120, 12]
88
+ ],
89
+ ];
90
+
91
+ examples.forEach(([expected, actual]) => {
92
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
93
+ expect(trailingStopTrigger.encode(...actual)).to.eql(expected);
94
+ });
95
+ });
96
+ });
97
+
98
+ describe('decode()', () => {
99
+ const examples: Array<[{ triggerPercentage: number, tokenAddr: EthereumAddress, roundId: string }, TriggerData]> = [
100
+ [
101
+ { tokenAddr: getAssetInfo('WETH', ChainId.Ethereum).address, triggerPercentage: 120, roundId: '10' },
102
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000002cb417800000000000000000000000000000000000000000000000000000000000000000a'],
103
+ ],
104
+ [
105
+ { tokenAddr: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address), triggerPercentage: 120, roundId: '12' },
106
+ ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000002cb417800000000000000000000000000000000000000000000000000000000000000000c'],
107
+ ],
108
+ ];
109
+
110
+ examples.forEach(([expected, actual]) => {
111
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
112
+ expect(trailingStopTrigger.decode(actual)).to.eql(expected);
113
+ });
114
+ });
115
+ });
116
+ });
117
+
118
+ describe('When testing triggerService.makerRatioTrigger', () => {
119
+ describe('encode()', () => {
120
+ const examples: Array<[[string], [number, number, RatioState]]> = [
121
+ [
122
+ ['0x0000000000000000000000000000000000000000000000000000000000000520000000000000000000000000000000000000000000000000122e0e0f2fc300000000000000000000000000000000000000000000000000000000000000000001'],
123
+ [1312, 131, RatioState.UNDER]
124
+ ],
125
+ [
126
+ ['0x000000000000000000000000000000000000000000000000000000000000a455000000000000000000000000000000000000000000000000200ec4c2d72700000000000000000000000000000000000000000000000000000000000000000000'],
127
+ [42069, 231, RatioState.OVER]
128
+ ],
129
+ ];
130
+
131
+ examples.forEach(([expected, actual]) => {
132
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
133
+ expect(makerRatioTrigger.encode(...actual)).to.eql(expected);
134
+ });
135
+ });
136
+ });
137
+
138
+ describe('decode()', () => {
139
+ const examples: Array<[{ vaultId: number, ratioState: number, ratio: number }, TriggerData]> = [
140
+ [
141
+ { vaultId: 1312, ratioState: RatioState.UNDER, ratio: 131 },
142
+ ['0x0000000000000000000000000000000000000000000000000000000000000520000000000000000000000000000000000000000000000000122e0e0f2fc300000000000000000000000000000000000000000000000000000000000000000001'],
143
+ ],
144
+ [
145
+ { vaultId: 42069, ratioState: RatioState.OVER, ratio: 231 },
146
+ ['0x000000000000000000000000000000000000000000000000000000000000a455000000000000000000000000000000000000000000000000200ec4c2d72700000000000000000000000000000000000000000000000000000000000000000000'],
147
+ ],
148
+ ];
149
+
150
+ examples.forEach(([expected, actual]) => {
151
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
152
+ expect(makerRatioTrigger.decode(actual)).to.eql(expected);
153
+ });
154
+ });
155
+ });
156
+ });
157
+
158
+ describe('When testing triggerService.aaveV3RatioTrigger', () => {
159
+ describe('encode()', () => {
160
+ const examples: Array<[[string], [owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
161
+ [
162
+ ['0x0000000000000000000000000039d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000000'],
163
+ [web3Utils.toChecksumAddress('0x0039d218133AFaB8F2B819B1066c7E434Ad94E9c'), '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e', 120, RatioState.OVER]
164
+ ],
165
+ [
166
+ ['0x0000000000000000000000000039d218ff3afab8f2b819b1066c7e434ad94e9f000000000000000000000000a97684ead0e402dc232d5a977953df7ecbab3cdb0000000000000000000000000000000000000000000000002c8c35fe210100000000000000000000000000000000000000000000000000000000000000000001'],
167
+ [web3Utils.toChecksumAddress('0x0039d218ff3AFaB8F2B819B1066c7E434Ad94E9f'), '0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb', 321, RatioState.UNDER]
168
+ ],
169
+ ];
170
+
171
+ examples.forEach(([expected, actual]) => {
172
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
173
+ expect(aaveV3RatioTrigger.encode(...actual)).to.eql(expected);
174
+ });
175
+ });
176
+ });
177
+
178
+ describe('decode()', () => {
179
+ const examples: Array<[{ owner: EthereumAddress, market: EthereumAddress, ratio: number, ratioState: RatioState }, TriggerData]> = [
180
+ [
181
+ { owner: web3Utils.toChecksumAddress('0x0039d218133AFaB8F2B819B1066c7E434Ad94E9c'), market: '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e', ratio: 120, ratioState: RatioState.OVER },
182
+ ['0x0000000000000000000000000039d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000000'],
183
+ ],
184
+ [
185
+ { owner: web3Utils.toChecksumAddress('0x0039d218ff3AFaB8F2B819B1066c7E434Ad94E9f'), market: '0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb', ratio: 321, ratioState: RatioState.UNDER },
186
+ ['0x0000000000000000000000000039d218ff3afab8f2b819b1066c7e434ad94e9f000000000000000000000000a97684ead0e402dc232d5a977953df7ecbab3cdb0000000000000000000000000000000000000000000000002c8c35fe210100000000000000000000000000000000000000000000000000000000000000000001'],
187
+ ],
188
+ ];
189
+
190
+ examples.forEach(([expected, actual]) => {
191
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
192
+ expect(aaveV3RatioTrigger.decode(actual)).to.eql(expected);
193
+ });
194
+ });
195
+ });
196
+ });
197
+
198
+ describe('When testing triggerService.morphoAaveV2RatioTrigger', () => {
199
+ describe('encode()', () => {
200
+ const examples: Array<[[string], [owner: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
201
+ [
202
+ ['0x0000000000000000000000000039d218133afab8f2b819b1066c7e434ad94e2c0000000000000000000000000000000000000000000000001eab7f4a799d00000000000000000000000000000000000000000000000000000000000000000001'],
203
+ [web3Utils.toChecksumAddress('0x0039d218133AFaB8F2B819B1066c7E434Ad94E2c'), 221, RatioState.UNDER]
204
+ ],
205
+ [
206
+ ['0x0000000000000000000000000032d218133afab8f2b819b1066c7e434ad94e2c0000000000000000000000000000000000000000000000003d3377a2837900000000000000000000000000000000000000000000000000000000000000000000'],
207
+ [web3Utils.toChecksumAddress('0x0032d218133AFaB8F2B819B1066c7E434Ad94E2c'), 441, RatioState.OVER]
208
+ ],
209
+ ];
210
+
211
+ examples.forEach(([expected, actual]) => {
212
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
213
+ expect(morphoAaveV2RatioTrigger.encode(...actual)).to.eql(expected);
214
+ });
215
+ });
216
+ });
217
+
218
+ describe('decode()', () => {
219
+ const examples: Array<[{ owner: EthereumAddress, ratio: number, ratioState: RatioState }, TriggerData]> = [
220
+ [
221
+ { owner: web3Utils.toChecksumAddress('0x0039d218133AFaB8F2B819B1066c7E434Ad94E2c'), ratio: 221, ratioState: RatioState.UNDER },
222
+ ['0x0000000000000000000000000039d218133afab8f2b819b1066c7e434ad94e2c0000000000000000000000000000000000000000000000001eab7f4a799d00000000000000000000000000000000000000000000000000000000000000000001'],
223
+ ],
224
+ [
225
+ { owner: web3Utils.toChecksumAddress('0x0032d218133AFaB8F2B819B1066c7E434Ad94E2c'), ratio: 441, ratioState: RatioState.OVER },
226
+ ['0x0000000000000000000000000032d218133afab8f2b819b1066c7e434ad94e2c0000000000000000000000000000000000000000000000003d3377a2837900000000000000000000000000000000000000000000000000000000000000000000'],
227
+ ],
228
+ ];
229
+
230
+ examples.forEach(([expected, actual]) => {
231
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
232
+ expect(morphoAaveV2RatioTrigger.decode(actual)).to.eql(expected);
233
+ });
234
+ });
235
+ });
236
+ });
237
+
238
+ describe('When testing triggerService.aaveV3QuotePriceTrigger', () => {
239
+ describe('encode()', () => {
240
+ const examples: Array<[[string], [baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState]]> = [
241
+ [
242
+ ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000009c400000000000000000000000000000000000000000000000000000000000000001'],
243
+ [getAssetInfo('DAI', ChainId.Ethereum).address, getAssetInfo('WETH', ChainId.Ethereum).address, 0.0004, RatioState.UNDER]
244
+ ],
245
+ [
246
+ ['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000fd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb900000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000000'],
247
+ [getAssetInfo('WBTC', ChainId.Arbitrum).address, getAssetInfo('USDT', ChainId.Arbitrum).address, 0.00000023, RatioState.OVER]
248
+ ],
249
+ ];
250
+
251
+ examples.forEach(([expected, actual]) => {
252
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
253
+ expect(aaveV3QuotePriceTrigger.encode(...actual)).to.eql(expected);
254
+ });
255
+ });
256
+ });
257
+
258
+ describe('decode()', () => {
259
+ const examples: Array<[{ baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: string, ratioState: RatioState }, TriggerData]> = [
260
+ [
261
+ {
262
+ baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
263
+ quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
264
+ price: '0.0004',
265
+ ratioState: RatioState.UNDER,
266
+ },
267
+ ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000009c400000000000000000000000000000000000000000000000000000000000000001'],
268
+ ],
269
+ [
270
+ {
271
+ baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
272
+ quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('USDT', ChainId.Arbitrum).address),
273
+ price: '0.00000023',
274
+ ratioState: RatioState.OVER,
275
+ },
276
+ ['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000fd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb900000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000000'],
277
+ ]
278
+ ];
279
+
280
+ examples.forEach(([expected, actual]) => {
281
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
282
+ expect(aaveV3QuotePriceTrigger.decode(actual)).to.eql(expected);
283
+ });
284
+ });
285
+ });
286
+ });
287
+
288
+ describe('When testing triggerService.aaveV3QuotePriceWithMaximumGasPriceTrigger', () => {
289
+ describe('encode()', () => {
290
+ const examples: Array<[TriggerData, [baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState, maximumGasPriceInGwei?: number]]> = [
291
+ [
292
+ [
293
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000009c400000000000000000000000000000000000000000000000000000000000000001',
294
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
295
+ ],
296
+ [getAssetInfo('DAI', ChainId.Ethereum).address, getAssetInfo('WETH', ChainId.Ethereum).address, 0.0004, RatioState.UNDER]
297
+ ],
298
+ [
299
+ [
300
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000000',
301
+ '0x00000000000000000000000000000000000000000000000000000002cb417800',
302
+ ],
303
+ [getAssetInfo('WBTC', ChainId.Ethereum).address, getAssetInfo('USDT', ChainId.Ethereum).address, 0.00000023, RatioState.OVER, 12]
304
+ ],
305
+ ];
306
+
307
+ examples.forEach(([expected, actual]) => {
308
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
309
+ expect(aaveV3QuotePriceWithMaximumGasPriceTrigger.encode(...actual)).to.eql(expected);
310
+ });
311
+ });
312
+ });
313
+
314
+ describe('decode()', () => {
315
+ const examples: Array<[{ baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: string, ratioState: RatioState, maximumGasPrice: string }, TriggerData]> = [
316
+ [
317
+ {
318
+ baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
319
+ quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
320
+ price: '0.0004',
321
+ ratioState: RatioState.UNDER,
322
+ maximumGasPrice: web3Utils.fromWei(MAXUINT, 'gwei')
323
+ },
324
+ [
325
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000009c400000000000000000000000000000000000000000000000000000000000000001',
326
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
327
+ ],
328
+ ],
329
+ [
330
+ {
331
+ baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
332
+ quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('USDT', ChainId.Ethereum).address),
333
+ price: '0.00000023',
334
+ ratioState: RatioState.OVER,
335
+ maximumGasPrice: '12',
336
+ },
337
+ [
338
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000000',
339
+ '0x00000000000000000000000000000000000000000000000000000002cb417800',
340
+ ],
341
+ ]
342
+ ];
343
+
344
+ examples.forEach(([expected, actual]) => {
345
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
346
+ expect(aaveV3QuotePriceWithMaximumGasPriceTrigger.decode(actual)).to.eql(expected);
347
+ });
348
+ });
349
+ });
350
+ });
351
+
352
+ describe('When testing triggerService.liquityRatioTrigger', () => {
353
+ describe('encode()', () => {
354
+ const examples: Array<[[string], [owner: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
355
+ [
356
+ ['0x0000000000000000000000000039d218133afab8f2b819b1066c7e434ad94e2c00000000000000000000000000000000000000000000000029c5ab0d65ed00000000000000000000000000000000000000000000000000000000000000000001'],
357
+ [web3Utils.toChecksumAddress('0x0039d218133AFaB8F2B819B1066c7E434Ad94E2c'), 301, RatioState.UNDER]
358
+ ],
359
+ [
360
+ ['0x0000000000000000000000000039d218133afab832b819b1066c7e434ad94e2c000000000000000000000000000000000000000000000000122e0e0f2fc300000000000000000000000000000000000000000000000000000000000000000000'],
361
+ [web3Utils.toChecksumAddress('0x0039d218133AFaB832B819B1066c7E434Ad94E2c'), 131, RatioState.OVER]
362
+ ],
363
+ ];
364
+
365
+ examples.forEach(([expected, actual]) => {
366
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
367
+ expect(compoundV2RatioTrigger.encode(...actual)).to.eql(expected);
368
+ });
369
+ });
370
+ });
371
+
372
+ describe('decode()', () => {
373
+ const examples: Array<[{ owner: EthereumAddress, ratioState: RatioState, ratio: number }, TriggerData]> = [
374
+ [
375
+ {
376
+ owner: web3Utils.toChecksumAddress('0x0039d218133AFaB8F2B819B1066c7E434Ad94E2c'),
377
+ ratio: 301,
378
+ ratioState: RatioState.UNDER,
379
+ },
380
+ ['0x0000000000000000000000000039d218133afab8f2b819b1066c7e434ad94e2c00000000000000000000000000000000000000000000000029c5ab0d65ed00000000000000000000000000000000000000000000000000000000000000000001'],
381
+ ],
382
+ [
383
+ {
384
+ owner: web3Utils.toChecksumAddress('0x0039d218133AFaB832B819B1066c7E434Ad94E2c'),
385
+ ratio: 131,
386
+ ratioState: RatioState.OVER,
387
+ },
388
+ ['0x0000000000000000000000000039d218133afab832b819b1066c7e434ad94e2c000000000000000000000000000000000000000000000000122e0e0f2fc300000000000000000000000000000000000000000000000000000000000000000000'],
389
+ ],
390
+ ];
391
+
392
+ examples.forEach(([expected, actual]) => {
393
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
394
+ expect(compoundV2RatioTrigger.decode(actual)).to.eql(expected);
395
+ });
396
+ });
397
+ });
398
+ });
399
+
400
+ describe('When testing triggerService.liquityDebtInFrontTrigger', () => {
401
+ describe('encode()', () => {
402
+ const examples: Array<[[string], [owner: EthereumAddress, debtInFrontMin: string]]> = [
403
+ [
404
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000006e0be8c4995af80000'],
405
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'), '2030']
406
+ ],
407
+ [
408
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000004697f83e6356dd440000'],
409
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'), '333369']
410
+ ],
411
+ [
412
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf000000000000000000000000000000000000000000084595161401484a000000'],
413
+ [web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'), '10000000']
414
+ ],
415
+ [
416
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf0000000000000000000000000000000000000000000000000000000000989680'],
417
+ [web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'), '0.00000000001']
418
+ ],
419
+ [
420
+ ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a0000000000000000000000000000000000000000019d971e4fe8401e74000000'],
421
+ [web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'), '500000000']
422
+ ],
423
+ [
424
+ ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a00000000000000000000000000000000000000000001a784379d99db42000000'],
425
+ [web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'), '2000000']
426
+ ],
427
+ ];
428
+
429
+ examples.forEach(([expected, actual]) => {
430
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
431
+ expect(liquityDebtInFrontTrigger.encode(...actual)).to.eql(expected);
432
+ expect(liquityDebtInFrontWithLimitTrigger.encode(...actual)).to.eql(expected);
433
+ });
434
+ });
435
+ });
436
+
437
+ describe('decode()', () => {
438
+ const examples: Array<[{ owner: EthereumAddress, debtInFrontMin: string }, TriggerData]> = [
439
+ [
440
+ {
441
+ owner: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'),
442
+ debtInFrontMin: '2030',
443
+ },
444
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000006e0be8c4995af80000'],
445
+ ],
446
+ [
447
+ {
448
+ owner: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'),
449
+ debtInFrontMin: '333369',
450
+ },
451
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000004697f83e6356dd440000'],
452
+ ],
453
+ [
454
+ {
455
+ owner: web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'),
456
+ debtInFrontMin: '10000000',
457
+ },
458
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf000000000000000000000000000000000000000000084595161401484a000000'],
459
+ ],
460
+ [
461
+ {
462
+ owner: web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'),
463
+ debtInFrontMin: '0.00000000001',
464
+ },
465
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf0000000000000000000000000000000000000000000000000000000000989680'],
466
+ ],
467
+ [
468
+ {
469
+ owner: web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'),
470
+ debtInFrontMin: '500000000',
471
+ },
472
+ ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a0000000000000000000000000000000000000000019d971e4fe8401e74000000'],
473
+ ],
474
+ [
475
+ {
476
+ owner: web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'),
477
+ debtInFrontMin: '2000000',
478
+ },
479
+ ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a00000000000000000000000000000000000000000001a784379d99db42000000'],
480
+ ],
481
+ ];
482
+
483
+ examples.forEach(([expected, actual]) => {
484
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
485
+ expect(liquityDebtInFrontTrigger.decode(actual)).to.eql(expected);
486
+ expect(liquityDebtInFrontWithLimitTrigger.decode(actual)).to.eql(expected);
487
+ });
488
+ });
489
+ });
490
+ });
491
+
492
+ describe('When testing triggerService.liquityV2DebtInFrontTrigger', () => {
493
+ describe('encode()', () => {
494
+ const examples: Array<[[string], [market: EthereumAddress, troveId: string, debtInFrontMin: string]]> = [
495
+ [
496
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd1500000000000000000000000000000000000000000000006e0be8c4995af80000'],
497
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'), '123456789', '2030']
498
+ ],
499
+ [
500
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1000000000000000000000000000000000000000000004697f83e6356dd440000'],
501
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'), '987654321', '333369']
502
+ ],
503
+ [
504
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf00000000000000000000000000000000000000000000000000000000075bd924000000000000000000000000000000000000000000084595161401484a000000'],
505
+ [web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'), '123459876', '10000000']
506
+ ],
507
+ [
508
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf000000000000000000000000000000000000000000000000000000002060d4950000000000000000000000000000000000000000000000000000000000989680'],
509
+ [web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'), '543216789', '0.00000000001']
510
+ ],
511
+ [
512
+ ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a000000000000000000000000000000000000000000000000000000003ade5ca20000000000000000000000000000000000000000019d971e4fe8401e74000000'],
513
+ [web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'), '987651234', '500000000']
514
+ ],
515
+ ];
516
+
517
+ examples.forEach(([expected, actual]) => {
518
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
519
+ expect(liquityV2DebtInFrontTrigger.encode(...actual)).to.eql(expected);
520
+ });
521
+ });
522
+ });
523
+
524
+ describe('decode()', () => {
525
+ const examples: Array<[{ market: EthereumAddress, troveId: string, debtInFrontMin: string }, TriggerData]> = [
526
+ [
527
+ {
528
+ market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'),
529
+ troveId: '123456789',
530
+ debtInFrontMin: '2030',
531
+ },
532
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd1500000000000000000000000000000000000000000000006e0be8c4995af80000'],
533
+ ],
534
+ [
535
+ {
536
+ market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'),
537
+ troveId: '987654321',
538
+ debtInFrontMin: '333369',
539
+ },
540
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1000000000000000000000000000000000000000000004697f83e6356dd440000'],
541
+ ], [
542
+ {
543
+ market: web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'),
544
+ troveId: '123459876',
545
+ debtInFrontMin: '10000000',
546
+ },
547
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf00000000000000000000000000000000000000000000000000000000075bd924000000000000000000000000000000000000000000084595161401484a000000'],
548
+ ], [
549
+ {
550
+ market: web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'),
551
+ troveId: '543216789',
552
+ debtInFrontMin: '0.00000000001',
553
+ },
554
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf000000000000000000000000000000000000000000000000000000002060d4950000000000000000000000000000000000000000000000000000000000989680'],
555
+ ], [
556
+ {
557
+ market: web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'),
558
+ troveId: '987651234',
559
+ debtInFrontMin: '500000000',
560
+ },
561
+ ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a000000000000000000000000000000000000000000000000000000003ade5ca20000000000000000000000000000000000000000019d971e4fe8401e74000000'],
562
+ ]
563
+ ];
564
+
565
+ examples.forEach(([expected, actual]) => {
566
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
567
+ expect(liquityV2DebtInFrontTrigger.decode(actual)).to.eql(expected);
568
+ });
569
+ });
570
+ });
571
+ });
572
+
573
+ describe('When testing triggerService.liquityV2AdjustTimeTrigger', () => {
574
+ describe('encode()', () => {
575
+ const examples: Array<[[string], [market: EthereumAddress, troveId: string]]> = [
576
+ [
577
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd15'],
578
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'), '123456789']
579
+ ],
580
+ [
581
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1'],
582
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'), '987654321']
583
+ ],
584
+ ];
585
+
586
+ examples.forEach(([expected, actual]) => {
587
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
588
+ expect(liquityV2AdjustTimeTrigger.encode(...actual)).to.eql(expected);
589
+ });
590
+ });
591
+ });
592
+
593
+ describe('decode()', () => {
594
+ const examples: Array<[{ market: EthereumAddress, troveId: string }, TriggerData]> = [
595
+ [
596
+ {
597
+ market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'),
598
+ troveId: '123456789',
599
+ },
600
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd15'],
601
+ ],
602
+ [
603
+ {
604
+ market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'),
605
+ troveId: '987654321',
606
+ },
607
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1'],
608
+ ]
609
+ ];
610
+
611
+ examples.forEach(([expected, actual]) => {
612
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
613
+ expect(liquityV2AdjustTimeTrigger.decode(actual)).to.eql(expected);
614
+ });
615
+ });
616
+ });
617
+ });
618
+ describe('When testing triggerService.aaveV2RatioTrigger', () => {
619
+ describe('encode()', () => {
620
+ const examples: Array<[[string], [owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
621
+ [
622
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c0000000000000000000000000249d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000000'],
623
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'), web3Utils.toChecksumAddress('0x0249d218133AFaB8F2B829B1066c7E434Ad94E2c'), 120, RatioState.OVER]
624
+ ],
625
+ ];
626
+
627
+ examples.forEach(([expected, actual]) => {
628
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
629
+ expect(aaveV2RatioTrigger.encode(...actual)).to.eql(expected);
630
+ });
631
+ });
632
+ });
633
+
634
+ describe('decode()', () => {
635
+ const examples: Array<[{ owner: EthereumAddress, market: EthereumAddress, ratioState: RatioState, ratio: number }, TriggerData]> = [
636
+ [
637
+ {
638
+ owner: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'),
639
+ market: web3Utils.toChecksumAddress('0x0249d218133AFaB8F2B829B1066c7E434Ad94E2c'),
640
+ ratio: 120,
641
+ ratioState: RatioState.OVER,
642
+ },
643
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c0000000000000000000000000249d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000000'],
644
+ ],
645
+ ];
646
+
647
+ examples.forEach(([expected, actual]) => {
648
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
649
+ expect(aaveV2RatioTrigger.decode(actual)).to.eql(expected);
650
+ });
651
+ });
652
+ });
653
+ });
654
+
655
+ describe('When testing triggerService.cBondsRebondTrigger', () => {
656
+ describe('encode()', () => {
657
+ const examples: Array<[[string], [bondId: number | string]]> = [
658
+ [
659
+ ['0x0000000000000000000000000000000000000000000000000000000000000141'],
660
+ [321]
661
+ ],
662
+ [
663
+ ['0x000000000000000000000000000000000000000000000000000000000000002c'],
664
+ [44]
665
+ ],
666
+ ];
667
+
668
+ examples.forEach(([expected, actual]) => {
669
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
670
+ expect(cBondsRebondTrigger.encode(...actual)).to.eql(expected);
671
+ });
672
+ });
673
+ });
674
+
675
+ describe('decode()', () => {
676
+ const examples: Array<[{ bondId: string }, TriggerData]> = [
677
+ [
678
+ { bondId: '321' },
679
+ ['0x0000000000000000000000000000000000000000000000000000000000000141'],
680
+ ],
681
+ [
682
+ { bondId: '44' },
683
+ ['0x000000000000000000000000000000000000000000000000000000000000002c'],
684
+ ],
685
+ ];
686
+
687
+ examples.forEach(([expected, actual]) => {
688
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
689
+ expect(cBondsRebondTrigger.decode(actual)).to.eql(expected);
690
+ });
691
+ });
692
+ });
693
+ });
694
+
695
+ describe('When testing triggerService.compoundV3RatioTrigger', () => {
696
+ describe('encode()', () => {
697
+ const examples: Array<[[string], [owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
698
+ [
699
+ ['0x0000000000000000000000000049d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000213d218133afab8f2b829b1066c7e43cad94e2c000000000000000000000000000000000000000000000000245c1c1e5f8600000000000000000000000000000000000000000000000000000000000000000000'],
700
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B106633E434Ad94E2c'), web3Utils.toChecksumAddress('0x0213d218133AFaB8F2B829B1066c7E43cAd94E2c'), 262, RatioState.OVER]
701
+ ],
702
+ [
703
+ ['0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000213d212133afab8f2b829b1066c7e43cad94e2c0000000000000000000000000000000000000000000000002def7b767e8b00000000000000000000000000000000000000000000000000000000000000000001'],
704
+ [web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'), 331, RatioState.UNDER]
705
+ ],
706
+ ];
707
+
708
+ examples.forEach(([expected, actual]) => {
709
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
710
+ expect(compoundV3RatioTrigger.encode(...actual)).to.eql(expected);
711
+ });
712
+ });
713
+ });
714
+
715
+ describe('decode()', () => {
716
+ const examples: Array<[{ owner: EthereumAddress, market: EthereumAddress, ratioState: RatioState, ratio: number }, TriggerData]> = [
717
+ [
718
+ {
719
+ owner: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B106633E434Ad94E2c'),
720
+ market: web3Utils.toChecksumAddress('0x0213d218133AFaB8F2B829B1066c7E43cAd94E2c'),
721
+ ratio: 262,
722
+ ratioState: RatioState.OVER,
723
+ },
724
+ ['0x0000000000000000000000000049d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000213d218133afab8f2b829b1066c7e43cad94e2c000000000000000000000000000000000000000000000000245c1c1e5f8600000000000000000000000000000000000000000000000000000000000000000000'],
725
+ ],
726
+ [
727
+ {
728
+ owner: web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'),
729
+ market: web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
730
+ ratio: 331,
731
+ ratioState: RatioState.UNDER,
732
+ },
733
+ ['0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000213d212133afab8f2b829b1066c7e43cad94e2c0000000000000000000000000000000000000000000000002def7b767e8b00000000000000000000000000000000000000000000000000000000000000000001'],
734
+ ],
735
+ ];
736
+
737
+ examples.forEach(([expected, actual]) => {
738
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
739
+ expect(compoundV3RatioTrigger.decode(actual)).to.eql(expected);
740
+ });
741
+ });
742
+ });
743
+ });
744
+
745
+ describe('When testing triggerService.exchangeTimestampTrigger', () => {
746
+ describe('encode()', () => {
747
+ const examples: Array<[[string], [timestamp: number, interval: number]]> = [
748
+ [
749
+ ['0x0000000000000000000000000000000000000000000000000000018adbcdf3c10000000000000000000000000000000000000000000000000000000077359fb8'],
750
+ [1695904822209, 2000003000]
751
+ ],
752
+ [
753
+ ['0x00000000000000000000000000000000000000000000000000000189ed59a4010000000000000000000000000000000000000000000000000000000011e378b8'],
754
+ [1691904222209, 300120248]
755
+ ],
756
+ ];
757
+
758
+ examples.forEach(([expected, actual]) => {
759
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
760
+ expect(exchangeTimestampTrigger.encode(...actual)).to.eql(expected);
761
+ });
762
+ });
763
+ });
764
+
765
+ describe('decode()', () => {
766
+ const examples: Array<[{ timestamp: number, interval: number }, TriggerData]> = [
767
+ [
768
+ {
769
+ timestamp: 1695904822209, interval: 2000003000,
770
+ },
771
+ ['0x0000000000000000000000000000000000000000000000000000018adbcdf3c10000000000000000000000000000000000000000000000000000000077359fb8'],
772
+ ],
773
+ [
774
+ {
775
+ timestamp: 1691904222209, interval: 300120248,
776
+ },
777
+ ['0x00000000000000000000000000000000000000000000000000000189ed59a4010000000000000000000000000000000000000000000000000000000011e378b8'],
778
+ ],
779
+ ];
780
+
781
+ examples.forEach(([expected, actual]) => {
782
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
783
+ expect(exchangeTimestampTrigger.decode(actual)).to.eql(expected);
784
+ });
785
+ });
786
+ });
787
+ });
788
+
789
+ describe('When testing triggerService.exchangeOffchainPriceTrigger', () => {
790
+ describe('encode()', () => {
791
+ const examples: Array<[[string], [targetPrice: string, goodUntil: number, orderType: OrderType, fromTokenDecimals: number, toTokenDecimals: number]]> = [
792
+ [
793
+ ['0x00000000000000000000000000000000000000000000000001b4fbd92b5f80000000000000000000000000000000000000000000000000000000018adbcdf3c10000000000000000000000000000000000000000000000000000000000000000'],
794
+ ['0.123', 1695904822209, OrderType.TAKE_PROFIT, 12, 12]
795
+ ],
796
+ [
797
+ ['0x00000000000000000000000000000000000000000000000000000000003432120000000000000000000000000000000000000000000000000000018adbbead990000000000000000000000000000000000000000000000000000000000000001'],
798
+ ['3.42069', 1695903821209, OrderType.STOP_LOSS, 18, 6]
799
+ ],
800
+ ];
801
+
802
+ examples.forEach(([expected, actual]) => {
803
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
804
+ expect(exchangeOffchainPriceTrigger.encode(...actual)).to.eql(expected);
805
+ });
806
+ });
807
+ });
808
+
809
+ describe('decode()', () => {
810
+ const examples: Array<[{ orderType: OrderType; targetPrice: string; goodUntil: any }, [TriggerData, number, number]]> = [
811
+ [
812
+ {
813
+ orderType: OrderType.TAKE_PROFIT, targetPrice: '0.123', goodUntil: 1695904822209,
814
+ },
815
+ [
816
+ ['0x00000000000000000000000000000000000000000000000001b4fbd92b5f80000000000000000000000000000000000000000000000000000000018adbcdf3c10000000000000000000000000000000000000000000000000000000000000000'],
817
+ 12,
818
+ 12,
819
+ ],
820
+ ],
821
+ [
822
+ {
823
+ orderType: OrderType.STOP_LOSS, targetPrice: '3.42069', goodUntil: 1695903821209,
824
+ },
825
+ [
826
+ ['0x00000000000000000000000000000000000000000000000000000000003432120000000000000000000000000000000000000000000000000000018adbbead990000000000000000000000000000000000000000000000000000000000000001'],
827
+ 18,
828
+ 6,
829
+ ],
830
+ ],
831
+ ];
832
+
833
+ examples.forEach(([expected, actual]) => {
834
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
835
+ expect(exchangeOffchainPriceTrigger.decode(...actual)).to.eql(expected);
836
+ });
837
+ });
838
+ });
839
+ });
840
+
841
+ describe('When testing triggerService.sparkRatioTrigger', () => {
842
+ describe('encode()', () => {
843
+ const examples: Array<[[string], [owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
844
+ [
845
+ ['0x0000000000000000000000000031d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000001131d218133afab8f2b819b1066c7e434ad94e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
846
+ [web3Utils.toChecksumAddress('0x0031d218133AFaB8F2B819B1066c7E434Ad94E9c'), web3Utils.toChecksumAddress('0x1131d218133AFaB8F2B819B1066c7E434Ad94E9c'), 120, RatioState.UNDER]
847
+ ],
848
+ [
849
+ ['0x0000000000000000000000000231d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000000131d218133afab8f2b819b1066c7e434ad94e9c000000000000000000000000000000000000000000000000200ec4c2d72700000000000000000000000000000000000000000000000000000000000000000000'],
850
+ [web3Utils.toChecksumAddress('0x0231d218133AFaB8F2B819B1066c7E434Ad94E9c'), web3Utils.toChecksumAddress('0x0131d218133AFaB8F2B819B1066c7E434Ad94E9c'), 231, RatioState.OVER]
851
+ ],
852
+ ];
853
+
854
+ examples.forEach(([expected, actual]) => {
855
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
856
+ expect(sparkRatioTrigger.encode(...actual)).to.eql(expected);
857
+ });
858
+ });
859
+ });
860
+
861
+ describe('decode()', () => {
862
+ const examples: Array<[{ owner: EthereumAddress, market: EthereumAddress, ratio: number, ratioState: RatioState }, TriggerData]> = [
863
+ [
864
+ { owner: web3Utils.toChecksumAddress('0x0031d218133AFaB8F2B819B1066c7E434Ad94E9c'), market: web3Utils.toChecksumAddress('0x1131d218133AFaB8F2B819B1066c7E434Ad94E9c'), ratio: 120, ratioState: RatioState.UNDER },
865
+ ['0x0000000000000000000000000031d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000001131d218133afab8f2b819b1066c7e434ad94e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
866
+ ],
867
+ [
868
+ { owner: web3Utils.toChecksumAddress('0x0231d218133AFaB8F2B819B1066c7E434Ad94E9c'), market: web3Utils.toChecksumAddress('0x0131d218133AFaB8F2B819B1066c7E434Ad94E9c'), ratio: 231, ratioState: RatioState.OVER },
869
+ ['0x0000000000000000000000000231d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000000131d218133afab8f2b819b1066c7e434ad94e9c000000000000000000000000000000000000000000000000200ec4c2d72700000000000000000000000000000000000000000000000000000000000000000000'],
870
+ ],
871
+ ];
872
+
873
+ examples.forEach(([expected, actual]) => {
874
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
875
+ expect(sparkRatioTrigger.decode(actual)).to.eql(expected);
876
+ });
877
+ });
878
+ });
879
+ });
880
+
881
+ describe('When testing triggerService.sparkQuotePriceTrigger', () => {
882
+ describe('encode()', () => {
883
+ const examples: Array<[[string], [baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState]]> = [
884
+ [
885
+ ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000000000000000000000000000000000000000a8ca0000000000000000000000000000000000000000000000000000000000000001'],
886
+ [getAssetInfo('DAI', ChainId.Ethereum).address, getAssetInfo('wstETH', ChainId.Ethereum).address, 0.0004321, RatioState.UNDER]
887
+ ],
888
+ [
889
+ ['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000186b70000000000000000000000000000000000000000000000000000000000000000'],
890
+ [getAssetInfo('WBTC', ChainId.Arbitrum).address, getAssetInfo('USDC', ChainId.Arbitrum).address, 0.00100023, RatioState.OVER]
891
+ ],
892
+ ];
893
+
894
+ examples.forEach(([expected, actual]) => {
895
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
896
+ expect(sparkQuotePriceTrigger.encode(...actual)).to.eql(expected);
897
+ });
898
+ });
899
+ });
900
+
901
+ describe('decode()', () => {
902
+ const examples: Array<[{ baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: string, ratioState: RatioState }, TriggerData]> = [
903
+ [
904
+ {
905
+ baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
906
+ quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Ethereum).address),
907
+ price: '0.0004321',
908
+ ratioState: RatioState.UNDER,
909
+ },
910
+ ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000000000000000000000000000000000000000a8ca0000000000000000000000000000000000000000000000000000000000000001'],
911
+ ],
912
+ [
913
+ {
914
+ baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
915
+ quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
916
+ price: '0.00100023',
917
+ ratioState: RatioState.OVER,
918
+ },
919
+ ['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000186b70000000000000000000000000000000000000000000000000000000000000000'],
920
+ ]
921
+ ];
922
+
923
+ examples.forEach(([expected, actual]) => {
924
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
925
+ expect(sparkQuotePriceTrigger.decode(actual)).to.eql(expected);
926
+ });
927
+ });
928
+ });
929
+ });
930
+
931
+ describe('When testing triggerService.curveUsdBorrowRateTrigger', () => {
932
+ describe('encode()', () => {
933
+ const examples: Array<[[string], [market: EthereumAddress, targetRate: string, rateState: RatioState]]> = [
934
+ [
935
+ ['0x0000000000000000000000000031d218133afab8c2b819b1066c7e434ad91e9c000000000000000000000000000000000000000000000000000000005c3744c40000000000000000000000000000000000000000000000000000000000000001'],
936
+ [web3Utils.toChecksumAddress('0x0031d218133AFaB8c2B819B1066c7E434Ad91E9c'), '5', RatioState.UNDER]
937
+ ],
938
+ [
939
+ ['0x0000000000000000000000000031d318133afab8c2b819b1066c7e434ad91e9c0000000000000000000000000000000000000000000000000000000037de1dae0000000000000000000000000000000000000000000000000000000000000000'],
940
+ [web3Utils.toChecksumAddress('0x0031d318133AFaB8c2B819B1066c7E434Ad91E9c'), '3', RatioState.OVER]
941
+ ],
942
+ ];
943
+
944
+ examples.forEach(([expected, actual]) => {
945
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
946
+ expect(curveUsdBorrowRateTrigger.encode(...actual)).to.eql(expected);
947
+ });
948
+ });
949
+ });
950
+
951
+ describe('decode()', () => {
952
+ const examples: Array<[{ market: EthereumAddress, targetRate: string, rateState: RatioState }, TriggerData]> = [
953
+ [
954
+ {
955
+ market: web3Utils.toChecksumAddress('0x0031d218133AFaB8c2B819B1066c7E434Ad91E9c'),
956
+ // Because of precision of reverse engineered rate we can't get exact number
957
+ targetRate: '4.9999999977932344260462314517997495470601974794180145018256513213117735079327887085499910715825462',
958
+ rateState: RatioState.UNDER,
959
+ },
960
+ ['0x0000000000000000000000000031d218133afab8c2b819b1066c7e434ad91e9c000000000000000000000000000000000000000000000000000000005c3744c40000000000000000000000000000000000000000000000000000000000000001'],
961
+ ],
962
+ [
963
+ {
964
+ market: web3Utils.toChecksumAddress('0x0031d318133AFaB8c2B819B1066c7E434Ad91E9c'),
965
+ // Because of precision of reverse engineered rate we can't get exact number
966
+ targetRate: '2.999999998802635853596007720123861222767915626254160712723033189270277420764438661596057080730334',
967
+ rateState: RatioState.OVER,
968
+ },
969
+ ['0x0000000000000000000000000031d318133afab8c2b819b1066c7e434ad91e9c0000000000000000000000000000000000000000000000000000000037de1dae0000000000000000000000000000000000000000000000000000000000000000'],
970
+ ],
971
+ ];
972
+
973
+ examples.forEach(([expected, actual]) => {
974
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
975
+ expect(curveUsdBorrowRateTrigger.decode(actual)).to.eql(expected);
976
+ });
977
+ });
978
+ });
979
+ });
980
+
981
+ describe('When testing triggerService.curveUsdSoftLiquidationTrigger', () => {
982
+ describe('encode()', () => {
983
+ const examples: Array<[[string], [market: EthereumAddress, market: EthereumAddress, percentage: string]]> = [
984
+ [
985
+ ['0x0000000000000000000000000031d218133afab8c2a819b1066c7e434ad91e9c0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000000b1a2bc2ec50000'],
986
+ [web3Utils.toChecksumAddress('0x0031d218133AFaB8c2a819B1066c7E434Ad91E9c'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), '5']
987
+ ],
988
+ [
989
+ ['0x0000000000000000000000000031d218233afab8c2a819b1066c7e434ad91e9c0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000000000000000000000000000001298a2e67f060000'],
990
+ [web3Utils.toChecksumAddress('0x0031d218233AFaB8c2a819B1066c7E434Ad91E9c'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), '134']
991
+ ],
992
+ ];
993
+
994
+ examples.forEach(([expected, actual]) => {
995
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
996
+ expect(curveUsdSoftLiquidationTrigger.encode(...actual)).to.eql(expected);
997
+ });
998
+ });
999
+ });
1000
+
1001
+ describe('decode()', () => {
1002
+ const examples: Array<[{ market: EthereumAddress, owner: EthereumAddress, percentage: string }, TriggerData]> = [
1003
+ [
1004
+ {
1005
+ market: web3Utils.toChecksumAddress('0x0031d218133AFaB8c2a819B1066c7E434Ad91E9c'),
1006
+ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1007
+ percentage: '5',
1008
+ },
1009
+ ['0x0000000000000000000000000031d218133afab8c2a819b1066c7e434ad91e9c0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000000b1a2bc2ec50000'],
1010
+ ],
1011
+ [
1012
+ {
1013
+ market: web3Utils.toChecksumAddress('0x0031d218233AFaB8c2a819B1066c7E434Ad91E9c'),
1014
+ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1015
+ percentage: '134',
1016
+ },
1017
+ ['0x0000000000000000000000000031d218233afab8c2a819b1066c7e434ad91e9c0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000000000000000000000000000001298a2e67f060000'],
1018
+ ],
1019
+ ];
1020
+
1021
+ examples.forEach(([expected, actual]) => {
1022
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1023
+ expect(curveUsdSoftLiquidationTrigger.decode(actual)).to.eql(expected);
1024
+ });
1025
+ });
1026
+ });
1027
+ });
1028
+ describe('When testing triggerService.crvUSDRatioTrigger', () => {
1029
+ describe('encode()', () => {
1030
+ const examples: Array<[[string], [owner: EthereumAddress, controller: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
1031
+ [
1032
+ ['0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
1033
+ [web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), 120, RatioState.UNDER]
1034
+ ],
1035
+ [
1036
+ ['0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d42196350000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
1037
+ [web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), 200, RatioState.OVER]
1038
+ ],
1039
+ ];
1040
+ examples.forEach(([expected, actual]) => {
1041
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1042
+ expect(crvUSDRatioTrigger.encode(...actual)).to.eql(expected);
1043
+ });
1044
+ });
1045
+ });
1046
+ describe('decode()', () => {
1047
+ const examples: Array<[{ owner: EthereumAddress, controller: EthereumAddress, ratio: number, ratioState: RatioState }, TriggerData]> = [
1048
+ [
1049
+ { owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), controller: web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), ratio: 120, ratioState: RatioState.UNDER },
1050
+ ['0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
1051
+ ],
1052
+ [
1053
+ { owner: web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), controller: web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), ratio: 200, ratioState: RatioState.OVER },
1054
+ ['0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d42196350000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
1055
+ ],
1056
+ ];
1057
+
1058
+ examples.forEach(([expected, actual]) => {
1059
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1060
+ expect(crvUSDRatioTrigger.decode(actual)).to.eql(expected);
1061
+ });
1062
+ });
1063
+ });
1064
+ });
1065
+
1066
+ describe('When testing triggerService.crvUsdHealthRatioTrigger', () => {
1067
+ describe('encode()', () => {
1068
+ const examples: Array<[[string], [owner: EthereumAddress, controller: EthereumAddress, ratioPercentage: number]]> = [
1069
+ [
1070
+ ['0x0000000000000000000000007a2af22ba3276108cd331c8985ef9528e10a871a000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000002c68af0bb140000'],
1071
+ [web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'), web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), 20]
1072
+ ]
1073
+ ];
1074
+ examples.forEach(([expected, actual]) => {
1075
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1076
+ expect(crvUsdHealthRatioTrigger.encode(...actual)).to.eql(expected);
1077
+ });
1078
+ });
1079
+ });
1080
+ describe('decode()', () => {
1081
+ const examples: Array<[{ owner: EthereumAddress, controller: EthereumAddress, ratio: number }, TriggerData]> = [
1082
+ [
1083
+ { owner: web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'), controller: web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), ratio: 20 },
1084
+ ['0x0000000000000000000000007a2af22ba3276108cd331c8985ef9528e10a871a000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000002c68af0bb140000'],
1085
+ ],
1086
+ ];
1087
+ examples.forEach(([expected, actual]) => {
1088
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1089
+ expect(crvUsdHealthRatioTrigger.decode(actual)).to.eql(expected);
1090
+ });
1091
+ });
1092
+ });
1093
+ });
1094
+
1095
+ describe('When testing triggerService.morphoBlueRatioTrigger', () => {
1096
+ describe('encode()', () => {
1097
+ const examples: Array<[[string], [marketId: string, owner: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
1098
+ [
1099
+ ['0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
1100
+ ['0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), 120, RatioState.UNDER]
1101
+ ],
1102
+ [
1103
+ ['0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
1104
+ ['0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc', web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), 200, RatioState.OVER]
1105
+ ],
1106
+ ];
1107
+ examples.forEach(([expected, actual]) => {
1108
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1109
+ expect(morphoBlueRatioTrigger.encode(...actual)).to.eql(expected);
1110
+ });
1111
+ });
1112
+ });
1113
+ describe('decode()', () => {
1114
+ const examples: Array<[{ marketId: string, owner: EthereumAddress, ratio: number, ratioState: RatioState }, TriggerData]> = [
1115
+ [
1116
+ { marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), ratio: 120, ratioState: RatioState.UNDER },
1117
+ ['0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
1118
+ ],
1119
+ [
1120
+ { marketId: '0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc', owner: web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), ratio: 200, ratioState: RatioState.OVER },
1121
+ ['0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
1122
+ ],
1123
+ ];
1124
+
1125
+ examples.forEach(([expected, actual]) => {
1126
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1127
+ expect(morphoBlueRatioTrigger.decode(actual)).to.eql(expected);
1128
+ });
1129
+ });
1130
+ });
1131
+ });
1132
+
1133
+ describe('When testing triggerService.compoundV3PriceTrigger', () => {
1134
+ describe('encode()', () => {
1135
+ const examples: Array<[[string], [market: EthereumAddress, collToken: EthereumAddress, user: EthereumAddress, price: number, priceState: RatioState]]> = [
1136
+ [
1137
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f07775030000000000000000000000000000000000000000000000000000002e90edd0000000000000000000000000000000000000000000000000000000000000000001'],
1138
+ [web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'), 2000, RatioState.UNDER]
1139
+ ],
1140
+ [
1141
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f077750300000000000000000000000000000000000000000000000000000045d964b8000000000000000000000000000000000000000000000000000000000000000000'],
1142
+ [web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'), 3000, RatioState.OVER]
1143
+ ],
1144
+ ];
1145
+
1146
+ examples.forEach(([expected, actual]) => {
1147
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1148
+ expect(compoundV3PriceTrigger.encode(...actual)).to.eql(expected);
1149
+ });
1150
+ });
1151
+ });
1152
+
1153
+ describe('decode()', () => {
1154
+ const examples: Array<[{ market: EthereumAddress, collToken: EthereumAddress, user: EthereumAddress, price: string, priceState: RatioState }, TriggerData]> = [
1155
+ [
1156
+ {
1157
+ market: web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1158
+ collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1159
+ user: web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
1160
+ price: '2000',
1161
+ priceState: RatioState.UNDER,
1162
+ },
1163
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f07775030000000000000000000000000000000000000000000000000000002e90edd0000000000000000000000000000000000000000000000000000000000000000001'],
1164
+ ],
1165
+ [
1166
+ {
1167
+ market: web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1168
+ collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1169
+ user: web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
1170
+ price: '3000',
1171
+ priceState: RatioState.OVER,
1172
+ },
1173
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f077750300000000000000000000000000000000000000000000000000000045d964b8000000000000000000000000000000000000000000000000000000000000000000'],
1174
+ ],
1175
+ ];
1176
+
1177
+ examples.forEach(([expected, actual]) => {
1178
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1179
+ expect(compoundV3PriceTrigger.decode(actual)).to.eql(expected);
1180
+ });
1181
+ });
1182
+ });
1183
+ });
1184
+
1185
+ describe('When testing triggerService.compoundV3PriceRangeTrigger', () => {
1186
+ describe('encode()', () => {
1187
+ const examples: Array<[[string], [market: EthereumAddress, collToken: EthereumAddress, lowerPrice: number, upperPrice: number]]> = [
1188
+ [
1189
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
1190
+ [web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 1500, 4000]
1191
+ ],
1192
+ [
1193
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
1194
+ [web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 0, 5000]
1195
+ ],
1196
+ ];
1197
+
1198
+ examples.forEach(([expected, actual]) => {
1199
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1200
+ expect(compoundV3PriceRangeTrigger.encode(...actual)).to.eql(expected);
1201
+ });
1202
+ });
1203
+ });
1204
+
1205
+ describe('decode()', () => {
1206
+ const examples: Array<[{ market: EthereumAddress, collToken: EthereumAddress, lowerPrice: string, upperPrice: string }, TriggerData]> = [
1207
+ [
1208
+ {
1209
+ market: web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1210
+ collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1211
+ lowerPrice: '1500',
1212
+ upperPrice: '4000',
1213
+ },
1214
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
1215
+ ],
1216
+ [
1217
+ {
1218
+ market: web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1219
+ collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1220
+ lowerPrice: '0',
1221
+ upperPrice: '5000',
1222
+ },
1223
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
1224
+ ],
1225
+ ];
1226
+
1227
+ examples.forEach(([expected, actual]) => {
1228
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1229
+ expect(compoundV3PriceRangeTrigger.decode(actual)).to.eql(expected);
1230
+ });
1231
+ });
1232
+ });
1233
+ });
1234
+ });