@defisaver/automation-sdk 3.1.4 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.env ADDED
@@ -0,0 +1,5 @@
1
+ # Used for testing
2
+ RPC_1=https://eth-mainnet.g.alchemy.com/v2/4jm0fn2xvapd3pDpmdE8Y1rZKEp71U0Y
3
+ RPC_10=https://opt-mainnet.g.alchemy.com/v2/4jm0fn2xvapd3pDpmdE8Y1rZKEp71U0Y
4
+ RPC_42161=https://arb-mainnet.g.alchemy.com/v2/4jm0fn2xvapd3pDpmdE8Y1rZKEp71U0Y
5
+ RPC_8453=https://base-mainnet.g.alchemy.com/v2/4jm0fn2xvapd3pDpmdE8Y1rZKEp71U0Y
@@ -1,24 +1,24 @@
1
1
  import type Web3 from 'web3';
2
2
  import type { PastEventOptions } from 'web3-eth-contract';
3
3
  import type { Position, Interfaces, EthereumAddress, SubscriptionOptions, Contract, ParseData, BlockNumber } from '../../types';
4
- import type { StrategyModel, SubStorage } from '../../types/contracts/generated/SubStorage';
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';
7
7
  interface IStrategiesAutomation extends Interfaces.Automation {
8
8
  chainId: ChainId;
9
- providerFork: Web3;
9
+ providerFork?: Web3;
10
10
  }
