@defisaver/automation-sdk 3.0.1 → 3.0.2-dev2

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 (49) hide show
  1. package/esm/automation/private/LegacyAutomation.js +2 -2
  2. package/esm/automation/private/StrategiesAutomation.js +9 -1
  3. package/esm/automation/private/StrategiesAutomation.test.d.ts +1 -1
  4. package/esm/automation/private/StrategiesAutomation.test.js +500 -499
  5. package/esm/constants/index.d.ts +4 -25
  6. package/esm/constants/index.js +77 -1
  7. package/esm/services/ethereumService.test.d.ts +1 -1
  8. package/esm/services/ethereumService.test.js +1 -0
  9. package/esm/services/strategiesService.js +63 -3
  10. package/esm/services/strategiesService.test.d.ts +1 -1
  11. package/esm/services/strategiesService.test.js +1 -0
  12. package/esm/services/strategySubService.d.ts +17 -0
  13. package/esm/services/strategySubService.js +30 -1
  14. package/esm/services/strategySubService.test.d.ts +1 -1
  15. package/esm/services/strategySubService.test.js +152 -0
  16. package/esm/services/subDataService.d.ts +32 -0
  17. package/esm/services/subDataService.js +96 -1
  18. package/esm/services/subDataService.test.d.ts +1 -1
  19. package/esm/services/subDataService.test.js +193 -0
  20. package/esm/services/triggerService.d.ts +17 -0
  21. package/esm/services/triggerService.js +31 -1
  22. package/esm/services/triggerService.test.d.ts +1 -1
  23. package/esm/services/triggerService.test.js +65 -0
  24. package/esm/services/utils.test.d.ts +1 -1
  25. package/esm/services/utils.test.js +1 -0
  26. package/esm/types/enums.d.ts +27 -8
  27. package/esm/types/enums.js +19 -0
  28. package/package.json +3 -3
  29. package/scripts/generateContractTypes.js +1 -1
  30. package/src/automation/private/LegacyAutomation.ts +2 -2
  31. package/src/automation/private/StrategiesAutomation.test.ts +503 -501
  32. package/src/automation/private/StrategiesAutomation.ts +9 -0
  33. package/src/constants/index.ts +80 -3
  34. package/src/services/ethereumService.test.ts +1 -0
  35. package/src/services/ethereumService.ts +1 -1
  36. package/src/services/strategiesService.test.ts +1 -0
  37. package/src/services/strategiesService.ts +81 -3
  38. package/src/services/strategySubService.test.ts +187 -1
  39. package/src/services/strategySubService.ts +68 -0
  40. package/src/services/subDataService.test.ts +212 -1
  41. package/src/services/subDataService.ts +134 -1
  42. package/src/services/triggerService.test.ts +70 -0
  43. package/src/services/triggerService.ts +44 -1
  44. package/src/services/utils.test.ts +1 -0
  45. package/src/types/enums.ts +19 -0
  46. package/umd/index.js +397 -58
  47. package/.env +0 -4
  48. package/.yarn/releases/yarn-1.22.1.cjs +0 -147386
  49. package/.yarnrc.yml +0 -3
@@ -6,6 +6,7 @@ import * as web3Utils from 'web3-utils';
6
6
  import { ChainId, OrderType, RatioState } from '../types/enums';
7
7
  import type { EthereumAddress, SubData } from '../types';
8
8
 
