@defisaver/automation-sdk 3.3.21-debt-switch-dev-dev → 3.3.21-instant-twap-close-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -535,110 +535,6 @@ describe('Feature: subDataService.ts', () => {
535
535
  });
536
536
  });
537
537
  });
538
- describe('When testing subDataService.aaveV3DebtSwitchSubData', () => {
539
- describe('encode()', () => {
540
- const examples = [
541
- // USDC -> DAI
542
- [
543
- [
544
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
545
- '0x0000000000000000000000000000000000000000000000000000000000000001',
546
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
547
- '0x0000000000000000000000000000000000000000000000000000000000000003',
548
- '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
549
- '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
550
- '0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
551
- ],
552
- [
553
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
554
- 1,
555
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
556
- 3,
557
- web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
558
- '10000000000000000000',
559
- web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
560
- ]
561
- ],
562
- // DAI -> USDC (MaxUint256)
563
- [
564
- [
565
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
566
- '0x0000000000000000000000000000000000000000000000000000000000000003',
567
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
568
- '0x0000000000000000000000000000000000000000000000000000000000000001',
569
- '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
570
- '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
571
- '0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
572
- ],
573
- [
574
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
575
- 3,
576
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
577
- 1,
578
- web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
579
- tokens_2.MAXUINT,
580
- web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
581
- ]
582
- ],
583
- ];
584
- examples.forEach(([expected, actual]) => {
585
- it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
586
- (0, chai_1.expect)(subDataService.aaveV3DebtSwitchSubData.encode(...actual)).to.eql(expected);
587
- });
588
- });
589
- });
590
- describe('decode()', () => {
591
- const examples = [
592
- // USDC -> DAI
593
- [
594
- {
595
- fromAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
596
- fromAssetId: 1,
597
- toAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
598
- toAssetId: 3,
599
- marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
600
- amountToSwitch: '10000000000000000000',
601
- user: web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
602
- },
603
- [
604
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
605
- '0x0000000000000000000000000000000000000000000000000000000000000001',
606
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
607
- '0x0000000000000000000000000000000000000000000000000000000000000003',
608
- '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
609
- '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
610
- '0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
611
- ],
612
- ],
613
- // DAI -> USDC (MaxUint256)
614
- [
615
- {
616
- fromAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
617
- fromAssetId: 3,
618
- toAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
619
- toAssetId: 1,
620
- marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
621
- amountToSwitch: tokens_2.MAXUINT,
622
- user: web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
623
- },
624
- [
625
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
626
- '0x0000000000000000000000000000000000000000000000000000000000000003',
627
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
628
- '0x0000000000000000000000000000000000000000000000000000000000000001',
629
- '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
630
- '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
631
- '0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
632
- ],
633
- ],
634
- ];
635
- examples.forEach(([expected, actual]) => {
636
- it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
637
- (0, chai_1.expect)(subDataService.aaveV3DebtSwitchSubData.decode(actual)).to.eql(expected);
638
- });
639
- });
640
- });
641
- });
642
538
  describe('When testing subDataService.sparkCollateralSwitchSubData', () => {
643
539
  describe('encode()', () => {
644
540
  const examples = [
@@ -2385,6 +2281,76 @@ describe('Feature: subDataService.ts', () => {
2385
2281
  });
2386
2282
  });
2387
2283
  });
2284
+ describe("When testing subDataService.aaveV3InstantCloseGenericSubData", () => {
2285
+ const WETH = web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address);
2286
+ const USDC = web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address);
2287
+ const MARKET = web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39');
2288
+ const USER = web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890');
2289
+ const examples = [
2290
+ // TAKE_PROFIT_IN_COLLATERAL, zero tsi and slippage
2291
+ [
2292
+ [
2293
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2294
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2295
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2296
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2297
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2298
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2299
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2300
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2301
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2302
+ ],
2303
+ [WETH, 0, USDC, 1, enums_1.CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL, MARKET, USER, '0', '0'],
2304
+ ],
2305
+ // STOP_LOSS_IN_DEBT
2306
+ [
2307
+ [
2308
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2309
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2310
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2311
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2312
+ '0x0000000000000000000000000000000000000000000000000000000000000003',
2313
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2314
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2315
+ '0x0000000000000000000000000000000000000000000000000de0b6b3a7640000',
2316
+ '0x000000000000000000000000000000000000000000000000002386f26fc10000',
2317
+ ],
2318
+ [WETH, 0, USDC, 1, enums_1.CloseStrategyType.STOP_LOSS_IN_DEBT, MARKET, USER, '1000000000000000000', '10000000000000000'],
2319
+ ],
2320
+ // TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL, asset ids above uint8 range
2321
+ [
2322
+ [
2323
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2324
+ '0x000000000000000000000000000000000000000000000000000000000000012c',
2325
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2326
+ '0x0000000000000000000000000000000000000000000000000000000000000190',
2327
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
2328
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2329
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2330
+ '0x00000000000000000000000000000000000000000000000000b1a2bc2ec50000',
2331
+ '0x0000000000000000000000000000000000000000000000000011c37937e08000',
2332
+ ],
2333
+ [WETH, 300, USDC, 400, enums_1.CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL, MARKET, USER, '50000000000000000', '5000000000000000'],
2334
+ ],
2335
+ ];
2336
+ describe("encode()", () => {
2337
+ examples.forEach(([expected, actual]) => {
2338
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2339
+ (0, chai_1.expect)(subDataService.aaveV3InstantCloseGenericSubData.encode(...actual)).to.eql(expected);
2340
+ });
2341
+ });
2342
+ });
2343
+ describe("decode()", () => {
2344
+ examples.forEach(([encoded, [collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user, tsi, slippage]]) => {
2345
+ const expected = {
2346
+ collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner: user, tsi, slippage,
2347
+ };
2348
+ it(`Given ${JSON.stringify(encoded)} should return expected value: ${JSON.stringify(expected)}`, () => {
2349
+ (0, chai_1.expect)(subDataService.aaveV3InstantCloseGenericSubData.decode(encoded)).to.eql(expected);
2350
+ });
2351
+ });
2352
+ });
2353
+ });
2388
2354
  describe('When testing subDataService.sparkLeverageManagementOnPriceSubData', () => {
2389
2355
  describe('encode()', () => {
2390
2356
  const examples = [
@@ -91,30 +91,22 @@ export declare namespace Strategies {
91
91
  AAVE_V4_COLLATERAL_SWITCH = 154,
92
92
  AAVE_V4_COLLATERAL_SWITCH_EOA = 155,
93
93
  SPARK_COLLATERAL_SWITCH = 156,
94
- SPARK_GENERIC_FL_COLLATERAL_SWITCH = 167,
95
- AAVE_V3_DEBT_SWITCH = 168,
96
- AAVE_V3_DEBT_SWITCH_EOA = 169
94
+ SPARK_GENERIC_FL_COLLATERAL_SWITCH = 167
97
95
  }
98
96
  enum OptimismIds {
99
97
  EXCHANGE_DCA = 8,
100
98
  EXCHANGE_LIMIT_ORDER = 9,
101
- AAVE_V3_COLLATERAL_SWITCH = 24,
102
- AAVE_V3_DEBT_SWITCH = 25,
103
- AAVE_V3_DEBT_SWITCH_EOA = 26
99
+ AAVE_V3_COLLATERAL_SWITCH = 24
104
100
  }
105
101
  enum BaseIds {
106
102
  EXCHANGE_DCA = 8,
107
103
  EXCHANGE_LIMIT_ORDER = 9,
108
- AAVE_V3_COLLATERAL_SWITCH = 56,
109
- AAVE_V3_DEBT_SWITCH = 61,
110
- AAVE_V3_DEBT_SWITCH_EOA = 62
104
+ AAVE_V3_COLLATERAL_SWITCH = 56
111
105
  }
112
106
  enum ArbitrumIds {
113
107
  EXCHANGE_DCA = 8,
114
108
  EXCHANGE_LIMIT_ORDER = 9,
115
- AAVE_V3_COLLATERAL_SWITCH = 50,
116
- AAVE_V3_DEBT_SWITCH = 55,
117
- AAVE_V3_DEBT_SWITCH_EOA = 56
109
+ AAVE_V3_COLLATERAL_SWITCH = 50
118
110
  }
119
111
  enum Identifiers {
120
112
  SavingsLiqProtection = "smart-savings-liquidation-protection",
@@ -132,6 +124,8 @@ export declare namespace Strategies {
132
124
  CloseOnPriceToColl = "close-on-price-to-collateral",
133
125
  CloseOnPrice = "close-on-price",
134
126
  EoaCloseOnPrice = "eoa-close-on-price",
127
+ InstantCloseOnPrice = "instant-close-on-price",
128
+ EoaInstantCloseOnPrice = "eoa-instant-close-on-price",
135
129
  TrailingStopToColl = "trailing-stop-to-collateral",
136
130
  TrailingStopToDebt = "trailing-stop-to-debt",
137
131
  Rebond = "rebond",
@@ -148,8 +142,6 @@ export declare namespace Strategies {
148
142
  EoaRepayOnPrice = "eoa-repay-on-price",
149
143
  CollateralSwitch = "collateral-switch",
150
144
  EoaCollateralSwitch = "eoa-collateral-switch",
151
- DebtSwitch = "debt-switch",
152
- EoaDebtSwitch = "eoa-debt-switch",
153
145
  LiquidationProtection = "liquidation-protection",
154
146
  EoaLiquidationProtection = "liquidation-protection-eoa"
155
147
  }
@@ -260,7 +252,9 @@ export declare namespace Bundles {
260
252
  SPARK_EOA_REPAY_ON_PRICE = 90,
261
253
  SPARK_EOA_BOOST_ON_PRICE = 91,
262
254
  SPARK_EOA_CLOSE = 92,
263
- SPARK_EOA_LIQUIDATION_PROTECTION = 93
255
+ SPARK_EOA_LIQUIDATION_PROTECTION = 93,
256
+ AAVE_V3_SW_INSTANT_CLOSE = 94,
257
+ AAVE_V3_EOA_INSTANT_CLOSE = 95
264
258
  }
265
259
  enum OptimismIds {
266
260
  AAVE_V3_REPAY = 0,
@@ -108,32 +108,24 @@ var Strategies;
108
108
  MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH_EOA"] = 155] = "AAVE_V4_COLLATERAL_SWITCH_EOA";
109
109
  MainnetIds[MainnetIds["SPARK_COLLATERAL_SWITCH"] = 156] = "SPARK_COLLATERAL_SWITCH";
110
110
  MainnetIds[MainnetIds["SPARK_GENERIC_FL_COLLATERAL_SWITCH"] = 167] = "SPARK_GENERIC_FL_COLLATERAL_SWITCH";
111
- MainnetIds[MainnetIds["AAVE_V3_DEBT_SWITCH"] = 168] = "AAVE_V3_DEBT_SWITCH";
112
- MainnetIds[MainnetIds["AAVE_V3_DEBT_SWITCH_EOA"] = 169] = "AAVE_V3_DEBT_SWITCH_EOA";
113
111
  })(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
114
112
  let OptimismIds;
115
113
  (function (OptimismIds) {
116
114
  OptimismIds[OptimismIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
117
115
  OptimismIds[OptimismIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
118
116
  OptimismIds[OptimismIds["AAVE_V3_COLLATERAL_SWITCH"] = 24] = "AAVE_V3_COLLATERAL_SWITCH";
119
- OptimismIds[OptimismIds["AAVE_V3_DEBT_SWITCH"] = 25] = "AAVE_V3_DEBT_SWITCH";
120
- OptimismIds[OptimismIds["AAVE_V3_DEBT_SWITCH_EOA"] = 26] = "AAVE_V3_DEBT_SWITCH_EOA";
121
117
  })(OptimismIds = Strategies.OptimismIds || (Strategies.OptimismIds = {}));
122
118
  let BaseIds;
123
119
  (function (BaseIds) {
124
120
  BaseIds[BaseIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
125
121
  BaseIds[BaseIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
126
122
  BaseIds[BaseIds["AAVE_V3_COLLATERAL_SWITCH"] = 56] = "AAVE_V3_COLLATERAL_SWITCH";
127
- BaseIds[BaseIds["AAVE_V3_DEBT_SWITCH"] = 61] = "AAVE_V3_DEBT_SWITCH";
128
- BaseIds[BaseIds["AAVE_V3_DEBT_SWITCH_EOA"] = 62] = "AAVE_V3_DEBT_SWITCH_EOA";
129
123
  })(BaseIds = Strategies.BaseIds || (Strategies.BaseIds = {}));
130
124
  let ArbitrumIds;
131
125
  (function (ArbitrumIds) {
132
126
  ArbitrumIds[ArbitrumIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
133
127
  ArbitrumIds[ArbitrumIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
134
128
  ArbitrumIds[ArbitrumIds["AAVE_V3_COLLATERAL_SWITCH"] = 50] = "AAVE_V3_COLLATERAL_SWITCH";
135
- ArbitrumIds[ArbitrumIds["AAVE_V3_DEBT_SWITCH"] = 55] = "AAVE_V3_DEBT_SWITCH";
136
- ArbitrumIds[ArbitrumIds["AAVE_V3_DEBT_SWITCH_EOA"] = 56] = "AAVE_V3_DEBT_SWITCH_EOA";
137
129
  })(ArbitrumIds = Strategies.ArbitrumIds || (Strategies.ArbitrumIds = {}));
138
130
  let Identifiers;
139
131
  (function (Identifiers) {
@@ -152,6 +144,8 @@ var Strategies;
152
144
  Identifiers["CloseOnPriceToColl"] = "close-on-price-to-collateral";
153
145
  Identifiers["CloseOnPrice"] = "close-on-price";
154
146
  Identifiers["EoaCloseOnPrice"] = "eoa-close-on-price";
147
+ Identifiers["InstantCloseOnPrice"] = "instant-close-on-price";
148
+ Identifiers["EoaInstantCloseOnPrice"] = "eoa-instant-close-on-price";
155
149
  Identifiers["TrailingStopToColl"] = "trailing-stop-to-collateral";
156
150
  Identifiers["TrailingStopToDebt"] = "trailing-stop-to-debt";
157
151
  Identifiers["Rebond"] = "rebond";
@@ -168,8 +162,6 @@ var Strategies;
168
162
  Identifiers["EoaRepayOnPrice"] = "eoa-repay-on-price";
169
163
  Identifiers["CollateralSwitch"] = "collateral-switch";
170
164
  Identifiers["EoaCollateralSwitch"] = "eoa-collateral-switch";
171
- Identifiers["DebtSwitch"] = "debt-switch";
172
- Identifiers["EoaDebtSwitch"] = "eoa-debt-switch";
173
165
  Identifiers["LiquidationProtection"] = "liquidation-protection";
174
166
  Identifiers["EoaLiquidationProtection"] = "liquidation-protection-eoa";
175
167
  })(Identifiers = Strategies.Identifiers || (Strategies.Identifiers = {}));
@@ -284,6 +276,8 @@ var Bundles;
284
276
  MainnetIds[MainnetIds["SPARK_EOA_BOOST_ON_PRICE"] = 91] = "SPARK_EOA_BOOST_ON_PRICE";
285
277
  MainnetIds[MainnetIds["SPARK_EOA_CLOSE"] = 92] = "SPARK_EOA_CLOSE";
286
278
  MainnetIds[MainnetIds["SPARK_EOA_LIQUIDATION_PROTECTION"] = 93] = "SPARK_EOA_LIQUIDATION_PROTECTION";
279
+ MainnetIds[MainnetIds["AAVE_V3_SW_INSTANT_CLOSE"] = 94] = "AAVE_V3_SW_INSTANT_CLOSE";
280
+ MainnetIds[MainnetIds["AAVE_V3_EOA_INSTANT_CLOSE"] = 95] = "AAVE_V3_EOA_INSTANT_CLOSE";
287
281
  })(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
288
282
  let OptimismIds;
289
283
  (function (OptimismIds) {
@@ -121,16 +121,6 @@ export const MAINNET_STRATEGIES_INFO = {
121
121
  strategyId: Strategies.Identifiers.EoaCollateralSwitch,
122
122
  protocol: PROTOCOLS.Spark,
123
123
  },
124
- [Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH]: {
125
- strategyOrBundleId: Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
126
- strategyId: Strategies.Identifiers.DebtSwitch,
127
- protocol: PROTOCOLS.AaveV3,
128
- },
129
- [Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH_EOA]: {
130
- strategyOrBundleId: Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH_EOA,
131
- strategyId: Strategies.Identifiers.EoaDebtSwitch,
132
- protocol: PROTOCOLS.AaveV3,
133
- },
134
124
  };
135
125
  export const OPTIMISM_STRATEGIES_INFO = {
136
126
  [Strategies.OptimismIds.EXCHANGE_DCA]: {
@@ -148,16 +138,6 @@ export const OPTIMISM_STRATEGIES_INFO = {
148
138
  strategyId: Strategies.Identifiers.CollateralSwitch,
149
139
  protocol: PROTOCOLS.AaveV3,
150
140
  },
151
- [Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH]: {
152
- strategyOrBundleId: Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH,
153
- strategyId: Strategies.Identifiers.DebtSwitch,
154
- protocol: PROTOCOLS.AaveV3,
155
- },
156
- [Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH_EOA]: {
157
- strategyOrBundleId: Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH_EOA,
158
- strategyId: Strategies.Identifiers.EoaDebtSwitch,
159
- protocol: PROTOCOLS.AaveV3,
160
- },
161
141
  };
162
142
  export const BASE_STRATEGIES_INFO = {
163
143
  [Strategies.BaseIds.EXCHANGE_DCA]: {
@@ -175,16 +155,6 @@ export const BASE_STRATEGIES_INFO = {
175
155
  strategyId: Strategies.Identifiers.CollateralSwitch,
176
156
  protocol: PROTOCOLS.AaveV3,
177
157
  },
178
- [Strategies.BaseIds.AAVE_V3_DEBT_SWITCH]: {
179
- strategyOrBundleId: Strategies.BaseIds.AAVE_V3_DEBT_SWITCH,
180
- strategyId: Strategies.Identifiers.DebtSwitch,
181
- protocol: PROTOCOLS.AaveV3,
182
- },
183
- [Strategies.BaseIds.AAVE_V3_DEBT_SWITCH_EOA]: {
184
- strategyOrBundleId: Strategies.BaseIds.AAVE_V3_DEBT_SWITCH_EOA,
185
- strategyId: Strategies.Identifiers.EoaDebtSwitch,
186
- protocol: PROTOCOLS.AaveV3,
187
- },
188
158
  };
189
159
  export const ARBITRUM_STRATEGIES_INFO = {
190
160
  [Strategies.ArbitrumIds.EXCHANGE_DCA]: {
@@ -202,16 +172,6 @@ export const ARBITRUM_STRATEGIES_INFO = {
202
172
  strategyId: Strategies.Identifiers.CollateralSwitch,
203
173
  protocol: PROTOCOLS.AaveV3,
204
174
  },
205
- [Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH]: {
206
- strategyOrBundleId: Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH,
207
- strategyId: Strategies.Identifiers.DebtSwitch,
208
- protocol: PROTOCOLS.AaveV3,
209
- },
210
- [Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH_EOA]: {
211
- strategyOrBundleId: Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH_EOA,
212
- strategyId: Strategies.Identifiers.EoaDebtSwitch,
213
- protocol: PROTOCOLS.AaveV3,
214
- },
215
175
  };
216
176
  export const STRATEGIES_INFO = {
217
177
  [ChainId.Ethereum]: MAINNET_STRATEGIES_INFO,
@@ -693,6 +653,16 @@ export const MAINNET_BUNDLES_INFO = {
693
653
  strategyId: Strategies.Identifiers.EoaLiquidationProtection,
694
654
  protocol: PROTOCOLS.Spark,
695
655
  },
656
+ [Bundles.MainnetIds.AAVE_V3_SW_INSTANT_CLOSE]: {
657
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V3_SW_INSTANT_CLOSE,
658
+ strategyId: Strategies.Identifiers.InstantCloseOnPrice,
659
+ protocol: PROTOCOLS.AaveV3,
660
+ },
661
+ [Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE]: {
662
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
663
+ strategyId: Strategies.Identifiers.EoaInstantCloseOnPrice,
664
+ protocol: PROTOCOLS.AaveV3,
665
+ },
696
666
  };
697
667
  export const OPTIMISM_BUNDLES_INFO = {
698
668
  [Bundles.OptimismIds.AAVE_V3_REPAY]: {
@@ -317,24 +317,36 @@ function parseAaveV3CloseOnPrice(position, parseData) {
317
317
  }
318
318
  return _position;
319
319
  }
320
- function parseAaveV3CollateralSwitch(position, parseData) {
320
+ function parseAaveV3InstantCloseOnPrice(position, parseData) {
321
321
  const _position = cloneDeep(position);
322
322
  const { subStruct } = parseData.subscriptionEventData;
323
- const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
324
- const subData = subDataService.aaveV3CollateralSwitchSubData.decode(subStruct.subData);
323
+ const triggerData = triggerService.aaveV3QuotePriceRangeTrigger.decode(subStruct.triggerData);
324
+ const subData = subDataService.aaveV3InstantCloseGenericSubData.decode(subStruct.subData);
325
+ const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
326
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, AAVE_V3_MARKET_ADDRESSES[_position.chainId]);
325
327
  _position.strategyData.decoded.triggerData = triggerData;
326
328
  _position.strategyData.decoded.subData = subData;
327
- _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
329
+ _position.specific = {
330
+ collAsset: subData.collAsset,
331
+ collAssetId: subData.collAssetId,
332
+ debtAsset: subData.debtAsset,
333
+ debtAssetId: subData.debtAssetId,
334
+ baseToken: triggerData.collToken,
335
+ quoteToken: triggerData.debtToken,
336
+ stopLossPrice: triggerData.lowerPrice,
337
+ takeProfitPrice: triggerData.upperPrice,
338
+ stopLossType,
339
+ takeProfitType,
340
+ };
328
341
  return _position;
329
342
  }
330
- function parseAaveV3DebtSwitch(position, parseData) {
343
+ function parseAaveV3CollateralSwitch(position, parseData) {
331
344
  const _position = cloneDeep(position);
332
345
  const { subStruct } = parseData.subscriptionEventData;
333
346
  const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
334
- const subData = subDataService.aaveV3DebtSwitchSubData.decode(subStruct.subData);
347
+ const subData = subDataService.aaveV3CollateralSwitchSubData.decode(subStruct.subData);
335
348
  _position.strategyData.decoded.triggerData = triggerData;
336
349
  _position.strategyData.decoded.subData = subData;
337
- // TODO -> This isn't enough for ID
338
350
  _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
339
351
  return _position;
340
352
  }
@@ -1227,9 +1239,9 @@ const parsingMethodsMapping = {
1227
1239
  [Strategies.Identifiers.EoaRepayOnPrice]: parseAaveV3LeverageManagementOnPrice,
1228
1240
  [Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV3LeverageManagementOnPrice,
1229
1241
  [Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
1242
+ [Strategies.Identifiers.InstantCloseOnPrice]: parseAaveV3InstantCloseOnPrice,
1243
+ [Strategies.Identifiers.EoaInstantCloseOnPrice]: parseAaveV3InstantCloseOnPrice,
1230
1244
  [Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
1231
- [Strategies.Identifiers.DebtSwitch]: parseAaveV3DebtSwitch,
1232
- [Strategies.Identifiers.EoaDebtSwitch]: parseAaveV3DebtSwitch,
1233
1245
  [Strategies.Identifiers.LiquidationProtection]: parseAaveV3LiquidationProtection,
1234
1246
  [Strategies.Identifiers.EoaLiquidationProtection]: parseAaveV3LiquidationProtection,
1235
1247
  },
@@ -8,9 +8,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { expect } from 'chai';
11
- import { ProtocolIdentifiers, Strategies } from '../types/enums';
11
+ import { Bundles, CloseStrategyType, CloseToAssetType, ProtocolIdentifiers, Strategies, } from '../types/enums';
12
12
  import '../configuration';
13
13
  import { parseStrategiesAutomatedPosition } from './strategiesService';
14
+ import { aaveV3Encode } from './strategySubService';
14
15
  describe('Feature: strategiesService.ts', () => {
15
16
  describe('When testing strategiesService.parseStrategiesAutomatedPosition', () => __awaiter(void 0, void 0, void 0, function* () {
16
17
  // TODO: we should probably write this for every strategy?
@@ -106,4 +107,65 @@ describe('Feature: strategiesService.ts', () => {
106
107
  }));
107
108
  });
108
109
  }));
110
+ describe('When parsing Aave V3 instant close bundles', () => {
111
+ const owner = '0x1234567890123456789012345678901234567890';
112
+ const market = '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e';
113
+ const weth = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
114
+ const usdc = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
115
+ const bundles = [
116
+ ['SW', Bundles.MainnetIds.AAVE_V3_SW_INSTANT_CLOSE, Strategies.Identifiers.InstantCloseOnPrice],
117
+ ['EOA', Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE, Strategies.Identifiers.EoaInstantCloseOnPrice],
118
+ ];
119
+ bundles.forEach(([walletType, expectedBundleId, expectedStrategyId]) => {
120
+ describe(`${walletType} bundle`, () => {
121
+ const [bundleId, isBundle, triggerData, subData] = aaveV3Encode.instantCloseOnPriceGeneric(expectedBundleId, weth, 0, usdc, 1, market, owner, '1000000000000000000', '10000000000000000', 1500, CloseToAssetType.DEBT, 5000, CloseToAssetType.COLLATERAL);
122
+ const parseData = {
123
+ chainId: 1,
124
+ blockNumber: 1,
125
+ subscriptionEventData: {
126
+ subId: '1',
127
+ proxy: owner,
128
+ subHash: '0xhash',
129
+ subStruct: {
130
+ strategyOrBundleId: String(bundleId), isBundle, triggerData, subData,
131
+ },
132
+ },
133
+ strategiesSubsData: { userProxy: owner, isEnabled: true, strategySubHash: '0xhash' },
134
+ };
135
+ const result = parseStrategiesAutomatedPosition(parseData);
136
+ it('should identify the strategy as instant close on price', () => {
137
+ expect(result.strategy.strategyOrBundleId).to.equal(expectedBundleId);
138
+ expect(result.strategy.strategyId).to.equal(expectedStrategyId);
139
+ expect(result.protocol.id).to.equal(ProtocolIdentifiers.StrategiesAutomation.AaveV3);
140
+ });
141
+ it('should decode sub data including tsi and slippage', () => {
142
+ expect(result.strategyData.decoded.subData).to.eql({
143
+ collAsset: weth,
144
+ collAssetId: 0,
145
+ debtAsset: usdc,
146
+ debtAssetId: 1,
147
+ closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
148
+ marketAddr: market,
149
+ owner,
150
+ tsi: '1000000000000000000',
151
+ slippage: '10000000000000000',
152
+ });
153
+ });
154
+ it('should fill specific with prices and close types', () => {
155
+ expect(result.specific).to.eql({
156
+ collAsset: weth,
157
+ collAssetId: 0,
158
+ debtAsset: usdc,
159
+ debtAssetId: 1,
160
+ baseToken: weth,
161
+ quoteToken: usdc,
162
+ stopLossPrice: '1500',
163
+ takeProfitPrice: '5000',
164
+ stopLossType: CloseToAssetType.DEBT,
165
+ takeProfitType: CloseToAssetType.COLLATERAL,
166
+ });
167
+ });
168
+ });
169
+ });
170
+ });
109
171
  });
@@ -61,8 +61,8 @@ export declare const aaveV3Encode: {
61
61
  liquidationProtection(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
62
62
  leverageManagementOnPriceGeneric(strategyOrBundleId: number, price: number, ratioState: RatioState, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number, user: EthereumAddress): (number | boolean | string[])[];
63
63
  closeOnPriceGeneric(strategyOrBundleId: number, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, user: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
64
+ instantCloseOnPriceGeneric(strategyOrBundleId: number, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, user: EthereumAddress, tsi: string, slippage: string, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
64
65
  collateralSwitch(strategyOrBundleId: number, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState): (number | boolean | string[])[];
65
- debtSwitch(strategyOrBundleId: number, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress, baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState): (number | boolean | string[])[];
66
66
  };
67
67
  export declare const compoundV2Encode: {
68
68
  leverageManagement(strategyOrBundleId: number, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
@@ -164,15 +164,16 @@ export const aaveV3Encode = {
164
164
  const triggerDataEncoded = triggerService.aaveV3QuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
165
165
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
166
166
  },
167
- collateralSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, baseTokenAddress, quoteTokenAddress, price, state) {
168
- const isBundle = false;
169
- const subDataEncoded = subDataService.aaveV3CollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
170
- const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
167
+ instantCloseOnPriceGeneric(strategyOrBundleId, collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, user, tsi, slippage, stopLossPrice = 0, stopLossType = CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = CloseToAssetType.COLLATERAL) {
168
+ const isBundle = true;
169
+ const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
170
+ const subDataEncoded = subDataService.aaveV3InstantCloseGenericSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user, tsi, slippage);
171
+ const triggerDataEncoded = triggerService.aaveV3QuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
171
172
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
172
173
  },
173
- debtSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user, baseTokenAddress, quoteTokenAddress, price, state) {
174
+ collateralSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, baseTokenAddress, quoteTokenAddress, price, state) {
174
175
  const isBundle = false;
175
- const subDataEncoded = subDataService.aaveV3DebtSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user);
176
+ const subDataEncoded = subDataService.aaveV3CollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
176
177
  const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
177
178
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
178
179
  },