@defisaver/automation-sdk 3.0.2-dev → 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.
@@ -564,6 +564,60 @@ describe('Feature: strategySubService.ts', () => {
564
564
  });
565
565
  });
566
566
  });
567
+
568
+ describe('openOrder()', () => {
569
+ const examples: Array<[
570
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
571
+ [
572
+ strategyOrBundleId: number,
573
+ isBundle: boolean,
574
+ triggerData: {
575
+ baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState.UNDER
576
+ },
577
+ subData: {
578
+ collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number,
579
+ },
580
+ ]
581
+ ]> = [
582
+ [
583
+ [
584
+ Bundles.MainnetIds.AAVE_V3_OPEN_ORDER_FROM_COLLATERAL,
585
+ true,
586
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000007acead34980000000000000000000000000000000000000000000000000000000000000001'],
587
+ [
588
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
589
+ '0x000000000000000000000000000000000000000000000000000000000000000a',
590
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
591
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
592
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
593
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
594
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
595
+ ],
596
+ ],
597
+ [
598
+ Bundles.MainnetIds.AAVE_V3_OPEN_ORDER_FROM_COLLATERAL,
599
+ true,
600
+ {
601
+ baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 5274.534678, state: RatioState.UNDER
602
+ },
603
+ {
604
+ collAsset: getAssetInfo('WETH').address,
605
+ collAssetId: 10,
606
+ debtAsset: getAssetInfo('DAI').address,
607
+ debtAssetId: 4,
608
+ marketAddr: '0x2f39d218133afab8f2b819b1066c7e434ad94e9e',
609
+ targetRatio: 200,
610
+ },
611
+ ]
612
+ ],
613
+ ];
614
+
615
+ examples.forEach(([expected, actual]) => {
616
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
617
+ expect(aaveV3Encode.openOrder(...actual)).to.eql(expected);
618
+ });
619
+ });
620
+ });
567
621
  });
568
622
 
569
623
  describe('When testing strategySubService.compoundV2Encode', () => {
@@ -899,6 +953,44 @@ describe('Feature: strategySubService.ts', () => {
899
953
  });
900
954
  });
901
955
  });
956
+ describe('payback()', () => {
957
+ const examples: Array<[
958
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
959
+ [owner: EthereumAddress, addressToPullTokensFrom: EthereumAddress, positionOwner: EthereumAddress, paybackAmount: string, crvUSDAddr: EthereumAddress, controllerAddr: EthereumAddress, minHealthRatio: number],
960
+ ]> = [
961
+ [
962
+ [
963
+ Strategies.MainnetIds.CURVEUSD_PAYBACK,
964
+ false,
965
+ [
966
+ '0x0000000000000000000000007a2af22ba3276108cd331c8985ef9528e10a871a000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000002c68af0bb140000',
967
+ ],
968
+ [
969
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
970
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
971
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
972
+ '0x00000000000000000000000000000000000000000000043c33c1937564800000',
973
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e'
974
+ ],
975
+ ],
976
+ [
977
+ web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'),
978
+ web3Utils.toChecksumAddress('0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280'),
979
+ web3Utils.toChecksumAddress('0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280'),
980
+ '20000',
981
+ '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
982
+ web3Utils.toChecksumAddress('0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635'),
983
+ 20,
984
+ ]
985
+ ]
986
+ ];
987
+
988
+ examples.forEach(([expected, actual]) => {
989
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
990
+ expect(crvUSDEncode.payback(...actual)).to.eql(expected);
991
+ });
992
+ });
993
+ });
902
994
  });
