@defisaver/automation-sdk 3.3.5 → 3.3.7-dev.0
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 -10
- package/cjs/services/strategiesService.js +11 -14
- package/cjs/services/strategySubService.d.ts +1 -11
- package/cjs/services/strategySubService.js +5 -5
- package/cjs/services/strategySubService.test.js +0 -72
- package/cjs/services/subDataService.d.ts +12 -9
- package/cjs/services/subDataService.js +33 -20
- package/cjs/services/subDataService.test.js +0 -72
- package/cjs/services/triggerService.d.ts +9 -9
- package/cjs/services/triggerService.js +20 -19
- package/cjs/services/triggerService.test.js +0 -46
- package/cjs/services/utils.test.js +0 -77
- package/cjs/types/enums.d.ts +2 -3
- package/cjs/types/enums.js +1 -2
- package/esm/constants/index.js +5 -10
- package/esm/services/strategiesService.js +11 -14
- package/esm/services/strategySubService.d.ts +1 -11
- package/esm/services/strategySubService.js +5 -5
- package/esm/services/strategySubService.test.js +1 -73
- package/esm/services/subDataService.d.ts +12 -9
- package/esm/services/subDataService.js +32 -19
- package/esm/services/subDataService.test.js +0 -72
- package/esm/services/triggerService.d.ts +9 -9
- package/esm/services/triggerService.js +19 -18
- package/esm/services/triggerService.test.js +1 -47
- package/esm/services/utils.test.js +1 -52
- package/esm/types/enums.d.ts +2 -3
- package/esm/types/enums.js +1 -2
- package/package.json +1 -1
- package/src/constants/index.ts +5 -12
- package/src/services/strategiesService.ts +12 -22
- package/src/services/strategySubService.test.ts +4 -94
- package/src/services/strategySubService.ts +15 -16
- package/src/services/subDataService.test.ts +1 -78
- package/src/services/subDataService.ts +52 -31
- package/src/services/triggerService.test.ts +0 -51
- package/src/services/triggerService.ts +29 -26
- package/src/services/utils.test.ts +0 -59
- package/src/types/enums.ts +1 -2
package/cjs/constants/index.js
CHANGED
|
@@ -308,16 +308,6 @@ exports.MAINNET_BUNDLES_INFO = {
|
|
|
308
308
|
strategyId: enums_1.Strategies.Identifiers.Boost,
|
|
309
309
|
protocol: exports.PROTOCOLS.Spark,
|
|
310
310
|
},
|
|
311
|
-
[enums_1.Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT]: {
|
|
312
|
-
strategyOrBundleId: enums_1.Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT,
|
|
313
|
-
strategyId: enums_1.Strategies.Identifiers.CloseToDebt,
|
|
314
|
-
protocol: exports.PROTOCOLS.Spark,
|
|
315
|
-
},
|
|
316
|
-
[enums_1.Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL]: {
|
|
317
|
-
strategyOrBundleId: enums_1.Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL,
|
|
318
|
-
strategyId: enums_1.Strategies.Identifiers.CloseToCollateral,
|
|
319
|
-
protocol: exports.PROTOCOLS.Spark,
|
|
320
|
-
},
|
|
321
311
|
[enums_1.Bundles.MainnetIds.AAVE_V2_REPAY]: {
|
|
322
312
|
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V2_REPAY,
|
|
323
313
|
strategyId: enums_1.Strategies.Identifiers.Repay,
|
|
@@ -473,6 +463,11 @@ exports.MAINNET_BUNDLES_INFO = {
|
|
|
473
463
|
strategyId: enums_1.Strategies.Identifiers.EoaCloseOnPrice,
|
|
474
464
|
protocol: exports.PROTOCOLS.AaveV3,
|
|
475
465
|
},
|
|
466
|
+
[enums_1.Bundles.MainnetIds.SPARK_CLOSE]: {
|
|
467
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.SPARK_CLOSE,
|
|
468
|
+
strategyId: enums_1.Strategies.Identifiers.CloseOnPrice,
|
|
469
|
+
protocol: exports.PROTOCOLS.Spark,
|
|
470
|
+
},
|
|
476
471
|
};
|
|
477
472
|
exports.OPTIMISM_BUNDLES_INFO = {
|
|
478
473
|
[enums_1.Bundles.OptimismIds.AAVE_V3_REPAY]: {
|
|
@@ -36,9 +36,6 @@ const utils_1 = require("./utils");
|
|
|
36
36
|
const subDataService = __importStar(require("./subDataService"));
|
|
37
37
|
const triggerService = __importStar(require("./triggerService"));
|
|
38
38
|
const web3 = new web3_1.default();
|
|
39
|
-
const SPARK_MARKET_ADDRESSES = {
|
|
40
|
-
[enums_1.ChainId.Ethereum]: '0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE',
|
|
41
|
-
};
|
|
42
39
|
const AAVE_V3_MARKET_ADDRESSES = {
|
|
43
40
|
[enums_1.ChainId.Ethereum]: '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e',
|
|
44
41
|
[enums_1.ChainId.Optimism]: '0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb',
|
|
@@ -619,23 +616,24 @@ function parseSparkLeverageManagement(position, parseData) {
|
|
|
619
616
|
function parseSparkCloseOnPrice(position, parseData) {
|
|
620
617
|
const _position = (0, lodash_1.cloneDeep)(position);
|
|
621
618
|
const { subStruct } = parseData.subscriptionEventData;
|
|
622
|
-
const triggerData = triggerService.
|
|
623
|
-
const subData = subDataService.
|
|
619
|
+
const triggerData = triggerService.sparkQuotePriceRangeTrigger.decode(subStruct.triggerData);
|
|
620
|
+
const subData = subDataService.sparkCloseGenericSubData.decode(subStruct.subData);
|
|
624
621
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
625
622
|
_position.strategyData.decoded.subData = subData;
|
|
626
|
-
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner,
|
|
623
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
624
|
+
const { takeProfitType, stopLossType } = (0, utils_1.getStopLossAndTakeProfitTypeByCloseStrategyType)(+subData.closeType);
|
|
627
625
|
_position.specific = {
|
|
628
626
|
collAsset: subData.collAsset,
|
|
629
627
|
collAssetId: subData.collAssetId,
|
|
630
628
|
debtAsset: subData.debtAsset,
|
|
631
629
|
debtAssetId: subData.debtAssetId,
|
|
632
|
-
baseToken: triggerData.
|
|
633
|
-
quoteToken: triggerData.
|
|
634
|
-
|
|
635
|
-
|
|
630
|
+
baseToken: triggerData.collToken,
|
|
631
|
+
quoteToken: triggerData.debtToken,
|
|
632
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
633
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
634
|
+
stopLossType,
|
|
635
|
+
takeProfitType,
|
|
636
636
|
};
|
|
637
|
-
const { ratioState } = (0, utils_1.getRatioStateInfoForAaveCloseStrategy)(_position.specific.ratioState, (0, utils_1.wethToEthByAddress)(_position.specific.collAsset, parseData.chainId), (0, utils_1.wethToEthByAddress)(_position.specific.debtAsset, parseData.chainId), parseData.chainId);
|
|
638
|
-
_position.strategy.strategyId = (0, utils_1.isRatioStateOver)(ratioState) ? enums_1.Strategies.IdOverrides.TakeProfit : enums_1.Strategies.IdOverrides.StopLoss;
|
|
639
637
|
return _position;
|
|
640
638
|
}
|
|
641
639
|
function parseLiquitySavingsLiqProtection(position, parseData) {
|
|
@@ -946,8 +944,7 @@ const parsingMethodsMapping = {
|
|
|
946
944
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.Spark]: {
|
|
947
945
|
[enums_1.Strategies.Identifiers.Repay]: parseSparkLeverageManagement,
|
|
948
946
|
[enums_1.Strategies.Identifiers.Boost]: parseSparkLeverageManagement,
|
|
949
|
-
[enums_1.Strategies.Identifiers.
|
|
950
|
-
[enums_1.Strategies.Identifiers.CloseToCollateral]: parseSparkCloseOnPrice,
|
|
947
|
+
[enums_1.Strategies.Identifiers.CloseOnPrice]: parseSparkCloseOnPrice,
|
|
951
948
|
},
|
|
952
949
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
|
|
953
950
|
[enums_1.Strategies.Identifiers.Repay]: parseCrvUSDLeverageManagement,
|
|
@@ -85,17 +85,7 @@ export declare const exchangeEncode: {
|
|
|
85
85
|
};
|
|
86
86
|
export declare const sparkEncode: {
|
|
87
87
|
leverageManagement(triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean): string;
|
|
88
|
-
|
|
89
|
-
baseTokenAddress: EthereumAddress;
|
|
90
|
-
quoteTokenAddress: EthereumAddress;
|
|
91
|
-
price: number;
|
|
92
|
-
ratioState: RatioState;
|
|
93
|
-
}, subData: {
|
|
94
|
-
collAsset: EthereumAddress;
|
|
95
|
-
collAssetId: number;
|
|
96
|
-
debtAsset: EthereumAddress;
|
|
97
|
-
debtAssetId: number;
|
|
98
|
-
}): (number | boolean | string[])[];
|
|
88
|
+
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[])[];
|
|
99
89
|
};
|
|
100
90
|
export declare const crvUSDEncode: {
|
|
101
91
|
leverageManagement(owner: EthereumAddress, controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress): (boolean | string[] | Bundles.MainnetIds)[];
|
|
@@ -261,11 +261,11 @@ exports.sparkEncode = {
|
|
|
261
261
|
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
262
262
|
return subInput;
|
|
263
263
|
},
|
|
264
|
-
|
|
265
|
-
const
|
|
266
|
-
const
|
|
267
|
-
const
|
|
268
|
-
const triggerDataEncoded = triggerService.
|
|
264
|
+
closeOnPriceGeneric(strategyOrBundleId, collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, user, stopLossPrice = 0, stopLossType = enums_1.CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = enums_1.CloseToAssetType.COLLATERAL) {
|
|
265
|
+
const isBundle = true;
|
|
266
|
+
const closeType = (0, utils_1.getCloseStrategyType)(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
267
|
+
const subDataEncoded = subDataService.sparkCloseGenericSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user);
|
|
268
|
+
const triggerDataEncoded = triggerService.sparkQuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
|
|
269
269
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
270
270
|
},
|
|
271
271
|
};
|
|
@@ -1191,78 +1191,6 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1191
1191
|
});
|
|
1192
1192
|
});
|
|
1193
1193
|
});
|
|
1194
|
-
describe('When testing strategySubService.sparkEncode', () => {
|
|
1195
|
-
describe('leverageManagement()', () => {
|
|
1196
|
-
const examples = [
|
|
1197
|
-
[
|
|
1198
|
-
'0x000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
|
|
1199
|
-
[160, 220, 180, 190, true]
|
|
1200
|
-
],
|
|
1201
|
-
[
|
|
1202
|
-
'0x000000000000000016345785d8a0000000000000000000001bc16d674ec80000000000000000000018fae27693b4000000000000000000001a5e27eef13e000000',
|
|
1203
|
-
[160, 200, 180, 190, false]
|
|
1204
|
-
],
|
|
1205
|
-
];
|
|
1206
|
-
examples.forEach(([expected, actual]) => {
|
|
1207
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1208
|
-
(0, chai_1.expect)(strategySubService_1.sparkEncode.leverageManagement(...actual)).to.eql(expected);
|
|
1209
|
-
});
|
|
1210
|
-
});
|
|
1211
|
-
});
|
|
1212
|
-
describe('closeToAsset()', () => {
|
|
1213
|
-
const examples = [
|
|
1214
|
-
[
|
|
1215
|
-
[
|
|
1216
|
-
enums_1.Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL,
|
|
1217
|
-
true,
|
|
1218
|
-
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1219
|
-
[
|
|
1220
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000015',
|
|
1221
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000020',
|
|
1222
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1223
|
-
],
|
|
1224
|
-
],
|
|
1225
|
-
[
|
|
1226
|
-
enums_1.Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL,
|
|
1227
|
-
true,
|
|
1228
|
-
{
|
|
1229
|
-
baseTokenAddress: (0, tokens_1.getAssetInfo)('WETH').address, quoteTokenAddress: (0, tokens_1.getAssetInfo)('DAI').address, price: 1670, ratioState: enums_1.RatioState.OVER
|
|
1230
|
-
},
|
|
1231
|
-
{
|
|
1232
|
-
collAsset: (0, tokens_1.getAssetInfo)('WETH').address, collAssetId: 21, debtAsset: (0, tokens_1.getAssetInfo)('DAI').address, debtAssetId: 32,
|
|
1233
|
-
},
|
|
1234
|
-
]
|
|
1235
|
-
],
|
|
1236
|
-
[
|
|
1237
|
-
[
|
|
1238
|
-
enums_1.Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT,
|
|
1239
|
-
true,
|
|
1240
|
-
['0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000084d000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1241
|
-
[
|
|
1242
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000015',
|
|
1243
|
-
'0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca', '0x0000000000000000000000000000000000000000000000000000000000000020',
|
|
1244
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1245
|
-
],
|
|
1246
|
-
],
|
|
1247
|
-
[
|
|
1248
|
-
enums_1.Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT,
|
|
1249
|
-
true,
|
|
1250
|
-
{
|
|
1251
|
-
baseTokenAddress: (0, tokens_1.getAssetInfo)('LINK').address, quoteTokenAddress: (0, tokens_1.getAssetInfo)('DAI').address, price: 0.00544, ratioState: enums_1.RatioState.UNDER
|
|
1252
|
-
},
|
|
1253
|
-
{
|
|
1254
|
-
collAsset: (0, tokens_1.getAssetInfo)('DAI').address, collAssetId: 21, debtAsset: (0, tokens_1.getAssetInfo)('LINK').address, debtAssetId: 32,
|
|
1255
|
-
},
|
|
1256
|
-
]
|
|
1257
|
-
]
|
|
1258
|
-
];
|
|
1259
|
-
examples.forEach(([expected, actual]) => {
|
|
1260
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1261
|
-
(0, chai_1.expect)(strategySubService_1.sparkEncode.closeToAsset(...actual)).to.eql(expected);
|
|
1262
|
-
});
|
|
1263
|
-
});
|
|
1264
|
-
});
|
|
1265
|
-
});
|
|
1266
1194
|
describe('When testing strategySubService.crvUSDEncode', () => {
|
|
1267
1195
|
describe('leverageManagement()', () => {
|
|
1268
1196
|
const examples = [
|
|
@@ -166,15 +166,6 @@ export declare const sparkLeverageManagementSubData: {
|
|
|
166
166
|
targetRatio: number;
|
|
167
167
|
};
|
|
168
168
|
};
|
|
169
|
-
export declare const sparkQuotePriceSubData: {
|
|
170
|
-
encode(collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, nullAddress?: EthereumAddress): string[];
|
|
171
|
-
decode(subData: string[]): {
|
|
172
|
-
collAsset: EthereumAddress;
|
|
173
|
-
collAssetId: number;
|
|
174
|
-
debtAsset: EthereumAddress;
|
|
175
|
-
debtAssetId: number;
|
|
176
|
-
};
|
|
177
|
-
};
|
|
178
169
|
export declare const liquityDsrPaybackSubData: {
|
|
179
170
|
encode: (targetRatio: number) => string[];
|
|
180
171
|
decode: (subData: string[]) => {
|
|
@@ -315,3 +306,15 @@ export declare const compoundV3CloseSubData: {
|
|
|
315
306
|
owner: EthereumAddress;
|
|
316
307
|
};
|
|
317
308
|
};
|
|
309
|
+
export declare const sparkCloseGenericSubData: {
|
|
310
|
+
encode(collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, closeType: CloseStrategyType, marketAddr: EthereumAddress, user: EthereumAddress): string[];
|
|
311
|
+
decode(subData: string[]): {
|
|
312
|
+
collAsset: EthereumAddress;
|
|
313
|
+
collAssetId: number;
|
|
314
|
+
debtAsset: EthereumAddress;
|
|
315
|
+
debtAssetId: number;
|
|
316
|
+
closeType: CloseStrategyType;
|
|
317
|
+
marketAddr: EthereumAddress;
|
|
318
|
+
owner: EthereumAddress;
|
|
319
|
+
};
|
|
320
|
+
};
|
|
@@ -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.compoundV3CloseSubData = exports.compoundV3LeverageManagementOnPriceSubData = exports.fluidLeverageManagementSubData = 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.
|
|
6
|
+
exports.sparkCloseGenericSubData = exports.compoundV3CloseSubData = exports.compoundV3LeverageManagementOnPriceSubData = exports.fluidLeverageManagementSubData = 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.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = exports.compoundV3L2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3CollateralSwitchSubData = exports.aaveV3CloseGenericSubData = exports.aaveV3LeverageManagementOnPriceGeneric = exports.aaveV3LeverageManagementSubDataWithoutSubProxy = 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");
|
|
@@ -417,25 +417,6 @@ exports.sparkLeverageManagementSubData = {
|
|
|
417
417
|
return { targetRatio };
|
|
418
418
|
},
|
|
419
419
|
};
|
|
420
|
-
exports.sparkQuotePriceSubData = {
|
|
421
|
-
encode(collAsset, collAssetId, debtAsset, debtAssetId, nullAddress = constants_1.ZERO_ADDRESS) {
|
|
422
|
-
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
423
|
-
const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
|
|
424
|
-
const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
|
|
425
|
-
const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
|
|
426
|
-
const encodedNullAddress = web3_eth_abi_1.default.encodeParameter('address', nullAddress);
|
|
427
|
-
return [encodedColl, encodedCollId, encodedDebt, encodedDebtId, encodedNullAddress];
|
|
428
|
-
},
|
|
429
|
-
decode(subData) {
|
|
430
|
-
const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
431
|
-
const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
432
|
-
const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
433
|
-
const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
434
|
-
return {
|
|
435
|
-
collAsset, collAssetId, debtAsset, debtAssetId,
|
|
436
|
-
};
|
|
437
|
-
},
|
|
438
|
-
};
|
|
439
420
|
exports.liquityDsrPaybackSubData = {
|
|
440
421
|
encode: (targetRatio) => {
|
|
441
422
|
const daiAddress = (0, tokens_1.getAssetInfo)('DAI').address;
|
|
@@ -845,3 +826,35 @@ exports.compoundV3CloseSubData = {
|
|
|
845
826
|
};
|
|
846
827
|
},
|
|
847
828
|
};
|
|
829
|
+
exports.sparkCloseGenericSubData = {
|
|
830
|
+
encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user) {
|
|
831
|
+
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
832
|
+
const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
|
|
833
|
+
const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
|
|
834
|
+
const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
|
|
835
|
+
const encodedCloseType = web3_eth_abi_1.default.encodeParameter('uint8', closeType);
|
|
836
|
+
const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
|
|
837
|
+
const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
|
|
838
|
+
return [
|
|
839
|
+
encodedColl,
|
|
840
|
+
encodedCollId,
|
|
841
|
+
encodedDebt,
|
|
842
|
+
encodedDebtId,
|
|
843
|
+
encodedCloseType,
|
|
844
|
+
encodedMarket,
|
|
845
|
+
userEncoded,
|
|
846
|
+
];
|
|
847
|
+
},
|
|
848
|
+
decode(subData) {
|
|
849
|
+
const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
850
|
+
const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
851
|
+
const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
852
|
+
const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
853
|
+
const closeType = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[4]));
|
|
854
|
+
const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[5]);
|
|
855
|
+
const owner = web3_eth_abi_1.default.decodeParameter('address', subData[6]);
|
|
856
|
+
return {
|
|
857
|
+
collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner,
|
|
858
|
+
};
|
|
859
|
+
},
|
|
860
|
+
};
|
|
@@ -901,78 +901,6 @@ describe('Feature: subDataService.ts', () => {
|
|
|
901
901
|
});
|
|
902
902
|
});
|
|
903
903
|
});
|
|
904
|
-
describe('When testing subDataService.sparkQuotePriceSubData', () => {
|
|
905
|
-
describe('encode()', () => {
|
|
906
|
-
const examples = [
|
|
907
|
-
[
|
|
908
|
-
[
|
|
909
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
910
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
911
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
912
|
-
],
|
|
913
|
-
[
|
|
914
|
-
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
915
|
-
2,
|
|
916
|
-
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
917
|
-
4,
|
|
918
|
-
]
|
|
919
|
-
],
|
|
920
|
-
[
|
|
921
|
-
[
|
|
922
|
-
'0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
|
|
923
|
-
'0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
924
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
925
|
-
],
|
|
926
|
-
[
|
|
927
|
-
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('wstETH', enums_1.ChainId.Arbitrum).address),
|
|
928
|
-
6,
|
|
929
|
-
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Arbitrum).address),
|
|
930
|
-
2,
|
|
931
|
-
]
|
|
932
|
-
],
|
|
933
|
-
];
|
|
934
|
-
examples.forEach(([expected, actual]) => {
|
|
935
|
-
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
936
|
-
(0, chai_1.expect)(subDataService.sparkQuotePriceSubData.encode(...actual)).to.eql(expected);
|
|
937
|
-
});
|
|
938
|
-
});
|
|
939
|
-
});
|
|
940
|
-
describe('decode()', () => {
|
|
941
|
-
const examples = [
|
|
942
|
-
[
|
|
943
|
-
{
|
|
944
|
-
collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
945
|
-
collAssetId: 2,
|
|
946
|
-
debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
947
|
-
debtAssetId: 4,
|
|
948
|
-
},
|
|
949
|
-
[
|
|
950
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
951
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
952
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
953
|
-
],
|
|
954
|
-
],
|
|
955
|
-
[
|
|
956
|
-
{
|
|
957
|
-
collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('wstETH', enums_1.ChainId.Arbitrum).address),
|
|
958
|
-
collAssetId: 6,
|
|
959
|
-
debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Arbitrum).address),
|
|
960
|
-
debtAssetId: 2,
|
|
961
|
-
},
|
|
962
|
-
[
|
|
963
|
-
'0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
|
|
964
|
-
'0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
965
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
966
|
-
],
|
|
967
|
-
],
|
|
968
|
-
];
|
|
969
|
-
examples.forEach(([expected, actual]) => {
|
|
970
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
971
|
-
(0, chai_1.expect)(subDataService.sparkQuotePriceSubData.decode(actual)).to.eql(expected);
|
|
972
|
-
});
|
|
973
|
-
});
|
|
974
|
-
});
|
|
975
|
-
});
|
|
976
904
|
describe('When testing subDataService.liquityDsrPaybackSubData', () => {
|
|
977
905
|
describe('encode()', () => {
|
|
978
906
|
const examples = [
|
|
@@ -153,15 +153,6 @@ export declare const sparkRatioTrigger: {
|
|
|
153
153
|
ratioState: number;
|
|
154
154
|
};
|
|
155
155
|
};
|
|
156
|
-
export declare const sparkQuotePriceTrigger: {
|
|
157
|
-
encode(baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState): string[];
|
|
158
|
-
decode(triggerData: string[]): {
|
|
159
|
-
baseTokenAddress: EthereumAddress;
|
|
160
|
-
quoteTokenAddress: EthereumAddress;
|
|
161
|
-
price: string;
|
|
162
|
-
ratioState: RatioState;
|
|
163
|
-
};
|
|
164
|
-
};
|
|
165
156
|
export declare const curveUsdBorrowRateTrigger: {
|
|
166
157
|
encode(market: EthereumAddress, targetRate: string, rateState: RatioState): string[];
|
|
167
158
|
decode(triggerData: string[]): {
|
|
@@ -275,3 +266,12 @@ export declare const aaveV3QuotePriceRangeTrigger: {
|
|
|
275
266
|
upperPrice: string;
|
|
276
267
|
};
|
|
277
268
|
};
|
|
269
|
+
export declare const sparkQuotePriceRangeTrigger: {
|
|
270
|
+
encode(collToken: EthereumAddress, debtToken: EthereumAddress, lowerPrice: number, upperPrice: number): string[];
|
|
271
|
+
decode(triggerData: string[]): {
|
|
272
|
+
collToken: string;
|
|
273
|
+
debtToken: string;
|
|
274
|
+
lowerPrice: string;
|
|
275
|
+
upperPrice: string;
|
|
276
|
+
};
|
|
277
|
+
};
|
|
@@ -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.aaveV3QuotePriceRangeTrigger = exports.compoundV3PriceRangeTrigger = exports.compoundV3PriceTrigger = exports.fluidRatioTrigger = exports.morphoBluePriceTrigger = exports.closePriceTrigger = exports.liquityV2QuotePriceTrigger = exports.liquityV2RatioTrigger = exports.morphoBlueRatioTrigger = exports.crvUsdHealthRatioTrigger = exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.
|
|
29
|
+
exports.sparkQuotePriceRangeTrigger = exports.aaveV3QuotePriceRangeTrigger = exports.compoundV3PriceRangeTrigger = exports.compoundV3PriceTrigger = exports.fluidRatioTrigger = exports.morphoBluePriceTrigger = exports.closePriceTrigger = exports.liquityV2QuotePriceTrigger = exports.liquityV2RatioTrigger = exports.morphoBlueRatioTrigger = exports.crvUsdHealthRatioTrigger = exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityV2AdjustTimeTrigger = exports.liquityV2DebtInFrontTrigger = 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"));
|
|
@@ -290,24 +290,6 @@ exports.sparkRatioTrigger = {
|
|
|
290
290
|
};
|
|
291
291
|
},
|
|
292
292
|
};
|
|
293
|
-
exports.sparkQuotePriceTrigger = {
|
|
294
|
-
encode(baseTokenAddress, quoteTokenAddress, price, ratioState) {
|
|
295
|
-
// Price is always in 8 decimals
|
|
296
|
-
const _price = new decimal_js_1.default(price.toString()).mul(Math.pow(10, 8)).floor().toString();
|
|
297
|
-
return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [baseTokenAddress, quoteTokenAddress, _price, ratioState])];
|
|
298
|
-
},
|
|
299
|
-
decode(triggerData) {
|
|
300
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
301
|
-
// Price is always in 8 decimals
|
|
302
|
-
const price = new decimal_js_1.default(decodedData[2]).div(Math.pow(10, 8)).toDP(8).toString();
|
|
303
|
-
return {
|
|
304
|
-
price,
|
|
305
|
-
baseTokenAddress: decodedData[0],
|
|
306
|
-
quoteTokenAddress: decodedData[1],
|
|
307
|
-
ratioState: +decodedData[3],
|
|
308
|
-
};
|
|
309
|
-
},
|
|
310
|
-
};
|
|
311
293
|
exports.curveUsdBorrowRateTrigger = {
|
|
312
294
|
encode(market, targetRate, rateState) {
|
|
313
295
|
// the form is x = (e**(rate*365*86400))-1 where x*100 is number in %
|
|
@@ -526,3 +508,22 @@ exports.aaveV3QuotePriceRangeTrigger = {
|
|
|
526
508
|
};
|
|
527
509
|
},
|
|
528
510
|
};
|
|
511
|
+
exports.sparkQuotePriceRangeTrigger = {
|
|
512
|
+
encode(collToken, debtToken, lowerPrice, upperPrice) {
|
|
513
|
+
// Price is scaled to 1e8
|
|
514
|
+
const lowerPriceFormatted = new decimal_js_1.default(lowerPrice).mul(1e8).floor().toString();
|
|
515
|
+
const upperPriceFormatted = new decimal_js_1.default(upperPrice).mul(1e8).floor().toString();
|
|
516
|
+
return [
|
|
517
|
+
web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint256'], [collToken, debtToken, lowerPriceFormatted, upperPriceFormatted]),
|
|
518
|
+
];
|
|
519
|
+
},
|
|
520
|
+
decode(triggerData) {
|
|
521
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint256'], triggerData[0]);
|
|
522
|
+
return {
|
|
523
|
+
collToken: decodedData[0],
|
|
524
|
+
debtToken: decodedData[1],
|
|
525
|
+
lowerPrice: new decimal_js_1.default(decodedData[2]).div(1e8).toString(),
|
|
526
|
+
upperPrice: new decimal_js_1.default(decodedData[3]).div(1e8).toString(),
|
|
527
|
+
};
|
|
528
|
+
},
|
|
529
|
+
};
|
|
@@ -806,52 +806,6 @@ describe('Feature: triggerService.ts', () => {
|
|
|
806
806
|
});
|
|
807
807
|
});
|
|
808
808
|
});
|
|
809
|
-
describe('When testing triggerService.sparkQuotePriceTrigger', () => {
|
|
810
|
-
describe('encode()', () => {
|
|
811
|
-
const examples = [
|
|
812
|
-
[
|
|
813
|
-
['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000000000000000000000000000000000000000a8ca0000000000000000000000000000000000000000000000000000000000000001'],
|
|
814
|
-
[(0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address, (0, tokens_1.getAssetInfo)('wstETH', enums_1.ChainId.Ethereum).address, 0.0004321, enums_1.RatioState.UNDER]
|
|
815
|
-
],
|
|
816
|
-
[
|
|
817
|
-
['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000186b70000000000000000000000000000000000000000000000000000000000000000'],
|
|
818
|
-
[(0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Arbitrum).address, (0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Arbitrum).address, 0.00100023, enums_1.RatioState.OVER]
|
|
819
|
-
],
|
|
820
|
-
];
|
|
821
|
-
examples.forEach(([expected, actual]) => {
|
|
822
|
-
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
823
|
-
(0, chai_1.expect)(triggerService_1.sparkQuotePriceTrigger.encode(...actual)).to.eql(expected);
|
|
824
|
-
});
|
|
825
|
-
});
|
|
826
|
-
});
|
|
827
|
-
describe('decode()', () => {
|
|
828
|
-
const examples = [
|
|
829
|
-
[
|
|
830
|
-
{
|
|
831
|
-
baseTokenAddress: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
832
|
-
quoteTokenAddress: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('wstETH', enums_1.ChainId.Ethereum).address),
|
|
833
|
-
price: '0.0004321',
|
|
834
|
-
ratioState: enums_1.RatioState.UNDER,
|
|
835
|
-
},
|
|
836
|
-
['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000000000000000000000000000000000000000a8ca0000000000000000000000000000000000000000000000000000000000000001'],
|
|
837
|
-
],
|
|
838
|
-
[
|
|
839
|
-
{
|
|
840
|
-
baseTokenAddress: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Arbitrum).address),
|
|
841
|
-
quoteTokenAddress: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Arbitrum).address),
|
|
842
|
-
price: '0.00100023',
|
|
843
|
-
ratioState: enums_1.RatioState.OVER,
|
|
844
|
-
},
|
|
845
|
-
['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000186b70000000000000000000000000000000000000000000000000000000000000000'],
|
|
846
|
-
]
|
|
847
|
-
];
|
|
848
|
-
examples.forEach(([expected, actual]) => {
|
|
849
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
850
|
-
(0, chai_1.expect)(triggerService_1.sparkQuotePriceTrigger.decode(actual)).to.eql(expected);
|
|
851
|
-
});
|
|
852
|
-
});
|
|
853
|
-
});
|
|
854
|
-
});
|
|
855
809
|
describe('When testing triggerService.curveUsdBorrowRateTrigger', () => {
|
|
856
810
|
describe('encode()', () => {
|
|
857
811
|
const examples = [
|
|
@@ -1,37 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
3
|
const chai_1 = require("chai");
|
|
30
|
-
const web3Utils = __importStar(require("web3-utils"));
|
|
31
|
-
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
32
4
|
const tokens_1 = require("@defisaver/tokens");
|
|
33
5
|
const enums_1 = require("../types/enums");
|
|
34
|
-
const strategySubService_1 = require("./strategySubService");
|
|
35
6
|
require("../configuration");
|
|
36
7
|
const utils_1 = require("./utils");
|
|
37
8
|
describe('Feature: utils.ts', () => {
|
|
@@ -167,54 +138,6 @@ describe('Feature: utils.ts', () => {
|
|
|
167
138
|
});
|
|
168
139
|
});
|
|
169
140
|
});
|
|
170
|
-
describe('When testing utils.compareSubHashes()', () => {
|
|
171
|
-
const subDataToEncodeOne = [
|
|
172
|
-
12,
|
|
173
|
-
false,
|
|
174
|
-
{
|
|
175
|
-
baseTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
176
|
-
quoteTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
177
|
-
price: 100,
|
|
178
|
-
ratioState: 1,
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
collAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
182
|
-
collAssetId: 2,
|
|
183
|
-
debtAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
184
|
-
debtAssetId: 3,
|
|
185
|
-
},
|
|
186
|
-
];
|
|
187
|
-
const subDataToEncodeTwo = [
|
|
188
|
-
13,
|
|
189
|
-
true,
|
|
190
|
-
{
|
|
191
|
-
baseTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
192
|
-
quoteTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
193
|
-
price: 100,
|
|
194
|
-
ratioState: 2,
|
|
195
|
-
},
|
|
196
|
-
{
|
|
197
|
-
collAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
198
|
-
collAssetId: 2,
|
|
199
|
-
debtAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
200
|
-
debtAssetId: 3,
|
|
201
|
-
},
|
|
202
|
-
];
|
|
203
|
-
// @ts-ignore
|
|
204
|
-
const encodedSubDataOne = strategySubService_1.sparkEncode.closeToAsset(...subDataToEncodeOne);
|
|
205
|
-
// @ts-ignore
|
|
206
|
-
const encodedSubDataTwo = strategySubService_1.sparkEncode.closeToAsset(...subDataToEncodeTwo);
|
|
207
|
-
const encodedParams = web3Utils.keccak256(web3_eth_abi_1.default.encodeParameter('(uint64,bool,bytes[],bytes32[])', encodedSubDataOne));
|
|
208
|
-
const examples = [
|
|
209
|
-
[true, [encodedParams, encodedSubDataOne]],
|
|
210
|
-
[false, [encodedParams, encodedSubDataTwo]],
|
|
211
|
-
];
|
|
212
|
-
examples.forEach(([expected, actual]) => {
|
|
213
|
-
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
214
|
-
(0, chai_1.expect)((0, utils_1.compareSubHashes)(...actual)).to.equal(expected);
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
141
|
describe('When testing utils.encodeSubId()', () => {
|
|
219
142
|
const examples = [
|
|
220
143
|
['00000001', '1'],
|
package/cjs/types/enums.d.ts
CHANGED
|
@@ -171,8 +171,6 @@ export declare namespace Bundles {
|
|
|
171
171
|
LIQUITY_BOOST = 17,
|
|
172
172
|
SPARK_REPAY = 18,
|
|
173
173
|
SPARK_BOOST = 19,
|
|
174
|
-
SPARK_CLOSE_TO_DEBT = -21231230,
|
|
175
|
-
SPARK_CLOSE_TO_COLLATERAL = -21231231,
|
|
176
174
|
AAVE_V2_REPAY = 22,
|
|
177
175
|
AAVE_V2_BOOST = 23,
|
|
178
176
|
COMP_V2_REPAY = 20,
|
|
@@ -207,7 +205,8 @@ export declare namespace Bundles {
|
|
|
207
205
|
AAVE_V3_EOA_BOOST = 53,
|
|
208
206
|
AAVE_V3_EOA_REPAY_ON_PRICE = 54,
|
|
209
207
|
AAVE_V3_EOA_BOOST_ON_PRICE = 55,
|
|
210
|
-
AAVE_V3_EOA_CLOSE = 56
|
|
208
|
+
AAVE_V3_EOA_CLOSE = 56,
|
|
209
|
+
SPARK_CLOSE = 57
|
|
211
210
|
}
|
|
212
211
|
enum OptimismIds {
|
|
213
212
|
AAVE_V3_REPAY = 0,
|