@defisaver/automation-sdk 2.0.2 → 2.0.3

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.
Files changed (53) hide show
  1. package/.eslintrc.js +1 -0
  2. package/esm/abis/index.js +27 -15
  3. package/esm/automation/private/Automation.js +9 -6
  4. package/esm/automation/private/LegacyAutomation.d.ts +5 -5
  5. package/esm/automation/private/LegacyAutomation.js +30 -23
  6. package/esm/automation/private/LegacyProtocol.js +4 -1
  7. package/esm/automation/private/Protocol.js +4 -1
  8. package/esm/automation/private/StrategiesAutomation.d.ts +2 -2
  9. package/esm/automation/private/StrategiesAutomation.js +27 -21
  10. package/esm/automation/public/ArbitrumStrategies.js +10 -4
  11. package/esm/automation/public/EthereumStrategies.js +10 -4
  12. package/esm/automation/public/OptimismStrategies.js +10 -4
  13. package/esm/automation/public/legacy/LegacyAaveAutomation.js +13 -7
  14. package/esm/automation/public/legacy/LegacyCompoundAutomation.js +13 -7
  15. package/esm/automation/public/legacy/LegacyMakerAutomation.js +13 -7
  16. package/esm/configuration.js +8 -5
  17. package/esm/constants/index.js +281 -275
  18. package/esm/index.js +57 -17
  19. package/esm/services/contractService.js +22 -14
  20. package/esm/services/ethereumService.js +18 -10
  21. package/esm/services/strategiesService.js +130 -103
  22. package/esm/services/strategySubService.js +90 -61
  23. package/esm/services/subDataService.js +151 -145
  24. package/esm/services/triggerService.d.ts +5 -5
  25. package/esm/services/triggerService.js +124 -94
  26. package/esm/services/utils.js +82 -33
  27. package/esm/services/utils.test.d.ts +1 -0
  28. package/esm/services/utils.test.js +362 -0
  29. package/esm/types/contracts/generated/Erc20.js +2 -1
  30. package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.js +2 -1
  31. package/esm/types/contracts/generated/Legacy_AuthCheck.js +2 -1
  32. package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +2 -1
  33. package/esm/types/contracts/generated/Legacy_MakerSubscriptions.js +2 -1
  34. package/esm/types/contracts/generated/SubStorage.js +2 -1
  35. package/esm/types/contracts/generated/UniMulticall.js +2 -1
  36. package/esm/types/contracts/generated/index.js +2 -1
  37. package/esm/types/contracts/generated/types.js +2 -1
  38. package/esm/types/enums.js +17 -14
  39. package/esm/types/index.js +2 -1
  40. package/package.json +11 -7
  41. package/src/automation/private/LegacyAutomation.ts +11 -10
  42. package/src/automation/private/StrategiesAutomation.ts +5 -6
  43. package/src/configuration.ts +0 -3
  44. package/src/index.ts +0 -1
  45. package/src/services/ethereumService.ts +6 -6
  46. package/src/services/subDataService.ts +75 -76
  47. package/src/services/triggerService.ts +83 -83
  48. package/src/services/utils.test.ts +414 -0
  49. package/src/services/utils.ts +6 -7
  50. package/tsconfig.json +1 -1
  51. package/umd/index.js +7016 -4105
  52. package/src/types/typings/process.d.ts +0 -9
  53. package/yarn-error.log +0 -7233
package/.eslintrc.js CHANGED
@@ -6,6 +6,7 @@ module.exports = {
6
6
  es6: true,
7
7
  browser: true,
8
8
  },
