@defisaver/automation-sdk 3.3.22-coll-switch-generic-dev → 3.3.22-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.
@@ -107,11 +107,6 @@ exports.MAINNET_STRATEGIES_INFO = {
107
107
  strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
108
108
  protocol: exports.PROTOCOLS.AaveV3,
109
109
  },
110
- [enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH_EOA]: {
111
- strategyOrBundleId: enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH_EOA,
112
- strategyId: enums_1.Strategies.Identifiers.EoaCollateralSwitch,
113
- protocol: exports.PROTOCOLS.AaveV3,
114
- },
115
110
  [enums_1.Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH]: {
116
111
  strategyOrBundleId: enums_1.Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH,
117
112
  strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
@@ -132,16 +127,6 @@ exports.MAINNET_STRATEGIES_INFO = {
132
127
  strategyId: enums_1.Strategies.Identifiers.EoaCollateralSwitch,
133
128
  protocol: exports.PROTOCOLS.Spark,
134
129
  },
135
- [enums_1.Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH]: {
136
- strategyOrBundleId: enums_1.Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
137
- strategyId: enums_1.Strategies.Identifiers.DebtSwitch,
138
- protocol: exports.PROTOCOLS.AaveV3,
139
- },
140
- [enums_1.Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH_EOA]: {
141
- strategyOrBundleId: enums_1.Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH_EOA,
142
- strategyId: enums_1.Strategies.Identifiers.EoaDebtSwitch,
143
- protocol: exports.PROTOCOLS.AaveV3,
144
- },
145
130
  };
