@defisaver/automation-sdk 3.3.18-audit-dev → 3.3.18-spark-eoa-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.
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import Web3 from 'web3';
11
11
  import { expect } from 'chai';
12
+ import { omit } from 'lodash';
12
13
  import { getAssetInfo } from '@defisaver/tokens';
13
14
  import { ChainId } from '../types/enums';
14
15
  import '../configuration';
@@ -96,7 +97,6 @@ describe('Feature: ethereumService.ts', () => {
96
97
  'address': '0x5f98805A4E8be255a32880FDeC7F6728C6568bA0',
97
98
  'blockHash': '0xb92cab2569456dbfbdb853d2c67d72c9a7580543dbcb55d483a77322b40755a4',
98
99
  'blockNumber': 15166163,
99
- 'blockTimestamp': '0x62d53ad8',
100
100
  'event': 'Transfer',
101
101
  'id': 'log_e2258e3a',
102
102
  'logIndex': 385,
@@ -123,7 +123,7 @@ describe('Feature: ethereumService.ts', () => {
123
123
  },
124
124
  ],
125
125
  [
126
- makeErc20Contract(Web3_1, getAssetInfo('LUSD').address, ChainId.Ethereum),
126
+ Object.assign(Object.assign({}, makeErc20Contract(Web3_1, getAssetInfo('LUSD').address, ChainId.Ethereum)), { createdBlock: 15166163 }),
127
127
  null,
128
128
  'Transfer',
129
129
  {
@@ -142,7 +142,6 @@ describe('Feature: ethereumService.ts', () => {
142
142
  'address': '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
143
143
  'blockHash': '0xacb0213af63b4c17c436f084a96d1ac385641a59a9a4cf014ae3337cbe545aa7',
144
144
  'blockNumber': 5353002,
145
- 'blockTimestamp': '0x624c1a5b',
146
145
  'event': 'Transfer',
147
146
  'id': 'log_f49645b8',
148
147
  'logIndex': 1,
@@ -188,7 +187,6 @@ describe('Feature: ethereumService.ts', () => {
188
187
  'address': '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
189
188
  'blockHash': '0xacb0213af63b4c17c436f084a96d1ac385641a59a9a4cf014ae3337cbe545aa7',
190
189
  'blockNumber': 5353002,
191
- 'blockTimestamp': '0x624c1a5b',
192
190
  'event': 'Transfer',
193
191
  'id': 'log_f49645b8',
194
192
  'logIndex': 1,
@@ -231,9 +229,8 @@ describe('Feature: ethereumService.ts', () => {
231
229
  ];
232
230
  examples.forEach(([expected, actual]) => {
233
231
  it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => __awaiter(void 0, void 0, void 0, function* () {
234
- const data = yield getEventsFromContract(...actual);
235
- console.log(data);
236
- expect(yield getEventsFromContract(...actual)).to.eql(expected);
232
+ const events = yield getEventsFromContract(...actual);
233
+ expect(events.map((event) => omit(event, 'blockTimestamp'))).to.eql(expected);
237
234
  }));
238
235
  });
239
236
  });
@@ -330,11 +330,17 @@ function parseAaveV3CollateralSwitch(position, parseData) {
330
330
  function parseSparkCollateralSwitch(position, parseData) {
331
331
  const _position = cloneDeep(position);
332
332
  const { subStruct } = parseData.subscriptionEventData;
333
+ const isEOA = _position.strategy.strategyId.includes('eoa');
333
334
  const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
334
- const subData = subDataService.sparkCollateralSwitchSubData.decode(subStruct.subData);
335
+ const subData = isEOA
336
+ ? subDataService.sparkGenericFLCollateralSwitchSubData.decode(subStruct.subData)
337
+ : subDataService.sparkCollateralSwitchSubData.decode(subStruct.subData);
335
338
  _position.strategyData.decoded.triggerData = triggerData;
336
339
  _position.strategyData.decoded.subData = subData;
337
340
  _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
341
+ _position.strategy.strategyId = isEOA
342
+ ? Strategies.Identifiers.EoaCollateralSwitch
343
+ : Strategies.Identifiers.CollateralSwitch;
338
344
  return _position;
339
345
  }
340
346
  function parseAaveV4LeverageManagement(position, parseData) {
@@ -746,19 +752,22 @@ function parseSparkLeverageManagement(position, parseData) {
746
752
  const _position = cloneDeep(position);
747
753
  const { subStruct, subId, subHash } = parseData.subscriptionEventData;
748
754
  const { isEnabled } = parseData.strategiesSubsData;
755
+ const isEOA = _position.strategy.strategyId.includes('eoa');
749
756
  const triggerData = triggerService.sparkRatioTrigger.decode(subStruct.triggerData);
750
- const subData = subDataService.legacySparkLeverageManagementSubData.decode(subStruct.subData);
757
+ const subData = isEOA
758
+ ? subDataService.sparkGenericLeverageManagementSubData.decode(subStruct.subData)
759
+ : subDataService.legacySparkLeverageManagementSubData.decode(subStruct.subData);
751
760
  _position.strategyData.decoded.triggerData = triggerData;
752
761
  _position.strategyData.decoded.subData = subData;
753
762
  _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.market);
754
- const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
763
+ const isRepay = [Strategies.Identifiers.Repay, Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId);
755
764
  if (isRepay) {
756
765
  _position.specific = {
757
766
  triggerRepayRatio: triggerData.ratio,
758
767
  targetRepayRatio: subData.targetRatio,
759
768
  repayEnabled: isEnabled,
760
769
  subId1: Number(subId),
761
- mergeWithId: Strategies.Identifiers.Boost,
770
+ mergeWithId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
762
771
  subHashRepay: subHash,
763
772
  };
764
773
  }
@@ -768,19 +777,24 @@ function parseSparkLeverageManagement(position, parseData) {
768
777
  targetBoostRatio: subData.targetRatio,
769
778
  boostEnabled: isEnabled,
770
779
  subId2: Number(subId),
771
- mergeId: Strategies.Identifiers.Boost,
780
+ mergeId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
772
781
  subHashBoost: subHash,
773
782
  };
774
783
  }
775
- _position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
784
+ _position.strategy.strategyId = isEOA
785
+ ? Strategies.IdOverrides.EoaLeverageManagement
786
+ : Strategies.IdOverrides.LeverageManagement;
776
787
  return _position;
777
788
  }
778
789
  function parseSparkLiquidationProtection(position, parseData) {
779
790
  const _position = cloneDeep(position);
780
791
  const { subStruct, subId, subHash } = parseData.subscriptionEventData;
781
792
  const { isEnabled } = parseData.strategiesSubsData;
793
+ const isEOA = _position.strategy.strategyId.includes('eoa');
782
794
  const triggerData = triggerService.sparkRatioTrigger.decode(subStruct.triggerData);
783
- const subData = subDataService.sparkLiquidationProtectionSubData.decode(subStruct.subData);
795
+ const subData = isEOA
796
+ ? subDataService.sparkGenericLiquidationProtectionSubData.decode(subStruct.subData)
797
+ : subDataService.sparkLiquidationProtectionSubData.decode(subStruct.subData);
784
798
  _position.strategyData.decoded.triggerData = triggerData;
785
799
  _position.strategyData.decoded.subData = subData;
786
800
  _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.market);
@@ -791,14 +805,20 @@ function parseSparkLiquidationProtection(position, parseData) {
791
805
  subId1: Number(subId),
792
806
  subHashRepay: subHash,
793
807
  };
808
+ _position.strategy.strategyId = isEOA
809
+ ? Strategies.IdOverrides.EoaLiquidationProtection
810
+ : Strategies.IdOverrides.LiquidationProtection;
794
811
  _position.strategy.strategyId = Strategies.IdOverrides.LiquidationProtection;
795
812
  return _position;
796
813
  }
797
814
  function parseSparkLeverageManagementOnPrice(position, parseData) {
798
815
  const _position = cloneDeep(position);
799
816
  const { subStruct } = parseData.subscriptionEventData;
817
+ const isEOA = _position.strategy.strategyId.includes('eoa');
800
818
  const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
801
- const subData = subDataService.sparkLeverageManagementOnPriceSubData.decode(subStruct.subData);
819
+ const subData = isEOA
820
+ ? subDataService.sparkLeverageManagementOnPriceGenericSubData.decode(subStruct.subData)
821
+ : subDataService.sparkLeverageManagementOnPriceSubData.decode(subStruct.subData);
802
822
  _position.strategyData.decoded.triggerData = triggerData;
803
823
  _position.strategyData.decoded.subData = subData;
804
824
  _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
@@ -815,6 +835,9 @@ function parseSparkLeverageManagementOnPrice(position, parseData) {
815
835
  price: triggerData.price,
816
836
  ratioState: triggerData.ratioState,
817
837
  };
838
+ _position.strategy.strategyId = isEOA
839
+ ? Strategies.IdOverrides.EoaLeverageManagementOnPrice
840
+ : Strategies.IdOverrides.LeverageManagementOnPrice;
818
841
  return _position;
819
842
  }
820
843
  function parseSparkCloseOnPrice(position, parseData) {
@@ -822,9 +845,11 @@ function parseSparkCloseOnPrice(position, parseData) {
822
845
  const { subStruct } = parseData.subscriptionEventData;
823
846
  const triggerData = triggerService.sparkQuotePriceRangeTrigger.decode(subStruct.triggerData);
824
847
  const subData = subDataService.sparkCloseGenericSubData.decode(subStruct.subData);
848
+ const isEOA = _position.strategy.strategyId.includes('eoa');
825
849
  _position.strategyData.decoded.triggerData = triggerData;
826
850
  _position.strategyData.decoded.subData = subData;
827
851
  _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
852
+ _position.strategy.strategyId = isEOA ? Strategies.Identifiers.EoaCloseOnPrice : Strategies.Identifiers.CloseOnPrice;
828
853
  const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
829
854
  _position.specific = {
830
855
  collAsset: subData.collAsset,
@@ -1247,8 +1272,15 @@ const parsingMethodsMapping = {
1247
1272
  [Strategies.Identifiers.RepayOnPrice]: parseSparkLeverageManagementOnPrice,
1248
1273
  [Strategies.Identifiers.BoostOnPrice]: parseSparkLeverageManagementOnPrice,
1249
1274
  [Strategies.Identifiers.CloseOnPrice]: parseSparkCloseOnPrice,
1275
+ [Strategies.Identifiers.EoaRepay]: parseSparkLeverageManagement,
1276
+ [Strategies.Identifiers.EoaBoost]: parseSparkLeverageManagement,
1277
+ [Strategies.Identifiers.EoaRepayOnPrice]: parseSparkLeverageManagementOnPrice,
1278
+ [Strategies.Identifiers.EoaBoostOnPrice]: parseSparkLeverageManagementOnPrice,
1279
+ [Strategies.Identifiers.EoaCloseOnPrice]: parseSparkCloseOnPrice,
1250
1280
  [Strategies.Identifiers.CollateralSwitch]: parseSparkCollateralSwitch,
1281
+ [Strategies.Identifiers.EoaCollateralSwitch]: parseSparkCollateralSwitch,
1251
1282
  [Strategies.Identifiers.LiquidationProtection]: parseSparkLiquidationProtection,
1283
+ [Strategies.Identifiers.EoaLiquidationProtection]: parseSparkLiquidationProtection,
1252
1284
  },
1253
1285
  [ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
1254
1286
  [Strategies.Identifiers.Repay]: parseCrvUSDLeverageManagement,
@@ -93,7 +93,11 @@ export declare const sparkEncode: {
93
93
  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[])[];
94
94
  leverageManagement(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
95
95
  liquidationProtection(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
96
+ leverageManagementGeneric(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
97
+ liquidationProtectionGeneric(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
98
+ leverageManagementOnPriceGeneric(strategyOrBundleId: number, price: number, ratioState: RatioState, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number, user: EthereumAddress): (number | boolean | string[])[];
96
99
  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[])[];
100
+ 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[])[];
97
101
  };
98
102
  export declare const crvUSDEncode: {
99
103
  leverageManagement(owner: EthereumAddress, controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress): (boolean | string[] | Bundles.MainnetIds)[];
@@ -250,12 +250,36 @@ export const sparkEncode = {
250
250
  const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
251
251
  return [strategyOrBundleId, isBundle, triggerData, subData];
252
252
  },
253
+ leverageManagementGeneric(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio) {
254
+ const isBundle = true;
255
+ const subData = subDataService.sparkGenericLeverageManagementSubData.encode(targetRatio, ratioState, market, user);
256
+ const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
257
+ return [strategyOrBundleId, isBundle, triggerData, subData];
258
+ },
259
+ liquidationProtectionGeneric(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio) {
260
+ const isBundle = true;
261
+ const subData = subDataService.sparkGenericLiquidationProtectionSubData.encode(targetRatio, ratioState, market, user);
262
+ const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
263
+ return [strategyOrBundleId, isBundle, triggerData, subData];
264
+ },
265
+ leverageManagementOnPriceGeneric(strategyOrBundleId, price, ratioState, collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio, user) {
266
+ const isBundle = true;
267
+ const subData = subDataService.sparkLeverageManagementOnPriceGenericSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio, user);
268
+ const triggerData = triggerService.sparkQuotePriceTrigger.encode(collAsset, debtAsset, price, ratioState);
269
+ return [strategyOrBundleId, isBundle, triggerData, subData];
270
+ },
253
271
  collateralSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, baseTokenAddress, quoteTokenAddress, price, state) {
254
272
  const isBundle = false;
255
273
  const subDataEncoded = subDataService.sparkCollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
256
274
  const triggerDataEncoded = triggerService.sparkQuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
257
275
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
258
276
  },
277
+ collateralSwitchGeneric(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user, baseTokenAddress, quoteTokenAddress, price, state) {
278
+ const isBundle = false;
279
+ const subDataEncoded = subDataService.sparkGenericFLCollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user);
280
+ const triggerDataEncoded = triggerService.sparkQuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
281
+ return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
282
+ },
259
283
  };
260
284
  export const crvUSDEncode = {
261
285
  leverageManagement(owner, controllerAddr, ratioState, targetRatio, triggerRatio, collTokenAddr, crvUSDAddr) {
@@ -1453,6 +1453,224 @@ describe('Feature: strategySubService.ts', () => {
1453
1453
  });
1454
1454
  });
1455
1455
  });
1456
+ describe('leverageManagementGeneric()', () => {
1457
+ const examples = [
1458
+ [
1459
+ [
1460
+ Bundles.MainnetIds.SPARK_EOA_REPAY,
1461
+ true,
1462
+ ['0x000000000000000000000000123456789012345678901234567890123456789000000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001'],
1463
+ [
1464
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
1465
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1466
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1467
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1468
+ ],
1469
+ ],
1470
+ [
1471
+ Bundles.MainnetIds.SPARK_EOA_REPAY,
1472
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1473
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1474
+ RatioState.UNDER,
1475
+ 180,
1476
+ 140,
1477
+ ],
1478
+ ],
1479
+ [
1480
+ [
1481
+ Bundles.MainnetIds.SPARK_EOA_BOOST,
1482
+ true,
1483
+ ['0x000000000000000000000000123456789012345678901234567890123456789000000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
1484
+ [
1485
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1486
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1487
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1488
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1489
+ ],
1490
+ ],
1491
+ [
1492
+ Bundles.MainnetIds.SPARK_EOA_BOOST,
1493
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1494
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1495
+ RatioState.OVER,
1496
+ 160,
1497
+ 200,
1498
+ ],
1499
+ ],
1500
+ ];
1501
+ examples.forEach(([expected, actual]) => {
1502
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1503
+ expect(sparkEncode.leverageManagementGeneric(...actual)).to.eql(expected);
1504
+ });
1505
+ });
1506
+ });
1507
+ describe('liquidationProtection()', () => {
1508
+ const examples = [
1509
+ [
1510
+ [
1511
+ Bundles.MainnetIds.SPARK_SW_LIQUIDATION_PROTECTION,
1512
+ true,
1513
+ ['0x000000000000000000000000123456789012345678901234567890123456789000000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001'],
1514
+ [
1515
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
1516
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1517
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1518
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1519
+ ],
1520
+ ],
1521
+ [
1522
+ Bundles.MainnetIds.SPARK_SW_LIQUIDATION_PROTECTION,
1523
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1524
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1525
+ RatioState.UNDER,
1526
+ 180,
1527
+ 140,
1528
+ ],
1529
+ ],
1530
+ [
1531
+ [
1532
+ Bundles.MainnetIds.SPARK_SW_LIQUIDATION_PROTECTION,
1533
+ true,
1534
+ ['0x000000000000000000000000123456789012345678901234567890123456789000000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
1535
+ [
1536
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1537
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1538
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1539
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1540
+ ],
1541
+ ],
1542
+ [
1543
+ Bundles.MainnetIds.SPARK_SW_LIQUIDATION_PROTECTION,
1544
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1545
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1546
+ RatioState.OVER,
1547
+ 160,
1548
+ 200,
1549
+ ],
1550
+ ],
1551
+ ];
1552
+ examples.forEach(([expected, actual]) => {
1553
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1554
+ expect(sparkEncode.liquidationProtection(...actual)).to.eql(expected);
1555
+ });
1556
+ });
1557
+ });
1558
+ describe('liquidationProtectionGeneric()', () => {
1559
+ const examples = [
1560
+ [
1561
+ [
1562
+ Bundles.MainnetIds.SPARK_EOA_LIQUIDATION_PROTECTION,
1563
+ true,
1564
+ ['0x000000000000000000000000123456789012345678901234567890123456789000000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001'],
1565
+ [
1566
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
1567
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1568
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1569
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1570
+ ],
1571
+ ],
1572
+ [
1573
+ Bundles.MainnetIds.SPARK_EOA_LIQUIDATION_PROTECTION,
1574
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1575
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1576
+ RatioState.UNDER,
1577
+ 180,
1578
+ 140,
1579
+ ],
1580
+ ],
1581
+ [
1582
+ [
1583
+ Bundles.MainnetIds.SPARK_EOA_LIQUIDATION_PROTECTION,
1584
+ true,
1585
+ ['0x000000000000000000000000123456789012345678901234567890123456789000000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
1586
+ [
1587
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1588
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1589
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1590
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1591
+ ],
1592
+ ],
1593
+ [
1594
+ Bundles.MainnetIds.SPARK_EOA_LIQUIDATION_PROTECTION,
1595
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1596
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1597
+ RatioState.OVER,
1598
+ 160,
1599
+ 200,
1600
+ ],
1601
+ ],
1602
+ ];
1603
+ examples.forEach(([expected, actual]) => {
1604
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1605
+ expect(sparkEncode.liquidationProtectionGeneric(...actual)).to.eql(expected);
1606
+ });
1607
+ });
1608
+ });
1609
+ describe('leverageManagementOnPriceGeneric()', () => {
1610
+ const examples = [
1611
+ [
1612
+ [
1613
+ Bundles.MainnetIds.SPARK_EOA_REPAY_ON_PRICE,
1614
+ true,
1615
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
1616
+ [
1617
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1618
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1619
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1620
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1621
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1622
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1623
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1624
+ ],
1625
+ ],
1626
+ [
1627
+ Bundles.MainnetIds.SPARK_EOA_REPAY_ON_PRICE,
1628
+ 2500,
1629
+ RatioState.UNDER,
1630
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1631
+ 0,
1632
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1633
+ 1,
1634
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1635
+ 200,
1636
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1637
+ ],
1638
+ ],
1639
+ [
1640
+ [
1641
+ Bundles.MainnetIds.SPARK_EOA_BOOST_ON_PRICE,
1642
+ true,
1643
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000417bce6c8000000000000000000000000000000000000000000000000000000000000000000'],
1644
+ [
1645
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1646
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1647
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
1648
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
1649
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1650
+ '0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
1651
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1652
+ ],
1653
+ ],
1654
+ [
1655
+ Bundles.MainnetIds.SPARK_EOA_BOOST_ON_PRICE,
1656
+ 45000,
1657
+ RatioState.OVER,
1658
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1659
+ 2,
1660
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
1661
+ 4,
1662
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1663
+ 250,
1664
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1665
+ ],
1666
+ ],
1667
+ ];
1668
+ examples.forEach(([expected, actual]) => {
1669
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1670
+ expect(sparkEncode.leverageManagementOnPriceGeneric(...actual)).to.eql(expected);
1671
+ });
1672
+ });
1673
+ });
1456
1674
  describe('closeOnPrice()', () => {
1457
1675
  const examples = [
1458
1676
  [
@@ -1491,6 +1709,44 @@ describe('Feature: strategySubService.ts', () => {
1491
1709
  });
1492
1710
  });
1493
1711
  });
