@defisaver/automation-sdk 3.1.3 → 3.1.4-dev-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/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 +35 -15
- package/cjs/services/strategiesService.js +68 -3
- package/cjs/services/strategySubService.d.ts +6 -2
- package/cjs/services/strategySubService.js +25 -3
- package/cjs/services/strategySubService.test.js +2 -2
- package/cjs/services/subDataService.d.ts +21 -2
- package/cjs/services/subDataService.js +56 -2
- package/cjs/services/subDataService.test.js +3 -3
- package/cjs/services/triggerService.d.ts +17 -0
- package/cjs/services/triggerService.js +33 -1
- package/cjs/services/utils.d.ts +6 -1
- package/cjs/services/utils.js +52 -1
- package/cjs/types/enums.d.ts +40 -11
- package/cjs/types/enums.js +37 -4
- package/cjs/types/index.d.ts +12 -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 +35 -15
- package/esm/services/strategiesService.js +69 -4
- package/esm/services/strategySubService.d.ts +6 -2
- package/esm/services/strategySubService.js +26 -4
- package/esm/services/strategySubService.test.js +2 -2
- package/esm/services/subDataService.d.ts +21 -2
- package/esm/services/subDataService.js +56 -2
- package/esm/services/subDataService.test.js +4 -4
- package/esm/services/triggerService.d.ts +17 -0
- package/esm/services/triggerService.js +32 -0
- package/esm/services/utils.d.ts +6 -1
- package/esm/services/utils.js +50 -1
- package/esm/types/enums.d.ts +40 -11
- package/esm/types/enums.js +36 -3
- package/esm/types/index.d.ts +12 -3
- package/package.json +1 -1
- package/src/automation/private/StrategiesAutomation.ts +2 -2
- package/src/automation/public/Strategies.test.ts +49 -0
- package/src/constants/index.ts +47 -16
- package/src/services/strategiesService.ts +89 -4
- package/src/services/strategySubService.test.ts +2 -2
- package/src/services/strategySubService.ts +52 -3
- package/src/services/subDataService.test.ts +4 -4
- package/src/services/subDataService.ts +85 -4
- package/src/services/triggerService.ts +53 -0
- package/src/services/utils.ts +60 -1
- package/src/types/enums.ts +36 -3
- package/src/types/index.ts +14 -2
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import { getAssetInfo } from '@defisaver/tokens';
|
|
3
|
-
import { Bundles, ChainId, RatioState, Strategies, } from '../types/enums';
|
|
3
|
+
import { CloseToAssetType, Bundles, ChainId, RatioState, Strategies, } from '../types/enums';
|
|
4
4
|
import { STRATEGY_IDS } from '../constants';
|
|
5
5
|
import * as subDataService from './subDataService';
|
|
6
6
|
import * as triggerService from './triggerService';
|
|
7
|
-
import { compareAddresses, requireAddress, requireAddresses } from './utils';
|
|
7
|
+
import { compareAddresses, getCloseStrategyType, requireAddress, requireAddresses, } from './utils';
|
|
8
8
|
export const makerEncode = {
|
|
9
9
|
repayFromSavings(bundleId, vaultId, triggerRepayRatio, targetRepayRatio, isBundle = true, chainId = ChainId.Ethereum, daiAddr, mcdCdpManagerAddr) {
|
|
10
10
|
const subData = subDataService.makerRepayFromSavingsSubData.encode(vaultId, targetRepayRatio, chainId, daiAddr, mcdCdpManagerAddr);
|
|
@@ -139,9 +139,9 @@ export const aaveV3Encode = {
|
|
|
139
139
|
const triggerDataEncoded = triggerService.aaveV3QuotePriceWithMaximumGasPriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, ratioState, maximumGasPrice);
|
|
140
140
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
141
141
|
},
|
|
142
|
-
|
|
142
|
+
leverageManagementOnPrice(strategyOrBundleId, isBundle = true, triggerData, subData) {
|
|
143
143
|
const { collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio, } = subData;
|
|
144
|
-
const subDataEncoded = subDataService.
|
|
144
|
+
const subDataEncoded = subDataService.aaveV3LeverageManagementOnPriceSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio);
|
|
145
145
|
const { baseTokenAddress, quoteTokenAddress, price, state, } = triggerData;
|
|
146
146
|
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
147
147
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
@@ -236,3 +236,25 @@ export const morphoBlueEncode = {
|
|
|
236
236
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
237
237
|
},
|
|
238
238
|
};
|
|
239
|
+
export const liquityV2Encode = {
|
|
240
|
+
leverageManagement(market, troveId, ratioState, targetRatio, triggerRatio, strategyOrBundleId) {
|
|
241
|
+
const isBundle = true;
|
|
242
|
+
const isRepay = ratioState === RatioState.UNDER;
|
|
243
|
+
const subData = subDataService.liquityV2LeverageManagementSubData.encode(market, troveId, ratioState, targetRatio);
|
|
244
|
+
const triggerData = triggerService.liquityV2RatioTrigger.encode(market, troveId, triggerRatio, ratioState);
|
|
245
|
+
// TODO: we can hardcode right bundles after testing
|
|
246
|
+
// const strategyOrBundleId = ratioState === RatioState.OVER
|
|
247
|
+
// ? Bundles.MainnetIds.LIQUITY_V2_BOOST
|
|
248
|
+
// : Bundles.MainnetIds.LIQUITY_V2_REPAY;
|
|
249
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
250
|
+
},
|
|
251
|
+
closeOnPrice(strategyOrBundleId, market, troveId, collToken, boldToken, stopLossPrice = 0, stopLossType = CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = CloseToAssetType.COLLATERAL) {
|
|
252
|
+
const isBundle = true;
|
|
253
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
254
|
+
const subData = subDataService.liquityV2CloseSubData.encode(market, troveId, collToken, boldToken, closeType);
|
|
255
|
+
const triggerData = triggerService.closePriceTrigger.encode(collToken, stopLossPrice, takeProfitPrice);
|
|
256
|
+
// TODO: we can hardcode bundleID after testing
|
|
257
|
+
// Bundles.MainnetIds.LIQUITY_V2_CLOSE;
|
|
258
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
259
|
+
},
|
|
260
|
+
};
|
|
@@ -426,7 +426,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
426
426
|
});
|
|
427
427
|
});
|
|
428
428
|
});
|
|
429
|
-
describe('
|
|
429
|
+
describe('leverageManagementOnPrice()', () => {
|
|
430
430
|
const examples = [
|
|
431
431
|
[
|
|
432
432
|
[
|
|
@@ -462,7 +462,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
462
462
|
];
|
|
463
463
|
examples.forEach(([expected, actual]) => {
|
|
464
464
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
465
|
-
expect(aaveV3Encode.
|
|
465
|
+
expect(aaveV3Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
466
466
|
});
|
|
467
467
|
});
|
|
468
468
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EthereumAddress } from '../types';
|
|
2
|
-
import type { OrderType } from '../types/enums';
|
|
2
|
+
import type { CloseStrategyType, OrderType } from '../types/enums';
|
|
3
3
|
import { ChainId, RatioState } from '../types/enums';
|
|
4
4
|
export declare const makerRepayFromSavingsSubData: {
|
|
5
5
|
encode(vaultId: number, targetRatioPercentage: number, chainId: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress): string[];
|
|
@@ -179,7 +179,7 @@ export declare const morphoBlueLeverageManagementSubData: {
|
|
|
179
179
|
targetRatio: number;
|
|
180
180
|
};
|
|
181
181
|
};
|
|
182
|
-
export declare const
|
|
182
|
+
export declare const aaveV3LeverageManagementOnPriceSubData: {
|
|
183
183
|
encode(collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number): string[];
|
|
184
184
|
decode(subData: string[]): {
|
|
185
185
|
collAsset: EthereumAddress;
|
|
@@ -190,3 +190,22 @@ export declare const aaveV3OpenOrderSubData: {
|
|
|
190
190
|
targetRatio: number;
|
|
191
191
|
};
|
|
192
192
|
};
|
|
193
|
+
export declare const liquityV2LeverageManagementSubData: {
|
|
194
|
+
encode: (market: EthereumAddress, troveId: string, ratioState: RatioState, targetRatio: number) => string[];
|
|
195
|
+
decode: (subData: string[]) => {
|
|
196
|
+
market: string;
|
|
197
|
+
troveId: string;
|
|
198
|
+
ratioState: RatioState;
|
|
199
|
+
targetRatio: number;
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
export declare const liquityV2CloseSubData: {
|
|
203
|
+
encode(market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, closeType: CloseStrategyType): string[];
|
|
204
|
+
decode(subData: string[]): {
|
|
205
|
+
market: EthereumAddress;
|
|
206
|
+
troveId: string;
|
|
207
|
+
collToken: EthereumAddress;
|
|
208
|
+
boldToken: EthereumAddress;
|
|
209
|
+
closeType: CloseStrategyType;
|
|
210
|
+
};
|
|
211
|
+
};
|
|
@@ -3,7 +3,7 @@ import AbiCoder from 'web3-eth-abi';
|
|
|
3
3
|
import { fromWei, toWei } from 'web3-utils';
|
|
4
4
|
import { assetAmountInEth, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
5
5
|
import { otherAddresses } from '@defisaver/sdk';
|
|
6
|
-
import { ChainId, RatioState } from '../types/enums';
|
|
6
|
+
import { ChainId, CollActionType, DebtActionType, RatioState, } from '../types/enums';
|
|
7
7
|
import { ZERO_ADDRESS } from '../constants';
|
|
8
8
|
import { compareAddresses, ratioPercentageToWei, weiToRatioPercentage } from './utils';
|
|
9
9
|
export const makerRepayFromSavingsSubData = {
|
|
@@ -435,7 +435,7 @@ export const morphoBlueLeverageManagementSubData = {
|
|
|
435
435
|
};
|
|
436
436
|
},
|
|
437
437
|
};
|
|
438
|
-
export const
|
|
438
|
+
export const aaveV3LeverageManagementOnPriceSubData = {
|
|
439
439
|
encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio) {
|
|
440
440
|
const encodedColl = AbiCoder.encodeParameter('address', collAsset);
|
|
441
441
|
const encodedCollId = AbiCoder.encodeParameter('uint8', collAssetId);
|
|
@@ -467,3 +467,57 @@ export const aaveV3OpenOrderSubData = {
|
|
|
467
467
|
};
|
|
468
468
|
},
|
|
469
469
|
};
|
|
470
|
+
export const liquityV2LeverageManagementSubData = {
|
|
471
|
+
encode: (market, troveId, ratioState, targetRatio) => {
|
|
472
|
+
const marketEncoded = AbiCoder.encodeParameter('address', market);
|
|
473
|
+
const troveIdEncoded = AbiCoder.encodeParameter('uint256', troveId);
|
|
474
|
+
const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
|
|
475
|
+
const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
476
|
+
const isRepay = ratioState === RatioState.UNDER;
|
|
477
|
+
const collActionType = isRepay ? CollActionType.WITHDRAW : CollActionType.SUPPLY;
|
|
478
|
+
const debtActionType = isRepay ? DebtActionType.PAYBACK : DebtActionType.BORROW;
|
|
479
|
+
const collActionTypeEncoded = AbiCoder.encodeParameter('uint8', collActionType);
|
|
480
|
+
const debtActionTypeEncoded = AbiCoder.encodeParameter('uint8', debtActionType);
|
|
481
|
+
return [marketEncoded, troveIdEncoded, ratioStateEncoded, targetRatioEncoded, collActionTypeEncoded, debtActionTypeEncoded];
|
|
482
|
+
},
|
|
483
|
+
decode: (subData) => {
|
|
484
|
+
const market = AbiCoder.decodeParameter('address', subData[0]);
|
|
485
|
+
const troveId = AbiCoder.decodeParameter('uint256', subData[1]);
|
|
486
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[2]);
|
|
487
|
+
const weiRatio = AbiCoder.decodeParameter('uint256', subData[3]);
|
|
488
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
489
|
+
return {
|
|
490
|
+
market, troveId, ratioState, targetRatio,
|
|
491
|
+
};
|
|
492
|
+
},
|
|
493
|
+
};
|
|
494
|
+
export const liquityV2CloseSubData = {
|
|
495
|
+
encode(market, troveId, collToken, boldToken, closeType) {
|
|
496
|
+
const marketEncoded = AbiCoder.encodeParameter('address', market);
|
|
497
|
+
const troveIdEncoded = AbiCoder.encodeParameter('uint256', troveId);
|
|
498
|
+
const collAddrEncoded = AbiCoder.encodeParameter('address', collToken);
|
|
499
|
+
const boldTokenEncoded = AbiCoder.encodeParameter('address', boldToken);
|
|
500
|
+
const wethAddress = getAssetInfo('WETH').address;
|
|
501
|
+
const wethAddressEncoded = AbiCoder.encodeParameter('address', wethAddress);
|
|
502
|
+
const closeTypeEncoded = AbiCoder.encodeParameter('uint8', closeType);
|
|
503
|
+
return [
|
|
504
|
+
marketEncoded,
|
|
505
|
+
troveIdEncoded,
|
|
506
|
+
collAddrEncoded,
|
|
507
|
+
boldTokenEncoded,
|
|
508
|
+
wethAddressEncoded,
|
|
509
|
+
closeTypeEncoded,
|
|
510
|
+
];
|
|
511
|
+
},
|
|
512
|
+
decode(subData) {
|
|
513
|
+
const market = AbiCoder.decodeParameter('address', subData[0]);
|
|
514
|
+
const troveId = AbiCoder.decodeParameter('uint256', subData[1]);
|
|
515
|
+
const collToken = AbiCoder.decodeParameter('address', subData[2]);
|
|
516
|
+
const boldToken = AbiCoder.decodeParameter('address', subData[3]);
|
|
517
|
+
// skip wethAddress
|
|
518
|
+
const closeType = AbiCoder.decodeParameter('uint8', subData[5]);
|
|
519
|
+
return {
|
|
520
|
+
market, troveId, collToken, boldToken, closeType,
|
|
521
|
+
};
|
|
522
|
+
},
|
|
523
|
+
};
|
|
@@ -4,7 +4,7 @@ import { getAssetInfo } from '@defisaver/tokens';
|
|
|
4
4
|
import * as web3Utils from 'web3-utils';
|
|
5
5
|
import { ChainId, OrderType, RatioState } from '../types/enums';
|
|
6
6
|
import '../configuration';
|
|
7
|
-
import { aaveV2LeverageManagementSubData, aaveV3LeverageManagementSubData, aaveV3QuotePriceSubData, cBondsRebondSubData, compoundV2LeverageManagementSubData, compoundV3LeverageManagementSubData, exchangeDcaSubData, exchangeLimitOrderSubData, liquityCloseSubData, liquityDebtInFrontRepaySubData, liquityDsrPaybackSubData, liquityDsrSupplySubData, liquityLeverageManagementSubData, liquityPaybackUsingChickenBondSubData, liquityRepayFromSavingsSubData, makerCloseSubData, makerLeverageManagementSubData, makerRepayFromSavingsSubData, morphoAaveV2LeverageManagementSubData, sparkLeverageManagementSubData, sparkQuotePriceSubData, crvUSDLeverageManagementSubData, compoundV3L2LeverageManagementSubData, morphoBlueLeverageManagementSubData, crvUSDPaybackSubData,
|
|
7
|
+
import { aaveV2LeverageManagementSubData, aaveV3LeverageManagementSubData, aaveV3QuotePriceSubData, cBondsRebondSubData, compoundV2LeverageManagementSubData, compoundV3LeverageManagementSubData, exchangeDcaSubData, exchangeLimitOrderSubData, liquityCloseSubData, liquityDebtInFrontRepaySubData, liquityDsrPaybackSubData, liquityDsrSupplySubData, liquityLeverageManagementSubData, liquityPaybackUsingChickenBondSubData, liquityRepayFromSavingsSubData, makerCloseSubData, makerLeverageManagementSubData, makerRepayFromSavingsSubData, morphoAaveV2LeverageManagementSubData, sparkLeverageManagementSubData, sparkQuotePriceSubData, crvUSDLeverageManagementSubData, compoundV3L2LeverageManagementSubData, morphoBlueLeverageManagementSubData, crvUSDPaybackSubData, aaveV3LeverageManagementOnPriceSubData, } from './subDataService';
|
|
8
8
|
describe('Feature: subDataService.ts', () => {
|
|
9
9
|
describe('When testing subDataService.makerRepayFromSavingsSubData', () => {
|
|
10
10
|
describe('encode()', () => {
|
|
@@ -1194,7 +1194,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1194
1194
|
});
|
|
1195
1195
|
});
|
|
1196
1196
|
});
|
|
1197
|
-
describe('When testing subDataService.
|
|
1197
|
+
describe('When testing subDataService.aaveV3LeverageManagementOnPriceSubData', () => {
|
|
1198
1198
|
describe('encode()', () => {
|
|
1199
1199
|
const examples = [
|
|
1200
1200
|
[
|
|
@@ -1219,7 +1219,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1219
1219
|
];
|
|
1220
1220
|
examples.forEach(([expected, actual]) => {
|
|
1221
1221
|
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1222
|
-
expect(
|
|
1222
|
+
expect(aaveV3LeverageManagementOnPriceSubData.encode(...actual)).to.eql(expected);
|
|
1223
1223
|
});
|
|
1224
1224
|
});
|
|
1225
1225
|
});
|
|
@@ -1246,7 +1246,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1246
1246
|
];
|
|
1247
1247
|
examples.forEach(([expected, actual]) => {
|
|
1248
1248
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1249
|
-
expect(
|
|
1249
|
+
expect(aaveV3LeverageManagementOnPriceSubData.decode(actual)).to.eql(expected);
|
|
1250
1250
|
});
|
|
1251
1251
|
});
|
|
1252
1252
|
});
|
|
@@ -189,3 +189,20 @@ 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 closePriceTrigger: {
|
|
202
|
+
encode(tokenAddr: EthereumAddress, lowerPrice: number, upperPrice: number): string[];
|
|
203
|
+
decode(triggerData: string[]): {
|
|
204
|
+
tokenAddr: EthereumAddress;
|
|
205
|
+
lowerPrice: string;
|
|
206
|
+
upperPrice: string;
|
|
207
|
+
};
|
|
208
|
+
};
|
|
@@ -336,3 +336,35 @@ 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 closePriceTrigger = {
|
|
355
|
+
encode(tokenAddr, lowerPrice, upperPrice) {
|
|
356
|
+
const lowerPriceFormatted = new Dec(lowerPrice).mul(1e8).floor().toString();
|
|
357
|
+
const upperPriceFormatted = new Dec(upperPrice).mul(1e8).floor().toString();
|
|
358
|
+
return [
|
|
359
|
+
AbiCoder.encodeParameters(['address', 'uint256', 'uint256'], [tokenAddr, lowerPriceFormatted, upperPriceFormatted]),
|
|
360
|
+
];
|
|
361
|
+
},
|
|
362
|
+
decode(triggerData) {
|
|
363
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint256'], triggerData[0]);
|
|
364
|
+
return {
|
|
365
|
+
tokenAddr: decodedData[0],
|
|
366
|
+
lowerPrice: new Dec(decodedData[1]).div(1e8).toString(),
|
|
367
|
+
upperPrice: new Dec(decodedData[2]).div(1e8).toString(),
|
|
368
|
+
};
|
|
369
|
+
},
|
|
370
|
+
};
|
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",
|
|
@@ -60,13 +83,11 @@ export declare namespace Strategies {
|
|
|
60
83
|
LIQUITY_DSR_PAYBACK = 69,
|
|
61
84
|
LIQUITY_DSR_SUPPLY = 70,
|
|
62
85
|
LIQUITY_DEBT_IN_FRONT_REPAY = 75,
|
|
63
|
-
CURVEUSD_PAYBACK = 92
|
|
64
|
-
AAVE_V3_OPEN_ORDER_FROM_DEBT = 96
|
|
86
|
+
CURVEUSD_PAYBACK = 92
|
|
65
87
|
}
|
|
66
88
|
enum OptimismIds {
|
|
67
89
|
EXCHANGE_DCA = 8,
|
|
68
|
-
EXCHANGE_LIMIT_ORDER = 9
|
|
69
|
-
AAVE_V3_OPEN_ORDER_FROM_DEBT = 12
|
|
90
|
+
EXCHANGE_LIMIT_ORDER = 9
|
|
70
91
|
}
|
|
71
92
|
enum BaseIds {
|
|
72
93
|
EXCHANGE_DCA = 8,
|
|
@@ -74,8 +95,7 @@ export declare namespace Strategies {
|
|
|
74
95
|
}
|
|
75
96
|
enum ArbitrumIds {
|
|
76
97
|
EXCHANGE_DCA = 8,
|
|
77
|
-
EXCHANGE_LIMIT_ORDER = 9
|
|
78
|
-
AAVE_V3_OPEN_ORDER_FROM_DEBT = 16
|
|
98
|
+
EXCHANGE_LIMIT_ORDER = 9
|
|
79
99
|
}
|
|
80
100
|
enum Identifiers {
|
|
81
101
|
SavingsLiqProtection = "smart-savings-liquidation-protection",
|
|
@@ -91,6 +111,7 @@ export declare namespace Strategies {
|
|
|
91
111
|
CloseToCollateralWithGasPrice = "close-to-collateral-with-gas-price",
|
|
92
112
|
CloseOnPriceToDebt = "close-on-price-to-debt",
|
|
93
113
|
CloseOnPriceToColl = "close-on-price-to-collateral",
|
|
114
|
+
CloseOnPrice = "close-on-price",
|
|
94
115
|
TrailingStopToColl = "trailing-stop-to-collateral",
|
|
95
116
|
TrailingStopToDebt = "trailing-stop-to-debt",
|
|
96
117
|
Rebond = "rebond",
|
|
@@ -100,7 +121,8 @@ export declare namespace Strategies {
|
|
|
100
121
|
LimitOrder = "limit-order",
|
|
101
122
|
DebtInFrontRepay = "debt-in-front-repay",
|
|
102
123
|
OpenOrderFromCollateral = "open-order-from-collateral",
|
|
103
|
-
OpenOrderFromDebt = "open-order-from-debt"
|
|
124
|
+
OpenOrderFromDebt = "open-order-from-debt",
|
|
125
|
+
RepayOnPrice = "repay-on-price"
|
|
104
126
|
}
|
|
105
127
|
enum IdOverrides {
|
|
106
128
|
TakeProfit = "take-profit",
|
|
@@ -152,14 +174,19 @@ export declare namespace Bundles {
|
|
|
152
174
|
MORPHO_BLUE_BOOST = 33,
|
|
153
175
|
MORPHO_BLUE_EOA_REPAY = 34,
|
|
154
176
|
MORPHO_BLUE_EOA_BOOST = 35,
|
|
155
|
-
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 36
|
|
177
|
+
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 36,
|
|
178
|
+
AAVE_V3_REPAY_ON_PRICE = 37,
|
|
179
|
+
LIQUITY_V2_REPAY = 38,
|
|
180
|
+
LIQUITY_V2_BOOST = 39,
|
|
181
|
+
LIQUITY_V2_CLOSE = 40
|
|
156
182
|
}
|
|
157
183
|
enum OptimismIds {
|
|
158
184
|
AAVE_V3_REPAY = 0,
|
|
159
185
|
AAVE_V3_BOOST = 1,
|
|
160
186
|
AAVE_V3_CLOSE_TO_DEBT = 2,
|
|
161
187
|
AAVE_V3_CLOSE_TO_COLLATERAL = 3,
|
|
162
|
-
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 4
|
|
188
|
+
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 4,
|
|
189
|
+
AAVE_V3_REPAY_ON_PRICE = 5
|
|
163
190
|
}
|
|
164
191
|
enum BaseIds {
|
|
165
192
|
AAVE_V3_REPAY = 0,
|
|
@@ -170,7 +197,8 @@ export declare namespace Bundles {
|
|
|
170
197
|
COMP_V3_SW_BOOST_BUNDLE = 5,
|
|
171
198
|
MORPHO_BLUE_REPAY = 8,
|
|
172
199
|
MORPHO_BLUE_BOOST = 9,
|
|
173
|
-
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 10
|
|
200
|
+
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 10,
|
|
201
|
+
AAVE_V3_REPAY_ON_PRICE = 11
|
|
174
202
|
}
|
|
175
203
|
enum ArbitrumIds {
|
|
176
204
|
AAVE_V3_REPAY = 0,
|
|
@@ -179,6 +207,7 @@ export declare namespace Bundles {
|
|
|
179
207
|
AAVE_V3_CLOSE_TO_COLLATERAL = 3,
|
|
180
208
|
COMP_V3_SW_REPAY_BUNDLE = 4,
|
|
181
209
|
COMP_V3_SW_BOOST_BUNDLE = 5,
|
|
182
|
-
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 6
|
|
210
|
+
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 6,
|
|
211
|
+
AAVE_V3_REPAY_ON_PRICE = 7
|
|
183
212
|
}
|
|
184
213
|
}
|
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";
|
|
@@ -70,13 +97,11 @@ export var Strategies;
|
|
|
70
97
|
MainnetIds[MainnetIds["LIQUITY_DSR_SUPPLY"] = 70] = "LIQUITY_DSR_SUPPLY";
|
|
71
98
|
MainnetIds[MainnetIds["LIQUITY_DEBT_IN_FRONT_REPAY"] = 75] = "LIQUITY_DEBT_IN_FRONT_REPAY";
|
|
72
99
|
MainnetIds[MainnetIds["CURVEUSD_PAYBACK"] = 92] = "CURVEUSD_PAYBACK";
|
|
73
|
-
MainnetIds[MainnetIds["AAVE_V3_OPEN_ORDER_FROM_DEBT"] = 96] = "AAVE_V3_OPEN_ORDER_FROM_DEBT";
|
|
74
100
|
})(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
|
|
75
101
|
let OptimismIds;
|
|
76
102
|
(function (OptimismIds) {
|
|
77
103
|
OptimismIds[OptimismIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
78
104
|
OptimismIds[OptimismIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
79
|
-
OptimismIds[OptimismIds["AAVE_V3_OPEN_ORDER_FROM_DEBT"] = 12] = "AAVE_V3_OPEN_ORDER_FROM_DEBT";
|
|
80
105
|
})(OptimismIds = Strategies.OptimismIds || (Strategies.OptimismIds = {}));
|
|
81
106
|
let BaseIds;
|
|
82
107
|
(function (BaseIds) {
|
|
@@ -87,7 +112,6 @@ export var Strategies;
|
|
|
87
112
|
(function (ArbitrumIds) {
|
|
88
113
|
ArbitrumIds[ArbitrumIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
89
114
|
ArbitrumIds[ArbitrumIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
90
|
-
ArbitrumIds[ArbitrumIds["AAVE_V3_OPEN_ORDER_FROM_DEBT"] = 16] = "AAVE_V3_OPEN_ORDER_FROM_DEBT";
|
|
91
115
|
})(ArbitrumIds = Strategies.ArbitrumIds || (Strategies.ArbitrumIds = {}));
|
|
92
116
|
let Identifiers;
|
|
93
117
|
(function (Identifiers) {
|
|
@@ -104,6 +128,7 @@ export var Strategies;
|
|
|
104
128
|
Identifiers["CloseToCollateralWithGasPrice"] = "close-to-collateral-with-gas-price";
|
|
105
129
|
Identifiers["CloseOnPriceToDebt"] = "close-on-price-to-debt";
|
|
106
130
|
Identifiers["CloseOnPriceToColl"] = "close-on-price-to-collateral";
|
|
131
|
+
Identifiers["CloseOnPrice"] = "close-on-price";
|
|
107
132
|
Identifiers["TrailingStopToColl"] = "trailing-stop-to-collateral";
|
|
108
133
|
Identifiers["TrailingStopToDebt"] = "trailing-stop-to-debt";
|
|
109
134
|
Identifiers["Rebond"] = "rebond";
|
|
@@ -114,6 +139,7 @@ export var Strategies;
|
|
|
114
139
|
Identifiers["DebtInFrontRepay"] = "debt-in-front-repay";
|
|
115
140
|
Identifiers["OpenOrderFromCollateral"] = "open-order-from-collateral";
|
|
116
141
|
Identifiers["OpenOrderFromDebt"] = "open-order-from-debt";
|
|
142
|
+
Identifiers["RepayOnPrice"] = "repay-on-price";
|
|
117
143
|
})(Identifiers = Strategies.Identifiers || (Strategies.Identifiers = {}));
|
|
118
144
|
let IdOverrides;
|
|
119
145
|
(function (IdOverrides) {
|
|
@@ -169,6 +195,10 @@ export var Bundles;
|
|
|
169
195
|
MainnetIds[MainnetIds["MORPHO_BLUE_EOA_REPAY"] = 34] = "MORPHO_BLUE_EOA_REPAY";
|
|
170
196
|
MainnetIds[MainnetIds["MORPHO_BLUE_EOA_BOOST"] = 35] = "MORPHO_BLUE_EOA_BOOST";
|
|
171
197
|
MainnetIds[MainnetIds["AAVE_V3_OPEN_ORDER_FROM_COLLATERAL"] = 36] = "AAVE_V3_OPEN_ORDER_FROM_COLLATERAL";
|
|
198
|
+
MainnetIds[MainnetIds["AAVE_V3_REPAY_ON_PRICE"] = 37] = "AAVE_V3_REPAY_ON_PRICE";
|
|
199
|
+
MainnetIds[MainnetIds["LIQUITY_V2_REPAY"] = 38] = "LIQUITY_V2_REPAY";
|
|
200
|
+
MainnetIds[MainnetIds["LIQUITY_V2_BOOST"] = 39] = "LIQUITY_V2_BOOST";
|
|
201
|
+
MainnetIds[MainnetIds["LIQUITY_V2_CLOSE"] = 40] = "LIQUITY_V2_CLOSE";
|
|
172
202
|
})(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
|
|
173
203
|
let OptimismIds;
|
|
174
204
|
(function (OptimismIds) {
|
|
@@ -177,6 +207,7 @@ export var Bundles;
|
|
|
177
207
|
OptimismIds[OptimismIds["AAVE_V3_CLOSE_TO_DEBT"] = 2] = "AAVE_V3_CLOSE_TO_DEBT";
|
|
178
208
|
OptimismIds[OptimismIds["AAVE_V3_CLOSE_TO_COLLATERAL"] = 3] = "AAVE_V3_CLOSE_TO_COLLATERAL";
|
|
179
209
|
OptimismIds[OptimismIds["AAVE_V3_OPEN_ORDER_FROM_COLLATERAL"] = 4] = "AAVE_V3_OPEN_ORDER_FROM_COLLATERAL";
|
|
210
|
+
OptimismIds[OptimismIds["AAVE_V3_REPAY_ON_PRICE"] = 5] = "AAVE_V3_REPAY_ON_PRICE";
|
|
180
211
|
})(OptimismIds = Bundles.OptimismIds || (Bundles.OptimismIds = {}));
|
|
181
212
|
let BaseIds;
|
|
182
213
|
(function (BaseIds) {
|
|
@@ -189,6 +220,7 @@ export var Bundles;
|
|
|
189
220
|
BaseIds[BaseIds["MORPHO_BLUE_REPAY"] = 8] = "MORPHO_BLUE_REPAY";
|
|
190
221
|
BaseIds[BaseIds["MORPHO_BLUE_BOOST"] = 9] = "MORPHO_BLUE_BOOST";
|
|
191
222
|
BaseIds[BaseIds["AAVE_V3_OPEN_ORDER_FROM_COLLATERAL"] = 10] = "AAVE_V3_OPEN_ORDER_FROM_COLLATERAL";
|
|
223
|
+
BaseIds[BaseIds["AAVE_V3_REPAY_ON_PRICE"] = 11] = "AAVE_V3_REPAY_ON_PRICE";
|
|
192
224
|
})(BaseIds = Bundles.BaseIds || (Bundles.BaseIds = {}));
|
|
193
225
|
let ArbitrumIds;
|
|
194
226
|
(function (ArbitrumIds) {
|
|
@@ -199,5 +231,6 @@ export var Bundles;
|
|
|
199
231
|
ArbitrumIds[ArbitrumIds["COMP_V3_SW_REPAY_BUNDLE"] = 4] = "COMP_V3_SW_REPAY_BUNDLE";
|
|
200
232
|
ArbitrumIds[ArbitrumIds["COMP_V3_SW_BOOST_BUNDLE"] = 5] = "COMP_V3_SW_BOOST_BUNDLE";
|
|
201
233
|
ArbitrumIds[ArbitrumIds["AAVE_V3_OPEN_ORDER_FROM_COLLATERAL"] = 6] = "AAVE_V3_OPEN_ORDER_FROM_COLLATERAL";
|
|
234
|
+
ArbitrumIds[ArbitrumIds["AAVE_V3_REPAY_ON_PRICE"] = 7] = "AAVE_V3_REPAY_ON_PRICE";
|
|
202
235
|
})(ArbitrumIds = Bundles.ArbitrumIds || (Bundles.ArbitrumIds = {}));
|
|
203
236
|
})(Bundles || (Bundles = {}));
|
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;
|
|
@@ -134,6 +134,15 @@ export declare namespace Position {
|
|
|
134
134
|
maximumGasPrice: string;
|
|
135
135
|
ratioState: RatioState;
|
|
136
136
|
}
|
|
137
|
+
interface CloseOnPriceLiquityV2 extends Base {
|
|
138
|
+
market: EthereumAddress;
|
|
139
|
+
troveId: string;
|
|
140
|
+
stopLossPrice: string;
|
|
141
|
+
takeProfitPrice: string;
|
|
142
|
+
closeToAssetAddr: EthereumAddress;
|
|
143
|
+
stopLossType: CloseToAssetType | undefined;
|
|
144
|
+
takeProfitType: CloseToAssetType | undefined;
|
|
145
|
+
}
|
|
137
146
|
interface TrailingStop extends Base {
|
|
138
147
|
roundId: number;
|
|
139
148
|
triggerPercentage: number;
|
|
@@ -148,7 +157,7 @@ export declare namespace Position {
|
|
|
148
157
|
subHashRepay?: string;
|
|
149
158
|
}
|
|
150
159
|
}
|
|
151
|
-
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD;
|
|
160
|
+
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD | Specific.CloseOnPriceLiquityV2;
|
|
152
161
|
interface Automated {
|
|
153
162
|
chainId: ChainId;
|
|
154
163
|
positionId: string;
|