@defisaver/automation-sdk 3.3.22-instant-twap-close-dev → 3.3.23
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/automation/private/StrategiesAutomation.d.ts +5 -1
- package/cjs/automation/private/StrategiesAutomation.js +12 -0
- package/cjs/automation/private/StrategiesAutomation.test.js +51 -0
- package/cjs/constants/index.js +40 -40
- package/cjs/services/apiSubscriptionsService.d.ts +7 -0
- package/cjs/services/apiSubscriptionsService.js +33 -0
- package/cjs/services/apiSubscriptionsService.test.d.ts +1 -0
- package/cjs/services/apiSubscriptionsService.test.js +67 -0
- package/cjs/services/strategiesService.js +8 -21
- package/cjs/services/strategiesService.test.js +0 -63
- package/cjs/services/strategySubService.d.ts +1 -1
- package/cjs/services/strategySubService.js +6 -7
- package/cjs/services/strategySubService.test.js +71 -111
- package/cjs/services/subDataService.d.ts +10 -12
- package/cjs/services/subDataService.js +30 -36
- package/cjs/services/subDataService.test.js +104 -70
- package/cjs/types/enums.d.ts +18 -18
- package/cjs/types/enums.js +10 -11
- package/cjs/types/index.d.ts +24 -2
- package/esm/automation/private/StrategiesAutomation.d.ts +5 -1
- package/esm/automation/private/StrategiesAutomation.js +12 -0
- package/esm/automation/private/StrategiesAutomation.test.js +51 -0
- package/esm/constants/index.js +40 -40
- package/esm/services/apiSubscriptionsService.d.ts +7 -0
- package/esm/services/apiSubscriptionsService.js +29 -0
- package/esm/services/apiSubscriptionsService.test.d.ts +1 -0
- package/esm/services/apiSubscriptionsService.test.js +65 -0
- package/esm/services/strategiesService.js +8 -21
- package/esm/services/strategiesService.test.js +1 -64
- package/esm/services/strategySubService.d.ts +1 -1
- package/esm/services/strategySubService.js +6 -7
- package/esm/services/strategySubService.test.js +71 -111
- package/esm/services/subDataService.d.ts +10 -12
- package/esm/services/subDataService.js +29 -35
- package/esm/services/subDataService.test.js +104 -70
- package/esm/types/enums.d.ts +18 -18
- package/esm/types/enums.js +10 -11
- package/esm/types/index.d.ts +24 -2
- package/package.json +1 -1
- package/src/automation/private/StrategiesAutomation.test.ts +65 -1
- package/src/automation/private/StrategiesAutomation.ts +17 -0
- package/src/constants/index.ts +40 -40
- package/src/services/apiSubscriptionsService.test.ts +73 -0
- package/src/services/apiSubscriptionsService.ts +33 -0
- package/src/services/strategiesService.test.ts +1 -79
- package/src/services/strategiesService.ts +8 -27
- package/src/services/strategySubService.test.ts +84 -125
- package/src/services/strategySubService.ts +16 -20
- package/src/services/subDataService.test.ts +108 -98
- package/src/services/subDataService.ts +40 -51
- package/src/types/enums.ts +10 -11
- package/src/types/index.ts +26 -2
|
@@ -687,68 +687,55 @@ export const aaveV3CloseGenericSubData = {
|
|
|
687
687
|
};
|
|
688
688
|
},
|
|
689
689
|
};
|
|
690
|
-
export const
|
|
690
|
+
export const aaveV3CollateralSwitchSubData = {
|
|
691
691
|
encode(
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
closeType: CloseStrategyType,
|
|
692
|
+
fromAsset: EthereumAddress,
|
|
693
|
+
fromAssetId: number,
|
|
694
|
+
toAsset: EthereumAddress,
|
|
695
|
+
toAssetId: number,
|
|
697
696
|
marketAddr: EthereumAddress,
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
slippage: string,
|
|
697
|
+
amountToSwitch: string,
|
|
698
|
+
useOnBehalf: boolean = false,
|
|
701
699
|
): SubData {
|
|
702
|
-
const
|
|
703
|
-
const
|
|
704
|
-
const
|
|
705
|
-
const
|
|
706
|
-
const
|
|
707
|
-
const
|
|
708
|
-
const
|
|
709
|
-
const encodedTsi = AbiCoder.encodeParameter('uint256', tsi);
|
|
710
|
-
const encodedSlippage = AbiCoder.encodeParameter('uint256', slippage);
|
|
700
|
+
const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
|
|
701
|
+
const encodedFromAssetId = AbiCoder.encodeParameter('uint8', fromAssetId);
|
|
702
|
+
const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
|
|
703
|
+
const encodedToAssetId = AbiCoder.encodeParameter('uint8', toAssetId);
|
|
704
|
+
const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
|
|
705
|
+
const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
|
|
706
|
+
const encodedUseOnBehalf = AbiCoder.encodeParameter('bool', useOnBehalf);
|
|
711
707
|
|
|
712
708
|
return [
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
encodedTsi,
|
|
721
|
-
encodedSlippage,
|
|
709
|
+
encodedFromAsset,
|
|
710
|
+
encodedFromAssetId,
|
|
711
|
+
encodedToAsset,
|
|
712
|
+
encodedToAssetId,
|
|
713
|
+
encodedMarketAddr,
|
|
714
|
+
encodedAmountToSwitch,
|
|
715
|
+
encodedUseOnBehalf,
|
|
722
716
|
];
|
|
723
717
|
},
|
|
724
|
-
|
|
725
718
|
decode(subData: SubData): {
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
closeType: CloseStrategyType,
|
|
719
|
+
fromAsset: EthereumAddress,
|
|
720
|
+
fromAssetId: number,
|
|
721
|
+
toAsset: EthereumAddress,
|
|
722
|
+
toAssetId: number,
|
|
731
723
|
marketAddr: EthereumAddress,
|
|
732
|
-
|
|
733
|
-
tsi: string,
|
|
734
|
-
slippage: string,
|
|
724
|
+
amountToSwitch: string,
|
|
735
725
|
} {
|
|
736
|
-
const
|
|
737
|
-
const
|
|
738
|
-
const
|
|
739
|
-
const
|
|
740
|
-
const
|
|
741
|
-
const
|
|
742
|
-
const owner = AbiCoder.decodeParameter('address', subData[6]) as unknown as EthereumAddress;
|
|
743
|
-
const tsi = AbiCoder.decodeParameter('uint256', subData[7]) as unknown as string;
|
|
744
|
-
const slippage = AbiCoder.decodeParameter('uint256', subData[8]) as unknown as string;
|
|
726
|
+
const fromAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
727
|
+
const fromAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
|
|
728
|
+
const toAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
|
|
729
|
+
const toAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
|
|
730
|
+
const marketAddr = AbiCoder.decodeParameter('address', subData[4]) as unknown as EthereumAddress;
|
|
731
|
+
const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]) as unknown as string;
|
|
745
732
|
|
|
746
733
|
return {
|
|
747
|
-
|
|
734
|
+
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
|
|
748
735
|
};
|
|
749
736
|
},
|
|
750
737
|
};
|
|
751
|
-
export const
|
|
738
|
+
export const aaveV3DebtSwitchSubData = {
|
|
752
739
|
encode(
|
|
753
740
|
fromAsset: EthereumAddress,
|
|
754
741
|
fromAssetId: number,
|
|
@@ -756,7 +743,7 @@ export const aaveV3CollateralSwitchSubData = {
|
|
|
756
743
|
toAssetId: number,
|
|
757
744
|
marketAddr: EthereumAddress,
|
|
758
745
|
amountToSwitch: string,
|
|
759
|
-
|
|
746
|
+
user: EthereumAddress,
|
|
760
747
|
): SubData {
|
|
761
748
|
const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
|
|
762
749
|
const encodedFromAssetId = AbiCoder.encodeParameter('uint8', fromAssetId);
|
|
@@ -764,7 +751,7 @@ export const aaveV3CollateralSwitchSubData = {
|
|
|
764
751
|
const encodedToAssetId = AbiCoder.encodeParameter('uint8', toAssetId);
|
|
765
752
|
const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
|
|
766
753
|
const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
|
|
767
|
-
const
|
|
754
|
+
const encodedUser = AbiCoder.encodeParameter('address', user);
|
|
768
755
|
|
|
769
756
|
return [
|
|
770
757
|
encodedFromAsset,
|
|
@@ -773,7 +760,7 @@ export const aaveV3CollateralSwitchSubData = {
|
|
|
773
760
|
encodedToAssetId,
|
|
774
761
|
encodedMarketAddr,
|
|
775
762
|
encodedAmountToSwitch,
|
|
776
|
-
|
|
763
|
+
encodedUser,
|
|
777
764
|
];
|
|
778
765
|
},
|
|
779
766
|
decode(subData: SubData): {
|
|
@@ -783,6 +770,7 @@ export const aaveV3CollateralSwitchSubData = {
|
|
|
783
770
|
toAssetId: number,
|
|
784
771
|
marketAddr: EthereumAddress,
|
|
785
772
|
amountToSwitch: string,
|
|
773
|
+
user: EthereumAddress,
|
|
786
774
|
} {
|
|
787
775
|
const fromAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
788
776
|
const fromAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
|
|
@@ -790,9 +778,10 @@ export const aaveV3CollateralSwitchSubData = {
|
|
|
790
778
|
const toAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
|
|
791
779
|
const marketAddr = AbiCoder.decodeParameter('address', subData[4]) as unknown as EthereumAddress;
|
|
792
780
|
const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]) as unknown as string;
|
|
781
|
+
const user = AbiCoder.decodeParameter('address', subData[6]) as unknown as EthereumAddress;
|
|
793
782
|
|
|
794
783
|
return {
|
|
795
|
-
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
|
|
784
|
+
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user,
|
|
796
785
|
};
|
|
797
786
|
},
|
|
798
787
|
};
|
package/src/types/enums.ts
CHANGED
|
@@ -102,24 +102,32 @@ export namespace Strategies {
|
|
|
102
102
|
AAVE_V4_COLLATERAL_SWITCH_EOA = 155,
|
|
103
103
|
SPARK_COLLATERAL_SWITCH = 156,
|
|
104
104
|
SPARK_GENERIC_FL_COLLATERAL_SWITCH = 167,
|
|
105
|
+
AAVE_V3_DEBT_SWITCH = 168,
|
|
106
|
+
AAVE_V3_DEBT_SWITCH_EOA = 169,
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
export enum OptimismIds {
|
|
108
110
|
EXCHANGE_DCA = 8,
|
|
109
111
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
110
112
|
AAVE_V3_COLLATERAL_SWITCH = 24,
|
|
113
|
+
AAVE_V3_DEBT_SWITCH = 25,
|
|
114
|
+
AAVE_V3_DEBT_SWITCH_EOA = 26,
|
|
111
115
|
}
|
|
112
116
|
|
|
113
117
|
export enum BaseIds {
|
|
114
118
|
EXCHANGE_DCA = 8,
|
|
115
119
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
116
120
|
AAVE_V3_COLLATERAL_SWITCH = 56,
|
|
121
|
+
AAVE_V3_DEBT_SWITCH = 61,
|
|
122
|
+
AAVE_V3_DEBT_SWITCH_EOA = 62,
|
|
117
123
|
}
|
|
118
124
|
|
|
119
125
|
export enum ArbitrumIds {
|
|
120
126
|
EXCHANGE_DCA = 8,
|
|
121
127
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
122
128
|
AAVE_V3_COLLATERAL_SWITCH = 50,
|
|
129
|
+
AAVE_V3_DEBT_SWITCH = 55,
|
|
130
|
+
AAVE_V3_DEBT_SWITCH_EOA = 56,
|
|
123
131
|
}
|
|
124
132
|
|
|
125
133
|
export enum Identifiers {
|
|
@@ -138,8 +146,6 @@ export namespace Strategies {
|
|
|
138
146
|
CloseOnPriceToColl = 'close-on-price-to-collateral',
|
|
139
147
|
CloseOnPrice = 'close-on-price',
|
|
140
148
|
EoaCloseOnPrice = 'eoa-close-on-price',
|
|
141
|
-
InstantCloseOnPrice = 'instant-close-on-price',
|
|
142
|
-
EoaInstantCloseOnPrice = 'eoa-instant-close-on-price',
|
|
143
149
|
TrailingStopToColl = 'trailing-stop-to-collateral',
|
|
144
150
|
TrailingStopToDebt = 'trailing-stop-to-debt',
|
|
145
151
|
Rebond = 'rebond',
|
|
@@ -156,6 +162,8 @@ export namespace Strategies {
|
|
|
156
162
|
EoaRepayOnPrice = 'eoa-repay-on-price',
|
|
157
163
|
CollateralSwitch = 'collateral-switch',
|
|
158
164
|
EoaCollateralSwitch = 'eoa-collateral-switch',
|
|
165
|
+
DebtSwitch = 'debt-switch',
|
|
166
|
+
EoaDebtSwitch = 'eoa-debt-switch',
|
|
159
167
|
LiquidationProtection = 'liquidation-protection',
|
|
160
168
|
EoaLiquidationProtection = 'liquidation-protection-eoa',
|
|
161
169
|
}
|
|
@@ -268,8 +276,6 @@ export namespace Bundles {
|
|
|
268
276
|
SPARK_EOA_BOOST_ON_PRICE = 91,
|
|
269
277
|
SPARK_EOA_CLOSE = 92,
|
|
270
278
|
SPARK_EOA_LIQUIDATION_PROTECTION = 93,
|
|
271
|
-
AAVE_V3_SW_INSTANT_CLOSE = 94,
|
|
272
|
-
AAVE_V3_EOA_INSTANT_CLOSE = 95,
|
|
273
279
|
}
|
|
274
280
|
|
|
275
281
|
export enum OptimismIds {
|
|
@@ -286,9 +292,6 @@ export namespace Bundles {
|
|
|
286
292
|
AAVE_V3_EOA_CLOSE = 10,
|
|
287
293
|
AAVE_V3_SW_LIQUIDATION_PROTECTION = 11,
|
|
288
294
|
AAVE_V3_EOA_LIQUIDATION_PROTECTION = 12,
|
|
289
|
-
// TODO -> Fix ids
|
|
290
|
-
AAVE_V3_SW_INSTANT_CLOSE = 13,
|
|
291
|
-
AAVE_V3_EOA_INSTANT_CLOSE = 14,
|
|
292
295
|
}
|
|
293
296
|
|
|
294
297
|
export enum BaseIds {
|
|
@@ -332,8 +335,6 @@ export namespace Bundles {
|
|
|
332
335
|
MORPHO_BLUE_EOA_REPAY_ON_PRICE = 40,
|
|
333
336
|
MORPHO_BLUE_EOA_CLOSE = 41,
|
|
334
337
|
MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION = 42,
|
|
335
|
-
AAVE_V3_SW_INSTANT_CLOSE = 43,
|
|
336
|
-
AAVE_V3_EOA_INSTANT_CLOSE = 44,
|
|
337
338
|
}
|
|
338
339
|
|
|
339
340
|
export enum ArbitrumIds {
|
|
@@ -377,7 +378,5 @@ export namespace Bundles {
|
|
|
377
378
|
MORPHO_BLUE_EOA_BOOST_ON_PRICE = 37,
|
|
378
379
|
MORPHO_BLUE_EOA_REPAY_ON_PRICE = 38,
|
|
379
380
|
MORPHO_BLUE_EOA_CLOSE = 39,
|
|
380
|
-
AAVE_V3_SW_INSTANT_CLOSE = 40,
|
|
381
|
-
AAVE_V3_EOA_INSTANT_CLOSE = 41,
|
|
382
381
|
}
|
|
383
382
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type Web3 from 'web3';
|
|
2
2
|
import type { AbiItem } from 'web3-utils';
|
|
3
3
|
import type { BaseContract, BlockType } from './contracts/generated/types';
|
|
4
|
-
import type {
|
|
4
|
+
import type { StrategyModel } from './contracts/generated/SubStorage';
|
|
5
5
|
import type {
|
|
6
6
|
ChainId, Strategies, Bundles, ProtocolIdentifiers,
|
|
7
7
|
RatioState,
|
|
@@ -72,6 +72,22 @@ interface _SubscriptionOptions {
|
|
|
72
72
|
|
|
73
73
|
export type SubscriptionOptions = Partial<_SubscriptionOptions>;
|
|
74
74
|
|
|
75
|
+
/** Subscription record as returned by the automation API (GET /v1/subscriptions) */
|
|
76
|
+
export interface ApiSubscriptionRecord {
|
|
77
|
+
id: number,
|
|
78
|
+
wallet: EthereumAddress,
|
|
79
|
+
wallet_type: string,
|
|
80
|
+
is_enabled: boolean,
|
|
81
|
+
is_bundle: boolean,
|
|
82
|
+
strategy_or_bundle_id: number,
|
|
83
|
+
strategy_ids: number[],
|
|
84
|
+
sub_data_hash: string,
|
|
85
|
+
trigger_data: string[],
|
|
86
|
+
sub_data: string[],
|
|
87
|
+
block_number: number,
|
|
88
|
+
additional_triggers: string[] | null,
|
|
89
|
+
}
|
|
90
|
+
|
|
75
91
|
export declare namespace Interfaces {
|
|
76
92
|
interface ProtocolBase {
|
|
77
93
|
id: ProtocolIdentifiers.StrategiesAutomation | ProtocolIdentifiers.LegacyAutomation,
|
|
@@ -369,10 +385,18 @@ export type StrategyOrBundleIds =
|
|
|
369
385
|
| typeof Bundles.ArbitrumIds[keyof typeof Bundles.ArbitrumIds]
|
|
370
386
|
| typeof Bundles.BaseIds[keyof typeof Bundles.BaseIds];
|
|
371
387
|
|
|
388
|
+
/** Fields of the Subscribe event that parsing relies on */
|
|
389
|
+
export interface SubscriptionEventData {
|
|
390
|
+
subId: string,
|
|
391
|
+
proxy: EthereumAddress,
|
|
392
|
+
subHash: string,
|
|
393
|
+
subStruct: StrategyModel.StrategySubStructOutputStruct,
|
|
394
|
+
}
|
|
395
|
+
|
|
372
396
|
export interface ParseData {
|
|
373
397
|
chainId: ChainId,
|
|
374
398
|
blockNumber: BlockNumber,
|
|
375
|
-
subscriptionEventData:
|
|
399
|
+
subscriptionEventData: SubscriptionEventData,
|
|
376
400
|
strategiesSubsData: StrategyModel.StoredSubDataStructOutputStruct,
|
|
377
401
|
}
|
|
378
402
|
|