@defisaver/automation-sdk 2.1.3 → 2.1.5
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/.env +4 -0
- package/esm/constants/index.js +10 -0
- package/esm/services/strategiesService.js +4 -1
- package/esm/services/strategySubService.d.ts +3 -0
- package/esm/services/strategySubService.js +6 -1
- package/esm/services/strategySubService.test.js +29 -0
- package/esm/services/subDataService.d.ts +6 -0
- package/esm/services/subDataService.js +24 -1
- package/esm/services/subDataService.test.js +165 -123
- package/esm/types/enums.d.ts +3 -1
- package/esm/types/enums.js +2 -0
- package/package.json +1 -1
- package/src/constants/index.ts +10 -0
- package/src/services/strategiesService.ts +5 -1
- package/src/services/strategySubService.test.ts +33 -1
- package/src/services/strategySubService.ts +14 -0
- package/src/services/subDataService.test.ts +174 -123
- package/src/services/subDataService.ts +36 -1
- package/src/types/enums.ts +2 -0
- package/umd/index.js +42 -1
|
@@ -3,7 +3,7 @@ import AbiCoder from 'web3-eth-abi';
|
|
|
3
3
|
import { assetAmountInEth, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
4
4
|
import { otherAddresses } from '@defisaver/sdk';
|
|
5
5
|
|
|
6
|
-
import type {
|
|
6
|
+
import type { SubData, EthereumAddress } from '../types';
|
|
7
7
|
import type { OrderType } from '../types/enums';
|
|
8
8
|
import { ChainId, RatioState } from '../types/enums';
|
|
9
9
|
|
|
@@ -255,6 +255,41 @@ export const compoundV3LeverageManagementSubData = {
|
|
|
255
255
|
},
|
|
256
256
|
};
|
|
257
257
|
|
|
258
|
+
export const compoundV3L2LeverageManagementSubData = {
|
|
259
|
+
encode(
|
|
260
|
+
market: EthereumAddress,
|
|
261
|
+
baseToken: EthereumAddress,
|
|
262
|
+
triggerRepayRatio: number,
|
|
263
|
+
triggerBoostRatio: number,
|
|
264
|
+
targetBoostRatio: number,
|
|
265
|
+
targetRepayRatio: number,
|
|
266
|
+
boostEnabled: boolean,
|
|
267
|
+
): string {
|
|
268
|
+
let subInput = '0x';
|
|
269
|
+
|
|
270
|
+
subInput = subInput.concat(market.slice(2));
|
|
271
|
+
subInput = subInput.concat(baseToken.slice(2));
|
|
272
|
+
subInput = subInput.concat(new Dec(triggerRepayRatio).mul(1e16).toHex().slice(2)
|
|
273
|
+
.padStart(32, '0'));
|
|
274
|
+
subInput = subInput.concat(new Dec(triggerBoostRatio).mul(1e16).toHex().slice(2)
|
|
275
|
+
.padStart(32, '0'));
|
|
276
|
+
subInput = subInput.concat(new Dec(targetBoostRatio).mul(1e16).toHex().slice(2)
|
|
277
|
+
.padStart(32, '0'));
|
|
278
|
+
subInput = subInput.concat(new Dec(targetRepayRatio).mul(1e16).toHex().slice(2)
|
|
279
|
+
.padStart(32, '0'));
|
|
280
|
+
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
281
|
+
|
|
282
|
+
return subInput;
|
|
283
|
+
},
|
|
284
|
+
decode(subData: SubData): { targetRatio: number } {
|
|
285
|
+
console.log(subData);
|
|
286
|
+
const ratioWei = AbiCoder.decodeParameter('uint256', subData[3]) as any as string;
|
|
287
|
+
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
288
|
+
|
|
289
|
+
return { targetRatio };
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
|
|
258
293
|
export const morphoAaveV2LeverageManagementSubData = {
|
|
259
294
|
encode(
|
|
260
295
|
triggerRepayRatio: number,
|
package/src/types/enums.ts
CHANGED
package/umd/index.js
CHANGED
|
@@ -416,6 +416,16 @@ var ARBITRUM_BUNDLES_INFO = {
|
|
|
416
416
|
strategyOrBundleId: _types_enums__WEBPACK_IMPORTED_MODULE_0__.Bundles.ArbitrumIds.AAVE_V3_CLOSE_TO_COLLATERAL,
|
|
417
417
|
strategyId: _types_enums__WEBPACK_IMPORTED_MODULE_0__.Strategies.Identifiers.CloseToCollateral,
|
|
418
418
|
protocol: PROTOCOLS.AaveV3
|
|
419
|
+
},
|
|
420
|
+
[_types_enums__WEBPACK_IMPORTED_MODULE_0__.Bundles.ArbitrumIds.COMP_V3_SW_BOOST_BUNDLE]: {
|
|
421
|
+
strategyOrBundleId: _types_enums__WEBPACK_IMPORTED_MODULE_0__.Bundles.ArbitrumIds.COMP_V3_SW_BOOST_BUNDLE,
|
|
422
|
+
strategyId: _types_enums__WEBPACK_IMPORTED_MODULE_0__.Strategies.Identifiers.Boost,
|
|
423
|
+
protocol: PROTOCOLS.CompoundV3
|
|
424
|
+
},
|
|
425
|
+
[_types_enums__WEBPACK_IMPORTED_MODULE_0__.Bundles.ArbitrumIds.COMP_V3_SW_REPAY_BUNDLE]: {
|
|
426
|
+
strategyOrBundleId: _types_enums__WEBPACK_IMPORTED_MODULE_0__.Bundles.ArbitrumIds.COMP_V3_SW_REPAY_BUNDLE,
|
|
427
|
+
strategyId: _types_enums__WEBPACK_IMPORTED_MODULE_0__.Strategies.Identifiers.Repay,
|
|
428
|
+
protocol: PROTOCOLS.CompoundV3
|
|
419
429
|
}
|
|
420
430
|
};
|
|
421
431
|
var BUNDLES_INFO = {
|
|
@@ -616,6 +626,8 @@ var Bundles;
|
|
|
616
626
|
ArbitrumIds[ArbitrumIds["AAVE_V3_BOOST"] = 1] = "AAVE_V3_BOOST";
|
|
617
627
|
ArbitrumIds[ArbitrumIds["AAVE_V3_CLOSE_TO_DEBT"] = 2] = "AAVE_V3_CLOSE_TO_DEBT";
|
|
618
628
|
ArbitrumIds[ArbitrumIds["AAVE_V3_CLOSE_TO_COLLATERAL"] = 3] = "AAVE_V3_CLOSE_TO_COLLATERAL";
|
|
629
|
+
ArbitrumIds[ArbitrumIds["COMP_V3_SW_REPAY_BUNDLE"] = 4] = "COMP_V3_SW_REPAY_BUNDLE";
|
|
630
|
+
ArbitrumIds[ArbitrumIds["COMP_V3_SW_BOOST_BUNDLE"] = 5] = "COMP_V3_SW_BOOST_BUNDLE";
|
|
619
631
|
})(ArbitrumIds || (ArbitrumIds = {}));
|
|
620
632
|
_Bundles.ArbitrumIds = ArbitrumIds;
|
|
621
633
|
})(Bundles || (Bundles = {}));
|
|
@@ -1962,8 +1974,9 @@ function parseCompoundV3LeverageManagement(position, parseData) {
|
|
|
1962
1974
|
var {
|
|
1963
1975
|
isEnabled
|
|
1964
1976
|
} = parseData.strategiesSubsData;
|
|
1977
|
+
var subDataDecoder = position.chainId !== 1 ? _subDataService__WEBPACK_IMPORTED_MODULE_5__.compoundV3L2LeverageManagementSubData : _subDataService__WEBPACK_IMPORTED_MODULE_5__.compoundV3LeverageManagementSubData;
|
|
1965
1978
|
var triggerData = _triggerService__WEBPACK_IMPORTED_MODULE_6__.compoundV3RatioTrigger.decode(subStruct.triggerData);
|
|
1966
|
-
var subData =
|
|
1979
|
+
var subData = subDataDecoder.decode(subStruct.subData);
|
|
1967
1980
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
1968
1981
|
_position.strategyData.decoded.subData = subData;
|
|
1969
1982
|
_position.owner = triggerData.owner.toLowerCase();
|
|
@@ -19536,6 +19549,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
19536
19549
|
/* harmony export */ aaveV3QuotePriceSubData: () => (/* binding */ aaveV3QuotePriceSubData),
|
|
19537
19550
|
/* harmony export */ cBondsRebondSubData: () => (/* binding */ cBondsRebondSubData),
|
|
19538
19551
|
/* harmony export */ compoundV2LeverageManagementSubData: () => (/* binding */ compoundV2LeverageManagementSubData),
|
|
19552
|
+
/* harmony export */ compoundV3L2LeverageManagementSubData: () => (/* binding */ compoundV3L2LeverageManagementSubData),
|
|
19539
19553
|
/* harmony export */ compoundV3LeverageManagementSubData: () => (/* binding */ compoundV3LeverageManagementSubData),
|
|
19540
19554
|
/* harmony export */ crvUSDLeverageManagementSubData: () => (/* binding */ crvUSDLeverageManagementSubData),
|
|
19541
19555
|
/* harmony export */ exchangeDcaSubData: () => (/* binding */ exchangeDcaSubData),
|
|
@@ -19753,6 +19767,27 @@ var compoundV3LeverageManagementSubData = {
|
|
|
19753
19767
|
};
|
|
19754
19768
|
}
|
|
19755
19769
|
};
|
|
19770
|
+
var compoundV3L2LeverageManagementSubData = {
|
|
19771
|
+
encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
19772
|
+
var subInput = '0x';
|
|
19773
|
+
subInput = subInput.concat(market.slice(2));
|
|
19774
|
+
subInput = subInput.concat(baseToken.slice(2));
|
|
19775
|
+
subInput = subInput.concat(new (decimal_js__WEBPACK_IMPORTED_MODULE_0___default())(triggerRepayRatio).mul(1e16).toHex().slice(2).padStart(32, '0'));
|
|
19776
|
+
subInput = subInput.concat(new (decimal_js__WEBPACK_IMPORTED_MODULE_0___default())(triggerBoostRatio).mul(1e16).toHex().slice(2).padStart(32, '0'));
|
|
19777
|
+
subInput = subInput.concat(new (decimal_js__WEBPACK_IMPORTED_MODULE_0___default())(targetBoostRatio).mul(1e16).toHex().slice(2).padStart(32, '0'));
|
|
19778
|
+
subInput = subInput.concat(new (decimal_js__WEBPACK_IMPORTED_MODULE_0___default())(targetRepayRatio).mul(1e16).toHex().slice(2).padStart(32, '0'));
|
|
19779
|
+
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
19780
|
+
return subInput;
|
|
19781
|
+
},
|
|
19782
|
+
decode(subData) {
|
|
19783
|
+
console.log(subData);
|
|
19784
|
+
var ratioWei = web3_eth_abi__WEBPACK_IMPORTED_MODULE_1___default().decodeParameter('uint256', subData[3]);
|
|
19785
|
+
var targetRatio = (0,_utils__WEBPACK_IMPORTED_MODULE_6__.weiToRatioPercentage)(ratioWei);
|
|
19786
|
+
return {
|
|
19787
|
+
targetRatio
|
|
19788
|
+
};
|
|
19789
|
+
}
|
|
19790
|
+
};
|
|
19756
19791
|
var morphoAaveV2LeverageManagementSubData = {
|
|
19757
19792
|
encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
19758
19793
|
return [(0,_utils__WEBPACK_IMPORTED_MODULE_6__.ratioPercentageToWei)(triggerRepayRatio), (0,_utils__WEBPACK_IMPORTED_MODULE_6__.ratioPercentageToWei)(triggerBoostRatio), (0,_utils__WEBPACK_IMPORTED_MODULE_6__.ratioPercentageToWei)(targetBoostRatio), (0,_utils__WEBPACK_IMPORTED_MODULE_6__.ratioPercentageToWei)(targetRepayRatio),
|
|
@@ -33411,6 +33446,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
33411
33446
|
/* harmony export */ chickenBondsEncode: () => (/* binding */ chickenBondsEncode),
|
|
33412
33447
|
/* harmony export */ compoundV2Encode: () => (/* binding */ compoundV2Encode),
|
|
33413
33448
|
/* harmony export */ compoundV3Encode: () => (/* binding */ compoundV3Encode),
|
|
33449
|
+
/* harmony export */ compoundV3L2Encode: () => (/* binding */ compoundV3L2Encode),
|
|
33414
33450
|
/* harmony export */ crvUSDEncode: () => (/* binding */ crvUSDEncode),
|
|
33415
33451
|
/* harmony export */ exchangeEncode: () => (/* binding */ exchangeEncode),
|
|
33416
33452
|
/* harmony export */ liquityEncode: () => (/* binding */ liquityEncode),
|
|
@@ -33602,6 +33638,11 @@ var compoundV3Encode = {
|
|
|
33602
33638
|
return _subDataService__WEBPACK_IMPORTED_MODULE_4__.compoundV3LeverageManagementSubData.encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA);
|
|
33603
33639
|
}
|
|
33604
33640
|
};
|
|
33641
|
+
var compoundV3L2Encode = {
|
|
33642
|
+
leverageManagement(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
33643
|
+
return _subDataService__WEBPACK_IMPORTED_MODULE_4__.compoundV3L2LeverageManagementSubData.encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled);
|
|
33644
|
+
}
|
|
33645
|
+
};
|
|
33605
33646
|
var morphoAaveV2Encode = {
|
|
33606
33647
|
leverageManagement(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
33607
33648
|
return _subDataService__WEBPACK_IMPORTED_MODULE_4__.morphoAaveV2LeverageManagementSubData.encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled);
|