9
+ import '../configuration';
9
10
  import {
10
11
  aaveV2LeverageManagementSubData,
11
12
  aaveV3LeverageManagementSubData,
@@ -29,8 +30,10 @@ import {
29
30
  sparkLeverageManagementSubData,
30
31
  sparkQuotePriceSubData,
31
32
  crvUSDLeverageManagementSubData,
32
- compoundV3L2LeverageManagementSubData,
33
+ compoundV3L2LeverageManagementSubData, morphoBlueLeverageManagementSubData, crvUSDPaybackSubData,
34
+ aaveV3OpenOrderSubData,
33
35
  } from './subDataService';
36
+ import { AAVE_V3_VARIABLE_BORROW_RATE } from '../constants';
34
37
 
35
38
  describe('Feature: subDataService.ts', () => {
36
39
 
@@ -1124,6 +1127,58 @@ describe('Feature: subDataService.ts', () => {
1124
1127
  });
1125
1128
  });
1126
1129
 
1130
+ describe('When testing subDataService.crvUSDPaybackSubData', () => {
1131
+ describe('encode()', () => {
1132
+ const examples: Array<[SubData, [controller: EthereumAddress, addressToPullTokensFrom: EthereumAddress, positionOwner: EthereumAddress, paybackAmount: string, crvUSDAddr: EthereumAddress]]> = [
1133
+ [
1134
+ [
1135
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1136
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1137
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1138
+ '0x00000000000000000000000000000000000000000000043c33c1937564800000',
1139
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1140
+ ],
1141
+ ['0xa920de414ea4ab66b97da1bfe9e6eca7d4219635', '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280', '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280', '20000', '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E'],
1142
+ ]
1143
+ ];
1144
+ examples.forEach(([expected, actual]) => {
1145
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1146
+ expect(crvUSDPaybackSubData.encode(...actual)).to.eql(expected);
1147
+ });
1148
+ });
1149
+ });
1150
+ describe('decode()', () => {
1151
+ const examples: Array<[{
1152
+ controller: EthereumAddress,
1153
+ addressToPullTokensFrom: EthereumAddress,
1154
+ positionOwner: EthereumAddress,
1155
+ paybackAmount: string,
1156
+ }, SubData]> = [
1157
+ [
1158
+ {
1159
+ controller: '0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635',
1160
+ addressToPullTokensFrom: '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280',
1161
+ positionOwner: '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280',
1162
+ paybackAmount: '20000'
1163
+ },
1164
+ [
1165
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1166
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1167
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1168
+ '0x00000000000000000000000000000000000000000000043c33c1937564800000',
1169
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1170
+ ]
1171
+ ]
1172
+ ];
1173
+
1174
+ examples.forEach(([expected, actual]) => {
1175
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1176
+ expect(crvUSDPaybackSubData.decode(actual)).to.eql(expected);
1177
+ });
1178
+ });
1179
+ });
1180
+ });
1181
+
1127
1182
  describe('When testing subDataService.compoundV3L2LeverageManagementSubData', () => {
1128
1183
  describe('encode()', () => {
1129
1184
  const examples: Array<[
@@ -1172,5 +1227,161 @@ describe('Feature: subDataService.ts', () => {
1172
1227
  });
1173
1228
  });
1174
1229
 
1230
+ describe('When testing subDataService.morphoBlueLeverageManagementSubData', () => {
1231
+ describe('encode()', () => {
1232
+ const examples: Array<[
1233
+ SubData,
1234
+ [loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, ratioState: RatioState, targetRatio: number, user: EthereumAddress, isEOA: boolean],
1235
+ ]> = [
1236
+ [
1237
+ [
1238
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1239
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1240
+ '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
1241
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1242
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1243
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1244
+ '0x00000000000000000000000000000000000000000000000010a741a462780000',
1245
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1246
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1247
+ ],
1248
+ [web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), '945000000000000000', RatioState.UNDER, 120, web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), false]
1249
+ ],
1250
+ [
1251
+ [
1252
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1253
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1254
+ '0x00000000000000000000000048f7e36eb6b826b2df4b2e630b62cd25e89e40e2',
1255
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1256
+ '0x0000000000000000000000000000000000000000000000000bef55718ad60000',
1257
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1258
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1259
+ '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c',
1260
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1261
+ ],
1262
+ [web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x48F7E36EB6B826B2dF4B2E630B62Cd25e89E40e2'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), '860000000000000000', RatioState.OVER, 200, web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), false]
1263
+ ],
1264
+ ];
1265
+
1266
+ examples.forEach(([expected, actual]) => {
1267
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1268
+ expect(morphoBlueLeverageManagementSubData.encode(...actual)).to.eql(expected);
1269
+ });
1270
+ });
1271
+ });
1272
+
1273
+ describe('decode()', () => {
1274
+ const examples: Array<[{ collToken: EthereumAddress, loanToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, targetRatio: number, user: EthereumAddress }, SubData]> = [
1275
+ [
1276
+ {
1277
+ 'collToken': '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
1278
+ 'irm': '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
1279
+ 'lltv': '945000000000000000',
1280
+ 'loanToken': '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
1281
+ 'oracle': '0x2a01EB9496094dA03c4E364Def50f5aD1280AD72',
1282
+ 'targetRatio': 120,
1283
+ 'user': '0x1031d218133AFaB8C2B819B1366c7e434Ad91e9c',
1284
+ },
1285
+ [
1286
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1287
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1288
+ '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
1289
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1290
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1291
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1292
+ '0x00000000000000000000000000000000000000000000000010a741a462780000',
1293
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1294
+ ],
1295
+ ],
1296
+ [
1297
+ {
1298
+ 'collToken': '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
1299
+ 'irm': '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
1300
+ 'lltv': '860000000000000000',
1301
+ 'loanToken': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
1302
+ 'oracle': '0x48F7E36EB6B826B2dF4B2E630B62Cd25e89E40e2',
1303
+ 'targetRatio': 200,
1304
+ 'user': '0x0043d218133aFaB8F2b829B106633E434aD94e2C',
1305
+ },
1306
+ [
1307
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1308
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1309
+ '0x00000000000000000000000048f7e36eb6b826b2df4b2e630b62cd25e89e40e2',
1310
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1311
+ '0x0000000000000000000000000000000000000000000000000bef55718ad60000',
1312
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1313
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1314
+ '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c',
1315
+ ],
1316
+ ],
1317
+ ];
1318
+
1319
+ examples.forEach(([expected, actual]) => {
1320
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1321
+ expect(morphoBlueLeverageManagementSubData.decode(actual)).to.eql(expected);
1322
+ });
1323
+ });
1324
+ });
1325
+ });
1326
+
1327
+ describe('When testing subDataService.aaveV3OpenOrderSubData', () => {
1328
+ describe('encode()', () => {
1329
+ const examples: Array<[SubData, [collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number]]> = [
1330
+ [
1331
+ [
1332
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1333
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1334
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
1335
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
1336
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
1337
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1338
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1339
+ ],
1340
+ [
1341
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1342
+ 0,
1343
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
1344
+ 4,
1345
+ web3Utils.toChecksumAddress('0x2f39d218133afab8f2b819b1066c7e434ad94e9e'),
1346
+ 200,
1347
+ ]
1348
+ ],
1349
+ ];
1350
+
1351
+ examples.forEach(([expected, actual]) => {
1352
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1353
+ expect(aaveV3OpenOrderSubData.encode(...actual)).to.eql(expected);
1354
+ });
1355
+ });
1356
+ });
1175
1357
 
