@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.
@@ -127,16 +127,6 @@ exports.MAINNET_STRATEGIES_INFO = {
127
127
  strategyId: enums_1.Strategies.Identifiers.EoaCollateralSwitch,
128
128
  protocol: exports.PROTOCOLS.Spark,
129
129
  },
130
- [enums_1.Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH]: {
131
- strategyOrBundleId: enums_1.Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
132
- strategyId: enums_1.Strategies.Identifiers.DebtSwitch,
133
- protocol: exports.PROTOCOLS.AaveV3,
134
- },
135
- [enums_1.Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH_EOA]: {
136
- strategyOrBundleId: enums_1.Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH_EOA,
137
- strategyId: enums_1.Strategies.Identifiers.EoaDebtSwitch,
138
- protocol: exports.PROTOCOLS.AaveV3,
139
- },
140
130
  };
141
131
  exports.OPTIMISM_STRATEGIES_INFO = {
142
132
  [enums_1.Strategies.OptimismIds.EXCHANGE_DCA]: {
@@ -154,16 +144,6 @@ exports.OPTIMISM_STRATEGIES_INFO = {
154
144
  strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
155
145
  protocol: exports.PROTOCOLS.AaveV3,
156
146
  },
157
- [enums_1.Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH]: {
158
- strategyOrBundleId: enums_1.Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH,
159
- strategyId: enums_1.Strategies.Identifiers.DebtSwitch,
160
- protocol: exports.PROTOCOLS.AaveV3,
161
- },
162
- [enums_1.Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH_EOA]: {
163
- strategyOrBundleId: enums_1.Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH_EOA,
164
- strategyId: enums_1.Strategies.Identifiers.EoaDebtSwitch,
165
- protocol: exports.PROTOCOLS.AaveV3,
166
- },
167
147
  };
168
148
  exports.BASE_STRATEGIES_INFO = {
169
149
  [enums_1.Strategies.BaseIds.EXCHANGE_DCA]: {
@@ -181,16 +161,6 @@ exports.BASE_STRATEGIES_INFO = {
181
161
  strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
182
162
  protocol: exports.PROTOCOLS.AaveV3,
183
163
  },
184
- [enums_1.Strategies.BaseIds.AAVE_V3_DEBT_SWITCH]: {
185
- strategyOrBundleId: enums_1.Strategies.BaseIds.AAVE_V3_DEBT_SWITCH,
186
- strategyId: enums_1.Strategies.Identifiers.DebtSwitch,
187
- protocol: exports.PROTOCOLS.AaveV3,
188
- },
189
- [enums_1.Strategies.BaseIds.AAVE_V3_DEBT_SWITCH_EOA]: {
190
- strategyOrBundleId: enums_1.Strategies.BaseIds.AAVE_V3_DEBT_SWITCH_EOA,
191
- strategyId: enums_1.Strategies.Identifiers.EoaDebtSwitch,
192
- protocol: exports.PROTOCOLS.AaveV3,
193
- },
194
164
  };
195
165
  exports.ARBITRUM_STRATEGIES_INFO = {
196
166
  [enums_1.Strategies.ArbitrumIds.EXCHANGE_DCA]: {
@@ -208,16 +178,6 @@ exports.ARBITRUM_STRATEGIES_INFO = {
208
178
  strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
209
179
  protocol: exports.PROTOCOLS.AaveV3,
210
180
  },
211
- [enums_1.Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH]: {
212
- strategyOrBundleId: enums_1.Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH,
213
- strategyId: enums_1.Strategies.Identifiers.DebtSwitch,
214
- protocol: exports.PROTOCOLS.AaveV3,
215
- },
216
- [enums_1.Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH_EOA]: {
217
- strategyOrBundleId: enums_1.Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH_EOA,
218
- strategyId: enums_1.Strategies.Identifiers.EoaDebtSwitch,
219
- protocol: exports.PROTOCOLS.AaveV3,
220
- },
221
181
  };
222
182
  exports.STRATEGIES_INFO = {
223
183
  [enums_1.ChainId.Ethereum]: exports.MAINNET_STRATEGIES_INFO,
@@ -699,6 +659,16 @@ exports.MAINNET_BUNDLES_INFO = {
699
659
  strategyId: enums_1.Strategies.Identifiers.EoaLiquidationProtection,
700
660
  protocol: exports.PROTOCOLS.Spark,
701
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
+ },
702
672
  };
703
673
  exports.OPTIMISM_BUNDLES_INFO = {
704
674
  [enums_1.Bundles.OptimismIds.AAVE_V3_REPAY]: {
@@ -346,24 +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 triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
353
- const subData = 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]);
354
356
  _position.strategyData.decoded.triggerData = triggerData;
355
357
  _position.strategyData.decoded.subData = subData;
356
- _position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
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
+ };
357
370
  return _position;
358
371
  }
359
- function parseAaveV3DebtSwitch(position, parseData) {
372
+ function parseAaveV3CollateralSwitch(position, parseData) {
360
373
  const _position = (0, lodash_1.cloneDeep)(position);
361
374
  const { subStruct } = parseData.subscriptionEventData;
362
375
  const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
363
- const subData = subDataService.aaveV3DebtSwitchSubData.decode(subStruct.subData);
376
+ const subData = subDataService.aaveV3CollateralSwitchSubData.decode(subStruct.subData);
364
377
  _position.strategyData.decoded.triggerData = triggerData;
365
378
  _position.strategyData.decoded.subData = subData;
366
- // TODO -> This isn't enough for ID
367
379
  _position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
368
380
  return _position;
369
381
  }
@@ -1256,9 +1268,9 @@ const parsingMethodsMapping = {
1256
1268
  [enums_1.Strategies.Identifiers.EoaRepayOnPrice]: parseAaveV3LeverageManagementOnPrice,
1257
1269
  [enums_1.Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV3LeverageManagementOnPrice,
1258
1270
  [enums_1.Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
1271
+ [enums_1.Strategies.Identifiers.InstantCloseOnPrice]: parseAaveV3InstantCloseOnPrice,
1272
+ [enums_1.Strategies.Identifiers.EoaInstantCloseOnPrice]: parseAaveV3InstantCloseOnPrice,
1259
1273
  [enums_1.Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
1260
- [enums_1.Strategies.Identifiers.DebtSwitch]: parseAaveV3DebtSwitch,
1261
- [enums_1.Strategies.Identifiers.EoaDebtSwitch]: parseAaveV3DebtSwitch,
1262
1274
  [enums_1.Strategies.Identifiers.LiquidationProtection]: parseAaveV3LiquidationProtection,
1263
1275
  [enums_1.Strategies.Identifiers.EoaLiquidationProtection]: parseAaveV3LiquidationProtection,
1264
1276
  },
@@ -13,6 +13,7 @@ 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
18
  describe('When testing strategiesService.parseStrategiesAutomatedPosition', () => __awaiter(void 0, void 0, void 0, function* () {
18
19
  // TODO: we should probably write this for every strategy?
@@ -108,4 +109,65 @@ describe('Feature: strategiesService.ts', () => {
108
109
  }));
109
110
  });
110
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
+ });
111
173
  });
@@ -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[])[];
@@ -190,15 +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);
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);
197
198
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
198
199
  },