903
995
  describe('When testing strategySubService.morphoBlueEncode', () => {
904
996
  describe('leverageManagement()', () => {
@@ -915,6 +1007,7 @@ describe('Feature: strategySubService.ts', () => {
915
1007
  targetRatio: number,
916
1008
  triggerRatio: number,
917
1009
  user: EthereumAddress,
1010
+ isEoa: boolean,
918
1011
  ],
919
1012
  ]> = [
920
1013
  [
@@ -933,6 +1026,7 @@ describe('Feature: strategySubService.ts', () => {
933
1026
  '0x0000000000000000000000000000000000000000000000000000000000000001',
934
1027
  '0x000000000000000000000000000000000000000000000000136dcc951d8c0000',
935
1028
  '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1029
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
936
1030
  ],
937
1031
  ],
938
1032
  [
@@ -945,7 +1039,8 @@ describe('Feature: strategySubService.ts', () => {
945
1039
  RatioState.UNDER,
946
1040
  140,
947
1041
  120,
948
- web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c')
1042
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1043
+ false,
949
1044
  ]
950
1045
  ],
951
1046
  [
@@ -964,6 +1059,7 @@ describe('Feature: strategySubService.ts', () => {
964
1059
  '0x0000000000000000000000000000000000000000000000000000000000000000',
965
1060
  '0x00000000000000000000000000000000000000000000000016345785d8a00000',
966
1061
  '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1062
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
967
1063
  ],
968
1064
  ],
969
1065
  [
@@ -976,7 +1072,8 @@ describe('Feature: strategySubService.ts', () => {
976
1072
  RatioState.OVER,
977
1073
  160,
978
1074
  200,
979
- web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c')
1075
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1076
+ false,
980
1077
  ]
981
1078
  ],
982
1079
  ];
@@ -296,6 +296,28 @@ export const aaveV3Encode = {
296
296
  } = triggerData;
297
297
  const triggerDataEncoded = triggerService.aaveV3QuotePriceWithMaximumGasPriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, ratioState, maximumGasPrice);
298
298
 
299
+ return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
300
+ },
301
+ openOrder(
302
+ strategyOrBundleId: number,
303
+ isBundle: boolean = true,
304
+ triggerData: {
305
+ baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState.UNDER
306
+ },
307
+ subData: {
308
+ collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number,
309
+ },
310
+ ) {
311
+ const {
312
+ collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio,
313
+ } = subData;
314
+ const subDataEncoded = subDataService.aaveV3OpenOrderSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio);
315
+
316
+ const {
317
+ baseTokenAddress, quoteTokenAddress, price, state,
318
+ } = triggerData;
319
+ const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
320
+
299
321
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
300
322
  },
301
323
  };
@@ -447,6 +469,23 @@ export const crvUSDEncode = {
447
469
 
448
470
  return [strategyOrBundleId, isBundle, triggerData, subData];
449
471
  },
472
+ payback(
473
+ proxyAddress: EthereumAddress,
474
+ addressToPullTokensFrom: EthereumAddress,
475
+ positionOwner: EthereumAddress,
476
+ paybackAmount: string,
477
+ crvUSDAddr: EthereumAddress,
478
+ controllerAddr: EthereumAddress,
479
+ minHealthRatio: number,
480
+ ) {
481
+ const subData = subDataService.crvUSDPaybackSubData.encode(controllerAddr, addressToPullTokensFrom, positionOwner, paybackAmount, crvUSDAddr);
482
+ const triggerData = triggerService.crvUsdHealthRatioTrigger.encode(proxyAddress, controllerAddr, minHealthRatio);
483
+
484
+ const strategyId = Strategies.MainnetIds.CURVEUSD_PAYBACK;
485
+ const isBundle = false;
486
+
487
+ return [strategyId, isBundle, triggerData, subData];
488
+ },
450
489
  };
451
490
 
452
491
  export const morphoBlueEncode = {
@@ -461,13 +500,17 @@ export const morphoBlueEncode = {
461
500
  targetRatio: number,
462
501
  triggerRatio: number,
463
502
  user: EthereumAddress,
503
+ isEOA: boolean,
464
504
  ) {
465
- const subData = subDataService.morphoBlueLeverageManagementSubData.encode(loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user);
505
+ const subData = subDataService.morphoBlueLeverageManagementSubData.encode(loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA);
466
506
 
467
507
  const triggerData = triggerService.morphoBlueRatioTrigger.encode(marketId, user, triggerRatio, ratioState);
468
508
 
469
509
  // over is boost, under is repay
470
- const strategyOrBundleId = ratioState === RatioState.OVER ? Bundles.MainnetIds.MORPHO_BLUE_BOOST : Bundles.MainnetIds.MORPHO_BLUE_REPAY;
510
+ const isBoost = ratioState === RatioState.OVER;
511
+ let strategyOrBundleId;
512
+ if (isBoost) strategyOrBundleId = isEOA ? Bundles.MainnetIds.MORPHO_BLUE_EOA_BOOST : Bundles.MainnetIds.MORPHO_BLUE_BOOST;
513
+ else strategyOrBundleId = isEOA ? Bundles.MainnetIds.MORPHO_BLUE_EOA_REPAY : Bundles.MainnetIds.MORPHO_BLUE_REPAY;
471
514
  const isBundle = true;
472
515
 
473
516
  return [strategyOrBundleId, isBundle, triggerData, subData];
@@ -30,8 +30,10 @@ import {
30
30
  sparkLeverageManagementSubData,
31
31
  sparkQuotePriceSubData,
32
32
  crvUSDLeverageManagementSubData,
33
- compoundV3L2LeverageManagementSubData, morphoBlueLeverageManagementSubData,
33
+ compoundV3L2LeverageManagementSubData, morphoBlueLeverageManagementSubData, crvUSDPaybackSubData,
34
+ aaveV3OpenOrderSubData,
34
35
  } from './subDataService';
36
+ import { AAVE_V3_VARIABLE_BORROW_RATE } from '../constants';
35
37
 
36
38
  describe('Feature: subDataService.ts', () => {
37
39
 
@@ -1125,6 +1127,58 @@ describe('Feature: subDataService.ts', () => {
1125
1127
  });
1126
1128
  });
1127
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
+
1128
1182
  describe('When testing subDataService.compoundV3L2LeverageManagementSubData', () => {
1129
1183
  describe('encode()', () => {
1130
1184
  const examples: Array<[
@@ -1177,7 +1231,7 @@ describe('Feature: subDataService.ts', () => {
1177
1231
  describe('encode()', () => {
1178
1232
  const examples: Array<[
1179
1233
  SubData,
1180
- [loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, ratioState: RatioState, targetRatio: number, user: EthereumAddress],
1234
+ [loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, ratioState: RatioState, targetRatio: number, user: EthereumAddress, isEOA: boolean],
1181
1235
  ]> = [
1182
1236
  [
1183
1237
  [
@@ -1189,8 +1243,9 @@ describe('Feature: subDataService.ts', () => {
1189
1243
  '0x0000000000000000000000000000000000000000000000000000000000000001',
1190
1244
  '0x00000000000000000000000000000000000000000000000010a741a462780000',
1191
1245
  '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1246
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1192
1247
  ],
1193
- [web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), '945000000000000000', RatioState.UNDER, 120, web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c')]
1248
+ [web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), '945000000000000000', RatioState.UNDER, 120, web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), false]
1194
1249
  ],
1195
1250
  [
1196
1251
  [
@@ -1202,8 +1257,9 @@ describe('Feature: subDataService.ts', () => {
1202
1257
  '0x0000000000000000000000000000000000000000000000000000000000000000',
1203
1258
  '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1204
1259
  '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c',
1260
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1205
1261
  ],
1206
- [web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x48F7E36EB6B826B2dF4B2E630B62Cd25e89E40e2'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), '860000000000000000', RatioState.OVER, 200, web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c')]
1262
+ [web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x48F7E36EB6B826B2dF4B2E630B62Cd25e89E40e2'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), '860000000000000000', RatioState.OVER, 200, web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), false]
1207
1263
  ],
1208
1264
  ];
1209
1265
 
@@ -1268,5 +1324,64 @@ describe('Feature: subDataService.ts', () => {
1268
1324
  });
1269
1325
  });
1270
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
+ });
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
+ ];
1271
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
+ });
1272
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
 
@@ -511,6 +513,42 @@ export const crvUSDLeverageManagementSubData = {
511
513
  },
512
514
  };
513
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
+
514
552
  export const morphoBlueLeverageManagementSubData = {
515
553
  encode: (
516
554
  loanToken: EthereumAddress,
@@ -521,6 +559,7 @@ export const morphoBlueLeverageManagementSubData = {
521
559
  ratioState: RatioState,
522
560
  targetRatio: number,
523
561
  user: EthereumAddress,
562
+ isEOA: boolean,
524
563
  ) => {
525
564
  const loanTokenEncoded = AbiCoder.encodeParameter('address', loanToken);
526
565
  const collTokenEncoded = AbiCoder.encodeParameter('address', collToken);
@@ -530,7 +569,8 @@ export const morphoBlueLeverageManagementSubData = {
530
569
  const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
531
570
  const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
532
571
  const userEncoded = AbiCoder.encodeParameter('address', user);
533
- return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, ratioStateEncoded, targetRatioEncoded, userEncoded];
572
+ const isEOAEncoded = AbiCoder.encodeParameter('bool', isEOA);
573
+ return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, ratioStateEncoded, targetRatioEncoded, userEncoded, isEOAEncoded];
534
574
  },
535
575
  decode: (subData: SubData) => {
536
576
  const loanToken = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
@@ -553,3 +593,53 @@ export const morphoBlueLeverageManagementSubData = {
553
593
  };
554
594
  },
555
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
+ };
@@ -28,6 +28,7 @@ import {
28
28
  liquityDebtInFrontWithLimitTrigger,
29
29
  crvUSDRatioTrigger,
30
30
  morphoBlueRatioTrigger,
31
+ crvUsdHealthRatioTrigger,
31
32
  } from './triggerService';
32
33
 
33
34
  describe('Feature: triggerService.ts', () => {
@@ -934,6 +935,35 @@ describe('Feature: triggerService.ts', () => {
934
935
  });
935
936
  });
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
+
937
967
  describe('When testing triggerService.morphoBlueRatioTrigger', () => {
938
968
  describe('encode()', () => {
939
969
  const examples: Array<[[string], [marketId: string, owner: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
@@ -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,
@@ -405,6 +404,27 @@ export const crvUSDRatioTrigger = {
405
404
  },
406
405
  };
407
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
+
408
428
  export const morphoBlueRatioTrigger = {
409
429
  encode(
410
430
  marketId: string, // bytes32
@@ -65,16 +65,20 @@ export namespace Strategies {
65
65
  LIQUITY_DSR_PAYBACK = 69,
66
66
  LIQUITY_DSR_SUPPLY = 70,
67
67
  LIQUITY_DEBT_IN_FRONT_REPAY = 75,
68
+ CURVEUSD_PAYBACK = 92,
69
+ AAVE_V3_OPEN_ORDER_FROM_DEBT = 96,
68
70
  }
69
71
 
70
72
  export enum OptimismIds {
71
73
  EXCHANGE_DCA = 8,
72
74
  EXCHANGE_LIMIT_ORDER = 9,
75
+ AAVE_V3_OPEN_ORDER_FROM_DEBT = 12,
73
76
  }
74
77
 
75
78
  export enum ArbitrumIds {
76
79
  EXCHANGE_DCA = 8,
77
80
  EXCHANGE_LIMIT_ORDER = 9,
81
+ AAVE_V3_OPEN_ORDER_FROM_DEBT = 16,
78
82
  }
79
83
 
80
84
  export enum Identifiers {
@@ -94,10 +98,13 @@ export namespace Strategies {
94
98
  TrailingStopToColl = 'trailing-stop-to-collateral',
95
99
  TrailingStopToDebt = 'trailing-stop-to-debt',
96
100
  Rebond = 'rebond',
101
+ Payback = 'payback',
97
102
  BondProtection = 'bond-protection',
98
103
  Dca = 'dca',
99
104
  LimitOrder = 'limit-order',
100
105
  DebtInFrontRepay = 'debt-in-front-repay',
106
+ OpenOrderFromCollateral = 'open-order-from-collateral',
107
+ OpenOrderFromDebt = 'open-order-from-debt',
101
108
  }
102
109
  export enum IdOverrides {
103
110
  TakeProfit = 'take-profit',
@@ -142,8 +149,15 @@ export namespace Bundles {
142
149
  COMP_V2_BOOST = 21,
143
150
  CRVUSD_REPAY = 26,
144
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,
145
156
  MORPHO_BLUE_REPAY = 32,
146
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,
147
161
  }
148
162
 
149
163
  export enum OptimismIds {
@@ -151,6 +165,7 @@ export namespace Bundles {
151
165
  AAVE_V3_BOOST = 1,
152
166
  AAVE_V3_CLOSE_TO_DEBT = 2,
153
167
  AAVE_V3_CLOSE_TO_COLLATERAL = 3,
168
+ AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 4,
154
169
  }
155
170
 
156
171
  export enum ArbitrumIds {
@@ -160,6 +175,7 @@ export namespace Bundles {
160
175
  AAVE_V3_CLOSE_TO_COLLATERAL = 3,
161
176
  COMP_V3_SW_REPAY_BUNDLE = 4,
162
177
  COMP_V3_SW_BOOST_BUNDLE = 5,
178
+ AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 6,
163
179
  }
164
180
  }
165
181