@defisaver/automation-sdk 3.3.10 → 3.3.11-aave-v4-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/constants/index.d.ts +1 -0
- package/cjs/constants/index.js +72 -1
- package/cjs/services/ethereumService.test.js +2 -0
- package/cjs/services/strategiesService.js +129 -0
- package/cjs/services/strategySubService.d.ts +19 -0
- package/cjs/services/strategySubService.js +37 -1
- package/cjs/services/strategySubService.test.js +229 -0
- package/cjs/services/subDataService.d.ts +298 -129
- package/cjs/services/subDataService.js +639 -369
- package/cjs/services/subDataService.test.js +214 -0
- package/cjs/services/triggerService.d.ts +38 -0
- package/cjs/services/triggerService.js +68 -1
- package/cjs/services/triggerService.test.js +130 -0
- package/cjs/services/utils.d.ts +1 -1
- package/cjs/services/utils.js +10 -2
- package/cjs/types/enums.d.ts +19 -3
- package/cjs/types/enums.js +16 -0
- package/cjs/types/index.d.ts +33 -1
- package/esm/constants/index.d.ts +1 -0
- package/esm/constants/index.js +71 -0
- package/esm/services/ethereumService.test.js +2 -0
- package/esm/services/strategiesService.js +130 -1
- package/esm/services/strategySubService.d.ts +19 -0
- package/esm/services/strategySubService.js +36 -0
- package/esm/services/strategySubService.test.js +230 -1
- package/esm/services/subDataService.d.ts +298 -129
- package/esm/services/subDataService.js +639 -369
- package/esm/services/subDataService.test.js +214 -0
- package/esm/services/triggerService.d.ts +38 -0
- package/esm/services/triggerService.js +67 -0
- package/esm/services/triggerService.test.js +131 -1
- package/esm/services/utils.d.ts +1 -1
- package/esm/services/utils.js +10 -2
- package/esm/types/enums.d.ts +19 -3
- package/esm/types/enums.js +16 -0
- package/esm/types/index.d.ts +33 -1
- package/package.json +2 -2
- package/src/constants/index.ts +72 -0
- package/src/services/ethereumService.test.ts +2 -0
- package/src/services/strategiesService.ts +150 -2
- package/src/services/strategySubService.test.ts +286 -0
- package/src/services/strategySubService.ts +140 -0
- package/src/services/subDataService.test.ts +239 -0
- package/src/services/subDataService.ts +1072 -784
- package/src/services/triggerService.test.ts +148 -0
- package/src/services/triggerService.ts +97 -1
- package/src/services/utils.ts +15 -4
- package/src/types/enums.ts +16 -0
- package/src/types/index.ts +40 -1
package/cjs/constants/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ArbitrumBundleInfo, ArbitrumStrategiesInfo, BundlesInfo, EthereumAddress, Interfaces, MainnetBundleInfo, MainnetStrategiesInfo, OptimismBundleInfo, OptimismStrategiesInfo, BaseBundleInfo, BaseStrategiesInfo, StrategiesInfo } from '../types';
|
|
2
2
|
import { ProtocolIdentifiers, Strategies, Bundles } from '../types/enums';
|
|
3
3
|
export declare const ZERO_ADDRESS: EthereumAddress;
|
|
4
|
+
export declare const EMPTY_SLOT: string;
|
|
4
5
|
export declare const AAVE_V3_VARIABLE_BORROW_RATE = 2;
|
|
5
6
|
export declare const PROTOCOLS: Record<keyof typeof ProtocolIdentifiers.StrategiesAutomation, Interfaces.Protocol>;
|
|
6
7
|
export declare const LEGACY_PROTOCOLS: Record<keyof typeof ProtocolIdentifiers.LegacyAutomation, Interfaces.LegacyProtocol>;
|
package/cjs/constants/index.js
CHANGED
|
@@ -3,12 +3,13 @@ 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.BUNDLE_IDS = exports.BUNDLES_INFO = exports.ARBITRUM_BUNDLES_INFO = exports.BASE_BUNDLES_INFO = exports.OPTIMISM_BUNDLES_INFO = exports.MAINNET_BUNDLES_INFO = exports.STRATEGY_IDS = exports.STRATEGIES_INFO = exports.ARBITRUM_STRATEGIES_INFO = exports.BASE_STRATEGIES_INFO = exports.OPTIMISM_STRATEGIES_INFO = exports.MAINNET_STRATEGIES_INFO = exports.LEGACY_PROTOCOLS = exports.PROTOCOLS = exports.AAVE_V3_VARIABLE_BORROW_RATE = exports.ZERO_ADDRESS = void 0;
|
|
6
|
+
exports.BUNDLE_IDS = exports.BUNDLES_INFO = exports.ARBITRUM_BUNDLES_INFO = exports.BASE_BUNDLES_INFO = exports.OPTIMISM_BUNDLES_INFO = exports.MAINNET_BUNDLES_INFO = exports.STRATEGY_IDS = exports.STRATEGIES_INFO = exports.ARBITRUM_STRATEGIES_INFO = exports.BASE_STRATEGIES_INFO = exports.OPTIMISM_STRATEGIES_INFO = exports.MAINNET_STRATEGIES_INFO = exports.LEGACY_PROTOCOLS = exports.PROTOCOLS = exports.AAVE_V3_VARIABLE_BORROW_RATE = exports.EMPTY_SLOT = exports.ZERO_ADDRESS = void 0;
|
|
7
7
|
const enums_1 = require("../types/enums");
|
|
8
8
|
const Protocol_1 = __importDefault(require("../automation/private/Protocol"));
|
|
9
9
|
const LegacyProtocol_1 = __importDefault(require("../automation/private/LegacyProtocol"));
|
|
10
10
|
// General
|
|
11
11
|
exports.ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
12
|
+
exports.EMPTY_SLOT = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
|
12
13
|
exports.AAVE_V3_VARIABLE_BORROW_RATE = 2;
|
|
13
14
|
exports.PROTOCOLS = (() => {
|
|
14
15
|
const protocolsMapping = {};
|
|
@@ -106,6 +107,16 @@ exports.MAINNET_STRATEGIES_INFO = {
|
|
|
106
107
|
strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
|
|
107
108
|
protocol: exports.PROTOCOLS.AaveV3,
|
|
108
109
|
},
|
|
110
|
+
[enums_1.Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH]: {
|
|
111
|
+
strategyOrBundleId: enums_1.Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH,
|
|
112
|
+
strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
|
|
113
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
114
|
+
},
|
|
115
|
+
[enums_1.Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH_EOA]: {
|
|
116
|
+
strategyOrBundleId: enums_1.Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH_EOA,
|
|
117
|
+
strategyId: enums_1.Strategies.Identifiers.EoaCollateralSwitch,
|
|
118
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
119
|
+
},
|
|
109
120
|
};
|
|
110
121
|
exports.OPTIMISM_STRATEGIES_INFO = {
|
|
111
122
|
[enums_1.Strategies.OptimismIds.EXCHANGE_DCA]: {
|
|
@@ -473,6 +484,66 @@ exports.MAINNET_BUNDLES_INFO = {
|
|
|
473
484
|
strategyId: enums_1.Strategies.Identifiers.CloseOnPrice,
|
|
474
485
|
protocol: exports.PROTOCOLS.MorphoBlue,
|
|
475
486
|
},
|
|
487
|
+
[enums_1.Bundles.MainnetIds.SPARK_REPAY_ON_PRICE]: {
|
|
488
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.SPARK_REPAY_ON_PRICE,
|
|
489
|
+
strategyId: enums_1.Strategies.Identifiers.RepayOnPrice,
|
|
490
|
+
protocol: exports.PROTOCOLS.Spark,
|
|
491
|
+
},
|
|
492
|
+
[enums_1.Bundles.MainnetIds.SPARK_BOOST_ON_PRICE]: {
|
|
493
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.SPARK_BOOST_ON_PRICE,
|
|
494
|
+
strategyId: enums_1.Strategies.Identifiers.BoostOnPrice,
|
|
495
|
+
protocol: exports.PROTOCOLS.Spark,
|
|
496
|
+
},
|
|
497
|
+
[enums_1.Bundles.MainnetIds.AAVE_V4_REPAY]: {
|
|
498
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_REPAY,
|
|
499
|
+
strategyId: enums_1.Strategies.Identifiers.Repay,
|
|
500
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
501
|
+
},
|
|
502
|
+
[enums_1.Bundles.MainnetIds.AAVE_V4_BOOST]: {
|
|
503
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_BOOST,
|
|
504
|
+
strategyId: enums_1.Strategies.Identifiers.Boost,
|
|
505
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
506
|
+
},
|
|
507
|
+
[enums_1.Bundles.MainnetIds.AAVE_V4_REPAY_ON_PRICE]: {
|
|
508
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_REPAY_ON_PRICE,
|
|
509
|
+
strategyId: enums_1.Strategies.Identifiers.RepayOnPrice,
|
|
510
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
511
|
+
},
|
|
512
|
+
[enums_1.Bundles.MainnetIds.AAVE_V4_BOOST_ON_PRICE]: {
|
|
513
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_BOOST_ON_PRICE,
|
|
514
|
+
strategyId: enums_1.Strategies.Identifiers.BoostOnPrice,
|
|
515
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
516
|
+
},
|
|
517
|
+
[enums_1.Bundles.MainnetIds.AAVE_V4_CLOSE]: {
|
|
518
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_CLOSE,
|
|
519
|
+
strategyId: enums_1.Strategies.Identifiers.CloseOnPrice,
|
|
520
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
521
|
+
},
|
|
522
|
+
[enums_1.Bundles.MainnetIds.AAVE_V4_EOA_REPAY]: {
|
|
523
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_EOA_REPAY,
|
|
524
|
+
strategyId: enums_1.Strategies.Identifiers.EoaRepay,
|
|
525
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
526
|
+
},
|
|
527
|
+
[enums_1.Bundles.MainnetIds.AAVE_V4_EOA_BOOST]: {
|
|
528
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_EOA_BOOST,
|
|
529
|
+
strategyId: enums_1.Strategies.Identifiers.EoaBoost,
|
|
530
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
531
|
+
},
|
|
532
|
+
[enums_1.Bundles.MainnetIds.AAVE_V4_EOA_REPAY_ON_PRICE]: {
|
|
533
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_EOA_REPAY_ON_PRICE,
|
|
534
|
+
strategyId: enums_1.Strategies.Identifiers.EoaRepayOnPrice,
|
|
535
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
536
|
+
},
|
|
537
|
+
[enums_1.Bundles.MainnetIds.AAVE_V4_EOA_BOOST_ON_PRICE]: {
|
|
538
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_EOA_BOOST_ON_PRICE,
|
|
539
|
+
strategyId: enums_1.Strategies.Identifiers.EoaBoostOnPrice,
|
|
540
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
541
|
+
},
|
|
542
|
+
[enums_1.Bundles.MainnetIds.AAVE_V4_EOA_CLOSE]: {
|
|
543
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_EOA_CLOSE,
|
|
544
|
+
strategyId: enums_1.Strategies.Identifiers.EoaCloseOnPrice,
|
|
545
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
546
|
+
},
|
|
476
547
|
};
|
|
477
548
|
exports.OPTIMISM_BUNDLES_INFO = {
|
|
478
549
|
[enums_1.Bundles.OptimismIds.AAVE_V3_REPAY]: {
|
|
@@ -147,6 +147,7 @@ describe('Feature: ethereumService.ts', () => {
|
|
|
147
147
|
'address': '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
|
|
148
148
|
'blockHash': '0xacb0213af63b4c17c436f084a96d1ac385641a59a9a4cf014ae3337cbe545aa7',
|
|
149
149
|
'blockNumber': 5353002,
|
|
150
|
+
'blockTimestamp': '0x624c1a5b',
|
|
150
151
|
'event': 'Transfer',
|
|
151
152
|
'id': 'log_f49645b8',
|
|
152
153
|
'logIndex': 1,
|
|
@@ -192,6 +193,7 @@ describe('Feature: ethereumService.ts', () => {
|
|
|
192
193
|
'address': '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
|
|
193
194
|
'blockHash': '0xacb0213af63b4c17c436f084a96d1ac385641a59a9a4cf014ae3337cbe545aa7',
|
|
194
195
|
'blockNumber': 5353002,
|
|
196
|
+
'blockTimestamp': '0x624c1a5b',
|
|
195
197
|
'event': 'Transfer',
|
|
196
198
|
'id': 'log_f49645b8',
|
|
197
199
|
'logIndex': 1,
|
|
@@ -314,6 +314,96 @@ function parseAaveV3CollateralSwitch(position, parseData) {
|
|
|
314
314
|
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
315
315
|
return _position;
|
|
316
316
|
}
|
|
317
|
+
function parseAaveV4LeverageManagement(position, parseData) {
|
|
318
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
319
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
320
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
321
|
+
const triggerData = triggerService.aaveV4RatioTrigger.decode(subStruct.triggerData);
|
|
322
|
+
const subData = subDataService.aaveV4LeverageManagementSubData.decode(subStruct.subData);
|
|
323
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
324
|
+
const isRepay = [enums_1.Strategies.Identifiers.Repay, enums_1.Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId);
|
|
325
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
326
|
+
_position.strategyData.decoded.subData = subData;
|
|
327
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
|
|
328
|
+
_position.strategy.strategyId = isEOA ? enums_1.Strategies.IdOverrides.EoaLeverageManagement : enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
329
|
+
if (isRepay) {
|
|
330
|
+
_position.specific = {
|
|
331
|
+
triggerRepayRatio: triggerData.ratio,
|
|
332
|
+
targetRepayRatio: subData.targetRatio,
|
|
333
|
+
repayEnabled: isEnabled,
|
|
334
|
+
subId1: Number(subId),
|
|
335
|
+
mergeWithId: isEOA ? enums_1.Strategies.Identifiers.EoaBoost : enums_1.Strategies.Identifiers.Boost,
|
|
336
|
+
subHashRepay: subHash,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
_position.specific = {
|
|
341
|
+
triggerBoostRatio: triggerData.ratio,
|
|
342
|
+
targetBoostRatio: subData.targetRatio,
|
|
343
|
+
boostEnabled: isEnabled,
|
|
344
|
+
subId2: Number(subId),
|
|
345
|
+
mergeId: isEOA ? enums_1.Strategies.Identifiers.EoaBoost : enums_1.Strategies.Identifiers.Boost,
|
|
346
|
+
subHashBoost: subHash,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
return _position;
|
|
350
|
+
}
|
|
351
|
+
function parseAaveV4LeverageManagementOnPrice(position, parseData) {
|
|
352
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
353
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
354
|
+
const triggerData = triggerService.aaveV4QuotePriceTrigger.decode(subStruct.triggerData);
|
|
355
|
+
const subData = subDataService.aaveV4LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
356
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
357
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
358
|
+
_position.strategyData.decoded.subData = subData;
|
|
359
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
|
|
360
|
+
_position.strategy.strategyId = isEOA ? enums_1.Strategies.IdOverrides.EoaLeverageManagementOnPrice : enums_1.Strategies.IdOverrides.LeverageManagementOnPrice;
|
|
361
|
+
_position.specific = {
|
|
362
|
+
collAsset: subData.collAsset,
|
|
363
|
+
collAssetId: subData.collAssetId,
|
|
364
|
+
debtAsset: subData.debtAsset,
|
|
365
|
+
debtAssetId: subData.debtAssetId,
|
|
366
|
+
price: triggerData.price,
|
|
367
|
+
ratioState: triggerData.ratioState,
|
|
368
|
+
ratio: subData.targetRatio,
|
|
369
|
+
};
|
|
370
|
+
return _position;
|
|
371
|
+
}
|
|
372
|
+
function parseAaveV4CloseOnPrice(position, parseData) {
|
|
373
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
374
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
375
|
+
const triggerData = triggerService.aaveV4QuotePriceRangeTrigger.decode(subStruct.triggerData);
|
|
376
|
+
const subData = subDataService.aaveV4CloseSubData.decode(subStruct.subData);
|
|
377
|
+
const { takeProfitType, stopLossType } = (0, utils_1.getStopLossAndTakeProfitTypeByCloseStrategyType)(+subData.closeType);
|
|
378
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
379
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
380
|
+
_position.strategyData.decoded.subData = subData;
|
|
381
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
|
|
382
|
+
_position.strategy.strategyId = isEOA ? enums_1.Strategies.Identifiers.EoaCloseOnPrice : enums_1.Strategies.Identifiers.CloseOnPrice;
|
|
383
|
+
_position.specific = {
|
|
384
|
+
collAsset: subData.collAsset,
|
|
385
|
+
collAssetId: subData.collAssetId,
|
|
386
|
+
debtAsset: subData.debtAsset,
|
|
387
|
+
debtAssetId: subData.debtAssetId,
|
|
388
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
389
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
390
|
+
stopLossType,
|
|
391
|
+
takeProfitType,
|
|
392
|
+
};
|
|
393
|
+
return _position;
|
|
394
|
+
}
|
|
395
|
+
function parseAaveV4CollateralSwitch(position, parseData) {
|
|
396
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
397
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
398
|
+
const triggerData = triggerService.aaveV4QuotePriceTrigger.decode(subStruct.triggerData);
|
|
399
|
+
const subData = subDataService.aaveV4CollateralSwitchSubData.decode(subStruct.subData);
|
|
400
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
401
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
402
|
+
_position.strategyData.decoded.subData = subData;
|
|
403
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
|
|
404
|
+
_position.strategy.strategyId = isEOA ? enums_1.Strategies.Identifiers.EoaCollateralSwitch : enums_1.Strategies.Identifiers.CollateralSwitch;
|
|
405
|
+
return _position;
|
|
406
|
+
}
|
|
317
407
|
function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
318
408
|
const _position = (0, lodash_1.cloneDeep)(position);
|
|
319
409
|
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
@@ -613,6 +703,29 @@ function parseSparkLeverageManagement(position, parseData) {
|
|
|
613
703
|
_position.strategy.strategyId = enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
614
704
|
return _position;
|
|
615
705
|
}
|
|
706
|
+
function parseSparkLeverageManagementOnPrice(position, parseData) {
|
|
707
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
708
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
709
|
+
const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
|
|
710
|
+
const subData = subDataService.sparkLeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
711
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
712
|
+
_position.strategyData.decoded.subData = subData;
|
|
713
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
714
|
+
_position.specific = {
|
|
715
|
+
// subData
|
|
716
|
+
collAsset: subData.collAsset,
|
|
717
|
+
collAssetId: subData.collAssetId,
|
|
718
|
+
debtAsset: subData.debtAsset,
|
|
719
|
+
debtAssetId: subData.debtAssetId,
|
|
720
|
+
ratio: subData.targetRatio,
|
|
721
|
+
// triggerData
|
|
722
|
+
baseToken: triggerData.baseTokenAddr,
|
|
723
|
+
quoteToken: triggerData.quoteTokenAddr,
|
|
724
|
+
price: triggerData.price,
|
|
725
|
+
ratioState: triggerData.ratioState,
|
|
726
|
+
};
|
|
727
|
+
return _position;
|
|
728
|
+
}
|
|
616
729
|
function parseSparkCloseOnPrice(position, parseData) {
|
|
617
730
|
const _position = (0, lodash_1.cloneDeep)(position);
|
|
618
731
|
const { subStruct } = parseData.subscriptionEventData;
|
|
@@ -943,6 +1056,20 @@ const parsingMethodsMapping = {
|
|
|
943
1056
|
[enums_1.Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
|
|
944
1057
|
[enums_1.Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
|
|
945
1058
|
},
|
|
1059
|
+
[enums_1.ProtocolIdentifiers.StrategiesAutomation.AaveV4]: {
|
|
1060
|
+
[enums_1.Strategies.Identifiers.Repay]: parseAaveV4LeverageManagement,
|
|
1061
|
+
[enums_1.Strategies.Identifiers.Boost]: parseAaveV4LeverageManagement,
|
|
1062
|
+
[enums_1.Strategies.Identifiers.RepayOnPrice]: parseAaveV4LeverageManagementOnPrice,
|
|
1063
|
+
[enums_1.Strategies.Identifiers.BoostOnPrice]: parseAaveV4LeverageManagementOnPrice,
|
|
1064
|
+
[enums_1.Strategies.Identifiers.CloseOnPrice]: parseAaveV4CloseOnPrice,
|
|
1065
|
+
[enums_1.Strategies.Identifiers.EoaRepay]: parseAaveV4LeverageManagement,
|
|
1066
|
+
[enums_1.Strategies.Identifiers.EoaBoost]: parseAaveV4LeverageManagement,
|
|
1067
|
+
[enums_1.Strategies.Identifiers.EoaRepayOnPrice]: parseAaveV4LeverageManagementOnPrice,
|
|
1068
|
+
[enums_1.Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV4LeverageManagementOnPrice,
|
|
1069
|
+
[enums_1.Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV4CloseOnPrice,
|
|
1070
|
+
[enums_1.Strategies.Identifiers.CollateralSwitch]: parseAaveV4CollateralSwitch,
|
|
1071
|
+
[enums_1.Strategies.Identifiers.EoaCollateralSwitch]: parseAaveV4CollateralSwitch,
|
|
1072
|
+
},
|
|
946
1073
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.CompoundV2]: {
|
|
947
1074
|
[enums_1.Strategies.Identifiers.Repay]: parseCompoundV2LeverageManagement,
|
|
948
1075
|
[enums_1.Strategies.Identifiers.Boost]: parseCompoundV2LeverageManagement,
|
|
@@ -973,6 +1100,8 @@ const parsingMethodsMapping = {
|
|
|
973
1100
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.Spark]: {
|
|
974
1101
|
[enums_1.Strategies.Identifiers.Repay]: parseSparkLeverageManagement,
|
|
975
1102
|
[enums_1.Strategies.Identifiers.Boost]: parseSparkLeverageManagement,
|
|
1103
|
+
[enums_1.Strategies.Identifiers.RepayOnPrice]: parseSparkLeverageManagementOnPrice,
|
|
1104
|
+
[enums_1.Strategies.Identifiers.BoostOnPrice]: parseSparkLeverageManagementOnPrice,
|
|
976
1105
|
[enums_1.Strategies.Identifiers.CloseOnPrice]: parseSparkCloseOnPrice,
|
|
977
1106
|
},
|
|
978
1107
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
|
|
@@ -86,6 +86,19 @@ export declare const exchangeEncode: {
|
|
|
86
86
|
};
|
|
87
87
|
export declare const sparkEncode: {
|
|
88
88
|
leverageManagement(triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean): string;
|
|
89
|
+
leverageManagementOnPrice(strategyOrBundleId: number, isBundle: boolean | undefined, triggerData: {
|
|
90
|
+
baseTokenAddr: EthereumAddress;
|
|
91
|
+
quoteTokenAddr: EthereumAddress;
|
|
92
|
+
price: number;
|
|
93
|
+
ratioState: RatioState;
|
|
94
|
+
}, subData: {
|
|
95
|
+
collAsset: EthereumAddress;
|
|
96
|
+
collAssetId: number;
|
|
97
|
+
debtAsset: EthereumAddress;
|
|
98
|
+
debtAssetId: number;
|
|
99
|
+
marketAddr: EthereumAddress;
|
|
100
|
+
targetRatio: number;
|
|
101
|
+
}): (number | boolean | string[])[];
|
|
89
102
|
closeOnPriceGeneric(strategyOrBundleId: number, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, user: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
90
103
|
leverageManagementWithoutSubProxy(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
91
104
|
};
|
|
@@ -107,3 +120,9 @@ export declare const liquityV2Encode: {
|
|
|
107
120
|
export declare const fluidEncode: {
|
|
108
121
|
leverageManagement(nftId: string, vault: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
109
122
|
};
|
|
123
|
+
export declare const aaveV4Encode: {
|
|
124
|
+
leverageManagement(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
125
|
+
leverageManagementOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, targetRatio: number, price: string, priceState: RatioState, ratioState: RatioState): (number | boolean | string[])[];
|
|
126
|
+
closeOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, stopLossPrice?: string, stopLossType?: CloseToAssetType, takeProfitPrice?: string, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
127
|
+
collateralSwitch(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, amountToSwitch: string, price: string, ratioState: RatioState): (number | boolean | string[])[];
|
|
128
|
+
};
|
|
@@ -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.fluidEncode = 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;
|
|
29
|
+
exports.aaveV4Encode = exports.fluidEncode = 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");
|
|
@@ -272,6 +272,13 @@ exports.sparkEncode = {
|
|
|
272
272
|
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
273
273
|
return subInput;
|
|
274
274
|
},
|
|
275
|
+
leverageManagementOnPrice(strategyOrBundleId, isBundle = true, triggerData, subData) {
|
|
276
|
+
const { collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio, } = subData;
|
|
277
|
+
const subDataEncoded = subDataService.sparkLeverageManagementOnPriceSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio);
|
|
278
|
+
const { baseTokenAddr, quoteTokenAddr, price, ratioState, } = triggerData;
|
|
279
|
+
const triggerDataEncoded = triggerService.sparkQuotePriceTrigger.encode(baseTokenAddr, quoteTokenAddr, price, ratioState);
|
|
280
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
281
|
+
},
|
|
275
282
|
closeOnPriceGeneric(strategyOrBundleId, collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, user, stopLossPrice = 0, stopLossType = enums_1.CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = enums_1.CloseToAssetType.COLLATERAL) {
|
|
276
283
|
const isBundle = true;
|
|
277
284
|
const closeType = (0, utils_1.getCloseStrategyType)(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
@@ -370,3 +377,32 @@ exports.fluidEncode = {
|
|
|
370
377
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
371
378
|
},
|
|
372
379
|
};
|
|
380
|
+
exports.aaveV4Encode = {
|
|
381
|
+
leverageManagement(strategyOrBundleId, owner, spoke, ratioState, targetRatio, triggerRatio) {
|
|
382
|
+
const isBundle = true;
|
|
383
|
+
const subData = subDataService.aaveV4LeverageManagementSubData.encode(spoke, owner, ratioState, targetRatio);
|
|
384
|
+
const triggerData = triggerService.aaveV4RatioTrigger.encode(owner, spoke, triggerRatio, ratioState);
|
|
385
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
386
|
+
},
|
|
387
|
+
leverageManagementOnPrice(strategyOrBundleId, owner, spoke, collAsset, collAssetId, debtAsset, debtAssetId, targetRatio, price, priceState, ratioState) {
|
|
388
|
+
const isBundle = true;
|
|
389
|
+
const subData = subDataService.aaveV4LeverageManagementOnPriceSubData.encode(spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, ratioState, targetRatio);
|
|
390
|
+
const triggerData = triggerService.aaveV4QuotePriceTrigger.encode(spoke, collAssetId, debtAssetId, price, priceState);
|
|
391
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
392
|
+
},
|
|
393
|
+
closeOnPrice(strategyOrBundleId, owner, spoke, collAsset, collAssetId, debtAsset, debtAssetId, stopLossPrice = '0', stopLossType = enums_1.CloseToAssetType.DEBT, takeProfitPrice = '0', takeProfitType = enums_1.CloseToAssetType.COLLATERAL) {
|
|
394
|
+
const isBundle = true;
|
|
395
|
+
const closeType = (0, utils_1.getCloseStrategyType)(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
396
|
+
const subData = subDataService.aaveV4CloseSubData.encode(spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, closeType);
|
|
397
|
+
const triggerData = triggerService.aaveV4QuotePriceRangeTrigger.encode(spoke, collAssetId, debtAssetId, stopLossPrice, takeProfitPrice);
|
|
398
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
399
|
+
},
|
|
400
|
+
collateralSwitch(strategyOrBundleId, owner, spoke, fromAsset, fromAssetId, toAsset, toAssetId, amountToSwitch, price, ratioState) {
|
|
401
|
+
const isBundle = false;
|
|
402
|
+
const subData = subDataService.aaveV4CollateralSwitchSubData.encode(spoke, owner, fromAsset, fromAssetId, toAsset, toAssetId, amountToSwitch);
|
|
403
|
+
const triggerData = triggerService.aaveV4QuotePriceTrigger.encode(spoke, fromAssetId, // baseTokenId
|
|
404
|
+
toAssetId, // quoteTokenId
|
|
405
|
+
price, ratioState);
|
|
406
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
407
|
+
},
|
|
408
|
+
};
|
|
@@ -1481,4 +1481,233 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1481
1481
|
});
|
|
1482
1482
|
});
|
|
1483
1483
|
});
|
|
1484
|
+
describe('When testing strategySubService.sparkEncode', () => {
|
|
1485
|
+
describe('leverageManagement()', () => {
|
|
1486
|
+
const examples = [
|
|
1487
|
+
[
|
|
1488
|
+
'0x0000000000000000136dcc951d8c00000000000000000000214e8348c4f0000000000000000000001d24b2dfac52000000000000000000001a5e27eef13e000001',
|
|
1489
|
+
[140, 240, 210, 190, true]
|
|
1490
|
+
],
|
|
1491
|
+
[
|
|
1492
|
+
'0x0000000000000000130337bdce49000000000000000000001988fe4052b800000000000000000000281b57b028e1000000000000000000002223acf76376000000',
|
|
1493
|
+
[137, 184, 289, 246, false]
|
|
1494
|
+
]
|
|
1495
|
+
];
|
|
1496
|
+
examples.forEach(([expected, actual]) => {
|
|
1497
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1498
|
+
(0, chai_1.expect)(strategySubService_1.sparkEncode.leverageManagement(...actual)).to.eql(expected);
|
|
1499
|
+
});
|
|
1500
|
+
});
|
|
1501
|
+
});
|
|
1502
|
+
describe('leverageManagementOnPrice()', () => {
|
|
1503
|
+
const examples = [
|
|
1504
|
+
[
|
|
1505
|
+
[
|
|
1506
|
+
enums_1.Bundles.MainnetIds.SPARK_REPAY_ON_PRICE,
|
|
1507
|
+
true,
|
|
1508
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1509
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1510
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1511
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1512
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1513
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1514
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1515
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1516
|
+
],
|
|
1517
|
+
],
|
|
1518
|
+
[
|
|
1519
|
+
59,
|
|
1520
|
+
true,
|
|
1521
|
+
{
|
|
1522
|
+
baseTokenAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
1523
|
+
quoteTokenAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
1524
|
+
price: 2500,
|
|
1525
|
+
ratioState: enums_1.RatioState.UNDER,
|
|
1526
|
+
},
|
|
1527
|
+
{
|
|
1528
|
+
collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
1529
|
+
collAssetId: 0,
|
|
1530
|
+
debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
1531
|
+
debtAssetId: 1,
|
|
1532
|
+
marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1533
|
+
targetRatio: 200,
|
|
1534
|
+
},
|
|
1535
|
+
]
|
|
1536
|
+
],
|
|
1537
|
+
[
|
|
1538
|
+
[
|
|
1539
|
+
enums_1.Bundles.MainnetIds.SPARK_BOOST_ON_PRICE,
|
|
1540
|
+
true,
|
|
1541
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000417bce6c8000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1542
|
+
[
|
|
1543
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1544
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1545
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1546
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
1547
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1548
|
+
'0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
|
|
1549
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1550
|
+
]
|
|
1551
|
+
],
|
|
1552
|
+
[
|
|
1553
|
+
60,
|
|
1554
|
+
true,
|
|
1555
|
+
{
|
|
1556
|
+
baseTokenAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
|
|
1557
|
+
quoteTokenAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
1558
|
+
price: 45000,
|
|
1559
|
+
ratioState: enums_1.RatioState.OVER,
|
|
1560
|
+
},
|
|
1561
|
+
{
|
|
1562
|
+
collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
|
|
1563
|
+
collAssetId: 2,
|
|
1564
|
+
debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
1565
|
+
debtAssetId: 4,
|
|
1566
|
+
marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1567
|
+
targetRatio: 250,
|
|
1568
|
+
},
|
|
1569
|
+
]
|
|
1570
|
+
]
|
|
1571
|
+
];
|
|
1572
|
+
examples.forEach(([expected, actual]) => {
|
|
1573
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1574
|
+
(0, chai_1.expect)(strategySubService_1.sparkEncode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
1575
|
+
});
|
|
1576
|
+
});
|
|
1577
|
+
});
|
|
1578
|
+
describe('closeOnPrice()', () => {
|
|
1579
|
+
const examples = [
|
|
1580
|
+
[
|
|
1581
|
+
[
|
|
1582
|
+
enums_1.Bundles.MainnetIds.SPARK_CLOSE,
|
|
1583
|
+
true,
|
|
1584
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000003a35294400000000000000000000000000000000000000000000000000000000574fbde6000'],
|
|
1585
|
+
[
|
|
1586
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1587
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1588
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1589
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
1590
|
+
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1591
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1592
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
1593
|
+
]
|
|
1594
|
+
],
|
|
1595
|
+
[
|
|
1596
|
+
57,
|
|
1597
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
|
|
1598
|
+
2,
|
|
1599
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
1600
|
+
4,
|
|
1601
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1602
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1603
|
+
40000,
|
|
1604
|
+
enums_1.CloseToAssetType.DEBT,
|
|
1605
|
+
60000,
|
|
1606
|
+
enums_1.CloseToAssetType.COLLATERAL,
|
|
1607
|
+
]
|
|
1608
|
+
],
|
|
1609
|
+
];
|
|
1610
|
+
examples.forEach(([expected, actual]) => {
|
|
1611
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1612
|
+
(0, chai_1.expect)(strategySubService_1.sparkEncode.closeOnPriceGeneric(...actual)).to.eql(expected);
|
|
1613
|
+
});
|
|
1614
|
+
});
|
|
1615
|
+
});
|
|
1616
|
+
});
|
|
1617
|
+
describe('When testing strategySubService.aaveV4Encode', () => {
|
|
1618
|
+
describe('leverageManagement()', () => {
|
|
1619
|
+
const examples = [
|
|
1620
|
+
[
|
|
1621
|
+
[1, true, ["0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x00000000000000000000000000000000000000000000000014d1120d7b160000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1622
|
+
[
|
|
1623
|
+
1,
|
|
1624
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1625
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1626
|
+
enums_1.RatioState.UNDER,
|
|
1627
|
+
150,
|
|
1628
|
+
120,
|
|
1629
|
+
]
|
|
1630
|
+
]
|
|
1631
|
+
];
|
|
1632
|
+
examples.forEach(([expected, actual]) => {
|
|
1633
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1634
|
+
(0, chai_1.expect)(strategySubService_1.aaveV4Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1635
|
+
});
|
|
1636
|
+
});
|
|
1637
|
+
});
|
|
1638
|
+
describe('leverageManagementOnPrice()', () => {
|
|
1639
|
+
const examples = [
|
|
1640
|
+
[
|
|
1641
|
+
[2, true, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000016345785d8a00000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1642
|
+
[
|
|
1643
|
+
2,
|
|
1644
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1645
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1646
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1647
|
+
10,
|
|
1648
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1649
|
+
20,
|
|
1650
|
+
160,
|
|
1651
|
+
'1500',
|
|
1652
|
+
enums_1.RatioState.OVER,
|
|
1653
|
+
enums_1.RatioState.OVER, // ratioState - UNDER for repay, OVER for boost
|
|
1654
|
+
]
|
|
1655
|
+
]
|
|
1656
|
+
];
|
|
1657
|
+
examples.forEach(([expected, actual]) => {
|
|
1658
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1659
|
+
(0, chai_1.expect)(strategySubService_1.aaveV4Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
1660
|
+
});
|
|
1661
|
+
});
|
|
1662
|
+
});
|
|
1663
|
+
describe('closeOnPrice()', () => {
|
|
1664
|
+
const examples = [
|
|
1665
|
+
[
|
|
1666
|
+
[3, true, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae000000000000000000000000000000000000000000000000000000000000000000000"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000003", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1667
|
+
[
|
|
1668
|
+
3,
|
|
1669
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1670
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1671
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1672
|
+
10,
|
|
1673
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1674
|
+
20,
|
|
1675
|
+
'1400',
|
|
1676
|
+
enums_1.CloseToAssetType.DEBT,
|
|
1677
|
+
'0',
|
|
1678
|
+
enums_1.CloseToAssetType.COLLATERAL
|
|
1679
|
+
]
|
|
1680
|
+
]
|
|
1681
|
+
];
|
|
1682
|
+
examples.forEach(([expected, actual]) => {
|
|
1683
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1684
|
+
(0, chai_1.expect)(strategySubService_1.aaveV4Encode.closeOnPrice(...actual)).to.eql(expected);
|
|
1685
|
+
});
|
|
1686
|
+
});
|
|
1687
|
+
});
|
|
1688
|
+
describe('collateralSwitch()', () => {
|
|
1689
|
+
const examples = [
|
|
1690
|
+
[
|
|
1691
|
+
[4, false, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000001"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1692
|
+
[
|
|
1693
|
+
4,
|
|
1694
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1695
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1696
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1697
|
+
10,
|
|
1698
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1699
|
+
20,
|
|
1700
|
+
'1000000000000000000',
|
|
1701
|
+
'1500',
|
|
1702
|
+
enums_1.RatioState.UNDER,
|
|
1703
|
+
]
|
|
1704
|
+
]
|
|
1705
|
+
];
|
|
1706
|
+
examples.forEach(([expected, actual]) => {
|
|
1707
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1708
|
+
(0, chai_1.expect)(strategySubService_1.aaveV4Encode.collateralSwitch(...actual)).to.eql(expected);
|
|
1709
|
+
});
|
|
1710
|
+
});
|
|
1711
|
+
});
|
|
1712
|
+
});
|
|
1484
1713
|
});
|