199
- 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) {
200
201
  const isBundle = false;
201
- const subDataEncoded = subDataService.aaveV3DebtSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user);
202
+ const subDataEncoded = subDataService.aaveV3CollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
202
203
  const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
203
204
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
204
205
  },
@@ -757,6 +757,117 @@ describe('Feature: strategySubService.ts', () => {
757
757
  });
758
758
  });
759
759
  });
760
+ describe('instantCloseOnPriceGeneric()', () => {
761
+ const examples = [
762
+ // Stop loss only (to debt)
763
+ [
764
+ [
765
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
766
+ true,
767
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
768
+ [
769
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
770
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
771
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
772
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
773
+ '0x0000000000000000000000000000000000000000000000000000000000000003',
774
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
775
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
776
+ '0x0000000000000000000000000000000000000000000000000de0b6b3a7640000',
777
+ '0x000000000000000000000000000000000000000000000000002386f26fc10000',
778
+ ],
779
+ ],
780
+ [
781
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
782
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
783
+ 0,
784
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
785
+ 1,
786
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
787
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
788
+ '1000000000000000000',
789
+ '10000000000000000',
790
+ 1500,
791
+ enums_1.CloseToAssetType.DEBT,
792
+ 0,
793
+ enums_1.CloseToAssetType.COLLATERAL, // takeProfitType (not used since price is 0)
794
+ ]
795
+ ],
796
+ // Take profit only (to collateral), zero tsi and slippage
797
+ [
798
+ [
799
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
800
+ true,
801
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
802
+ [
803
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
804
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
805
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
806
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
807
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
808
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
809
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
810
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
811
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
812
+ ],
813
+ ],
814
+ [
815
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
816
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
817
+ 0,
818
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
819
+ 1,
820
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
821
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
822
+ '0',
823
+ '0',
824
+ 0,
825
+ enums_1.CloseToAssetType.DEBT,
826
+ 5000,
827
+ enums_1.CloseToAssetType.COLLATERAL, // takeProfitType
828
+ ]
829
+ ],
830
+ // Take profit (to debt) and stop loss (to collateral)
831
+ [
832
+ [
833
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
834
+ true,
835
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
836
+ [
837
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
838
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
839
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
840
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
841
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
842
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
843
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
844
+ '0x00000000000000000000000000000000000000000000000000b1a2bc2ec50000',
845
+ '0x0000000000000000000000000000000000000000000000000011c37937e08000',
846
+ ],
847
+ ],
848
+ [
849
+ enums_1.Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
850
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
851
+ 0,
852
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
853
+ 1,
854
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
855
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
856
+ '50000000000000000',
857
+ '5000000000000000',
858
+ 1500,
859
+ enums_1.CloseToAssetType.COLLATERAL,
860
+ 4000,
861
+ enums_1.CloseToAssetType.DEBT, // takeProfitType
862
+ ]
863
+ ],
864
+ ];
865
+ examples.forEach(([expected, actual]) => {
866
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
867
+ (0, chai_1.expect)(strategySubService_1.aaveV3Encode.instantCloseOnPriceGeneric(...actual)).to.eql(expected);
868
+ });
869
+ });
870
+ });
760
871
  describe('collateralSwitch()', () => {
761
872
  const examples = [
762
873
  // WETH -> USDC, price 100000, state UNDER
@@ -856,77 +967,6 @@ describe('Feature: strategySubService.ts', () => {
856
967
  });
857
968
  });
858
969
  });