9
+ ignorePatterns: ['*.test.ts'],
9
10
  overrides: [{
10
11
  // these are overrides for .ts files, meaning these are only applied to .ts files
11
12
  files: ['*.ts'],
package/esm/abis/index.js CHANGED
@@ -1,18 +1,30 @@
1
- import MakerSubscriptions from './legacy_MakerSubscriptions.json';
2
- import AaveV2Subscriptions from './legacy_AaveV2Subscriptions.json';
3
- import CompoundV2Subscriptions from './legacy_CompoundV2Subscriptions.json';
4
- import Erc20 from './Erc20.json';
5
- import UniMulticall from './UniMulticall.json';
6
- import SubStorage from './SubStorage.json';
7
- import AuthCheck from './legacy_AuthCheck.json';
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AuthCheckJson = exports.SubStorageJson = exports.UniMulticallJson = exports.Erc20Json = exports.CompoundV2SubscriptionsJson = exports.AaveV2SubscriptionsJson = exports.MakerSubscriptionsJson = void 0;
7
+ const legacy_MakerSubscriptions_json_1 = __importDefault(require("./legacy_MakerSubscriptions.json"));
8
+ const legacy_AaveV2Subscriptions_json_1 = __importDefault(require("./legacy_AaveV2Subscriptions.json"));
9
+ const legacy_CompoundV2Subscriptions_json_1 = __importDefault(require("./legacy_CompoundV2Subscriptions.json"));
10
+ const Erc20_json_1 = __importDefault(require("./Erc20.json"));
11
+ const UniMulticall_json_1 = __importDefault(require("./UniMulticall.json"));
12
+ const SubStorage_json_1 = __importDefault(require("./SubStorage.json"));
13
+ const legacy_AuthCheck_json_1 = __importDefault(require("./legacy_AuthCheck.json"));
8
14
  function castToContractJsonType(json) {
9
15
  return json;
10
16
  }
11
- const MakerSubscriptionsJson = castToContractJsonType(MakerSubscriptions);
12
- const AaveV2SubscriptionsJson = castToContractJsonType(AaveV2Subscriptions);
13
- const CompoundV2SubscriptionsJson = castToContractJsonType(CompoundV2Subscriptions);
14
- const Erc20Json = castToContractJsonType(Erc20);
15
- const UniMulticallJson = castToContractJsonType(UniMulticall);
16
- const SubStorageJson = castToContractJsonType(SubStorage);
17
- const AuthCheckJson = castToContractJsonType(AuthCheck);
18
- export { MakerSubscriptionsJson, AaveV2SubscriptionsJson, CompoundV2SubscriptionsJson, Erc20Json, UniMulticallJson, SubStorageJson, AuthCheckJson, };
17
+ const MakerSubscriptionsJson = castToContractJsonType(legacy_MakerSubscriptions_json_1.default);
18
+ exports.MakerSubscriptionsJson = MakerSubscriptionsJson;
19
+ const AaveV2SubscriptionsJson = castToContractJsonType(legacy_AaveV2Subscriptions_json_1.default);
20
+ exports.AaveV2SubscriptionsJson = AaveV2SubscriptionsJson;
21
+ const CompoundV2SubscriptionsJson = castToContractJsonType(legacy_CompoundV2Subscriptions_json_1.default);
22
+ exports.CompoundV2SubscriptionsJson = CompoundV2SubscriptionsJson;
23
+ const Erc20Json = castToContractJsonType(Erc20_json_1.default);
24
+ exports.Erc20Json = Erc20Json;
25
+ const UniMulticallJson = castToContractJsonType(UniMulticall_json_1.default);
26
+ exports.UniMulticallJson = UniMulticallJson;
27
+ const SubStorageJson = castToContractJsonType(SubStorage_json_1.default);
28
+ exports.SubStorageJson = SubStorageJson;
29
+ const AuthCheckJson = castToContractJsonType(legacy_AuthCheck_json_1.default);
30
+ exports.AuthCheckJson = AuthCheckJson;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,18 +8,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
10
- import { isUndefined } from '../../services/utils';
11
- import { ChainId } from '../../types/enums';
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const utils_1 = require("../../services/utils");
13
+ const enums_1 = require("../../types/enums");
12
14
  // TODO - Improve provider assertion
13
- export default class Automation {
15
+ class Automation {
14
16
  assertProvider() {
15
- if (isUndefined(this.web3)) {
17
+ if ((0, utils_1.isUndefined)(this.web3)) {
16
18
  throw new Error(`Assertion for property 'web3' failed. \nExpected web3.js instance. Got: '${this.web3}.`);
17
19
  }
18
20
  }
19
21
  assertChainId() {
20
- const allowedChainIds = Object.values(ChainId);
21
- if (isUndefined(this.chainId) || !allowedChainIds.includes(this.chainId || '')) {
22
+ const allowedChainIds = Object.values(enums_1.ChainId);
23
+ if ((0, utils_1.isUndefined)(this.chainId) || !allowedChainIds.includes(this.chainId || '')) {
22
24
  throw new Error(`Assertion for property 'chainId' failed. \nExpected one of: '${allowedChainIds.join(', ')}. Got: '${this.chainId}.`);
23
25
  }
24
26
  }
@@ -37,3 +39,4 @@ export default class Automation {
37
39
  });
38
40
  }
39
41
  }
42
+ exports.default = Automation;
@@ -1,5 +1,5 @@
1
1
  import type Web3 from 'web3';
2
- import type { EthereumAddress, Position, Interfaces, Contract, PlaceholderType } from '../../types';
2
+ import type { EthereumAddress, Position, Interfaces, Contract, PlaceholderType, SubscriptionOptions } from '../../types';
3
3
  import type { Legacy_AaveV2Subscriptions, Legacy_CompoundV2Subscriptions, Legacy_MakerSubscriptions, Legacy_AuthCheck } from '../../types/contracts/generated';
4
4
  import Automation from './Automation';
5
5
  import { ChainId } from '../../types/enums';
@@ -18,8 +18,8 @@ export default class LegacyAutomation extends Automation {
18
18
  protected isMonitorAuthorized(address: EthereumAddress, caller: EthereumAddress): Promise<boolean>;
19
19
  protected isMonitorAuthorizedMulticall(addresses: EthereumAddress[], caller: EthereumAddress): Promise<boolean[]>;
20
20
  private getOwnerPropName;
21
- protected _getSubscriptions(addresses?: EthereumAddress[]): Promise<PlaceholderType>;
22
- protected getParsedSubscriptions(addresses?: EthereumAddress[]): Promise<Position.LegacyAutomated[]>;
23
- getSubscriptions(): Promise<Position.LegacyAutomated[]>;
24
- getSubscriptionsFor(addresses: EthereumAddress[]): Promise<Position.LegacyAutomated[]>;
21
+ protected _getSubscriptions(addresses?: EthereumAddress[], options?: SubscriptionOptions): Promise<PlaceholderType>;
22
+ protected getParsedSubscriptions(addresses?: EthereumAddress[], options?: SubscriptionOptions): Promise<Position.LegacyAutomated[]>;
23
+ getSubscriptions(options?: SubscriptionOptions): Promise<Position.LegacyAutomated[]>;
24
+ getSubscriptionsFor(addresses: EthereumAddress[], options?: SubscriptionOptions): Promise<Position.LegacyAutomated[]>;
25
25
  }
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,34 +8,38 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
10
- import { getAbiItem, makeAuthCheckerContract } from '../../services/contractService';
11
- import { multicall } from '../../services/ethereumService';
12
- import { isAddress, isUndefined } from '../../services/utils';
13
- import Automation from './Automation';
14
- import { ChainId, ProtocolIdentifiers } from '../../types/enums';
15
- export default class LegacyAutomation extends Automation {
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 contractService_1 = require("../../services/contractService");
16
+ const ethereumService_1 = require("../../services/ethereumService");
17
+ const utils_1 = require("../../services/utils");
18
+ const Automation_1 = __importDefault(require("./Automation"));
19
+ const enums_1 = require("../../types/enums");
20
+ class LegacyAutomation extends Automation_1.default {
16
21
  constructor(args) {
17
22
  super();
18
- this.chainId = ChainId.Ethereum;
23
+ this.chainId = enums_1.ChainId.Ethereum;
19
24
  this.web3 = args.provider;
20
25
  this.subscriptionsContract = args.subscriptionsJson;
21
26
  this.monitorAddress = args.monitorAddress;
22
27
  this.protocol = args.protocol;
23
- this.authCheckerContract = makeAuthCheckerContract(this.web3, this.chainId);
28
+ this.authCheckerContract = (0, contractService_1.makeAuthCheckerContract)(this.web3, this.chainId);
24
29
  this.assertLegacy();
25
30
  }
26
31
  assertSubscriptionContract() {
27
- if (isUndefined(this.subscriptionsContract)) {
32
+ if ((0, utils_1.isUndefined)(this.subscriptionsContract)) {
28
33
  throw new Error(`Assertion for property 'subscriptionsContract' failed. \nGot: '${this.subscriptionsContract}.`);
29
34
  }
30
35
  }
31
36
  assertProtocol() {
32
- if (isUndefined(this.protocol)) {
37
+ if ((0, utils_1.isUndefined)(this.protocol)) {
33
38
  throw new Error(`Assertion for property 'protocol' failed. \nGot: '${this.protocol}.`);
34
39
  }
35
40
  }
36
41
  assertMonitorAddress() {
37
- if (!isAddress(this.monitorAddress)) {
42
+ if (!(0, utils_1.isAddress)(this.monitorAddress)) {
38
43
  throw new Error(`Assertion for property 'monitorAddress' failed. \nGot: '${this.monitorAddress}.`);
39
44
  }
40
45
  }
@@ -54,19 +59,19 @@ export default class LegacyAutomation extends Automation {
54
59
  const authCheckerContract = this.authCheckerContract;
55
60
  const defaultOptions = {
56
61
  target: authCheckerContract.address,
57
- abiItem: getAbiItem(authCheckerContract.abi, 'canCall'),
62
+ abiItem: (0, contractService_1.getAbiItem)(authCheckerContract.abi, 'canCall'),
58
63
  };
59
64
  const multicallCalls = addresses.map((addr) => (Object.assign(Object.assign({}, defaultOptions), { params: [caller, addr, '0x1cff79cd'] })));
60
- return (yield multicall(this.web3, this.chainId, multicallCalls)).map(res => res[0]);
65
+ return (yield (0, ethereumService_1.multicall)(this.web3, this.chainId, multicallCalls)).map(res => res[0]);
61
66
  });
62
67
  }
63
68
  // Aave and Compound use 'user' for property name
64
69
  getOwnerPropName() {
65
- return this.protocol.id === ProtocolIdentifiers.LegacyAutomation.MakerDAO ? 'owner' : 'user';
70
+ return this.protocol.id === enums_1.ProtocolIdentifiers.LegacyAutomation.MakerDAO ? 'owner' : 'user';
66
71
  }
67
- _getSubscriptions(addresses) {
72
+ _getSubscriptions(addresses, options) {
68
73
  return __awaiter(this, void 0, void 0, function* () {
69
- let subscriptions = yield this.subscriptionsContract.contract.methods.getSubscribers().call();
74
+ let subscriptions = yield this.subscriptionsContract.contract.methods.getSubscribers().call({}, (options === null || options === void 0 ? void 0 : options.fromBlock) || 'latest');
70
75
  if (addresses) {
71
76
  const _addresses = addresses.map(a => a.toLowerCase());
72
77
  // @ts-ignore
@@ -75,14 +80,15 @@ export default class LegacyAutomation extends Automation {
75
80
  return subscriptions;
76
81
  });
77
82
  }
78
- getParsedSubscriptions(addresses) {
83
+ getParsedSubscriptions(addresses, options) {
79
84
  return __awaiter(this, void 0, void 0, function* () {
80
- const subscriptions = yield this._getSubscriptions(addresses);
85
+ const subscriptions = yield this._getSubscriptions(addresses, options);
81
86
  // @ts-ignore
82
87
  return subscriptions.map((sub) => ({
83
88
  chainId: this.chainId,
84
89
  owner: sub[this.getOwnerPropName()],
85
- isEnabled: true,
90
+ isEnabled: ((options === null || options === void 0 ? void 0 : options.fromBlock) && (options === null || options === void 0 ? void 0 : options.fromBlock) !== 'latest')
91
+ ? (options === null || options === void 0 ? void 0 : options.fromBlock) > 18213086 : false,
86
92
  protocol: this.protocol,
87
93
  specific: Object.assign({}, sub),
88
94
  strategy: {
@@ -92,14 +98,15 @@ export default class LegacyAutomation extends Automation {
92
98
  }));
93
99
  });
94
100
  }
95
- getSubscriptions() {
101
+ getSubscriptions(options) {
96
102
  return __awaiter(this, void 0, void 0, function* () {
97
- return this.getParsedSubscriptions();
103
+ return this.getParsedSubscriptions(undefined, options);
98
104
  });
99
105
  }
100
- getSubscriptionsFor(addresses) {
106
+ getSubscriptionsFor(addresses, options) {
101
107
  return __awaiter(this, void 0, void 0, function* () {
102
- return this.getParsedSubscriptions(addresses);
108
+ return this.getParsedSubscriptions(addresses, options);
103
109
  });
104
110
  }
105
111
  }
112
+ exports.default = LegacyAutomation;
@@ -1,10 +1,12 @@
1
+ "use strict";
1
2
  var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
3
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
4
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
5
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
6
  };
6
7
  var _Protocol_versionSeparator;
7
- export default class Protocol {
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ class Protocol {
8
10
  constructor(args) {
9
11
  _Protocol_versionSeparator.set(this, '__');
10
12
  this.id = args.id;
@@ -35,4 +37,5 @@ export default class Protocol {
35
37
  return this.hasVersion() ? `${this.name} ${this.version}` : this.name;
36
38
  }
37
39
  }
40
+ exports.default = Protocol;
38
41
  _Protocol_versionSeparator = new WeakMap();
@@ -1,10 +1,12 @@
1
+ "use strict";
1
2
  var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
3
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
4
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
5
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
6
  };
6
7
  var _Protocol_versionSeparator;
7
- export default class Protocol {
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ class Protocol {
8
10
  constructor(args) {
9
11
  _Protocol_versionSeparator.set(this, '__');
10
12
  this.id = args.id;
@@ -35,4 +37,5 @@ export default class Protocol {
35
37
  return this.hasVersion() ? `${this.name} ${this.version}` : this.name;
36
38
  }
37
39
  }
40
+ exports.default = Protocol;
38
41
  _Protocol_versionSeparator = new WeakMap();
@@ -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 } from '../../types';
3
+ import type { Position, Interfaces, EthereumAddress, SubscriptionOptions, Contract, ParseData, BlockNumber } from '../../types';
4
4
  import type { StrategyModel, SubStorage } from '../../types/contracts/generated/SubStorage';
5
5
  import type { ChainId } from '../../types/enums';
6
6
  import Automation from './Automation';
@@ -16,7 +16,7 @@ export default class StrategiesAutomation extends Automation {
16
16
  protected subStorageContractFork: Contract.WithMeta<SubStorage> | null;
17
17
  constructor(args: IStrategiesAutomation);
18
18
  protected getEventFromSubStorage(event: string, options?: PastEventOptions): Promise<any[]>;
19
- protected getStrategiesSubs(subIds: number[]): Promise<StrategyModel.StoredSubDataStructOutputStruct[]>;
19
+ protected getStrategiesSubs(subIds: number[], fromBlock?: BlockNumber): Promise<StrategyModel.StoredSubDataStructOutputStruct[]>;
20
20
  protected getSubscriptionEventsFromSubStorage(options?: PastEventOptions): Promise<any[]>;
21
21
  protected getUpdateDataEventsFromSubStorage(options?: PastEventOptions): Promise<any[]>;
22
22
  protected getParsedSubscriptions(parseData: ParseData): Position.Automated | null;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,47 +8,51 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
10
- import Dec from 'decimal.js';
11
- import { addToObjectIf, isDefined } from '../../services/utils';
12
- import { getAbiItem, makeSubStorageContract } from '../../services/contractService';
13
- import { getEventsFromContract, multicall } from '../../services/ethereumService';
14
- import { parseStrategiesAutomatedPosition } from '../../services/strategiesService';
15
- import Automation from './Automation';
16
- export default class StrategiesAutomation extends Automation {
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 decimal_js_1 = __importDefault(require("decimal.js"));
16
+ const utils_1 = require("../../services/utils");
17
+ const contractService_1 = require("../../services/contractService");
18
+ const ethereumService_1 = require("../../services/ethereumService");
19
+ const strategiesService_1 = require("../../services/strategiesService");
20
+ const Automation_1 = __importDefault(require("./Automation"));
21
+ class StrategiesAutomation extends Automation_1.default {
17
22
  constructor(args) {
18
23
  super();
19
24
  this.web3 = args.provider;
20
25
  this.web3Fork = args.providerFork;
21
26
  this.chainId = args.chainId;
22
- this.subStorageContract = makeSubStorageContract(this.web3, this.chainId);
23
- this.subStorageContractFork = this.web3Fork ? makeSubStorageContract(this.web3Fork, this.chainId) : null;
27
+ this.subStorageContract = (0, contractService_1.makeSubStorageContract)(this.web3, this.chainId);
28
+ this.subStorageContractFork = this.web3Fork ? (0, contractService_1.makeSubStorageContract)(this.web3Fork, this.chainId) : null;
24
29
  this.assert();
25
30
  }
26
31
  getEventFromSubStorage(event, options) {
27
32
  return __awaiter(this, void 0, void 0, function* () {
28
- return getEventsFromContract(this.subStorageContract, this.subStorageContractFork, event, options);
33
+ return (0, ethereumService_1.getEventsFromContract)(this.subStorageContract, this.subStorageContractFork, event, options);
29
34
  });
30
35
  }
31
- getStrategiesSubs(subIds) {
36
+ getStrategiesSubs(subIds, fromBlock = 'latest') {
32
37
  return __awaiter(this, void 0, void 0, function* () {
33
38
  let options;
34
39
  let web3;
35
40
  if (this.web3Fork && this.subStorageContractFork) {
36
41
  options = {
37
42
  target: this.subStorageContractFork.address,
38
- abiItem: getAbiItem(this.subStorageContractFork.abi, 'strategiesSubs'),
43
+ abiItem: (0, contractService_1.getAbiItem)(this.subStorageContractFork.abi, 'strategiesSubs'),
39
44
  };
40
45
  web3 = this.web3Fork;
41
46
  }
42
47
  else {
43
48
  options = {
44
49
  target: this.subStorageContract.address,
45
- abiItem: getAbiItem(this.subStorageContract.abi, 'strategiesSubs'),
50
+ abiItem: (0, contractService_1.getAbiItem)(this.subStorageContract.abi, 'strategiesSubs'),
46
51
  };
47
52
  web3 = this.web3;
48
53
  }
49
54
  const multicallCalls = subIds.map((subId) => (Object.assign(Object.assign({}, options), { params: [subId] })));
50
- return multicall(web3, this.chainId, multicallCalls);
55
+ return (0, ethereumService_1.multicall)(web3, this.chainId, multicallCalls, fromBlock);
51
56
  });
52
57
  }
53
58
  getSubscriptionEventsFromSubStorage(options) {
@@ -63,21 +68,21 @@ export default class StrategiesAutomation extends Automation {
63
68
  });
64
69
  }
65
70
  getParsedSubscriptions(parseData) {
66
- return parseStrategiesAutomatedPosition(parseData);
71
+ return (0, strategiesService_1.parseStrategiesAutomatedPosition)(parseData);
67
72
  }
68
73
  _getSubscriptions(addresses, options) {
69
74
  return __awaiter(this, void 0, void 0, function* () {
70
- const _options = Object.assign(Object.assign({}, addToObjectIf(isDefined(options), options)), addToObjectIf(isDefined(addresses), { filter: { proxy: addresses } }));
75
+ 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 } }));
71
76
  const subscriptionEvents = (yield this.getSubscriptionEventsFromSubStorage(_options)); // TODO PlaceholderType
72
77
  let subscriptions = [];
73
78
  if (subscriptionEvents) {
74
79
  // @ts-ignore
75
- const strategiesSubs = yield this.getStrategiesSubs(subscriptionEvents.map((e) => e.returnValues.subId));
80
+ const strategiesSubs = yield this.getStrategiesSubs(subscriptionEvents.map((e) => e.returnValues.subId), _options.fromBlock);
76
81
  subscriptions = yield Promise.all(strategiesSubs.map((sub, index) => __awaiter(this, void 0, void 0, function* () {
77
82
  var _a;
78
83
  let latestUpdate = subscriptionEvents[index].returnValues;
79
84
  if (latestUpdate.subHash !== (sub === null || sub === void 0 ? void 0 : sub.strategySubHash)) {
80
- const updates = yield this.getUpdateDataEventsFromSubStorage(Object.assign(Object.assign({}, addToObjectIf(!!_options, _options)), { filter: { subId: latestUpdate.subId } }));
85
+ const updates = yield this.getUpdateDataEventsFromSubStorage(Object.assign(Object.assign({}, (0, utils_1.addToObjectIf)(!!_options, _options)), { filter: { subId: latestUpdate.subId } }));
81
86
  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);
82
87
  }
83
88
  return this.getParsedSubscriptions({
@@ -90,7 +95,7 @@ export default class StrategiesAutomation extends Automation {
90
95
  if (options === null || options === void 0 ? void 0 : options.mergeWithSameId) {
91
96
  subscriptions = subscriptions.reduce((list, current) => {
92
97
  const copyList = [...list];
93
- if (isDefined(current)) {
98
+ if ((0, utils_1.isDefined)(current)) {
94
99
  if (current.specific.mergeWithSameId) {
95
100
  const mergePairIndex = copyList.findIndex(s => (s && s.specific.mergeWithSameId
96
101
  && s.owner === current.owner
@@ -98,10 +103,10 @@ export default class StrategiesAutomation extends Automation {
98
103
  && s.protocol.id === current.protocol.id));
99
104
  if (mergePairIndex !== -1) {
100
105
  const mergePair = copyList[mergePairIndex];
101
- if (isDefined(mergePair)) {
106
+ if ((0, utils_1.isDefined)(mergePair)) {
102
107
  copyList[mergePairIndex] = Object.assign(Object.assign(Object.assign({}, mergePair), current), {
103
108
  // @ts-ignore
104
- blockNumber: Dec.max(mergePair.blockNumber, current.blockNumber).toNumber(), subIds: isDefined(mergePair.subIds) ? [...mergePair.subIds, current.subId] : undefined, isEnabled: mergePair.isEnabled || current.isEnabled, subId: mergePair.subId, specific: Object.assign(Object.assign(Object.assign({}, mergePair.specific), current.specific), { mergeWithSameId: false }) });
109
+ blockNumber: decimal_js_1.default.max(mergePair.blockNumber, current.blockNumber).toNumber(), subIds: (0, utils_1.isDefined)(mergePair.subIds) ? [...mergePair.subIds, current.subId] : undefined, isEnabled: mergePair.isEnabled || current.isEnabled, subId: mergePair.subId, specific: Object.assign(Object.assign(Object.assign({}, mergePair.specific), current.specific), { mergeWithSameId: false }) });
105
110
  return copyList;
106
111
  }
107
112
  }
@@ -129,3 +134,4 @@ export default class StrategiesAutomation extends Automation {
129
134
  });
130
135
  }
131
136
  }
137
+ exports.default = StrategiesAutomation;
@@ -1,7 +1,13 @@
1
- import StrategiesAutomation from '../private/StrategiesAutomation';
2
- import { ChainId } from '../../types/enums';
3
- export default class ArbitrumStrategies extends StrategiesAutomation {
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const StrategiesAutomation_1 = __importDefault(require("../private/StrategiesAutomation"));
7
+ const enums_1 = require("../../types/enums");
8
+ class ArbitrumStrategies extends StrategiesAutomation_1.default {
4
9
  constructor(args) {
5
- super(Object.assign(Object.assign({}, args), { chainId: ChainId.Arbitrum }));
10
+ super(Object.assign(Object.assign({}, args), { chainId: enums_1.ChainId.Arbitrum }));
6
11
  }
7
12
  }
13
+ exports.default = ArbitrumStrategies;
@@ -1,7 +1,13 @@
1
- import StrategiesAutomation from '../private/StrategiesAutomation';
2
- import { ChainId } from '../../types/enums';
3
- export default class EthereumStrategies extends StrategiesAutomation {
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const StrategiesAutomation_1 = __importDefault(require("../private/StrategiesAutomation"));
7
+ const enums_1 = require("../../types/enums");
8
+ class EthereumStrategies extends StrategiesAutomation_1.default {
4
9
  constructor(args) {
5
- super(Object.assign(Object.assign({}, args), { chainId: ChainId.Ethereum }));
10
+ super(Object.assign(Object.assign({}, args), { chainId: enums_1.ChainId.Ethereum }));
6
11
  }
7
12
  }
13
+ exports.default = EthereumStrategies;
@@ -1,7 +1,13 @@
1
- import StrategiesAutomation from '../private/StrategiesAutomation';
2
- import { ChainId } from '../../types/enums';
3
- export default class OptimismStrategies extends StrategiesAutomation {
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const StrategiesAutomation_1 = __importDefault(require("../private/StrategiesAutomation"));
7
+ const enums_1 = require("../../types/enums");
8
+ class OptimismStrategies extends StrategiesAutomation_1.default {
4
9
  constructor(args) {
5
- super(Object.assign(Object.assign({}, args), { chainId: ChainId.Optimism }));
10
+ super(Object.assign(Object.assign({}, args), { chainId: enums_1.ChainId.Optimism }));
6
11
  }
7
12
  }
13
+ exports.default = OptimismStrategies;
@@ -1,14 +1,20 @@
1
- import { LEGACY_PROTOCOLS } from '../../../constants';
2
- import { AaveV2SubscriptionsJson } from '../../../abis';
3
- import { makeLegacySubscriptionContract } from '../../../services/contractService';
4
- import LegacyAutomation from '../../private/LegacyAutomation';
5
- export default class LegacyAaveAutomation extends LegacyAutomation {
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const constants_1 = require("../../../constants");
7
+ const abis_1 = require("../../../abis");
8
+ const contractService_1 = require("../../../services/contractService");
9
+ const LegacyAutomation_1 = __importDefault(require("../../private/LegacyAutomation"));
10
+ class LegacyAaveAutomation extends LegacyAutomation_1.default {
6
11
  constructor(args) {
7
12
  super({
8
13
  provider: args.provider,
9
- subscriptionsJson: makeLegacySubscriptionContract(args.provider, AaveV2SubscriptionsJson),
14
+ subscriptionsJson: (0, contractService_1.makeLegacySubscriptionContract)(args.provider, abis_1.AaveV2SubscriptionsJson),
10
15
  monitorAddress: '0x380982902872836ceC629171DaeAF42EcC02226e',
11
- protocol: LEGACY_PROTOCOLS.AaveV2,
16
+ protocol: constants_1.LEGACY_PROTOCOLS.AaveV2,
12
17
  });
13
18
  }
14
19
  }
20
+ exports.default = LegacyAaveAutomation;
@@ -1,14 +1,20 @@
1
- import { LEGACY_PROTOCOLS } from '../../../constants';
2
- import { CompoundV2SubscriptionsJson } from '../../../abis';
3
- import { makeLegacySubscriptionContract } from '../../../services/contractService';
4
- import LegacyAutomation from '../../private/LegacyAutomation';
5
- export default class LegacyAaveAutomation extends LegacyAutomation {
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const constants_1 = require("../../../constants");
7
+ const abis_1 = require("../../../abis");
8
+ const contractService_1 = require("../../../services/contractService");
9
+ const LegacyAutomation_1 = __importDefault(require("../../private/LegacyAutomation"));
10
+ class LegacyAaveAutomation extends LegacyAutomation_1.default {
6
11
  constructor(args) {
7
12
  super({
8
13
  provider: args.provider,
9
- subscriptionsJson: makeLegacySubscriptionContract(args.provider, CompoundV2SubscriptionsJson),
14
+ subscriptionsJson: (0, contractService_1.makeLegacySubscriptionContract)(args.provider, abis_1.CompoundV2SubscriptionsJson),
10
15
  monitorAddress: '0xB1cF8DE8e791E4Ed1Bd86c03E2fc1f14389Cb10a',
11
- protocol: LEGACY_PROTOCOLS.CompoundV2,
16
+ protocol: constants_1.LEGACY_PROTOCOLS.CompoundV2,
12
17
  });
13
18
  }
14
19
  }
20
+ exports.default = LegacyAaveAutomation;
@@ -1,14 +1,20 @@
1
- import { LEGACY_PROTOCOLS } from '../../../constants';
2
- import { MakerSubscriptionsJson } from '../../../abis';
3
- import { makeLegacySubscriptionContract } from '../../../services/contractService';
4
- import LegacyAutomation from '../../private/LegacyAutomation';
5
- export default class LegacyMakerAutomation extends LegacyAutomation {
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const constants_1 = require("../../../constants");
7
+ const abis_1 = require("../../../abis");
8
+ const contractService_1 = require("../../../services/contractService");
9
+ const LegacyAutomation_1 = __importDefault(require("../../private/LegacyAutomation"));
10
+ class LegacyMakerAutomation extends LegacyAutomation_1.default {
6
11
  constructor(args) {
7
12
  super({
8
13
  provider: args.provider,
9
- subscriptionsJson: makeLegacySubscriptionContract(args.provider, MakerSubscriptionsJson),
14
+ subscriptionsJson: (0, contractService_1.makeLegacySubscriptionContract)(args.provider, abis_1.MakerSubscriptionsJson),
10
15
  monitorAddress: '0x1816A86C4DA59395522a42b871bf11A4E96A1C7a',
11
- protocol: LEGACY_PROTOCOLS.MakerDAO,
16
+ protocol: constants_1.LEGACY_PROTOCOLS.MakerDAO,
12
17
  });
13
18
  }
14
19
  }
20
+ exports.default = LegacyMakerAutomation;
@@ -1,8 +1,11 @@
1
- import Web3 from 'web3';
2
- import Dec from 'decimal.js';
3
- process.mockedWeb3 = new Web3('');
4
- Dec.set({
5
- rounding: Dec.ROUND_DOWN,
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const decimal_js_1 = __importDefault(require("decimal.js"));
7
+ decimal_js_1.default.set({
8
+ rounding: decimal_js_1.default.ROUND_DOWN,
6
9
  toExpPos: 9e15,
7
10
  toExpNeg: -9e15,
8
11
  precision: 100,