@defisaver/automation-sdk 3.3.21-debt-switch-dev-dev → 3.3.21
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 -40
- 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 +0 -13
- package/cjs/services/strategiesService.test.js +0 -1
- package/cjs/services/strategySubService.d.ts +0 -1
- package/cjs/services/strategySubService.js +0 -6
- package/cjs/services/strategySubService.test.js +0 -71
- package/cjs/services/subDataService.d.ts +0 -12
- package/cjs/services/subDataService.js +2 -34
- package/cjs/services/subDataService.test.js +0 -104
- package/cjs/types/enums.d.ts +4 -14
- package/cjs/types/enums.js +0 -10
- 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 -40
- 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 +0 -13
- package/esm/services/strategiesService.test.js +0 -1
- package/esm/services/strategySubService.d.ts +0 -1
- package/esm/services/strategySubService.js +0 -6
- package/esm/services/strategySubService.test.js +0 -71
- package/esm/services/subDataService.d.ts +0 -12
- package/esm/services/subDataService.js +0 -32
- package/esm/services/subDataService.test.js +0 -104
- package/esm/types/enums.d.ts +4 -14
- package/esm/types/enums.js +0 -10
- 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 -40
- package/src/services/apiSubscriptionsService.test.ts +73 -0
- package/src/services/apiSubscriptionsService.ts +33 -0
- package/src/services/strategiesService.test.ts +0 -1
- package/src/services/strategiesService.ts +0 -15
- package/src/services/strategySubService.test.ts +0 -89
- package/src/services/strategySubService.ts +0 -22
- package/src/services/subDataService.test.ts +0 -108
- package/src/services/subDataService.ts +0 -50
- package/src/types/enums.ts +0 -10
- package/src/types/index.ts +26 -2
package/cjs/types/enums.d.ts
CHANGED
|
@@ -91,30 +91,22 @@ export declare namespace Strategies {
|
|
|
91
91
|
AAVE_V4_COLLATERAL_SWITCH = 154,
|
|
92
92
|
AAVE_V4_COLLATERAL_SWITCH_EOA = 155,
|
|
93
93
|
SPARK_COLLATERAL_SWITCH = 156,
|
|
94
|
-
SPARK_GENERIC_FL_COLLATERAL_SWITCH = 167
|
|
95
|
-
AAVE_V3_DEBT_SWITCH = 168,
|
|
96
|
-
AAVE_V3_DEBT_SWITCH_EOA = 169
|
|
94
|
+
SPARK_GENERIC_FL_COLLATERAL_SWITCH = 167
|
|
97
95
|
}
|
|
98
96
|
enum OptimismIds {
|
|
99
97
|
EXCHANGE_DCA = 8,
|
|
100
98
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
101
|
-
AAVE_V3_COLLATERAL_SWITCH = 24
|
|
102
|
-
AAVE_V3_DEBT_SWITCH = 25,
|
|
103
|
-
AAVE_V3_DEBT_SWITCH_EOA = 26
|
|
99
|
+
AAVE_V3_COLLATERAL_SWITCH = 24
|
|
104
100
|
}
|
|
105
101
|
enum BaseIds {
|
|
106
102
|
EXCHANGE_DCA = 8,
|
|
107
103
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
108
|
-
AAVE_V3_COLLATERAL_SWITCH = 56
|
|
109
|
-
AAVE_V3_DEBT_SWITCH = 61,
|
|
110
|
-
AAVE_V3_DEBT_SWITCH_EOA = 62
|
|
104
|
+
AAVE_V3_COLLATERAL_SWITCH = 56
|
|
111
105
|
}
|
|
112
106
|
enum ArbitrumIds {
|
|
113
107
|
EXCHANGE_DCA = 8,
|
|
114
108
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
115
|
-
AAVE_V3_COLLATERAL_SWITCH = 50
|
|
116
|
-
AAVE_V3_DEBT_SWITCH = 55,
|
|
117
|
-
AAVE_V3_DEBT_SWITCH_EOA = 56
|
|
109
|
+
AAVE_V3_COLLATERAL_SWITCH = 50
|
|
118
110
|
}
|
|
119
111
|
enum Identifiers {
|
|
120
112
|
SavingsLiqProtection = "smart-savings-liquidation-protection",
|
|
@@ -148,8 +140,6 @@ export declare namespace Strategies {
|
|
|
148
140
|
EoaRepayOnPrice = "eoa-repay-on-price",
|
|
149
141
|
CollateralSwitch = "collateral-switch",
|
|
150
142
|
EoaCollateralSwitch = "eoa-collateral-switch",
|
|
151
|
-
DebtSwitch = "debt-switch",
|
|
152
|
-
EoaDebtSwitch = "eoa-debt-switch",
|
|
153
143
|
LiquidationProtection = "liquidation-protection",
|
|
154
144
|
EoaLiquidationProtection = "liquidation-protection-eoa"
|
|
155
145
|
}
|
package/cjs/types/enums.js
CHANGED
|
@@ -108,32 +108,24 @@ var Strategies;
|
|
|
108
108
|
MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH_EOA"] = 155] = "AAVE_V4_COLLATERAL_SWITCH_EOA";
|
|
109
109
|
MainnetIds[MainnetIds["SPARK_COLLATERAL_SWITCH"] = 156] = "SPARK_COLLATERAL_SWITCH";
|
|
110
110
|
MainnetIds[MainnetIds["SPARK_GENERIC_FL_COLLATERAL_SWITCH"] = 167] = "SPARK_GENERIC_FL_COLLATERAL_SWITCH";
|
|
111
|
-
MainnetIds[MainnetIds["AAVE_V3_DEBT_SWITCH"] = 168] = "AAVE_V3_DEBT_SWITCH";
|
|
112
|
-
MainnetIds[MainnetIds["AAVE_V3_DEBT_SWITCH_EOA"] = 169] = "AAVE_V3_DEBT_SWITCH_EOA";
|
|
113
111
|
})(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
|
|
114
112
|
let OptimismIds;
|
|
115
113
|
(function (OptimismIds) {
|
|
116
114
|
OptimismIds[OptimismIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
117
115
|
OptimismIds[OptimismIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
118
116
|
OptimismIds[OptimismIds["AAVE_V3_COLLATERAL_SWITCH"] = 24] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
119
|
-
OptimismIds[OptimismIds["AAVE_V3_DEBT_SWITCH"] = 25] = "AAVE_V3_DEBT_SWITCH";
|
|
120
|
-
OptimismIds[OptimismIds["AAVE_V3_DEBT_SWITCH_EOA"] = 26] = "AAVE_V3_DEBT_SWITCH_EOA";
|
|
121
117
|
})(OptimismIds = Strategies.OptimismIds || (Strategies.OptimismIds = {}));
|
|
122
118
|
let BaseIds;
|
|
123
119
|
(function (BaseIds) {
|
|
124
120
|
BaseIds[BaseIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
125
121
|
BaseIds[BaseIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
126
122
|
BaseIds[BaseIds["AAVE_V3_COLLATERAL_SWITCH"] = 56] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
127
|
-
BaseIds[BaseIds["AAVE_V3_DEBT_SWITCH"] = 61] = "AAVE_V3_DEBT_SWITCH";
|
|
128
|
-
BaseIds[BaseIds["AAVE_V3_DEBT_SWITCH_EOA"] = 62] = "AAVE_V3_DEBT_SWITCH_EOA";
|
|
129
123
|
})(BaseIds = Strategies.BaseIds || (Strategies.BaseIds = {}));
|
|
130
124
|
let ArbitrumIds;
|
|
131
125
|
(function (ArbitrumIds) {
|
|
132
126
|
ArbitrumIds[ArbitrumIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
133
127
|
ArbitrumIds[ArbitrumIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
134
128
|
ArbitrumIds[ArbitrumIds["AAVE_V3_COLLATERAL_SWITCH"] = 50] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
135
|
-
ArbitrumIds[ArbitrumIds["AAVE_V3_DEBT_SWITCH"] = 55] = "AAVE_V3_DEBT_SWITCH";
|
|
136
|
-
ArbitrumIds[ArbitrumIds["AAVE_V3_DEBT_SWITCH_EOA"] = 56] = "AAVE_V3_DEBT_SWITCH_EOA";
|
|
137
129
|
})(ArbitrumIds = Strategies.ArbitrumIds || (Strategies.ArbitrumIds = {}));
|
|
138
130
|
let Identifiers;
|
|
139
131
|
(function (Identifiers) {
|
|
@@ -168,8 +160,6 @@ var Strategies;
|
|
|
168
160
|
Identifiers["EoaRepayOnPrice"] = "eoa-repay-on-price";
|
|
169
161
|
Identifiers["CollateralSwitch"] = "collateral-switch";
|
|
170
162
|
Identifiers["EoaCollateralSwitch"] = "eoa-collateral-switch";
|
|
171
|
-
Identifiers["DebtSwitch"] = "debt-switch";
|
|
172
|
-
Identifiers["EoaDebtSwitch"] = "eoa-debt-switch";
|
|
173
163
|
Identifiers["LiquidationProtection"] = "liquidation-protection";
|
|
174
164
|
Identifiers["EoaLiquidationProtection"] = "liquidation-protection-eoa";
|
|
175
165
|
})(Identifiers = Strategies.Identifiers || (Strategies.Identifiers = {}));
|
package/cjs/types/index.d.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 { ChainId, Strategies, Bundles, ProtocolIdentifiers, RatioState, CloseToAssetType } from './enums';
|
|
6
6
|
export type PlaceholderType = any;
|
|
7
7
|
export type EthereumAddress = string;
|
|
@@ -53,6 +53,21 @@ interface _SubscriptionOptions {
|
|
|
53
53
|
unexpiredOnly: boolean;
|
|
54
54
|
}
|
|
55
55
|
export type SubscriptionOptions = Partial<_SubscriptionOptions>;
|
|
56
|
+
/** Subscription record as returned by the automation API (GET /v1/subscriptions) */
|
|
57
|
+
export interface ApiSubscriptionRecord {
|
|
58
|
+
id: number;
|
|
59
|
+
wallet: EthereumAddress;
|
|
60
|
+
wallet_type: string;
|
|
61
|
+
is_enabled: boolean;
|
|
62
|
+
is_bundle: boolean;
|
|
63
|
+
strategy_or_bundle_id: number;
|
|
64
|
+
strategy_ids: number[];
|
|
65
|
+
sub_data_hash: string;
|
|
66
|
+
trigger_data: string[];
|
|
67
|
+
sub_data: string[];
|
|
68
|
+
block_number: number;
|
|
69
|
+
additional_triggers: string[] | null;
|
|
70
|
+
}
|
|
56
71
|
export declare namespace Interfaces {
|
|
57
72
|
interface ProtocolBase {
|
|
58
73
|
id: ProtocolIdentifiers.StrategiesAutomation | ProtocolIdentifiers.LegacyAutomation;
|
|
@@ -291,10 +306,17 @@ export interface BundlesInfo {
|
|
|
291
306
|
[ChainId.Base]: BaseBundleInfo;
|
|
292
307
|
}
|
|
293
308
|
export type StrategyOrBundleIds = typeof Strategies.MainnetIds[keyof typeof Strategies.MainnetIds] | typeof Strategies.OptimismIds[keyof typeof Strategies.OptimismIds] | typeof Strategies.ArbitrumIds[keyof typeof Strategies.ArbitrumIds] | typeof Strategies.BaseIds[keyof typeof Strategies.BaseIds] | typeof Bundles.MainnetIds[keyof typeof Bundles.MainnetIds] | typeof Bundles.OptimismIds[keyof typeof Bundles.OptimismIds] | typeof Bundles.ArbitrumIds[keyof typeof Bundles.ArbitrumIds] | typeof Bundles.BaseIds[keyof typeof Bundles.BaseIds];
|
|
309
|
+
/** Fields of the Subscribe event that parsing relies on */
|
|
310
|
+
export interface SubscriptionEventData {
|
|
311
|
+
subId: string;
|
|
312
|
+
proxy: EthereumAddress;
|
|
313
|
+
subHash: string;
|
|
314
|
+
subStruct: StrategyModel.StrategySubStructOutputStruct;
|
|
315
|
+
}
|
|
294
316
|
export interface ParseData {
|
|
295
317
|
chainId: ChainId;
|
|
296
318
|
blockNumber: BlockNumber;
|
|
297
|
-
subscriptionEventData:
|
|
319
|
+
subscriptionEventData: SubscriptionEventData;
|
|
298
320
|
strategiesSubsData: StrategyModel.StoredSubDataStructOutputStruct;
|
|
299
321
|
}
|
|
300
322
|
type MapToProtocolVersion<T> = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type Web3 from 'web3';
|
|
2
2
|
import type { PastEventOptions } from 'web3-eth-contract';
|
|
3
|
-
import type { Position, Interfaces, EthereumAddress, SubscriptionOptions, Contract, ParseData, BlockNumber } from '../../types';
|
|
3
|
+
import type { Position, Interfaces, EthereumAddress, SubscriptionOptions, Contract, ParseData, BlockNumber, ApiSubscriptionRecord } from '../../types';
|
|
4
4
|
import type { StrategyModel, Subscribe, SubStorage, UpdateData } from '../../types/contracts/generated/SubStorage';
|
|
5
5
|
import type { ChainId } from '../../types/enums';
|
|
6
6
|
import Automation from './Automation';
|
|
@@ -30,6 +30,10 @@ export default class StrategiesAutomation extends Automation {
|
|
|
30
30
|
protected mergeSubs(_subscriptions: (Position.Automated | null)[]): Position.Automated[];
|
|
31
31
|
protected _getSubscriptions(addresses?: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
|
|
32
32
|
getSubscriptions(options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
|
|
33
|
+
/**
|
|
34
|
+
* @description Parses subscriptions returned by the automation API (GET /v1/subscriptions)
|
|
35
|
+
*/
|
|
36
|
+
parseSubscriptionsFromApi(records: ApiSubscriptionRecord[], options?: SubscriptionOptions): (Position.Automated | null)[];
|
|
33
37
|
getSubscriptionsFor(addresses: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
|
|
34
38
|
}
|
|
35
39
|
export {};
|
|
@@ -14,6 +14,7 @@ import { addToObjectIf, isDefined, isUndefined } from '../../services/utils';
|
|
|
14
14
|
import { getAbiItem, makeSubStorageContract } from '../../services/contractService';
|
|
15
15
|
import { getEventsFromContract, multicall } from '../../services/ethereumService';
|
|
16
16
|
import { parseStrategiesAutomatedPosition } from '../../services/strategiesService';
|
|
17
|
+
import { parseDataFromApiSubscription } from '../../services/apiSubscriptionsService';
|
|
17
18
|
import Automation from './Automation';
|
|
18
19
|
export default class StrategiesAutomation extends Automation {
|
|
19
20
|
constructor(args) {
|
|
@@ -184,6 +185,17 @@ export default class StrategiesAutomation extends Automation {
|
|
|
184
185
|
return this._getSubscriptions(undefined, options);
|
|
185
186
|
});
|
|
186
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* @description Parses subscriptions returned by the automation API (GET /v1/subscriptions)
|
|
190
|
+
*/
|
|
191
|
+
parseSubscriptionsFromApi(records, options) {
|
|
192
|
+
const filtered = (options === null || options === void 0 ? void 0 : options.enabledOnly) ? records.filter((record) => record.is_enabled) : records;
|
|
193
|
+
let subscriptions = filtered.map((record) => this.getParsedSubscriptions(parseDataFromApiSubscription(record, this.chainId)));
|
|
194
|
+
if (options === null || options === void 0 ? void 0 : options.mergeSubs) {
|
|
195
|
+
subscriptions = this.mergeSubs(subscriptions);
|
|
196
|
+
}
|
|
197
|
+
return (options === null || options === void 0 ? void 0 : options.unexpiredOnly) ? this.removeExpiredSubscriptions(subscriptions) : subscriptions;
|
|
198
|
+
}
|
|
187
199
|
getSubscriptionsFor(addresses, options) {
|
|
188
200
|
return __awaiter(this, void 0, void 0, function* () {
|
|
189
201
|
return this._getSubscriptions(addresses, options);
|
|
@@ -688,4 +688,55 @@ describe('Feature: StrategiesAutomation.ts', () => {
|
|
|
688
688
|
expect(loneBoost === null || loneBoost === void 0 ? void 0 : loneBoost.subId).to.equal(1);
|
|
689
689
|
});
|
|
690
690
|
}));
|
|
691
|
+
describe('When testing StrategiesAutomation.parseSubscriptionsFromApi', () => {
|
|
692
|
+
const strategiesAutomation = new StrategiesAutomation({
|
|
693
|
+
chainId: ChainId.Ethereum,
|
|
694
|
+
provider: Web3_1,
|
|
695
|
+
providerFork: null,
|
|
696
|
+
});
|
|
697
|
+
const owner = '0x9cB7E19861665366011899d74E75d4F2A419aEeD';
|
|
698
|
+
const subData = [
|
|
699
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
700
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
701
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
702
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
703
|
+
];
|
|
704
|
+
// Aave V3 leverage management: repay (bundle 8, ratio under) and boost (bundle 9, ratio over) for the same owner and market
|
|
705
|
+
const repay = {
|
|
706
|
+
id: 379,
|
|
707
|
+
wallet: owner,
|
|
708
|
+
wallet_type: 'safe',
|
|
709
|
+
is_enabled: true,
|
|
710
|
+
is_bundle: true,
|
|
711
|
+
strategy_or_bundle_id: 8,
|
|
712
|
+
strategy_ids: [34, 35],
|
|
713
|
+
sub_data_hash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
|
|
714
|
+
trigger_data: ['0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000019ac8532c27900000000000000000000000000000000000000000000000000000000000000000001'],
|
|
715
|
+
sub_data: subData,
|
|
716
|
+
block_number: 18015756,
|
|
717
|
+
additional_triggers: null,
|
|
718
|
+
};
|
|
719
|
+
const boost = Object.assign(Object.assign({}, repay), { id: 380, is_enabled: false, strategy_or_bundle_id: 9, sub_data_hash: '0x1111111111111111111111111111111111111111111111111111111111111111', trigger_data: ['0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e0000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000000000000000000000000'] });
|
|
720
|
+
it('Given API records should return parsed positions', () => {
|
|
721
|
+
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost]);
|
|
722
|
+
expect(positions).to.have.length(2);
|
|
723
|
+
expect(positions.map((p) => p === null || p === void 0 ? void 0 : p.subId)).to.eql([379, 380]);
|
|
724
|
+
expect(positions.map((p) => p === null || p === void 0 ? void 0 : p.isEnabled)).to.eql([true, false]);
|
|
725
|
+
});
|
|
726
|
+
it('Given mergeSubs option should merge the repay and boost pair', () => {
|
|
727
|
+
var _a, _b;
|
|
728
|
+
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost], { mergeSubs: true });
|
|
729
|
+
expect(positions).to.have.length(1);
|
|
730
|
+
expect((_a = positions[0]) === null || _a === void 0 ? void 0 : _a.subIds).to.eql([379, 380]);
|
|
731
|
+
expect((_b = positions[0]) === null || _b === void 0 ? void 0 : _b.isEnabled).to.equal(true);
|
|
732
|
+
});
|
|
733
|
+
it('Given enabledOnly option should drop disabled records before parsing', () => {
|
|
734
|
+
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost], { enabledOnly: true });
|
|
735
|
+
expect(positions.map((p) => p === null || p === void 0 ? void 0 : p.subId)).to.eql([379]);
|
|
736
|
+
});
|
|
737
|
+
it('Given a record of an unknown strategy should return null for it', () => {
|
|
738
|
+
const positions = strategiesAutomation.parseSubscriptionsFromApi([Object.assign(Object.assign({}, repay), { strategy_or_bundle_id: 9999 })]);
|
|
739
|
+
expect(positions).to.eql([null]);
|
|
740
|
+
});
|
|
741
|
+
});
|
|
691
742
|
});
|
package/esm/constants/index.js
CHANGED
|
@@ -121,16 +121,6 @@ export const MAINNET_STRATEGIES_INFO = {
|
|
|
121
121
|
strategyId: Strategies.Identifiers.EoaCollateralSwitch,
|
|
122
122
|
protocol: PROTOCOLS.Spark,
|
|
123
123
|
},
|
|
124
|
-
[Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH]: {
|
|
125
|
-
strategyOrBundleId: Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
126
|
-
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
127
|
-
protocol: PROTOCOLS.AaveV3,
|
|
128
|
-
},
|
|
129
|
-
[Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
130
|
-
strategyOrBundleId: Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
131
|
-
strategyId: Strategies.Identifiers.EoaDebtSwitch,
|
|
132
|
-
protocol: PROTOCOLS.AaveV3,
|
|
133
|
-
},
|
|
134
124
|
};
|
|
135
125
|
export const OPTIMISM_STRATEGIES_INFO = {
|
|
136
126
|
[Strategies.OptimismIds.EXCHANGE_DCA]: {
|
|
@@ -148,16 +138,6 @@ export const OPTIMISM_STRATEGIES_INFO = {
|
|
|
148
138
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
149
139
|
protocol: PROTOCOLS.AaveV3,
|
|
150
140
|
},
|
|
151
|
-
[Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH]: {
|
|
152
|
-
strategyOrBundleId: Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH,
|
|
153
|
-
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
154
|
-
protocol: PROTOCOLS.AaveV3,
|
|
155
|
-
},
|
|
156
|
-
[Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
157
|
-
strategyOrBundleId: Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
158
|
-
strategyId: Strategies.Identifiers.EoaDebtSwitch,
|
|
159
|
-
protocol: PROTOCOLS.AaveV3,
|
|
160
|
-
},
|
|
161
141
|
};
|
|
162
142
|
export const BASE_STRATEGIES_INFO = {
|
|
163
143
|
[Strategies.BaseIds.EXCHANGE_DCA]: {
|
|
@@ -175,16 +155,6 @@ export const BASE_STRATEGIES_INFO = {
|
|
|
175
155
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
176
156
|
protocol: PROTOCOLS.AaveV3,
|
|
177
157
|
},
|
|
178
|
-
[Strategies.BaseIds.AAVE_V3_DEBT_SWITCH]: {
|
|
179
|
-
strategyOrBundleId: Strategies.BaseIds.AAVE_V3_DEBT_SWITCH,
|
|
180
|
-
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
181
|
-
protocol: PROTOCOLS.AaveV3,
|
|
182
|
-
},
|
|
183
|
-
[Strategies.BaseIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
184
|
-
strategyOrBundleId: Strategies.BaseIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
185
|
-
strategyId: Strategies.Identifiers.EoaDebtSwitch,
|
|
186
|
-
protocol: PROTOCOLS.AaveV3,
|
|
187
|
-
},
|
|
188
158
|
};
|
|
189
159
|
export const ARBITRUM_STRATEGIES_INFO = {
|
|
190
160
|
[Strategies.ArbitrumIds.EXCHANGE_DCA]: {
|
|
@@ -202,16 +172,6 @@ export const ARBITRUM_STRATEGIES_INFO = {
|
|
|
202
172
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
203
173
|
protocol: PROTOCOLS.AaveV3,
|
|
204
174
|
},
|
|
205
|
-
[Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH]: {
|
|
206
|
-
strategyOrBundleId: Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH,
|
|
207
|
-
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
208
|
-
protocol: PROTOCOLS.AaveV3,
|
|
209
|
-
},
|
|
210
|
-
[Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
211
|
-
strategyOrBundleId: Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
212
|
-
strategyId: Strategies.Identifiers.EoaDebtSwitch,
|
|
213
|
-
protocol: PROTOCOLS.AaveV3,
|
|
214
|
-
},
|
|
215
175
|
};
|
|
216
176
|
export const STRATEGIES_INFO = {
|
|
217
177
|
[ChainId.Ethereum]: MAINNET_STRATEGIES_INFO,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ApiSubscriptionRecord, ParseData } from '../types';
|
|
2
|
+
import type { ChainId } from '../types/enums';
|
|
3
|
+
/**
|
|
4
|
+
* @description Maps a subscription record returned by the automation API to the data
|
|
5
|
+
* the parser expects from Subscribe events and SubStorage (trigger data is stored without 0x prefix)
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseDataFromApiSubscription(record: ApiSubscriptionRecord, chainId: ChainId): ParseData;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function addHexPrefix(value) {
|
|
2
|
+
return value.startsWith('0x') ? value : `0x${value}`;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* @description Maps a subscription record returned by the automation API to the data
|
|
6
|
+
* the parser expects from Subscribe events and SubStorage (trigger data is stored without 0x prefix)
|
|
7
|
+
*/
|
|
8
|
+
export function parseDataFromApiSubscription(record, chainId) {
|
|
9
|
+
return {
|
|
10
|
+
chainId,
|
|
11
|
+
blockNumber: record.block_number,
|
|
12
|
+
subscriptionEventData: {
|
|
13
|
+
subId: record.id.toString(),
|
|
14
|
+
proxy: record.wallet,
|
|
15
|
+
subHash: record.sub_data_hash,
|
|
16
|
+
subStruct: {
|
|
17
|
+
strategyOrBundleId: record.strategy_or_bundle_id.toString(),
|
|
18
|
+
isBundle: record.is_bundle,
|
|
19
|
+
triggerData: record.trigger_data.map(addHexPrefix),
|
|
20
|
+
subData: record.sub_data.map(addHexPrefix),
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
strategiesSubsData: {
|
|
24
|
+
userProxy: record.wallet,
|
|
25
|
+
isEnabled: record.is_enabled,
|
|
26
|
+
strategySubHash: record.sub_data_hash,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '../configuration';
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import { ChainId } from '../types/enums';
|
|
3
|
+
import '../configuration';
|
|
4
|
+
import { parseDataFromApiSubscription } from './apiSubscriptionsService';
|
|
5
|
+
import { parseStrategiesAutomatedPosition } from './strategiesService';
|
|
6
|
+
describe('Feature: apiSubscriptionsService.ts', () => {
|
|
7
|
+
describe('When testing apiSubscriptionsService.parseDataFromApiSubscription', () => {
|
|
8
|
+
// same subscription as in strategiesService.test.ts, in the shape the automation API returns it
|
|
9
|
+
const record = {
|
|
10
|
+
id: 379,
|
|
11
|
+
wallet: '0x9cB7E19861665366011899d74E75d4F2A419aEeD',
|
|
12
|
+
wallet_type: 'safe',
|
|
13
|
+
is_enabled: true,
|
|
14
|
+
is_bundle: true,
|
|
15
|
+
strategy_or_bundle_id: 8,
|
|
16
|
+
strategy_ids: [34, 35],
|
|
17
|
+
sub_data_hash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
|
|
18
|
+
trigger_data: [
|
|
19
|
+
'0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000019ac8532c27900000000000000000000000000000000000000000000000000000000000000000001',
|
|
20
|
+
],
|
|
21
|
+
sub_data: [
|
|
22
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
23
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
24
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
25
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
26
|
+
],
|
|
27
|
+
block_number: 18015756,
|
|
28
|
+
additional_triggers: null,
|
|
29
|
+
};
|
|
30
|
+
const fromEvents = {
|
|
31
|
+
chainId: ChainId.Ethereum,
|
|
32
|
+
blockNumber: 18015756,
|
|
33
|
+
subscriptionEventData: {
|
|
34
|
+
subId: '379',
|
|
35
|
+
proxy: '0x9cB7E19861665366011899d74E75d4F2A419aEeD',
|
|
36
|
+
subHash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
|
|
37
|
+
subStruct: {
|
|
38
|
+
strategyOrBundleId: '8',
|
|
39
|
+
isBundle: true,
|
|
40
|
+
triggerData: [
|
|
41
|
+
'0x0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000019ac8532c27900000000000000000000000000000000000000000000000000000000000000000001',
|
|
42
|
+
],
|
|
43
|
+
subData: record.sub_data,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
strategiesSubsData: {
|
|
47
|
+
userProxy: '0x9cB7E19861665366011899d74E75d4F2A419aEeD',
|
|
48
|
+
isEnabled: true,
|
|
49
|
+
strategySubHash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
it('Given an API record should return the same parse data as Subscribe event and SubStorage would', () => {
|
|
53
|
+
expect(parseDataFromApiSubscription(record, ChainId.Ethereum)).to.eql(fromEvents);
|
|
54
|
+
});
|
|
55
|
+
it('Given an API record the parsed position should match the one parsed from events', () => {
|
|
56
|
+
const fromApi = parseStrategiesAutomatedPosition(parseDataFromApiSubscription(record, ChainId.Ethereum));
|
|
57
|
+
expect(fromApi).to.not.equal(null);
|
|
58
|
+
expect(fromApi).to.eql(parseStrategiesAutomatedPosition(fromEvents));
|
|
59
|
+
});
|
|
60
|
+
it('Given a disabled record should keep it disabled', () => {
|
|
61
|
+
const parseData = parseDataFromApiSubscription(Object.assign(Object.assign({}, record), { is_enabled: false }), ChainId.Ethereum);
|
|
62
|
+
expect(parseData.strategiesSubsData.isEnabled).to.equal(false);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -327,17 +327,6 @@ function parseAaveV3CollateralSwitch(position, parseData) {
|
|
|
327
327
|
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
328
328
|
return _position;
|
|
329
329
|
}
|
|
330
|
-
function parseAaveV3DebtSwitch(position, parseData) {
|
|
331
|
-
const _position = cloneDeep(position);
|
|
332
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
333
|
-
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
334
|
-
const subData = subDataService.aaveV3DebtSwitchSubData.decode(subStruct.subData);
|
|
335
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
336
|
-
_position.strategyData.decoded.subData = subData;
|
|
337
|
-
// TODO -> This isn't enough for ID
|
|
338
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
339
|
-
return _position;
|
|
340
|
-
}
|
|
341
330
|
function parseSparkCollateralSwitch(position, parseData) {
|
|
342
331
|
const _position = cloneDeep(position);
|
|
343
332
|
const { subStruct } = parseData.subscriptionEventData;
|
|
@@ -1228,8 +1217,6 @@ const parsingMethodsMapping = {
|
|
|
1228
1217
|
[Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
1229
1218
|
[Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
|
|
1230
1219
|
[Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
|
|
1231
|
-
[Strategies.Identifiers.DebtSwitch]: parseAaveV3DebtSwitch,
|
|
1232
|
-
[Strategies.Identifiers.EoaDebtSwitch]: parseAaveV3DebtSwitch,
|
|
1233
1220
|
[Strategies.Identifiers.LiquidationProtection]: parseAaveV3LiquidationProtection,
|
|
1234
1221
|
[Strategies.Identifiers.EoaLiquidationProtection]: parseAaveV3LiquidationProtection,
|
|
1235
1222
|
},
|
|
@@ -81,7 +81,6 @@ describe('Feature: strategiesService.ts', () => {
|
|
|
81
81
|
subId: '379',
|
|
82
82
|
proxy: '0x9cb7e19861665366011899d74e75d4f2a419aeed',
|
|
83
83
|
subHash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
|
|
84
|
-
// @ts-ignore
|
|
85
84
|
subStruct: {
|
|
86
85
|
strategyOrBundleId: '8',
|
|
87
86
|
isBundle: true,
|
|
@@ -62,7 +62,6 @@ export declare const aaveV3Encode: {
|
|
|
62
62
|
leverageManagementOnPriceGeneric(strategyOrBundleId: number, price: number, ratioState: RatioState, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number, user: EthereumAddress): (number | boolean | string[])[];
|
|
63
63
|
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[])[];
|
|
64
64
|
collateralSwitch(strategyOrBundleId: number, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState): (number | boolean | string[])[];
|
|
65
|
-
debtSwitch(strategyOrBundleId: number, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress, baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState): (number | boolean | string[])[];
|
|
66
65
|
};
|
|
67
66
|
export declare const compoundV2Encode: {
|
|
68
67
|
leverageManagement(strategyOrBundleId: number, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
@@ -170,12 +170,6 @@ export const aaveV3Encode = {
|
|
|
170
170
|
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
171
171
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
172
172
|
},
|
|
173
|
-
debtSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user, baseTokenAddress, quoteTokenAddress, price, state) {
|
|
174
|
-
const isBundle = false;
|
|
175
|
-
const subDataEncoded = subDataService.aaveV3DebtSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user);
|
|
176
|
-
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
177
|
-
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
178
|
-
},
|
|
179
173
|
};
|
|
180
174
|
export const compoundV2Encode = {
|
|
181
175
|
leverageManagement(strategyOrBundleId, user, ratioState, targetRatio, triggerRatio) {
|
|
@@ -831,77 +831,6 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
831
831
|
});
|
|
832
832
|
});
|
|
833
833
|
});
|
|
834
|
-
describe('debtSwitch()', () => {
|
|
835
|
-
const examples = [
|
|
836
|
-
// USDC -> DAI, price 100000, state UNDER
|
|
837
|
-
[
|
|
838
|
-
[
|
|
839
|
-
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
840
|
-
false,
|
|
841
|
-
['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000009184e72a0000000000000000000000000000000000000000000000000000000000000000001'],
|
|
842
|
-
[
|
|
843
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
844
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
845
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
846
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
847
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
848
|
-
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
849
|
-
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
850
|
-
],
|
|
851
|
-
],
|
|
852
|
-
[
|
|
853
|
-
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
854
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
855
|
-
1,
|
|
856
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
857
|
-
3,
|
|
858
|
-
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
859
|
-
'10000000000000000000',
|
|
860
|
-
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
861
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
862
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
863
|
-
100000,
|
|
864
|
-
RatioState.UNDER,
|
|
865
|
-
]
|
|
866
|
-
],
|
|
867
|
-
// DAI -> USDC (MaxUint256), price 1, state OVER
|
|
868
|
-
[
|
|
869
|
-
[
|
|
870
|
-
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
871
|
-
false,
|
|
872
|
-
['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000000'],
|
|
873
|
-
[
|
|
874
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
875
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
876
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
877
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
878
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
879
|
-
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
880
|
-
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
881
|
-
],
|
|
882
|
-
],
|
|
883
|
-
[
|
|
884
|
-
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
885
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
886
|
-
3,
|
|
887
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
888
|
-
1,
|
|
889
|
-
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
890
|
-
MAXUINT,
|
|
891
|
-
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
892
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
893
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
894
|
-
1,
|
|
895
|
-
RatioState.OVER,
|
|
896
|
-
]
|
|
897
|
-
],
|
|
898
|
-
];
|
|
899
|
-
examples.forEach(([expected, actual]) => {
|
|
900
|
-
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
901
|
-
expect(aaveV3Encode.debtSwitch(...actual)).to.eql(expected);
|
|
902
|
-
});
|
|
903
|
-
});
|
|
904
|
-
});
|
|
905
834
|
});
|
|
906
835
|
describe('When testing strategySubService.compoundV3Encode', () => {
|
|
907
836
|
describe('leverageManagementOnPrice()', () => {
|
|
@@ -259,18 +259,6 @@ export declare const aaveV3CollateralSwitchSubData: {
|
|
|
259
259
|
amountToSwitch: string;
|
|
260
260
|
};
|
|
261
261
|
};
|
|
262
|
-
export declare const aaveV3DebtSwitchSubData: {
|
|
263
|
-
encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress): string[];
|
|
264
|
-
decode(subData: string[]): {
|
|
265
|
-
fromAsset: EthereumAddress;
|
|
266
|
-
fromAssetId: number;
|
|
267
|
-
toAsset: EthereumAddress;
|
|
268
|
-
toAssetId: number;
|
|
269
|
-
marketAddr: EthereumAddress;
|
|
270
|
-
amountToSwitch: string;
|
|
271
|
-
user: EthereumAddress;
|
|
272
|
-
};
|
|
273
|
-
};
|
|
274
262
|
export declare const aaveV3QuotePriceSubData: {
|
|
275
263
|
encode(collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, nullAddress?: EthereumAddress): string[];
|
|
276
264
|
decode(subData: string[]): {
|
|
@@ -542,38 +542,6 @@ export const aaveV3CollateralSwitchSubData = {
|
|
|
542
542
|
};
|
|
543
543
|
},
|
|
544
544
|
};
|
|
545
|
-
export const aaveV3DebtSwitchSubData = {
|
|
546
|
-
encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user) {
|
|
547
|
-
const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
|
|
548
|
-
const encodedFromAssetId = AbiCoder.encodeParameter('uint8', fromAssetId);
|
|
549
|
-
const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
|
|
550
|
-
const encodedToAssetId = AbiCoder.encodeParameter('uint8', toAssetId);
|
|
551
|
-
const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
|
|
552
|
-
const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
|
|
553
|
-
const encodedUser = AbiCoder.encodeParameter('address', user);
|
|
554
|
-
return [
|
|
555
|
-
encodedFromAsset,
|
|
556
|
-
encodedFromAssetId,
|
|
557
|
-
encodedToAsset,
|
|
558
|
-
encodedToAssetId,
|
|
559
|
-
encodedMarketAddr,
|
|
560
|
-
encodedAmountToSwitch,
|
|
561
|
-
encodedUser,
|
|
562
|
-
];
|
|
563
|
-
},
|
|
564
|
-
decode(subData) {
|
|
565
|
-
const fromAsset = AbiCoder.decodeParameter('address', subData[0]);
|
|
566
|
-
const fromAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
|
|
567
|
-
const toAsset = AbiCoder.decodeParameter('address', subData[2]);
|
|
568
|
-
const toAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
|
|
569
|
-
const marketAddr = AbiCoder.decodeParameter('address', subData[4]);
|
|
570
|
-
const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]);
|
|
571
|
-
const user = AbiCoder.decodeParameter('address', subData[6]);
|
|
572
|
-
return {
|
|
573
|
-
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user,
|
|
574
|
-
};
|
|
575
|
-
},
|
|
576
|
-
};
|
|
577
545
|
export const aaveV3QuotePriceSubData = {
|
|
578
546
|
encode(collAsset, collAssetId, debtAsset, debtAssetId, nullAddress = ZERO_ADDRESS) {
|
|
579
547
|
const encodedColl = AbiCoder.encodeParameter('address', collAsset);
|