859
- describe('debtSwitch()', () => {
860
- const examples = [
861
- // USDC -> DAI, price 100000, state UNDER
862
- [
863
- [
864
- enums_1.Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
865
- false,
866
- ['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000009184e72a0000000000000000000000000000000000000000000000000000000000000000001'],
867
- [
868
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
869
- '0x0000000000000000000000000000000000000000000000000000000000000001',
870
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
871
- '0x0000000000000000000000000000000000000000000000000000000000000003',
872
- '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
873
- '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
874
- '0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
875
- ],
876
- ],
877
- [
878
- enums_1.Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
879
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
880
- 1,
881
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
882
- 3,
883
- web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
884
- '10000000000000000000',
885
- web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
886
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
887
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
888
- 100000,
889
- enums_1.RatioState.UNDER,
890
- ]
891
- ],
892
- // DAI -> USDC (MaxUint256), price 1, state OVER
893
- [
894
- [
895
- enums_1.Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
896
- false,
897
- ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000000'],
898
- [
899
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
900
- '0x0000000000000000000000000000000000000000000000000000000000000003',
901
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
902
- '0x0000000000000000000000000000000000000000000000000000000000000001',
903
- '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
904
- '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
905
- '0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
906
- ],
907
- ],
908
- [
909
- enums_1.Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
910
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
911
- 3,
912
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
913
- 1,
914
- web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
915
- tokens_1.MAXUINT,
916
- web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
917
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
918
- web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
919
- 1,
920
- enums_1.RatioState.OVER,
921
- ]
922
- ],
923
- ];
924
- examples.forEach(([expected, actual]) => {
925
- it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
926
- (0, chai_1.expect)(strategySubService_1.aaveV3Encode.debtSwitch(...actual)).to.eql(expected);
927
- });
928
- });
929
- });
930
970
  });
