@defisaver/automation-sdk 3.1.8 → 3.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/constants/index.js +5 -0
- package/cjs/services/strategiesService.js +19 -0
- package/cjs/services/strategySubService.d.ts +1 -0
- package/cjs/services/strategySubService.js +7 -0
- package/cjs/services/subDataService.d.ts +10 -0
- package/cjs/services/subDataService.js +28 -1
- package/cjs/types/enums.d.ts +2 -1
- package/cjs/types/enums.js +1 -0
- package/cjs/types/index.d.ts +7 -1
- package/esm/constants/index.js +5 -0
- package/esm/services/strategiesService.js +19 -0
- package/esm/services/strategySubService.d.ts +1 -0
- package/esm/services/strategySubService.js +7 -0
- package/esm/services/subDataService.d.ts +10 -0
- package/esm/services/subDataService.js +27 -0
- package/esm/types/enums.d.ts +2 -1
- package/esm/types/enums.js +1 -0
- package/esm/types/index.d.ts +7 -1
- package/package.json +1 -1
- package/src/constants/index.ts +5 -0
- package/src/services/strategiesService.ts +24 -0
- package/src/services/strategySubService.ts +17 -1
- package/src/services/subDataService.ts +35 -0
- package/src/types/enums.ts +1 -0
- package/src/types/index.ts +9 -1
package/cjs/constants/index.js
CHANGED
|
@@ -96,6 +96,11 @@ 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.LIQUITY_V2_PAYBACK]: {
|
|
100
|
+
strategyOrBundleId: enums_1.Strategies.MainnetIds.LIQUITY_V2_PAYBACK,
|
|
101
|
+
strategyId: enums_1.Strategies.Identifiers.Payback,
|
|
102
|
+
protocol: exports.PROTOCOLS.LiquityV2,
|
|
103
|
+
},
|
|
99
104
|
};
|
|
100
105
|
exports.OPTIMISM_STRATEGIES_INFO = {
|
|
101
106
|
[enums_1.Strategies.OptimismIds.EXCHANGE_DCA]: {
|
|
@@ -721,6 +721,24 @@ function parseLiquityV2LeverageManagementOnPrice(position, parseData) {
|
|
|
721
721
|
};
|
|
722
722
|
return _position;
|
|
723
723
|
}
|
|
724
|
+
function parseLiquityV2Payback(position, parseData) {
|
|
725
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
726
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
727
|
+
const triggerData = triggerService.liquityV2RatioTrigger.decode(subStruct.triggerData);
|
|
728
|
+
const subData = subDataService.liquityV2PaybackSubData.decode(subStruct.subData);
|
|
729
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
730
|
+
_position.strategyData.decoded.subData = subData;
|
|
731
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.troveId, triggerData.market);
|
|
732
|
+
_position.strategy.strategyId = enums_1.Strategies.Identifiers.Payback;
|
|
733
|
+
_position.specific = {
|
|
734
|
+
subHash: _position.subHash,
|
|
735
|
+
market: subData.market,
|
|
736
|
+
troveId: subData.troveId,
|
|
737
|
+
targetRatio: subData.targetRatio,
|
|
738
|
+
triggerRatio: triggerData.ratio,
|
|
739
|
+
};
|
|
740
|
+
return _position;
|
|
741
|
+
}
|
|
724
742
|
const parsingMethodsMapping = {
|
|
725
743
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.MakerDAO]: {
|
|
726
744
|
[enums_1.Strategies.Identifiers.SavingsLiqProtection]: parseMakerSavingsLiqProtection,
|
|
@@ -747,6 +765,7 @@ const parsingMethodsMapping = {
|
|
|
747
765
|
[enums_1.Strategies.Identifiers.CloseOnPrice]: parseLiquityV2CloseOnPrice,
|
|
748
766
|
[enums_1.Strategies.Identifiers.BoostOnPrice]: parseLiquityV2LeverageManagementOnPrice,
|
|
749
767
|
[enums_1.Strategies.Identifiers.RepayOnPrice]: parseLiquityV2LeverageManagementOnPrice,
|
|
768
|
+
[enums_1.Strategies.Identifiers.Payback]: parseLiquityV2Payback,
|
|
750
769
|
},
|
|
751
770
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.AaveV2]: {
|
|
752
771
|
[enums_1.Strategies.Identifiers.Repay]: parseAaveV2LeverageManagement,
|
|
@@ -103,4 +103,5 @@ export declare const liquityV2Encode: {
|
|
|
103
103
|
leverageManagement(market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
104
104
|
closeOnPrice(strategyOrBundleId: number, market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
105
105
|
leverageManagementOnPrice(strategyOrBundleId: number, market: EthereumAddress, price: number, state: RatioState, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, targetRatio: number, isRepayOnPrice: boolean): (number | boolean | string[])[];
|
|
106
|
+
payback(market: EthereumAddress, troveId: string, boldToken: EthereumAddress, targetRatio: number, ratioState: RatioState, triggerRatio: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
106
107
|
};
|
|
@@ -290,4 +290,11 @@ exports.liquityV2Encode = {
|
|
|
290
290
|
const isBundle = true;
|
|
291
291
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
292
292
|
},
|
|
293
|
+
payback(market, troveId, boldToken, targetRatio, ratioState, triggerRatio) {
|
|
294
|
+
const strategyId = enums_1.Strategies.MainnetIds.LIQUITY_V2_PAYBACK;
|
|
295
|
+
const isBundle = false;
|
|
296
|
+
const subData = subDataService.liquityV2PaybackSubData.encode(market, troveId, boldToken, targetRatio, ratioState);
|
|
297
|
+
const triggerData = triggerService.liquityV2RatioTrigger.encode(market, troveId, triggerRatio, ratioState);
|
|
298
|
+
return [strategyId, isBundle, triggerData, subData];
|
|
299
|
+
},
|
|
293
300
|
};
|
|
@@ -233,3 +233,13 @@ export declare const morphoBlueLeverageManagementOnPriceSubData: {
|
|
|
233
233
|
user: string;
|
|
234
234
|
};
|
|
235
235
|
};
|
|
236
|
+
export declare const liquityV2PaybackSubData: {
|
|
237
|
+
encode: (market: EthereumAddress, troveId: string, boldToken: EthereumAddress, targetRatio: number, ratioState: RatioState) => string[];
|
|
238
|
+
decode: (subData: string[]) => {
|
|
239
|
+
market: string;
|
|
240
|
+
troveId: string;
|
|
241
|
+
boldToken: string;
|
|
242
|
+
ratioState: RatioState;
|
|
243
|
+
targetRatio: number;
|
|
244
|
+
};
|
|
245
|
+
};
|
|
@@ -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.morphoBlueLeverageManagementOnPriceSubData = exports.liquityV2LeverageManagementOnPriceSubData = 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;
|
|
6
|
+
exports.liquityV2PaybackSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.liquityV2LeverageManagementOnPriceSubData = 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");
|
|
@@ -607,3 +607,30 @@ exports.morphoBlueLeverageManagementOnPriceSubData = {
|
|
|
607
607
|
};
|
|
608
608
|
},
|
|
609
609
|
};
|
|
610
|
+
exports.liquityV2PaybackSubData = {
|
|
611
|
+
encode: (market, troveId, boldToken, targetRatio, ratioState) => {
|
|
612
|
+
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
613
|
+
const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
614
|
+
const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
615
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
616
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
617
|
+
return [
|
|
618
|
+
marketEncoded,
|
|
619
|
+
troveIdEncoded,
|
|
620
|
+
boldTokenEncoded,
|
|
621
|
+
targetRatioEncoded,
|
|
622
|
+
ratioStateEncoded,
|
|
623
|
+
];
|
|
624
|
+
},
|
|
625
|
+
decode: (subData) => {
|
|
626
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
627
|
+
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
628
|
+
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
629
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
630
|
+
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[4]);
|
|
631
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
632
|
+
return {
|
|
633
|
+
market, troveId, boldToken, ratioState, targetRatio,
|
|
634
|
+
};
|
|
635
|
+
},
|
|
636
|
+
};
|
package/cjs/types/enums.d.ts
CHANGED
|
@@ -83,7 +83,8 @@ export declare namespace Strategies {
|
|
|
83
83
|
LIQUITY_DSR_PAYBACK = 69,
|
|
84
84
|
LIQUITY_DSR_SUPPLY = 70,
|
|
85
85
|
LIQUITY_DEBT_IN_FRONT_REPAY = 75,
|
|
86
|
-
CURVEUSD_PAYBACK = 92
|
|
86
|
+
CURVEUSD_PAYBACK = 92,
|
|
87
|
+
LIQUITY_V2_PAYBACK = 113
|
|
87
88
|
}
|
|
88
89
|
enum OptimismIds {
|
|
89
90
|
EXCHANGE_DCA = 8,
|
package/cjs/types/enums.js
CHANGED
|
@@ -100,6 +100,7 @@ var Strategies;
|
|
|
100
100
|
MainnetIds[MainnetIds["LIQUITY_DSR_SUPPLY"] = 70] = "LIQUITY_DSR_SUPPLY";
|
|
101
101
|
MainnetIds[MainnetIds["LIQUITY_DEBT_IN_FRONT_REPAY"] = 75] = "LIQUITY_DEBT_IN_FRONT_REPAY";
|
|
102
102
|
MainnetIds[MainnetIds["CURVEUSD_PAYBACK"] = 92] = "CURVEUSD_PAYBACK";
|
|
103
|
+
MainnetIds[MainnetIds["LIQUITY_V2_PAYBACK"] = 113] = "LIQUITY_V2_PAYBACK";
|
|
103
104
|
})(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
|
|
104
105
|
let OptimismIds;
|
|
105
106
|
(function (OptimismIds) {
|
package/cjs/types/index.d.ts
CHANGED
|
@@ -152,6 +152,12 @@ export declare namespace Position {
|
|
|
152
152
|
troveId: string;
|
|
153
153
|
subHash: string;
|
|
154
154
|
}
|
|
155
|
+
interface PaybackLiquityV2 extends Base {
|
|
156
|
+
market: EthereumAddress;
|
|
157
|
+
troveId: string;
|
|
158
|
+
targetRatio: number;
|
|
159
|
+
triggerRatio: number;
|
|
160
|
+
}
|
|
155
161
|
interface TrailingStop extends Base {
|
|
156
162
|
roundId: number;
|
|
157
163
|
triggerPercentage: number;
|
|
@@ -166,7 +172,7 @@ export declare namespace Position {
|
|
|
166
172
|
subHashRepay?: string;
|
|
167
173
|
}
|
|
168
174
|
}
|
|
169
|
-
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD | Specific.CloseOnPriceLiquityV2 | Specific.BoostOnPriceMorpho | Specific.BoostOnPriceLiquityV2;
|
|
175
|
+
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD | Specific.CloseOnPriceLiquityV2 | Specific.BoostOnPriceMorpho | Specific.BoostOnPriceLiquityV2 | Specific.PaybackLiquityV2;
|
|
170
176
|
interface Automated {
|
|
171
177
|
chainId: ChainId;
|
|
172
178
|
positionId: string;
|
package/esm/constants/index.js
CHANGED
|
@@ -90,6 +90,11 @@ export const MAINNET_STRATEGIES_INFO = {
|
|
|
90
90
|
strategyId: Strategies.Identifiers.Payback,
|
|
91
91
|
protocol: PROTOCOLS.CrvUSD,
|
|
92
92
|
},
|
|
93
|
+
[Strategies.MainnetIds.LIQUITY_V2_PAYBACK]: {
|
|
94
|
+
strategyOrBundleId: Strategies.MainnetIds.LIQUITY_V2_PAYBACK,
|
|
95
|
+
strategyId: Strategies.Identifiers.Payback,
|
|
96
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
97
|
+
},
|
|
93
98
|
};
|
|
94
99
|
export const OPTIMISM_STRATEGIES_INFO = {
|
|
95
100
|
[Strategies.OptimismIds.EXCHANGE_DCA]: {
|
|
@@ -692,6 +692,24 @@ function parseLiquityV2LeverageManagementOnPrice(position, parseData) {
|
|
|
692
692
|
};
|
|
693
693
|
return _position;
|
|
694
694
|
}
|
|
695
|
+
function parseLiquityV2Payback(position, parseData) {
|
|
696
|
+
const _position = cloneDeep(position);
|
|
697
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
698
|
+
const triggerData = triggerService.liquityV2RatioTrigger.decode(subStruct.triggerData);
|
|
699
|
+
const subData = subDataService.liquityV2PaybackSubData.decode(subStruct.subData);
|
|
700
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
701
|
+
_position.strategyData.decoded.subData = subData;
|
|
702
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.troveId, triggerData.market);
|
|
703
|
+
_position.strategy.strategyId = Strategies.Identifiers.Payback;
|
|
704
|
+
_position.specific = {
|
|
705
|
+
subHash: _position.subHash,
|
|
706
|
+
market: subData.market,
|
|
707
|
+
troveId: subData.troveId,
|
|
708
|
+
targetRatio: subData.targetRatio,
|
|
709
|
+
triggerRatio: triggerData.ratio,
|
|
710
|
+
};
|
|
711
|
+
return _position;
|
|
712
|
+
}
|
|
695
713
|
const parsingMethodsMapping = {
|
|
696
714
|
[ProtocolIdentifiers.StrategiesAutomation.MakerDAO]: {
|
|
697
715
|
[Strategies.Identifiers.SavingsLiqProtection]: parseMakerSavingsLiqProtection,
|
|
@@ -718,6 +736,7 @@ const parsingMethodsMapping = {
|
|
|
718
736
|
[Strategies.Identifiers.CloseOnPrice]: parseLiquityV2CloseOnPrice,
|
|
719
737
|
[Strategies.Identifiers.BoostOnPrice]: parseLiquityV2LeverageManagementOnPrice,
|
|
720
738
|
[Strategies.Identifiers.RepayOnPrice]: parseLiquityV2LeverageManagementOnPrice,
|
|
739
|
+
[Strategies.Identifiers.Payback]: parseLiquityV2Payback,
|
|
721
740
|
},
|
|
722
741
|
[ProtocolIdentifiers.StrategiesAutomation.AaveV2]: {
|
|
723
742
|
[Strategies.Identifiers.Repay]: parseAaveV2LeverageManagement,
|
|
@@ -103,4 +103,5 @@ export declare const liquityV2Encode: {
|
|
|
103
103
|
leverageManagement(market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
104
104
|
closeOnPrice(strategyOrBundleId: number, market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
105
105
|
leverageManagementOnPrice(strategyOrBundleId: number, market: EthereumAddress, price: number, state: RatioState, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, targetRatio: number, isRepayOnPrice: boolean): (number | boolean | string[])[];
|
|
106
|
+
payback(market: EthereumAddress, troveId: string, boldToken: EthereumAddress, targetRatio: number, ratioState: RatioState, triggerRatio: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
106
107
|
};
|
|
@@ -261,4 +261,11 @@ export const liquityV2Encode = {
|
|
|
261
261
|
const isBundle = true;
|
|
262
262
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
263
263
|
},
|
|
264
|
+
payback(market, troveId, boldToken, targetRatio, ratioState, triggerRatio) {
|
|
265
|
+
const strategyId = Strategies.MainnetIds.LIQUITY_V2_PAYBACK;
|
|
266
|
+
const isBundle = false;
|
|
267
|
+
const subData = subDataService.liquityV2PaybackSubData.encode(market, troveId, boldToken, targetRatio, ratioState);
|
|
268
|
+
const triggerData = triggerService.liquityV2RatioTrigger.encode(market, troveId, triggerRatio, ratioState);
|
|
269
|
+
return [strategyId, isBundle, triggerData, subData];
|
|
270
|
+
},
|
|
264
271
|
};
|
|
@@ -233,3 +233,13 @@ export declare const morphoBlueLeverageManagementOnPriceSubData: {
|
|
|
233
233
|
user: string;
|
|
234
234
|
};
|
|
235
235
|
};
|
|
236
|
+
export declare const liquityV2PaybackSubData: {
|
|
237
|
+
encode: (market: EthereumAddress, troveId: string, boldToken: EthereumAddress, targetRatio: number, ratioState: RatioState) => string[];
|
|
238
|
+
decode: (subData: string[]) => {
|
|
239
|
+
market: string;
|
|
240
|
+
troveId: string;
|
|
241
|
+
boldToken: string;
|
|
242
|
+
ratioState: RatioState;
|
|
243
|
+
targetRatio: number;
|
|
244
|
+
};
|
|
245
|
+
};
|
|
@@ -601,3 +601,30 @@ export const morphoBlueLeverageManagementOnPriceSubData = {
|
|
|
601
601
|
};
|
|
602
602
|
},
|
|
603
603
|
};
|
|
604
|
+
export const liquityV2PaybackSubData = {
|
|
605
|
+
encode: (market, troveId, boldToken, targetRatio, ratioState) => {
|
|
606
|
+
const marketEncoded = AbiCoder.encodeParameter('address', market);
|
|
607
|
+
const troveIdEncoded = AbiCoder.encodeParameter('uint256', troveId);
|
|
608
|
+
const boldTokenEncoded = AbiCoder.encodeParameter('address', boldToken);
|
|
609
|
+
const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
610
|
+
const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
|
|
611
|
+
return [
|
|
612
|
+
marketEncoded,
|
|
613
|
+
troveIdEncoded,
|
|
614
|
+
boldTokenEncoded,
|
|
615
|
+
targetRatioEncoded,
|
|
616
|
+
ratioStateEncoded,
|
|
617
|
+
];
|
|
618
|
+
},
|
|
619
|
+
decode: (subData) => {
|
|
620
|
+
const market = AbiCoder.decodeParameter('address', subData[0]);
|
|
621
|
+
const troveId = AbiCoder.decodeParameter('uint256', subData[1]);
|
|
622
|
+
const boldToken = AbiCoder.decodeParameter('address', subData[2]);
|
|
623
|
+
const weiRatio = AbiCoder.decodeParameter('uint256', subData[3]);
|
|
624
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[4]);
|
|
625
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
626
|
+
return {
|
|
627
|
+
market, troveId, boldToken, ratioState, targetRatio,
|
|
628
|
+
};
|
|
629
|
+
},
|
|
630
|
+
};
|
package/esm/types/enums.d.ts
CHANGED
|
@@ -83,7 +83,8 @@ export declare namespace Strategies {
|
|
|
83
83
|
LIQUITY_DSR_PAYBACK = 69,
|
|
84
84
|
LIQUITY_DSR_SUPPLY = 70,
|
|
85
85
|
LIQUITY_DEBT_IN_FRONT_REPAY = 75,
|
|
86
|
-
CURVEUSD_PAYBACK = 92
|
|
86
|
+
CURVEUSD_PAYBACK = 92,
|
|
87
|
+
LIQUITY_V2_PAYBACK = 113
|
|
87
88
|
}
|
|
88
89
|
enum OptimismIds {
|
|
89
90
|
EXCHANGE_DCA = 8,
|
package/esm/types/enums.js
CHANGED
|
@@ -97,6 +97,7 @@ export var Strategies;
|
|
|
97
97
|
MainnetIds[MainnetIds["LIQUITY_DSR_SUPPLY"] = 70] = "LIQUITY_DSR_SUPPLY";
|
|
98
98
|
MainnetIds[MainnetIds["LIQUITY_DEBT_IN_FRONT_REPAY"] = 75] = "LIQUITY_DEBT_IN_FRONT_REPAY";
|
|
99
99
|
MainnetIds[MainnetIds["CURVEUSD_PAYBACK"] = 92] = "CURVEUSD_PAYBACK";
|
|
100
|
+
MainnetIds[MainnetIds["LIQUITY_V2_PAYBACK"] = 113] = "LIQUITY_V2_PAYBACK";
|
|
100
101
|
})(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
|
|
101
102
|
let OptimismIds;
|
|
102
103
|
(function (OptimismIds) {
|
package/esm/types/index.d.ts
CHANGED
|
@@ -152,6 +152,12 @@ export declare namespace Position {
|
|
|
152
152
|
troveId: string;
|
|
153
153
|
subHash: string;
|
|
154
154
|
}
|
|
155
|
+
interface PaybackLiquityV2 extends Base {
|
|
156
|
+
market: EthereumAddress;
|
|
157
|
+
troveId: string;
|
|
158
|
+
targetRatio: number;
|
|
159
|
+
triggerRatio: number;
|
|
160
|
+
}
|
|
155
161
|
interface TrailingStop extends Base {
|
|
156
162
|
roundId: number;
|
|
157
163
|
triggerPercentage: number;
|
|
@@ -166,7 +172,7 @@ export declare namespace Position {
|
|
|
166
172
|
subHashRepay?: string;
|
|
167
173
|
}
|
|
168
174
|
}
|
|
169
|
-
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD | Specific.CloseOnPriceLiquityV2 | Specific.BoostOnPriceMorpho | Specific.BoostOnPriceLiquityV2;
|
|
175
|
+
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD | Specific.CloseOnPriceLiquityV2 | Specific.BoostOnPriceMorpho | Specific.BoostOnPriceLiquityV2 | Specific.PaybackLiquityV2;
|
|
170
176
|
interface Automated {
|
|
171
177
|
chainId: ChainId;
|
|
172
178
|
positionId: string;
|
package/package.json
CHANGED
package/src/constants/index.ts
CHANGED
|
@@ -113,6 +113,11 @@ export const MAINNET_STRATEGIES_INFO: MainnetStrategiesInfo = {
|
|
|
113
113
|
strategyId: Strategies.Identifiers.Payback,
|
|
114
114
|
protocol: PROTOCOLS.CrvUSD,
|
|
115
115
|
},
|
|
116
|
+
[Strategies.MainnetIds.LIQUITY_V2_PAYBACK]: {
|
|
117
|
+
strategyOrBundleId: Strategies.MainnetIds.LIQUITY_V2_PAYBACK,
|
|
118
|
+
strategyId: Strategies.Identifiers.Payback,
|
|
119
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
120
|
+
},
|
|
116
121
|
};
|
|
117
122
|
|
|
118
123
|
export const OPTIMISM_STRATEGIES_INFO: OptimismStrategiesInfo = {
|
|
@@ -950,6 +950,29 @@ function parseLiquityV2LeverageManagementOnPrice(position: Position.Automated, p
|
|
|
950
950
|
return _position;
|
|
951
951
|
}
|
|
952
952
|
|
|
953
|
+
function parseLiquityV2Payback(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
954
|
+
const _position = cloneDeep(position);
|
|
955
|
+
|
|
956
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
957
|
+
const triggerData = triggerService.liquityV2RatioTrigger.decode(subStruct.triggerData);
|
|
958
|
+
const subData = subDataService.liquityV2PaybackSubData.decode(subStruct.subData);
|
|
959
|
+
|
|
960
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
961
|
+
_position.strategyData.decoded.subData = subData;
|
|
962
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.troveId, triggerData.market);
|
|
963
|
+
_position.strategy.strategyId = Strategies.Identifiers.Payback;
|
|
964
|
+
|
|
965
|
+
_position.specific = {
|
|
966
|
+
subHash: _position.subHash,
|
|
967
|
+
market: subData.market,
|
|
968
|
+
troveId: subData.troveId,
|
|
969
|
+
targetRatio: subData.targetRatio,
|
|
970
|
+
triggerRatio: triggerData.ratio,
|
|
971
|
+
};
|
|
972
|
+
|
|
973
|
+
return _position;
|
|
974
|
+
}
|
|
975
|
+
|
|
953
976
|
const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
954
977
|
[ProtocolIdentifiers.StrategiesAutomation.MakerDAO]: {
|
|
955
978
|
[Strategies.Identifiers.SavingsLiqProtection]: parseMakerSavingsLiqProtection,
|
|
@@ -976,6 +999,7 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
|
976
999
|
[Strategies.Identifiers.CloseOnPrice]: parseLiquityV2CloseOnPrice,
|
|
977
1000
|
[Strategies.Identifiers.BoostOnPrice]: parseLiquityV2LeverageManagementOnPrice,
|
|
978
1001
|
[Strategies.Identifiers.RepayOnPrice]: parseLiquityV2LeverageManagementOnPrice,
|
|
1002
|
+
[Strategies.Identifiers.Payback]: parseLiquityV2Payback,
|
|
979
1003
|
},
|
|
980
1004
|
[ProtocolIdentifiers.StrategiesAutomation.AaveV2]: {
|
|
981
1005
|
[Strategies.Identifiers.Repay]: parseAaveV2LeverageManagement,
|
|
@@ -598,4 +598,20 @@ export const liquityV2Encode = {
|
|
|
598
598
|
const isBundle = true;
|
|
599
599
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
600
600
|
},
|
|
601
|
-
|
|
601
|
+
payback(
|
|
602
|
+
market: EthereumAddress,
|
|
603
|
+
troveId: string,
|
|
604
|
+
boldToken: EthereumAddress,
|
|
605
|
+
targetRatio: number,
|
|
606
|
+
ratioState: RatioState,
|
|
607
|
+
triggerRatio: number,
|
|
608
|
+
) {
|
|
609
|
+
const strategyId = Strategies.MainnetIds.LIQUITY_V2_PAYBACK;
|
|
610
|
+
const isBundle = false;
|
|
611
|
+
|
|
612
|
+
const subData = subDataService.liquityV2PaybackSubData.encode(market, troveId, boldToken, targetRatio, ratioState);
|
|
613
|
+
const triggerData = triggerService.liquityV2RatioTrigger.encode(market, troveId, triggerRatio, ratioState);
|
|
614
|
+
|
|
615
|
+
return [strategyId, isBundle, triggerData, subData];
|
|
616
|
+
},
|
|
617
|
+
};
|
|
@@ -833,3 +833,38 @@ export const morphoBlueLeverageManagementOnPriceSubData = {
|
|
|
833
833
|
};
|
|
834
834
|
},
|
|
835
835
|
};
|
|
836
|
+
export const liquityV2PaybackSubData = {
|
|
837
|
+
encode: (
|
|
838
|
+
market: EthereumAddress,
|
|
839
|
+
troveId: string,
|
|
840
|
+
boldToken: EthereumAddress,
|
|
841
|
+
targetRatio: number,
|
|
842
|
+
ratioState: RatioState,
|
|
843
|
+
) => {
|
|
844
|
+
const marketEncoded = AbiCoder.encodeParameter('address', market);
|
|
845
|
+
const troveIdEncoded = AbiCoder.encodeParameter('uint256', troveId);
|
|
846
|
+
const boldTokenEncoded = AbiCoder.encodeParameter('address', boldToken);
|
|
847
|
+
const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
848
|
+
const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
|
|
849
|
+
|
|
850
|
+
return [
|
|
851
|
+
marketEncoded,
|
|
852
|
+
troveIdEncoded,
|
|
853
|
+
boldTokenEncoded,
|
|
854
|
+
targetRatioEncoded,
|
|
855
|
+
ratioStateEncoded,
|
|
856
|
+
];
|
|
857
|
+
},
|
|
858
|
+
decode: (subData: SubData) => {
|
|
859
|
+
const market = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
860
|
+
const troveId = AbiCoder.decodeParameter('uint256', subData[1]) as any as string;
|
|
861
|
+
const boldToken = AbiCoder.decodeParameter('address', subData[2]) as any as EthereumAddress;
|
|
862
|
+
const weiRatio = AbiCoder.decodeParameter('uint256', subData[3]) as any as string;
|
|
863
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[4]) as any as RatioState;
|
|
864
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
865
|
+
|
|
866
|
+
return {
|
|
867
|
+
market, troveId, boldToken, ratioState, targetRatio,
|
|
868
|
+
};
|
|
869
|
+
},
|
|
870
|
+
};
|
package/src/types/enums.ts
CHANGED
package/src/types/index.ts
CHANGED
|
@@ -183,6 +183,13 @@ export declare namespace Position {
|
|
|
183
183
|
subHash: string;
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
+
interface PaybackLiquityV2 extends Base {
|
|
187
|
+
market: EthereumAddress,
|
|
188
|
+
troveId: string,
|
|
189
|
+
targetRatio: number;
|
|
190
|
+
triggerRatio: number;
|
|
191
|
+
}
|
|
192
|
+
|
|
186
193
|
interface TrailingStop extends Base {
|
|
187
194
|
roundId: number,
|
|
188
195
|
triggerPercentage: number,
|
|
@@ -211,7 +218,8 @@ export declare namespace Position {
|
|
|
211
218
|
| Specific.LeverageManagementCrvUSD
|
|
212
219
|
| Specific.CloseOnPriceLiquityV2
|
|
213
220
|
| Specific.BoostOnPriceMorpho
|
|
214
|
-
| Specific.BoostOnPriceLiquityV2
|
|
221
|
+
| Specific.BoostOnPriceLiquityV2
|
|
222
|
+
| Specific.PaybackLiquityV2;
|
|
215
223
|
|
|
216
224
|
export interface Automated {
|
|
217
225
|
chainId: ChainId,
|