@defisaver/automation-sdk 3.3.14 → 3.3.15
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/services/strategiesService.js +30 -17
- package/cjs/services/strategySubService.d.ts +5 -11
- package/cjs/services/strategySubService.js +27 -62
- package/cjs/services/strategySubService.test.js +0 -234
- package/cjs/services/subDataService.d.ts +35 -2
- package/cjs/services/subDataService.js +84 -20
- package/cjs/services/subDataService.test.js +0 -42
- package/esm/services/strategiesService.js +30 -17
- package/esm/services/strategySubService.d.ts +5 -11
- package/esm/services/strategySubService.js +26 -58
- package/esm/services/strategySubService.test.js +2 -236
- package/esm/services/subDataService.d.ts +35 -2
- package/esm/services/subDataService.js +82 -19
- package/esm/services/subDataService.test.js +0 -42
- package/package.json +1 -1
- package/src/services/strategiesService.ts +30 -17
- package/src/services/strategySubService.test.ts +0 -279
- package/src/services/strategySubService.ts +60 -111
- package/src/services/subDataService.test.ts +0 -48
- package/src/services/subDataService.ts +107 -28
|
@@ -81,23 +81,6 @@ export const makerEncode = {
|
|
|
81
81
|
|
|
82
82
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
83
83
|
},
|
|
84
|
-
leverageManagement(
|
|
85
|
-
vaultId: number,
|
|
86
|
-
triggerRepayRatio: string,
|
|
87
|
-
triggerBoostRatio: string,
|
|
88
|
-
targetBoostRatio: string,
|
|
89
|
-
targetRepayRatio: string,
|
|
90
|
-
boostEnabled: boolean,
|
|
91
|
-
) {
|
|
92
|
-
return [
|
|
93
|
-
vaultId,
|
|
94
|
-
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
95
|
-
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
96
|
-
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
97
|
-
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
98
|
-
boostEnabled,
|
|
99
|
-
];
|
|
100
|
-
},
|
|
101
84
|
leverageManagementWithoutSubProxy(
|
|
102
85
|
vaultId: number,
|
|
103
86
|
triggerRatio: number,
|
|
@@ -179,20 +162,19 @@ export const liquityEncode = {
|
|
|
179
162
|
|
|
180
163
|
return [strategyId, isBundle, triggerData, subData];
|
|
181
164
|
},
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
165
|
+
leverageManagementWithoutSubProxy(
|
|
166
|
+
strategyOrBundleId: number,
|
|
167
|
+
user: EthereumAddress,
|
|
168
|
+
ratioState: RatioState,
|
|
169
|
+
targetRatio: number,
|
|
170
|
+
triggerRatio: number,
|
|
188
171
|
) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
];
|
|
172
|
+
const isBundle = true;
|
|
173
|
+
|
|
174
|
+
const subData = subDataService.liquityLeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState);
|
|
175
|
+
const triggerData = triggerService.liquityRatioTrigger.encode(user, triggerRatio, ratioState);
|
|
176
|
+
|
|
177
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
196
178
|
},
|
|
197
179
|
dsrPayback(
|
|
198
180
|
proxyAddress: EthereumAddress,
|
|
@@ -248,39 +230,24 @@ export const chickenBondsEncode = {
|
|
|
248
230
|
};
|
|
249
231
|
|
|
250
232
|
export const aaveV2Encode = {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
233
|
+
leverageManagementWithoutSubProxy(
|
|
234
|
+
strategyOrBundleId: number,
|
|
235
|
+
market: EthereumAddress,
|
|
236
|
+
user: EthereumAddress,
|
|
237
|
+
ratioState: RatioState,
|
|
238
|
+
targetRatio: number,
|
|
239
|
+
triggerRatio: number,
|
|
257
240
|
) {
|
|
258
|
-
|
|
241
|
+
const isBundle = true;
|
|
242
|
+
|
|
243
|
+
const subData = subDataService.aaveV2LeverageManagementSubDataWithoutSubProxy.encode(market, targetRatio, ratioState);
|
|
244
|
+
const triggerData = triggerService.aaveV2RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
245
|
+
|
|
246
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
259
247
|
},
|
|
260
248
|
};
|
|
261
249
|
|
|
262
250
|
export const aaveV3Encode = {
|
|
263
|
-
leverageManagement(
|
|
264
|
-
triggerRepayRatio: number,
|
|
265
|
-
triggerBoostRatio: number,
|
|
266
|
-
targetBoostRatio: number,
|
|
267
|
-
targetRepayRatio: number,
|
|
268
|
-
boostEnabled: boolean,
|
|
269
|
-
) {
|
|
270
|
-
let subInput = '0x';
|
|
271
|
-
|
|
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
251
|
closeToAsset(
|
|
285
252
|
strategyOrBundleId: number,
|
|
286
253
|
isBundle: boolean = true,
|
|
@@ -441,29 +408,38 @@ export const aaveV3Encode = {
|
|
|
441
408
|
};
|
|
442
409
|
|
|
443
410
|
export const compoundV2Encode = {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
411
|
+
leverageManagementWithoutSubProxy(
|
|
412
|
+
strategyOrBundleId: number,
|
|
413
|
+
user: EthereumAddress,
|
|
414
|
+
ratioState: RatioState,
|
|
415
|
+
targetRatio: number,
|
|
416
|
+
triggerRatio: number,
|
|
450
417
|
) {
|
|
451
|
-
|
|
418
|
+
const isBundle = true;
|
|
419
|
+
|
|
420
|
+
const subData = subDataService.compoundV2LeverageManagementSubDataWithoutSubProxy.encode(targetRatio, ratioState);
|
|
421
|
+
const triggerData = triggerService.compoundV2RatioTrigger.encode(user, triggerRatio, ratioState);
|
|
422
|
+
|
|
423
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
452
424
|
},
|
|
453
425
|
};
|
|
454
426
|
|
|
455
427
|
export const compoundV3Encode = {
|
|
456
|
-
|
|
428
|
+
leverageManagementWithoutSubProxy(
|
|
429
|
+
strategyOrBundleId: number,
|
|
457
430
|
market: EthereumAddress,
|
|
458
431
|
baseToken: EthereumAddress,
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
boostEnabled: boolean,
|
|
464
|
-
isEOA: boolean,
|
|
432
|
+
user: EthereumAddress,
|
|
433
|
+
ratioState: RatioState,
|
|
434
|
+
targetRatio: number,
|
|
435
|
+
triggerRatio: number,
|
|
465
436
|
) {
|
|
466
|
-
|
|
437
|
+
const isBundle = true;
|
|
438
|
+
|
|
439
|
+
const subData = subDataService.compoundV3LeverageManagementSubDataWithoutSubProxy.encode(market, baseToken, targetRatio, ratioState);
|
|
440
|
+
const triggerData = triggerService.compoundV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
441
|
+
|
|
442
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
467
443
|
},
|
|
468
444
|
leverageManagementOnPrice(
|
|
469
445
|
strategyOrBundleId: number,
|
|
@@ -503,21 +479,6 @@ export const compoundV3Encode = {
|
|
|
503
479
|
},
|
|
504
480
|
};
|
|
505
481
|
|
|
506
|
-
export const compoundV3L2Encode = {
|
|
507
|
-
leverageManagement(
|
|
508
|
-
market: EthereumAddress,
|
|
509
|
-
baseToken: EthereumAddress,
|
|
510
|
-
triggerRepayRatio: number,
|
|
511
|
-
triggerBoostRatio: number,
|
|
512
|
-
targetBoostRatio: number,
|
|
513
|
-
targetRepayRatio: number,
|
|
514
|
-
boostEnabled: boolean,
|
|
515
|
-
isEOA: boolean = false,
|
|
516
|
-
) {
|
|
517
|
-
return subDataService.compoundV3L2LeverageManagementSubData.encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA);
|
|
518
|
-
},
|
|
519
|
-
};
|
|
520
|
-
|
|
521
482
|
export const morphoAaveV2Encode = {
|
|
522
483
|
leverageManagement(
|
|
523
484
|
triggerRepayRatio: number,
|
|
@@ -547,40 +508,28 @@ export const exchangeEncode = {
|
|
|
547
508
|
|
|
548
509
|
return [strategyId, false, triggerData, subData];
|
|
549
510
|
},
|
|
550
|
-
|
|
511
|
+
limitOrderWithoutSubProxy(
|
|
551
512
|
fromToken: EthereumAddress,
|
|
552
513
|
toToken: EthereumAddress,
|
|
553
514
|
amount: string,
|
|
554
515
|
targetPrice: string,
|
|
555
516
|
goodUntil: string | number,
|
|
556
517
|
orderType: OrderType,
|
|
518
|
+
fromTokenDecimals: number,
|
|
519
|
+
toTokenDecimals: number,
|
|
520
|
+
network: ChainId,
|
|
557
521
|
) {
|
|
558
|
-
|
|
522
|
+
requireAddresses([fromToken, toToken]);
|
|
523
|
+
const subData = subDataService.exchangeLimitOrderSubDataWithoutSubProxy.encode(fromToken, toToken, amount);
|
|
524
|
+
const triggerData = triggerService.exchangeOffchainPriceTrigger.encode(targetPrice, Number(goodUntil), orderType, fromTokenDecimals, toTokenDecimals);
|
|
525
|
+
|
|
526
|
+
const strategyId = STRATEGY_IDS[network].EXCHANGE_LIMIT_ORDER;
|
|
527
|
+
|
|
528
|
+
return [strategyId, false, triggerData, subData];
|
|
559
529
|
},
|
|
560
530
|
};
|
|
561
531
|
|
|
562
532
|
export const sparkEncode = {
|
|
563
|
-
leverageManagement(
|
|
564
|
-
triggerRepayRatio: number,
|
|
565
|
-
triggerBoostRatio: number,
|
|
566
|
-
targetBoostRatio: number,
|
|
567
|
-
targetRepayRatio: number,
|
|
568
|
-
boostEnabled: boolean,
|
|
569
|
-
) {
|
|
570
|
-
let subInput = '0x';
|
|
571
|
-
|
|
572
|
-
subInput = subInput.concat(new Dec(triggerRepayRatio).mul(1e16).toHex().slice(2)
|
|
573
|
-
.padStart(32, '0'));
|
|
574
|
-
subInput = subInput.concat(new Dec(triggerBoostRatio).mul(1e16).toHex().slice(2)
|
|
575
|
-
.padStart(32, '0'));
|
|
576
|
-
subInput = subInput.concat(new Dec(targetBoostRatio).mul(1e16).toHex().slice(2)
|
|
577
|
-
.padStart(32, '0'));
|
|
578
|
-
subInput = subInput.concat(new Dec(targetRepayRatio).mul(1e16).toHex().slice(2)
|
|
579
|
-
.padStart(32, '0'));
|
|
580
|
-
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
581
|
-
|
|
582
|
-
return subInput;
|
|
583
|
-
},
|
|
584
533
|
leverageManagementOnPrice(
|
|
585
534
|
strategyOrBundleId: number,
|
|
586
535
|
isBundle: boolean = true,
|
|
@@ -1408,54 +1408,6 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1408
1408
|
});
|
|
1409
1409
|
});
|
|
1410
1410
|
|
|
1411
|
-
describe('When testing subDataService.compoundV3L2LeverageManagementSubData', () => {
|
|
1412
|
-
describe('encode()', () => {
|
|
1413
|
-
const examples: Array<[
|
|
1414
|
-
string,
|
|
1415
|
-
[market: EthereumAddress, baseToken: EthereumAddress, triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean, isEOA: boolean],
|
|
1416
|
-
]> = [
|
|
1417
|
-
[
|
|
1418
|
-
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e00000100',
|
|
1419
|
-
[web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 190, true, false]
|
|
1420
|
-
],
|
|
1421
|
-
[
|
|
1422
|
-
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee00000000',
|
|
1423
|
-
[web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 110, false, false]
|
|
1424
|
-
],
|
|
1425
|
-
];
|
|
1426
|
-
|
|
1427
|
-
examples.forEach(([expected, actual]) => {
|
|
1428
|
-
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1429
|
-
expect(subDataService.compoundV3L2LeverageManagementSubData.encode(...actual)).to.eql(expected);
|
|
1430
|
-
});
|
|
1431
|
-
});
|
|
1432
|
-
});
|
|
1433
|
-
describe('decode()', () => {
|
|
1434
|
-
const examples: Array<[{ targetRatio: number }, SubData]> = [
|
|
1435
|
-
[
|
|
1436
|
-
{ targetRatio: 200 },
|
|
1437
|
-
[
|
|
1438
|
-
'0x0000000000000000000000000313d212133AFaB8F2B829B1066c7E43cAd94E2c', '0x0000000000000000000000000213d212133AFaB8F2B829B1066c7E43cAd94E2c',
|
|
1439
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1440
|
-
],
|
|
1441
|
-
],
|
|
1442
|
-
[
|
|
1443
|
-
{ targetRatio: 123 },
|
|
1444
|
-
[
|
|
1445
|
-
'0x0000000000000000000000000313d212133AFaB8F2B829B1066c7E43cAd94E2c', '0x0000000000000000000000000413d212133AFaB8F2B829B1066c7E43cAd94E2c',
|
|
1446
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
|
|
1447
|
-
],
|
|
1448
|
-
],
|
|
1449
|
-
];
|
|
1450
|
-
|
|
1451
|
-
examples.forEach(([expected, actual]) => {
|
|
1452
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1453
|
-
expect(subDataService.compoundV3L2LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
1454
|
-
});
|
|
1455
|
-
});
|
|
1456
|
-
});
|
|
1457
|
-
});
|
|
1458
|
-
|
|
1459
1411
|
describe('When testing subDataService.morphoBlueLeverageManagementSubData', () => {
|
|
1460
1412
|
describe('encode()', () => {
|
|
1461
1413
|
const examples: Array<[
|
|
@@ -207,6 +207,30 @@ export const liquityLeverageManagementSubData = {
|
|
|
207
207
|
return { targetRatio };
|
|
208
208
|
},
|
|
209
209
|
};
|
|
210
|
+
export const liquityLeverageManagementSubDataWithoutSubProxy = {
|
|
211
|
+
encode(
|
|
212
|
+
targetRatio: number,
|
|
213
|
+
ratioState: RatioState,
|
|
214
|
+
): SubData {
|
|
215
|
+
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
216
|
+
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
217
|
+
|
|
218
|
+
const isRepay = ratioState === RatioState.UNDER;
|
|
219
|
+
const collActionType = isRepay ? CollActionType.WITHDRAW : CollActionType.SUPPLY;
|
|
220
|
+
const debtActionType = isRepay ? DebtActionType.PAYBACK : DebtActionType.BORROW;
|
|
221
|
+
|
|
222
|
+
const collActionTypeEncoded = AbiCoder.encodeParameter('uint8', collActionType);
|
|
223
|
+
const debtActionTypeEncoded = AbiCoder.encodeParameter('uint8', debtActionType);
|
|
224
|
+
|
|
225
|
+
return [encodedRatioState, encodedTargetRatio, collActionTypeEncoded, debtActionTypeEncoded];
|
|
226
|
+
},
|
|
227
|
+
decode(subData: SubData): { targetRatio: number, ratioState: RatioState } {
|
|
228
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[0]) as any as RatioState;
|
|
229
|
+
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[1]) as any as string);
|
|
230
|
+
|
|
231
|
+
return { targetRatio, ratioState };
|
|
232
|
+
},
|
|
233
|
+
};
|
|
210
234
|
export const liquityCloseSubData = {
|
|
211
235
|
encode(
|
|
212
236
|
closeToAssetAddr: EthereumAddress,
|
|
@@ -510,6 +534,33 @@ export const aaveV2LeverageManagementSubData = {
|
|
|
510
534
|
return { targetRatio };
|
|
511
535
|
},
|
|
512
536
|
};
|
|
537
|
+
export const aaveV2LeverageManagementSubDataWithoutSubProxy = {
|
|
538
|
+
encode(
|
|
539
|
+
market: EthereumAddress,
|
|
540
|
+
targetRatio: number,
|
|
541
|
+
ratioState: RatioState,
|
|
542
|
+
): SubData {
|
|
543
|
+
const encodedMarket = AbiCoder.encodeParameter('address', market);
|
|
544
|
+
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
545
|
+
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
546
|
+
|
|
547
|
+
const isBoost = ratioState === RatioState.OVER;
|
|
548
|
+
|
|
549
|
+
if (isBoost) {
|
|
550
|
+
const enableAsCollEncoded = AbiCoder.encodeParameter('uint256', 1);
|
|
551
|
+
return [encodedMarket, encodedTargetRatio, encodedRatioState, enableAsCollEncoded];
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
return [encodedMarket, encodedTargetRatio, encodedRatioState];
|
|
555
|
+
},
|
|
556
|
+
decode(subData: SubData): { market: EthereumAddress, targetRatio: number, ratioState: RatioState } {
|
|
557
|
+
const market = AbiCoder.decodeParameter('address', subData[0]) as any as EthereumAddress;
|
|
558
|
+
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[1]) as any as string);
|
|
559
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[2]) as any as RatioState;
|
|
560
|
+
|
|
561
|
+
return { market, targetRatio, ratioState };
|
|
562
|
+
},
|
|
563
|
+
};
|
|
513
564
|
|
|
514
565
|
/**
|
|
515
566
|
___ ___ ____ ____ _______ ____ ____ ____
|
|
@@ -997,6 +1048,30 @@ export const compoundV2LeverageManagementSubData = {
|
|
|
997
1048
|
return { targetRatio };
|
|
998
1049
|
},
|
|
999
1050
|
};
|
|
1051
|
+
export const compoundV2LeverageManagementSubDataWithoutSubProxy = {
|
|
1052
|
+
encode(
|
|
1053
|
+
targetRatio: number,
|
|
1054
|
+
ratioState: RatioState,
|
|
1055
|
+
): SubData {
|
|
1056
|
+
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
1057
|
+
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
1058
|
+
|
|
1059
|
+
const isBoost = ratioState === RatioState.OVER;
|
|
1060
|
+
|
|
1061
|
+
if (isBoost) {
|
|
1062
|
+
const enableAsCollEncoded = AbiCoder.encodeParameter('uint256', 1);
|
|
1063
|
+
return [encodedTargetRatio, encodedRatioState, enableAsCollEncoded];
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
return [encodedTargetRatio, encodedRatioState];
|
|
1067
|
+
},
|
|
1068
|
+
decode(subData: SubData): { targetRatio: number, ratioState: RatioState } {
|
|
1069
|
+
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[0]) as any as string);
|
|
1070
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[1]) as any as RatioState;
|
|
1071
|
+
|
|
1072
|
+
return { targetRatio, ratioState };
|
|
1073
|
+
},
|
|
1074
|
+
};
|
|
1000
1075
|
|
|
1001
1076
|
/**
|
|
1002
1077
|
______ ______ .___ ___. .______ ____ ____ ____
|
|
@@ -1035,39 +1110,28 @@ export const compoundV3LeverageManagementSubData = {
|
|
|
1035
1110
|
return { targetRatio };
|
|
1036
1111
|
},
|
|
1037
1112
|
};
|
|
1038
|
-
export const
|
|
1113
|
+
export const compoundV3LeverageManagementSubDataWithoutSubProxy = {
|
|
1039
1114
|
encode(
|
|
1040
1115
|
market: EthereumAddress,
|
|
1041
1116
|
baseToken: EthereumAddress,
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
subInput = subInput.concat(market.slice(2));
|
|
1052
|
-
subInput = subInput.concat(baseToken.slice(2));
|
|
1053
|
-
subInput = subInput.concat(new Dec(triggerRepayRatio).mul(1e16).toHex().slice(2)
|
|
1054
|
-
.padStart(32, '0'));
|
|
1055
|
-
subInput = subInput.concat(new Dec(triggerBoostRatio).mul(1e16).toHex().slice(2)
|
|
1056
|
-
.padStart(32, '0'));
|
|
1057
|
-
subInput = subInput.concat(new Dec(targetBoostRatio).mul(1e16).toHex().slice(2)
|
|
1058
|
-
.padStart(32, '0'));
|
|
1059
|
-
subInput = subInput.concat(new Dec(targetRepayRatio).mul(1e16).toHex().slice(2)
|
|
1060
|
-
.padStart(32, '0'));
|
|
1061
|
-
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
1062
|
-
subInput = subInput.concat(isEOA ? '01' : '00');
|
|
1063
|
-
|
|
1064
|
-
return subInput;
|
|
1117
|
+
targetRatio: number,
|
|
1118
|
+
ratioState: RatioState,
|
|
1119
|
+
): SubData {
|
|
1120
|
+
const encodedMarket = AbiCoder.encodeParameter('address', market);
|
|
1121
|
+
const encodedBaseToken = AbiCoder.encodeParameter('address', baseToken);
|
|
1122
|
+
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
1123
|
+
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
1124
|
+
return [encodedMarket, encodedBaseToken, encodedRatioState, encodedTargetRatio];
|
|
1065
1125
|
},
|
|
1066
|
-
decode(subData: SubData): { targetRatio: number } {
|
|
1067
|
-
const
|
|
1068
|
-
const
|
|
1126
|
+
decode(subData: SubData): { market: EthereumAddress, baseToken: EthereumAddress, targetRatio: number, ratioState: RatioState } {
|
|
1127
|
+
const market = AbiCoder.decodeParameter('address', subData[0]) as any as EthereumAddress;
|
|
1128
|
+
const baseToken = AbiCoder.decodeParameter('address', subData[1]) as any as EthereumAddress;
|
|
1129
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[2]) as any as RatioState;
|
|
1130
|
+
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[3]) as any as string);
|
|
1069
1131
|
|
|
1070
|
-
return {
|
|
1132
|
+
return {
|
|
1133
|
+
market, baseToken, targetRatio, ratioState,
|
|
1134
|
+
};
|
|
1071
1135
|
},
|
|
1072
1136
|
};
|
|
1073
1137
|
export const compoundV3LeverageManagementOnPriceSubData = {
|
|
@@ -1205,6 +1269,21 @@ export const exchangeLimitOrderSubData = {
|
|
|
1205
1269
|
return { fromToken, toToken, amount };
|
|
1206
1270
|
},
|
|
1207
1271
|
};
|
|
1272
|
+
export const exchangeLimitOrderSubDataWithoutSubProxy = {
|
|
1273
|
+
encode(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string): SubData {
|
|
1274
|
+
return [
|
|
1275
|
+
AbiCoder.encodeParameter('address', fromToken),
|
|
1276
|
+
AbiCoder.encodeParameter('address', toToken),
|
|
1277
|
+
AbiCoder.encodeParameter('uint256', amount),
|
|
1278
|
+
];
|
|
1279
|
+
},
|
|
1280
|
+
decode: (subData: SubData, chainId: ChainId) => {
|
|
1281
|
+
const fromToken = AbiCoder.decodeParameter('address', subData[0])!.toString();
|
|
1282
|
+
const toToken = AbiCoder.decodeParameter('address', subData[1])!.toString();
|
|
1283
|
+
const amount = assetAmountInEth(AbiCoder.decodeParameter('uint256', subData[2])!.toString(), getAssetInfoByAddress(fromToken, chainId).symbol);
|
|
1284
|
+
return { fromToken, toToken, amount };
|
|
1285
|
+
},
|
|
1286
|
+
};
|
|
1208
1287
|
|
|
1209
1288
|
/**
|
|
1210
1289
|
_______..______ ___ .______ __ ___
|