931
971
  describe('When testing strategySubService.compoundV3Encode', () => {
932
972
  describe('leverageManagementOnPrice()', () => {
@@ -248,19 +248,22 @@ export declare const aaveV3CloseGenericSubData: {
248
248
  owner: EthereumAddress;
249
249
  };
250
250
  };
251
- export declare const aaveV3CollateralSwitchSubData: {
252
- encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, useOnBehalf?: boolean): string[];
251
+ export declare const aaveV3InstantCloseGenericSubData: {
252
+ encode(collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, closeType: CloseStrategyType, marketAddr: EthereumAddress, user: EthereumAddress, tsi: string, slippage: string): string[];
253
253
  decode(subData: string[]): {
254
- fromAsset: EthereumAddress;
255
- fromAssetId: number;
256
- toAsset: EthereumAddress;
257
- toAssetId: number;
254
+ collAsset: EthereumAddress;
255
+ collAssetId: number;
256
+ debtAsset: EthereumAddress;
257
+ debtAssetId: number;
258
+ closeType: CloseStrategyType;
258
259
  marketAddr: EthereumAddress;
259
- amountToSwitch: string;
260
+ owner: EthereumAddress;
261
+ tsi: string;
262
+ slippage: string;
260
263
  };
261
264
  };
262
- export declare const aaveV3DebtSwitchSubData: {
263
- encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress): string[];
265
+ export declare const aaveV3CollateralSwitchSubData: {
266
+ encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, useOnBehalf?: boolean): string[];
264
267
  decode(subData: string[]): {
265
268
  fromAsset: EthereumAddress;
266
269
  fromAssetId: number;
@@ -268,7 +271,6 @@ export declare const aaveV3DebtSwitchSubData: {
268
271
  toAssetId: number;
269
272
  marketAddr: EthereumAddress;
270
273
  amountToSwitch: string;
271
- user: EthereumAddress;
272
274
  };
273
275
  };
274
276
  export declare const aaveV3QuotePriceSubData: {
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.sparkCloseGenericSubData = exports.sparkGenericLiquidationProtectionSubData = exports.sparkGenericLeverageManagementSubData = exports.sparkLiquidationProtectionSubData = exports.sparkLeverageManagementSubData = exports.legacySparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.legacyExchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.compoundV3CloseSubData = exports.compoundV3LeverageManagementOnPriceSubData = exports.compoundV3LiquidationProtectionSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.legacyCompoundV2LeverageManagementSubData = exports.aaveV4CollateralSwitchSubData = exports.aaveV4CloseSubData = exports.aaveV4LeverageManagementOnPriceSubData = exports.aaveV4LiquidationProtectionSubData = exports.aaveV4LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3DebtSwitchSubData = exports.aaveV3CollateralSwitchSubData = exports.aaveV3CloseGenericSubData = exports.aaveV3LeverageManagementOnPriceGeneric = exports.aaveV3LiquidationProtectionSubData = exports.aaveV3LeverageManagementSubData = exports.legacyAaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.legacyAaveV2LeverageManagementSubData = exports.liquityV2PaybackSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.legacyLiquityLeverageManagementSubData = exports.liquityRepayFromSavingsSubData = exports.makerLiquidationProtectionSubData = exports.makerLeverageManagementSubData = exports.legacyMakerLeverageManagementSubData = exports.makerCloseSubData = exports.makerRepayFromSavingsSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = void 0;
6
+ exports.sparkCloseGenericSubData = exports.sparkGenericLiquidationProtectionSubData = exports.sparkGenericLeverageManagementSubData = exports.sparkLiquidationProtectionSubData = exports.sparkLeverageManagementSubData = exports.legacySparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.legacyExchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.compoundV3CloseSubData = exports.compoundV3LeverageManagementOnPriceSubData = exports.compoundV3LiquidationProtectionSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.legacyCompoundV2LeverageManagementSubData = exports.aaveV4CollateralSwitchSubData = exports.aaveV4CloseSubData = exports.aaveV4LeverageManagementOnPriceSubData = exports.aaveV4LiquidationProtectionSubData = exports.aaveV4LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3CollateralSwitchSubData = exports.aaveV3InstantCloseGenericSubData = exports.aaveV3CloseGenericSubData = exports.aaveV3LeverageManagementOnPriceGeneric = exports.aaveV3LiquidationProtectionSubData = exports.aaveV3LeverageManagementSubData = exports.legacyAaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.legacyAaveV2LeverageManagementSubData = exports.liquityV2PaybackSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.legacyLiquityLeverageManagementSubData = exports.liquityRepayFromSavingsSubData = exports.makerLiquidationProtectionSubData = exports.makerLeverageManagementSubData = exports.legacyMakerLeverageManagementSubData = exports.makerCloseSubData = exports.makerRepayFromSavingsSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = void 0;
7
7
  exports.fluidLiquidationProtectionSubData = exports.fluidLeverageManagementSubData = exports.morphoBlueCloseOnPriceSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.morphoBlueLiquidationProtectionSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.sparkGenericFLCollateralSwitchSubData = exports.sparkCollateralSwitchSubData = exports.sparkLeverageManagementOnPriceGenericSubData = exports.sparkLeverageManagementOnPriceSubData = void 0;
8
8
  const decimal_js_1 = __importDefault(require("decimal.js"));
9
9
  const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
@@ -518,46 +518,53 @@ exports.aaveV3CloseGenericSubData = {
518
518
  };
519
519
  },
520
520
  };
521
- exports.aaveV3CollateralSwitchSubData = {
522
- encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, useOnBehalf = false) {
523
- const encodedFromAsset = web3_eth_abi_1.default.encodeParameter('address', fromAsset);
524
- const encodedFromAssetId = web3_eth_abi_1.default.encodeParameter('uint8', fromAssetId);
525
- const encodedToAsset = web3_eth_abi_1.default.encodeParameter('address', toAsset);
526
- const encodedToAssetId = web3_eth_abi_1.default.encodeParameter('uint8', toAssetId);
527
- const encodedMarketAddr = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
528
- const encodedAmountToSwitch = web3_eth_abi_1.default.encodeParameter('uint256', amountToSwitch);
529
- const encodedUseOnBehalf = web3_eth_abi_1.default.encodeParameter('bool', useOnBehalf);
521
+ exports.aaveV3InstantCloseGenericSubData = {
522
+ encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user, tsi, slippage) {
523
+ const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
524
+ const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint16', collAssetId);
525
+ const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
526
+ const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint16', debtAssetId);
527
+ const encodedCloseType = web3_eth_abi_1.default.encodeParameter('uint8', closeType);
528
+ const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
529
+ const encodedUser = web3_eth_abi_1.default.encodeParameter('address', user);
530
+ const encodedTsi = web3_eth_abi_1.default.encodeParameter('uint256', tsi);
531
+ const encodedSlippage = web3_eth_abi_1.default.encodeParameter('uint256', slippage);
530
532
  return [
531
- encodedFromAsset,
532
- encodedFromAssetId,
533
- encodedToAsset,
534
- encodedToAssetId,
535
- encodedMarketAddr,
536
- encodedAmountToSwitch,
537
- encodedUseOnBehalf,
533
+ encodedColl,
534
+ encodedCollId,
535
+ encodedDebt,
536
+ encodedDebtId,
537
+ encodedCloseType,
538
+ encodedMarket,
539
+ encodedUser,
540
+ encodedTsi,
541
+ encodedSlippage,
538
542
  ];
539
543
  },
540
544
  decode(subData) {
541
- const fromAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
542
- const fromAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
543
- const toAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
544
- const toAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
545
- const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
546
- const amountToSwitch = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
545
+ const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
546
+ const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint16', subData[1]));
547
+ const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
548
+ const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint16', subData[3]));
549
+ const closeType = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[4]));
550
+ const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[5]);
551
+ const owner = web3_eth_abi_1.default.decodeParameter('address', subData[6]);
552
+ const tsi = web3_eth_abi_1.default.decodeParameter('uint256', subData[7]);
553
+ const slippage = web3_eth_abi_1.default.decodeParameter('uint256', subData[8]);
547
554
  return {
548
- fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
555
+ collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner, tsi, slippage,
549
556
  };
550
557
  },
