@defisaver/automation-sdk 3.1.4 → 3.1.6-fluid-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/automation/private/StrategiesAutomation.d.ts +2 -2
- package/cjs/automation/public/Strategies.test.d.ts +1 -0
- package/cjs/automation/public/Strategies.test.js +61 -0
- package/cjs/constants/index.js +45 -0
- package/cjs/services/strategiesService.js +155 -0
- package/cjs/services/strategySubService.d.ts +10 -1
- package/cjs/services/strategySubService.js +35 -1
- package/cjs/services/subDataService.d.ts +55 -1
- package/cjs/services/subDataService.js +174 -1
- package/cjs/services/triggerService.d.ts +43 -0
- package/cjs/services/triggerService.js +81 -1
- package/cjs/services/utils.d.ts +6 -1
- package/cjs/services/utils.js +52 -1
- package/cjs/types/enums.d.ts +38 -3
- package/cjs/types/enums.js +40 -1
- package/cjs/types/index.d.ts +16 -3
- package/esm/automation/private/StrategiesAutomation.d.ts +2 -2
- package/esm/automation/public/Strategies.test.d.ts +1 -0
- package/esm/automation/public/Strategies.test.js +56 -0
- package/esm/constants/index.js +45 -0
- package/esm/services/strategiesService.js +153 -1
- package/esm/services/strategySubService.d.ts +10 -1
- package/esm/services/strategySubService.js +36 -2
- package/esm/services/subDataService.d.ts +55 -1
- package/esm/services/subDataService.js +174 -1
- package/esm/services/triggerService.d.ts +43 -0
- package/esm/services/triggerService.js +80 -0
- package/esm/services/utils.d.ts +6 -1
- package/esm/services/utils.js +50 -1
- package/esm/types/enums.d.ts +38 -3
- package/esm/types/enums.js +39 -0
- package/esm/types/index.d.ts +16 -3
- package/package.json +3 -3
- package/src/automation/private/StrategiesAutomation.ts +2 -2
- package/src/automation/public/Strategies.test.ts +49 -0
- package/src/constants/index.ts +45 -0
- package/src/services/strategiesService.ts +199 -1
- package/src/services/strategySubService.ts +97 -1
- package/src/services/subDataService.ts +243 -2
- package/src/services/triggerService.ts +125 -0
- package/src/services/utils.ts +60 -1
- package/src/types/enums.ts +39 -0
- package/src/types/index.ts +20 -2
- package/umd/index.js +34219 -0
|
@@ -189,3 +189,46 @@ export declare const morphoBlueRatioTrigger: {
|
|
|
189
189
|
ratioState: number;
|
|
190
190
|
};
|
|
191
191
|
};
|
|
192
|
+
export declare const liquityV2RatioTrigger: {
|
|
193
|
+
encode(market: EthereumAddress, troveId: string, ratioPercentage: number, ratioState: RatioState): string[];
|
|
194
|
+
decode(triggerData: string[]): {
|
|
195
|
+
market: string;
|
|
196
|
+
troveId: string;
|
|
197
|
+
ratio: number;
|
|
198
|
+
ratioState: number;
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
export declare const liquityV2QuotePriceTrigger: {
|
|
202
|
+
encode(market: EthereumAddress, price: number, ratioState: RatioState): string[];
|
|
203
|
+
decode(triggerData: string[]): {
|
|
204
|
+
market: string;
|
|
205
|
+
price: string;
|
|
206
|
+
ratioState: number;
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
export declare const closePriceTrigger: {
|
|
210
|
+
encode(tokenAddr: EthereumAddress, lowerPrice: number, upperPrice: number): string[];
|
|
211
|
+
decode(triggerData: string[]): {
|
|
212
|
+
tokenAddr: EthereumAddress;
|
|
213
|
+
lowerPrice: string;
|
|
214
|
+
upperPrice: string;
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
export declare const morphoBluePriceTrigger: {
|
|
218
|
+
encode(oracle: EthereumAddress, collateralToken: EthereumAddress, loanToken: EthereumAddress, price: number, priceState: RatioState): string[];
|
|
219
|
+
decode(triggerData: string[]): {
|
|
220
|
+
oracle: string;
|
|
221
|
+
collateralToken: string;
|
|
222
|
+
loanToken: string;
|
|
223
|
+
price: string;
|
|
224
|
+
priceState: number;
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
export declare const fluidRatioTrigger: {
|
|
228
|
+
encode(nftId: string, ratioPercentage: number, ratioState: RatioState): string[];
|
|
229
|
+
decode(triggerData: string[]): {
|
|
230
|
+
nftId: string;
|
|
231
|
+
ratio: number;
|
|
232
|
+
ratioState: number;
|
|
233
|
+
};
|
|
234
|
+
};
|
|
@@ -336,3 +336,83 @@ export const morphoBlueRatioTrigger = {
|
|
|
336
336
|
};
|
|
337
337
|
},
|
|
338
338
|
};
|
|
339
|
+
export const liquityV2RatioTrigger = {
|
|
340
|
+
encode(market, troveId, ratioPercentage, ratioState) {
|
|
341
|
+
const ratioWei = ratioPercentageToWei(ratioPercentage);
|
|
342
|
+
return [AbiCoder.encodeParameters(['address', 'uint256', 'uint256', 'uint8'], [market, troveId, ratioWei, ratioState])];
|
|
343
|
+
},
|
|
344
|
+
decode(triggerData) {
|
|
345
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint256', 'uint8'], triggerData[0]);
|
|
346
|
+
return {
|
|
347
|
+
market: decodedData[0],
|
|
348
|
+
troveId: decodedData[1],
|
|
349
|
+
ratio: weiToRatioPercentage(decodedData[2]),
|
|
350
|
+
ratioState: Number(decodedData[3]),
|
|
351
|
+
};
|
|
352
|
+
},
|
|
353
|
+
};
|
|
354
|
+
export const liquityV2QuotePriceTrigger = {
|
|
355
|
+
encode(market, price, ratioState) {
|
|
356
|
+
// Price is always in 18 decimals
|
|
357
|
+
const _price = new Dec(price.toString()).mul(Math.pow(10, 18)).floor().toString();
|
|
358
|
+
return [AbiCoder.encodeParameters(['address', 'uint256', 'uint8'], [market, _price, ratioState])];
|
|
359
|
+
},
|
|
360
|
+
decode(triggerData) {
|
|
361
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint8'], triggerData[0]);
|
|
362
|
+
const price = new Dec(decodedData[1]).div(Math.pow(10, 18)).toDP(18).toString();
|
|
363
|
+
return {
|
|
364
|
+
market: decodedData[0],
|
|
365
|
+
price,
|
|
366
|
+
ratioState: Number(decodedData[2]),
|
|
367
|
+
};
|
|
368
|
+
},
|
|
369
|
+
};
|
|
370
|
+
export const closePriceTrigger = {
|
|
371
|
+
encode(tokenAddr, lowerPrice, upperPrice) {
|
|
372
|
+
const lowerPriceFormatted = new Dec(lowerPrice).mul(1e8).floor().toString();
|
|
373
|
+
const upperPriceFormatted = new Dec(upperPrice).mul(1e8).floor().toString();
|
|
374
|
+
return [
|
|
375
|
+
AbiCoder.encodeParameters(['address', 'uint256', 'uint256'], [tokenAddr, lowerPriceFormatted, upperPriceFormatted]),
|
|
376
|
+
];
|
|
377
|
+
},
|
|
378
|
+
decode(triggerData) {
|
|
379
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint256'], triggerData[0]);
|
|
380
|
+
return {
|
|
381
|
+
tokenAddr: decodedData[0],
|
|
382
|
+
lowerPrice: new Dec(decodedData[1]).div(1e8).toString(),
|
|
383
|
+
upperPrice: new Dec(decodedData[2]).div(1e8).toString(),
|
|
384
|
+
};
|
|
385
|
+
},
|
|
386
|
+
};
|
|
387
|
+
export const morphoBluePriceTrigger = {
|
|
388
|
+
encode(oracle, collateralToken, loanToken, price, priceState) {
|
|
389
|
+
const _price = new Dec(price.toString()).mul(1e8).floor().toString();
|
|
390
|
+
return [
|
|
391
|
+
AbiCoder.encodeParameters(['address', 'address', 'address', 'uint256', 'uint8'], [oracle, collateralToken, loanToken, _price, priceState]),
|
|
392
|
+
];
|
|
393
|
+
},
|
|
394
|
+
decode(triggerData) {
|
|
395
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
396
|
+
return {
|
|
397
|
+
oracle: decodedData[0],
|
|
398
|
+
collateralToken: decodedData[1],
|
|
399
|
+
loanToken: decodedData[2],
|
|
400
|
+
price: new Dec(decodedData[3]).div(1e8).toString(),
|
|
401
|
+
priceState: Number(decodedData[4]),
|
|
402
|
+
};
|
|
403
|
+
},
|
|
404
|
+
};
|
|
405
|
+
export const fluidRatioTrigger = {
|
|
406
|
+
encode(nftId, ratioPercentage, ratioState) {
|
|
407
|
+
const ratioWei = ratioPercentageToWei(ratioPercentage);
|
|
408
|
+
return [AbiCoder.encodeParameters(['uint256', 'uint256', 'uint8'], [nftId, ratioWei, ratioState])];
|
|
409
|
+
},
|
|
410
|
+
decode(triggerData) {
|
|
411
|
+
const decodedData = AbiCoder.decodeParameters(['uint256', 'uint256', 'uint8'], triggerData[0]);
|
|
412
|
+
return {
|
|
413
|
+
nftId: decodedData[0],
|
|
414
|
+
ratio: weiToRatioPercentage(decodedData[1]),
|
|
415
|
+
ratioState: Number(decodedData[2]),
|
|
416
|
+
};
|
|
417
|
+
},
|
|
418
|
+
};
|
package/esm/services/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EthereumAddress } from '../types';
|
|
2
|
-
import { ChainId, RatioState } from '../types/enums';
|
|
2
|
+
import { ChainId, CloseStrategyType, CloseToAssetType, RatioState } from '../types/enums';
|
|
3
3
|
export declare function isDefined<T>(value: T): value is NonNullable<T>;
|
|
4
4
|
export declare function isUndefined(value: unknown): boolean;
|
|
5
5
|
export declare function compareAddresses(firstAddress: EthereumAddress, secondAddress: EthereumAddress): boolean;
|
|
@@ -23,3 +23,8 @@ export declare function getRatioStateInfoForAaveCloseStrategy(currentRatioState:
|
|
|
23
23
|
ratioState: RatioState;
|
|
24
24
|
};
|
|
25
25
|
export declare function getPositionId(...args: (number | string)[]): string;
|
|
26
|
+
export declare function getCloseStrategyType(stopLossPrice: number, stopLossType: CloseToAssetType, takeProfitPrice: number, takeProfitType: CloseToAssetType): CloseStrategyType;
|
|
27
|
+
export declare function getStopLossAndTakeProfitTypeByCloseStrategyType(closeStrategyType: CloseStrategyType): {
|
|
28
|
+
stopLossType: CloseToAssetType | undefined;
|
|
29
|
+
takeProfitType: CloseToAssetType | undefined;
|
|
30
|
+
};
|
package/esm/services/utils.js
CHANGED
|
@@ -2,7 +2,7 @@ import Dec from 'decimal.js';
|
|
|
2
2
|
import * as web3Utils from 'web3-utils';
|
|
3
3
|
import AbiCoder from 'web3-eth-abi';
|
|
4
4
|
import { getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
5
|
-
import { ChainId, RatioState } from '../types/enums';
|
|
5
|
+
import { ChainId, CloseStrategyType, CloseToAssetType, RatioState, } from '../types/enums';
|
|
6
6
|
export function isDefined(value) {
|
|
7
7
|
return value !== undefined && value !== null;
|
|
8
8
|
}
|
|
@@ -80,3 +80,52 @@ export function getRatioStateInfoForAaveCloseStrategy(currentRatioState, collAss
|
|
|
80
80
|
export function getPositionId(...args) {
|
|
81
81
|
return args.map(arg => arg.toString().toLowerCase().split(' ').join('_')).join('-');
|
|
82
82
|
}
|
|
83
|
+
export function getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType) {
|
|
84
|
+
const isStopLoss = stopLossPrice > 0;
|
|
85
|
+
const isTakeProfit = takeProfitPrice > 0;
|
|
86
|
+
if (!isStopLoss && !isTakeProfit) {
|
|
87
|
+
throw new Error('CloseOnPrice: At least one price must be defined');
|
|
88
|
+
}
|
|
89
|
+
if (isStopLoss && isTakeProfit) {
|
|
90
|
+
if (stopLossType === CloseToAssetType.COLLATERAL && takeProfitType === CloseToAssetType.COLLATERAL) {
|
|
91
|
+
return CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL;
|
|
92
|
+
}
|
|
93
|
+
if (stopLossType === CloseToAssetType.COLLATERAL) {
|
|
94
|
+
return CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL;
|
|
95
|
+
}
|
|
96
|
+
if (takeProfitType === CloseToAssetType.COLLATERAL) {
|
|
97
|
+
return CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT;
|
|
98
|
+
}
|
|
99
|
+
return CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT;
|
|
100
|
+
}
|
|
101
|
+
if (isStopLoss) {
|
|
102
|
+
return stopLossType === CloseToAssetType.COLLATERAL
|
|
103
|
+
? CloseStrategyType.STOP_LOSS_IN_COLLATERAL
|
|
104
|
+
: CloseStrategyType.STOP_LOSS_IN_DEBT;
|
|
105
|
+
}
|
|
106
|
+
return takeProfitType === CloseToAssetType.COLLATERAL
|
|
107
|
+
? CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL
|
|
108
|
+
: CloseStrategyType.TAKE_PROFIT_IN_DEBT;
|
|
109
|
+
}
|
|
110
|
+
export function getStopLossAndTakeProfitTypeByCloseStrategyType(closeStrategyType) {
|
|
111
|
+
switch (closeStrategyType) {
|
|
112
|
+
case CloseStrategyType.STOP_LOSS_IN_COLLATERAL:
|
|
113
|
+
return { stopLossType: CloseToAssetType.COLLATERAL, takeProfitType: undefined };
|
|
114
|
+
case CloseStrategyType.STOP_LOSS_IN_DEBT:
|
|
115
|
+
return { stopLossType: CloseToAssetType.DEBT, takeProfitType: undefined };
|
|
116
|
+
case CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL:
|
|
117
|
+
return { stopLossType: undefined, takeProfitType: CloseToAssetType.COLLATERAL };
|
|
118
|
+
case CloseStrategyType.TAKE_PROFIT_IN_DEBT:
|
|
119
|
+
return { stopLossType: undefined, takeProfitType: CloseToAssetType.DEBT };
|
|
120
|
+
case CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT:
|
|
121
|
+
return { stopLossType: CloseToAssetType.DEBT, takeProfitType: CloseToAssetType.COLLATERAL };
|
|
122
|
+
case CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL:
|
|
123
|
+
return { stopLossType: CloseToAssetType.COLLATERAL, takeProfitType: CloseToAssetType.DEBT };
|
|
124
|
+
case CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT:
|
|
125
|
+
return { stopLossType: CloseToAssetType.DEBT, takeProfitType: CloseToAssetType.DEBT };
|
|
126
|
+
case CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL:
|
|
127
|
+
return { stopLossType: CloseToAssetType.COLLATERAL, takeProfitType: CloseToAssetType.COLLATERAL };
|
|
128
|
+
default:
|
|
129
|
+
throw new Error('CloseStrategyType not supported');
|
|
130
|
+
}
|
|
131
|
+
}
|
package/esm/types/enums.d.ts
CHANGED
|
@@ -17,6 +17,28 @@ export declare enum BundleProtocols {
|
|
|
17
17
|
Yearn = "yearn",
|
|
18
18
|
Rari = "rari"
|
|
19
19
|
}
|
|
20
|
+
export declare enum CollActionType {
|
|
21
|
+
SUPPLY = 0,
|
|
22
|
+
WITHDRAW = 1
|
|
23
|
+
}
|
|
24
|
+
export declare enum DebtActionType {
|
|
25
|
+
PAYBACK = 0,
|
|
26
|
+
BORROW = 1
|
|
27
|
+
}
|
|
28
|
+
export declare enum CloseStrategyType {
|
|
29
|
+
TAKE_PROFIT_IN_COLLATERAL = 0,
|
|
30
|
+
STOP_LOSS_IN_COLLATERAL = 1,
|
|
31
|
+
TAKE_PROFIT_IN_DEBT = 2,
|
|
32
|
+
STOP_LOSS_IN_DEBT = 3,
|
|
33
|
+
TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL = 4,
|
|
34
|
+
TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT = 5,
|
|
35
|
+
TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT = 6,
|
|
36
|
+
TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL = 7
|
|
37
|
+
}
|
|
38
|
+
export declare enum CloseToAssetType {
|
|
39
|
+
COLLATERAL = 0,
|
|
40
|
+
DEBT = 1
|
|
41
|
+
}
|
|
20
42
|
/**
|
|
21
43
|
* @dev Follow the naming convention:
|
|
22
44
|
* - Enum name consists of two parts, name and version
|
|
@@ -28,6 +50,7 @@ export declare namespace ProtocolIdentifiers {
|
|
|
28
50
|
enum StrategiesAutomation {
|
|
29
51
|
MakerDAO = "MakerDAO",
|
|
30
52
|
Liquity = "Liquity",
|
|
53
|
+
LiquityV2 = "Liquity__V2",
|
|
31
54
|
ChickenBonds = "Chicken Bonds",
|
|
32
55
|
CompoundV2 = "Compound__V2",
|
|
33
56
|
CompoundV3 = "Compound__V3",
|
|
@@ -37,7 +60,8 @@ export declare namespace ProtocolIdentifiers {
|
|
|
37
60
|
Exchange = "Exchange",
|
|
38
61
|
Spark = "Spark",
|
|
39
62
|
CrvUSD = "CurveUSD",
|
|
40
|
-
MorphoBlue = "MorphoBlue"
|
|
63
|
+
MorphoBlue = "MorphoBlue",
|
|
64
|
+
FluidT1 = "FluidT1"
|
|
41
65
|
}
|
|
42
66
|
enum LegacyAutomation {
|
|
43
67
|
MakerDAO = "MakerDAO",
|
|
@@ -88,6 +112,7 @@ export declare namespace Strategies {
|
|
|
88
112
|
CloseToCollateralWithGasPrice = "close-to-collateral-with-gas-price",
|
|
89
113
|
CloseOnPriceToDebt = "close-on-price-to-debt",
|
|
90
114
|
CloseOnPriceToColl = "close-on-price-to-collateral",
|
|
115
|
+
CloseOnPrice = "close-on-price",
|
|
91
116
|
TrailingStopToColl = "trailing-stop-to-collateral",
|
|
92
117
|
TrailingStopToDebt = "trailing-stop-to-debt",
|
|
93
118
|
Rebond = "rebond",
|
|
@@ -98,6 +123,7 @@ export declare namespace Strategies {
|
|
|
98
123
|
DebtInFrontRepay = "debt-in-front-repay",
|
|
99
124
|
OpenOrderFromCollateral = "open-order-from-collateral",
|
|
100
125
|
OpenOrderFromDebt = "open-order-from-debt",
|
|
126
|
+
BoostOnPrice = "boost-on-price",
|
|
101
127
|
RepayOnPrice = "repay-on-price"
|
|
102
128
|
}
|
|
103
129
|
enum IdOverrides {
|
|
@@ -151,7 +177,15 @@ export declare namespace Bundles {
|
|
|
151
177
|
MORPHO_BLUE_EOA_REPAY = 34,
|
|
152
178
|
MORPHO_BLUE_EOA_BOOST = 35,
|
|
153
179
|
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 36,
|
|
154
|
-
AAVE_V3_REPAY_ON_PRICE = 37
|
|
180
|
+
AAVE_V3_REPAY_ON_PRICE = 37,
|
|
181
|
+
MORPHO_BLUE_BOOST_ON_PRICE = 38,
|
|
182
|
+
LIQUITY_V2_REPAY = 39,
|
|
183
|
+
LIQUITY_V2_BOOST = 40,
|
|
184
|
+
LIQUITY_V2_CLOSE = 41,
|
|
185
|
+
LIQUITY_V2_REPAY_ON_PRICE = 42,
|
|
186
|
+
LIQUITY_V2_BOOST_ON_PRICE = 43,
|
|
187
|
+
FLUID_T1_REPAY = 44,
|
|
188
|
+
FLUID_T2_BOOST = 45
|
|
155
189
|
}
|
|
156
190
|
enum OptimismIds {
|
|
157
191
|
AAVE_V3_REPAY = 0,
|
|
@@ -171,7 +205,8 @@ export declare namespace Bundles {
|
|
|
171
205
|
MORPHO_BLUE_REPAY = 8,
|
|
172
206
|
MORPHO_BLUE_BOOST = 9,
|
|
173
207
|
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 10,
|
|
174
|
-
AAVE_V3_REPAY_ON_PRICE = 11
|
|
208
|
+
AAVE_V3_REPAY_ON_PRICE = 11,
|
|
209
|
+
MORPHO_BLUE_BOOST_ON_PRICE = 12
|
|
175
210
|
}
|
|
176
211
|
enum ArbitrumIds {
|
|
177
212
|
AAVE_V3_REPAY = 0,
|
package/esm/types/enums.js
CHANGED
|
@@ -21,6 +21,32 @@ export var BundleProtocols;
|
|
|
21
21
|
BundleProtocols["Yearn"] = "yearn";
|
|
22
22
|
BundleProtocols["Rari"] = "rari";
|
|
23
23
|
})(BundleProtocols || (BundleProtocols = {}));
|
|
24
|
+
export var CollActionType;
|
|
25
|
+
(function (CollActionType) {
|
|
26
|
+
CollActionType[CollActionType["SUPPLY"] = 0] = "SUPPLY";
|
|
27
|
+
CollActionType[CollActionType["WITHDRAW"] = 1] = "WITHDRAW";
|
|
28
|
+
})(CollActionType || (CollActionType = {}));
|
|
29
|
+
export var DebtActionType;
|
|
30
|
+
(function (DebtActionType) {
|
|
31
|
+
DebtActionType[DebtActionType["PAYBACK"] = 0] = "PAYBACK";
|
|
32
|
+
DebtActionType[DebtActionType["BORROW"] = 1] = "BORROW";
|
|
33
|
+
})(DebtActionType || (DebtActionType = {}));
|
|
34
|
+
export var CloseStrategyType;
|
|
35
|
+
(function (CloseStrategyType) {
|
|
36
|
+
CloseStrategyType[CloseStrategyType["TAKE_PROFIT_IN_COLLATERAL"] = 0] = "TAKE_PROFIT_IN_COLLATERAL";
|
|
37
|
+
CloseStrategyType[CloseStrategyType["STOP_LOSS_IN_COLLATERAL"] = 1] = "STOP_LOSS_IN_COLLATERAL";
|
|
38
|
+
CloseStrategyType[CloseStrategyType["TAKE_PROFIT_IN_DEBT"] = 2] = "TAKE_PROFIT_IN_DEBT";
|
|
39
|
+
CloseStrategyType[CloseStrategyType["STOP_LOSS_IN_DEBT"] = 3] = "STOP_LOSS_IN_DEBT";
|
|
40
|
+
CloseStrategyType[CloseStrategyType["TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL"] = 4] = "TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL";
|
|
41
|
+
CloseStrategyType[CloseStrategyType["TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT"] = 5] = "TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT";
|
|
42
|
+
CloseStrategyType[CloseStrategyType["TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT"] = 6] = "TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT";
|
|
43
|
+
CloseStrategyType[CloseStrategyType["TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL"] = 7] = "TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL";
|
|
44
|
+
})(CloseStrategyType || (CloseStrategyType = {}));
|
|
45
|
+
export var CloseToAssetType;
|
|
46
|
+
(function (CloseToAssetType) {
|
|
47
|
+
CloseToAssetType[CloseToAssetType["COLLATERAL"] = 0] = "COLLATERAL";
|
|
48
|
+
CloseToAssetType[CloseToAssetType["DEBT"] = 1] = "DEBT";
|
|
49
|
+
})(CloseToAssetType || (CloseToAssetType = {}));
|
|
24
50
|
/**
|
|
25
51
|
* @dev Follow the naming convention:
|
|
26
52
|
* - Enum name consists of two parts, name and version
|
|
@@ -34,6 +60,7 @@ export var ProtocolIdentifiers;
|
|
|
34
60
|
(function (StrategiesAutomation) {
|
|
35
61
|
StrategiesAutomation["MakerDAO"] = "MakerDAO";
|
|
36
62
|
StrategiesAutomation["Liquity"] = "Liquity";
|
|
63
|
+
StrategiesAutomation["LiquityV2"] = "Liquity__V2";
|
|
37
64
|
StrategiesAutomation["ChickenBonds"] = "Chicken Bonds";
|
|
38
65
|
StrategiesAutomation["CompoundV2"] = "Compound__V2";
|
|
39
66
|
StrategiesAutomation["CompoundV3"] = "Compound__V3";
|
|
@@ -44,6 +71,7 @@ export var ProtocolIdentifiers;
|
|
|
44
71
|
StrategiesAutomation["Spark"] = "Spark";
|
|
45
72
|
StrategiesAutomation["CrvUSD"] = "CurveUSD";
|
|
46
73
|
StrategiesAutomation["MorphoBlue"] = "MorphoBlue";
|
|
74
|
+
StrategiesAutomation["FluidT1"] = "FluidT1";
|
|
47
75
|
})(StrategiesAutomation = ProtocolIdentifiers.StrategiesAutomation || (ProtocolIdentifiers.StrategiesAutomation = {}));
|
|
48
76
|
let LegacyAutomation;
|
|
49
77
|
(function (LegacyAutomation) {
|
|
@@ -101,6 +129,7 @@ export var Strategies;
|
|
|
101
129
|
Identifiers["CloseToCollateralWithGasPrice"] = "close-to-collateral-with-gas-price";
|
|
102
130
|
Identifiers["CloseOnPriceToDebt"] = "close-on-price-to-debt";
|
|
103
131
|
Identifiers["CloseOnPriceToColl"] = "close-on-price-to-collateral";
|
|
132
|
+
Identifiers["CloseOnPrice"] = "close-on-price";
|
|
104
133
|
Identifiers["TrailingStopToColl"] = "trailing-stop-to-collateral";
|
|
105
134
|
Identifiers["TrailingStopToDebt"] = "trailing-stop-to-debt";
|
|
106
135
|
Identifiers["Rebond"] = "rebond";
|
|
@@ -111,6 +140,7 @@ export var Strategies;
|
|
|
111
140
|
Identifiers["DebtInFrontRepay"] = "debt-in-front-repay";
|
|
112
141
|
Identifiers["OpenOrderFromCollateral"] = "open-order-from-collateral";
|
|
113
142
|
Identifiers["OpenOrderFromDebt"] = "open-order-from-debt";
|
|
143
|
+
Identifiers["BoostOnPrice"] = "boost-on-price";
|
|
114
144
|
Identifiers["RepayOnPrice"] = "repay-on-price";
|
|
115
145
|
})(Identifiers = Strategies.Identifiers || (Strategies.Identifiers = {}));
|
|
116
146
|
let IdOverrides;
|
|
@@ -168,6 +198,14 @@ export var Bundles;
|
|
|
168
198
|
MainnetIds[MainnetIds["MORPHO_BLUE_EOA_BOOST"] = 35] = "MORPHO_BLUE_EOA_BOOST";
|
|
169
199
|
MainnetIds[MainnetIds["AAVE_V3_OPEN_ORDER_FROM_COLLATERAL"] = 36] = "AAVE_V3_OPEN_ORDER_FROM_COLLATERAL";
|
|
170
200
|
MainnetIds[MainnetIds["AAVE_V3_REPAY_ON_PRICE"] = 37] = "AAVE_V3_REPAY_ON_PRICE";
|
|
201
|
+
MainnetIds[MainnetIds["MORPHO_BLUE_BOOST_ON_PRICE"] = 38] = "MORPHO_BLUE_BOOST_ON_PRICE";
|
|
202
|
+
MainnetIds[MainnetIds["LIQUITY_V2_REPAY"] = 39] = "LIQUITY_V2_REPAY";
|
|
203
|
+
MainnetIds[MainnetIds["LIQUITY_V2_BOOST"] = 40] = "LIQUITY_V2_BOOST";
|
|
204
|
+
MainnetIds[MainnetIds["LIQUITY_V2_CLOSE"] = 41] = "LIQUITY_V2_CLOSE";
|
|
205
|
+
MainnetIds[MainnetIds["LIQUITY_V2_REPAY_ON_PRICE"] = 42] = "LIQUITY_V2_REPAY_ON_PRICE";
|
|
206
|
+
MainnetIds[MainnetIds["LIQUITY_V2_BOOST_ON_PRICE"] = 43] = "LIQUITY_V2_BOOST_ON_PRICE";
|
|
207
|
+
MainnetIds[MainnetIds["FLUID_T1_REPAY"] = 44] = "FLUID_T1_REPAY";
|
|
208
|
+
MainnetIds[MainnetIds["FLUID_T2_BOOST"] = 45] = "FLUID_T2_BOOST";
|
|
171
209
|
})(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
|
|
172
210
|
let OptimismIds;
|
|
173
211
|
(function (OptimismIds) {
|
|
@@ -190,6 +228,7 @@ export var Bundles;
|
|
|
190
228
|
BaseIds[BaseIds["MORPHO_BLUE_BOOST"] = 9] = "MORPHO_BLUE_BOOST";
|
|
191
229
|
BaseIds[BaseIds["AAVE_V3_OPEN_ORDER_FROM_COLLATERAL"] = 10] = "AAVE_V3_OPEN_ORDER_FROM_COLLATERAL";
|
|
192
230
|
BaseIds[BaseIds["AAVE_V3_REPAY_ON_PRICE"] = 11] = "AAVE_V3_REPAY_ON_PRICE";
|
|
231
|
+
BaseIds[BaseIds["MORPHO_BLUE_BOOST_ON_PRICE"] = 12] = "MORPHO_BLUE_BOOST_ON_PRICE";
|
|
193
232
|
})(BaseIds = Bundles.BaseIds || (Bundles.BaseIds = {}));
|
|
194
233
|
let ArbitrumIds;
|
|
195
234
|
(function (ArbitrumIds) {
|
package/esm/types/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type Web3 from 'web3';
|
|
|
2
2
|
import type { AbiItem } from 'web3-utils';
|
|
3
3
|
import type { BaseContract, BlockType } from './contracts/generated/types';
|
|
4
4
|
import type { Subscribe, StrategyModel } from './contracts/generated/SubStorage';
|
|
5
|
-
import type { ChainId, Strategies, Bundles, ProtocolIdentifiers, RatioState } from './enums';
|
|
5
|
+
import type { ChainId, Strategies, Bundles, ProtocolIdentifiers, RatioState, CloseToAssetType } from './enums';
|
|
6
6
|
export type PlaceholderType = any;
|
|
7
7
|
export type EthereumAddress = string;
|
|
8
8
|
export type BlockNumber = BlockType;
|
|
@@ -69,7 +69,7 @@ export declare namespace Interfaces {
|
|
|
69
69
|
}
|
|
70
70
|
interface Automation {
|
|
71
71
|
provider: Web3;
|
|
72
|
-
providerFork
|
|
72
|
+
providerFork?: Web3;
|
|
73
73
|
}
|
|
74
74
|
interface LegacyAutomation<T extends BaseContract> {
|
|
75
75
|
provider: Web3;
|
|
@@ -123,6 +123,10 @@ export declare namespace Position {
|
|
|
123
123
|
interface BoostOnPriceAave extends CloseOnPriceAave {
|
|
124
124
|
ratio: number;
|
|
125
125
|
}
|
|
126
|
+
interface BoostOnPriceMorpho extends Base {
|
|
127
|
+
marketId: string;
|
|
128
|
+
subHash: string;
|
|
129
|
+
}
|
|
126
130
|
interface CloseOnPriceWithMaximumGasPriceAave extends Base {
|
|
127
131
|
collAsset: EthereumAddress;
|
|
128
132
|
collAssetId: number;
|
|
@@ -134,6 +138,15 @@ export declare namespace Position {
|
|
|
134
138
|
maximumGasPrice: string;
|
|
135
139
|
ratioState: RatioState;
|
|
136
140
|
}
|
|
141
|
+
interface CloseOnPriceLiquityV2 extends Base {
|
|
142
|
+
market: EthereumAddress;
|
|
143
|
+
troveId: string;
|
|
144
|
+
stopLossPrice: string;
|
|
145
|
+
takeProfitPrice: string;
|
|
146
|
+
closeToAssetAddr: EthereumAddress;
|
|
147
|
+
stopLossType: CloseToAssetType | undefined;
|
|
148
|
+
takeProfitType: CloseToAssetType | undefined;
|
|
149
|
+
}
|
|
137
150
|
interface TrailingStop extends Base {
|
|
138
151
|
roundId: number;
|
|
139
152
|
triggerPercentage: number;
|
|
@@ -148,7 +161,7 @@ export declare namespace Position {
|
|
|
148
161
|
subHashRepay?: string;
|
|
149
162
|
}
|
|
150
163
|
}
|
|
151
|
-
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD;
|
|
164
|
+
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD | Specific.CloseOnPriceLiquityV2 | Specific.BoostOnPriceMorpho;
|
|
152
165
|
interface Automated {
|
|
153
166
|
chainId: ChainId;
|
|
154
167
|
positionId: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defisaver/automation-sdk",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.6-fluid-dev",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@defisaver/eslint-config": "^1.0.1",
|
|
27
|
-
"@defisaver/sdk": "^1.
|
|
28
|
-
"@defisaver/tokens": "^1.5.
|
|
27
|
+
"@defisaver/sdk": "^1.2.17",
|
|
28
|
+
"@defisaver/tokens": "^1.5.54",
|
|
29
29
|
"@ethersproject/address": "^5.0.10",
|
|
30
30
|
"@ethersproject/solidity": "^5.0.9",
|
|
31
31
|
"decimal.js": "^10.4.3",
|
|
@@ -19,7 +19,7 @@ import Automation from './Automation';
|
|
|
19
19
|
|
|
20
20
|
interface IStrategiesAutomation extends Interfaces.Automation {
|
|
21
21
|
chainId: ChainId,
|
|
22
|
-
providerFork
|
|
22
|
+
providerFork?: Web3,
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export default class StrategiesAutomation extends Automation {
|
|
@@ -27,7 +27,7 @@ export default class StrategiesAutomation extends Automation {
|
|
|
27
27
|
|
|
28
28
|
protected web3: Web3;
|
|
29
29
|
|
|
30
|
-
protected web3Fork
|
|
30
|
+
protected web3Fork?: Web3;
|
|
31
31
|
|
|
32
32
|
protected subStorageContract: Contract.WithMeta<SubStorage>;
|
|
33
33
|
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import Web3 from 'web3';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
|
|
4
|
+
import {ChainId} from '../../types/enums';
|
|
5
|
+
|
|
6
|
+
import '../../configuration';
|
|
7
|
+
import EthereumStrategies from './EthereumStrategies';
|
|
8
|
+
import ArbitrumStrategies from './ArbitrumStrategies';
|
|
9
|
+
import OptimismStrategies from './OptimismStrategies';
|
|
10
|
+
import BaseStrategies from './BaseStrategies';
|
|
11
|
+
|
|
12
|
+
require('dotenv').config({ path: '.env' });
|
|
13
|
+
|
|
14
|
+
const Web3_1 = new Web3(process.env.RPC_1!);
|
|
15
|
+
const Web3_42161 = new Web3(process.env.RPC_42161!);
|
|
16
|
+
const Web3_10 = new Web3(process.env.RPC_10!);
|
|
17
|
+
const Web3_8453 = new Web3(process.env.RPC_8453!);
|
|
18
|
+
|
|
19
|
+
describe('Feature: StrategiesAutomation.ts', () => {
|
|
20
|
+
describe('Fetching subscriptions', () => {
|
|
21
|
+
it('can fetch subscriptions on Mainnet', async function () {
|
|
22
|
+
this.timeout(120000);
|
|
23
|
+
const ethStrategies = new EthereumStrategies({provider: Web3_1});
|
|
24
|
+
const subs = await ethStrategies.getSubscriptions({mergeSubs: true})
|
|
25
|
+
console.log(subs.length);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('can fetch subscriptions on Arbitrum', async function () {
|
|
29
|
+
this.timeout(120000);
|
|
30
|
+
const arbiStrategies = new ArbitrumStrategies({provider: Web3_42161});
|
|
31
|
+
const subs = await arbiStrategies.getSubscriptions({mergeSubs: true})
|
|
32
|
+
console.log(subs.length);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('can fetch subscriptions on Optimism', async function () {
|
|
36
|
+
this.timeout(120000);
|
|
37
|
+
const optimismStrategies = new OptimismStrategies({provider: Web3_10});
|
|
38
|
+
const subs = await optimismStrategies.getSubscriptions({mergeSubs: true})
|
|
39
|
+
console.log(subs.length);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('can fetch subscriptions on Base', async function () {
|
|
43
|
+
this.timeout(120000);
|
|
44
|
+
const baseStrategies = new BaseStrategies({provider: Web3_8453});
|
|
45
|
+
const subs = await baseStrategies.getSubscriptions({mergeSubs: true})
|
|
46
|
+
console.log(subs.length);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
package/src/constants/index.ts
CHANGED
|
@@ -376,6 +376,46 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
|
|
|
376
376
|
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
377
377
|
protocol: PROTOCOLS.AaveV3,
|
|
378
378
|
},
|
|
379
|
+
[Bundles.MainnetIds.LIQUITY_V2_REPAY]: {
|
|
380
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_V2_REPAY,
|
|
381
|
+
strategyId: Strategies.Identifiers.Repay,
|
|
382
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
383
|
+
},
|
|
384
|
+
[Bundles.MainnetIds.LIQUITY_V2_BOOST]: {
|
|
385
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_V2_BOOST,
|
|
386
|
+
strategyId: Strategies.Identifiers.Boost,
|
|
387
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
388
|
+
},
|
|
389
|
+
[Bundles.MainnetIds.LIQUITY_V2_CLOSE]: {
|
|
390
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_V2_CLOSE,
|
|
391
|
+
strategyId: Strategies.Identifiers.CloseOnPrice,
|
|
392
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
393
|
+
},
|
|
394
|
+
[Bundles.MainnetIds.LIQUITY_V2_REPAY_ON_PRICE]: {
|
|
395
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_V2_REPAY_ON_PRICE,
|
|
396
|
+
strategyId: Strategies.Identifiers.OpenOrderFromCollateral,
|
|
397
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
398
|
+
},
|
|
399
|
+
[Bundles.MainnetIds.LIQUITY_V2_BOOST_ON_PRICE]: {
|
|
400
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_V2_BOOST_ON_PRICE,
|
|
401
|
+
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
402
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
403
|
+
},
|
|
404
|
+
[Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE]: {
|
|
405
|
+
strategyOrBundleId: Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE,
|
|
406
|
+
strategyId: Strategies.Identifiers.BoostOnPrice,
|
|
407
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
408
|
+
},
|
|
409
|
+
[Bundles.MainnetIds.FLUID_T1_REPAY]: {
|
|
410
|
+
strategyOrBundleId: Bundles.MainnetIds.FLUID_T1_REPAY,
|
|
411
|
+
strategyId: Strategies.Identifiers.Repay,
|
|
412
|
+
protocol: PROTOCOLS.FluidT1,
|
|
413
|
+
},
|
|
414
|
+
[Bundles.MainnetIds.FLUID_T2_BOOST]: {
|
|
415
|
+
strategyOrBundleId: Bundles.MainnetIds.FLUID_T2_BOOST,
|
|
416
|
+
strategyId: Strategies.Identifiers.Boost,
|
|
417
|
+
protocol: PROTOCOLS.FluidT1,
|
|
418
|
+
},
|
|
379
419
|
};
|
|
380
420
|
|
|
381
421
|
export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
|
|
@@ -462,6 +502,11 @@ export const BASE_BUNDLES_INFO: BaseBundleInfo = {
|
|
|
462
502
|
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
463
503
|
protocol: PROTOCOLS.AaveV3,
|
|
464
504
|
},
|
|
505
|
+
[Bundles.BaseIds.MORPHO_BLUE_BOOST_ON_PRICE]: {
|
|
506
|
+
strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_BOOST_ON_PRICE,
|
|
507
|
+
strategyId: Strategies.Identifiers.BoostOnPrice,
|
|
508
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
509
|
+
},
|
|
465
510
|
};
|
|
466
511
|
|
|
467
512
|
export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
|