@defisaver/automation-sdk 3.2.3 → 3.2.4-dev-1

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.
Files changed (39) hide show
  1. package/cjs/constants/index.js +90 -0
  2. package/cjs/services/strategiesService.js +48 -1
  3. package/cjs/services/strategySubService.d.ts +2 -0
  4. package/cjs/services/strategySubService.js +13 -0
  5. package/cjs/services/strategySubService.test.js +108 -0
  6. package/cjs/services/subDataService.d.ts +18 -0
  7. package/cjs/services/subDataService.js +48 -1
  8. package/cjs/services/subDataService.test.js +124 -48
  9. package/cjs/services/triggerService.d.ts +33 -0
  10. package/cjs/services/triggerService.js +62 -1
  11. package/cjs/services/triggerService.test.js +211 -0
  12. package/cjs/types/enums.d.ts +28 -5
  13. package/cjs/types/enums.js +23 -0
  14. package/cjs/types/index.d.ts +17 -1
  15. package/esm/constants/index.js +90 -0
  16. package/esm/services/strategiesService.js +48 -1
  17. package/esm/services/strategySubService.d.ts +2 -0
  18. package/esm/services/strategySubService.js +13 -0
  19. package/esm/services/strategySubService.test.js +109 -1
  20. package/esm/services/subDataService.d.ts +18 -0
  21. package/esm/services/subDataService.js +47 -0
  22. package/esm/services/subDataService.test.js +124 -48
  23. package/esm/services/triggerService.d.ts +33 -0
  24. package/esm/services/triggerService.js +61 -0
  25. package/esm/services/triggerService.test.js +212 -1
  26. package/esm/types/enums.d.ts +28 -5
  27. package/esm/types/enums.js +23 -0
  28. package/esm/types/index.d.ts +17 -1
  29. package/package.json +2 -2
  30. package/src/constants/index.ts +90 -1
  31. package/src/services/strategiesService.ts +62 -1
  32. package/src/services/strategySubService.test.ts +115 -1
  33. package/src/services/strategySubService.ts +33 -0
  34. package/src/services/subDataService.test.ts +128 -73
  35. package/src/services/subDataService.ts +73 -0
  36. package/src/services/triggerService.test.ts +229 -1
  37. package/src/services/triggerService.ts +83 -0
  38. package/src/types/enums.ts +23 -0
  39. package/src/types/index.ts +22 -1
@@ -3,7 +3,7 @@ import Dec from 'decimal.js';
3
3
  import { otherAddresses } from '@defisaver/sdk';
4
4
  import { getAssetInfo } from '@defisaver/tokens';
5
5
  import * as web3Utils from 'web3-utils';
6
- import { Bundles, ChainId, OrderType, RatioState, Strategies } from '../types/enums';
6
+ import { Bundles, ChainId, CloseToAssetType, OrderType, RatioState, Strategies } from '../types/enums';
7
7
  import '../configuration';
8
8
  import { aaveV2Encode, chickenBondsEncode, liquityEncode, makerEncode, aaveV3Encode, compoundV2Encode, compoundV3Encode, morphoAaveV2Encode, exchangeEncode, sparkEncode, crvUSDEncode, compoundV3L2Encode, morphoBlueEncode, } from './strategySubService';
9
9
  describe('Feature: strategySubService.ts', () => {
@@ -530,6 +530,114 @@ describe('Feature: strategySubService.ts', () => {
530
530
  });
531
531
  });
532
532
  });
