@defisaver/automation-sdk 3.3.12 → 3.3.13-strategies-refactor-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.
@@ -81,23 +81,6 @@ export const makerEncode = {
81
81
 
82
82
  return [strategyOrBundleId, isBundle, triggerData, subData];
83
83
  },
84
- leverageManagement(
85
- vaultId: number,
86
- triggerRepayRatio: string,
87
- triggerBoostRatio: string,
88
- targetBoostRatio: string,
89
- targetRepayRatio: string,
90
- boostEnabled: boolean,
91
- ) {
92
- return [
93
- vaultId,
94
- new Dec(triggerRepayRatio).mul(1e16).toString(),
95
- new Dec(triggerBoostRatio).mul(1e16).toString(),
96
- new Dec(targetBoostRatio).mul(1e16).toString(),
97
- new Dec(targetRepayRatio).mul(1e16).toString(),
98
- boostEnabled,
99
- ];
100
- },
101
84
  leverageManagementWithoutSubProxy(
102
85
  vaultId: number,
103
86
  triggerRatio: number,
@@ -179,20 +162,19 @@ export const liquityEncode = {
179
162
 
180
163
  return [strategyId, isBundle, triggerData, subData];
181
164
  },
182
- leverageManagement(
183
- triggerRepayRatio:string,
184
- triggerBoostRatio:string,
185
- targetBoostRatio:string,
186
- targetRepayRatio:string,
187
- boostEnabled:boolean,
165
+ leverageManagementWithoutSubProxy(
166
+ strategyOrBundleId: number,
167
+ user: EthereumAddress,
168
+ ratioState: RatioState,
169
+ targetRatio: number,
170
+ triggerRatio: number,
188
171
  ) {
189
- return [
190
- new Dec(triggerRepayRatio).mul(1e16).toString(),
191
- new Dec(triggerBoostRatio).mul(1e16).toString(),
192
- new Dec(targetBoostRatio).mul(1e16).toString(),
193
- new Dec(targetRepayRatio).mul(1e16).toString(),
194
- boostEnabled,
195
- ];
172
+ const isBundle = true;
173
+
174
+ const subData = subDataService.liquityLeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState);
175
+ const triggerData = triggerService.liquityRatioTrigger.encode(user, triggerRatio, ratioState);
176
+
177
+ return [strategyOrBundleId, isBundle, triggerData, subData];
196
178
  },
197
179
  dsrPayback(
198
180
  proxyAddress: EthereumAddress,
@@ -248,39 +230,24 @@ export const chickenBondsEncode = {
248
230
  };
249
231
 
250
232
  export const aaveV2Encode = {
251
- leverageManagement(
252
- triggerRepayRatio: number,
253
- triggerBoostRatio: number,
254
- targetBoostRatio: number,
255
- targetRepayRatio: number,
256
- boostEnabled: boolean,
233
+ leverageManagementWithoutSubProxy(
234
+ strategyOrBundleId: number,
235
+ market: EthereumAddress,
236
+ user: EthereumAddress,
237
+ ratioState: RatioState,
238
+ targetRatio: number,
239
+ triggerRatio: number,
257
240
  ) {
258
- return subDataService.aaveV2LeverageManagementSubData.encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled);
241
+ const isBundle = true;
242
+
243
+ const subData = subDataService.aaveV2LeverageManagementSubDataWithoutSubProxy.encode(market, targetRatio, ratioState);
244
+ const triggerData = triggerService.aaveV2RatioTrigger.encode(user, market, triggerRatio, ratioState);
245
+
246
+ return [strategyOrBundleId, isBundle, triggerData, subData];
259
247
  },
260
248
  };
261
249
 
262
250
  export const aaveV3Encode = {
263
- leverageManagement(
264
- triggerRepayRatio: number,
265
- triggerBoostRatio: number,
266
- targetBoostRatio: number,
267
- targetRepayRatio: number,
268
- boostEnabled: boolean,
269
- ) {
270
- let subInput = '0x';
271
-
272
- subInput = subInput.concat(new Dec(triggerRepayRatio).mul(1e16).toHex().slice(2)
273
- .padStart(32, '0'));
274
- subInput = subInput.concat(new Dec(triggerBoostRatio).mul(1e16).toHex().slice(2)
275
- .padStart(32, '0'));
276
- subInput = subInput.concat(new Dec(targetBoostRatio).mul(1e16).toHex().slice(2)
277
- .padStart(32, '0'));
278
- subInput = subInput.concat(new Dec(targetRepayRatio).mul(1e16).toHex().slice(2)
279
- .padStart(32, '0'));
280
- subInput = subInput.concat(boostEnabled ? '01' : '00');
281
-
282
- return subInput;
283
- },
284
251
  closeToAsset(
285
252
  strategyOrBundleId: number,
286
253
  isBundle: boolean = true,
@@ -441,29 +408,38 @@ export const aaveV3Encode = {
441
408
  };
442
409
 
443
410
  export const compoundV2Encode = {
444
- leverageManagement(
445
- triggerRepayRatio: number,
446
- triggerBoostRatio: number,
447
- targetBoostRatio: number,
448
- targetRepayRatio: number,
449
- boostEnabled: boolean,
411
+ leverageManagementWithoutSubProxy(
412
+ strategyOrBundleId: number,
413
+ user: EthereumAddress,
414
+ ratioState: RatioState,
415
+ targetRatio: number,
416
+ triggerRatio: number,
450
417
  ) {
451
- return subDataService.compoundV2LeverageManagementSubData.encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled);
418
+ const isBundle = true;
419
+
420
+ const subData = subDataService.compoundV2LeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState);
421
+ const triggerData = triggerService.compoundV2RatioTrigger.encode(user, triggerRatio, ratioState);
422
+
423
+ return [strategyOrBundleId, isBundle, triggerData, subData];
452
424
  },
453
425
  };
454
426
 
455
427
  export const compoundV3Encode = {
456
- leverageManagement(
428
+ leverageManagementWithoutSubProxy(
429
+ strategyOrBundleId: number,
457
430
  market: EthereumAddress,
458
431
  baseToken: EthereumAddress,
459
- triggerRepayRatio: number,
460
- triggerBoostRatio: number,
461
- targetBoostRatio: number,
462
- targetRepayRatio: number,
463
- boostEnabled: boolean,
464
- isEOA: boolean,
432
+ user: EthereumAddress,
433
+ ratioState: RatioState,
434
+ targetRatio: number,
435
+ triggerRatio: number,
465
436
  ) {
466
- return subDataService.compoundV3LeverageManagementSubData.encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA);
437
+ const isBundle = true;
438
+
439
+ const subData = subDataService.compoundV3LeverageManagementSubDataWithoutSubProxy.encode(market, baseToken, targetRatio, ratioState);
440
+ const triggerData = triggerService.compoundV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
441
+
442
+ return [strategyOrBundleId, isBundle, triggerData, subData];
467
443
  },
468
444
  leverageManagementOnPrice(
469
445
  strategyOrBundleId: number,
@@ -503,21 +479,6 @@ export const compoundV3Encode = {
503
479
  },
504
480
  };
505
481
 
506
- export const compoundV3L2Encode = {
507
- leverageManagement(
508
- market: EthereumAddress,
509
- baseToken: EthereumAddress,
510
- triggerRepayRatio: number,
511
- triggerBoostRatio: number,
512
- targetBoostRatio: number,
513
- targetRepayRatio: number,
514
- boostEnabled: boolean,
515
- isEOA: boolean = false,
516
- ) {
517
- return subDataService.compoundV3L2LeverageManagementSubData.encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA);
518
- },
519
- };
520
-
521
482
  export const morphoAaveV2Encode = {
522
483
  leverageManagement(
523
484
  triggerRepayRatio: number,
@@ -547,40 +508,28 @@ export const exchangeEncode = {
547
508
 
548
509
  return [strategyId, false, triggerData, subData];
549
510
  },
550
- limitOrder(
511
+ limitOrderWithoutSubProxy(
551
512
  fromToken: EthereumAddress,
552
513
  toToken: EthereumAddress,
553
514
  amount: string,
554
515
  targetPrice: string,
555
516
  goodUntil: string | number,
556
517
  orderType: OrderType,
518
+ fromTokenDecimals: number,
519
+ toTokenDecimals: number,
520
+ network: ChainId,
557
521
  ) {
558
- return subDataService.exchangeLimitOrderSubData.encode(fromToken, toToken, amount, targetPrice, goodUntil, orderType);
522
+ requireAddresses([fromToken, toToken]);
523
+ const subData = subDataService.exchangeLimitOrderSubDataWithoutSubProxy.encode(fromToken, toToken, amount);
524
+ const triggerData = triggerService.exchangeOffchainPriceTrigger.encode(targetPrice, Number(goodUntil), orderType, fromTokenDecimals, toTokenDecimals);
525
+
526
+ const strategyId = STRATEGY_IDS[network].EXCHANGE_LIMIT_ORDER;
527
+
528
+ return [strategyId, false, triggerData, subData];
559
529
  },
560
530
  };
561
531
 
562
532
  export const sparkEncode = {
563
- leverageManagement(
564
- triggerRepayRatio: number,
565
- triggerBoostRatio: number,
566
- targetBoostRatio: number,
567
- targetRepayRatio: number,
568
- boostEnabled: boolean,
569
- ) {
570
- let subInput = '0x';
571
-
572
- subInput = subInput.concat(new Dec(triggerRepayRatio).mul(1e16).toHex().slice(2)
573
- .padStart(32, '0'));
574
- subInput = subInput.concat(new Dec(triggerBoostRatio).mul(1e16).toHex().slice(2)
575
- .padStart(32, '0'));
576
- subInput = subInput.concat(new Dec(targetBoostRatio).mul(1e16).toHex().slice(2)
577
- .padStart(32, '0'));
578
- subInput = subInput.concat(new Dec(targetRepayRatio).mul(1e16).toHex().slice(2)
579
- .padStart(32, '0'));
580
- subInput = subInput.concat(boostEnabled ? '01' : '00');
581
-
582
- return subInput;
583
- },
584
533
  leverageManagementOnPrice(
585
534
  strategyOrBundleId: number,
586
535
  isBundle: boolean = true,
@@ -642,6 +591,27 @@ export const sparkEncode = {
642
591
 
643
592
  return [strategyOrBundleId, isBundle, triggerData, subData];
644
593
  },
594
+ collateralSwitch(
595
+ strategyOrBundleId: number,
596
+ fromAsset: EthereumAddress,
597
+ fromAssetId: number,
598
+ toAsset: EthereumAddress,
599
+ toAssetId: number,
600
+ marketAddr: EthereumAddress,
601
+ amountToSwitch: string,
602
+ baseTokenAddress: EthereumAddress,
603
+ quoteTokenAddress: EthereumAddress,
604
+ price: number,
605
+ state: RatioState,
606
+ ) {
607
+ const isBundle = false;
608
+
609
+ const subDataEncoded = subDataService.sparkCollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
610
+ const triggerDataEncoded = triggerService.sparkQuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
611
+
612
+ return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
613
+ },
614
+
645
615
  };
646
616
 
647
617
  export const crvUSDEncode = {
@@ -569,6 +569,131 @@ describe('Feature: subDataService.ts', () => {
569
569
  });
570
570
  });
571
571
 
572
+ describe('When testing subDataService.sparkCollateralSwitchSubData', () => {
573
+ describe('encode()', () => {
574
+ const examples: Array<[SubData, [fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, useOnBehalf?: boolean]]> = [
575
+ // WETH -> cbBTC
576
+ [
577
+ [
578
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
579
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
580
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
581
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
582
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
583
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
584
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
585
+ ],
586
+ [
587
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
588
+ 0,
589
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
590
+ 7,
591
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
592
+ '10000000000000000000', // 10 WETH
593
+ false,
594
+ ]
595
+ ],
596
+ // cbBTC -> WETH (MaxUint256)
597
+ [
598
+ [
599
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
600
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
601
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
602
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
603
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
604
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
605
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
606
+ ],
607
+ [
608
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
609
+ 7,
610
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
611
+ 0,
612
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
613
+ MAXUINT,
614
+ ]
615
+ ],
616
+ // WETH -> cbBTC (5 WETH)
617
+ [
618
+ [
619
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
620
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
621
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
622
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
623
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
624
+ '0x0000000000000000000000000000000000000000000000004563918244f40000',
625
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
626
+ ],
627
+ [
628
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
629
+ 0,
630
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
631
+ 7,
632
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
633
+ '5000000000000000000', // 5 WETH
634
+ ]
635
+ ],
636
+ ];
637
+
638
+ examples.forEach(([expected, actual]) => {
639
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
640
+ expect(subDataService.sparkCollateralSwitchSubData.encode(...actual)).to.eql(expected);
641
+ });
642
+ });
643
+ });
644
+
645
+ describe('decode()', () => {
646
+ const examples: Array<[{ fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string }, SubData]> = [
647
+ // WETH -> cbBTC
648
+ [
649
+ {
650
+ fromAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
651
+ fromAssetId: 0,
652
+ toAsset: web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
653
+ toAssetId: 7,
654
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
655
+ amountToSwitch: '10000000000000000000',
656
+ },
657
+ [
658
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
659
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
660
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
661
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
662
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
663
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
664
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
665
+ ],
666
+ ],
667
+ // cbBTC -> WETH (MaxUint256)
668
+ [
669
+ {
670
+ fromAsset: web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
671
+ fromAssetId: 7,
672
+ toAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
673
+ toAssetId: 0,
674
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
675
+ amountToSwitch: MAXUINT,
676
+ },
677
+ [
678
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
679
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
680
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
681
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
682
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
683
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
684
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
685
+ ],
686
+ ],
687
+ ];
688
+
689
+ examples.forEach(([expected, actual]) => {
690
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
691
+ expect(subDataService.sparkCollateralSwitchSubData.decode(actual)).to.eql(expected);
692
+ });
693
+ });
694
+ });
695
+ });
696
+
572
697
  describe('When testing subDataService.compoundV2LeverageManagementSubData', () => {
573
698
  describe('encode()', () => {
574
699
  const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
@@ -1283,54 +1408,6 @@ describe('Feature: subDataService.ts', () => {
1283
1408
  });
1284
1409
  });
1285
1410
 
1286
- describe('When testing subDataService.compoundV3L2LeverageManagementSubData', () => {
1287
- describe('encode()', () => {
1288
- const examples: Array<[
1289
- string,
1290
- [market: EthereumAddress, baseToken: EthereumAddress, triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean, isEOA: boolean],
1291
- ]> = [
1292
- [
1293
- '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e00000100',
1294
- [web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 190, true, false]
1295
- ],
1296
- [
1297
- '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee00000000',
1298
- [web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 110, false, false]
1299
- ],
1300
- ];
1301
-
1302
- examples.forEach(([expected, actual]) => {
1303
- it(`Given ${actual} should return expected value: ${expected}`, () => {
1304
- expect(subDataService.compoundV3L2LeverageManagementSubData.encode(...actual)).to.eql(expected);
1305
- });
1306
- });
1307
- });
1308
- describe('decode()', () => {
1309
- const examples: Array<[{ targetRatio: number }, SubData]> = [
1310
- [
1311
- { targetRatio: 200 },
1312
- [
1313
- '0x0000000000000000000000000313d212133AFaB8F2B829B1066c7E43cAd94E2c', '0x0000000000000000000000000213d212133AFaB8F2B829B1066c7E43cAd94E2c',
1314
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1315
- ],
1316
- ],
1317
- [
1318
- { targetRatio: 123 },
1319
- [
1320
- '0x0000000000000000000000000313d212133AFaB8F2B829B1066c7E43cAd94E2c', '0x0000000000000000000000000413d212133AFaB8F2B829B1066c7E43cAd94E2c',
1321
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
1322
- ],
1323
- ],
1324
- ];
1325
-
1326
- examples.forEach(([expected, actual]) => {
1327
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1328
- expect(subDataService.compoundV3L2LeverageManagementSubData.decode(actual)).to.eql(expected);
1329
- });
1330
- });
1331
- });
1332
- });
1333
-
1334
1411
  describe('When testing subDataService.morphoBlueLeverageManagementSubData', () => {
1335
1412
  describe('encode()', () => {
1336
1413
  const examples: Array<[
@@ -207,6 +207,30 @@ export const liquityLeverageManagementSubData = {
207
207
  return { targetRatio };
208
208
  },
209
209
  };
210
+ export const liquityLeverageManagementSubDataWithoutSubProxy = {
211
+ encode(
212
+ targetRatio: number,
213
+ ratioState: RatioState,
214
+ ): SubData {
215
+ const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
216
+ const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
217
+
218
+ const isRepay = ratioState === RatioState.UNDER;
219
+ const collActionType = isRepay ? CollActionType.WITHDRAW : CollActionType.SUPPLY;
220
+ const debtActionType = isRepay ? DebtActionType.PAYBACK : DebtActionType.BORROW;
221
+
222
+ const collActionTypeEncoded = AbiCoder.encodeParameter('uint8', collActionType);
223
+ const debtActionTypeEncoded = AbiCoder.encodeParameter('uint8', debtActionType);
224
+
225
+ return [encodedRatioState, encodedTargetRatio, collActionTypeEncoded, debtActionTypeEncoded];
226
+ },
227
+ decode(subData: SubData): { targetRatio: number, ratioState: RatioState } {
228
+ const ratioState = AbiCoder.decodeParameter('uint8', subData[0]) as any as RatioState;
229
+ const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[1]) as any as string);
230
+
231
+ return { targetRatio, ratioState };
232
+ },
233
+ };
210
234
  export const liquityCloseSubData = {
211
235
  encode(
212
236
  closeToAssetAddr: EthereumAddress,
@@ -510,6 +534,33 @@ export const aaveV2LeverageManagementSubData = {
510
534
  return { targetRatio };
511
535
  },
512
536
  };
537
+ export const aaveV2LeverageManagementSubDataWithoutSubProxy = {
538
+ encode(
539
+ market: EthereumAddress,
540
+ targetRatio: number,
541
+ ratioState: RatioState,
542
+ ): SubData {
543
+ const encodedMarket = AbiCoder.encodeParameter('address', market);
544
+ const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
545
+ const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
546
+
547
+ const isBoost = ratioState === RatioState.OVER;
548
+
549
+ if (isBoost) {
550
+ const enableAsCollEncoded = AbiCoder.encodeParameter('uint256', 1);
551
+ return [encodedMarket, encodedTargetRatio, encodedRatioState, enableAsCollEncoded];
552
+ }
553
+
554
+ return [encodedMarket, encodedTargetRatio, encodedRatioState];
555
+ },
556
+ decode(subData: SubData): { market: EthereumAddress, targetRatio: number, ratioState: RatioState } {
557
+ const market = AbiCoder.decodeParameter('address', subData[0]) as any as EthereumAddress;
558
+ const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[1]) as any as string);
559
+ const ratioState = AbiCoder.decodeParameter('uint8', subData[2]) as any as RatioState;
560
+
561
+ return { market, targetRatio, ratioState };
562
+ },
563
+ };
513
564
 
514
565
  /**
515
566
  ___ ___ ____ ____ _______ ____ ____ ____
@@ -997,6 +1048,30 @@ export const compoundV2LeverageManagementSubData = {
997
1048
  return { targetRatio };
998
1049
  },
999
1050
  };
1051
+ export const compoundV2LeverageManagementSubDataWithoutSubProxy = {
1052
+ encode(
1053
+ targetRatio: number,
1054
+ ratioState: RatioState,
1055
+ ): SubData {
1056
+ const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
1057
+ const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
1058
+
1059
+ const isBoost = ratioState === RatioState.OVER;
1060
+
1061
+ if (isBoost) {
1062
+ const enableAsCollEncoded = AbiCoder.encodeParameter('uint256', 1);
1063
+ return [encodedTargetRatio, encodedRatioState, enableAsCollEncoded];
1064
+ }
1065
+
1066
+ return [encodedTargetRatio, encodedRatioState];
1067
+ },
1068
+ decode(subData: SubData): { targetRatio: number, ratioState: RatioState } {
1069
+ const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[0]) as any as string);
1070
+ const ratioState = AbiCoder.decodeParameter('uint8', subData[1]) as any as RatioState;
1071
+
1072
+ return { targetRatio, ratioState };
1073
+ },
1074
+ };
1000
1075
 
1001
1076
  /**
1002
1077
  ______ ______ .___ ___. .______ ____ ____ ____
@@ -1035,39 +1110,28 @@ export const compoundV3LeverageManagementSubData = {
1035
1110
  return { targetRatio };
1036
1111
  },
1037
1112
  };
1038
- export const compoundV3L2LeverageManagementSubData = {
1113
+ export const compoundV3LeverageManagementSubDataWithoutSubProxy = {
1039
1114
  encode(
1040
1115
  market: EthereumAddress,
1041
1116
  baseToken: EthereumAddress,
1042
- triggerRepayRatio: number,
1043
- triggerBoostRatio: number,
1044
- targetBoostRatio: number,
1045
- targetRepayRatio: number,
1046
- boostEnabled: boolean,
1047
- isEOA: boolean,
1048
- ): string {
1049
- let subInput = '0x';
1050
-
1051
- subInput = subInput.concat(market.slice(2));
1052
- subInput = subInput.concat(baseToken.slice(2));
1053
- subInput = subInput.concat(new Dec(triggerRepayRatio).mul(1e16).toHex().slice(2)
1054
- .padStart(32, '0'));
1055
- subInput = subInput.concat(new Dec(triggerBoostRatio).mul(1e16).toHex().slice(2)
1056
- .padStart(32, '0'));
1057
- subInput = subInput.concat(new Dec(targetBoostRatio).mul(1e16).toHex().slice(2)
1058
- .padStart(32, '0'));
1059
- subInput = subInput.concat(new Dec(targetRepayRatio).mul(1e16).toHex().slice(2)
1060
- .padStart(32, '0'));
1061
- subInput = subInput.concat(boostEnabled ? '01' : '00');
1062
- subInput = subInput.concat(isEOA ? '01' : '00');
1063
-
1064
- return subInput;
1117
+ targetRatio: number,
1118
+ ratioState: RatioState,
1119
+ ): SubData {
1120
+ const encodedMarket = AbiCoder.encodeParameter('address', market);
1121
+ const encodedBaseToken = AbiCoder.encodeParameter('address', baseToken);
1122
+ const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
1123
+ const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
1124
+ return [encodedMarket, encodedBaseToken, encodedRatioState, encodedTargetRatio];
1065
1125
  },
1066
- decode(subData: SubData): { targetRatio: number } {
1067
- const ratioWei = AbiCoder.decodeParameter('uint256', subData[3]) as any as string;
1068
- const targetRatio = weiToRatioPercentage(ratioWei);
1126
+ decode(subData: SubData): { market: EthereumAddress, baseToken: EthereumAddress, targetRatio: number, ratioState: RatioState } {
1127
+ const market = AbiCoder.decodeParameter('address', subData[0]) as any as EthereumAddress;
1128
+ const baseToken = AbiCoder.decodeParameter('address', subData[1]) as any as EthereumAddress;
1129
+ const ratioState = AbiCoder.decodeParameter('uint8', subData[2]) as any as RatioState;
1130
+ const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[3]) as any as string);
1069
1131
 
1070
- return { targetRatio };
1132
+ return {
1133
+ market, baseToken, targetRatio, ratioState,
1134
+ };
1071
1135
  },
1072
1136
  };
1073
1137
  export const compoundV3LeverageManagementOnPriceSubData = {
@@ -1205,6 +1269,21 @@ export const exchangeLimitOrderSubData = {
1205
1269
  return { fromToken, toToken, amount };
1206
1270
  },
1207
1271
  };
1272
+ export const exchangeLimitOrderSubDataWithoutSubProxy = {
1273
+ encode(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string): SubData {
1274
+ return [
1275
+ AbiCoder.encodeParameter('address', fromToken),
1276
+ AbiCoder.encodeParameter('address', toToken),
1277
+ AbiCoder.encodeParameter('uint256', amount),
1278
+ ];
1279
+ },
1280
+ decode: (subData: SubData, chainId: ChainId) => {
1281
+ const fromToken = AbiCoder.decodeParameter('address', subData[0])!.toString();
1282
+ const toToken = AbiCoder.decodeParameter('address', subData[1])!.toString();
1283
+ const amount = assetAmountInEth(AbiCoder.decodeParameter('uint256', subData[2])!.toString(), getAssetInfoByAddress(fromToken, chainId).symbol);
1284
+ return { fromToken, toToken, amount };
1285
+ },
1286
+ };
1208
1287
 
1209
1288
  /**
1210
1289
  _______..______ ___ .______ __ ___
@@ -1330,6 +1409,55 @@ export const sparkLeverageManagementOnPriceSubData = {
1330
1409
  };
1331
1410
  },
1332
1411
  };
1412
+ export const sparkCollateralSwitchSubData = {
1413
+ encode(
1414
+ fromAsset: EthereumAddress,
1415
+ fromAssetId: number,
1416
+ toAsset: EthereumAddress,
1417
+ toAssetId: number,
1418
+ marketAddr: EthereumAddress,
1419
+ amountToSwitch: string,
1420
+ useOnBehalf: boolean = false,
1421
+ ): SubData {
1422
+ const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
1423
+ const encodedFromAssetId = AbiCoder.encodeParameter('uint8', fromAssetId);
1424
+ const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
1425
+ const encodedToAssetId = AbiCoder.encodeParameter('uint8', toAssetId);
1426
+ const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
1427
+ const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
1428
+ const encodedUseOnBehalf = AbiCoder.encodeParameter('bool', useOnBehalf);
1429
+
1430
+ return [
1431
+ encodedFromAsset,
1432
+ encodedFromAssetId,
1433
+ encodedToAsset,
1434
+ encodedToAssetId,
1435
+ encodedMarketAddr,
1436
+ encodedAmountToSwitch,
1437
+ encodedUseOnBehalf,
1438
+ ];
1439
+ },
1440
+ decode(subData: SubData): {
1441
+ fromAsset: EthereumAddress,
1442
+ fromAssetId: number,
1443
+ toAsset: EthereumAddress,
1444
+ toAssetId: number,
1445
+ marketAddr: EthereumAddress,
1446
+ amountToSwitch: string,
1447
+ } {
1448
+ const fromAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
1449
+ const fromAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
1450
+ const toAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
1451
+ const toAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
1452
+ const marketAddr = AbiCoder.decodeParameter('address', subData[4]) as unknown as EthereumAddress;
1453
+ const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]) as unknown as string;
1454
+
1455
+ return {
1456
+ fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
1457
+ };
1458
+ },
1459
+ };
1460
+
1333
1461
 
1334
1462
  /**
1335
1463
  ______ .______ ____ ____ __ __ _______. _______