@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.
@@ -1045,6 +1045,51 @@ describe('Feature: subDataService.ts', () => {
1045
1045
  });
1046
1046
  });
1047
1047
  });
1048
+ describe('When testing subDataService.crvUSDPaybackSubData', () => {
1049
+ describe('encode()', () => {
1050
+ const examples = [
1051
+ [
1052
+ [
1053
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1054
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1055
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1056
+ '0x00000000000000000000000000000000000000000000043c33c1937564800000',
1057
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1058
+ ],
1059
+ ['0xa920de414ea4ab66b97da1bfe9e6eca7d4219635', '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280', '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280', '20000', '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E'],
1060
+ ]
1061
+ ];
1062
+ examples.forEach(([expected, actual]) => {
1063
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1064
+ (0, chai_1.expect)(subDataService_1.crvUSDPaybackSubData.encode(...actual)).to.eql(expected);
1065
+ });
1066
+ });
1067
+ });
1068
+ describe('decode()', () => {
1069
+ const examples = [
1070
+ [
1071
+ {
1072
+ controller: '0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635',
1073
+ addressToPullTokensFrom: '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280',
1074
+ positionOwner: '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280',
1075
+ paybackAmount: '20000'
1076
+ },
1077
+ [
1078
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1079
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1080
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1081
+ '0x00000000000000000000000000000000000000000000043c33c1937564800000',
1082
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1083
+ ]
1084
+ ]
1085
+ ];
1086
+ examples.forEach(([expected, actual]) => {
1087
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1088
+ (0, chai_1.expect)(subDataService_1.crvUSDPaybackSubData.decode(actual)).to.eql(expected);
1089
+ });
1090
+ });
1091
+ });
1092
+ });
1048
1093
  describe('When testing subDataService.compoundV3L2LeverageManagementSubData', () => {
1049
1094
  describe('encode()', () => {
1050
1095
  const examples = [
@@ -1100,8 +1145,9 @@ describe('Feature: subDataService.ts', () => {
1100
1145
  '0x0000000000000000000000000000000000000000000000000000000000000001',
1101
1146
  '0x00000000000000000000000000000000000000000000000010a741a462780000',
1102
1147
  '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1148
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1103
1149
  ],
1104
- [web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), '945000000000000000', enums_1.RatioState.UNDER, 120, web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c')]
1150
+ [web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), '945000000000000000', enums_1.RatioState.UNDER, 120, web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), false]
1105
1151
  ],
1106
1152
  [
1107
1153
  [
@@ -1113,8 +1159,9 @@ describe('Feature: subDataService.ts', () => {
1113
1159
  '0x0000000000000000000000000000000000000000000000000000000000000000',
1114
1160
  '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1115
1161
  '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c',
1162
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1116
1163
  ],
1117
- [web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x48F7E36EB6B826B2dF4B2E630B62Cd25e89E40e2'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), '860000000000000000', enums_1.RatioState.OVER, 200, web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c')]
1164
+ [web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x48F7E36EB6B826B2dF4B2E630B62Cd25e89E40e2'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), '860000000000000000', enums_1.RatioState.OVER, 200, web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), false]
1118
1165
  ],
1119
1166
  ];
1120
1167
  examples.forEach(([expected, actual]) => {
@@ -1175,4 +1222,61 @@ describe('Feature: subDataService.ts', () => {
1175
1222
  });
1176
1223
  });
1177
1224
  });
1225
+ describe('When testing subDataService.aaveV3OpenOrderSubData', () => {
1226
+ describe('encode()', () => {
1227
+ const examples = [
1228
+ [
1229
+ [
1230
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1231
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1232
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
1233
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
1234
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
1235
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1236
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1237
+ ],
1238
+ [
1239
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1240
+ 0,
1241
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
1242
+ 4,
1243
+ web3Utils.toChecksumAddress('0x2f39d218133afab8f2b819b1066c7e434ad94e9e'),
1244
+ 200,
1245
+ ]
1246
+ ],
1247
+ ];
1248
+ examples.forEach(([expected, actual]) => {
1249
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1250
+ (0, chai_1.expect)(subDataService_1.aaveV3OpenOrderSubData.encode(...actual)).to.eql(expected);
1251
+ });
1252
+ });
1253
+ });
1254
+ describe('decode()', () => {
1255
+ const examples = [
1256
+ [
1257
+ {
1258
+ collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1259
+ collAssetId: 0,
1260
+ debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
1261
+ debtAssetId: 4,
1262
+ marketAddr: web3Utils.toChecksumAddress('0x2f39d218133afab8f2b819b1066c7e434ad94e9e'),
1263
+ targetRatio: 200,
1264
+ },
1265
+ [
1266
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1267
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1268
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
1269
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
1270
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
1271
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1272
+ ],
1273
+ ],
1274
+ ];
1275
+ examples.forEach(([expected, actual]) => {
1276
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1277
+ (0, chai_1.expect)(subDataService_1.aaveV3OpenOrderSubData.decode(actual)).to.eql(expected);
1278
+ });
1279
+ });
1280
+ });
1281
+ });
1178
1282
  });