1358
+ describe('decode()', () => {
1359
+ const examples: Array<[{ collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number}, SubData]> = [
1360
+ [
1361
+ {
1362
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1363
+ collAssetId: 0,
1364
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
1365
+ debtAssetId: 4,
1366
+ marketAddr: web3Utils.toChecksumAddress('0x2f39d218133afab8f2b819b1066c7e434ad94e9e'),
1367
+ targetRatio: 200,
1368
+ },
1369
+ [
1370
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1371
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1372
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
1373
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
1374
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
1375
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1376
+ ],
1377
+ ],
1378
+ ];
1379
+
1380
+ examples.forEach(([expected, actual]) => {
1381
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1382
+ expect(aaveV3OpenOrderSubData.decode(actual)).to.eql(expected);
1383
+ });
1384
+ });
1385
+ });
1386
+ });
1176
1387
  });
@@ -1,5 +1,7 @@
1
1
  import Dec from 'decimal.js';
2
2
  import AbiCoder from 'web3-eth-abi';
3
+ import { fromWei, toWei } from 'web3-utils';
4
+
3
5
  import { assetAmountInEth, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
4
6
  import { otherAddresses } from '@defisaver/sdk';
5
7
 
@@ -7,7 +9,7 @@ import type { SubData, EthereumAddress } from '../types';
7
9
  import type { OrderType } from '../types/enums';
8
10
  import { ChainId, RatioState } from '../types/enums';
9
11
 
10
- import { ZERO_ADDRESS } from '../constants';
12
+ import { AAVE_V3_VARIABLE_BORROW_RATE, ZERO_ADDRESS } from '../constants';
11
13
 
12
14
  import { compareAddresses, ratioPercentageToWei, weiToRatioPercentage } from './utils';
13
15
 
@@ -510,3 +512,134 @@ export const crvUSDLeverageManagementSubData = {
510
512
  return { controller, targetRatio };
511
513
  },
512
514
  };
