@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
|
@@ -6,12 +6,12 @@ import type { ChainId } from '../../types/enums';
|
|
|
6
6
|
import Automation from './Automation';
|
|
7
7
|
interface IStrategiesAutomation extends Interfaces.Automation {
|
|
8
8
|
chainId: ChainId;
|
|
9
|
-
providerFork
|
|
9
|
+
providerFork?: Web3;
|
|
10
10
|
}
|
|
11
11
|
export default class StrategiesAutomation extends Automation {
|
|
12
12
|
protected chainId: ChainId;
|
|
13
13
|
protected web3: Web3;
|
|
14
|
-
protected web3Fork
|
|
14
|
+
protected web3Fork?: Web3;
|
|
15
15
|
protected subStorageContract: Contract.WithMeta<SubStorage>;
|
|
16
16
|
protected subStorageContractFork: Contract.WithMeta<SubStorage> | null;
|
|
17
17
|
constructor(args: IStrategiesAutomation);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '../../configuration';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const web3_1 = __importDefault(require("web3"));
|
|
16
|
+
require("../../configuration");
|
|
17
|
+
const EthereumStrategies_1 = __importDefault(require("./EthereumStrategies"));
|
|
18
|
+
const ArbitrumStrategies_1 = __importDefault(require("./ArbitrumStrategies"));
|
|
19
|
+
const OptimismStrategies_1 = __importDefault(require("./OptimismStrategies"));
|
|
20
|
+
const BaseStrategies_1 = __importDefault(require("./BaseStrategies"));
|
|
21
|
+
require('dotenv').config({ path: '.env' });
|
|
22
|
+
const Web3_1 = new web3_1.default(process.env.RPC_1);
|
|
23
|
+
const Web3_42161 = new web3_1.default(process.env.RPC_42161);
|
|
24
|
+
const Web3_10 = new web3_1.default(process.env.RPC_10);
|
|
25
|
+
const Web3_8453 = new web3_1.default(process.env.RPC_8453);
|
|
26
|
+
describe('Feature: StrategiesAutomation.ts', () => {
|
|
27
|
+
describe('Fetching subscriptions', () => {
|
|
28
|
+
it('can fetch subscriptions on Mainnet', function () {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
this.timeout(120000);
|
|
31
|
+
const ethStrategies = new EthereumStrategies_1.default({ provider: Web3_1 });
|
|
32
|
+
const subs = yield ethStrategies.getSubscriptions({ mergeSubs: true });
|
|
33
|
+
console.log(subs.length);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
it('can fetch subscriptions on Arbitrum', function () {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
this.timeout(120000);
|
|
39
|
+
const arbiStrategies = new ArbitrumStrategies_1.default({ provider: Web3_42161 });
|
|
40
|
+
const subs = yield arbiStrategies.getSubscriptions({ mergeSubs: true });
|
|
41
|
+
console.log(subs.length);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
it('can fetch subscriptions on Optimism', function () {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
this.timeout(120000);
|
|
47
|
+
const optimismStrategies = new OptimismStrategies_1.default({ provider: Web3_10 });
|
|
48
|
+
const subs = yield optimismStrategies.getSubscriptions({ mergeSubs: true });
|
|
49
|
+
console.log(subs.length);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
it('can fetch subscriptions on Base', function () {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
this.timeout(120000);
|
|
55
|
+
const baseStrategies = new BaseStrategies_1.default({ provider: Web3_8453 });
|
|
56
|
+
const subs = yield baseStrategies.getSubscriptions({ mergeSubs: true });
|
|
57
|
+
console.log(subs.length);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
package/cjs/constants/index.js
CHANGED
|
@@ -96,11 +96,6 @@ exports.MAINNET_STRATEGIES_INFO = {
|
|
|
96
96
|
strategyId: enums_1.Strategies.Identifiers.Payback,
|
|
97
97
|
protocol: exports.PROTOCOLS.CrvUSD,
|
|
98
98
|
},
|
|
99
|
-
[enums_1.Strategies.MainnetIds.AAVE_V3_OPEN_ORDER_FROM_DEBT]: {
|
|
100
|
-
strategyOrBundleId: enums_1.Strategies.MainnetIds.AAVE_V3_OPEN_ORDER_FROM_DEBT,
|
|
101
|
-
strategyId: enums_1.Strategies.Identifiers.OpenOrderFromDebt,
|
|
102
|
-
protocol: exports.PROTOCOLS.AaveV3,
|
|
103
|
-
},
|
|
104
99
|
};
|
|
105
100
|
exports.OPTIMISM_STRATEGIES_INFO = {
|
|
106
101
|
[enums_1.Strategies.OptimismIds.EXCHANGE_DCA]: {
|
|
@@ -113,11 +108,6 @@ exports.OPTIMISM_STRATEGIES_INFO = {
|
|
|
113
108
|
strategyId: enums_1.Strategies.Identifiers.LimitOrder,
|
|
114
109
|
protocol: exports.PROTOCOLS.Exchange,
|
|
115
110
|
},
|
|
116
|
-
[enums_1.Strategies.OptimismIds.AAVE_V3_OPEN_ORDER_FROM_DEBT]: {
|
|
117
|
-
strategyOrBundleId: enums_1.Strategies.OptimismIds.AAVE_V3_OPEN_ORDER_FROM_DEBT,
|
|
118
|
-
strategyId: enums_1.Strategies.Identifiers.OpenOrderFromDebt,
|
|
119
|
-
protocol: exports.PROTOCOLS.AaveV3,
|
|
120
|
-
},
|
|
121
111
|
};
|
|
122
112
|
exports.BASE_STRATEGIES_INFO = {
|
|
123
113
|
[enums_1.Strategies.BaseIds.EXCHANGE_DCA]: {
|
|
@@ -142,11 +132,6 @@ exports.ARBITRUM_STRATEGIES_INFO = {
|
|
|
142
132
|
strategyId: enums_1.Strategies.Identifiers.LimitOrder,
|
|
143
133
|
protocol: exports.PROTOCOLS.Exchange,
|
|
144
134
|
},
|
|
145
|
-
[enums_1.Strategies.ArbitrumIds.AAVE_V3_OPEN_ORDER_FROM_DEBT]: {
|
|
146
|
-
strategyOrBundleId: enums_1.Strategies.ArbitrumIds.AAVE_V3_OPEN_ORDER_FROM_DEBT,
|
|
147
|
-
strategyId: enums_1.Strategies.Identifiers.OpenOrderFromDebt,
|
|
148
|
-
protocol: exports.PROTOCOLS.AaveV3,
|
|
149
|
-
},
|
|
150
135
|
};
|
|
151
136
|
exports.STRATEGIES_INFO = {
|
|
152
137
|
[enums_1.ChainId.Ethereum]: exports.MAINNET_STRATEGIES_INFO,
|
|
@@ -363,6 +348,26 @@ exports.MAINNET_BUNDLES_INFO = {
|
|
|
363
348
|
strategyId: enums_1.Strategies.Identifiers.OpenOrderFromCollateral,
|
|
364
349
|
protocol: exports.PROTOCOLS.AaveV3,
|
|
365
350
|
},
|
|
351
|
+
[enums_1.Bundles.MainnetIds.AAVE_V3_REPAY_ON_PRICE]: {
|
|
352
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V3_REPAY_ON_PRICE,
|
|
353
|
+
strategyId: enums_1.Strategies.Identifiers.RepayOnPrice,
|
|
354
|
+
protocol: exports.PROTOCOLS.AaveV3,
|
|
355
|
+
},
|
|
356
|
+
[enums_1.Bundles.MainnetIds.LIQUITY_V2_REPAY]: {
|
|
357
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.LIQUITY_V2_REPAY,
|
|
358
|
+
strategyId: enums_1.Strategies.Identifiers.Repay,
|
|
359
|
+
protocol: exports.PROTOCOLS.LiquityV2,
|
|
360
|
+
},
|
|
361
|
+
[enums_1.Bundles.MainnetIds.LIQUITY_V2_BOOST]: {
|
|
362
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.LIQUITY_V2_BOOST,
|
|
363
|
+
strategyId: enums_1.Strategies.Identifiers.Boost,
|
|
364
|
+
protocol: exports.PROTOCOLS.LiquityV2,
|
|
365
|
+
},
|
|
366
|
+
[enums_1.Bundles.MainnetIds.LIQUITY_V2_CLOSE]: {
|
|
367
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.LIQUITY_V2_CLOSE,
|
|
368
|
+
strategyId: enums_1.Strategies.Identifiers.CloseOnPrice,
|
|
369
|
+
protocol: exports.PROTOCOLS.LiquityV2,
|
|
370
|
+
},
|
|
366
371
|
};
|
|
367
372
|
exports.OPTIMISM_BUNDLES_INFO = {
|
|
368
373
|
[enums_1.Bundles.OptimismIds.AAVE_V3_REPAY]: {
|
|
@@ -390,6 +395,11 @@ exports.OPTIMISM_BUNDLES_INFO = {
|
|
|
390
395
|
strategyId: enums_1.Strategies.Identifiers.OpenOrderFromCollateral,
|
|
391
396
|
protocol: exports.PROTOCOLS.AaveV3,
|
|
392
397
|
},
|
|
398
|
+
[enums_1.Bundles.OptimismIds.AAVE_V3_REPAY_ON_PRICE]: {
|
|
399
|
+
strategyOrBundleId: enums_1.Bundles.OptimismIds.AAVE_V3_REPAY_ON_PRICE,
|
|
400
|
+
strategyId: enums_1.Strategies.Identifiers.RepayOnPrice,
|
|
401
|
+
protocol: exports.PROTOCOLS.AaveV3,
|
|
402
|
+
},
|
|
393
403
|
};
|
|
394
404
|
exports.BASE_BUNDLES_INFO = {
|
|
395
405
|
[enums_1.Bundles.BaseIds.AAVE_V3_REPAY]: {
|
|
@@ -437,6 +447,11 @@ exports.BASE_BUNDLES_INFO = {
|
|
|
437
447
|
strategyId: enums_1.Strategies.Identifiers.OpenOrderFromCollateral,
|
|
438
448
|
protocol: exports.PROTOCOLS.AaveV3,
|
|
439
449
|
},
|
|
450
|
+
[enums_1.Bundles.BaseIds.AAVE_V3_REPAY_ON_PRICE]: {
|
|
451
|
+
strategyOrBundleId: enums_1.Bundles.BaseIds.AAVE_V3_REPAY_ON_PRICE,
|
|
452
|
+
strategyId: enums_1.Strategies.Identifiers.RepayOnPrice,
|
|
453
|
+
protocol: exports.PROTOCOLS.AaveV3,
|
|
454
|
+
},
|
|
440
455
|
};
|
|
441
456
|
exports.ARBITRUM_BUNDLES_INFO = {
|
|
442
457
|
[enums_1.Bundles.ArbitrumIds.AAVE_V3_REPAY]: {
|
|
@@ -474,6 +489,11 @@ exports.ARBITRUM_BUNDLES_INFO = {
|
|
|
474
489
|
strategyId: enums_1.Strategies.Identifiers.OpenOrderFromCollateral,
|
|
475
490
|
protocol: exports.PROTOCOLS.AaveV3,
|
|
476
491
|
},
|
|
492
|
+
[enums_1.Bundles.ArbitrumIds.AAVE_V3_REPAY_ON_PRICE]: {
|
|
493
|
+
strategyOrBundleId: enums_1.Bundles.ArbitrumIds.AAVE_V3_REPAY_ON_PRICE,
|
|
494
|
+
strategyId: enums_1.Strategies.Identifiers.RepayOnPrice,
|
|
495
|
+
protocol: exports.PROTOCOLS.AaveV3,
|
|
496
|
+
},
|
|
477
497
|
};
|
|
478
498
|
exports.BUNDLES_INFO = {
|
|
479
499
|
[enums_1.ChainId.Ethereum]: exports.MAINNET_BUNDLES_INFO,
|
|
@@ -429,6 +429,39 @@ function parseLiquityLeverageManagement(position, parseData) {
|
|
|
429
429
|
_position.strategy.strategyId = enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
430
430
|
return _position;
|
|
431
431
|
}
|
|
432
|
+
function parseLiquityV2LeverageManagement(position, parseData) {
|
|
433
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
434
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
435
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
436
|
+
const triggerData = triggerService.liquityV2RatioTrigger.decode(subStruct.triggerData);
|
|
437
|
+
const subData = subDataService.liquityV2LeverageManagementSubData.decode(subStruct.subData);
|
|
438
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
439
|
+
_position.strategyData.decoded.subData = subData;
|
|
440
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.troveId, triggerData.market);
|
|
441
|
+
const isRepay = _position.strategy.strategyId === enums_1.Strategies.Identifiers.Repay;
|
|
442
|
+
if (isRepay) {
|
|
443
|
+
_position.specific = {
|
|
444
|
+
triggerRepayRatio: triggerData.ratio,
|
|
445
|
+
targetRepayRatio: subData.targetRatio,
|
|
446
|
+
repayEnabled: isEnabled,
|
|
447
|
+
subId1: Number(subId),
|
|
448
|
+
subHashRepay: subHash,
|
|
449
|
+
mergeWithId: enums_1.Strategies.Identifiers.Boost,
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
else {
|
|
453
|
+
_position.specific = {
|
|
454
|
+
triggerBoostRatio: triggerData.ratio,
|
|
455
|
+
targetBoostRatio: subData.targetRatio,
|
|
456
|
+
boostEnabled: isEnabled,
|
|
457
|
+
subId2: Number(subId),
|
|
458
|
+
subHashBoost: subHash,
|
|
459
|
+
mergeId: enums_1.Strategies.Identifiers.Boost,
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
_position.strategy.strategyId = enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
463
|
+
return _position;
|
|
464
|
+
}
|
|
432
465
|
function parseSparkLeverageManagement(position, parseData) {
|
|
433
466
|
const _position = (0, lodash_1.cloneDeep)(position);
|
|
434
467
|
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
@@ -590,11 +623,11 @@ function parseMorphoBlueLeverageManagement(position, parseData) {
|
|
|
590
623
|
_position.strategy.strategyId = isEOA ? enums_1.Strategies.IdOverrides.EoaLeverageManagement : enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
591
624
|
return _position;
|
|
592
625
|
}
|
|
593
|
-
function
|
|
626
|
+
function parseAaveV3LeverageManagementOnPrice(position, parseData) {
|
|
594
627
|
const _position = (0, lodash_1.cloneDeep)(position);
|
|
595
628
|
const { subStruct } = parseData.subscriptionEventData;
|
|
596
629
|
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
597
|
-
const subData = subDataService.
|
|
630
|
+
const subData = subDataService.aaveV3LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
598
631
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
599
632
|
_position.strategyData.decoded.subData = subData;
|
|
600
633
|
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
@@ -611,6 +644,32 @@ function parseAaveV3OpenOrderFromCollateral(position, parseData) {
|
|
|
611
644
|
};
|
|
612
645
|
return _position;
|
|
613
646
|
}
|
|
647
|
+
function parseLiquityV2CloseOnPrice(position, parseData) {
|
|
648
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
649
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
650
|
+
const triggerData = triggerService.closePriceTrigger.decode(subStruct.triggerData);
|
|
651
|
+
const subData = subDataService.liquityV2CloseSubData.decode(subStruct.subData);
|
|
652
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
653
|
+
_position.strategyData.decoded.subData = subData;
|
|
654
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.troveId, subData.market);
|
|
655
|
+
const { takeProfitType, stopLossType } = (0, utils_1.getStopLossAndTakeProfitTypeByCloseStrategyType)(+subData.closeType);
|
|
656
|
+
// User can have:
|
|
657
|
+
// - Only TakeProfit
|
|
658
|
+
// - Only StopLoss
|
|
659
|
+
// - Both
|
|
660
|
+
// TODO: see on frontend what specific data we need here because stop-loss and take-profit is one bundle now
|
|
661
|
+
_position.strategy.strategyId = enums_1.Strategies.Identifiers.CloseOnPrice;
|
|
662
|
+
_position.specific = {
|
|
663
|
+
market: subData.market,
|
|
664
|
+
troveId: subData.troveId,
|
|
665
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
666
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
667
|
+
closeToAssetAddr: triggerData.tokenAddr,
|
|
668
|
+
takeProfitType,
|
|
669
|
+
stopLossType,
|
|
670
|
+
};
|
|
671
|
+
return _position;
|
|
672
|
+
}
|
|
614
673
|
const parsingMethodsMapping = {
|
|
615
674
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.MakerDAO]: {
|
|
616
675
|
[enums_1.Strategies.Identifiers.SavingsLiqProtection]: parseMakerSavingsLiqProtection,
|
|
@@ -631,6 +690,11 @@ const parsingMethodsMapping = {
|
|
|
631
690
|
[enums_1.Strategies.Identifiers.SavingsDsrSupply]: parseLiquitySavingsLiqProtection,
|
|
632
691
|
[enums_1.Strategies.Identifiers.DebtInFrontRepay]: parseLiquityDebtInFrontRepay,
|
|
633
692
|
},
|
|
693
|
+
[enums_1.ProtocolIdentifiers.StrategiesAutomation.LiquityV2]: {
|
|
694
|
+
[enums_1.Strategies.Identifiers.Repay]: parseLiquityV2LeverageManagement,
|
|
695
|
+
[enums_1.Strategies.Identifiers.Boost]: parseLiquityV2LeverageManagement,
|
|
696
|
+
[enums_1.Strategies.Identifiers.CloseOnPrice]: parseLiquityV2CloseOnPrice,
|
|
697
|
+
},
|
|
634
698
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.AaveV2]: {
|
|
635
699
|
[enums_1.Strategies.Identifiers.Repay]: parseAaveV2LeverageManagement,
|
|
636
700
|
[enums_1.Strategies.Identifiers.Boost]: parseAaveV2LeverageManagement,
|
|
@@ -642,7 +706,8 @@ const parsingMethodsMapping = {
|
|
|
642
706
|
[enums_1.Strategies.Identifiers.CloseToDebtWithGasPrice]: parseAaveV3CloseOnPriceWithMaximumGasPrice,
|
|
643
707
|
[enums_1.Strategies.Identifiers.CloseToCollateral]: parseAaveV3CloseOnPrice,
|
|
644
708
|
[enums_1.Strategies.Identifiers.CloseToCollateralWithGasPrice]: parseAaveV3CloseOnPriceWithMaximumGasPrice,
|
|
645
|
-
[enums_1.Strategies.Identifiers.OpenOrderFromCollateral]:
|
|
709
|
+
[enums_1.Strategies.Identifiers.OpenOrderFromCollateral]: parseAaveV3LeverageManagementOnPrice,
|
|
710
|
+
[enums_1.Strategies.Identifiers.RepayOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
646
711
|
},
|
|
647
712
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.CompoundV2]: {
|
|
648
713
|
[enums_1.Strategies.Identifiers.Repay]: parseCompoundV2LeverageManagement,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { OrderType } from '../types/enums';
|
|
2
|
-
import { Bundles, ChainId, RatioState, Strategies } from '../types/enums';
|
|
2
|
+
import { CloseToAssetType, Bundles, ChainId, RatioState, Strategies } from '../types/enums';
|
|
3
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)[];
|
|
@@ -47,7 +47,7 @@ export declare const aaveV3Encode: {
|
|
|
47
47
|
debtAsset: EthereumAddress;
|
|
48
48
|
debtAssetId: number;
|
|
49
49
|
}): (number | boolean | string[])[];
|
|
50
|
-
|
|
50
|
+
leverageManagementOnPrice(strategyOrBundleId: number, isBundle: boolean | undefined, triggerData: {
|
|
51
51
|
baseTokenAddress: EthereumAddress;
|
|
52
52
|
quoteTokenAddress: EthereumAddress;
|
|
53
53
|
price: number;
|
|
@@ -98,3 +98,7 @@ export declare const crvUSDEncode: {
|
|
|
98
98
|
export declare const morphoBlueEncode: {
|
|
99
99
|
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): (boolean | string[] | Bundles.MainnetIds)[] | (boolean | string[] | Bundles.BaseIds)[];
|
|
100
100
|
};
|
|
101
|
+
export declare const liquityV2Encode: {
|
|
102
|
+
leverageManagement(market: EthereumAddress, troveId: string, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
103
|
+
closeOnPrice(strategyOrBundleId: number, market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
104
|
+
};
|
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.morphoBlueEncode = exports.crvUSDEncode = exports.sparkEncode = exports.exchangeEncode = exports.morphoAaveV2Encode = exports.compoundV3L2Encode = exports.compoundV3Encode = exports.compoundV2Encode = exports.aaveV3Encode = exports.aaveV2Encode = exports.chickenBondsEncode = exports.liquityEncode = exports.makerEncode = void 0;
|
|
29
|
+
exports.liquityV2Encode = exports.morphoBlueEncode = exports.crvUSDEncode = exports.sparkEncode = exports.exchangeEncode = exports.morphoAaveV2Encode = exports.compoundV3L2Encode = exports.compoundV3Encode = exports.compoundV2Encode = exports.aaveV3Encode = exports.aaveV2Encode = exports.chickenBondsEncode = exports.liquityEncode = exports.makerEncode = void 0;
|
|
30
30
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
31
31
|
const tokens_1 = require("@defisaver/tokens");
|
|
32
32
|
const enums_1 = require("../types/enums");
|
|
@@ -168,9 +168,9 @@ exports.aaveV3Encode = {
|
|
|
168
168
|
const triggerDataEncoded = triggerService.aaveV3QuotePriceWithMaximumGasPriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, ratioState, maximumGasPrice);
|
|
169
169
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
170
170
|
},
|
|
171
|
-
|
|
171
|
+
leverageManagementOnPrice(strategyOrBundleId, isBundle = true, triggerData, subData) {
|
|
172
172
|
const { collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio, } = subData;
|
|
173
|
-
const subDataEncoded = subDataService.
|
|
173
|
+
const subDataEncoded = subDataService.aaveV3LeverageManagementOnPriceSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio);
|
|
174
174
|
const { baseTokenAddress, quoteTokenAddress, price, state, } = triggerData;
|
|
175
175
|
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
176
176
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
@@ -265,3 +265,25 @@ exports.morphoBlueEncode = {
|
|
|
265
265
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
266
266
|
},
|
|
267
267
|
};
|
|
268
|
+
exports.liquityV2Encode = {
|
|
269
|
+
leverageManagement(market, troveId, ratioState, targetRatio, triggerRatio, strategyOrBundleId) {
|
|
270
|
+
const isBundle = true;
|
|
271
|
+
const isRepay = ratioState === enums_1.RatioState.UNDER;
|
|
272
|
+
const subData = subDataService.liquityV2LeverageManagementSubData.encode(market, troveId, ratioState, targetRatio);
|
|
273
|
+
const triggerData = triggerService.liquityV2RatioTrigger.encode(market, troveId, triggerRatio, ratioState);
|
|
274
|
+
// TODO: we can hardcode right bundles after testing
|
|
275
|
+
// const strategyOrBundleId = ratioState === RatioState.OVER
|
|
276
|
+
// ? Bundles.MainnetIds.LIQUITY_V2_BOOST
|
|
277
|
+
// : Bundles.MainnetIds.LIQUITY_V2_REPAY;
|
|
278
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
279
|
+
},
|
|
280
|
+
closeOnPrice(strategyOrBundleId, market, troveId, collToken, boldToken, stopLossPrice = 0, stopLossType = enums_1.CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = enums_1.CloseToAssetType.COLLATERAL) {
|
|
281
|
+
const isBundle = true;
|
|
282
|
+
const closeType = (0, utils_1.getCloseStrategyType)(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
283
|
+
const subData = subDataService.liquityV2CloseSubData.encode(market, troveId, collToken, boldToken, closeType);
|
|
284
|
+
const triggerData = triggerService.closePriceTrigger.encode(collToken, stopLossPrice, takeProfitPrice);
|
|
285
|
+
// TODO: we can hardcode bundleID after testing
|
|
286
|
+
// Bundles.MainnetIds.LIQUITY_V2_CLOSE;
|
|
287
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
288
|
+
},
|
|
289
|
+
};
|
|
@@ -454,7 +454,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
454
454
|
});
|
|
455
455
|
});
|
|
456
456
|
});
|
|
457
|
-
describe('
|
|
457
|
+
describe('leverageManagementOnPrice()', () => {
|
|
458
458
|
const examples = [
|
|
459
459
|
[
|
|
460
460
|
[
|
|
@@ -490,7 +490,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
490
490
|
];
|
|
491
491
|
examples.forEach(([expected, actual]) => {
|
|
492
492
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
493
|
-
(0, chai_1.expect)(strategySubService_1.aaveV3Encode.
|
|
493
|
+
(0, chai_1.expect)(strategySubService_1.aaveV3Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
494
494
|
});
|
|
495
495
|
});
|
|
496
496
|
});
|
|
@@ -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 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.sparkQuotePriceSubData = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = exports.compoundV3L2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.liquityRepayFromSavingsSubData = exports.makerRepayFromSavingsSubData = void 0;
|
|
7
7
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
8
|
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
9
9
|
const web3_utils_1 = require("web3-utils");
|
|
@@ -441,7 +441,7 @@ exports.morphoBlueLeverageManagementSubData = {
|
|
|
441
441
|
};
|
|
442
442
|
},
|
|
443
443
|
};
|
|
444
|
-
exports.
|
|
444
|
+
exports.aaveV3LeverageManagementOnPriceSubData = {
|
|
445
445
|
encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio) {
|
|
446
446
|
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
447
447
|
const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
|
|
@@ -473,3 +473,57 @@ exports.aaveV3OpenOrderSubData = {
|
|
|
473
473
|
};
|
|
474
474
|
},
|
|
475
475
|
};
|
|
476
|
+
exports.liquityV2LeverageManagementSubData = {
|
|
477
|
+
encode: (market, troveId, ratioState, targetRatio) => {
|
|
478
|
+
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
479
|
+
const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
480
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
481
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
482
|
+
const isRepay = ratioState === enums_1.RatioState.UNDER;
|
|
483
|
+
const collActionType = isRepay ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
|
|
484
|
+
const debtActionType = isRepay ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
|
|
485
|
+
const collActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
|
|
486
|
+
const debtActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
|
|
487
|
+
return [marketEncoded, troveIdEncoded, ratioStateEncoded, targetRatioEncoded, collActionTypeEncoded, debtActionTypeEncoded];
|
|
488
|
+
},
|
|
489
|
+
decode: (subData) => {
|
|
490
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
491
|
+
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
492
|
+
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[2]);
|
|
493
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
494
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
495
|
+
return {
|
|
496
|
+
market, troveId, ratioState, targetRatio,
|
|
497
|
+
};
|
|
498
|
+
},
|
|
499
|
+
};
|
|
500
|
+
exports.liquityV2CloseSubData = {
|
|
501
|
+
encode(market, troveId, collToken, boldToken, closeType) {
|
|
502
|
+
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
503
|
+
const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
504
|
+
const collAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
505
|
+
const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
506
|
+
const wethAddress = (0, tokens_1.getAssetInfo)('WETH').address;
|
|
507
|
+
const wethAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', wethAddress);
|
|
508
|
+
const closeTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', closeType);
|
|
509
|
+
return [
|
|
510
|
+
marketEncoded,
|
|
511
|
+
troveIdEncoded,
|
|
512
|
+
collAddrEncoded,
|
|
513
|
+
boldTokenEncoded,
|
|
514
|
+
wethAddressEncoded,
|
|
515
|
+
closeTypeEncoded,
|
|
516
|
+
];
|
|
517
|
+
},
|
|
518
|
+
decode(subData) {
|
|
519
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
520
|
+
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
521
|
+
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
522
|
+
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
523
|
+
// skip wethAddress
|
|
524
|
+
const closeType = web3_eth_abi_1.default.decodeParameter('uint8', subData[5]);
|
|
525
|
+
return {
|
|
526
|
+
market, troveId, collToken, boldToken, closeType,
|
|
527
|
+
};
|
|
528
|
+
},
|
|
529
|
+
};
|
|
@@ -1222,7 +1222,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1222
1222
|
});
|
|
1223
1223
|
});
|
|
1224
1224
|
});
|
|
1225
|
-
describe('When testing subDataService.
|
|
1225
|
+
describe('When testing subDataService.aaveV3LeverageManagementOnPriceSubData', () => {
|
|
1226
1226
|
describe('encode()', () => {
|
|
1227
1227
|
const examples = [
|
|
1228
1228
|
[
|
|
@@ -1247,7 +1247,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1247
1247
|
];
|
|
1248
1248
|
examples.forEach(([expected, actual]) => {
|
|
1249
1249
|
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1250
|
-
(0, chai_1.expect)(subDataService_1.
|
|
1250
|
+
(0, chai_1.expect)(subDataService_1.aaveV3LeverageManagementOnPriceSubData.encode(...actual)).to.eql(expected);
|
|
1251
1251
|
});
|
|
1252
1252
|
});
|
|
1253
1253
|
});
|
|
@@ -1274,7 +1274,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1274
1274
|
];
|
|
1275
1275
|
examples.forEach(([expected, actual]) => {
|
|
1276
1276
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1277
|
-
(0, chai_1.expect)(subDataService_1.
|
|
1277
|
+
(0, chai_1.expect)(subDataService_1.aaveV3LeverageManagementOnPriceSubData.decode(actual)).to.eql(expected);
|
|
1278
1278
|
});
|
|
1279
1279
|
});
|
|
1280
1280
|
});
|
|
@@ -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
|
+
};
|
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.morphoBlueRatioTrigger = exports.crvUsdHealthRatioTrigger = exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkQuotePriceTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
|
|
29
|
+
exports.closePriceTrigger = exports.liquityV2RatioTrigger = exports.morphoBlueRatioTrigger = exports.crvUsdHealthRatioTrigger = exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkQuotePriceTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
|
|
30
30
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
31
31
|
const tokens_1 = require("@defisaver/tokens");
|
|
32
32
|
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
@@ -365,3 +365,35 @@ exports.morphoBlueRatioTrigger = {
|
|
|
365
365
|
};
|
|
366
366
|
},
|
|
367
367
|
};
|
|
368
|
+
exports.liquityV2RatioTrigger = {
|
|
369
|
+
encode(market, troveId, ratioPercentage, ratioState) {
|
|
370
|
+
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
371
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint256', 'uint8'], [market, troveId, ratioWei, ratioState])];
|
|
372
|
+
},
|
|
373
|
+
decode(triggerData) {
|
|
374
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint256', 'uint8'], triggerData[0]);
|
|
375
|
+
return {
|
|
376
|
+
market: decodedData[0],
|
|
377
|
+
troveId: decodedData[1],
|
|
378
|
+
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[2]),
|
|
379
|
+
ratioState: Number(decodedData[3]),
|
|
380
|
+
};
|
|
381
|
+
},
|
|
382
|
+
};
|
|
383
|
+
exports.closePriceTrigger = {
|
|
384
|
+
encode(tokenAddr, lowerPrice, upperPrice) {
|
|
385
|
+
const lowerPriceFormatted = new decimal_js_1.default(lowerPrice).mul(1e8).floor().toString();
|
|
386
|
+
const upperPriceFormatted = new decimal_js_1.default(upperPrice).mul(1e8).floor().toString();
|
|
387
|
+
return [
|
|
388
|
+
web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint256'], [tokenAddr, lowerPriceFormatted, upperPriceFormatted]),
|
|
389
|
+
];
|
|
390
|
+
},
|
|
391
|
+
decode(triggerData) {
|
|
392
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint256'], triggerData[0]);
|
|
393
|
+
return {
|
|
394
|
+
tokenAddr: decodedData[0],
|
|
395
|
+
lowerPrice: new decimal_js_1.default(decodedData[1]).div(1e8).toString(),
|
|
396
|
+
upperPrice: new decimal_js_1.default(decodedData[2]).div(1e8).toString(),
|
|
397
|
+
};
|
|
398
|
+
},
|
|
399
|
+
};
|
package/cjs/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
|
+
};
|