@defisaver/automation-sdk 3.2.2 → 3.2.4

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