515
+
516
+ export const crvUSDPaybackSubData = {
517
+ encode: (
518
+ controllerAddr: EthereumAddress,
519
+ addressToPullTokensFrom: EthereumAddress,
520
+ positionOwner: EthereumAddress,
521
+ paybackAmount: string,
522
+ crvUSDAddr: EthereumAddress,
523
+ ) => {
524
+ const controllerAddrEncoded = AbiCoder.encodeParameter('address', controllerAddr);
525
+ const addressToPullTokensFromEncoded = AbiCoder.encodeParameter('address', addressToPullTokensFrom);
526
+ const positionOwnerEncoded = AbiCoder.encodeParameter('address', positionOwner);
527
+ const paybackAmountEncoded = AbiCoder.encodeParameter('uint256', toWei(paybackAmount, 'ether'));
528
+ const crvUSDAddrEncoded = AbiCoder.encodeParameter('address', crvUSDAddr);
529
+ return [
530
+ controllerAddrEncoded,
531
+ addressToPullTokensFromEncoded,
532
+ positionOwnerEncoded,
533
+ paybackAmountEncoded,
534
+ crvUSDAddrEncoded,
535
+ ];
536
+ },
537
+ decode: (subData: SubData) => {
538
+ const controller = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
539
+ const addressToPullTokensFrom = AbiCoder.decodeParameter('address', subData[1]) as any as EthereumAddress;
540
+ const positionOwner = AbiCoder.decodeParameter('address', subData[2]) as any as EthereumAddress;
541
+ const weiPaybackAmount = AbiCoder.decodeParameter('uint256', subData[3]) as any as string;
542
+ const paybackAmount = fromWei(weiPaybackAmount, 'ether');
543
+ return {
544
+ controller,
545
+ addressToPullTokensFrom,
546
+ positionOwner,
547
+ paybackAmount,
548
+ };
549
+ },
550
+ };
551
+
552
+ export const morphoBlueLeverageManagementSubData = {
553
+ encode: (
554
+ loanToken: EthereumAddress,
555
+ collToken: EthereumAddress,
556
+ oracle: EthereumAddress,
557
+ irm: EthereumAddress,
558
+ lltv: string,
559
+ ratioState: RatioState,
560
+ targetRatio: number,
561
+ user: EthereumAddress,
562
+ isEOA: boolean,
563
+ ) => {
564
+ const loanTokenEncoded = AbiCoder.encodeParameter('address', loanToken);
565
+ const collTokenEncoded = AbiCoder.encodeParameter('address', collToken);
566
+ const oracleEncoded = AbiCoder.encodeParameter('address', oracle);
567
+ const irmEncoded = AbiCoder.encodeParameter('address', irm);
568
+ const lltvEncoded = AbiCoder.encodeParameter('uint256', lltv);
569
+ const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
570
+ const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
571
+ const userEncoded = AbiCoder.encodeParameter('address', user);
572
+ const isEOAEncoded = AbiCoder.encodeParameter('bool', isEOA);
573
+ return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, ratioStateEncoded, targetRatioEncoded, userEncoded, isEOAEncoded];
574
+ },
575
+ decode: (subData: SubData) => {
576
+ const loanToken = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
577
+ const collToken = AbiCoder.decodeParameter('address', subData[1]) as any as EthereumAddress;
578
+ const oracle = AbiCoder.decodeParameter('address', subData[2]) as any as EthereumAddress;
579
+ const irm = AbiCoder.decodeParameter('address', subData[3]) as any as EthereumAddress;
580
+ const lltv = AbiCoder.decodeParameter('uint256', subData[4]) as any as EthereumAddress;
581
+ const weiRatio = AbiCoder.decodeParameter('uint256', subData[6]) as any as EthereumAddress;
582
+ const user = AbiCoder.decodeParameter('address', subData[7]) as any as EthereumAddress;
583
+ const targetRatio = weiToRatioPercentage(weiRatio);
584
+
585
+ return {
586
+ loanToken,
587
+ collToken,
588
+ oracle,
589
+ irm,
590
+ lltv,
591
+ user,
592
+ targetRatio,
593
+ };
594
+ },
595
+ };
596
+
597
+ export const aaveV3OpenOrderSubData = {
598
+ encode(
599
+ collAsset: EthereumAddress,
600
+ collAssetId: number,
601
+ debtAsset: EthereumAddress,
602
+ debtAssetId: number,
603
+ marketAddr: EthereumAddress,
604
+ targetRatio: number,
605
+ ): SubData {
606
+ const encodedColl = AbiCoder.encodeParameter('address', collAsset);
607
+ const encodedCollId = AbiCoder.encodeParameter('uint8', collAssetId);
608
+ const encodedDebt = AbiCoder.encodeParameter('address', debtAsset);
609
+ const encodedDebtId = AbiCoder.encodeParameter('uint8', debtAssetId);
610
+ const encodedMarket = AbiCoder.encodeParameter('address', marketAddr);
611
+ const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
612
+ const useOnBehalfEncoded = AbiCoder.encodeParameter('bool', false);
613
+
614
+ return [
615
+ encodedColl,
616
+ encodedCollId,
617
+ encodedDebt,
618
+ encodedDebtId,
619
+ encodedMarket,
620
+ encodedTargetRatio,
621
+ useOnBehalfEncoded,
622
+ ];
623
+ },
624
+ decode(subData: SubData): {
625
+ collAsset: EthereumAddress,
626
+ collAssetId: number,
627
+ debtAsset: EthereumAddress,
628
+ debtAssetId: number,
629
+ marketAddr: EthereumAddress,
630
+ targetRatio: number,
631
+ } {
632
+ const collAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
633
+ const collAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
634
+ const debtAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
635
+ const debtAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
636
+ const marketAddr = AbiCoder.decodeParameter('address', subData[4]) as unknown as EthereumAddress;
637
+
638
+ const weiRatio = AbiCoder.decodeParameter('uint256', subData[5]) as any as string;
639
+ const targetRatio = weiToRatioPercentage(weiRatio);
640
+
641
+ return {
642
+ collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio,
643
+ };
644
+ },
645
+ };
@@ -5,6 +5,7 @@ import * as web3Utils from 'web3-utils';
5
5
  import { ChainId, OrderType, RatioState } from '../types/enums';