146
131
  exports.OPTIMISM_STRATEGIES_INFO = {
147
132
  [enums_1.Strategies.OptimismIds.EXCHANGE_DCA]: {
@@ -159,21 +144,6 @@ exports.OPTIMISM_STRATEGIES_INFO = {
159
144
  strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
160
145
  protocol: exports.PROTOCOLS.AaveV3,
161
146
  },
162
- [enums_1.Strategies.OptimismIds.AAVE_V3_COLLATERAL_SWITCH_EOA]: {
163
- strategyOrBundleId: enums_1.Strategies.OptimismIds.AAVE_V3_COLLATERAL_SWITCH_EOA,
164
- strategyId: enums_1.Strategies.Identifiers.EoaCollateralSwitch,
165
- protocol: exports.PROTOCOLS.AaveV3,
166
- },
167
- [enums_1.Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH]: {
168
- strategyOrBundleId: enums_1.Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH,
169
- strategyId: enums_1.Strategies.Identifiers.DebtSwitch,
170
- protocol: exports.PROTOCOLS.AaveV3,
171
- },
172
- [enums_1.Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH_EOA]: {
173
- strategyOrBundleId: enums_1.Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH_EOA,
174
- strategyId: enums_1.Strategies.Identifiers.EoaDebtSwitch,
175
- protocol: exports.PROTOCOLS.AaveV3,
176
- },
177
147
  };
178
148
  exports.BASE_STRATEGIES_INFO = {
179
149
  [enums_1.Strategies.BaseIds.EXCHANGE_DCA]: {
@@ -191,21 +161,6 @@ exports.BASE_STRATEGIES_INFO = {
191
161
  strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
192
162
  protocol: exports.PROTOCOLS.AaveV3,
193
163
  },
194
- [enums_1.Strategies.BaseIds.AAVE_V3_COLLATERAL_SWITCH_EOA]: {
195
- strategyOrBundleId: enums_1.Strategies.BaseIds.AAVE_V3_COLLATERAL_SWITCH_EOA,
196
- strategyId: enums_1.Strategies.Identifiers.EoaCollateralSwitch,
197
- protocol: exports.PROTOCOLS.AaveV3,
198
- },
199
- [enums_1.Strategies.BaseIds.AAVE_V3_DEBT_SWITCH]: {
200
- strategyOrBundleId: enums_1.Strategies.BaseIds.AAVE_V3_DEBT_SWITCH,
201
- strategyId: enums_1.Strategies.Identifiers.DebtSwitch,
202
- protocol: exports.PROTOCOLS.AaveV3,
203
- },
204
- [enums_1.Strategies.BaseIds.AAVE_V3_DEBT_SWITCH_EOA]: {
205
- strategyOrBundleId: enums_1.Strategies.BaseIds.AAVE_V3_DEBT_SWITCH_EOA,
206
- strategyId: enums_1.Strategies.Identifiers.EoaDebtSwitch,
207
- protocol: exports.PROTOCOLS.AaveV3,
208
- },
209
164
  };
210
165
  exports.ARBITRUM_STRATEGIES_INFO = {
211
166
  [enums_1.Strategies.ArbitrumIds.EXCHANGE_DCA]: {
@@ -223,21 +178,6 @@ exports.ARBITRUM_STRATEGIES_INFO = {
223
178
  strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
224
179
  protocol: exports.PROTOCOLS.AaveV3,
225
180
  },
226
- [enums_1.Strategies.ArbitrumIds.AAVE_V3_COLLATERAL_SWITCH_EOA]: {
227
- strategyOrBundleId: enums_1.Strategies.ArbitrumIds.AAVE_V3_COLLATERAL_SWITCH_EOA,
228
- strategyId: enums_1.Strategies.Identifiers.EoaCollateralSwitch,
229
- protocol: exports.PROTOCOLS.AaveV3,
230
- },
231
- [enums_1.Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH]: {
232
- strategyOrBundleId: enums_1.Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH,
233
- strategyId: enums_1.Strategies.Identifiers.DebtSwitch,
234
- protocol: exports.PROTOCOLS.AaveV3,
235
- },
236
- [enums_1.Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH_EOA]: {
237
- strategyOrBundleId: enums_1.Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH_EOA,
238
- strategyId: enums_1.Strategies.Identifiers.EoaDebtSwitch,
239
- protocol: exports.PROTOCOLS.AaveV3,
240
- },
241
181
  };
242
182
  exports.STRATEGIES_INFO = {
243
183
  [enums_1.ChainId.Ethereum]: exports.MAINNET_STRATEGIES_INFO,
@@ -719,6 +659,16 @@ exports.MAINNET_BUNDLES_INFO = {
719
659
  strategyId: enums_1.Strategies.Identifiers.EoaLiquidationProtection,
720
660
  protocol: exports.PROTOCOLS.Spark,
721
661
  },
662
+ [enums_1.Bundles.MainnetIds.AAVE_V3_SW_INSTANT_CLOSE]: {
663
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V3_SW_INSTANT_CLOSE,
664
+ strategyId: enums_1.Strategies.Identifiers.InstantCloseOnPrice,
665
+ protocol: exports.PROTOCOLS.AaveV3,
666
+ },
667
+ [enums_1.Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE]: {
668
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
669
+ strategyId: enums_1.Strategies.Identifiers.EoaInstantCloseOnPrice,
670
+ protocol: exports.PROTOCOLS.AaveV3,
671
+ },
722
672
  };
723
673
  exports.OPTIMISM_BUNDLES_INFO = {
724
674
  [enums_1.Bundles.OptimismIds.AAVE_V3_REPAY]: {
@@ -786,6 +736,16 @@ exports.OPTIMISM_BUNDLES_INFO = {
786
736
  strategyId: enums_1.Strategies.Identifiers.EoaLiquidationProtection,
787
737
  protocol: exports.PROTOCOLS.AaveV3,
788
738
  },
739
+ [enums_1.Bundles.OptimismIds.AAVE_V3_SW_INSTANT_CLOSE]: {
740
+ strategyOrBundleId: enums_1.Bundles.OptimismIds.AAVE_V3_SW_INSTANT_CLOSE,
741
+ strategyId: enums_1.Strategies.Identifiers.InstantCloseOnPrice,
742
+ protocol: exports.PROTOCOLS.AaveV3,
743
+ },
744
+ [enums_1.Bundles.OptimismIds.AAVE_V3_EOA_INSTANT_CLOSE]: {
745
+ strategyOrBundleId: enums_1.Bundles.OptimismIds.AAVE_V3_EOA_INSTANT_CLOSE,
746
+ strategyId: enums_1.Strategies.Identifiers.EoaInstantCloseOnPrice,
747
+ protocol: exports.PROTOCOLS.AaveV3,
748
+ },
789
749
  };
790
750
  exports.BASE_BUNDLES_INFO = {
791
751
  [enums_1.Bundles.BaseIds.AAVE_V3_REPAY]: {
@@ -988,6 +948,16 @@ exports.BASE_BUNDLES_INFO = {
988
948
  strategyId: enums_1.Strategies.Identifiers.EoaCloseOnPrice,
989
949
  protocol: exports.PROTOCOLS.MorphoBlue,
990
950
  },
951
+ [enums_1.Bundles.BaseIds.AAVE_V3_SW_INSTANT_CLOSE]: {
952
+ strategyOrBundleId: enums_1.Bundles.BaseIds.AAVE_V3_SW_INSTANT_CLOSE,
953
+ strategyId: enums_1.Strategies.Identifiers.InstantCloseOnPrice,
954
+ protocol: exports.PROTOCOLS.AaveV3,
955
+ },
956
+ [enums_1.Bundles.BaseIds.AAVE_V3_EOA_INSTANT_CLOSE]: {
957
+ strategyOrBundleId: enums_1.Bundles.BaseIds.AAVE_V3_EOA_INSTANT_CLOSE,
958
+ strategyId: enums_1.Strategies.Identifiers.EoaInstantCloseOnPrice,
959
+ protocol: exports.PROTOCOLS.AaveV3,
960
+ },
991
961
  };
992
962
  exports.ARBITRUM_BUNDLES_INFO = {
993
963
  [enums_1.Bundles.ArbitrumIds.AAVE_V3_REPAY]: {
@@ -1190,6 +1160,16 @@ exports.ARBITRUM_BUNDLES_INFO = {
1190
1160
  strategyId: enums_1.Strategies.Identifiers.EoaCloseOnPrice,
1191
1161
  protocol: exports.PROTOCOLS.MorphoBlue,
1192
1162
  },
1163
+ [enums_1.Bundles.ArbitrumIds.AAVE_V3_SW_INSTANT_CLOSE]: {
1164
+ strategyOrBundleId: enums_1.Bundles.ArbitrumIds.AAVE_V3_SW_INSTANT_CLOSE,
1165
+ strategyId: enums_1.Strategies.Identifiers.InstantCloseOnPrice,
1166
+ protocol: exports.PROTOCOLS.AaveV3,
1167
+ },
1168
+ [enums_1.Bundles.ArbitrumIds.AAVE_V3_EOA_INSTANT_CLOSE]: {
1169
+ strategyOrBundleId: enums_1.Bundles.ArbitrumIds.AAVE_V3_EOA_INSTANT_CLOSE,
1170
+ strategyId: enums_1.Strategies.Identifiers.EoaInstantCloseOnPrice,
1171
+ protocol: exports.PROTOCOLS.AaveV3,
1172
+ },
1193
1173
  };
1194
1174
  exports.BUNDLES_INFO = {
1195
1175
  [enums_1.ChainId.Ethereum]: exports.MAINNET_BUNDLES_INFO,
@@ -346,30 +346,36 @@ function parseAaveV3CloseOnPrice(position, parseData) {
346
346
  }
347
347
  return _position;
348
348
  }
349
- function parseAaveV3CollateralSwitch(position, parseData) {
349
+ function parseAaveV3InstantCloseOnPrice(position, parseData) {
350
350
  const _position = (0, lodash_1.cloneDeep)(position);
351
351
  const { subStruct } = parseData.subscriptionEventData;
352
- const isEOA = _position.strategy.strategyId.includes('eoa');
353
- const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
354
- const subData = isEOA
355
- ? subDataService.aaveV3GenericFLCollateralSwitchSubData.decode(subStruct.subData)
356
- : subDataService.aaveV3CollateralSwitchSubData.decode(subStruct.subData);
352
+ const triggerData = triggerService.aaveV3QuotePriceRangeTrigger.decode(subStruct.triggerData);
353
+ const subData = subDataService.aaveV3InstantCloseGenericSubData.decode(subStruct.subData);
354
+ const { takeProfitType, stopLossType } = (0, utils_1.getStopLossAndTakeProfitTypeByCloseStrategyType)(+subData.closeType);
355
+ _position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, AAVE_V3_MARKET_ADDRESSES[_position.chainId]);
357
356
  _position.strategyData.decoded.triggerData = triggerData;
358
357
  _position.strategyData.decoded.subData = subData;
359
- _position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
360
- _position.strategy.strategyId = isEOA
361
- ? enums_1.Strategies.Identifiers.EoaCollateralSwitch
362
- : enums_1.Strategies.Identifiers.CollateralSwitch;
358
+ _position.specific = {
359
+ collAsset: subData.collAsset,
360
+ collAssetId: subData.collAssetId,
361
+ debtAsset: subData.debtAsset,
362
+ debtAssetId: subData.debtAssetId,
363
+ baseToken: triggerData.collToken,
364
+ quoteToken: triggerData.debtToken,
365
+ stopLossPrice: triggerData.lowerPrice,
366
+ takeProfitPrice: triggerData.upperPrice,
367
+ stopLossType,
368
+ takeProfitType,
369
+ };
363
370
  return _position;
364
371
  }
365
- function parseAaveV3DebtSwitch(position, parseData) {
372
+ function parseAaveV3CollateralSwitch(position, parseData) {
366
373
  const _position = (0, lodash_1.cloneDeep)(position);
367
374
  const { subStruct } = parseData.subscriptionEventData;
368
375
  const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
369
- const subData = subDataService.aaveV3DebtSwitchSubData.decode(subStruct.subData);
376
+ const subData = subDataService.aaveV3CollateralSwitchSubData.decode(subStruct.subData);
370
377
  _position.strategyData.decoded.triggerData = triggerData;
371
378
  _position.strategyData.decoded.subData = subData;
372
- // TODO -> This isn't enough for ID
373
379
  _position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
374
380
  return _position;
375
381
  }
@@ -1262,10 +1268,9 @@ const parsingMethodsMapping = {
1262
1268
  [enums_1.Strategies.Identifiers.EoaRepayOnPrice]: parseAaveV3LeverageManagementOnPrice,
1263
1269
  [enums_1.Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV3LeverageManagementOnPrice,
1264
1270
  [enums_1.Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
1271
+ [enums_1.Strategies.Identifiers.InstantCloseOnPrice]: parseAaveV3InstantCloseOnPrice,
1272
+ [enums_1.Strategies.Identifiers.EoaInstantCloseOnPrice]: parseAaveV3InstantCloseOnPrice,
1265
1273
  [enums_1.Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
1266
- [enums_1.Strategies.Identifiers.EoaCollateralSwitch]: parseAaveV3CollateralSwitch,
1267
- [enums_1.Strategies.Identifiers.DebtSwitch]: parseAaveV3DebtSwitch,
1268
- [enums_1.Strategies.Identifiers.EoaDebtSwitch]: parseAaveV3DebtSwitch,
1269
1274
  [enums_1.Strategies.Identifiers.LiquidationProtection]: parseAaveV3LiquidationProtection,
1270
1275
  [enums_1.Strategies.Identifiers.EoaLiquidationProtection]: parseAaveV3LiquidationProtection,
1271
1276
  },
@@ -13,99 +13,8 @@ const chai_1 = require("chai");
13
13
  const enums_1 = require("../types/enums");
14
14
  require("../configuration");
15
15
  const strategiesService_1 = require("./strategiesService");
16
+ const strategySubService_1 = require("./strategySubService");
16
17
  describe('Feature: strategiesService.ts', () => {
17
- describe('When parsing Aave V3 collateral switch subscriptions', () => {
18
- const proxy = '0x9cB7E19861665366011899d74E75d4F2A419aEeD';
19
- const user = '0x1234567890123456789012345678901234567890';
20
- const fromAsset = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
21
- const toAsset = '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf';
22
- const marketAddr = '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e';
23
- const amountToSwitch = '115792089237316195423570985008687907853269984665640564039457584007913129639935';
24
- const subHash = `0x${'ab'.repeat(32)}`;
25
- const triggerData = [
26
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
27
- + '000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf'
28
- + '0000000000000000000000000000000000000000000000000000000000989680'
29
- + '0000000000000000000000000000000000000000000000000000000000000001',
30
- ];
31
- function getParseData(strategyId, isGeneric, chainId = enums_1.ChainId.Ethereum) {
32
- const subData = [
33
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
34
- isGeneric
35
- ? '0x0000000000000000000000000000000000000000000000000000000000000100'
36
- : '0x0000000000000000000000000000000000000000000000000000000000000000',
37
- '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
38
- isGeneric
39
- ? '0x000000000000000000000000000000000000000000000000000000000000ffff'
40
- : '0x0000000000000000000000000000000000000000000000000000000000000007',
41
- '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
42
- '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
43
- isGeneric
44
- ? '0x0000000000000000000000001234567890123456789012345678901234567890'
45
- : '0x0000000000000000000000000000000000000000000000000000000000000000',
46
- ];
47
- const subStruct = Object.assign([String(strategyId), false, triggerData, subData], { strategyOrBundleId: String(strategyId), isBundle: false, triggerData, subData });
48
- return {
49
- chainId,
50
- blockNumber: 18015756,
51
- subscriptionEventData: {
52
- subId: '379', proxy, subHash, subStruct,
53
- 0: '379', 1: proxy, 2: subHash, 3: subStruct,
54
- },
55
- strategiesSubsData: {
56
- userProxy: proxy, isEnabled: true, strategySubHash: subHash,
57
- },
58
- };
59
- }
60
- const genericStrategies = [
61
- [enums_1.ChainId.Ethereum, enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH_EOA],
62
- [enums_1.ChainId.Optimism, enums_1.Strategies.OptimismIds.AAVE_V3_COLLATERAL_SWITCH_EOA],
63
- [enums_1.ChainId.Arbitrum, enums_1.Strategies.ArbitrumIds.AAVE_V3_COLLATERAL_SWITCH_EOA],
64
- [enums_1.ChainId.Base, enums_1.Strategies.BaseIds.AAVE_V3_COLLATERAL_SWITCH_EOA],
65
- ];
66
- genericStrategies.forEach(([chainId, strategyId]) => {
67
- it(`decodes generic collateral switches with the user and uint16 reserve IDs on chain ${chainId}`, () => {
68
- const parseData = getParseData(strategyId, true, chainId);
69
- const position = (0, strategiesService_1.parseStrategiesAutomatedPosition)(parseData);
70
- (0, chai_1.expect)(position).not.to.equal(null);
71
- (0, chai_1.expect)(position.protocol.id).to.equal(enums_1.ProtocolIdentifiers.StrategiesAutomation.AaveV3);
72
- (0, chai_1.expect)(position.strategy.strategyId).to.equal(enums_1.Strategies.Identifiers.EoaCollateralSwitch);
73
- (0, chai_1.expect)(position.strategy.isBundle).to.equal(false);
74
- (0, chai_1.expect)(position.strategyData.encoded).to.eql({
75
- triggerData,
76
- subData: parseData.subscriptionEventData.subStruct.subData,
77
- });
78
- (0, chai_1.expect)(position.strategyData.decoded.triggerData).to.eql({
79
- baseTokenAddress: fromAsset,
80
- quoteTokenAddress: toAsset,
81
- price: '0.1',
82
- ratioState: enums_1.RatioState.UNDER,
83
- });
84
- (0, chai_1.expect)(position.strategyData.decoded.subData).to.eql({
85
- fromAsset, fromAssetId: 256, toAsset, toAssetId: 65535, marketAddr, amountToSwitch, user,
86
- });
87
- (0, chai_1.expect)(position.owner).to.equal(proxy.toLowerCase());
88
- (0, chai_1.expect)(position.positionId).to.equal(`${chainId}-aave__v3-${proxy.toLowerCase()}-${marketAddr.toLowerCase()}`);
89
- });
90
- });
91
- const legacyStrategies = [
92
- [enums_1.ChainId.Ethereum, enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH],
93
- [enums_1.ChainId.Optimism, enums_1.Strategies.OptimismIds.AAVE_V3_COLLATERAL_SWITCH],
94
- [enums_1.ChainId.Arbitrum, enums_1.Strategies.ArbitrumIds.AAVE_V3_COLLATERAL_SWITCH],
95
- [enums_1.ChainId.Base, enums_1.Strategies.BaseIds.AAVE_V3_COLLATERAL_SWITCH],
96
- ];
97
- legacyStrategies.forEach(([chainId, strategyId]) => {
98
- it(`continues to decode legacy collateral switches on chain ${chainId}`, () => {
99
- const position = (0, strategiesService_1.parseStrategiesAutomatedPosition)(getParseData(strategyId, false, chainId));
100
- (0, chai_1.expect)(position).not.to.equal(null);
101
- (0, chai_1.expect)(position.strategy.strategyId).to.equal(enums_1.Strategies.Identifiers.CollateralSwitch);
102
- (0, chai_1.expect)(position.strategyData.decoded.subData).to.eql({
103
- fromAsset, fromAssetId: 0, toAsset, toAssetId: 7, marketAddr, amountToSwitch,
104
- });
105
- (0, chai_1.expect)(position.positionId).to.equal(`${chainId}-aave__v3-${proxy.toLowerCase()}-${marketAddr.toLowerCase()}`);
106
- });
107
- });
108
- });
109
18
  describe('When testing strategiesService.parseStrategiesAutomatedPosition', () => __awaiter(void 0, void 0, void 0, function* () {
110
19
  // TODO: we should probably write this for every strategy?
111
20
  const examples = [
@@ -200,4 +109,65 @@ describe('Feature: strategiesService.ts', () => {
200
109
  }));
201
110
  });
202
111
  }));
112
+ describe('When parsing Aave V3 instant close bundles', () => {
113
+ const owner = '0x1234567890123456789012345678901234567890';
114
+ const market = '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e';
115
+ const weth = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
116
+ const usdc = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
117
+ const bundles = [
118
+ ['SW', enums_1.Bundles.MainnetIds.AAVE_V3_SW_INSTANT_CLOSE, enums_1.Strategies.Identifiers.InstantCloseOnPrice],
119
+ ['EOA', enums_1.Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE, enums_1.Strategies.Identifiers.EoaInstantCloseOnPrice],
120
+ ];
121
+ bundles.forEach(([walletType, expectedBundleId, expectedStrategyId]) => {
122
+ describe(`${walletType} bundle`, () => {
123
+ const [bundleId, isBundle, triggerData, subData] = strategySubService_1.aaveV3Encode.instantCloseOnPriceGeneric(expectedBundleId, weth, 0, usdc, 1, market, owner, '1000000000000000000', '10000000000000000', 1500, enums_1.CloseToAssetType.DEBT, 5000, enums_1.CloseToAssetType.COLLATERAL);
124
+ const parseData = {
125
+ chainId: 1,
126
+ blockNumber: 1,
127
+ subscriptionEventData: {
128
+ subId: '1',
129
+ proxy: owner,
130
+ subHash: '0xhash',
131
+ subStruct: {
132
+ strategyOrBundleId: String(bundleId), isBundle, triggerData, subData,
133
+ },
134
+ },
135
+ strategiesSubsData: { userProxy: owner, isEnabled: true, strategySubHash: '0xhash' },
136
+ };
137
+ const result = (0, strategiesService_1.parseStrategiesAutomatedPosition)(parseData);
138
+ it('should identify the strategy as instant close on price', () => {
139
+ (0, chai_1.expect)(result.strategy.strategyOrBundleId).to.equal(expectedBundleId);
140
+ (0, chai_1.expect)(result.strategy.strategyId).to.equal(expectedStrategyId);
141
+ (0, chai_1.expect)(result.protocol.id).to.equal(enums_1.ProtocolIdentifiers.StrategiesAutomation.AaveV3);
142
+ });
143
+ it('should decode sub data including tsi and slippage', () => {
144
+ (0, chai_1.expect)(result.strategyData.decoded.subData).to.eql({
145
+ collAsset: weth,
146
+ collAssetId: 0,
147
+ debtAsset: usdc,
148
+ debtAssetId: 1,
149
+ closeType: enums_1.CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
150
+ marketAddr: market,
151
+ owner,
152
+ tsi: '1000000000000000000',
153
+ slippage: '10000000000000000',
154
+ });
155
+ });
156
+ it('should fill specific with prices and close types', () => {
157
+ (0, chai_1.expect)(result.specific).to.eql({
158
+ collAsset: weth,
159
+ collAssetId: 0,
160
+ debtAsset: usdc,
161
+ debtAssetId: 1,
162
+ baseToken: weth,
163
+ quoteToken: usdc,
164
+ stopLossPrice: '1500',
165
+ takeProfitPrice: '5000',
166
+ stopLossType: enums_1.CloseToAssetType.DEBT,
167
+ takeProfitType: enums_1.CloseToAssetType.COLLATERAL,
168
+ });
169
+ });
170
+ });
171
+ });
172
+ });
203
173
  });
@@ -61,9 +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
- collateralSwitchGeneric(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
- 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[])[];
67
66
  };
68
67
  export declare const compoundV2Encode: {
69
68
  leverageManagement(strategyOrBundleId: number, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
@@ -190,21 +190,16 @@ exports.aaveV3Encode = {
190
190
  const triggerDataEncoded = triggerService.aaveV3QuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
191
191
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
192
192
  },
193
- collateralSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, baseTokenAddress, quoteTokenAddress, price, state) {
194
- const isBundle = false;
195
- const subDataEncoded = subDataService.aaveV3CollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
196
- const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
197
- return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
198
- },
199
- collateralSwitchGeneric(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user, baseTokenAddress, quoteTokenAddress, price, state) {
200
- const isBundle = false;
201
- const subDataEncoded = subDataService.aaveV3GenericFLCollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user);
202
- const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
193
+ instantCloseOnPriceGeneric(strategyOrBundleId, collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, user, tsi, slippage, stopLossPrice = 0, stopLossType = enums_1.CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = enums_1.CloseToAssetType.COLLATERAL) {
194
+ const isBundle = true;
195
+ const closeType = (0, utils_1.getCloseStrategyType)(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
196
+ const subDataEncoded = subDataService.aaveV3InstantCloseGenericSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user, tsi, slippage);
197
+ const triggerDataEncoded = triggerService.aaveV3QuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
203
198
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
204
199
  },
205
- debtSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user, baseTokenAddress, quoteTokenAddress, price, state) {
200
+ collateralSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, baseTokenAddress, quoteTokenAddress, price, state) {
206
201
  const isBundle = false;
207
- const subDataEncoded = subDataService.aaveV3DebtSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user);
202
+ const subDataEncoded = subDataService.aaveV3CollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
208
203
  const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
209
204
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
210
205
  },