@defisaver/automation-sdk 3.3.15-liq-prot-3-dev → 3.3.16-dev-13082-morpho-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.
- package/cjs/constants/index.js +51 -111
- package/cjs/index.d.ts +2 -2
- package/cjs/index.js +2 -5
- package/cjs/services/strategiesService.js +13 -157
- package/cjs/services/strategySubService.d.ts +21 -18
- package/cjs/services/strategySubService.js +74 -78
- package/cjs/services/strategySubService.test.js +216 -3
- package/cjs/services/subDataService.d.ts +20 -70
- package/cjs/services/subDataService.js +79 -23
- package/cjs/services/subDataService.test.js +302 -17
- package/cjs/services/triggerService.test.js +60 -0
- package/cjs/services/utils.d.ts +1 -2
- package/cjs/services/utils.js +1 -14
- package/cjs/types/enums.d.ts +17 -33
- package/cjs/types/enums.js +14 -30
- package/esm/constants/index.js +51 -111
- package/esm/index.d.ts +2 -2
- package/esm/index.js +2 -5
- package/esm/services/strategiesService.js +13 -157
- package/esm/services/strategySubService.d.ts +21 -18
- package/esm/services/strategySubService.js +73 -78
- package/esm/services/strategySubService.test.js +214 -4
- package/esm/services/subDataService.d.ts +20 -70
- package/esm/services/subDataService.js +77 -21
- package/esm/services/subDataService.test.js +300 -18
- package/esm/services/triggerService.test.js +61 -1
- package/esm/services/utils.d.ts +1 -2
- package/esm/services/utils.js +1 -13
- package/esm/types/enums.d.ts +17 -33
- package/esm/types/enums.js +14 -30
- package/package.json +1 -1
- package/src/constants/index.ts +52 -113
- package/src/index.ts +6 -22
- package/src/services/strategiesService.ts +13 -221
- package/src/services/strategySubService.test.ts +275 -3
- package/src/services/strategySubService.ts +121 -173
- package/src/services/subDataService.test.ts +324 -18
- package/src/services/subDataService.ts +106 -42
- package/src/services/triggerService.test.ts +69 -0
- package/src/services/utils.test.ts +1 -1
- package/src/services/utils.ts +1 -15
- package/src/types/enums.ts +16 -30
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
import { Bundles, ChainId, CloseToAssetType, RatioState, Strategies } from '../types/enums';
|
|
2
|
-
import type { EthereumAddress, StrategyOrBundleIds } from '../types';
|
|
3
1
|
import type { OrderType } from '../types/enums';
|
|
2
|
+
import { CloseToAssetType, Bundles, ChainId, RatioState, Strategies } from '../types/enums';
|
|
3
|
+
import type { EthereumAddress, StrategyOrBundleIds } from '../types';
|
|
4
4
|
export declare const makerEncode: {
|
|
5
5
|
repayFromSavings(bundleId: StrategyOrBundleIds, vaultId: number, triggerRepayRatio: number, targetRepayRatio: number, isBundle?: boolean, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds | Strategies.OptimismIds | Strategies.ArbitrumIds | Strategies.BaseIds | Bundles.MainnetIds | Bundles.OptimismIds | Bundles.ArbitrumIds | Bundles.BaseIds)[];
|
|
6
6
|
closeOnPrice(vaultId: number, ratioState: RatioState, price: string, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
|
|
7
7
|
trailingStop(vaultId: number, triggerPercentage: number, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, roundId: number, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
|
|
8
|
-
|
|
9
|
-
liquidationProtection(vaultId: number, triggerRatio: number, targetRatio: number, ratioState: RatioState, daiAddr?: EthereumAddress): (boolean | string[] | Bundles.MainnetIds)[];
|
|
8
|
+
leverageManagementWithoutSubProxy(vaultId: number, triggerRatio: number, targetRatio: number, ratioState: RatioState, isBoost: boolean, daiAddr?: EthereumAddress): (boolean | string[] | Bundles.MainnetIds)[];
|
|
10
9
|
};
|
|
11
10
|
export declare const liquityEncode: {
|
|
12
11
|
closeOnPrice(priceOverOrUnder: RatioState, price: string, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
|
|
13
12
|
trailingStop(triggerPercentage: number, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, roundId: number, chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
|
|
14
13
|
paybackFromChickenBondStrategySub(proxyAddress: EthereumAddress, ratio: number, sourceId: string, sourceType: number, ratioState?: RatioState): (boolean | string[] | Bundles.MainnetIds)[];
|
|
15
|
-
|
|
14
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId: number, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
16
15
|
dsrPayback(proxyAddress: EthereumAddress, triggerRatio: number, targetRatio: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
17
16
|
dsrSupply(proxyAddress: EthereumAddress, triggerRatio: number, targetRatio: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
18
17
|
debtInFrontRepay(proxyAddress: EthereumAddress, debtInFrontMin: string, targetRatioIncrease: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
19
18
|
};
|
|
19
|
+
export declare const chickenBondsEncode: {
|
|
20
|
+
rebond(bondId: number): string[];
|
|
21
|
+
};
|
|
20
22
|
export declare const aaveV2Encode: {
|
|
21
|
-
|
|
23
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
22
24
|
};
|
|
23
25
|
export declare const aaveV3Encode: {
|
|
24
26
|
closeToAsset(strategyOrBundleId: number, isBundle: boolean | undefined, triggerData: {
|
|
@@ -57,24 +59,25 @@ export declare const aaveV3Encode: {
|
|
|
57
59
|
marketAddr: EthereumAddress;
|
|
58
60
|
targetRatio: number;
|
|
59
61
|
}): (number | boolean | string[])[];
|
|
60
|
-
|
|
61
|
-
liquidationProtection(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
62
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, isGeneric?: boolean): (number | boolean | string[])[];
|
|
62
63
|
leverageManagementOnPriceGeneric(strategyOrBundleId: number, price: number, ratioState: RatioState, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number, user: EthereumAddress): (number | boolean | string[])[];
|
|
63
64
|
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[])[];
|
|
64
65
|
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[])[];
|
|
65
66
|
};
|
|
66
67
|
export declare const compoundV2Encode: {
|
|
67
|
-
|
|
68
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId: number, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
68
69
|
};
|
|
69
70
|
export declare const compoundV3Encode: {
|
|
70
|
-
|
|
71
|
-
liquidationProtection(strategyOrBundleId: number, market: EthereumAddress, baseToken: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
71
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId: number, market: EthereumAddress, baseToken: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
72
72
|
leverageManagementOnPrice(strategyOrBundleId: number, market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, targetRatio: number, price: number, priceState: RatioState, ratioState: RatioState, user: EthereumAddress): (number | boolean | string[])[];
|
|
73
73
|
closeOnPrice(strategyOrBundleId: number, market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, stopLossPrice: number | undefined, stopLossType: CloseToAssetType | undefined, takeProfitPrice: number | undefined, takeProfitType: CloseToAssetType | undefined, user: EthereumAddress): (number | boolean | string[])[];
|
|
74
74
|
};
|
|
75
|
+
export declare const morphoAaveV2Encode: {
|
|
76
|
+
leverageManagement(triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean): string[];
|
|
77
|
+
};
|
|
75
78
|
export declare const exchangeEncode: {
|
|
76
79
|
dca(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, timestamp: number, interval: number, network: ChainId): (boolean | string[] | Strategies.MainnetIds | Strategies.OptimismIds | Strategies.ArbitrumIds | Strategies.BaseIds)[];
|
|
77
|
-
|
|
80
|
+
limitOrderWithoutSubProxy(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string | number, orderType: OrderType, fromTokenDecimals: number, toTokenDecimals: number, network: ChainId): (boolean | string[] | Strategies.MainnetIds | Strategies.OptimismIds | Strategies.ArbitrumIds | Strategies.BaseIds)[];
|
|
78
81
|
};
|
|
79
82
|
export declare const sparkEncode: {
|
|
80
83
|
leverageManagementOnPrice(strategyOrBundleId: number, isBundle: boolean | undefined, triggerData: {
|
|
@@ -91,19 +94,21 @@ export declare const sparkEncode: {
|
|
|
91
94
|
targetRatio: number;
|
|
92
95
|
}): (number | boolean | string[])[];
|
|
93
96
|
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
|
-
|
|
95
|
-
liquidationProtection(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
97
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
96
98
|
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[])[];
|
|
97
99
|
};
|
|
98
100
|
export declare const crvUSDEncode: {
|
|
99
101
|
leverageManagement(owner: EthereumAddress, controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress): (boolean | string[] | Bundles.MainnetIds)[];
|
|
100
102
|
payback(proxyAddress: EthereumAddress, addressToPullTokensFrom: EthereumAddress, positionOwner: EthereumAddress, paybackAmount: string, crvUSDAddr: EthereumAddress, controllerAddr: EthereumAddress, minHealthRatio: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
101
103
|
};
|
|
104
|
+
export type MorphoBlueBundleStrategy = 'repay' | 'boost' | 'repayOnPrice' | 'boostOnPrice' | 'close';
|
|
105
|
+
export declare function getMorphoBlueBundleId(network: ChainId, strategy: MorphoBlueBundleStrategy, isEOA: boolean): number;
|
|
102
106
|
export declare const morphoBlueEncode: {
|
|
103
|
-
leverageManagement(marketId: string, loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, ratioState: RatioState, targetRatio: number, triggerRatio: number, user: EthereumAddress, isEOA: boolean, network: ChainId): (
|
|
104
|
-
liquidationProtection(marketId: string, loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, ratioState: RatioState, targetRatio: number, triggerRatio: number, user: EthereumAddress, isEOA: boolean, network: ChainId): (boolean | string[] | Bundles.MainnetIds)[];
|
|
107
|
+
leverageManagement(marketId: string, loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, ratioState: RatioState, targetRatio: number, triggerRatio: number, user: EthereumAddress, isEOA: boolean, network: ChainId): (number | boolean | string[])[];
|
|
105
108
|
leverageManagementOnPrice(strategyOrBundleId: number, isBundle: boolean | undefined, loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, targetRatio: number, price: number, priceState: RatioState): (number | boolean | string[])[];
|
|
109
|
+
leverageManagementOnPriceGeneric(loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, targetRatio: number, price: number, priceState: RatioState, isBoost: boolean, isEOA: boolean, network: ChainId): (number | boolean | string[])[];
|
|
106
110
|
closeOnPrice(strategyOrBundleId: number, loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
111
|
+
closeOnPriceGeneric(loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, stopLossPrice: number | undefined, stopLossType: CloseToAssetType | undefined, takeProfitPrice: number | undefined, takeProfitType: CloseToAssetType | undefined, isEOA: boolean, network: ChainId): (number | boolean | string[])[];
|
|
107
112
|
};
|
|
108
113
|
export declare const liquityV2Encode: {
|
|
109
114
|
leverageManagement(market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
@@ -113,11 +118,9 @@ export declare const liquityV2Encode: {
|
|
|
113
118
|
};
|
|
114
119
|
export declare const fluidEncode: {
|
|
115
120
|
leverageManagement(nftId: string, vault: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
116
|
-
liquidationProtection(nftId: string, vault: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
117
121
|
};
|
|
118
122
|
export declare const aaveV4Encode: {
|
|
119
123
|
leverageManagement(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
120
|
-
liquidationProtection(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
121
124
|
leverageManagementOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, targetRatio: number, price: string, priceState: RatioState, ratioState: RatioState): (number | boolean | string[])[];
|
|
122
125
|
closeOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, stopLossPrice?: string, stopLossType?: CloseToAssetType, takeProfitPrice?: string, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
123
126
|
collateralSwitch(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, amountToSwitch: string, price: string, ratioState: RatioState): (number | boolean | string[])[];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { getAssetInfo } from '@defisaver/tokens';
|
|
2
|
+
import { CloseToAssetType, Bundles, ChainId, RatioState, Strategies, } from '../types/enums';
|
|
2
3
|
import { STRATEGY_IDS } from '../constants';
|
|
3
|
-
import { Bundles, ChainId, CloseToAssetType, RatioState, Strategies, } from '../types/enums';
|
|
4
4
|
import * as subDataService from './subDataService';
|
|
5
5
|
import * as triggerService from './triggerService';
|
|
6
|
-
import { compareAddresses,
|
|
6
|
+
import { compareAddresses, getCloseStrategyType, requireAddress, requireAddresses, } from './utils';
|
|
7
7
|
export const makerEncode = {
|
|
8
8
|
repayFromSavings(bundleId, vaultId, triggerRepayRatio, targetRepayRatio, isBundle = true, chainId = ChainId.Ethereum, daiAddr, mcdCdpManagerAddr) {
|
|
9
9
|
const subData = subDataService.makerRepayFromSavingsSubData.encode(vaultId, targetRepayRatio, chainId, daiAddr, mcdCdpManagerAddr);
|
|
@@ -30,21 +30,10 @@ export const makerEncode = {
|
|
|
30
30
|
const isBundle = false;
|
|
31
31
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
32
32
|
},
|
|
33
|
-
|
|
33
|
+
leverageManagementWithoutSubProxy(vaultId, triggerRatio, targetRatio, ratioState, isBoost, daiAddr) {
|
|
34
34
|
const bundleId = isBoost ? Bundles.MainnetIds.MAKER_BOOST : Bundles.MainnetIds.MAKER_REPAY;
|
|
35
35
|
const triggerData = triggerService.makerRatioTrigger.encode(vaultId, triggerRatio, ratioState);
|
|
36
|
-
const subData = subDataService.
|
|
37
|
-
return [
|
|
38
|
-
bundleId,
|
|
39
|
-
true,
|
|
40
|
-
triggerData,
|
|
41
|
-
subData,
|
|
42
|
-
];
|
|
43
|
-
},
|
|
44
|
-
liquidationProtection(vaultId, triggerRatio, targetRatio, ratioState, daiAddr) {
|
|
45
|
-
const bundleId = Bundles.MainnetIds.MAKER_SW_LIQUIDATION_PROTECTION;
|
|
46
|
-
const triggerData = triggerService.makerRatioTrigger.encode(vaultId, triggerRatio, ratioState);
|
|
47
|
-
const subData = subDataService.makerLiquidationProtectionSubData.encode(vaultId, targetRatio, daiAddr);
|
|
36
|
+
const subData = subDataService.makerLeverageManagementWithoutSubProxy.encode(vaultId, targetRatio, daiAddr);
|
|
48
37
|
return [
|
|
49
38
|
bundleId,
|
|
50
39
|
true,
|
|
@@ -78,9 +67,9 @@ export const liquityEncode = {
|
|
|
78
67
|
const isBundle = true;
|
|
79
68
|
return [strategyId, isBundle, triggerData, subData];
|
|
80
69
|
},
|
|
81
|
-
|
|
70
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId, user, ratioState, targetRatio, triggerRatio) {
|
|
82
71
|
const isBundle = true;
|
|
83
|
-
const subData = subDataService.
|
|
72
|
+
const subData = subDataService.liquityLeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState);
|
|
84
73
|
const triggerData = triggerService.liquityRatioTrigger.encode(user, triggerRatio, ratioState);
|
|
85
74
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
86
75
|
},
|
|
@@ -109,10 +98,15 @@ export const liquityEncode = {
|
|
|
109
98
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
110
99
|
},
|
|
111
100
|
};
|
|
101
|
+
export const chickenBondsEncode = {
|
|
102
|
+
rebond(bondId) {
|
|
103
|
+
return subDataService.cBondsRebondSubData.encode(bondId);
|
|
104
|
+
},
|
|
105
|
+
};
|
|
112
106
|
export const aaveV2Encode = {
|
|
113
|
-
|
|
107
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio) {
|
|
114
108
|
const isBundle = true;
|
|
115
|
-
const subData = subDataService.
|
|
109
|
+
const subData = subDataService.aaveV2LeverageManagementSubDataWithoutSubProxy.encode(market, targetRatio, ratioState);
|
|
116
110
|
const triggerData = triggerService.aaveV2RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
117
111
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
118
112
|
},
|
|
@@ -139,15 +133,9 @@ export const aaveV3Encode = {
|
|
|
139
133
|
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
140
134
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
141
135
|
},
|
|
142
|
-
|
|
136
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio, isGeneric = false) {
|
|
143
137
|
const isBundle = true;
|
|
144
|
-
const subData = subDataService.
|
|
145
|
-
const triggerData = triggerService.aaveV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
146
|
-
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
147
|
-
},
|
|
148
|
-
liquidationProtection(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio) {
|
|
149
|
-
const isBundle = true;
|
|
150
|
-
const subData = subDataService.aaveV3LiquidationProtectionSubData.encode(targetRatio, ratioState, market, user, true);
|
|
138
|
+
const subData = subDataService.aaveV3LeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState, market, user, isGeneric);
|
|
151
139
|
const triggerData = triggerService.aaveV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
152
140
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
153
141
|
},
|
|
@@ -172,23 +160,17 @@ export const aaveV3Encode = {
|
|
|
172
160
|
},
|
|
173
161
|
};
|
|
174
162
|
export const compoundV2Encode = {
|
|
175
|
-
|
|
163
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId, user, ratioState, targetRatio, triggerRatio) {
|
|
176
164
|
const isBundle = true;
|
|
177
|
-
const subData = subDataService.
|
|
165
|
+
const subData = subDataService.compoundV2LeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState);
|
|
178
166
|
const triggerData = triggerService.compoundV2RatioTrigger.encode(user, triggerRatio, ratioState);
|
|
179
167
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
180
168
|
},
|
|
181
169
|
};
|
|
182
170
|
export const compoundV3Encode = {
|
|
183
|
-
|
|
184
|
-
const isBundle = true;
|
|
185
|
-
const subData = subDataService.compoundV3LeverageManagementSubData.encode(market, baseToken, targetRatio, ratioState);
|
|
186
|
-
const triggerData = triggerService.compoundV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
187
|
-
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
188
|
-
},
|
|
189
|
-
liquidationProtection(strategyOrBundleId, market, baseToken, user, ratioState, targetRatio, triggerRatio) {
|
|
171
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId, market, baseToken, user, ratioState, targetRatio, triggerRatio) {
|
|
190
172
|
const isBundle = true;
|
|
191
|
-
const subData = subDataService.
|
|
173
|
+
const subData = subDataService.compoundV3LeverageManagementSubDataWithoutSubProxy.encode(market, baseToken, targetRatio, ratioState);
|
|
192
174
|
const triggerData = triggerService.compoundV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
193
175
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
194
176
|
},
|
|
@@ -207,6 +189,11 @@ export const compoundV3Encode = {
|
|
|
207
189
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
208
190
|
},
|
|
209
191
|
};
|
|
192
|
+
export const morphoAaveV2Encode = {
|
|
193
|
+
leverageManagement(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
194
|
+
return subDataService.morphoAaveV2LeverageManagementSubData.encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled);
|
|
195
|
+
},
|
|
196
|
+
};
|
|
210
197
|
export const exchangeEncode = {
|
|
211
198
|
dca(fromToken, toToken, amount, timestamp, interval, network) {
|
|
212
199
|
requireAddresses([fromToken, toToken]);
|
|
@@ -215,9 +202,9 @@ export const exchangeEncode = {
|
|
|
215
202
|
const strategyId = STRATEGY_IDS[network].EXCHANGE_DCA;
|
|
216
203
|
return [strategyId, false, triggerData, subData];
|
|
217
204
|
},
|
|
218
|
-
|
|
205
|
+
limitOrderWithoutSubProxy(fromToken, toToken, amount, targetPrice, goodUntil, orderType, fromTokenDecimals, toTokenDecimals, network) {
|
|
219
206
|
requireAddresses([fromToken, toToken]);
|
|
220
|
-
const subData = subDataService.
|
|
207
|
+
const subData = subDataService.exchangeLimitOrderSubDataWithoutSubProxy.encode(fromToken, toToken, amount);
|
|
221
208
|
const triggerData = triggerService.exchangeOffchainPriceTrigger.encode(targetPrice, Number(goodUntil), orderType, fromTokenDecimals, toTokenDecimals);
|
|
222
209
|
const strategyId = STRATEGY_IDS[network].EXCHANGE_LIMIT_ORDER;
|
|
223
210
|
return [strategyId, false, triggerData, subData];
|
|
@@ -238,15 +225,9 @@ export const sparkEncode = {
|
|
|
238
225
|
const triggerDataEncoded = triggerService.sparkQuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
|
|
239
226
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
240
227
|
},
|
|
241
|
-
|
|
242
|
-
const isBundle = true;
|
|
243
|
-
const subData = subDataService.sparkLeverageManagementSubData.encode(targetRatio, ratioState);
|
|
244
|
-
const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
245
|
-
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
246
|
-
},
|
|
247
|
-
liquidationProtection(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio) {
|
|
228
|
+
leverageManagementWithoutSubProxy(strategyOrBundleId, market, user, ratioState, targetRatio, triggerRatio) {
|
|
248
229
|
const isBundle = true;
|
|
249
|
-
const subData = subDataService.
|
|
230
|
+
const subData = subDataService.sparkLeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState);
|
|
250
231
|
const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
251
232
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
252
233
|
},
|
|
@@ -274,31 +255,42 @@ export const crvUSDEncode = {
|
|
|
274
255
|
return [strategyId, isBundle, triggerData, subData];
|
|
275
256
|
},
|
|
276
257
|
};
|
|
258
|
+
function getMorphoBlueBundlesIds(network) {
|
|
259
|
+
switch (network) {
|
|
260
|
+
case ChainId.Ethereum:
|
|
261
|
+
return Bundles.MainnetIds;
|
|
262
|
+
case ChainId.Base:
|
|
263
|
+
return Bundles.BaseIds;
|
|
264
|
+
case ChainId.Arbitrum:
|
|
265
|
+
return Bundles.ArbitrumIds;
|
|
266
|
+
default:
|
|
267
|
+
throw new Error(`Morpho Blue strategies are not supported on chain ${network}`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
export function getMorphoBlueBundleId(network, strategy, isEOA) {
|
|
271
|
+
const bundlesIds = getMorphoBlueBundlesIds(network);
|
|
272
|
+
switch (strategy) {
|
|
273
|
+
case 'repay':
|
|
274
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY : bundlesIds.MORPHO_BLUE_REPAY;
|
|
275
|
+
case 'boost':
|
|
276
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST : bundlesIds.MORPHO_BLUE_BOOST;
|
|
277
|
+
case 'repayOnPrice':
|
|
278
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE : bundlesIds.MORPHO_BLUE_REPAY_ON_PRICE;
|
|
279
|
+
case 'boostOnPrice':
|
|
280
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE : bundlesIds.MORPHO_BLUE_BOOST_ON_PRICE;
|
|
281
|
+
case 'close':
|
|
282
|
+
return isEOA ? bundlesIds.MORPHO_BLUE_EOA_CLOSE : bundlesIds.MORPHO_BLUE_CLOSE;
|
|
283
|
+
default:
|
|
284
|
+
throw new Error(`Unknown Morpho Blue strategy: ${strategy}`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
277
287
|
export const morphoBlueEncode = {
|
|
278
288
|
leverageManagement(marketId, loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, triggerRatio, user, isEOA, network) {
|
|
279
289
|
const subData = subDataService.morphoBlueLeverageManagementSubData.encode(loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA);
|
|
280
290
|
const triggerData = triggerService.morphoBlueRatioTrigger.encode(marketId, user, triggerRatio, ratioState);
|
|
281
291
|
// over is boost, under is repay
|
|
282
292
|
const isBoost = ratioState === RatioState.OVER;
|
|
283
|
-
|
|
284
|
-
if (network === ChainId.Base) {
|
|
285
|
-
return [isBoost ? Bundles.BaseIds.MORPHO_BLUE_BOOST : Bundles.BaseIds.MORPHO_BLUE_REPAY, true, triggerData, subData];
|
|
286
|
-
}
|
|
287
|
-
const bundlesIds = network === ChainId.Arbitrum ? Bundles.ArbitrumIds : Bundles.MainnetIds;
|
|
288
|
-
if (isBoost)
|
|
289
|
-
strategyOrBundleId = isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST : bundlesIds.MORPHO_BLUE_BOOST;
|
|
290
|
-
else
|
|
291
|
-
strategyOrBundleId = isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY : bundlesIds.MORPHO_BLUE_REPAY;
|
|
292
|
-
const isBundle = true;
|
|
293
|
-
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
294
|
-
},
|
|
295
|
-
liquidationProtection(marketId, loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, triggerRatio, user, isEOA, network) {
|
|
296
|
-
const subData = subDataService.morphoBlueLiquidationProtectionSubData.encode(loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA);
|
|
297
|
-
const triggerData = triggerService.morphoBlueRatioTrigger.encode(marketId, user, triggerRatio, ratioState);
|
|
298
|
-
// Type casting because there is no MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION for Base chain.
|
|
299
|
-
// That is fine because we will just always send isEOA == false for Base chain.
|
|
300
|
-
const bundleNetwork = getBundleIdsByNetwork(network);
|
|
301
|
-
const bundleId = isEOA ? bundleNetwork.MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION : bundleNetwork.MORPHO_BLUE_SW_LIQUIDATION_PROTECTION;
|
|
293
|
+
const bundleId = getMorphoBlueBundleId(network, isBoost ? 'boost' : 'repay', isEOA);
|
|
302
294
|
const isBundle = true;
|
|
303
295
|
return [bundleId, isBundle, triggerData, subData];
|
|
304
296
|
},
|
|
@@ -307,6 +299,13 @@ export const morphoBlueEncode = {
|
|
|
307
299
|
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
308
300
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
309
301
|
},
|
|
302
|
+
leverageManagementOnPriceGeneric(loanToken, collToken, oracle, irm, lltv, user, targetRatio, price, priceState, isBoost, isEOA, network) {
|
|
303
|
+
const subData = subDataService.morphoBlueLeverageManagementOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user);
|
|
304
|
+
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
305
|
+
const bundleId = getMorphoBlueBundleId(network, isBoost ? 'boostOnPrice' : 'repayOnPrice', isEOA);
|
|
306
|
+
const isBundle = true;
|
|
307
|
+
return [bundleId, isBundle, triggerData, subData];
|
|
308
|
+
},
|
|
310
309
|
closeOnPrice(strategyOrBundleId, loanToken, collToken, oracle, irm, lltv, user, stopLossPrice = 0, stopLossType = CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = CloseToAssetType.COLLATERAL) {
|
|
311
310
|
const isBundle = true;
|
|
312
311
|
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
@@ -314,6 +313,14 @@ export const morphoBlueEncode = {
|
|
|
314
313
|
const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
|
|
315
314
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
316
315
|
},
|
|
316
|
+
closeOnPriceGeneric(loanToken, collToken, oracle, irm, lltv, user, stopLossPrice = 0, stopLossType = CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = CloseToAssetType.COLLATERAL, isEOA, network) {
|
|
317
|
+
const isBundle = true;
|
|
318
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
319
|
+
const subDataEncoded = subDataService.morphoBlueCloseOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, user, closeType);
|
|
320
|
+
const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
|
|
321
|
+
const bundleId = getMorphoBlueBundleId(network, 'close', isEOA);
|
|
322
|
+
return [bundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
323
|
+
},
|
|
317
324
|
};
|
|
318
325
|
export const liquityV2Encode = {
|
|
319
326
|
leverageManagement(market, troveId, collToken, boldToken, ratioState, targetRatio, triggerRatio, strategyOrBundleId) {
|
|
@@ -350,12 +357,6 @@ export const fluidEncode = {
|
|
|
350
357
|
const triggerData = triggerService.fluidRatioTrigger.encode(nftId, triggerRatio, ratioState);
|
|
351
358
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
352
359
|
},
|
|
353
|
-
liquidationProtection(nftId, vault, ratioState, targetRatio, triggerRatio, strategyOrBundleId) {
|
|
354
|
-
const isBundle = true;
|
|
355
|
-
const subData = subDataService.fluidLiquidationProtectionSubData.encode(nftId, vault, ratioState, targetRatio);
|
|
356
|
-
const triggerData = triggerService.fluidRatioTrigger.encode(nftId, triggerRatio, ratioState);
|
|
357
|
-
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
358
|
-
},
|
|
359
360
|
};
|
|
360
361
|
export const aaveV4Encode = {
|
|
361
362
|
leverageManagement(strategyOrBundleId, owner, spoke, ratioState, targetRatio, triggerRatio) {
|
|
@@ -364,12 +365,6 @@ export const aaveV4Encode = {
|
|
|
364
365
|
const triggerData = triggerService.aaveV4RatioTrigger.encode(owner, spoke, triggerRatio, ratioState);
|
|
365
366
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
366
367
|
},
|
|
367
|
-
liquidationProtection(strategyOrBundleId, owner, spoke, ratioState, targetRatio, triggerRatio) {
|
|
368
|
-
const isBundle = true;
|
|
369
|
-
const subData = subDataService.aaveV4LiquidationProtectionSubData.encode(spoke, owner, ratioState, targetRatio);
|
|
370
|
-
const triggerData = triggerService.aaveV4RatioTrigger.encode(owner, spoke, triggerRatio, ratioState);
|
|
371
|
-
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
372
|
-
},
|
|
373
368
|
leverageManagementOnPrice(strategyOrBundleId, owner, spoke, collAsset, collAssetId, debtAsset, debtAssetId, targetRatio, price, priceState, ratioState) {
|
|
374
369
|
const isBundle = true;
|
|
375
370
|
const subData = subDataService.aaveV4LeverageManagementOnPriceSubData.encode(spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, ratioState, targetRatio);
|