6
6
  import type { EthereumAddress, TriggerData } from '../types';
7
7
 
8
+ import '../configuration';
8
9
  import {
9
10
  aaveV2RatioTrigger,
10
11
  aaveV3QuotePriceTrigger,
@@ -26,6 +27,8 @@ import {
26
27
  trailingStopTrigger,
27
28
  liquityDebtInFrontWithLimitTrigger,
28
29
  crvUSDRatioTrigger,
30
+ morphoBlueRatioTrigger,
31
+ crvUsdHealthRatioTrigger,
29
32
  } from './triggerService';
30
33
 
31
34
  describe('Feature: triggerService.ts', () => {
@@ -931,4 +934,71 @@ describe('Feature: triggerService.ts', () => {
931
934
  });
932
935
  });
933
936
  });
937
+
938
+ describe('When testing triggerService.crvUsdHealthRatioTrigger', () => {
939
+ describe('encode()', () => {
940
+ const examples: Array<[[string], [owner: EthereumAddress, controller: EthereumAddress, ratioPercentage: number]]> = [
941
+ [
942
+ ['0x0000000000000000000000007a2af22ba3276108cd331c8985ef9528e10a871a000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000002c68af0bb140000'],
943
+ [web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'), web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), 20]
944
+ ]
945
+ ];
946
+ examples.forEach(([expected, actual]) => {
947
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
948
+ expect(crvUsdHealthRatioTrigger.encode(...actual)).to.eql(expected);
949
+ });
950
+ });
951
+ });
952
+ describe('decode()', () => {
953
+ const examples: Array<[{ owner: EthereumAddress, controller: EthereumAddress, ratio: number }, TriggerData]> = [
954
+ [
955
+ { owner: web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'), controller: web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), ratio: 20 },
956
+ ['0x0000000000000000000000007a2af22ba3276108cd331c8985ef9528e10a871a000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000002c68af0bb140000'],
957
+ ],
958
+ ];
959
+ examples.forEach(([expected, actual]) => {
960
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
961
+ expect(crvUsdHealthRatioTrigger.decode(actual)).to.eql(expected);
962
+ });
963
+ });
964
+ });
965
+ });
966
+
967
+ describe('When testing triggerService.morphoBlueRatioTrigger', () => {
968
+ describe('encode()', () => {
969
+ const examples: Array<[[string], [marketId: string, owner: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
970
+ [
971
+ ['0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
972
+ ['0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), 120, RatioState.UNDER]
973
+ ],
974
+ [
975
+ ['0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
976
+ ['0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc', web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), 200, RatioState.OVER]
977
+ ],
978
+ ];
979
+ examples.forEach(([expected, actual]) => {
980
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
981
+ expect(morphoBlueRatioTrigger.encode(...actual)).to.eql(expected);
982
+ });
983
+ });
984
+ });
985
+ describe('decode()', () => {
986
+ const examples: Array<[{ marketId: string, owner: EthereumAddress, ratio: number, ratioState: RatioState }, TriggerData]> = [
987
+ [
988
+ { marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), ratio: 120, ratioState: RatioState.UNDER },
989
+ ['0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
990
+ ],
991
+ [
992
+ { marketId: '0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc', owner: web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), ratio: 200, ratioState: RatioState.OVER },
993
+ ['0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
994
+ ],
995
+ ];
996
+
997
+ examples.forEach(([expected, actual]) => {
998
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
999
+ expect(morphoBlueRatioTrigger.decode(actual)).to.eql(expected);
1000
+ });
1001
+ });
1002
+ });
1003
+ });
934
1004
  });
