@defisaver/automation-sdk 3.3.22-coll-switch-generic-dev → 3.3.22
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/automation/private/StrategiesAutomation.d.ts +5 -1
- package/cjs/automation/private/StrategiesAutomation.js +12 -0
- package/cjs/automation/private/StrategiesAutomation.test.js +51 -0
- package/cjs/constants/index.js +0 -60
- package/cjs/services/apiSubscriptionsService.d.ts +7 -0
- package/cjs/services/apiSubscriptionsService.js +33 -0
- package/cjs/services/apiSubscriptionsService.test.d.ts +1 -0
- package/cjs/services/apiSubscriptionsService.test.js +67 -0
- package/cjs/services/strategiesService.js +1 -21
- package/cjs/services/strategiesService.test.js +0 -93
- package/cjs/services/strategySubService.d.ts +0 -2
- package/cjs/services/strategySubService.js +0 -12
- package/cjs/services/strategySubService.test.js +0 -107
- package/cjs/services/subDataService.d.ts +0 -24
- package/cjs/services/subDataService.js +2 -66
- package/cjs/services/subDataService.test.js +0 -139
- package/cjs/types/enums.d.ts +4 -18
- package/cjs/types/enums.js +0 -14
- package/cjs/types/index.d.ts +24 -2
- package/esm/automation/private/StrategiesAutomation.d.ts +5 -1
- package/esm/automation/private/StrategiesAutomation.js +12 -0
- package/esm/automation/private/StrategiesAutomation.test.js +51 -0
- package/esm/constants/index.js +0 -60
- package/esm/services/apiSubscriptionsService.d.ts +7 -0
- package/esm/services/apiSubscriptionsService.js +29 -0
- package/esm/services/apiSubscriptionsService.test.d.ts +1 -0
- package/esm/services/apiSubscriptionsService.test.js +65 -0
- package/esm/services/strategiesService.js +1 -21
- package/esm/services/strategiesService.test.js +1 -94
- package/esm/services/strategySubService.d.ts +0 -2
- package/esm/services/strategySubService.js +0 -12
- package/esm/services/strategySubService.test.js +0 -107
- package/esm/services/subDataService.d.ts +0 -24
- package/esm/services/subDataService.js +0 -64
- package/esm/services/subDataService.test.js +0 -139
- package/esm/types/enums.d.ts +4 -18
- package/esm/types/enums.js +0 -14
- package/esm/types/index.d.ts +24 -2
- package/package.json +1 -1
- package/src/automation/private/StrategiesAutomation.test.ts +65 -1
- package/src/automation/private/StrategiesAutomation.ts +17 -0
- package/src/constants/index.ts +0 -60
- package/src/services/apiSubscriptionsService.test.ts +73 -0
- package/src/services/apiSubscriptionsService.ts +33 -0
- package/src/services/strategiesService.test.ts +1 -103
- package/src/services/strategiesService.ts +1 -23
- package/src/services/strategySubService.test.ts +0 -131
- package/src/services/strategySubService.ts +0 -46
- package/src/services/subDataService.test.ts +0 -149
- package/src/services/subDataService.ts +0 -101
- package/src/types/enums.ts +0 -14
- package/src/types/index.ts +26 -2
|
@@ -1002,137 +1002,6 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1002
1002
|
});
|
|
1003
1003
|
});
|
|
1004
1004
|
});
|
|
1005
|
-
|
|
1006
|
-
describe('collateralSwitchGeneric()', () => {
|
|
1007
|
-
const strategyId = 12345;
|
|
1008
|
-
const fromAsset = web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address);
|
|
1009
|
-
const toAsset = web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address);
|
|
1010
|
-
const marketAddr = web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39');
|
|
1011
|
-
const user = web3Utils.toChecksumAddress('0x1234567890abcdef1234567890abcdef12345678');
|
|
1012
|
-
const examples: Array<[RatioState, string, string, string]> = [
|
|
1013
|
-
[
|
|
1014
|
-
RatioState.UNDER,
|
|
1015
|
-
'10000000000000000000',
|
|
1016
|
-
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
1017
|
-
'0000000000000000000000000000000000000000000000000000000000000001',
|
|
1018
|
-
],
|
|
1019
|
-
[
|
|
1020
|
-
RatioState.OVER,
|
|
1021
|
-
MAXUINT,
|
|
1022
|
-
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
1023
|
-
'0000000000000000000000000000000000000000000000000000000000000000',
|
|
1024
|
-
],
|
|
1025
|
-
];
|
|
1026
|
-
|
|
1027
|
-
examples.forEach(([state, amountToSwitch, encodedAmount, encodedState]) => {
|
|
1028
|
-
it(`encodes a generic collateral switch with the supplied quote pair and state ${state}`, () => {
|
|
1029
|
-
const expectedTrigger = `0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000003e8${encodedState}`;
|
|
1030
|
-
const expectedSubData: SubData = [
|
|
1031
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1032
|
-
'0x0000000000000000000000000000000000000000000000000000000000000100',
|
|
1033
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1034
|
-
'0x000000000000000000000000000000000000000000000000000000000000ffff',
|
|
1035
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1036
|
-
encodedAmount,
|
|
1037
|
-
'0x0000000000000000000000001234567890abcdef1234567890abcdef12345678',
|
|
1038
|
-
];
|
|
1039
|
-
|
|
1040
|
-
expect(aaveV3Encode.collateralSwitchGeneric(
|
|
1041
|
-
strategyId, fromAsset, 256, toAsset, 65535, marketAddr, amountToSwitch, user,
|
|
1042
|
-
toAsset, fromAsset, 0.00001, state,
|
|
1043
|
-
)).to.eql([strategyId, false, [expectedTrigger], expectedSubData]);
|
|
1044
|
-
});
|
|
1045
|
-
});
|
|
1046
|
-
});
|
|
1047
|
-
|
|
1048
|
-
describe('debtSwitch()', () => {
|
|
1049
|
-
const examples: Array<[
|
|
1050
|
-
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1051
|
-
[
|
|
1052
|
-
strategyOrBundleId: number,
|
|
1053
|
-
fromAsset: EthereumAddress,
|
|
1054
|
-
fromAssetId: number,
|
|
1055
|
-
toAsset: EthereumAddress,
|
|
1056
|
-
toAssetId: number,
|
|
1057
|
-
marketAddr: EthereumAddress,
|
|
1058
|
-
amountToSwitch: string,
|
|
1059
|
-
user: EthereumAddress,
|
|
1060
|
-
baseTokenAddress: EthereumAddress,
|
|
1061
|
-
quoteTokenAddress: EthereumAddress,
|
|
1062
|
-
price: number,
|
|
1063
|
-
state: RatioState,
|
|
1064
|
-
]
|
|
1065
|
-
]> = [
|
|
1066
|
-
// USDC -> DAI, price 100000, state UNDER
|
|
1067
|
-
[
|
|
1068
|
-
[
|
|
1069
|
-
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
1070
|
-
false,
|
|
1071
|
-
['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000009184e72a0000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1072
|
-
[
|
|
1073
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1074
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1075
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1076
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
1077
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1078
|
-
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
1079
|
-
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
1080
|
-
],
|
|
1081
|
-
],
|
|
1082
|
-
[
|
|
1083
|
-
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
1084
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1085
|
-
1,
|
|
1086
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1087
|
-
3,
|
|
1088
|
-
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1089
|
-
'10000000000000000000', // 10 tokens
|
|
1090
|
-
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
1091
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1092
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1093
|
-
100000,
|
|
1094
|
-
RatioState.UNDER,
|
|
1095
|
-
]
|
|
1096
|
-
],
|
|
1097
|
-
// DAI -> USDC (MaxUint256), price 1, state OVER
|
|
1098
|
-
[
|
|
1099
|
-
[
|
|
1100
|
-
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
1101
|
-
false,
|
|
1102
|
-
['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1103
|
-
[
|
|
1104
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1105
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
1106
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1107
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1108
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1109
|
-
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
1110
|
-
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
1111
|
-
],
|
|
1112
|
-
],
|
|
1113
|
-
[
|
|
1114
|
-
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
1115
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1116
|
-
3,
|
|
1117
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1118
|
-
1,
|
|
1119
|
-
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1120
|
-
MAXUINT, // MaxUint256
|
|
1121
|
-
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
1122
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1123
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1124
|
-
1,
|
|
1125
|
-
RatioState.OVER,
|
|
1126
|
-
]
|
|
1127
|
-
],
|
|
1128
|
-
];
|
|
1129
|
-
|
|
1130
|
-
examples.forEach(([expected, actual]) => {
|
|
1131
|
-
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1132
|
-
expect(aaveV3Encode.debtSwitch(...actual)).to.eql(expected);
|
|
1133
|
-
});
|
|
1134
|
-
});
|
|
1135
|
-
});
|
|
1136
1005
|
});
|
|
1137
1006
|
|
|
1138
1007
|
describe('When testing strategySubService.compoundV3Encode', () => {
|
|
@@ -444,52 +444,6 @@ export const aaveV3Encode = {
|
|
|
444
444
|
|
|
445
445
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
446
446
|
},
|
|
447
|
-
|
|
448
|
-
collateralSwitchGeneric(
|
|
449
|
-
strategyOrBundleId: number,
|
|
450
|
-
fromAsset: EthereumAddress,
|
|
451
|
-
fromAssetId: number,
|
|
452
|
-
toAsset: EthereumAddress,
|
|
453
|
-
toAssetId: number,
|
|
454
|
-
marketAddr: EthereumAddress,
|
|
455
|
-
amountToSwitch: string,
|
|
456
|
-
user: EthereumAddress,
|
|
457
|
-
baseTokenAddress: EthereumAddress,
|
|
458
|
-
quoteTokenAddress: EthereumAddress,
|
|
459
|
-
price: number,
|
|
460
|
-
state: RatioState,
|
|
461
|
-
) {
|
|
462
|
-
const isBundle = false;
|
|
463
|
-
|
|
464
|
-
const subDataEncoded = subDataService.aaveV3GenericFLCollateralSwitchSubData.encode(
|
|
465
|
-
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user,
|
|
466
|
-
);
|
|
467
|
-
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
468
|
-
|
|
469
|
-
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
470
|
-
},
|
|
471
|
-
|
|
472
|
-
debtSwitch(
|
|
473
|
-
strategyOrBundleId: number,
|
|
474
|
-
fromAsset: EthereumAddress,
|
|
475
|
-
fromAssetId: number,
|
|
476
|
-
toAsset: EthereumAddress,
|
|
477
|
-
toAssetId: number,
|
|
478
|
-
marketAddr: EthereumAddress,
|
|
479
|
-
amountToSwitch: string,
|
|
480
|
-
user: EthereumAddress,
|
|
481
|
-
baseTokenAddress: EthereumAddress,
|
|
482
|
-
quoteTokenAddress: EthereumAddress,
|
|
483
|
-
price: number,
|
|
484
|
-
state: RatioState,
|
|
485
|
-
) {
|
|
486
|
-
const isBundle = false;
|
|
487
|
-
|
|
488
|
-
const subDataEncoded = subDataService.aaveV3DebtSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user);
|
|
489
|
-
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
490
|
-
|
|
491
|
-
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
492
|
-
},
|
|
493
447
|
};
|
|
494
448
|
|
|
495
449
|
export const compoundV2Encode = {
|
|
@@ -549,155 +549,6 @@ describe('Feature: subDataService.ts', () => {
|
|
|
549
549
|
});
|
|
550
550
|
});
|
|
551
551
|
|
|
552
|
-
describe('When testing subDataService.aaveV3DebtSwitchSubData', () => {
|
|
553
|
-
describe('encode()', () => {
|
|
554
|
-
const examples: Array<[SubData, [fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress]]> = [
|
|
555
|
-
// USDC -> DAI
|
|
556
|
-
[
|
|
557
|
-
[
|
|
558
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
559
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
560
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
561
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
562
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
563
|
-
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
564
|
-
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
565
|
-
],
|
|
566
|
-
[
|
|
567
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
568
|
-
1,
|
|
569
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
570
|
-
3,
|
|
571
|
-
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
572
|
-
'10000000000000000000', // 10 tokens
|
|
573
|
-
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
574
|
-
]
|
|
575
|
-
],
|
|
576
|
-
// DAI -> USDC (MaxUint256)
|
|
577
|
-
[
|
|
578
|
-
[
|
|
579
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
580
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
581
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
582
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
583
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
584
|
-
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
585
|
-
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
586
|
-
],
|
|
587
|
-
[
|
|
588
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
589
|
-
3,
|
|
590
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
591
|
-
1,
|
|
592
|
-
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
593
|
-
MAXUINT, // MaxUint256
|
|
594
|
-
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
595
|
-
]
|
|
596
|
-
],
|
|
597
|
-
];
|
|
598
|
-
|
|
599
|
-
examples.forEach(([expected, actual]) => {
|
|
600
|
-
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
601
|
-
expect(subDataService.aaveV3DebtSwitchSubData.encode(...actual)).to.eql(expected);
|
|
602
|
-
});
|
|
603
|
-
});
|
|
604
|
-
});
|
|
605
|
-
|
|
606
|
-
describe('decode()', () => {
|
|
607
|
-
const examples: Array<[{ fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress }, SubData]> = [
|
|
608
|
-
// USDC -> DAI
|
|
609
|
-
[
|
|
610
|
-
{
|
|
611
|
-
fromAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
612
|
-
fromAssetId: 1,
|
|
613
|
-
toAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
614
|
-
toAssetId: 3,
|
|
615
|
-
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
616
|
-
amountToSwitch: '10000000000000000000',
|
|
617
|
-
user: web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
618
|
-
},
|
|
619
|
-
[
|
|
620
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
621
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
622
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
623
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
624
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
625
|
-
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
626
|
-
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
627
|
-
],
|
|
628
|
-
],
|
|
629
|
-
// DAI -> USDC (MaxUint256)
|
|
630
|
-
[
|
|
631
|
-
{
|
|
632
|
-
fromAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
633
|
-
fromAssetId: 3,
|
|
634
|
-
toAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
635
|
-
toAssetId: 1,
|
|
636
|
-
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
637
|
-
amountToSwitch: MAXUINT,
|
|
638
|
-
user: web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
639
|
-
},
|
|
640
|
-
[
|
|
641
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
642
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
643
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
644
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
645
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
646
|
-
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
647
|
-
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
648
|
-
],
|
|
649
|
-
],
|
|
650
|
-
];
|
|
651
|
-
|
|
652
|
-
examples.forEach(([expected, actual]) => {
|
|
653
|
-
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
654
|
-
expect(subDataService.aaveV3DebtSwitchSubData.decode(actual)).to.eql(expected);
|
|
655
|
-
});
|
|
656
|
-
});
|
|
657
|
-
});
|
|
658
|
-
});
|
|
659
|
-
|
|
660
|
-
describe('When testing subDataService.aaveV3GenericFLCollateralSwitchSubData', () => {
|
|
661
|
-
const fromAsset = web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address);
|
|
662
|
-
const toAsset = web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address);
|
|
663
|
-
const marketAddr = web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39');
|
|
664
|
-
const user = web3Utils.toChecksumAddress('0x1234567890abcdef1234567890abcdef12345678');
|
|
665
|
-
const examples = [
|
|
666
|
-
['10000000000000000000', '0x0000000000000000000000000000000000000000000000008ac7230489e80000'],
|
|
667
|
-
[MAXUINT, '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'],
|
|
668
|
-
];
|
|
669
|
-
|
|
670
|
-
examples.forEach(([amountToSwitch, encodedAmount]) => {
|
|
671
|
-
const subData: SubData = [
|
|
672
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
673
|
-
'0x0000000000000000000000000000000000000000000000000000000000000100',
|
|
674
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
675
|
-
'0x000000000000000000000000000000000000000000000000000000000000ffff',
|
|
676
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
677
|
-
encodedAmount,
|
|
678
|
-
'0x0000000000000000000000001234567890abcdef1234567890abcdef12345678',
|
|
679
|
-
];
|
|
680
|
-
|
|
681
|
-
it(`encode() preserves uint16 asset IDs and user when switching ${amountToSwitch}`, () => {
|
|
682
|
-
expect(subDataService.aaveV3GenericFLCollateralSwitchSubData.encode(
|
|
683
|
-
fromAsset, 256, toAsset, 65535, marketAddr, amountToSwitch, user,
|
|
684
|
-
)).to.eql(subData);
|
|
685
|
-
});
|
|
686
|
-
|
|
687
|
-
it(`decode() preserves uint16 asset IDs and user when switching ${amountToSwitch}`, () => {
|
|
688
|
-
expect(subDataService.aaveV3GenericFLCollateralSwitchSubData.decode(subData)).to.eql({
|
|
689
|
-
fromAsset,
|
|
690
|
-
fromAssetId: 256,
|
|
691
|
-
toAsset,
|
|
692
|
-
toAssetId: 65535,
|
|
693
|
-
marketAddr,
|
|
694
|
-
amountToSwitch,
|
|
695
|
-
user,
|
|
696
|
-
});
|
|
697
|
-
});
|
|
698
|
-
});
|
|
699
|
-
});
|
|
700
|
-
|
|
701
552
|
describe('When testing subDataService.sparkCollateralSwitchSubData', () => {
|
|
702
553
|
describe('encode()', () => {
|
|
703
554
|
const examples: Array<[SubData, [fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, useOnBehalf?: boolean]]> = [
|
|
@@ -735,107 +735,6 @@ export const aaveV3CollateralSwitchSubData = {
|
|
|
735
735
|
};
|
|
736
736
|
},
|
|
737
737
|
};
|
|
738
|
-
export const aaveV3GenericFLCollateralSwitchSubData = {
|
|
739
|
-
encode(
|
|
740
|
-
fromAsset: EthereumAddress,
|
|
741
|
-
fromAssetId: number,
|
|
742
|
-
toAsset: EthereumAddress,
|
|
743
|
-
toAssetId: number,
|
|
744
|
-
marketAddr: EthereumAddress,
|
|
745
|
-
amountToSwitch: string,
|
|
746
|
-
user: EthereumAddress,
|
|
747
|
-
): SubData {
|
|
748
|
-
const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
|
|
749
|
-
const encodedFromAssetId = AbiCoder.encodeParameter('uint16', fromAssetId);
|
|
750
|
-
const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
|
|
751
|
-
const encodedToAssetId = AbiCoder.encodeParameter('uint16', toAssetId);
|
|
752
|
-
const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
|
|
753
|
-
const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
|
|
754
|
-
const encodedUser = AbiCoder.encodeParameter('address', user);
|
|
755
|
-
|
|
756
|
-
return [
|
|
757
|
-
encodedFromAsset,
|
|
758
|
-
encodedFromAssetId,
|
|
759
|
-
encodedToAsset,
|
|
760
|
-
encodedToAssetId,
|
|
761
|
-
encodedMarketAddr,
|
|
762
|
-
encodedAmountToSwitch,
|
|
763
|
-
encodedUser,
|
|
764
|
-
];
|
|
765
|
-
},
|
|
766
|
-
decode(subData: SubData): {
|
|
767
|
-
fromAsset: EthereumAddress,
|
|
768
|
-
fromAssetId: number,
|
|
769
|
-
toAsset: EthereumAddress,
|
|
770
|
-
toAssetId: number,
|
|
771
|
-
marketAddr: EthereumAddress,
|
|
772
|
-
amountToSwitch: string,
|
|
773
|
-
user: EthereumAddress,
|
|
774
|
-
} {
|
|
775
|
-
const fromAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
776
|
-
const fromAssetId = Number(AbiCoder.decodeParameter('uint16', subData[1]));
|
|
777
|
-
const toAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
|
|
778
|
-
const toAssetId = Number(AbiCoder.decodeParameter('uint16', subData[3]));
|
|
779
|
-
const marketAddr = AbiCoder.decodeParameter('address', subData[4]) as unknown as EthereumAddress;
|
|
780
|
-
const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]) as unknown as string;
|
|
781
|
-
const user = AbiCoder.decodeParameter('address', subData[6]) as unknown as EthereumAddress;
|
|
782
|
-
|
|
783
|
-
return {
|
|
784
|
-
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user,
|
|
785
|
-
};
|
|
786
|
-
},
|
|
787
|
-
};
|
|
788
|
-
|
|
789
|
-
export const aaveV3DebtSwitchSubData = {
|
|
790
|
-
encode(
|
|
791
|
-
fromAsset: EthereumAddress,
|
|
792
|
-
fromAssetId: number,
|
|
793
|
-
toAsset: EthereumAddress,
|
|
794
|
-
toAssetId: number,
|
|
795
|
-
marketAddr: EthereumAddress,
|
|
796
|
-
amountToSwitch: string,
|
|
797
|
-
user: EthereumAddress,
|
|
798
|
-
): SubData {
|
|
799
|
-
const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
|
|
800
|
-
const encodedFromAssetId = AbiCoder.encodeParameter('uint8', fromAssetId);
|
|
801
|
-
const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
|
|
802
|
-
const encodedToAssetId = AbiCoder.encodeParameter('uint8', toAssetId);
|
|
803
|
-
const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
|
|
804
|
-
const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
|
|
805
|
-
const encodedUser = AbiCoder.encodeParameter('address', user);
|
|
806
|
-
|
|
807
|
-
return [
|
|
808
|
-
encodedFromAsset,
|
|
809
|
-
encodedFromAssetId,
|
|
810
|
-
encodedToAsset,
|
|
811
|
-
encodedToAssetId,
|
|
812
|
-
encodedMarketAddr,
|
|
813
|
-
encodedAmountToSwitch,
|
|
814
|
-
encodedUser,
|
|
815
|
-
];
|
|
816
|
-
},
|
|
817
|
-
decode(subData: SubData): {
|
|
818
|
-
fromAsset: EthereumAddress,
|
|
819
|
-
fromAssetId: number,
|
|
820
|
-
toAsset: EthereumAddress,
|
|
821
|
-
toAssetId: number,
|
|
822
|
-
marketAddr: EthereumAddress,
|
|
823
|
-
amountToSwitch: string,
|
|
824
|
-
user: EthereumAddress,
|
|
825
|
-
} {
|
|
826
|
-
const fromAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
827
|
-
const fromAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
|
|
828
|
-
const toAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
|
|
829
|
-
const toAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
|
|
830
|
-
const marketAddr = AbiCoder.decodeParameter('address', subData[4]) as unknown as EthereumAddress;
|
|
831
|
-
const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]) as unknown as string;
|
|
832
|
-
const user = AbiCoder.decodeParameter('address', subData[6]) as unknown as EthereumAddress;
|
|
833
|
-
|
|
834
|
-
return {
|
|
835
|
-
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user,
|
|
836
|
-
};
|
|
837
|
-
},
|
|
838
|
-
};
|
|
839
738
|
export const aaveV3QuotePriceSubData = {
|
|
840
739
|
encode(
|
|
841
740
|
collAsset: EthereumAddress,
|
package/src/types/enums.ts
CHANGED
|
@@ -102,36 +102,24 @@ export namespace Strategies {
|
|
|
102
102
|
AAVE_V4_COLLATERAL_SWITCH_EOA = 155,
|
|
103
103
|
SPARK_COLLATERAL_SWITCH = 156,
|
|
104
104
|
SPARK_GENERIC_FL_COLLATERAL_SWITCH = 167,
|
|
105
|
-
AAVE_V3_DEBT_SWITCH = 168,
|
|
106
|
-
AAVE_V3_DEBT_SWITCH_EOA = 169,
|
|
107
|
-
AAVE_V3_COLLATERAL_SWITCH_EOA = 170,
|
|
108
105
|
}
|
|
109
106
|
|
|
110
107
|
export enum OptimismIds {
|
|
111
108
|
EXCHANGE_DCA = 8,
|
|
112
109
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
113
110
|
AAVE_V3_COLLATERAL_SWITCH = 24,
|
|
114
|
-
AAVE_V3_DEBT_SWITCH = 25,
|
|
115
|
-
AAVE_V3_DEBT_SWITCH_EOA = 26,
|
|
116
|
-
AAVE_V3_COLLATERAL_SWITCH_EOA = 27,
|
|
117
111
|
}
|
|
118
112
|
|
|
119
113
|
export enum BaseIds {
|
|
120
114
|
EXCHANGE_DCA = 8,
|
|
121
115
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
122
116
|
AAVE_V3_COLLATERAL_SWITCH = 56,
|
|
123
|
-
AAVE_V3_DEBT_SWITCH = 61,
|
|
124
|
-
AAVE_V3_DEBT_SWITCH_EOA = 62,
|
|
125
|
-
AAVE_V3_COLLATERAL_SWITCH_EOA = 63,
|
|
126
117
|
}
|
|
127
118
|
|
|
128
119
|
export enum ArbitrumIds {
|
|
129
120
|
EXCHANGE_DCA = 8,
|
|
130
121
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
131
122
|
AAVE_V3_COLLATERAL_SWITCH = 50,
|
|
132
|
-
AAVE_V3_DEBT_SWITCH = 55,
|
|
133
|
-
AAVE_V3_DEBT_SWITCH_EOA = 56,
|
|
134
|
-
AAVE_V3_COLLATERAL_SWITCH_EOA = 57,
|
|
135
123
|
}
|
|
136
124
|
|
|
137
125
|
export enum Identifiers {
|
|
@@ -166,8 +154,6 @@ export namespace Strategies {
|
|
|
166
154
|
EoaRepayOnPrice = 'eoa-repay-on-price',
|
|
167
155
|
CollateralSwitch = 'collateral-switch',
|
|
168
156
|
EoaCollateralSwitch = 'eoa-collateral-switch',
|
|
169
|
-
DebtSwitch = 'debt-switch',
|
|
170
|
-
EoaDebtSwitch = 'eoa-debt-switch',
|
|
171
157
|
LiquidationProtection = 'liquidation-protection',
|
|
172
158
|
EoaLiquidationProtection = 'liquidation-protection-eoa',
|
|
173
159
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type Web3 from 'web3';
|
|
2
2
|
import type { AbiItem } from 'web3-utils';
|
|
3
3
|
import type { BaseContract, BlockType } from './contracts/generated/types';
|
|
4
|
-
import type {
|
|
4
|
+
import type { StrategyModel } from './contracts/generated/SubStorage';
|
|
5
5
|
import type {
|
|
6
6
|
ChainId, Strategies, Bundles, ProtocolIdentifiers,
|
|
7
7
|
RatioState,
|
|
@@ -72,6 +72,22 @@ interface _SubscriptionOptions {
|
|
|
72
72
|
|
|
73
73
|
export type SubscriptionOptions = Partial<_SubscriptionOptions>;
|
|
74
74
|
|
|
75
|
+
/** Subscription record as returned by the automation API (GET /v1/subscriptions) */
|
|
76
|
+
export interface ApiSubscriptionRecord {
|
|
77
|
+
id: number,
|
|
78
|
+
wallet: EthereumAddress,
|
|
79
|
+
wallet_type: string,
|
|
80
|
+
is_enabled: boolean,
|
|
81
|
+
is_bundle: boolean,
|
|
82
|
+
strategy_or_bundle_id: number,
|
|
83
|
+
strategy_ids: number[],
|
|
84
|
+
sub_data_hash: string,
|
|
85
|
+
trigger_data: string[],
|
|
86
|
+
sub_data: string[],
|
|
87
|
+
block_number: number,
|
|
88
|
+
additional_triggers: string[] | null,
|
|
89
|
+
}
|
|
90
|
+
|
|
75
91
|
export declare namespace Interfaces {
|
|
76
92
|
interface ProtocolBase {
|
|
77
93
|
id: ProtocolIdentifiers.StrategiesAutomation | ProtocolIdentifiers.LegacyAutomation,
|
|
@@ -369,10 +385,18 @@ export type StrategyOrBundleIds =
|
|
|
369
385
|
| typeof Bundles.ArbitrumIds[keyof typeof Bundles.ArbitrumIds]
|
|
370
386
|
| typeof Bundles.BaseIds[keyof typeof Bundles.BaseIds];
|
|
371
387
|
|
|
388
|
+
/** Fields of the Subscribe event that parsing relies on */
|
|
389
|
+
export interface SubscriptionEventData {
|
|
390
|
+
subId: string,
|
|
391
|
+
proxy: EthereumAddress,
|
|
392
|
+
subHash: string,
|
|
393
|
+
subStruct: StrategyModel.StrategySubStructOutputStruct,
|
|
394
|
+
}
|
|
395
|
+
|
|
372
396
|
export interface ParseData {
|
|
373
397
|
chainId: ChainId,
|
|
374
398
|
blockNumber: BlockNumber,
|
|
375
|
-
subscriptionEventData:
|
|
399
|
+
subscriptionEventData: SubscriptionEventData,
|
|
376
400
|
strategiesSubsData: StrategyModel.StoredSubDataStructOutputStruct,
|
|
377
401
|
}
|
|
378
402
|
|