@defisaver/automation-sdk 3.2.2 → 3.2.4

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 (245) 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 +564 -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 +898 -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 +110 -110
  67. package/cjs/services/strategySubService.js +308 -308
  68. package/cjs/services/strategySubService.test.d.ts +1 -1
  69. package/cjs/services/strategySubService.test.js +936 -936
  70. package/cjs/services/subDataService.d.ts +254 -254
  71. package/cjs/services/subDataService.js +669 -669
  72. package/cjs/services/subDataService.test.d.ts +1 -1
  73. package/cjs/services/subDataService.test.js +1282 -1282
  74. package/cjs/services/triggerService.d.ts +249 -234
  75. package/cjs/services/triggerService.js +473 -447
  76. package/cjs/services/triggerService.test.d.ts +1 -1
  77. package/cjs/services/triggerService.test.js +1045 -926
  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 +226 -226
  101. package/cjs/types/enums.js +252 -252
  102. package/cjs/types/index.d.ts +248 -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 +558 -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 +868 -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 +110 -110
  162. package/esm/services/strategySubService.js +279 -279
  163. package/esm/services/strategySubService.test.d.ts +1 -1
  164. package/esm/services/strategySubService.test.js +908 -908
  165. package/esm/services/subDataService.d.ts +254 -254
  166. package/esm/services/subDataService.js +663 -663
  167. package/esm/services/subDataService.test.d.ts +1 -1
  168. package/esm/services/subDataService.test.js +1254 -1254
  169. package/esm/services/triggerService.d.ts +249 -234
  170. package/esm/services/triggerService.js +444 -418
  171. package/esm/services/triggerService.test.d.ts +1 -1
  172. package/esm/services/triggerService.test.js +1020 -901
  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 +226 -226
  196. package/esm/types/enums.js +249 -249
  197. package/esm/types/index.d.ts +248 -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 +593 -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 +1158 -1158
  233. package/src/services/strategySubService.test.ts +1122 -1122
  234. package/src/services/strategySubService.ts +634 -634
  235. package/src/services/subDataService.test.ts +1387 -1387
  236. package/src/services/subDataService.ts +914 -914
  237. package/src/services/triggerService.test.ts +1130 -1004
  238. package/src/services/triggerService.ts +602 -574
  239. package/src/services/utils.test.ts +430 -430
  240. package/src/services/utils.ts +162 -162
  241. package/src/types/enums.ts +246 -246
  242. package/src/types/index.ts +312 -312
  243. package/tsconfig.esm.json +8 -8
  244. package/tsconfig.json +22 -22
  245. package/.env +0 -4