@@ -381,7 +381,6 @@ export const curveUsdSoftLiquidationTrigger = {
381
381
  },
382
382
  };
383
383
 
384
-
385
384
  export const crvUSDRatioTrigger = {
386
385
  encode(
387
386
  owner: EthereumAddress,
@@ -404,3 +403,47 @@ export const crvUSDRatioTrigger = {
404
403
  };
405
404
  },
406
405
  };
406
+
407
+ export const crvUsdHealthRatioTrigger = {
408
+ encode(
409
+ owner: EthereumAddress,
410
+ controller: EthereumAddress,
411
+ ratioPercentage: number,
412
+ ) {
413
+ const ratioWei = ratioPercentageToWei(ratioPercentage);
414
+ return [AbiCoder.encodeParameters(['address', 'address', 'uint256'], [owner, controller, ratioWei])];
415
+ },
416
+ decode(
417
+ triggerData: TriggerData,
418
+ ) {
419
+ const decodedData = AbiCoder.decodeParameters(['address', 'address', 'uint256'], triggerData[0]);
420
+ return {
421
+ owner: decodedData[0] as EthereumAddress,
422
+ controller: decodedData[1] as EthereumAddress,
423
+ ratio: weiToRatioPercentage(decodedData[2] as string),
424
+ };
425
+ },
426
+ };
427
+
428
+ export const morphoBlueRatioTrigger = {
429
+ encode(
430
+ marketId: string, // bytes32
431
+ owner: EthereumAddress,
432
+ ratioPercentage: number,
433
+ ratioState: RatioState,
434
+ ) {
435
+ const ratioWei = ratioPercentageToWei(ratioPercentage);
436
+ return [AbiCoder.encodeParameters(['bytes32', 'address', 'uint256', 'uint8'], [marketId, owner, ratioWei, ratioState])];
437
+ },
438
+ decode(
439
+ triggerData: TriggerData,
440
+ ) {
441
+ const decodedData = AbiCoder.decodeParameters(['bytes32', 'address', 'uint256', 'uint8'], triggerData[0]);
442
+ return {
443
+ marketId: decodedData[0] as string,
444
+ owner: decodedData[1] as EthereumAddress,
445
+ ratio: weiToRatioPercentage(decodedData[2] as string),
446
+ ratioState: Number(decodedData[3]),
447
+ };
448
+ },
449
+ };
@@ -8,6 +8,7 @@ import { ChainId, ProtocolIdentifiers, RatioState } from '../types/enums';
8
8
 