1712
+ describe('closeOnPriceGeneric()', () => {
1713
+ const examples = [
1714
+ [
1715
+ [
1716
+ Bundles.MainnetIds.SPARK_EOA_CLOSE,
1717
+ true,
1718
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000003a35294400000000000000000000000000000000000000000000000000000000574fbde6000'],
1719
+ [
1720
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1721
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1722
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
1723
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
1724
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
1725
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1726
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1727
+ ],
1728
+ ],
1729
+ [
1730
+ Bundles.MainnetIds.SPARK_EOA_CLOSE,
1731
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1732
+ 2,
1733
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
1734
+ 4,
1735
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1736
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1737
+ 40000,
1738
+ CloseToAssetType.DEBT,
1739
+ 60000,
1740
+ CloseToAssetType.COLLATERAL,
1741
+ ],
1742
+ ],
1743
+ ];
1744
+ examples.forEach(([expected, actual]) => {
1745
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1746
+ expect(sparkEncode.closeOnPriceGeneric(...actual)).to.eql(expected);
1747
+ });
1748
+ });
1749
+ });
1494
1750
  describe('collateralSwitch()', () => {
1495
1751
  const examples = [
1496
1752
  // WETH -> cbBTC, price 0.025 WETH/cbBTC, state UNDER
@@ -1590,6 +1846,45 @@ describe('Feature: strategySubService.ts', () => {
1590
1846
  });
1591
1847
  });
1592
1848
  });
