@defisaver/automation-sdk 3.1.9 → 3.1.14-spark-dev

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