@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.
- package/cjs/constants/index.js +90 -0
- package/cjs/services/strategiesService.js +48 -1
- package/cjs/services/strategySubService.d.ts +2 -0
- package/cjs/services/strategySubService.js +13 -0
- package/cjs/services/strategySubService.test.js +108 -0
- package/cjs/services/subDataService.d.ts +18 -0
- package/cjs/services/subDataService.js +48 -1
- package/cjs/services/subDataService.test.js +124 -48
- package/cjs/services/triggerService.d.ts +33 -0
- package/cjs/services/triggerService.js +62 -1
- package/cjs/services/triggerService.test.js +211 -0
- package/cjs/types/enums.d.ts +28 -5
- package/cjs/types/enums.js +23 -0
- package/cjs/types/index.d.ts +17 -1
- package/esm/constants/index.js +90 -0
- package/esm/services/strategiesService.js +48 -1
- package/esm/services/strategySubService.d.ts +2 -0
- package/esm/services/strategySubService.js +13 -0
- package/esm/services/strategySubService.test.js +109 -1
- package/esm/services/subDataService.d.ts +18 -0
- package/esm/services/subDataService.js +47 -0
- package/esm/services/subDataService.test.js +124 -48
- package/esm/services/triggerService.d.ts +33 -0
- package/esm/services/triggerService.js +61 -0
- package/esm/services/triggerService.test.js +212 -1
- package/esm/types/enums.d.ts +28 -5
- package/esm/types/enums.js +23 -0
- package/esm/types/index.d.ts +17 -1
- package/package.json +2 -2
- package/src/constants/index.ts +90 -1
- package/src/services/strategiesService.ts +62 -1
- package/src/services/strategySubService.test.ts +115 -1
- package/src/services/strategySubService.ts +33 -0
- package/src/services/subDataService.test.ts +128 -73
- package/src/services/subDataService.ts +73 -0
- package/src/services/triggerService.test.ts +229 -1
- package/src/services/triggerService.ts +83 -0
- package/src/types/enums.ts +23 -0
- package/src/types/index.ts +22 -1
|
@@ -4,7 +4,7 @@ import { otherAddresses } from '@defisaver/sdk';
|
|
|
4
4
|
import { getAssetInfo } from '@defisaver/tokens';
|
|
5
5
|
import * as web3Utils from 'web3-utils';
|
|
6
6
|
|
|
7
|
-
import { Bundles, ChainId, OrderType, RatioState, Strategies } from '../types/enums';
|
|
7
|
+
import { Bundles, ChainId, CloseToAssetType, OrderType, RatioState, Strategies } from '../types/enums';
|
|
8
8
|
import type { EthereumAddress, StrategyOrBundleIds, SubData, TriggerData } from '../types';
|
|
9
9
|
|
|
10
10
|
import '../configuration';
|
|
@@ -688,6 +688,120 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
688
688
|
});
|
|
689
689
|
});
|
|
690
690
|
});
|
|
691
|
+
describe('leverageManagementOnPrice()', () => {
|
|
692
|
+
const examples: Array<[
|
|
693
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
694
|
+
[strategyOrBundleId: number, market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, targetRatio: number, price: number, priceState: RatioState]
|
|
695
|
+
]> = [
|
|
696
|
+
[
|
|
697
|
+
[
|
|
698
|
+
Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE,
|
|
699
|
+
true,
|
|
700
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000002e90edd0000000000000000000000000000000000000000000000000000000000000000001'],
|
|
701
|
+
[
|
|
702
|
+
'0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
|
|
703
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
704
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
705
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000'
|
|
706
|
+
],
|
|
707
|
+
],
|
|
708
|
+
[
|
|
709
|
+
Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE,
|
|
710
|
+
web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
|
|
711
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
712
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
713
|
+
200,
|
|
714
|
+
2000,
|
|
715
|
+
RatioState.UNDER,
|
|
716
|
+
],
|
|
717
|
+
],
|
|
718
|
+
[
|
|
719
|
+
[
|
|
720
|
+
Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE,
|
|
721
|
+
true,
|
|
722
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000045d964b8000000000000000000000000000000000000000000000000000000000000000000'],
|
|
723
|
+
[
|
|
724
|
+
'0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
|
|
725
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
726
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
727
|
+
'0x0000000000000000000000000000000000000000000000001a5e27eef13e0000'
|
|
728
|
+
],
|
|
729
|
+
],
|
|
730
|
+
[
|
|
731
|
+
Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE,
|
|
732
|
+
web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
|
|
733
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
734
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
735
|
+
190,
|
|
736
|
+
3000,
|
|
737
|
+
RatioState.OVER,
|
|
738
|
+
],
|
|
739
|
+
]
|
|
740
|
+
];
|
|
741
|
+
examples.forEach(([expected, actual]) => {
|
|
742
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
743
|
+
expect(compoundV3Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
744
|
+
});
|
|
745
|
+
});
|
|
746
|
+
});
|
|
747
|
+
describe('closeOnPrice()', () => {
|
|
748
|
+
const examples: Array<[
|
|
749
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
750
|
+
[strategyOrBundleId: number, market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, stopLossPrice: number, stopLossType: CloseToAssetType, takeProfitPrice: number, takeProfitType: CloseToAssetType]
|
|
751
|
+
]> = [
|
|
752
|
+
[
|
|
753
|
+
[
|
|
754
|
+
Bundles.MainnetIds.COMP_V3_SW_CLOSE,
|
|
755
|
+
true,
|
|
756
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
757
|
+
[
|
|
758
|
+
'0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
|
|
759
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
760
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
761
|
+
'0x0000000000000000000000000000000000000000000000000000000000000006'
|
|
762
|
+
],
|
|
763
|
+
],
|
|
764
|
+
[
|
|
765
|
+
Bundles.MainnetIds.COMP_V3_SW_CLOSE,
|
|
766
|
+
web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
|
|
767
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
768
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
769
|
+
1500,
|
|
770
|
+
CloseToAssetType.DEBT,
|
|
771
|
+
4000,
|
|
772
|
+
CloseToAssetType.DEBT,
|
|
773
|
+
],
|
|
774
|
+
],
|
|
775
|
+
[
|
|
776
|
+
[
|
|
777
|
+
Bundles.MainnetIds.COMP_V3_EOA_CLOSE,
|
|
778
|
+
true,
|
|
779
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
780
|
+
[
|
|
781
|
+
'0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
|
|
782
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
783
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
784
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000'
|
|
785
|
+
],
|
|
786
|
+
],
|
|
787
|
+
[
|
|
788
|
+
Bundles.MainnetIds.COMP_V3_EOA_CLOSE,
|
|
789
|
+
web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
|
|
790
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
791
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
792
|
+
0,
|
|
793
|
+
CloseToAssetType.DEBT,
|
|
794
|
+
5000,
|
|
795
|
+
CloseToAssetType.COLLATERAL,
|
|
796
|
+
],
|
|
797
|
+
]
|
|
798
|
+
];
|
|
799
|
+
examples.forEach(([expected, actual]) => {
|
|
800
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
801
|
+
expect(compoundV3Encode.closeOnPrice(...actual)).to.eql(expected);
|
|
802
|
+
});
|
|
803
|
+
});
|
|
804
|
+
});
|
|
691
805
|
});
|
|
692
806
|
|
|
693
807
|
describe('When testing strategySubService.morphoAaveV2Encode', () => {
|
|
@@ -350,6 +350,39 @@ export const compoundV3Encode = {
|
|
|
350
350
|
) {
|
|
351
351
|
return subDataService.compoundV3LeverageManagementSubData.encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA);
|
|
352
352
|
},
|
|
353
|
+
leverageManagementOnPrice(
|
|
354
|
+
strategyOrBundleId: number,
|
|
355
|
+
market: EthereumAddress,
|
|
356
|
+
collToken: EthereumAddress,
|
|
357
|
+
baseToken: EthereumAddress,
|
|
358
|
+
targetRatio: number,
|
|
359
|
+
price: number,
|
|
360
|
+
priceState: RatioState,
|
|
361
|
+
) {
|
|
362
|
+
const isBundle = true;
|
|
363
|
+
const subDataEncoded = subDataService.compoundV3LeverageManagementOnPriceSubData.encode(market, collToken, baseToken, targetRatio);
|
|
364
|
+
const triggerDataEncoded = triggerService.compoundV3PriceTrigger.encode(market, collToken, price, priceState);
|
|
365
|
+
|
|
366
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
367
|
+
},
|
|
368
|
+
closeOnPrice(
|
|
369
|
+
strategyOrBundleId: number,
|
|
370
|
+
market: EthereumAddress,
|
|
371
|
+
collToken: EthereumAddress,
|
|
372
|
+
baseToken: EthereumAddress,
|
|
373
|
+
stopLossPrice: number = 0,
|
|
374
|
+
stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
|
|
375
|
+
takeProfitPrice: number = 0,
|
|
376
|
+
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
377
|
+
) {
|
|
378
|
+
const isBundle = true;
|
|
379
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
380
|
+
|
|
381
|
+
const subDataEncoded = subDataService.compoundV3CloseSubData.encode(market, collToken, baseToken, closeType);
|
|
382
|
+
const triggerDataEncoded = triggerService.compoundV3PriceRangeTrigger.encode(market, collToken, stopLossPrice, takeProfitPrice);
|
|
383
|
+
|
|
384
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
385
|
+
},
|
|
353
386
|
};
|
|
354
387
|
|
|
355
388
|
export const compoundV3L2Encode = {
|