@defisaver/automation-sdk 3.3.19-sub-fetching.2-dev → 3.3.20
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 +1 -5
- package/cjs/automation/private/StrategiesAutomation.js +0 -12
- package/cjs/automation/private/StrategiesAutomation.test.js +0 -51
- package/cjs/services/strategiesService.test.js +1 -0
- package/cjs/types/index.d.ts +2 -24
- package/esm/automation/private/StrategiesAutomation.d.ts +1 -5
- package/esm/automation/private/StrategiesAutomation.js +0 -12
- package/esm/automation/private/StrategiesAutomation.test.js +0 -51
- package/esm/services/strategiesService.test.js +1 -0
- package/esm/types/index.d.ts +2 -24
- package/package.json +12 -2
- package/src/automation/private/StrategiesAutomation.test.ts +1 -65
- package/src/automation/private/StrategiesAutomation.ts +0 -17
- package/src/services/strategiesService.test.ts +1 -0
- package/src/types/index.ts +2 -26
- package/cjs/services/apiSubscriptionsService.d.ts +0 -7
- package/cjs/services/apiSubscriptionsService.js +0 -33
- package/cjs/services/apiSubscriptionsService.test.d.ts +0 -1
- package/cjs/services/apiSubscriptionsService.test.js +0 -67
- package/esm/services/apiSubscriptionsService.d.ts +0 -7
- package/esm/services/apiSubscriptionsService.js +0 -29
- package/esm/services/apiSubscriptionsService.test.d.ts +0 -1
- package/esm/services/apiSubscriptionsService.test.js +0 -65
- package/src/services/apiSubscriptionsService.test.ts +0 -73
- package/src/services/apiSubscriptionsService.ts +0 -33
|
@@ -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
|
|
3
|
+
import type { Position, Interfaces, EthereumAddress, SubscriptionOptions, Contract, ParseData, BlockNumber } 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,10 +30,6 @@ 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)[];
|
|
37
33
|
getSubscriptionsFor(addresses: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
|
|
38
34
|
}
|
|
39
35
|
export {};
|
|
@@ -19,7 +19,6 @@ const utils_1 = require("../../services/utils");
|
|
|
19
19
|
const contractService_1 = require("../../services/contractService");
|
|
20
20
|
const ethereumService_1 = require("../../services/ethereumService");
|
|
21
21
|
const strategiesService_1 = require("../../services/strategiesService");
|
|
22
|
-
const apiSubscriptionsService_1 = require("../../services/apiSubscriptionsService");
|
|
23
22
|
const Automation_1 = __importDefault(require("./Automation"));
|
|
24
23
|
class StrategiesAutomation extends Automation_1.default {
|
|
25
24
|
constructor(args) {
|
|
@@ -190,17 +189,6 @@ class StrategiesAutomation extends Automation_1.default {
|
|
|
190
189
|
return this._getSubscriptions(undefined, options);
|
|
191
190
|
});
|
|
192
191
|
}
|
|
193
|
-
/**
|
|
194
|
-
* @description Parses subscriptions returned by the automation API (GET /v1/subscriptions)
|
|
195
|
-
*/
|
|
196
|
-
parseSubscriptionsFromApi(records, options) {
|
|
197
|
-
const filtered = (options === null || options === void 0 ? void 0 : options.enabledOnly) ? records.filter((record) => record.is_enabled) : records;
|
|
198
|
-
let subscriptions = filtered.map((record) => this.getParsedSubscriptions((0, apiSubscriptionsService_1.parseDataFromApiSubscription)(record, this.chainId)));
|
|
199
|
-
if (options === null || options === void 0 ? void 0 : options.mergeSubs) {
|
|
200
|
-
subscriptions = this.mergeSubs(subscriptions);
|
|
201
|
-
}
|
|
202
|
-
return (options === null || options === void 0 ? void 0 : options.unexpiredOnly) ? this.removeExpiredSubscriptions(subscriptions) : subscriptions;
|
|
203
|
-
}
|
|
204
192
|
getSubscriptionsFor(addresses, options) {
|
|
205
193
|
return __awaiter(this, void 0, void 0, function* () {
|
|
206
194
|
return this._getSubscriptions(addresses, options);
|
|
@@ -693,55 +693,4 @@ describe('Feature: StrategiesAutomation.ts', () => {
|
|
|
693
693
|
(0, chai_1.expect)(loneBoost === null || loneBoost === void 0 ? void 0 : loneBoost.subId).to.equal(1);
|
|
694
694
|
});
|
|
695
695
|
}));
|
|
696
|
-
describe('When testing StrategiesAutomation.parseSubscriptionsFromApi', () => {
|
|
697
|
-
const strategiesAutomation = new StrategiesAutomation_1.default({
|
|
698
|
-
chainId: enums_1.ChainId.Ethereum,
|
|
699
|
-
provider: Web3_1,
|
|
700
|
-
providerFork: null,
|
|
701
|
-
});
|
|
702
|
-
const owner = '0x9cB7E19861665366011899d74E75d4F2A419aEeD';
|
|
703
|
-
const subData = [
|
|
704
|
-
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
705
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
706
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
707
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
708
|
-
];
|
|
709
|
-
// Aave V3 leverage management: repay (bundle 8, ratio under) and boost (bundle 9, ratio over) for the same owner and market
|
|
710
|
-
const repay = {
|
|
711
|
-
id: 379,
|
|
712
|
-
wallet: owner,
|
|
713
|
-
wallet_type: 'safe',
|
|
714
|
-
is_enabled: true,
|
|
715
|
-
is_bundle: true,
|
|
716
|
-
strategy_or_bundle_id: 8,
|
|
717
|
-
strategy_ids: [34, 35],
|
|
718
|
-
sub_data_hash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
|
|
719
|
-
trigger_data: ['0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000019ac8532c27900000000000000000000000000000000000000000000000000000000000000000001'],
|
|
720
|
-
sub_data: subData,
|
|
721
|
-
block_number: 18015756,
|
|
722
|
-
additional_triggers: null,
|
|
723
|
-
};
|
|
724
|
-
const boost = Object.assign(Object.assign({}, repay), { id: 380, is_enabled: false, strategy_or_bundle_id: 9, sub_data_hash: '0x1111111111111111111111111111111111111111111111111111111111111111', trigger_data: ['0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e0000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000000000000000000000000'] });
|
|
725
|
-
it('Given API records should return parsed positions', () => {
|
|
726
|
-
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost]);
|
|
727
|
-
(0, chai_1.expect)(positions).to.have.length(2);
|
|
728
|
-
(0, chai_1.expect)(positions.map((p) => p === null || p === void 0 ? void 0 : p.subId)).to.eql([379, 380]);
|
|
729
|
-
(0, chai_1.expect)(positions.map((p) => p === null || p === void 0 ? void 0 : p.isEnabled)).to.eql([true, false]);
|
|
730
|
-
});
|
|
731
|
-
it('Given mergeSubs option should merge the repay and boost pair', () => {
|
|
732
|
-
var _a, _b;
|
|
733
|
-
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost], { mergeSubs: true });
|
|
734
|
-
(0, chai_1.expect)(positions).to.have.length(1);
|
|
735
|
-
(0, chai_1.expect)((_a = positions[0]) === null || _a === void 0 ? void 0 : _a.subIds).to.eql([379, 380]);
|
|
736
|
-
(0, chai_1.expect)((_b = positions[0]) === null || _b === void 0 ? void 0 : _b.isEnabled).to.equal(true);
|
|
737
|
-
});
|
|
738
|
-
it('Given enabledOnly option should drop disabled records before parsing', () => {
|
|
739
|
-
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost], { enabledOnly: true });
|
|
740
|
-
(0, chai_1.expect)(positions.map((p) => p === null || p === void 0 ? void 0 : p.subId)).to.eql([379]);
|
|
741
|
-
});
|
|
742
|
-
it('Given a record of an unknown strategy should return null for it', () => {
|
|
743
|
-
const positions = strategiesAutomation.parseSubscriptionsFromApi([Object.assign(Object.assign({}, repay), { strategy_or_bundle_id: 9999 })]);
|
|
744
|
-
(0, chai_1.expect)(positions).to.eql([null]);
|
|
745
|
-
});
|
|
746
|
-
});
|
|
747
696
|
});
|
|
@@ -83,6 +83,7 @@ describe('Feature: strategiesService.ts', () => {
|
|
|
83
83
|
subId: '379',
|
|
84
84
|
proxy: '0x9cb7e19861665366011899d74e75d4f2a419aeed',
|
|
85
85
|
subHash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
|
|
86
|
+
// @ts-ignore
|
|
86
87
|
subStruct: {
|
|
87
88
|
strategyOrBundleId: '8',
|
|
88
89
|
isBundle: true,
|
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 { StrategyModel } from './contracts/generated/SubStorage';
|
|
4
|
+
import type { Subscribe, 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,21 +53,6 @@ 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
|
-
}
|
|
71
56
|
export declare namespace Interfaces {
|
|
72
57
|
interface ProtocolBase {
|
|
73
58
|
id: ProtocolIdentifiers.StrategiesAutomation | ProtocolIdentifiers.LegacyAutomation;
|
|
@@ -306,17 +291,10 @@ export interface BundlesInfo {
|
|
|
306
291
|
[ChainId.Base]: BaseBundleInfo;
|
|
307
292
|
}
|
|
308
293
|
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
|
-
}
|
|
316
294
|
export interface ParseData {
|
|
317
295
|
chainId: ChainId;
|
|
318
296
|
blockNumber: BlockNumber;
|
|
319
|
-
subscriptionEventData:
|
|
297
|
+
subscriptionEventData: Subscribe['returnValues'];
|
|
320
298
|
strategiesSubsData: StrategyModel.StoredSubDataStructOutputStruct;
|
|
321
299
|
}
|
|
322
300
|
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
|
|
3
|
+
import type { Position, Interfaces, EthereumAddress, SubscriptionOptions, Contract, ParseData, BlockNumber } 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,10 +30,6 @@ 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)[];
|
|
37
33
|
getSubscriptionsFor(addresses: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
|
|
38
34
|
}
|
|
39
35
|
export {};
|
|
@@ -14,7 +14,6 @@ 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';
|
|
18
17
|
import Automation from './Automation';
|
|
19
18
|
export default class StrategiesAutomation extends Automation {
|
|
20
19
|
constructor(args) {
|
|
@@ -185,17 +184,6 @@ export default class StrategiesAutomation extends Automation {
|
|
|
185
184
|
return this._getSubscriptions(undefined, options);
|
|
186
185
|
});
|
|
187
186
|
}
|
|
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
|
-
}
|
|
199
187
|
getSubscriptionsFor(addresses, options) {
|
|
200
188
|
return __awaiter(this, void 0, void 0, function* () {
|
|
201
189
|
return this._getSubscriptions(addresses, options);
|
|
@@ -688,55 +688,4 @@ 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
|
-
});
|
|
742
691
|
});
|
|
@@ -81,6 +81,7 @@ describe('Feature: strategiesService.ts', () => {
|
|
|
81
81
|
subId: '379',
|
|
82
82
|
proxy: '0x9cb7e19861665366011899d74e75d4f2a419aeed',
|
|
83
83
|
subHash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
|
|
84
|
+
// @ts-ignore
|
|
84
85
|
subStruct: {
|
|
85
86
|
strategyOrBundleId: '8',
|
|
86
87
|
isBundle: true,
|
package/esm/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 { StrategyModel } from './contracts/generated/SubStorage';
|
|
4
|
+
import type { Subscribe, 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,21 +53,6 @@ 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
|
-
}
|
|
71
56
|
export declare namespace Interfaces {
|
|
72
57
|
interface ProtocolBase {
|
|
73
58
|
id: ProtocolIdentifiers.StrategiesAutomation | ProtocolIdentifiers.LegacyAutomation;
|
|
@@ -306,17 +291,10 @@ export interface BundlesInfo {
|
|
|
306
291
|
[ChainId.Base]: BaseBundleInfo;
|
|
307
292
|
}
|
|
308
293
|
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
|
-
}
|
|
316
294
|
export interface ParseData {
|
|
317
295
|
chainId: ChainId;
|
|
318
296
|
blockNumber: BlockNumber;
|
|
319
|
-
subscriptionEventData:
|
|
297
|
+
subscriptionEventData: Subscribe['returnValues'];
|
|
320
298
|
strategiesSubsData: StrategyModel.StoredSubDataStructOutputStruct;
|
|
321
299
|
}
|
|
322
300
|
type MapToProtocolVersion<T> = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defisaver/automation-sdk",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.20",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -22,6 +22,17 @@
|
|
|
22
22
|
"author": "DeFi Saver",
|
|
23
23
|
"repository": "https://github.com/defisaver/automation-sdk",
|
|
24
24
|
"license": "ISC",
|
|
25
|
+
"overrides": {
|
|
26
|
+
"axios": "^1.19.0",
|
|
27
|
+
"tar": "^7.5.21",
|
|
28
|
+
"ws": "^8.18.3",
|
|
29
|
+
"form-data": "^4.0.4",
|
|
30
|
+
"tough-cookie": "^4.1.3",
|
|
31
|
+
"qs": "^6.16.0",
|
|
32
|
+
"serialize-javascript": "^7.1.0",
|
|
33
|
+
"fast-uri": "^3.1.8",
|
|
34
|
+
"js-yaml": "^4.3.2"
|
|
35
|
+
},
|
|
25
36
|
"dependencies": {
|
|
26
37
|
"@defisaver/sdk": "^1.3.22",
|
|
27
38
|
"@defisaver/tokens": "^1.6.19",
|
|
@@ -44,7 +55,6 @@
|
|
|
44
55
|
"dotenv": "^16.3.1",
|
|
45
56
|
"eslint": "^8.49.0",
|
|
46
57
|
"husky": "^8.0.0",
|
|
47
|
-
"jsdoc-to-markdown": "^6.0.1",
|
|
48
58
|
"mocha": "^10.2.0",
|
|
49
59
|
"ts-node": "^10.9.1",
|
|
50
60
|
"typechain": "^8.1.0",
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import Web3 from 'web3';
|
|
2
2
|
import { expect } from 'chai';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import type { ApiSubscriptionRecord } from '../../types';
|
|
4
|
+
import {ChainId} from '../../types/enums';
|
|
6
5
|
|
|
7
6
|
import '../../configuration';
|
|
8
7
|
import StrategiesAutomation from './StrategiesAutomation';
|
|
@@ -701,67 +700,4 @@ describe('Feature: StrategiesAutomation.ts', () => {
|
|
|
701
700
|
expect(loneBoost?.subId).to.equal(1);
|
|
702
701
|
});
|
|
703
702
|
});
|
|
704
|
-
|
|
705
|
-
describe('When testing StrategiesAutomation.parseSubscriptionsFromApi', () => {
|
|
706
|
-
const strategiesAutomation = new StrategiesAutomation({
|
|
707
|
-
chainId: ChainId.Ethereum,
|
|
708
|
-
provider: Web3_1,
|
|
709
|
-
providerFork: null!,
|
|
710
|
-
});
|
|
711
|
-
|
|
712
|
-
const owner = '0x9cB7E19861665366011899d74E75d4F2A419aEeD';
|
|
713
|
-
const subData = [
|
|
714
|
-
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
715
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
716
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
717
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
718
|
-
];
|
|
719
|
-
// Aave V3 leverage management: repay (bundle 8, ratio under) and boost (bundle 9, ratio over) for the same owner and market
|
|
720
|
-
const repay: ApiSubscriptionRecord = {
|
|
721
|
-
id: 379,
|
|
722
|
-
wallet: owner,
|
|
723
|
-
wallet_type: 'safe',
|
|
724
|
-
is_enabled: true,
|
|
725
|
-
is_bundle: true,
|
|
726
|
-
strategy_or_bundle_id: 8,
|
|
727
|
-
strategy_ids: [34, 35],
|
|
728
|
-
sub_data_hash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
|
|
729
|
-
trigger_data: ['0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000019ac8532c27900000000000000000000000000000000000000000000000000000000000000000001'],
|
|
730
|
-
sub_data: subData,
|
|
731
|
-
block_number: 18015756,
|
|
732
|
-
additional_triggers: null,
|
|
733
|
-
};
|
|
734
|
-
const boost: ApiSubscriptionRecord = {
|
|
735
|
-
...repay,
|
|
736
|
-
id: 380,
|
|
737
|
-
is_enabled: false,
|
|
738
|
-
strategy_or_bundle_id: 9,
|
|
739
|
-
sub_data_hash: '0x1111111111111111111111111111111111111111111111111111111111111111',
|
|
740
|
-
trigger_data: ['0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e0000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000000000000000000000000'],
|
|
741
|
-
};
|
|
742
|
-
|
|
743
|
-
it('Given API records should return parsed positions', () => {
|
|
744
|
-
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost]);
|
|
745
|
-
expect(positions).to.have.length(2);
|
|
746
|
-
expect(positions.map((p) => p?.subId)).to.eql([379, 380]);
|
|
747
|
-
expect(positions.map((p) => p?.isEnabled)).to.eql([true, false]);
|
|
748
|
-
});
|
|
749
|
-
|
|
750
|
-
it('Given mergeSubs option should merge the repay and boost pair', () => {
|
|
751
|
-
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost], { mergeSubs: true });
|
|
752
|
-
expect(positions).to.have.length(1);
|
|
753
|
-
expect(positions[0]?.subIds).to.eql([379, 380]);
|
|
754
|
-
expect(positions[0]?.isEnabled).to.equal(true);
|
|
755
|
-
});
|
|
756
|
-
|
|
757
|
-
it('Given enabledOnly option should drop disabled records before parsing', () => {
|
|
758
|
-
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost], { enabledOnly: true });
|
|
759
|
-
expect(positions.map((p) => p?.subId)).to.eql([379]);
|
|
760
|
-
});
|
|
761
|
-
|
|
762
|
-
it('Given a record of an unknown strategy should return null for it', () => {
|
|
763
|
-
const positions = strategiesAutomation.parseSubscriptionsFromApi([{ ...repay, strategy_or_bundle_id: 9999 }]);
|
|
764
|
-
expect(positions).to.eql([null]);
|
|
765
|
-
});
|
|
766
|
-
});
|
|
767
703
|
});
|
|
@@ -4,7 +4,6 @@ import type { PastEventOptions } from 'web3-eth-contract';
|
|
|
4
4
|
import PromisePool from 'es6-promise-pool';
|
|
5
5
|
import type {
|
|
6
6
|
Position, Interfaces, EthereumAddress, SubscriptionOptions, Contract, ParseData, PlaceholderType, BlockNumber,
|
|
7
|
-
ApiSubscriptionRecord,
|
|
8
7
|
} from '../../types';
|
|
9
8
|
import type {
|
|
10
9
|
StrategyModel, Subscribe, SubStorage, UpdateData,
|
|
@@ -16,7 +15,6 @@ import { addToObjectIf, isDefined, isUndefined } from '../../services/utils';
|
|
|
16
15
|
import { getAbiItem, makeSubStorageContract } from '../../services/contractService';
|
|
17
16
|
import { getEventsFromContract, multicall } from '../../services/ethereumService';
|
|
18
17
|
import { parseStrategiesAutomatedPosition } from '../../services/strategiesService';
|
|
19
|
-
import { parseDataFromApiSubscription } from '../../services/apiSubscriptionsService';
|
|
20
18
|
|
|
21
19
|
import Automation from './Automation';
|
|
22
20
|
|
|
@@ -261,21 +259,6 @@ export default class StrategiesAutomation extends Automation {
|
|
|
261
259
|
return this._getSubscriptions(undefined, options);
|
|
262
260
|
}
|
|
263
261
|
|
|
264
|
-
/**
|
|
265
|
-
* @description Parses subscriptions returned by the automation API (GET /v1/subscriptions)
|
|
266
|
-
*/
|
|
267
|
-
public parseSubscriptionsFromApi(records: ApiSubscriptionRecord[], options?: SubscriptionOptions): (Position.Automated | null)[] {
|
|
268
|
-
const filtered = options?.enabledOnly ? records.filter((record) => record.is_enabled) : records;
|
|
269
|
-
|
|
270
|
-
let subscriptions = filtered.map((record) => this.getParsedSubscriptions(parseDataFromApiSubscription(record, this.chainId)));
|
|
271
|
-
|
|
272
|
-
if (options?.mergeSubs) {
|
|
273
|
-
subscriptions = this.mergeSubs(subscriptions);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
return options?.unexpiredOnly ? this.removeExpiredSubscriptions(subscriptions) : subscriptions;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
262
|
public async getSubscriptionsFor(addresses: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]> {
|
|
280
263
|
return this._getSubscriptions(addresses, options);
|
|
281
264
|
}
|
|
@@ -76,6 +76,7 @@ describe('Feature: strategiesService.ts', () => {
|
|
|
76
76
|
subId: '379',
|
|
77
77
|
proxy: '0x9cb7e19861665366011899d74e75d4f2a419aeed',
|
|
78
78
|
subHash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
|
|
79
|
+
// @ts-ignore
|
|
79
80
|
subStruct:
|
|
80
81
|
{
|
|
81
82
|
strategyOrBundleId: '8',
|
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 { StrategyModel } from './contracts/generated/SubStorage';
|
|
4
|
+
import type { Subscribe, StrategyModel } from './contracts/generated/SubStorage';
|
|
5
5
|
import type {
|
|
6
6
|
ChainId, Strategies, Bundles, ProtocolIdentifiers,
|
|
7
7
|
RatioState,
|
|
@@ -72,22 +72,6 @@ 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
|
-
|
|
91
75
|
export declare namespace Interfaces {
|
|
92
76
|
interface ProtocolBase {
|
|
93
77
|
id: ProtocolIdentifiers.StrategiesAutomation | ProtocolIdentifiers.LegacyAutomation,
|
|
@@ -385,18 +369,10 @@ export type StrategyOrBundleIds =
|
|
|
385
369
|
| typeof Bundles.ArbitrumIds[keyof typeof Bundles.ArbitrumIds]
|
|
386
370
|
| typeof Bundles.BaseIds[keyof typeof Bundles.BaseIds];
|
|
387
371
|
|
|
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
|
-
|
|
396
372
|
export interface ParseData {
|
|
397
373
|
chainId: ChainId,
|
|
398
374
|
blockNumber: BlockNumber,
|
|
399
|
-
subscriptionEventData:
|
|
375
|
+
subscriptionEventData: Subscribe['returnValues']
|
|
400
376
|
strategiesSubsData: StrategyModel.StoredSubDataStructOutputStruct,
|
|
401
377
|
}
|
|
402
378
|
|
|
@@ -1,7 +0,0 @@
|
|
|
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;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseDataFromApiSubscription = void 0;
|
|
4
|
-
function addHexPrefix(value) {
|
|
5
|
-
return value.startsWith('0x') ? value : `0x${value}`;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* @description Maps a subscription record returned by the automation API to the data
|
|
9
|
-
* the parser expects from Subscribe events and SubStorage (trigger data is stored without 0x prefix)
|
|
10
|
-
*/
|
|
11
|
-
function parseDataFromApiSubscription(record, chainId) {
|
|
12
|
-
return {
|
|
13
|
-
chainId,
|
|
14
|
-
blockNumber: record.block_number,
|
|
15
|
-
subscriptionEventData: {
|
|
16
|
-
subId: record.id.toString(),
|
|
17
|
-
proxy: record.wallet,
|
|
18
|
-
subHash: record.sub_data_hash,
|
|
19
|
-
subStruct: {
|
|
20
|
-
strategyOrBundleId: record.strategy_or_bundle_id.toString(),
|
|
21
|
-
isBundle: record.is_bundle,
|
|
22
|
-
triggerData: record.trigger_data.map(addHexPrefix),
|
|
23
|
-
subData: record.sub_data.map(addHexPrefix),
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
strategiesSubsData: {
|
|
27
|
-
userProxy: record.wallet,
|
|
28
|
-
isEnabled: record.is_enabled,
|
|
29
|
-
strategySubHash: record.sub_data_hash,
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
exports.parseDataFromApiSubscription = parseDataFromApiSubscription;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '../configuration';
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const chai_1 = require("chai");
|
|
4
|
-
const enums_1 = require("../types/enums");
|
|
5
|
-
require("../configuration");
|
|
6
|
-
const apiSubscriptionsService_1 = require("./apiSubscriptionsService");
|
|
7
|
-
const strategiesService_1 = require("./strategiesService");
|
|
8
|
-
describe('Feature: apiSubscriptionsService.ts', () => {
|
|
9
|
-
describe('When testing apiSubscriptionsService.parseDataFromApiSubscription', () => {
|
|
10
|
-
// same subscription as in strategiesService.test.ts, in the shape the automation API returns it
|
|
11
|
-
const record = {
|
|
12
|
-
id: 379,
|
|
13
|
-
wallet: '0x9cB7E19861665366011899d74E75d4F2A419aEeD',
|
|
14
|
-
wallet_type: 'safe',
|
|
15
|
-
is_enabled: true,
|
|
16
|
-
is_bundle: true,
|
|
17
|
-
strategy_or_bundle_id: 8,
|
|
18
|
-
strategy_ids: [34, 35],
|
|
19
|
-
sub_data_hash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
|
|
20
|
-
trigger_data: [
|
|
21
|
-
'0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000019ac8532c27900000000000000000000000000000000000000000000000000000000000000000001',
|
|
22
|
-
],
|
|
23
|
-
sub_data: [
|
|
24
|
-
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
25
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
26
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
27
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
28
|
-
],
|
|
29
|
-
block_number: 18015756,
|
|
30
|
-
additional_triggers: null,
|
|
31
|
-
};
|
|
32
|
-
const fromEvents = {
|
|
33
|
-
chainId: enums_1.ChainId.Ethereum,
|
|
34
|
-
blockNumber: 18015756,
|
|
35
|
-
subscriptionEventData: {
|
|
36
|
-
subId: '379',
|
|
37
|
-
proxy: '0x9cB7E19861665366011899d74E75d4F2A419aEeD',
|
|
38
|
-
subHash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
|
|
39
|
-
subStruct: {
|
|
40
|
-
strategyOrBundleId: '8',
|
|
41
|
-
isBundle: true,
|
|
42
|
-
triggerData: [
|
|
43
|
-
'0x0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000019ac8532c27900000000000000000000000000000000000000000000000000000000000000000001',
|
|
44
|
-
],
|
|
45
|
-
subData: record.sub_data,
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
strategiesSubsData: {
|
|
49
|
-
userProxy: '0x9cB7E19861665366011899d74E75d4F2A419aEeD',
|
|
50
|
-
isEnabled: true,
|
|
51
|
-
strategySubHash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
it('Given an API record should return the same parse data as Subscribe event and SubStorage would', () => {
|
|
55
|
-
(0, chai_1.expect)((0, apiSubscriptionsService_1.parseDataFromApiSubscription)(record, enums_1.ChainId.Ethereum)).to.eql(fromEvents);
|
|
56
|
-
});
|
|
57
|
-
it('Given an API record the parsed position should match the one parsed from events', () => {
|
|
58
|
-
const fromApi = (0, strategiesService_1.parseStrategiesAutomatedPosition)((0, apiSubscriptionsService_1.parseDataFromApiSubscription)(record, enums_1.ChainId.Ethereum));
|
|
59
|
-
(0, chai_1.expect)(fromApi).to.not.equal(null);
|
|
60
|
-
(0, chai_1.expect)(fromApi).to.eql((0, strategiesService_1.parseStrategiesAutomatedPosition)(fromEvents));
|
|
61
|
-
});
|
|
62
|
-
it('Given a disabled record should keep it disabled', () => {
|
|
63
|
-
const parseData = (0, apiSubscriptionsService_1.parseDataFromApiSubscription)(Object.assign(Object.assign({}, record), { is_enabled: false }), enums_1.ChainId.Ethereum);
|
|
64
|
-
(0, chai_1.expect)(parseData.strategiesSubsData.isEnabled).to.equal(false);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
});
|
|
@@ -1,7 +0,0 @@
|
|
|
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;
|
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '../configuration';
|
|
@@ -1,65 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
|
|
3
|
-
import type { ApiSubscriptionRecord, ParseData } from '../types';
|
|
4
|
-
import { ChainId } from '../types/enums';
|
|
5
|
-
|
|
6
|
-
import '../configuration';
|
|
7
|
-
import { parseDataFromApiSubscription } from './apiSubscriptionsService';
|
|
8
|
-
import { parseStrategiesAutomatedPosition } from './strategiesService';
|
|
9
|
-
|
|
10
|
-
describe('Feature: apiSubscriptionsService.ts', () => {
|
|
11
|
-
describe('When testing apiSubscriptionsService.parseDataFromApiSubscription', () => {
|
|
12
|
-
// same subscription as in strategiesService.test.ts, in the shape the automation API returns it
|
|
13
|
-
const record: ApiSubscriptionRecord = {
|
|
14
|
-
id: 379,
|
|
15
|
-
wallet: '0x9cB7E19861665366011899d74E75d4F2A419aEeD',
|
|
16
|
-
wallet_type: 'safe',
|
|
17
|
-
is_enabled: true,
|
|
18
|
-
is_bundle: true,
|
|
19
|
-
strategy_or_bundle_id: 8,
|
|
20
|
-
strategy_ids: [34, 35],
|
|
21
|
-
sub_data_hash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
|
|
22
|
-
trigger_data: [
|
|
23
|
-
'0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000019ac8532c27900000000000000000000000000000000000000000000000000000000000000000001',
|
|
24
|
-
],
|
|
25
|
-
sub_data: [
|
|
26
|
-
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
27
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
28
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
29
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
30
|
-
],
|
|
31
|
-
block_number: 18015756,
|
|
32
|
-
additional_triggers: null,
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const fromEvents: ParseData = {
|
|
36
|
-
chainId: ChainId.Ethereum,
|
|
37
|
-
blockNumber: 18015756,
|
|
38
|
-
subscriptionEventData: {
|
|
39
|
-
subId: '379',
|
|
40
|
-
proxy: '0x9cB7E19861665366011899d74E75d4F2A419aEeD',
|
|
41
|
-
subHash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
|
|
42
|
-
subStruct: {
|
|
43
|
-
strategyOrBundleId: '8',
|
|
44
|
-
isBundle: true,
|
|
45
|
-
triggerData: [
|
|
46
|
-
'0x0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000019ac8532c27900000000000000000000000000000000000000000000000000000000000000000001',
|
|
47
|
-
],
|
|
48
|
-
subData: record.sub_data,
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
strategiesSubsData: {
|
|
52
|
-
userProxy: '0x9cB7E19861665366011899d74E75d4F2A419aEeD',
|
|
53
|
-
isEnabled: true,
|
|
54
|
-
strategySubHash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
it('Given an API record should return the same parse data as Subscribe event and SubStorage would', () => {
|
|
59
|
-
expect(parseDataFromApiSubscription(record, ChainId.Ethereum)).to.eql(fromEvents);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('Given an API record the parsed position should match the one parsed from events', () => {
|
|
63
|
-
const fromApi = parseStrategiesAutomatedPosition(parseDataFromApiSubscription(record, ChainId.Ethereum));
|
|
64
|
-
expect(fromApi).to.not.equal(null);
|
|
65
|
-
expect(fromApi).to.eql(parseStrategiesAutomatedPosition(fromEvents));
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('Given a disabled record should keep it disabled', () => {
|
|
69
|
-
const parseData = parseDataFromApiSubscription({ ...record, is_enabled: false }, ChainId.Ethereum);
|
|
70
|
-
expect(parseData.strategiesSubsData.isEnabled).to.equal(false);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { ApiSubscriptionRecord, ParseData } from '../types';
|
|
2
|
-
import type { ChainId } from '../types/enums';
|
|
3
|
-
|
|
4
|
-
function addHexPrefix(value: string): string {
|
|
5
|
-
return value.startsWith('0x') ? value : `0x${value}`;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @description Maps a subscription record returned by the automation API to the data
|
|
10
|
-
* the parser expects from Subscribe events and SubStorage (trigger data is stored without 0x prefix)
|
|
11
|
-
*/
|
|
12
|
-
export function parseDataFromApiSubscription(record: ApiSubscriptionRecord, chainId: ChainId): ParseData {
|
|
13
|
-
return {
|
|
14
|
-
chainId,
|
|
15
|
-
blockNumber: record.block_number,
|
|
16
|
-
subscriptionEventData: {
|
|
17
|
-
subId: record.id.toString(),
|
|
18
|
-
proxy: record.wallet,
|
|
19
|
-
subHash: record.sub_data_hash,
|
|
20
|
-
subStruct: {
|
|
21
|
-
strategyOrBundleId: record.strategy_or_bundle_id.toString(),
|
|
22
|
-
isBundle: record.is_bundle,
|
|
23
|
-
triggerData: record.trigger_data.map(addHexPrefix),
|
|
24
|
-
subData: record.sub_data.map(addHexPrefix),
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
strategiesSubsData: {
|
|
28
|
-
userProxy: record.wallet,
|
|
29
|
-
isEnabled: record.is_enabled,
|
|
30
|
-
strategySubHash: record.sub_data_hash,
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
}
|