@@ -172,6 +172,14 @@ export declare const crvUSDRatioTrigger: {
172
172
  ratioState: number;
173
173
  };
174
174
  };
175
+ export declare const crvUsdHealthRatioTrigger: {
176
+ encode(owner: EthereumAddress, controller: EthereumAddress, ratioPercentage: number): string[];
177
+ decode(triggerData: string[]): {
178
+ owner: string;
179
+ controller: string;
180
+ ratio: number;
181
+ };
182
+ };
175
183
  export declare const morphoBlueRatioTrigger: {
176
184
  encode(marketId: string, owner: EthereumAddress, ratioPercentage: number, ratioState: RatioState): string[];
177
185
  decode(triggerData: string[]): {
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.morphoBlueRatioTrigger = exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkQuotePriceTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
29
+ exports.morphoBlueRatioTrigger = exports.crvUsdHealthRatioTrigger = exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkQuotePriceTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
30
30
  const decimal_js_1 = __importDefault(require("decimal.js"));
31
31
  const tokens_1 = require("@defisaver/tokens");
32
32
  const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
@@ -335,6 +335,20 @@ exports.crvUSDRatioTrigger = {
335
335
  };
336
336
  },
337
337
  };
338
+ exports.crvUsdHealthRatioTrigger = {
339
+ encode(owner, controller, ratioPercentage) {
340
+ const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
341
+ return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256'], [owner, controller, ratioWei])];
342
+ },
343
+ decode(triggerData) {
344
+ const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256'], triggerData[0]);
345
+ return {
346
+ owner: decodedData[0],
347
+ controller: decodedData[1],
348
+ ratio: (0, utils_1.weiToRatioPercentage)(decodedData[2]),
349
+ };
350
+ },
351
+ };
338
352
  exports.morphoBlueRatioTrigger = {
339
353
  encode(marketId, // bytes32
340
354
  owner, ratioPercentage, ratioState) {
@@ -859,6 +859,34 @@ describe('Feature: triggerService.ts', () => {
859
859
  });
860
860
  });
861
861
  });