11
11
  export default class StrategiesAutomation extends Automation {
12
12
  protected chainId: ChainId;
13
13
  protected web3: Web3;
14
- protected web3Fork: Web3;
14
+ protected web3Fork?: Web3;
15
15
  protected subStorageContract: Contract.WithMeta<SubStorage>;
16
16
  protected subStorageContractFork: Contract.WithMeta<SubStorage> | null;
17
17
  constructor(args: IStrategiesAutomation);
18
18
  protected getEventFromSubStorage(event: string, options?: PastEventOptions): Promise<any[]>;
19
19
  protected getStrategiesSubs(subIds: number[], fromBlock?: BlockNumber): Promise<StrategyModel.StoredSubDataStructOutputStruct[]>;
20
- protected getSubscriptionEventsFromSubStorage(options?: PastEventOptions): Promise<any[]>;
21
- protected getUpdateDataEventsFromSubStorage(options?: PastEventOptions): Promise<any[]>;
20
+ protected getSubscriptionEventsFromSubStorage(options?: PastEventOptions): Promise<Subscribe[]>;
21
+ protected getUpdateDataEventsFromSubStorage(options?: PastEventOptions): Promise<UpdateData[]>;
22
22
  protected getParsedSubscriptions(parseData: ParseData): Position.Automated | null;
23
23
  /**
24
24
  * @description Removes expired Limit Order subscriptions
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const decimal_js_1 = __importDefault(require("decimal.js"));
16
+ const es6_promise_pool_1 = __importDefault(require("es6-promise-pool"));
16
17
  const enums_1 = require("../../types/enums");
17
18
  const utils_1 = require("../../services/utils");
18
19
  const contractService_1 = require("../../services/contractService");
@@ -133,10 +134,10 @@ class StrategiesAutomation extends Automation_1.default {
133
134
  _getSubscriptions(addresses, options) {
134
135
  return __awaiter(this, void 0, void 0, function* () {
135
136
  const _options = Object.assign(Object.assign({}, (0, utils_1.addToObjectIf)((0, utils_1.isDefined)(options), options)), (0, utils_1.addToObjectIf)((0, utils_1.isDefined)(addresses), { filter: { proxy: addresses } }));
136
- let subscriptionEvents = (yield this.getSubscriptionEventsFromSubStorage(_options)); // TODO PlaceholderType
137
+ let subscriptionEvents = yield this.getSubscriptionEventsFromSubStorage(_options);
137
138
  let subscriptions = [];
138
139
  if (subscriptionEvents) {
139
- let strategiesSubs = yield this.getStrategiesSubs(subscriptionEvents.map((e) => e.returnValues.subId), _options.toBlock);
140
+ let strategiesSubs = yield this.getStrategiesSubs(subscriptionEvents.map((e) => +e.returnValues.subId), _options.toBlock);
140
141
  if (_options.enabledOnly) {
141
142
  const filteredSubscriptionEvents = [];
142
143
  strategiesSubs = strategiesSubs.filter((sub, index) => {
@@ -146,20 +147,28 @@ class StrategiesAutomation extends Automation_1.default {
146
147
  });
147
148
  subscriptionEvents = filteredSubscriptionEvents;
148
149
  }
149
- subscriptions = yield Promise.all(strategiesSubs.map((sub, index) => __awaiter(this, void 0, void 0, function* () {
150
+ const replaceSubWithUpdate = (index) => __awaiter(this, void 0, void 0, function* () {
150
151
  var _a;
152
+ const sub = strategiesSubs[index];
151
153
  let latestUpdate = subscriptionEvents[index].returnValues;
152
154
  if (latestUpdate.subHash !== (sub === null || sub === void 0 ? void 0 : sub.strategySubHash)) {
153
155
  const updates = yield this.getUpdateDataEventsFromSubStorage(Object.assign(Object.assign({}, (0, utils_1.addToObjectIf)(!!_options, _options)), { filter: { subId: latestUpdate.subId } }));
154
156
  latestUpdate = Object.assign(Object.assign({}, latestUpdate), (_a = updates === null || updates === void 0 ? void 0 : updates[updates.length - 1]) === null || _a === void 0 ? void 0 : _a.returnValues);
155
157
  }
156
- return this.getParsedSubscriptions({
158
+ subscriptions.push(this.getParsedSubscriptions({
157
159
  chainId: this.chainId,
158
160
  blockNumber: subscriptionEvents[index].blockNumber,
159
161
  subscriptionEventData: latestUpdate,
160
162
  strategiesSubsData: sub,
161
- });
162
- })));
163
+ }));
164
+ });
165
+ const generatePromises = function* () {
166
+ for (let index = 0; index < strategiesSubs.length; index++) {
167
+ yield replaceSubWithUpdate(index);
168
+ }
169
+ };
170
+ const pool = new es6_promise_pool_1.default(generatePromises, 50);
171
+ yield pool.start();
163
172
  if (options === null || options === void 0 ? void 0 : options.mergeSubs) {
164
173
  subscriptions = this.mergeSubs(subscriptions);
165
174
  }
@@ -0,0 +1 @@
1
+ import '../../configuration';
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const web3_1 = __importDefault(require("web3"));
16
+ require("../../configuration");
17
+ const EthereumStrategies_1 = __importDefault(require("./EthereumStrategies"));
18
+ const ArbitrumStrategies_1 = __importDefault(require("./ArbitrumStrategies"));
19
+ const OptimismStrategies_1 = __importDefault(require("./OptimismStrategies"));
20
+ const BaseStrategies_1 = __importDefault(require("./BaseStrategies"));
21
+ require('dotenv').config({ path: '.env' });
22
+ const Web3_1 = new web3_1.default(process.env.RPC_1);
23
+ const Web3_42161 = new web3_1.default(process.env.RPC_42161);
24
+ const Web3_10 = new web3_1.default(process.env.RPC_10);
25
+ const Web3_8453 = new web3_1.default(process.env.RPC_8453);
26
+ describe('Feature: StrategiesAutomation.ts', () => {
27
+ describe('Fetching subscriptions', () => {
28
+ it('can fetch subscriptions on Mainnet', function () {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ this.timeout(120000);
31
+ const ethStrategies = new EthereumStrategies_1.default({ provider: Web3_1 });
32
+ const subs = yield ethStrategies.getSubscriptions({ mergeSubs: true });
33
+ console.log(subs.length);
34
+ });
35
+ });
36
+ it('can fetch subscriptions on Arbitrum', function () {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ this.timeout(120000);
39
+ const arbiStrategies = new ArbitrumStrategies_1.default({ provider: Web3_42161 });
40
+ const subs = yield arbiStrategies.getSubscriptions({ mergeSubs: true });
41
+ console.log(subs.length);
42
+ });
43
+ });
44
+ it('can fetch subscriptions on Optimism', function () {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ this.timeout(120000);
47
+ const optimismStrategies = new OptimismStrategies_1.default({ provider: Web3_10 });
48
+ const subs = yield optimismStrategies.getSubscriptions({ mergeSubs: true });
49
+ console.log(subs.length);
50
+ });
51
+ });
52
+ it('can fetch subscriptions on Base', function () {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ this.timeout(120000);
55
+ const baseStrategies = new BaseStrategies_1.default({ provider: Web3_8453 });
56
+ const subs = yield baseStrategies.getSubscriptions({ mergeSubs: true });
57
+ console.log(subs.length);
58
+ });
59
+ });
60
+ });
61
+ });
@@ -55,10 +55,6 @@ export type Subscribe = ContractEventLog<{
55
55
  proxy: string;
56
56
  subHash: string;
57
57
  subStruct: StrategyModel.StrategySubStructOutput;
58
- 0: string;
59
- 1: string;
60
- 2: string;
61
- 3: StrategyModel.StrategySubStructOutput;
62
58
  }>;
63
59
  export type UpdateData = ContractEventLog<{
64
60
  subId: string;
@@ -69,7 +69,7 @@ export declare namespace Interfaces {
69
69
  }
70
70
  interface Automation {
71
71
  provider: Web3;
72
- providerFork: Web3;
72
+ providerFork?: Web3;
73
73
  }
74
74
  interface LegacyAutomation<T extends BaseContract> {
75
75
  provider: Web3;
@@ -1,24 +1,24 @@
1
1
  import type Web3 from 'web3';
2
2
  import type { PastEventOptions } from 'web3-eth-contract';
3
3
  import type { Position, Interfaces, EthereumAddress, SubscriptionOptions, Contract, ParseData, BlockNumber } from '../../types';
4
- import type { StrategyModel, SubStorage } from '../../types/contracts/generated/SubStorage';
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';
7
7
  interface IStrategiesAutomation extends Interfaces.Automation {
8
8
  chainId: ChainId;
9
- providerFork: Web3;
9
+ providerFork?: Web3;
10
10
  }
11
11
  export default class StrategiesAutomation extends Automation {
12
12
  protected chainId: ChainId;
13
13
  protected web3: Web3;
14
- protected web3Fork: Web3;
14
+ protected web3Fork?: Web3;
15
15
  protected subStorageContract: Contract.WithMeta<SubStorage>;
16
16
  protected subStorageContractFork: Contract.WithMeta<SubStorage> | null;
17
17
  constructor(args: IStrategiesAutomation);
18
18
  protected getEventFromSubStorage(event: string, options?: PastEventOptions): Promise<any[]>;
19
19
  protected getStrategiesSubs(subIds: number[], fromBlock?: BlockNumber): Promise<StrategyModel.StoredSubDataStructOutputStruct[]>;
20
- protected getSubscriptionEventsFromSubStorage(options?: PastEventOptions): Promise<any[]>;
21
- protected getUpdateDataEventsFromSubStorage(options?: PastEventOptions): Promise<any[]>;
20
+ protected getSubscriptionEventsFromSubStorage(options?: PastEventOptions): Promise<Subscribe[]>;
21
+ protected getUpdateDataEventsFromSubStorage(options?: PastEventOptions): Promise<UpdateData[]>;
22
22
  protected getParsedSubscriptions(parseData: ParseData): Position.Automated | null;
23
23
  /**
24
24
  * @description Removes expired Limit Order subscriptions
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import Dec from 'decimal.js';
11
+ import PromisePool from 'es6-promise-pool';
11
12
  import { Strategies, ProtocolIdentifiers } from '../../types/enums';
12
13
  import { addToObjectIf, isDefined, isUndefined } from '../../services/utils';
13
14
  import { getAbiItem, makeSubStorageContract } from '../../services/contractService';
@@ -128,10 +129,10 @@ export default class StrategiesAutomation extends Automation {
128
129
  _getSubscriptions(addresses, options) {
129
130
  return __awaiter(this, void 0, void 0, function* () {
130
131
  const _options = Object.assign(Object.assign({}, addToObjectIf(isDefined(options), options)), addToObjectIf(isDefined(addresses), { filter: { proxy: addresses } }));
131
- let subscriptionEvents = (yield this.getSubscriptionEventsFromSubStorage(_options)); // TODO PlaceholderType
132
+ let subscriptionEvents = yield this.getSubscriptionEventsFromSubStorage(_options);
132
133
  let subscriptions = [];
133
134
  if (subscriptionEvents) {
134
- let strategiesSubs = yield this.getStrategiesSubs(subscriptionEvents.map((e) => e.returnValues.subId), _options.toBlock);
135
+ let strategiesSubs = yield this.getStrategiesSubs(subscriptionEvents.map((e) => +e.returnValues.subId), _options.toBlock);
135
136
  if (_options.enabledOnly) {
136
137
  const filteredSubscriptionEvents = [];
137
138
  strategiesSubs = strategiesSubs.filter((sub, index) => {
@@ -141,20 +142,28 @@ export default class StrategiesAutomation extends Automation {
141
142
  });
142
143
  subscriptionEvents = filteredSubscriptionEvents;
143
144
  }
144
- subscriptions = yield Promise.all(strategiesSubs.map((sub, index) => __awaiter(this, void 0, void 0, function* () {
145
+ const replaceSubWithUpdate = (index) => __awaiter(this, void 0, void 0, function* () {
145
146
  var _a;
147
+ const sub = strategiesSubs[index];
146
148
  let latestUpdate = subscriptionEvents[index].returnValues;
147
149
  if (latestUpdate.subHash !== (sub === null || sub === void 0 ? void 0 : sub.strategySubHash)) {
148
150
  const updates = yield this.getUpdateDataEventsFromSubStorage(Object.assign(Object.assign({}, addToObjectIf(!!_options, _options)), { filter: { subId: latestUpdate.subId } }));
149
151
  latestUpdate = Object.assign(Object.assign({}, latestUpdate), (_a = updates === null || updates === void 0 ? void 0 : updates[updates.length - 1]) === null || _a === void 0 ? void 0 : _a.returnValues);
150
152
  }
151
- return this.getParsedSubscriptions({
153
+ subscriptions.push(this.getParsedSubscriptions({
152
154
  chainId: this.chainId,
153
155
  blockNumber: subscriptionEvents[index].blockNumber,
154
156
  subscriptionEventData: latestUpdate,
155
157
  strategiesSubsData: sub,
156
- });
157
- })));
158
+ }));
159
+ });
160
+ const generatePromises = function* () {
161
+ for (let index = 0; index < strategiesSubs.length; index++) {
162
+ yield replaceSubWithUpdate(index);
163
+ }
164
+ };
165
+ const pool = new PromisePool(generatePromises, 50);
166
+ yield pool.start();
158
167
  if (options === null || options === void 0 ? void 0 : options.mergeSubs) {
159
168
  subscriptions = this.mergeSubs(subscriptions);
160
169
  }
@@ -0,0 +1 @@
1
+ import '../../configuration';
@@ -0,0 +1,56 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import Web3 from 'web3';
11
+ import '../../configuration';
12
+ import EthereumStrategies from './EthereumStrategies';
13
+ import ArbitrumStrategies from './ArbitrumStrategies';
14
+ import OptimismStrategies from './OptimismStrategies';
15
+ import BaseStrategies from './BaseStrategies';
16
+ require('dotenv').config({ path: '.env' });
17
+ const Web3_1 = new Web3(process.env.RPC_1);
18
+ const Web3_42161 = new Web3(process.env.RPC_42161);
19
+ const Web3_10 = new Web3(process.env.RPC_10);
20
+ const Web3_8453 = new Web3(process.env.RPC_8453);
21
+ describe('Feature: StrategiesAutomation.ts', () => {
22
+ describe('Fetching subscriptions', () => {
23
+ it('can fetch subscriptions on Mainnet', function () {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ this.timeout(120000);
26
+ const ethStrategies = new EthereumStrategies({ provider: Web3_1 });
27
+ const subs = yield ethStrategies.getSubscriptions({ mergeSubs: true });
28
+ console.log(subs.length);
29
+ });
30
+ });
31
+ it('can fetch subscriptions on Arbitrum', function () {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ this.timeout(120000);
34
+ const arbiStrategies = new ArbitrumStrategies({ provider: Web3_42161 });
35
+ const subs = yield arbiStrategies.getSubscriptions({ mergeSubs: true });
36
+ console.log(subs.length);
37
+ });
38
+ });
39
+ it('can fetch subscriptions on Optimism', function () {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ this.timeout(120000);
42
+ const optimismStrategies = new OptimismStrategies({ provider: Web3_10 });
43
+ const subs = yield optimismStrategies.getSubscriptions({ mergeSubs: true });
44
+ console.log(subs.length);
45
+ });
46
+ });
47
+ it('can fetch subscriptions on Base', function () {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ this.timeout(120000);
50
+ const baseStrategies = new BaseStrategies({ provider: Web3_8453 });
51
+ const subs = yield baseStrategies.getSubscriptions({ mergeSubs: true });
52
+ console.log(subs.length);
53
+ });
54
+ });
55
+ });
56
+ });
@@ -55,10 +55,6 @@ export type Subscribe = ContractEventLog<{
55
55
  proxy: string;
56
56
  subHash: string;
57
57
  subStruct: StrategyModel.StrategySubStructOutput;
58
- 0: string;
59
- 1: string;
60
- 2: string;
61
- 3: StrategyModel.StrategySubStructOutput;
62
58
  }>;
63
59
  export type UpdateData = ContractEventLog<{
64
60
  subId: string;
@@ -69,7 +69,7 @@ export declare namespace Interfaces {
69
69
  }
70
70
  interface Automation {
71
71
  provider: Web3;
72
- providerFork: Web3;
72
+ providerFork?: Web3;
73
73
  }
74
74
  interface LegacyAutomation<T extends BaseContract> {
75
75
  provider: Web3;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "3.1.4",
3
+ "version": "3.2.0",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -29,6 +29,7 @@
29
29
  "@ethersproject/address": "^5.0.10",
30
30
  "@ethersproject/solidity": "^5.0.9",
31
31
  "decimal.js": "^10.4.3",
32
+ "es6-promise-pool": "^2.5.0",
32
33
  "lodash": "^4.17.21",
33
34
  "web3-eth-abi": "^1.10.2",
34
35
  "web3-utils": "^1.10.2"
@@ -1,11 +1,12 @@
1
1
  import Dec from 'decimal.js';
2
2
  import type Web3 from 'web3';
3
3
  import type { PastEventOptions } from 'web3-eth-contract';
4
+ import PromisePool from 'es6-promise-pool';
4
5
  import type {
5
6
  Position, Interfaces, EthereumAddress, SubscriptionOptions, Contract, ParseData, PlaceholderType, BlockNumber,
6
7
  } from '../../types';
7
8
  import type {
8
- StrategyModel, SubStorage,
9
+ StrategyModel, Subscribe, SubStorage, UpdateData,
9
10
  } from '../../types/contracts/generated/SubStorage';
10
11
  import type { ChainId } from '../../types/enums';
11
12
  import { Strategies, ProtocolIdentifiers } from '../../types/enums';
@@ -19,7 +20,7 @@ import Automation from './Automation';
19
20
 
20
21
  interface IStrategiesAutomation extends Interfaces.Automation {
21
22
  chainId: ChainId,
22
- providerFork: Web3,
23
+ providerFork?: Web3,
23
24
  }
24
25
 
25
26
  export default class StrategiesAutomation extends Automation {
@@ -27,7 +28,7 @@ export default class StrategiesAutomation extends Automation {
27
28
 
28
29
  protected web3: Web3;
29
30
 
30
- protected web3Fork: Web3;
31
+ protected web3Fork?: Web3;
31
32
 
32
33
  protected subStorageContract: Contract.WithMeta<SubStorage>;
33
34
 
@@ -77,13 +78,13 @@ export default class StrategiesAutomation extends Automation {
77
78
  }
78
79
 
79
80
  protected async getSubscriptionEventsFromSubStorage(options?: PastEventOptions) {
80
- return this.getEventFromSubStorage('Subscribe', options);
81
+ return this.getEventFromSubStorage('Subscribe', options) as Promise<Subscribe[]>;
81
82
  }
82
83
 
83
84
  protected async getUpdateDataEventsFromSubStorage(options?: PastEventOptions) {
84
85
  const events = await this.getEventFromSubStorage('UpdateData', options);
85
86
  /** @dev - Some RPCs sort events differently */
86
- return events.sort((a, b) => a.blockNumber - b.blockNumber);
87
+ return events.sort((a, b) => a.blockNumber - b.blockNumber) as UpdateData[];
87
88
  }