1849
+ describe('collateralSwitchGeneric()', () => {
1850
+ const examples = [
1851
+ [
1852
+ [
1853
+ Strategies.MainnetIds.SPARK_GENERIC_FL_COLLATERAL_SWITCH,
1854
+ false,
1855
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf00000000000000000000000000000000000000000000000000000000002625a00000000000000000000000000000000000000000000000000000000000000001'],
1856
+ [
1857
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1858
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1859
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1860
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1861
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1862
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
1863
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1864
+ ],
1865
+ ],
1866
+ [
1867
+ Strategies.MainnetIds.SPARK_GENERIC_FL_COLLATERAL_SWITCH,
1868
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1869
+ 0,
1870
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1871
+ 7,
1872
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1873
+ '10000000000000000000',
1874
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1875
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1876
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1877
+ 0.025,
1878
+ RatioState.UNDER,
1879
+ ],
1880
+ ],
1881
+ ];
1882
+ examples.forEach(([expected, actual]) => {
1883
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1884
+ expect(sparkEncode.collateralSwitchGeneric(...actual)).to.eql(expected);
1885
+ });
1886
+ });
1887
+ });
1593
1888
  });
1594
1889
  describe('When testing strategySubService.aaveV4Encode', () => {
1595
1890
  describe('leverageManagement()', () => {
@@ -468,6 +468,20 @@ export declare const sparkLiquidationProtectionSubData: {
468
468
  ratioState: RatioState;
469
469
  };
470
470
  };
471
+ export declare const sparkGenericLeverageManagementSubData: {
472
+ encode(targetRatio: number, ratioState: RatioState, market: EthereumAddress, user: EthereumAddress): string[];
473
+ decode(subData: string[]): {
474
+ targetRatio: number;
475
+ ratioState: RatioState;
476
+ };
477
+ };
478
+ export declare const sparkGenericLiquidationProtectionSubData: {
479
+ encode(targetRatio: number, ratioState: RatioState, market: EthereumAddress, user: EthereumAddress): string[];
480
+ decode(subData: string[]): {
481
+ targetRatio: number;
482
+ ratioState: RatioState;
483
+ };
484
+ };
471
485
  export declare const sparkCloseGenericSubData: {
472
486
  encode(collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, closeType: CloseStrategyType, marketAddr: EthereumAddress, user: EthereumAddress): string[];
473
487
  decode(subData: string[]): {
@@ -491,6 +505,18 @@ export declare const sparkLeverageManagementOnPriceSubData: {
491
505
  targetRatio: number;
492
506
  };
493
507
  };
508
+ export declare const sparkLeverageManagementOnPriceGenericSubData: {
509
+ encode(collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number, user: EthereumAddress): string[];
510
+ decode(subData: string[]): {
511
+ collAsset: string;
512
+ collAssetId: number;
513
+ debtAsset: string;
514
+ debtAssetId: number;
515
+ marketAddr: string;
516
+ targetRatio: number;
517
+ user: string;
518
+ };
519
+ };
494
520
  export declare const sparkCollateralSwitchSubData: {
495
521
  encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, useOnBehalf?: boolean): string[];
496
522
  decode(subData: string[]): {
@@ -502,6 +528,18 @@ export declare const sparkCollateralSwitchSubData: {
502
528
  amountToSwitch: string;
503
529
  };
504
530
  };
531
+ export declare const sparkGenericFLCollateralSwitchSubData: {
532
+ encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress): string[];
533
+ decode(subData: string[]): {
534
+ fromAsset: EthereumAddress;
535
+ fromAssetId: number;
536
+ toAsset: EthereumAddress;
537
+ toAssetId: number;
538
+ marketAddr: EthereumAddress;
539
+ amountToSwitch: string;
540
+ user: EthereumAddress;
541
+ };
542
+ };
505
543
  /**
506
544
  ______ .______ ____ ____ __ __ _______. _______
507
545
  / || _ \ \ \ / / | | | | / || \