@defisaver/automation-sdk 1.1.2 → 1.2.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/esm/constants/index.js +10 -0
- package/esm/services/strategiesService.js +31 -0
- package/esm/services/strategySubService.d.ts +1 -0
- package/esm/services/strategySubService.js +10 -0
- package/esm/services/subDataService.d.ts +6 -0
- package/esm/services/subDataService.js +16 -0
- package/esm/types/enums.d.ts +3 -1
- package/esm/types/enums.js +2 -0
- package/package.json +3 -2
- package/src/constants/index.ts +11 -1
- package/src/services/strategiesService.ts +37 -1
- package/src/services/strategySubService.ts +18 -1
- package/src/services/subDataService.ts +17 -1
- package/src/types/enums.ts +2 -0
- package/umd/index.js +597 -309
package/esm/constants/index.js
CHANGED
|
@@ -130,6 +130,16 @@ export const MAINNET_BUNDLES_INFO = {
|
|
|
130
130
|
strategyId: Strategies.Identifiers.Boost,
|
|
131
131
|
protocol: PROTOCOLS.AaveV3,
|
|
132
132
|
},
|
|
133
|
+
[Bundles.MainnetIds.MAKER_REPAY]: {
|
|
134
|
+
strategyOrBundleId: Bundles.MainnetIds.MAKER_REPAY,
|
|
135
|
+
strategyId: Strategies.Identifiers.Repay,
|
|
136
|
+
protocol: PROTOCOLS.MakerDAO,
|
|
137
|
+
},
|
|
138
|
+
[Bundles.MainnetIds.MAKER_BOOST]: {
|
|
139
|
+
strategyOrBundleId: Bundles.MainnetIds.MAKER_BOOST,
|
|
140
|
+
strategyId: Strategies.Identifiers.Boost,
|
|
141
|
+
protocol: PROTOCOLS.MakerDAO,
|
|
142
|
+
},
|
|
133
143
|
};
|
|
134
144
|
export const OPTIMISM_BUNDLES_INFO = {
|
|
135
145
|
[Bundles.OptimismIds.AAVE_V3_REPAY]: {
|
|
@@ -49,6 +49,35 @@ function parseMakerTrailingStop(position, parseData) {
|
|
|
49
49
|
};
|
|
50
50
|
return _position;
|
|
51
51
|
}
|
|
52
|
+
function parseMakerLeverageManagement(position, parseData) {
|
|
53
|
+
const _position = cloneDeep(position);
|
|
54
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
55
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
56
|
+
const triggerData = triggerService.makerRatioTrigger.decode(subStruct.triggerData);
|
|
57
|
+
const subData = subDataService.makerLeverageManagementSubData.decode(subStruct.subData);
|
|
58
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
59
|
+
_position.strategyData.decoded.subData = subData;
|
|
60
|
+
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
61
|
+
if (isRepay) {
|
|
62
|
+
_position.specific = {
|
|
63
|
+
minRatio: triggerData.ratio,
|
|
64
|
+
minOptimalRatio: subData.targetRatio,
|
|
65
|
+
repayEnabled: true,
|
|
66
|
+
subId1: Number(subId),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
_position.specific = {
|
|
71
|
+
maxRatio: triggerData.ratio,
|
|
72
|
+
maxOptimalRatio: subData.targetRatio,
|
|
73
|
+
boostEnabled: isEnabled,
|
|
74
|
+
subId2: Number(subId),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
78
|
+
_position.specific.mergeWithSameId = true;
|
|
79
|
+
return _position;
|
|
80
|
+
}
|
|
52
81
|
function parseLiquityCloseOnPrice(position, parseData) {
|
|
53
82
|
const _position = cloneDeep(position);
|
|
54
83
|
const { subStruct } = parseData.subscriptionEventData;
|
|
@@ -186,6 +215,8 @@ const parsingMethodsMapping = {
|
|
|
186
215
|
[Strategies.Identifiers.CloseOnPriceToColl]: parseMakerCloseOnPrice,
|
|
187
216
|
[Strategies.Identifiers.TrailingStopToColl]: parseMakerTrailingStop,
|
|
188
217
|
[Strategies.Identifiers.TrailingStopToDebt]: parseMakerTrailingStop,
|
|
218
|
+
[Strategies.Identifiers.Repay]: parseMakerLeverageManagement,
|
|
219
|
+
[Strategies.Identifiers.Boost]: parseMakerLeverageManagement,
|
|
189
220
|
},
|
|
190
221
|
[ProtocolIdentifiers.StrategiesAutomation.Liquity]: {
|
|
191
222
|
[Strategies.Identifiers.CloseOnPriceToColl]: parseLiquityCloseOnPrice,
|
|
@@ -4,6 +4,7 @@ export declare const makerEncode: {
|
|
|
4
4
|
repayFromSavings(bundleId: StrategyOrBundleIds, vaultId: number, priceOverOrUnder: RatioState, targetRatio: number, isBundle?: boolean, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress): (boolean | string[])[];
|
|
5
5
|
closeOnPrice(vaultId: number, ratioState: RatioState, price: string, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
|
|
6
6
|
trailingStop(vaultId: number, triggerPercentage: number, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, roundId: number, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
|
|
7
|
+
leverageManagement(vaultId: number, minRatio: string, maxRatio: string, maxOptimalRatio: string, minOptimalRatio: string, boostEnabled: boolean): (string | number | boolean)[];
|
|
7
8
|
};
|
|
8
9
|
export declare const liquityEncode: {
|
|
9
10
|
closeOnPrice(priceOverOrUnder: RatioState, price: string, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
|
|
@@ -30,6 +30,16 @@ export const makerEncode = {
|
|
|
30
30
|
const isBundle = false;
|
|
31
31
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
32
32
|
},
|
|
33
|
+
leverageManagement(vaultId, minRatio, maxRatio, maxOptimalRatio, minOptimalRatio, boostEnabled) {
|
|
34
|
+
return [
|
|
35
|
+
vaultId,
|
|
36
|
+
new Dec(minRatio).mul(1e16).toString(),
|
|
37
|
+
new Dec(maxRatio).mul(1e16).toString(),
|
|
38
|
+
new Dec(maxOptimalRatio).mul(1e16).toString(),
|
|
39
|
+
new Dec(minOptimalRatio).mul(1e16).toString(),
|
|
40
|
+
boostEnabled,
|
|
41
|
+
];
|
|
42
|
+
},
|
|
33
43
|
};
|
|
34
44
|
export const liquityEncode = {
|
|
35
45
|
closeOnPrice(priceOverOrUnder, price, closeToAssetAddr, chainlinkCollAddress, chainId = ChainId.Ethereum, collAddr, debtAddr) {
|
|
@@ -16,6 +16,12 @@ export declare const makerCloseSubData: {
|
|
|
16
16
|
closeToAssetAddr: EthereumAddress;
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
|
+
export declare const makerLeverageManagementSubData: {
|
|
20
|
+
decode: (subData: string[]) => {
|
|
21
|
+
vaultId: number;
|
|
22
|
+
targetRatio: number;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
19
25
|
export declare const liquityCloseSubData: {
|
|
20
26
|
encode(closeToAssetAddr: EthereumAddress, chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress): string[];
|
|
21
27
|
decode(subData: string[]): {
|
|
@@ -54,6 +54,22 @@ export const makerCloseSubData = {
|
|
|
54
54
|
};
|
|
55
55
|
},
|
|
56
56
|
};
|
|
57
|
+
export const makerLeverageManagementSubData = {
|
|
58
|
+
// encode: (vaultId:number, repayFrom, boostFrom, boostTo, repayTo, boostEnabled) => [
|
|
59
|
+
// vaultId,
|
|
60
|
+
// new Dec(repayFrom).mul(1e16).toString(),
|
|
61
|
+
// new Dec(boostFrom).mul(1e16).toString(),
|
|
62
|
+
// new Dec(boostTo).mul(1e16).toString(),
|
|
63
|
+
// new Dec(repayTo).mul(1e16).toString(),
|
|
64
|
+
// boostEnabled,
|
|
65
|
+
// ],
|
|
66
|
+
decode: (subData) => {
|
|
67
|
+
const vaultId = +mockedWeb3.eth.abi.decodeParameter('uint256', subData[0]).toString();
|
|
68
|
+
const weiRatio = mockedWeb3.eth.abi.decodeParameter('uint256', subData[1]);
|
|
69
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
70
|
+
return { vaultId, targetRatio };
|
|
71
|
+
},
|
|
72
|
+
};
|
|
57
73
|
export const liquityCloseSubData = {
|
|
58
74
|
encode(closeToAssetAddr, chainId = ChainId.Ethereum, collAddr, debtAddr) {
|
|
59
75
|
const _collAddr = collAddr || getAssetInfo('WETH', chainId).address;
|
package/esm/types/enums.d.ts
CHANGED
|
@@ -82,7 +82,9 @@ export declare namespace Bundles {
|
|
|
82
82
|
COMP_V3_EOA_BOOST_BUNDLE = 6,
|
|
83
83
|
LIQUITY_PAYBACK_USING_CHICKEN_BOND = 7,
|
|
84
84
|
AAVE_V3_REPAY = 8,
|
|
85
|
-
AAVE_V3_BOOST = 9
|
|
85
|
+
AAVE_V3_BOOST = 9,
|
|
86
|
+
MAKER_REPAY = 10,
|
|
87
|
+
MAKER_BOOST = 11
|
|
86
88
|
}
|
|
87
89
|
enum OptimismIds {
|
|
88
90
|
AAVE_V3_REPAY = 0,
|
package/esm/types/enums.js
CHANGED
|
@@ -97,6 +97,8 @@ export var Bundles;
|
|
|
97
97
|
MainnetIds[MainnetIds["LIQUITY_PAYBACK_USING_CHICKEN_BOND"] = 7] = "LIQUITY_PAYBACK_USING_CHICKEN_BOND";
|
|
98
98
|
MainnetIds[MainnetIds["AAVE_V3_REPAY"] = 8] = "AAVE_V3_REPAY";
|
|
99
99
|
MainnetIds[MainnetIds["AAVE_V3_BOOST"] = 9] = "AAVE_V3_BOOST";
|
|
100
|
+
MainnetIds[MainnetIds["MAKER_REPAY"] = 10] = "MAKER_REPAY";
|
|
101
|
+
MainnetIds[MainnetIds["MAKER_BOOST"] = 11] = "MAKER_BOOST";
|
|
100
102
|
})(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
|
|
101
103
|
let OptimismIds;
|
|
102
104
|
(function (OptimismIds) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defisaver/automation-sdk",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./umd/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"document": "npx typedoc --out docs/default",
|
|
15
15
|
"lint": "node_modules/.bin/eslint ./src",
|
|
16
16
|
"gtc": "node scripts/generateContractTypes.js",
|
|
17
|
-
"prepare": "husky install && npm run gtc"
|
|
17
|
+
"prepare": "husky install && npm run gtc",
|
|
18
|
+
"cpublish": "yarn build && yarn publish"
|
|
18
19
|
},
|
|
19
20
|
"author": "DeFi Saver",
|
|
20
21
|
"repository": "https://github.com/defisaver/automation-sdk",
|
package/src/constants/index.ts
CHANGED
|
@@ -146,6 +146,16 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
|
|
|
146
146
|
strategyId: Strategies.Identifiers.Boost,
|
|
147
147
|
protocol: PROTOCOLS.AaveV3,
|
|
148
148
|
},
|
|
149
|
+
[Bundles.MainnetIds.MAKER_REPAY]: {
|
|
150
|
+
strategyOrBundleId: Bundles.MainnetIds.MAKER_REPAY,
|
|
151
|
+
strategyId: Strategies.Identifiers.Repay,
|
|
152
|
+
protocol: PROTOCOLS.MakerDAO,
|
|
153
|
+
},
|
|
154
|
+
[Bundles.MainnetIds.MAKER_BOOST]: {
|
|
155
|
+
strategyOrBundleId: Bundles.MainnetIds.MAKER_BOOST,
|
|
156
|
+
strategyId: Strategies.Identifiers.Boost,
|
|
157
|
+
protocol: PROTOCOLS.MakerDAO,
|
|
158
|
+
},
|
|
149
159
|
};
|
|
150
160
|
|
|
151
161
|
export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
|
|
@@ -204,4 +214,4 @@ export const BUNDLE_IDS = {
|
|
|
204
214
|
[ChainId.Ethereum]: Bundles.MainnetIds,
|
|
205
215
|
[ChainId.Optimism]: Bundles.OptimismIds,
|
|
206
216
|
[ChainId.Arbitrum]: Bundles.ArbitrumIds,
|
|
207
|
-
};
|
|
217
|
+
};
|
|
@@ -75,7 +75,41 @@ function parseMakerTrailingStop(position: Position.Automated, parseData: ParseDa
|
|
|
75
75
|
|
|
76
76
|
return _position;
|
|
77
77
|
}
|
|
78
|
+
function parseMakerLeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
79
|
+
const _position = cloneDeep(position);
|
|
80
|
+
|
|
81
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
82
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
83
|
+
|
|
84
|
+
const triggerData = triggerService.makerRatioTrigger.decode(subStruct.triggerData);
|
|
85
|
+
const subData = subDataService.makerLeverageManagementSubData.decode(subStruct.subData);
|
|
86
|
+
|
|
87
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
88
|
+
_position.strategyData.decoded.subData = subData;
|
|
78
89
|
|
|
90
|
+
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
91
|
+
|
|
92
|
+
if (isRepay) {
|
|
93
|
+
_position.specific = {
|
|
94
|
+
minRatio: triggerData.ratio,
|
|
95
|
+
minOptimalRatio: subData.targetRatio,
|
|
96
|
+
repayEnabled: true,
|
|
97
|
+
subId1: Number(subId),
|
|
98
|
+
};
|
|
99
|
+
} else {
|
|
100
|
+
_position.specific = {
|
|
101
|
+
maxRatio: triggerData.ratio,
|
|
102
|
+
maxOptimalRatio: subData.targetRatio,
|
|
103
|
+
boostEnabled: isEnabled,
|
|
104
|
+
subId2: Number(subId),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
109
|
+
_position.specific.mergeWithSameId = true;
|
|
110
|
+
|
|
111
|
+
return _position;
|
|
112
|
+
}
|
|
79
113
|
function parseLiquityCloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
80
114
|
const _position = cloneDeep(position);
|
|
81
115
|
|
|
@@ -265,6 +299,8 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
|
265
299
|
[Strategies.Identifiers.CloseOnPriceToColl]: parseMakerCloseOnPrice,
|
|
266
300
|
[Strategies.Identifiers.TrailingStopToColl]: parseMakerTrailingStop,
|
|
267
301
|
[Strategies.Identifiers.TrailingStopToDebt]: parseMakerTrailingStop,
|
|
302
|
+
[Strategies.Identifiers.Repay]: parseMakerLeverageManagement,
|
|
303
|
+
[Strategies.Identifiers.Boost]: parseMakerLeverageManagement,
|
|
268
304
|
},
|
|
269
305
|
[ProtocolIdentifiers.StrategiesAutomation.Liquity]: {
|
|
270
306
|
[Strategies.Identifiers.CloseOnPriceToColl]: parseLiquityCloseOnPrice,
|
|
@@ -339,4 +375,4 @@ export function parseStrategiesAutomatedPosition(parseData: ParseData): Position
|
|
|
339
375
|
};
|
|
340
376
|
|
|
341
377
|
return getParsingMethod(position.protocol.id, position.strategy)(position, parseData);
|
|
342
|
-
}
|
|
378
|
+
}
|
|
@@ -72,6 +72,23 @@ export const makerEncode = {
|
|
|
72
72
|
|
|
73
73
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
74
74
|
},
|
|
75
|
+
leverageManagement(
|
|
76
|
+
vaultId:number,
|
|
77
|
+
minRatio:string,
|
|
78
|
+
maxRatio:string,
|
|
79
|
+
maxOptimalRatio:string,
|
|
80
|
+
minOptimalRatio:string,
|
|
81
|
+
boostEnabled:boolean,
|
|
82
|
+
) {
|
|
83
|
+
return [
|
|
84
|
+
vaultId,
|
|
85
|
+
new Dec(minRatio).mul(1e16).toString(),
|
|
86
|
+
new Dec(maxRatio).mul(1e16).toString(),
|
|
87
|
+
new Dec(maxOptimalRatio).mul(1e16).toString(),
|
|
88
|
+
new Dec(minOptimalRatio).mul(1e16).toString(),
|
|
89
|
+
boostEnabled,
|
|
90
|
+
];
|
|
91
|
+
},
|
|
75
92
|
};
|
|
76
93
|
|
|
77
94
|
export const liquityEncode = {
|
|
@@ -199,4 +216,4 @@ export const compoundV3Encode = {
|
|
|
199
216
|
) {
|
|
200
217
|
return subDataService.compoundV3LeverageManagementSubData.encode(market, baseToken, minRatio, maxRatio, maxOptimalRatio, minOptimalRatio, boostEnabled, isEOA);
|
|
201
218
|
},
|
|
202
|
-
};
|
|
219
|
+
};
|
|
@@ -82,6 +82,22 @@ export const makerCloseSubData = {
|
|
|
82
82
|
},
|
|
83
83
|
};
|
|
84
84
|
|
|
85
|
+
export const makerLeverageManagementSubData = {
|
|
86
|
+
// encode: (vaultId:number, repayFrom, boostFrom, boostTo, repayTo, boostEnabled) => [
|
|
87
|
+
// vaultId,
|
|
88
|
+
// new Dec(repayFrom).mul(1e16).toString(),
|
|
89
|
+
// new Dec(boostFrom).mul(1e16).toString(),
|
|
90
|
+
// new Dec(boostTo).mul(1e16).toString(),
|
|
91
|
+
// new Dec(repayTo).mul(1e16).toString(),
|
|
92
|
+
// boostEnabled,
|
|
93
|
+
// ],
|
|
94
|
+
decode: (subData:SubData) => {
|
|
95
|
+
const vaultId = +mockedWeb3.eth.abi.decodeParameter('uint256', subData[0]).toString();
|
|
96
|
+
const weiRatio = mockedWeb3.eth.abi.decodeParameter('uint256', subData[1]) as any as string;
|
|
97
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
98
|
+
return { vaultId, targetRatio };
|
|
99
|
+
},
|
|
100
|
+
};
|
|
85
101
|
export const liquityCloseSubData = {
|
|
86
102
|
encode(
|
|
87
103
|
closeToAssetAddr: EthereumAddress,
|
|
@@ -210,4 +226,4 @@ export const liquityPaybackUsingChickenBondSubData = {
|
|
|
210
226
|
|
|
211
227
|
return { sourceId, sourceType };
|
|
212
228
|
},
|
|
213
|
-
};
|
|
229
|
+
};
|