533
+ describe('leverageManagementOnPrice()', () => {
534
+ const examples = [
535
+ [
536
+ [
537
+ Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE,
538
+ true,
539
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000002e90edd0000000000000000000000000000000000000000000000000000000000000000001'],
540
+ [
541
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
542
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
543
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
544
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000'
545
+ ],
546
+ ],
547
+ [
548
+ Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE,
549
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
550
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
551
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
552
+ 200,
553
+ 2000,
554
+ RatioState.UNDER,
555
+ ],
556
+ ],
557
+ [
558
+ [
559
+ Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE,
560
+ true,
561
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000045d964b8000000000000000000000000000000000000000000000000000000000000000000'],
562
+ [
563
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
564
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
565
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
566
+ '0x0000000000000000000000000000000000000000000000001a5e27eef13e0000'
567
+ ],
568
+ ],
569
+ [
570
+ Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE,
571
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
572
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
573
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
574
+ 190,
575
+ 3000,
576
+ RatioState.OVER,
577
+ ],
578
+ ]
579
+ ];
580
+ examples.forEach(([expected, actual]) => {
581
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
582
+ expect(compoundV3Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
583
+ });
584
+ });
585
+ });
586
+ describe('closeOnPrice()', () => {
587
+ const examples = [
588
+ [
589
+ [
590
+ Bundles.MainnetIds.COMP_V3_SW_CLOSE,
591
+ true,
592
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
593
+ [
594
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
595
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
596
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
597
+ '0x0000000000000000000000000000000000000000000000000000000000000006'
598
+ ],
599
+ ],
600
+ [
601
+ Bundles.MainnetIds.COMP_V3_SW_CLOSE,
602
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
603
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
604
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
605
+ 1500,
606
+ CloseToAssetType.DEBT,
607
+ 4000,
608
+ CloseToAssetType.DEBT,
609
+ ],
610
+ ],
611
+ [
612
+ [
613
+ Bundles.MainnetIds.COMP_V3_EOA_CLOSE,
614
+ true,
615
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
616
+ [
617
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
618
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
619
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
620
+ '0x0000000000000000000000000000000000000000000000000000000000000000'
621
+ ],
622
+ ],
623
+ [
624
+ Bundles.MainnetIds.COMP_V3_EOA_CLOSE,
625
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
626
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
627
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
628
+ 0,
629
+ CloseToAssetType.DEBT,
630
+ 5000,
631
+ CloseToAssetType.COLLATERAL,
632
+ ],
633
+ ]
634
+ ];
635
+ examples.forEach(([expected, actual]) => {
636
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
637
+ expect(compoundV3Encode.closeOnPrice(...actual)).to.eql(expected);
638
+ });
639
+ });
640
+ });
533
641
  });
534
642
  describe('When testing strategySubService.morphoAaveV2Encode', () => {
535
643
  describe('leverageManagement()', () => {
@@ -252,3 +252,21 @@ export declare const fluidLeverageManagementSubData: {
252
252
  targetRatio: number;
253
253
  };
254
254
  };
255
+ export declare const compoundV3LeverageManagementOnPriceSubData: {
256
+ encode(market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, targetRatio: number): string[];
257
+ decode(subData: string[]): {
258
+ market: EthereumAddress;
259
+ collToken: EthereumAddress;
260
+ baseToken: EthereumAddress;
261
+ targetRatio: number;
262
+ };
263
+ };
264
+ export declare const compoundV3CloseSubData: {
265
+ encode(market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, closeType: CloseStrategyType): string[];
266
+ decode(subData: string[]): {
267
+ market: EthereumAddress;
268
+ collToken: EthereumAddress;
269
+ baseToken: EthereumAddress;
270
+ closeType: CloseStrategyType;
271
+ };
272
+ };
@@ -661,3 +661,50 @@ export const fluidLeverageManagementSubData = {
661
661
  };
662
662
  },
663
663
  };
664
+ export const compoundV3LeverageManagementOnPriceSubData = {
665
+ encode(market, collToken, baseToken, targetRatio) {
666
+ const marketEncoded = AbiCoder.encodeParameter('address', market);
667
+ const collTokenEncoded = AbiCoder.encodeParameter('address', collToken);
668
+ const baseTokenEncoded = AbiCoder.encodeParameter('address', baseToken);
669
+ const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
670
+ return [
671
+ marketEncoded,
672
+ collTokenEncoded,
673
+ baseTokenEncoded,
674
+ targetRatioEncoded,
675
+ ];
676
+ },
677
+ decode(subData) {
678
+ const market = AbiCoder.decodeParameter('address', subData[0]);
679
+ const collToken = AbiCoder.decodeParameter('address', subData[1]);
680
+ const baseToken = AbiCoder.decodeParameter('address', subData[2]);
681
+ const weiRatio = AbiCoder.decodeParameter('uint256', subData[3]);
682
+ const targetRatio = weiToRatioPercentage(weiRatio);
683
+ return {
684
+ market, collToken, baseToken, targetRatio,
685
+ };
686
+ },
687
+ };
688
+ export const compoundV3CloseSubData = {
689
+ encode(market, collToken, baseToken, closeType) {
690
+ const marketEncoded = AbiCoder.encodeParameter('address', market);
691
+ const collTokenEncoded = AbiCoder.encodeParameter('address', collToken);
692
+ const baseTokenEncoded = AbiCoder.encodeParameter('address', baseToken);
693
+ const closeTypeEncoded = AbiCoder.encodeParameter('uint8', closeType);
694
+ return [
695
+ marketEncoded,
696
+ collTokenEncoded,
697
+ baseTokenEncoded,
698
+ closeTypeEncoded,
699
+ ];
700
+ },
701
+ decode(subData) {
702
+ const market = AbiCoder.decodeParameter('address', subData[0]);
703
+ const collToken = AbiCoder.decodeParameter('address', subData[1]);
704
+ const baseToken = AbiCoder.decodeParameter('address', subData[2]);
705
+ const closeType = AbiCoder.decodeParameter('uint8', subData[3]);
706
+ return {
707
+ market, collToken, baseToken, closeType,
708
+ };
709
+ },
710
+ };