88
89
 
89
90
  protected getParsedSubscriptions(parseData: ParseData) {
@@ -183,13 +184,13 @@ export default class StrategiesAutomation extends Automation {
183
184
  ...addToObjectIf(isDefined(addresses), { filter: { proxy: addresses } }),
184
185
  } as SubscriptionOptions & PastEventOptions;
185
186
 
186
- let subscriptionEvents = (await this.getSubscriptionEventsFromSubStorage(_options)) as PlaceholderType; // TODO PlaceholderType
187
+ let subscriptionEvents = await this.getSubscriptionEventsFromSubStorage(_options);
187
188
 
188
189
  let subscriptions: (Position.Automated | null)[] = [];
189
190
 
190
191
  if (subscriptionEvents) {
191
192
  let strategiesSubs = await this.getStrategiesSubs(
192
- subscriptionEvents.map((e: { returnValues: { subId: number } }) => e.returnValues.subId), _options.toBlock,
193
+ subscriptionEvents.map((e) => +e.returnValues.subId), _options.toBlock,
193
194
  );
194
195
 
195
196
  if (_options.enabledOnly) {
@@ -203,7 +204,8 @@ export default class StrategiesAutomation extends Automation {
203
204
  subscriptionEvents = filteredSubscriptionEvents;
204
205
  }
205
206
 
206
- subscriptions = await Promise.all(strategiesSubs.map(async (sub, index: number) => {
207
+ const replaceSubWithUpdate = async (index: number) => {
208
+ const sub = strategiesSubs[index];
207
209
  let latestUpdate = subscriptionEvents[index].returnValues;
208
210
 
209
211
  if (latestUpdate.subHash !== sub?.strategySubHash) {
@@ -216,13 +218,23 @@ export default class StrategiesAutomation extends Automation {
216
218
  ...updates?.[updates.length - 1]?.returnValues,
217
219
  };
218
220
  }
219
- return this.getParsedSubscriptions({
220
- chainId: this.chainId,
221
- blockNumber: subscriptionEvents[index].blockNumber,
222
- subscriptionEventData: latestUpdate,
223
- strategiesSubsData: sub,
224
- });
225
- }));
221
+ subscriptions.push(
222
+ this.getParsedSubscriptions({
223
+ chainId: this.chainId,
224
+ blockNumber: subscriptionEvents[index].blockNumber,
225
+ subscriptionEventData: latestUpdate,
226
+ strategiesSubsData: sub,
227
+ }),
228
+ );
229
+ };
230
+
231
+ const generatePromises = function* () {
232
+ for (let index = 0; index < strategiesSubs.length; index++) {
233
+ yield replaceSubWithUpdate(index);
234
+ }
235
+ };
236
+ const pool = new PromisePool(generatePromises as any, 50);
237
+ await pool.start();
226
238
 
227
239
  if (options?.mergeSubs) {
228
240
  subscriptions = this.mergeSubs(subscriptions);
@@ -0,0 +1,49 @@
1
+ import Web3 from 'web3';
2
+ import { expect } from 'chai';
3
+
4
+ import {ChainId} from '../../types/enums';
5
+
6
+ import '../../configuration';
7
+ import EthereumStrategies from './EthereumStrategies';
8
+ import ArbitrumStrategies from './ArbitrumStrategies';
9
+ import OptimismStrategies from './OptimismStrategies';
10
+ import BaseStrategies from './BaseStrategies';
11
+
12
+ require('dotenv').config({ path: '.env' });
13
+
14
+ const Web3_1 = new Web3(process.env.RPC_1!);
15
+ const Web3_42161 = new Web3(process.env.RPC_42161!);
16
+ const Web3_10 = new Web3(process.env.RPC_10!);
17
+ const Web3_8453 = new Web3(process.env.RPC_8453!);
18
+
19
+ describe('Feature: StrategiesAutomation.ts', () => {
20
+ describe('Fetching subscriptions', () => {
21
+ it('can fetch subscriptions on Mainnet', async function () {
22
+ this.timeout(120000);
23
+ const ethStrategies = new EthereumStrategies({provider: Web3_1});
24
+ const subs = await ethStrategies.getSubscriptions({mergeSubs: true})
25
+ console.log(subs.length);
26
+ });
27
+
28
+ it('can fetch subscriptions on Arbitrum', async function () {
29
+ this.timeout(120000);
30
+ const arbiStrategies = new ArbitrumStrategies({provider: Web3_42161});
31
+ const subs = await arbiStrategies.getSubscriptions({mergeSubs: true})
32
+ console.log(subs.length);
33
+ });
34
+
35
+ it('can fetch subscriptions on Optimism', async function () {
36
+ this.timeout(120000);
37
+ const optimismStrategies = new OptimismStrategies({provider: Web3_10});
38
+ const subs = await optimismStrategies.getSubscriptions({mergeSubs: true})
39
+ console.log(subs.length);
40
+ });
41
+
42
+ it('can fetch subscriptions on Base', async function () {
43
+ this.timeout(120000);
44
+ const baseStrategies = new BaseStrategies({provider: Web3_8453});
45
+ const subs = await baseStrategies.getSubscriptions({mergeSubs: true})
46
+ console.log(subs.length);
47
+ });
48
+ });
49
+ });
@@ -90,7 +90,7 @@ export declare namespace Interfaces {
90
90
 
91
91
  interface Automation {
92
92
  provider: Web3,
93
- providerFork: Web3,
93
+ providerFork?: Web3,
94
94
  }
95
95
  interface LegacyAutomation<T extends BaseContract> {
96
96
  provider: Web3,