@@ -1,1004 +1,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
- 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,
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.aaveV2RatioTrigger', () => {
491
- describe('encode()', () => {
492
- const examples: Array<[[string], [owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
493
- [
494
- ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c0000000000000000000000000249d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000000'],
495
- [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'), web3Utils.toChecksumAddress('0x0249d218133AFaB8F2B829B1066c7E434Ad94E2c'), 120, RatioState.OVER]
496
- ],
497
- ];
498
-
499
- examples.forEach(([expected, actual]) => {
500
- it(`Given ${actual} should return expected value: ${expected}`, () => {
501
- expect(aaveV2RatioTrigger.encode(...actual)).to.eql(expected);
502
- });
503
- });
504
- });
505
-
506
- describe('decode()', () => {
507
- const examples: Array<[{ owner: EthereumAddress, market: EthereumAddress, ratioState: RatioState, ratio: number }, TriggerData]> = [
508
- [
509
- {
510
- owner: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'),
511
- market: web3Utils.toChecksumAddress('0x0249d218133AFaB8F2B829B1066c7E434Ad94E2c'),
512
- ratio: 120,
513
- ratioState: RatioState.OVER,
514
- },
515
- ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c0000000000000000000000000249d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000000'],
516
- ],
517
- ];
518
-
519
- examples.forEach(([expected, actual]) => {
520
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
521
- expect(aaveV2RatioTrigger.decode(actual)).to.eql(expected);
522
- });
523
- });
524
- });
525
- });
526
-
527
- describe('When testing triggerService.cBondsRebondTrigger', () => {
528
- describe('encode()', () => {
529
- const examples: Array<[[string], [bondId: number | string]]> = [
530
- [
531
- ['0x0000000000000000000000000000000000000000000000000000000000000141'],
532
- [321]
533
- ],
534
- [
535
- ['0x000000000000000000000000000000000000000000000000000000000000002c'],
536
- [44]
537
- ],
538
- ];
539
-
540
- examples.forEach(([expected, actual]) => {
541
- it(`Given ${actual} should return expected value: ${expected}`, () => {
542
- expect(cBondsRebondTrigger.encode(...actual)).to.eql(expected);
543
- });
544
- });
545
- });
546
-
547
- describe('decode()', () => {
548
- const examples: Array<[{ bondId: string }, TriggerData]> = [
549
- [
550
- { bondId: '321' },
551
- ['0x0000000000000000000000000000000000000000000000000000000000000141'],
552
- ],
553
- [
554
- { bondId: '44' },
555
- ['0x000000000000000000000000000000000000000000000000000000000000002c'],
556
- ],
557
- ];
558
-
559
- examples.forEach(([expected, actual]) => {
560
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
561
- expect(cBondsRebondTrigger.decode(actual)).to.eql(expected);
562
- });
563
- });
564
- });
565
- });
566
-
567
- describe('When testing triggerService.compoundV3RatioTrigger', () => {
568
- describe('encode()', () => {
569
- const examples: Array<[[string], [owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
570
- [
571
- ['0x0000000000000000000000000049d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000213d218133afab8f2b829b1066c7e43cad94e2c000000000000000000000000000000000000000000000000245c1c1e5f8600000000000000000000000000000000000000000000000000000000000000000000'],
572
- [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B106633E434Ad94E2c'), web3Utils.toChecksumAddress('0x0213d218133AFaB8F2B829B1066c7E43cAd94E2c'), 262, RatioState.OVER]
573
- ],
574
- [
575
- ['0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000213d212133afab8f2b829b1066c7e43cad94e2c0000000000000000000000000000000000000000000000002def7b767e8b00000000000000000000000000000000000000000000000000000000000000000001'],
576
- [web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'), 331, RatioState.UNDER]
577
- ],
578
- ];
579
-
580
- examples.forEach(([expected, actual]) => {
581
- it(`Given ${actual} should return expected value: ${expected}`, () => {
582
- expect(compoundV3RatioTrigger.encode(...actual)).to.eql(expected);
583
- });
584
- });
585
- });
586
-
587
- describe('decode()', () => {
588
- const examples: Array<[{ owner: EthereumAddress, market: EthereumAddress, ratioState: RatioState, ratio: number }, TriggerData]> = [
589
- [
590
- {
591
- owner: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B106633E434Ad94E2c'),
592
- market: web3Utils.toChecksumAddress('0x0213d218133AFaB8F2B829B1066c7E43cAd94E2c'),
593
- ratio: 262,
594
- ratioState: RatioState.OVER,
595
- },
596
- ['0x0000000000000000000000000049d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000213d218133afab8f2b829b1066c7e43cad94e2c000000000000000000000000000000000000000000000000245c1c1e5f8600000000000000000000000000000000000000000000000000000000000000000000'],
597
- ],
598
- [
599
- {
600
- owner: web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'),
601
- market: web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
602
- ratio: 331,
603
- ratioState: RatioState.UNDER,
604
- },
605
- ['0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000213d212133afab8f2b829b1066c7e43cad94e2c0000000000000000000000000000000000000000000000002def7b767e8b00000000000000000000000000000000000000000000000000000000000000000001'],
606
- ],
607
- ];
608
-
609
- examples.forEach(([expected, actual]) => {
610
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
611
- expect(compoundV3RatioTrigger.decode(actual)).to.eql(expected);
612
- });
613
- });
614
- });
615
- });
616
-
617
- describe('When testing triggerService.exchangeTimestampTrigger', () => {
618
- describe('encode()', () => {
619
- const examples: Array<[[string], [timestamp: number, interval: number]]> = [
620
- [
621
- ['0x0000000000000000000000000000000000000000000000000000018adbcdf3c10000000000000000000000000000000000000000000000000000000077359fb8'],
622
- [1695904822209, 2000003000]
623
- ],
624
- [
625
- ['0x00000000000000000000000000000000000000000000000000000189ed59a4010000000000000000000000000000000000000000000000000000000011e378b8'],
626
- [1691904222209, 300120248]
627
- ],
628
- ];
629
-
630
- examples.forEach(([expected, actual]) => {
631
- it(`Given ${actual} should return expected value: ${expected}`, () => {
632
- expect(exchangeTimestampTrigger.encode(...actual)).to.eql(expected);
633
- });
634
- });
635
- });
636
-
637
- describe('decode()', () => {
638
- const examples: Array<[{ timestamp: number, interval: number }, TriggerData]> = [
639
- [
640
- {
641
- timestamp: 1695904822209, interval: 2000003000,
642
- },
643
- ['0x0000000000000000000000000000000000000000000000000000018adbcdf3c10000000000000000000000000000000000000000000000000000000077359fb8'],
644
- ],
645
- [
646
- {
647
- timestamp: 1691904222209, interval: 300120248,
648
- },
649
- ['0x00000000000000000000000000000000000000000000000000000189ed59a4010000000000000000000000000000000000000000000000000000000011e378b8'],
650
- ],
651
- ];
652
-
653
- examples.forEach(([expected, actual]) => {
654
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
655
- expect(exchangeTimestampTrigger.decode(actual)).to.eql(expected);
656
- });
657
- });
658
- });
659
- });
660
-
661
- describe('When testing triggerService.exchangeOffchainPriceTrigger', () => {
662
- describe('encode()', () => {
663
- const examples: Array<[[string], [targetPrice: string, goodUntil: number, orderType: OrderType, fromTokenDecimals: number, toTokenDecimals: number]]> = [
664
- [
665
- ['0x00000000000000000000000000000000000000000000000001b4fbd92b5f80000000000000000000000000000000000000000000000000000000018adbcdf3c10000000000000000000000000000000000000000000000000000000000000000'],
666
- ['0.123', 1695904822209, OrderType.TAKE_PROFIT, 12, 12]
667
- ],
668
- [
669
- ['0x00000000000000000000000000000000000000000000000000000000003432120000000000000000000000000000000000000000000000000000018adbbead990000000000000000000000000000000000000000000000000000000000000001'],
670
- ['3.42069', 1695903821209, OrderType.STOP_LOSS, 18, 6]
671
- ],
672
- ];
673
-
674
- examples.forEach(([expected, actual]) => {
675
- it(`Given ${actual} should return expected value: ${expected}`, () => {
676
- expect(exchangeOffchainPriceTrigger.encode(...actual)).to.eql(expected);
677
- });
678
- });
679
- });
680
-
681
- describe('decode()', () => {
682
- const examples: Array<[{ orderType: OrderType; targetPrice: string; goodUntil: any }, [TriggerData, number, number]]> = [
683
- [
684
- {
685
- orderType: OrderType.TAKE_PROFIT, targetPrice: '0.123', goodUntil: 1695904822209,
686
- },
687
- [
688
- ['0x00000000000000000000000000000000000000000000000001b4fbd92b5f80000000000000000000000000000000000000000000000000000000018adbcdf3c10000000000000000000000000000000000000000000000000000000000000000'],
689
- 12,
690
- 12,
691
- ],
692
- ],
693
- [
694
- {
695
- orderType: OrderType.STOP_LOSS, targetPrice: '3.42069', goodUntil: 1695903821209,
696
- },
697
- [
698
- ['0x00000000000000000000000000000000000000000000000000000000003432120000000000000000000000000000000000000000000000000000018adbbead990000000000000000000000000000000000000000000000000000000000000001'],
699
- 18,
700
- 6,
701
- ],
702
- ],
703
- ];
704
-
705
- examples.forEach(([expected, actual]) => {
706
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
707
- expect(exchangeOffchainPriceTrigger.decode(...actual)).to.eql(expected);
708
- });
709
- });
710
- });
711
- });
712
-
713
- describe('When testing triggerService.sparkRatioTrigger', () => {
714
- describe('encode()', () => {
715
- const examples: Array<[[string], [owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
716
- [
717
- ['0x0000000000000000000000000031d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000001131d218133afab8f2b819b1066c7e434ad94e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
718
- [web3Utils.toChecksumAddress('0x0031d218133AFaB8F2B819B1066c7E434Ad94E9c'), web3Utils.toChecksumAddress('0x1131d218133AFaB8F2B819B1066c7E434Ad94E9c'), 120, RatioState.UNDER]
719
- ],
720
- [
721
- ['0x0000000000000000000000000231d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000000131d218133afab8f2b819b1066c7e434ad94e9c000000000000000000000000000000000000000000000000200ec4c2d72700000000000000000000000000000000000000000000000000000000000000000000'],
722
- [web3Utils.toChecksumAddress('0x0231d218133AFaB8F2B819B1066c7E434Ad94E9c'), web3Utils.toChecksumAddress('0x0131d218133AFaB8F2B819B1066c7E434Ad94E9c'), 231, RatioState.OVER]
723
- ],
724
- ];
725
-
726
- examples.forEach(([expected, actual]) => {
727
- it(`Given ${actual} should return expected value: ${expected}`, () => {
728
- expect(sparkRatioTrigger.encode(...actual)).to.eql(expected);
729
- });
730
- });
731
- });
732
-
733
- describe('decode()', () => {
734
- const examples: Array<[{ owner: EthereumAddress, market: EthereumAddress, ratio: number, ratioState: RatioState }, TriggerData]> = [
735
- [
736
- { owner: web3Utils.toChecksumAddress('0x0031d218133AFaB8F2B819B1066c7E434Ad94E9c'), market: web3Utils.toChecksumAddress('0x1131d218133AFaB8F2B819B1066c7E434Ad94E9c'), ratio: 120, ratioState: RatioState.UNDER },
737
- ['0x0000000000000000000000000031d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000001131d218133afab8f2b819b1066c7e434ad94e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
738
- ],
739
- [
740
- { owner: web3Utils.toChecksumAddress('0x0231d218133AFaB8F2B819B1066c7E434Ad94E9c'), market: web3Utils.toChecksumAddress('0x0131d218133AFaB8F2B819B1066c7E434Ad94E9c'), ratio: 231, ratioState: RatioState.OVER },
741
- ['0x0000000000000000000000000231d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000000131d218133afab8f2b819b1066c7e434ad94e9c000000000000000000000000000000000000000000000000200ec4c2d72700000000000000000000000000000000000000000000000000000000000000000000'],
742
- ],
743
- ];
744
-
745
- examples.forEach(([expected, actual]) => {
746
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
747
- expect(sparkRatioTrigger.decode(actual)).to.eql(expected);
748
- });
749
- });
750
- });
751
- });
752
-
753
- describe('When testing triggerService.sparkQuotePriceTrigger', () => {
754
- describe('encode()', () => {
755
- const examples: Array<[[string], [baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState]]> = [
756
- [
757
- ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000000000000000000000000000000000000000a8ca0000000000000000000000000000000000000000000000000000000000000001'],
758
- [getAssetInfo('DAI', ChainId.Ethereum).address, getAssetInfo('wstETH', ChainId.Ethereum).address, 0.0004321, RatioState.UNDER]
759
- ],
760
- [
761
- ['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000186b70000000000000000000000000000000000000000000000000000000000000000'],
762
- [getAssetInfo('WBTC', ChainId.Arbitrum).address, getAssetInfo('USDC', ChainId.Arbitrum).address, 0.00100023, RatioState.OVER]
763
- ],
764
- ];
765
-
766
- examples.forEach(([expected, actual]) => {
767
- it(`Given ${actual} should return expected value: ${expected}`, () => {
768
- expect(sparkQuotePriceTrigger.encode(...actual)).to.eql(expected);
769
- });
770
- });
771
- });
772
-
773
- describe('decode()', () => {
774
- const examples: Array<[{ baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: string, ratioState: RatioState }, TriggerData]> = [
775
- [
776
- {
777
- baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
778
- quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Ethereum).address),
779
- price: '0.0004321',
780
- ratioState: RatioState.UNDER,
781
- },
782
- ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000000000000000000000000000000000000000a8ca0000000000000000000000000000000000000000000000000000000000000001'],
783
- ],
784
- [
785
- {
786
- baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
787
- quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
788
- price: '0.00100023',
789
- ratioState: RatioState.OVER,
790
- },
791
- ['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000186b70000000000000000000000000000000000000000000000000000000000000000'],
792
- ]
793
- ];
794
-
795
- examples.forEach(([expected, actual]) => {
796
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
797
- expect(sparkQuotePriceTrigger.decode(actual)).to.eql(expected);
798
- });
799
- });
800
- });
801
- });
802
-
803
- describe('When testing triggerService.curveUsdBorrowRateTrigger', () => {
804
- describe('encode()', () => {
805
- const examples: Array<[[string], [market: EthereumAddress, targetRate: string, rateState: RatioState]]> = [
806
- [
807
- ['0x0000000000000000000000000031d218133afab8c2b819b1066c7e434ad91e9c000000000000000000000000000000000000000000000000000000005c3744c40000000000000000000000000000000000000000000000000000000000000001'],
808
- [web3Utils.toChecksumAddress('0x0031d218133AFaB8c2B819B1066c7E434Ad91E9c'), '5', RatioState.UNDER]
809
- ],
810
- [
811
- ['0x0000000000000000000000000031d318133afab8c2b819b1066c7e434ad91e9c0000000000000000000000000000000000000000000000000000000037de1dae0000000000000000000000000000000000000000000000000000000000000000'],
812
- [web3Utils.toChecksumAddress('0x0031d318133AFaB8c2B819B1066c7E434Ad91E9c'), '3', RatioState.OVER]
813
- ],
814
- ];
815
-
816
- examples.forEach(([expected, actual]) => {
817
- it(`Given ${actual} should return expected value: ${expected}`, () => {
818
- expect(curveUsdBorrowRateTrigger.encode(...actual)).to.eql(expected);
819
- });
820
- });
821
- });
822
-
823
- describe('decode()', () => {
824
- const examples: Array<[{ market: EthereumAddress, targetRate: string, rateState: RatioState }, TriggerData]> = [
825
- [
826
- {
827
- market: web3Utils.toChecksumAddress('0x0031d218133AFaB8c2B819B1066c7E434Ad91E9c'),
828
- // Because of precision of reverse engineered rate we can't get exact number
829
- targetRate: '4.9999999977932344260462314517997495470601974794180145018256513213117735079327887085499910715825462',
830
- rateState: RatioState.UNDER,
831
- },
832
- ['0x0000000000000000000000000031d218133afab8c2b819b1066c7e434ad91e9c000000000000000000000000000000000000000000000000000000005c3744c40000000000000000000000000000000000000000000000000000000000000001'],
833
- ],
834
- [
835
- {
836
- market: web3Utils.toChecksumAddress('0x0031d318133AFaB8c2B819B1066c7E434Ad91E9c'),
837
- // Because of precision of reverse engineered rate we can't get exact number
838
- targetRate: '2.999999998802635853596007720123861222767915626254160712723033189270277420764438661596057080730334',
839
- rateState: RatioState.OVER,
840
- },
841
- ['0x0000000000000000000000000031d318133afab8c2b819b1066c7e434ad91e9c0000000000000000000000000000000000000000000000000000000037de1dae0000000000000000000000000000000000000000000000000000000000000000'],
842
- ],
843
- ];
844
-
845
- examples.forEach(([expected, actual]) => {
846
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
847
- expect(curveUsdBorrowRateTrigger.decode(actual)).to.eql(expected);
848
- });
849
- });
850
- });
851
- });
852
-
853
- describe('When testing triggerService.curveUsdSoftLiquidationTrigger', () => {
854
- describe('encode()', () => {
855
- const examples: Array<[[string], [market: EthereumAddress, market: EthereumAddress, percentage: string]]> = [
856
- [
857
- ['0x0000000000000000000000000031d218133afab8c2a819b1066c7e434ad91e9c0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000000b1a2bc2ec50000'],
858
- [web3Utils.toChecksumAddress('0x0031d218133AFaB8c2a819B1066c7E434Ad91E9c'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), '5']
859
- ],
860
- [
861
- ['0x0000000000000000000000000031d218233afab8c2a819b1066c7e434ad91e9c0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000000000000000000000000000001298a2e67f060000'],
862
- [web3Utils.toChecksumAddress('0x0031d218233AFaB8c2a819B1066c7E434Ad91E9c'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), '134']
863
- ],
864
- ];
865
-
866
- examples.forEach(([expected, actual]) => {
867
- it(`Given ${actual} should return expected value: ${expected}`, () => {
868
- expect(curveUsdSoftLiquidationTrigger.encode(...actual)).to.eql(expected);
869
- });
870
- });
871
- });
872
-
873
- describe('decode()', () => {
874
- const examples: Array<[{ market: EthereumAddress, owner: EthereumAddress, percentage: string }, TriggerData]> = [
875
- [
876
- {
877
- market: web3Utils.toChecksumAddress('0x0031d218133AFaB8c2a819B1066c7E434Ad91E9c'),
878
- owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
879
- percentage: '5',
880
- },
881
- ['0x0000000000000000000000000031d218133afab8c2a819b1066c7e434ad91e9c0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000000b1a2bc2ec50000'],
882
- ],
883
- [
884
- {
885
- market: web3Utils.toChecksumAddress('0x0031d218233AFaB8c2a819B1066c7E434Ad91E9c'),
886
- owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
887
- percentage: '134',
888
- },
889
- ['0x0000000000000000000000000031d218233afab8c2a819b1066c7e434ad91e9c0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000000000000000000000000000001298a2e67f060000'],
890
- ],
891
- ];
892
-
893
- examples.forEach(([expected, actual]) => {
894
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
895
- expect(curveUsdSoftLiquidationTrigger.decode(actual)).to.eql(expected);
896
- });
897
- });
898
- });
899
- });
900
- describe('When testing triggerService.crvUSDRatioTrigger', () => {
901
- describe('encode()', () => {
902
- const examples: Array<[[string], [owner: EthereumAddress, controller: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
903
- [
904
- ['0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
905
- [web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), 120, RatioState.UNDER]
906
- ],
907
- [
908
- ['0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d42196350000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
909
- [web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), 200, RatioState.OVER]
910
- ],
911
- ];
912
- examples.forEach(([expected, actual]) => {
913
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
914
- expect(crvUSDRatioTrigger.encode(...actual)).to.eql(expected);
915
- });
916
- });
917
- });
918
- describe('decode()', () => {
919
- const examples: Array<[{ owner: EthereumAddress, controller: EthereumAddress, ratio: number, ratioState: RatioState }, TriggerData]> = [
920
- [
921
- { owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), controller: web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), ratio: 120, ratioState: RatioState.UNDER },
922
- ['0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
923
- ],
924
- [
925
- { owner: web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), controller: web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), ratio: 200, ratioState: RatioState.OVER },
926
- ['0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d42196350000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
927
- ],
928
- ];
929
-
930
- examples.forEach(([expected, actual]) => {
931
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
932
- expect(crvUSDRatioTrigger.decode(actual)).to.eql(expected);
933
- });
934
- });
935
- });
936
- });
937
-
938
- describe('When testing triggerService.crvUsdHealthRatioTrigger', () => {
939
- describe('encode()', () => {
940
- const examples: Array<[[string], [owner: EthereumAddress, controller: EthereumAddress, ratioPercentage: number]]> = [
941
- [
942
- ['0x0000000000000000000000007a2af22ba3276108cd331c8985ef9528e10a871a000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000002c68af0bb140000'],
943
- [web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'), web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), 20]
944
- ]
945
- ];
946
- examples.forEach(([expected, actual]) => {
947
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
948
- expect(crvUsdHealthRatioTrigger.encode(...actual)).to.eql(expected);
949
- });
950
- });
951
- });
952
- describe('decode()', () => {
953
- const examples: Array<[{ owner: EthereumAddress, controller: EthereumAddress, ratio: number }, TriggerData]> = [
954
- [
955
- { owner: web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'), controller: web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), ratio: 20 },
956
- ['0x0000000000000000000000007a2af22ba3276108cd331c8985ef9528e10a871a000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000002c68af0bb140000'],
957
- ],
958
- ];
959
- examples.forEach(([expected, actual]) => {
960
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
961
- expect(crvUsdHealthRatioTrigger.decode(actual)).to.eql(expected);
962
- });
963
- });
964
- });
965
- });
966
-
967
- describe('When testing triggerService.morphoBlueRatioTrigger', () => {
968
- describe('encode()', () => {
969
- const examples: Array<[[string], [marketId: string, owner: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
970
- [
971
- ['0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
972
- ['0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), 120, RatioState.UNDER]
973
- ],
974
- [
975
- ['0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
976
- ['0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc', web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), 200, RatioState.OVER]
977
- ],
978
- ];
979
- examples.forEach(([expected, actual]) => {
980
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
981
- expect(morphoBlueRatioTrigger.encode(...actual)).to.eql(expected);
982
- });
983
- });
984
- });
985
- describe('decode()', () => {
986
- const examples: Array<[{ marketId: string, owner: EthereumAddress, ratio: number, ratioState: RatioState }, TriggerData]> = [
987
- [
988
- { marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), ratio: 120, ratioState: RatioState.UNDER },
989
- ['0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
990
- ],
991
- [
992
- { marketId: '0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc', owner: web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), ratio: 200, ratioState: RatioState.OVER },
993
- ['0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
994
- ],
995
- ];
996
-
997
- examples.forEach(([expected, actual]) => {
998
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
999
- expect(morphoBlueRatioTrigger.decode(actual)).to.eql(expected);
1000
- });
1001
- });
1002
- });
1003
- });
1004
- });
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
+ });