551
558
  };
552
- exports.aaveV3DebtSwitchSubData = {
553
- encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user) {
559
+ exports.aaveV3CollateralSwitchSubData = {
560
+ encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, useOnBehalf = false) {
554
561
  const encodedFromAsset = web3_eth_abi_1.default.encodeParameter('address', fromAsset);
555
562
  const encodedFromAssetId = web3_eth_abi_1.default.encodeParameter('uint8', fromAssetId);
556
563
  const encodedToAsset = web3_eth_abi_1.default.encodeParameter('address', toAsset);
557
564
  const encodedToAssetId = web3_eth_abi_1.default.encodeParameter('uint8', toAssetId);
558
565
  const encodedMarketAddr = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
559
566
  const encodedAmountToSwitch = web3_eth_abi_1.default.encodeParameter('uint256', amountToSwitch);
560
- const encodedUser = web3_eth_abi_1.default.encodeParameter('address', user);
567
+ const encodedUseOnBehalf = web3_eth_abi_1.default.encodeParameter('bool', useOnBehalf);
561
568
  return [
562
569
  encodedFromAsset,
563
570
  encodedFromAssetId,
@@ -565,7 +572,7 @@ exports.aaveV3DebtSwitchSubData = {
565
572
  encodedToAssetId,
566
573
  encodedMarketAddr,
567
574
  encodedAmountToSwitch,
568
- encodedUser,
575
+ encodedUseOnBehalf,
569
576
  ];
570
577
  },
571
578
  decode(subData) {
@@ -575,9 +582,8 @@ exports.aaveV3DebtSwitchSubData = {
575
582
  const toAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
576
583
  const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
577
584
  const amountToSwitch = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
578
- const user = web3_eth_abi_1.default.decodeParameter('address', subData[6]);
579
585
  return {
580
- fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user,
586
+ fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
581
587
  };
582
588
  },
583
589
  };