9
9
  import { sparkEncode } from './strategySubService';
10
10
 
11
+ import '../configuration';
11
12
  import {
12
13
  addToArrayIf,
13
14
  addToObjectIf,
@@ -40,6 +40,7 @@ export namespace ProtocolIdentifiers {
40
40
  Exchange = 'Exchange',
41
41
  Spark = 'Spark',
42
42
  CrvUSD = 'CurveUSD',
43
+ MorphoBlue = 'MorphoBlue',
43
44
  }
44
45
 
45
46
  export enum LegacyAutomation {
@@ -64,16 +65,20 @@ export namespace Strategies {
64
65
  LIQUITY_DSR_PAYBACK = 69,
65
66
  LIQUITY_DSR_SUPPLY = 70,
66
67
  LIQUITY_DEBT_IN_FRONT_REPAY = 75,
68
+ CURVEUSD_PAYBACK = 92,
69
+ AAVE_V3_OPEN_ORDER_FROM_DEBT = 96,
67
70
  }
68
71
 
69
72
  export enum OptimismIds {
70
73
  EXCHANGE_DCA = 8,
71
74
  EXCHANGE_LIMIT_ORDER = 9,
75
+ AAVE_V3_OPEN_ORDER_FROM_DEBT = 12,
72
76
  }
73
77
 
74
78
  export enum ArbitrumIds {
75
79
  EXCHANGE_DCA = 8,
76
80
  EXCHANGE_LIMIT_ORDER = 9,
81
+ AAVE_V3_OPEN_ORDER_FROM_DEBT = 16,
77
82
  }
78
83
 
79
84
  export enum Identifiers {
@@ -93,10 +98,13 @@ export namespace Strategies {
93
98
  TrailingStopToColl = 'trailing-stop-to-collateral',
94
99
  TrailingStopToDebt = 'trailing-stop-to-debt',
95
100
  Rebond = 'rebond',
101
+ Payback = 'payback',
96
102
  BondProtection = 'bond-protection',
97
103
  Dca = 'dca',
98
104
  LimitOrder = 'limit-order',
99
105
  DebtInFrontRepay = 'debt-in-front-repay',
106
+ OpenOrderFromCollateral = 'open-order-from-collateral',
107
+ OpenOrderFromDebt = 'open-order-from-debt',
100
108
  }
101
109
  export enum IdOverrides {
102
110
  TakeProfit = 'take-profit',
@@ -141,6 +149,15 @@ export namespace Bundles {
141
149
  COMP_V2_BOOST = 21,
142
150
  CRVUSD_REPAY = 26,
143
151
  CRVUSD_BOOST = 27,
152
+ COMP_V3_SW_REPAY_V2_BUNDLE = 28,
153
+ COMP_V3_SW_BOOST_V2_BUNDLE = 29,
154
+ COMP_V3_EOA_REPAY_V2_BUNDLE = 30,
155
+ COMP_V3_EOA_BOOST_V2_BUNDLE = 31,
156
+ MORPHO_BLUE_REPAY = 32,
157
+ MORPHO_BLUE_BOOST = 33,
158
+ MORPHO_BLUE_EOA_REPAY = 34,
159
+ MORPHO_BLUE_EOA_BOOST = 35,
160
+ AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 36,
144
161
  }
145
162
 
146
163
  export enum OptimismIds {
@@ -148,6 +165,7 @@ export namespace Bundles {
148
165
  AAVE_V3_BOOST = 1,
149
166
  AAVE_V3_CLOSE_TO_DEBT = 2,
150
167
  AAVE_V3_CLOSE_TO_COLLATERAL = 3,
168
+ AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 4,
151
169
  }
152
170
 
153
171
  export enum ArbitrumIds {
@@ -157,6 +175,7 @@ export namespace Bundles {
157
175
  AAVE_V3_CLOSE_TO_COLLATERAL = 3,
158
176
  COMP_V3_SW_REPAY_BUNDLE = 4,
159
177
  COMP_V3_SW_BOOST_BUNDLE = 5,
178
+ AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 6,
160
179
  }
161
180
  }
162
181