862
+ describe('When testing triggerService.crvUsdHealthRatioTrigger', () => {
863
+ describe('encode()', () => {
864
+ const examples = [
865
+ [
866
+ ['0x0000000000000000000000007a2af22ba3276108cd331c8985ef9528e10a871a000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000002c68af0bb140000'],
867
+ [web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'), web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), 20]
868
+ ]
869
+ ];
870
+ examples.forEach(([expected, actual]) => {
871
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
872
+ (0, chai_1.expect)(triggerService_1.crvUsdHealthRatioTrigger.encode(...actual)).to.eql(expected);
873
+ });
874
+ });
875
+ });
876
+ describe('decode()', () => {
877
+ const examples = [
878
+ [
879
+ { owner: web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'), controller: web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), ratio: 20 },
880
+ ['0x0000000000000000000000007a2af22ba3276108cd331c8985ef9528e10a871a000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000002c68af0bb140000'],
881
+ ],
882
+ ];
883
+ examples.forEach(([expected, actual]) => {
884
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
885
+ (0, chai_1.expect)(triggerService_1.crvUsdHealthRatioTrigger.decode(actual)).to.eql(expected);
886
+ });
887
+ });
888
+ });
889
+ });
862
890
  describe('When testing triggerService.morphoBlueRatioTrigger', () => {
863
891
  describe('encode()', () => {
864
892
  const examples = [
@@ -58,15 +58,19 @@ export declare namespace Strategies {
58
58
  EXCHANGE_LIMIT_ORDER = 51,
59
59
  LIQUITY_DSR_PAYBACK = 69,
60
60
  LIQUITY_DSR_SUPPLY = 70,
61
- LIQUITY_DEBT_IN_FRONT_REPAY = 75
61
+ LIQUITY_DEBT_IN_FRONT_REPAY = 75,
62
+ CURVEUSD_PAYBACK = 92,
63
+ AAVE_V3_OPEN_ORDER_FROM_DEBT = 96
62
64
  }
63
65
  enum OptimismIds {
64
66
  EXCHANGE_DCA = 8,
65
- EXCHANGE_LIMIT_ORDER = 9
67
+ EXCHANGE_LIMIT_ORDER = 9,
68
+ AAVE_V3_OPEN_ORDER_FROM_DEBT = 12
66
69
  }
67
70
  enum ArbitrumIds {
68
71
  EXCHANGE_DCA = 8,
69
- EXCHANGE_LIMIT_ORDER = 9
72
+ EXCHANGE_LIMIT_ORDER = 9,
73
+ AAVE_V3_OPEN_ORDER_FROM_DEBT = 16
70
74
  }
71
75
  enum Identifiers {
72
76
  SavingsLiqProtection = "smart-savings-liquidation-protection",
@@ -85,10 +89,13 @@ export declare namespace Strategies {
85
89
  TrailingStopToColl = "trailing-stop-to-collateral",
86
90
  TrailingStopToDebt = "trailing-stop-to-debt",
87
91
  Rebond = "rebond",
92
+ Payback = "payback",
88
93
  BondProtection = "bond-protection",
89
94
  Dca = "dca",
90
95
  LimitOrder = "limit-order",
91
- DebtInFrontRepay = "debt-in-front-repay"
96
+ DebtInFrontRepay = "debt-in-front-repay",
97
+ OpenOrderFromCollateral = "open-order-from-collateral",
98
+ OpenOrderFromDebt = "open-order-from-debt"
92
99
  }
93
100
  enum IdOverrides {
94
101
  TakeProfit = "take-profit",
@@ -132,14 +139,22 @@ export declare namespace Bundles {
132
139
  COMP_V2_BOOST = 21,
133
140
  CRVUSD_REPAY = 26,
134
141
  CRVUSD_BOOST = 27,
142
+ COMP_V3_SW_REPAY_V2_BUNDLE = 28,
143
+ COMP_V3_SW_BOOST_V2_BUNDLE = 29,
144
+ COMP_V3_EOA_REPAY_V2_BUNDLE = 30,
145
+ COMP_V3_EOA_BOOST_V2_BUNDLE = 31,
135
146
  MORPHO_BLUE_REPAY = 32,
136
- MORPHO_BLUE_BOOST = 33
147
+ MORPHO_BLUE_BOOST = 33,
148
+ MORPHO_BLUE_EOA_REPAY = 34,
149
+ MORPHO_BLUE_EOA_BOOST = 35,
150
+ AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 36
137
151
  }
138
152
  enum OptimismIds {
139
153
  AAVE_V3_REPAY = 0,
140
154
  AAVE_V3_BOOST = 1,
141
155
  AAVE_V3_CLOSE_TO_DEBT = 2,
142
- AAVE_V3_CLOSE_TO_COLLATERAL = 3
156
+ AAVE_V3_CLOSE_TO_COLLATERAL = 3,
157
+ AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 4
143
158
  }
144
159
  enum ArbitrumIds {
145
160
  AAVE_V3_REPAY = 0,
@@ -147,6 +162,7 @@ export declare namespace Bundles {
147
162
  AAVE_V3_CLOSE_TO_DEBT = 2,
148
163
  AAVE_V3_CLOSE_TO_COLLATERAL = 3,
149
164
  COMP_V3_SW_REPAY_BUNDLE = 4,
150
- COMP_V3_SW_BOOST_BUNDLE = 5
165
+ COMP_V3_SW_BOOST_BUNDLE = 5,
166
+ AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 6
151
167
  }
152
168
  }
@@ -71,16 +71,20 @@ var Strategies;
71
71
  MainnetIds[MainnetIds["LIQUITY_DSR_PAYBACK"] = 69] = "LIQUITY_DSR_PAYBACK";
72
72
  MainnetIds[MainnetIds["LIQUITY_DSR_SUPPLY"] = 70] = "LIQUITY_DSR_SUPPLY";
73
73
  MainnetIds[MainnetIds["LIQUITY_DEBT_IN_FRONT_REPAY"] = 75] = "LIQUITY_DEBT_IN_FRONT_REPAY";
74
+ MainnetIds[MainnetIds["CURVEUSD_PAYBACK"] = 92] = "CURVEUSD_PAYBACK";
75
+ MainnetIds[MainnetIds["AAVE_V3_OPEN_ORDER_FROM_DEBT"] = 96] = "AAVE_V3_OPEN_ORDER_FROM_DEBT";
74
76
  })(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
75
77
  let OptimismIds;
76
78
  (function (OptimismIds) {
77
79
  OptimismIds[OptimismIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
78
80
  OptimismIds[OptimismIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
81
+ OptimismIds[OptimismIds["AAVE_V3_OPEN_ORDER_FROM_DEBT"] = 12] = "AAVE_V3_OPEN_ORDER_FROM_DEBT";
79
82
  })(OptimismIds = Strategies.OptimismIds || (Strategies.OptimismIds = {}));
80
83
  let ArbitrumIds;
81
84
  (function (ArbitrumIds) {
82
85
  ArbitrumIds[ArbitrumIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
83
86
  ArbitrumIds[ArbitrumIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
87
+ ArbitrumIds[ArbitrumIds["AAVE_V3_OPEN_ORDER_FROM_DEBT"] = 16] = "AAVE_V3_OPEN_ORDER_FROM_DEBT";
84
88
  })(ArbitrumIds = Strategies.ArbitrumIds || (Strategies.ArbitrumIds = {}));
85
89
  let Identifiers;
86
90
  (function (Identifiers) {
@@ -100,10 +104,13 @@ var Strategies;
100
104
  Identifiers["TrailingStopToColl"] = "trailing-stop-to-collateral";
101
105
  Identifiers["TrailingStopToDebt"] = "trailing-stop-to-debt";
102
106
  Identifiers["Rebond"] = "rebond";
107
+ Identifiers["Payback"] = "payback";
103
108
  Identifiers["BondProtection"] = "bond-protection";
104
109
  Identifiers["Dca"] = "dca";
105
110
  Identifiers["LimitOrder"] = "limit-order";
106
111
  Identifiers["DebtInFrontRepay"] = "debt-in-front-repay";
112
+ Identifiers["OpenOrderFromCollateral"] = "open-order-from-collateral";
113
+ Identifiers["OpenOrderFromDebt"] = "open-order-from-debt";
107
114
  })(Identifiers = Strategies.Identifiers || (Strategies.Identifiers = {}));
108
115
  let IdOverrides;
109
116
  (function (IdOverrides) {
@@ -150,8 +157,15 @@ var Bundles;
150
157
  MainnetIds[MainnetIds["COMP_V2_BOOST"] = 21] = "COMP_V2_BOOST";
151
158
  MainnetIds[MainnetIds["CRVUSD_REPAY"] = 26] = "CRVUSD_REPAY";
152
159
  MainnetIds[MainnetIds["CRVUSD_BOOST"] = 27] = "CRVUSD_BOOST";
160
+ MainnetIds[MainnetIds["COMP_V3_SW_REPAY_V2_BUNDLE"] = 28] = "COMP_V3_SW_REPAY_V2_BUNDLE";
161
+ MainnetIds[MainnetIds["COMP_V3_SW_BOOST_V2_BUNDLE"] = 29] = "COMP_V3_SW_BOOST_V2_BUNDLE";
162
+ MainnetIds[MainnetIds["COMP_V3_EOA_REPAY_V2_BUNDLE"] = 30] = "COMP_V3_EOA_REPAY_V2_BUNDLE";
163
+ MainnetIds[MainnetIds["COMP_V3_EOA_BOOST_V2_BUNDLE"] = 31] = "COMP_V3_EOA_BOOST_V2_BUNDLE";
153
164
  MainnetIds[MainnetIds["MORPHO_BLUE_REPAY"] = 32] = "MORPHO_BLUE_REPAY";
154
165
  MainnetIds[MainnetIds["MORPHO_BLUE_BOOST"] = 33] = "MORPHO_BLUE_BOOST";
166
+ MainnetIds[MainnetIds["MORPHO_BLUE_EOA_REPAY"] = 34] = "MORPHO_BLUE_EOA_REPAY";
167
+ MainnetIds[MainnetIds["MORPHO_BLUE_EOA_BOOST"] = 35] = "MORPHO_BLUE_EOA_BOOST";
168
+ MainnetIds[MainnetIds["AAVE_V3_OPEN_ORDER_FROM_COLLATERAL"] = 36] = "AAVE_V3_OPEN_ORDER_FROM_COLLATERAL";
155
169
  })(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
156
170
  let OptimismIds;
157
171
  (function (OptimismIds) {
@@ -159,6 +173,7 @@ var Bundles;
159
173
  OptimismIds[OptimismIds["AAVE_V3_BOOST"] = 1] = "AAVE_V3_BOOST";
160
174
  OptimismIds[OptimismIds["AAVE_V3_CLOSE_TO_DEBT"] = 2] = "AAVE_V3_CLOSE_TO_DEBT";
161
175
  OptimismIds[OptimismIds["AAVE_V3_CLOSE_TO_COLLATERAL"] = 3] = "AAVE_V3_CLOSE_TO_COLLATERAL";
176
+ OptimismIds[OptimismIds["AAVE_V3_OPEN_ORDER_FROM_COLLATERAL"] = 4] = "AAVE_V3_OPEN_ORDER_FROM_COLLATERAL";
162
177
  })(OptimismIds = Bundles.OptimismIds || (Bundles.OptimismIds = {}));
163
178
  let ArbitrumIds;
164
179
  (function (ArbitrumIds) {
@@ -168,5 +183,6 @@ var Bundles;
168
183
  ArbitrumIds[ArbitrumIds["AAVE_V3_CLOSE_TO_COLLATERAL"] = 3] = "AAVE_V3_CLOSE_TO_COLLATERAL";
169
184
  ArbitrumIds[ArbitrumIds["COMP_V3_SW_REPAY_BUNDLE"] = 4] = "COMP_V3_SW_REPAY_BUNDLE";
170
185
  ArbitrumIds[ArbitrumIds["COMP_V3_SW_BOOST_BUNDLE"] = 5] = "COMP_V3_SW_BOOST_BUNDLE";
186
+ ArbitrumIds[ArbitrumIds["AAVE_V3_OPEN_ORDER_FROM_COLLATERAL"] = 6] = "AAVE_V3_OPEN_ORDER_FROM_COLLATERAL";
171
187
  })(ArbitrumIds = Bundles.ArbitrumIds || (Bundles.ArbitrumIds = {}));
172
188
  })(Bundles = exports.Bundles || (exports.Bundles = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "3.0.2-dev",
3
+ "version": "3.0.2-dev2",
4
4
  "description": "",
5
5
  "main": "./umd/index.js",
6
6
  "module": "./esm/index.js",
@@ -12,7 +12,7 @@
12
12
  "build": "npm run lint && npm run build:umd && npm run build:esm",
13
13
  "documentMD": "npx typedoc --plugin typedoc-plugin-markdown --out docs/md",
14
14
  "document": "npx typedoc --out docs/default",
15
- "lint": "node_modules/.bin/eslint ./src",
15
+ "lint": "eslint ./src",
16
16
  "gtc": "node scripts/generateContractTypes.js",
17
17
  "prepare": "husky install && npm run gtc",
18
18
  "test": "./.tests.sh"
@@ -46,7 +46,9 @@ export default class StrategiesAutomation extends Automation {
46
46
  }
47
47
 
48
48
  protected async getEventFromSubStorage(event: string, options?: PastEventOptions) {
49
- if (new Dec(this.subStorageContract.createdBlock.toString()).gt(options?.fromBlock?.toString() || 0)) {
49
+ // only used for backfilling, so in case options?.fromBlock in undefined
50
+ // (just like we omit fromBlock when we call from app when not on fork), we still want to fetch events
51
+ if (new Dec(this.subStorageContract.createdBlock.toString()).gt(options?.fromBlock?.toString() || this.subStorageContract.createdBlock.toString())) {
50
52
  return [];
51
53
  }
52
54
  return getEventsFromContract<SubStorage>(this.subStorageContract, this.subStorageContractFork, event, options);
@@ -1,5 +1,5 @@
1
1
  import type {
2
- ArbitrumBundleInfo, BundlesInfo, EthereumAddress, Interfaces, MainnetBundleInfo, MainnetStrategiesInfo, OptimismBundleInfo, StrategiesInfo,
2
+ ArbitrumBundleInfo, ArbitrumStrategiesInfo, BundlesInfo, EthereumAddress, Interfaces, MainnetBundleInfo, MainnetStrategiesInfo, OptimismBundleInfo, OptimismStrategiesInfo, StrategiesInfo,
3
3
  } from '../types';
4
4
 
5
5
  import {
@@ -12,6 +12,8 @@ import LegacyProtocol from '../automation/private/LegacyProtocol';
12
12
  // General
13
13
  export const ZERO_ADDRESS: EthereumAddress = '0x0000000000000000000000000000000000000000';
14
14
 
15
+ export const AAVE_V3_VARIABLE_BORROW_RATE = 2;
16
+
15
17
  export const PROTOCOLS: Record<keyof typeof ProtocolIdentifiers.StrategiesAutomation, Interfaces.Protocol> = (() => {
16
18
  const protocolsMapping: any = {};
17
19
  Object.entries(ProtocolIdentifiers.StrategiesAutomation).forEach(([id, value]) => {
@@ -95,9 +97,19 @@ export const MAINNET_STRATEGIES_INFO: MainnetStrategiesInfo = {
95
97
  strategyId: Strategies.Identifiers.DebtInFrontRepay,
96
98
  protocol: PROTOCOLS.Liquity,
97
99
  },
100
+ [Strategies.MainnetIds.CURVEUSD_PAYBACK]: {
101
+ strategyOrBundleId: Strategies.MainnetIds.CURVEUSD_PAYBACK,
102
+ strategyId: Strategies.Identifiers.Payback,
103
+ protocol: PROTOCOLS.CrvUSD,
104
+ },
105
+ [Strategies.MainnetIds.AAVE_V3_OPEN_ORDER_FROM_DEBT]: {
106
+ strategyOrBundleId: Strategies.MainnetIds.AAVE_V3_OPEN_ORDER_FROM_DEBT,
107
+ strategyId: Strategies.Identifiers.OpenOrderFromDebt,
108
+ protocol: PROTOCOLS.AaveV3,
109
+ },
98
110
  };
99
111
 
100
- export const OPTIMISM_STRATEGIES_INFO = {
112
+ export const OPTIMISM_STRATEGIES_INFO: OptimismStrategiesInfo = {
101
113
  [Strategies.OptimismIds.EXCHANGE_DCA]: {
102
114
  strategyOrBundleId: Strategies.OptimismIds.EXCHANGE_DCA,
103
115
  strategyId: Strategies.Identifiers.Dca,
@@ -108,9 +120,14 @@ export const OPTIMISM_STRATEGIES_INFO = {
108
120
  strategyId: Strategies.Identifiers.LimitOrder,
109
121
  protocol: PROTOCOLS.Exchange,
110
122
  },
123
+ [Strategies.OptimismIds.AAVE_V3_OPEN_ORDER_FROM_DEBT]: {
124
+ strategyOrBundleId: Strategies.OptimismIds.AAVE_V3_OPEN_ORDER_FROM_DEBT,
125
+ strategyId: Strategies.Identifiers.OpenOrderFromDebt,
126
+ protocol: PROTOCOLS.AaveV3,
127
+ },
111
128
  };
112
129
 
113
- export const ARBITRUM_STRATEGIES_INFO = {
130
+ export const ARBITRUM_STRATEGIES_INFO: ArbitrumStrategiesInfo = {
114
131
  [Strategies.ArbitrumIds.EXCHANGE_DCA]: {
115
132
  strategyOrBundleId: Strategies.ArbitrumIds.EXCHANGE_DCA,
116
133
  strategyId: Strategies.Identifiers.Dca,
@@ -121,6 +138,11 @@ export const ARBITRUM_STRATEGIES_INFO = {
121
138
  strategyId: Strategies.Identifiers.LimitOrder,
122
139
  protocol: PROTOCOLS.Exchange,
123
140
  },
141
+ [Strategies.ArbitrumIds.AAVE_V3_OPEN_ORDER_FROM_DEBT]: {
142
+ strategyOrBundleId: Strategies.ArbitrumIds.AAVE_V3_OPEN_ORDER_FROM_DEBT,
143
+ strategyId: Strategies.Identifiers.OpenOrderFromDebt,
144
+ protocol: PROTOCOLS.AaveV3,
145
+ },
124
146
  };
125
147
 
126
148
  export const STRATEGIES_INFO: StrategiesInfo = {
@@ -178,6 +200,26 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
178
200
  strategyId: Strategies.Identifiers.EoaBoost,
179
201
  protocol: PROTOCOLS.CompoundV3,
180
202
  },
203
+ [Bundles.MainnetIds.COMP_V3_SW_REPAY_V2_BUNDLE]: {
204
+ strategyOrBundleId: Bundles.MainnetIds.COMP_V3_SW_REPAY_V2_BUNDLE,
205
+ strategyId: Strategies.Identifiers.Repay,
206
+ protocol: PROTOCOLS.CompoundV3,
207
+ },
208
+ [Bundles.MainnetIds.COMP_V3_SW_BOOST_V2_BUNDLE]: {
209
+ strategyOrBundleId: Bundles.MainnetIds.COMP_V3_SW_BOOST_V2_BUNDLE,
210
+ strategyId: Strategies.Identifiers.Boost,
211
+ protocol: PROTOCOLS.CompoundV3,
212
+ },
213
+ [Bundles.MainnetIds.COMP_V3_EOA_REPAY_V2_BUNDLE]: {
214
+ strategyOrBundleId: Bundles.MainnetIds.COMP_V3_EOA_REPAY_V2_BUNDLE,
215
+ strategyId: Strategies.Identifiers.EoaRepay,
216
+ protocol: PROTOCOLS.CompoundV3,
217
+ },
218
+ [Bundles.MainnetIds.COMP_V3_EOA_BOOST_V2_BUNDLE]: {
219
+ strategyOrBundleId: Bundles.MainnetIds.COMP_V3_EOA_BOOST_V2_BUNDLE,
220
+ strategyId: Strategies.Identifiers.EoaBoost,
221
+ protocol: PROTOCOLS.CompoundV3,
222
+ },
181
223
  [Bundles.MainnetIds.LIQUITY_PAYBACK_USING_CHICKEN_BOND]: {
182
224
  strategyOrBundleId: Bundles.MainnetIds.LIQUITY_PAYBACK_USING_CHICKEN_BOND,
183
225
  strategyId: Strategies.Identifiers.BondProtection,
@@ -303,6 +345,21 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
303
345
  strategyId: Strategies.Identifiers.Boost,
304
346
  protocol: PROTOCOLS.MorphoBlue,
305
347
  },
348
+ [Bundles.MainnetIds.MORPHO_BLUE_EOA_REPAY]: {
349
+ strategyOrBundleId: Bundles.MainnetIds.MORPHO_BLUE_EOA_REPAY,
350
+ strategyId: Strategies.Identifiers.EoaRepay,
351
+ protocol: PROTOCOLS.MorphoBlue,
352
+ },
353
+ [Bundles.MainnetIds.MORPHO_BLUE_EOA_BOOST]: {
354
+ strategyOrBundleId: Bundles.MainnetIds.MORPHO_BLUE_EOA_BOOST,
355
+ strategyId: Strategies.Identifiers.EoaBoost,
356
+ protocol: PROTOCOLS.MorphoBlue,
357
+ },
358
+ [Bundles.MainnetIds.AAVE_V3_OPEN_ORDER_FROM_COLLATERAL]: {
359
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V3_OPEN_ORDER_FROM_COLLATERAL,
360
+ strategyId: Strategies.Identifiers.OpenOrderFromCollateral,
361
+ protocol: PROTOCOLS.AaveV3,
362
+ },
306
363
  };
307
364
 
308
365
  export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
@@ -326,6 +383,11 @@ export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
326
383
  strategyId: Strategies.Identifiers.CloseToCollateral,
327
384
  protocol: PROTOCOLS.AaveV3,
328
385
  },
386
+ [Bundles.OptimismIds.AAVE_V3_OPEN_ORDER_FROM_COLLATERAL]: {
387
+ strategyOrBundleId: Bundles.OptimismIds.AAVE_V3_OPEN_ORDER_FROM_COLLATERAL,
388
+ strategyId: Strategies.Identifiers.OpenOrderFromCollateral,
389
+ protocol: PROTOCOLS.AaveV3,
390
+ },
329
391
  };
330
392
 
331
393
  export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
@@ -359,6 +421,11 @@ export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
359
421
  strategyId: Strategies.Identifiers.Repay,
360
422
  protocol: PROTOCOLS.CompoundV3,
361
423
  },
424
+ [Bundles.ArbitrumIds.AAVE_V3_OPEN_ORDER_FROM_COLLATERAL]: {
425
+ strategyOrBundleId: Bundles.ArbitrumIds.AAVE_V3_OPEN_ORDER_FROM_COLLATERAL,
426
+ strategyId: Strategies.Identifiers.OpenOrderFromCollateral,
427
+ protocol: PROTOCOLS.AaveV3,
428
+ },
362
429
  };
363
430
 
364
431
  export const BUNDLES_INFO: BundlesInfo = {
@@ -66,4 +66,4 @@ export async function getEventsFromContract<T extends BaseContract>(
66
66
  }
67
67
 
68
68
  return [...events, ...eventsFork];
69
- }
69
+ }
@@ -431,9 +431,8 @@ function parseCompoundV3LeverageManagement(position: Position.Automated, parseDa
431
431
 
432
432
  _position.strategyData.decoded.triggerData = triggerData;
433
433
  _position.strategyData.decoded.subData = subData;
434
- _position.owner = triggerData.owner.toLowerCase();
435
434
 
436
- _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.market);
435
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, triggerData.owner.toLowerCase(), triggerData.market);
437
436
 
438
437
  const isRepay = [Strategies.Identifiers.Repay, Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId as Strategies.Identifiers);
439
438
 
@@ -692,7 +691,10 @@ function parseCrvUSDLeverageManagement(position: Position.Automated, parseData:
692
691
  _position.strategyData.decoded.triggerData = triggerData;
693
692
  _position.strategyData.decoded.subData = subData;
694
693
 
694
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.controller);
695
+
695
696
  const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
697
+
696
698
  if (isRepay) {
697
699
  _position.specific = {
698
700
  triggerRepayRatio: triggerData.ratio,
@@ -713,12 +715,26 @@ function parseCrvUSDLeverageManagement(position: Position.Automated, parseData:
713
715
  };
714
716
  }
715
717
 
716
- _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.controller);
717
718
  _position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
718
719
 
719
720
  return _position;
720
721
  }
721
722
 
723
+ function parseCrvUSDPayback(position: Position.Automated, parseData: ParseData): Position.Automated {
724
+ const _position = cloneDeep(position);
725
+
726
+ const { subStruct } = parseData.subscriptionEventData;
727
+ const triggerData = triggerService.crvUsdHealthRatioTrigger.decode(subStruct.triggerData);
728
+ const subData = subDataService.crvUSDPaybackSubData.decode(subStruct.subData);
729
+
730
+ _position.strategyData.decoded.triggerData = triggerData;
731
+ _position.strategyData.decoded.subData = subData;
732
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.controller, Math.random());
733
+ _position.strategy.strategyId = Strategies.Identifiers.Payback;
734
+
735
+ return _position;
736
+ }
737
+
722
738
  function parseMorphoBlueLeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
723
739
  const _position = cloneDeep(position);
724
740
 
@@ -729,7 +745,10 @@ function parseMorphoBlueLeverageManagement(position: Position.Automated, parseDa
729
745
 
730
746
  _position.strategyData.decoded.triggerData = triggerData;
731
747
  _position.strategyData.decoded.subData = subData;
732
- const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
748
+
749
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, triggerData.owner.toLowerCase(), triggerData.marketId);
750
+
751
+ const isRepay = [Strategies.Identifiers.Repay, Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId as Strategies.Identifiers);
733
752
 
734
753
  if (isRepay) {
735
754
  _position.specific = {
@@ -751,8 +770,21 @@ function parseMorphoBlueLeverageManagement(position: Position.Automated, parseDa
751
770
  };
752
771
  }
753
772
 
754
- _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.marketId);
755
- _position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
773
+ const isEOA = _position.strategy.strategyId.includes('eoa');
774
+ _position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagement : Strategies.IdOverrides.LeverageManagement;
775
+
776
+
777
+ return _position;
778
+ }
779
+
780
+ function parseAaveV3OpenOrderFromCollateral(position: Position.Automated, parseData: ParseData): Position.Automated {
781
+ const _position = cloneDeep(position);
782
+
783
+ const { subStruct } = parseData.subscriptionEventData;
784
+
785
+ _position.strategyData.decoded.triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
786
+ _position.strategyData.decoded.subData = subDataService.aaveV3OpenOrderSubData.decode(subStruct.subData);
787
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
756
788
 
757
789
  return _position;
758
790
  }
@@ -788,6 +820,7 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
788
820
  [Strategies.Identifiers.CloseToDebtWithGasPrice]: parseAaveV3CloseOnPriceWithMaximumGasPrice,
789
821
  [Strategies.Identifiers.CloseToCollateral]: parseAaveV3CloseOnPrice,
790
822
  [Strategies.Identifiers.CloseToCollateralWithGasPrice]: parseAaveV3CloseOnPriceWithMaximumGasPrice,
823
+ [Strategies.Identifiers.OpenOrderFromCollateral]: parseAaveV3OpenOrderFromCollateral,
791
824
  },
792
825
  [ProtocolIdentifiers.StrategiesAutomation.CompoundV2]: {
793
826
  [Strategies.Identifiers.Repay]: parseCompoundV2LeverageManagement,
@@ -819,10 +852,13 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
819
852
  [ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
820
853
  [Strategies.Identifiers.Repay]: parseCrvUSDLeverageManagement,
821
854
  [Strategies.Identifiers.Boost]: parseCrvUSDLeverageManagement,
855
+ [Strategies.Identifiers.Payback]: parseCrvUSDPayback,
822
856
  },
823
857
  [ProtocolIdentifiers.StrategiesAutomation.MorphoBlue]: {
824
858
  [Strategies.Identifiers.Repay]: parseMorphoBlueLeverageManagement,
825
859
  [Strategies.Identifiers.Boost]: parseMorphoBlueLeverageManagement,
860
+ [Strategies.Identifiers.EoaRepay]: parseMorphoBlueLeverageManagement,
861
+ [Strategies.Identifiers.EoaBoost]: parseMorphoBlueLeverageManagement,
826
862
  },
827
863
  };
828
864