@defisaver/automation-sdk 1.0.1

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 (123) hide show
  1. package/.babelrc +3 -0
  2. package/.editorconfig +9 -0
  3. package/.eslintignore +7 -0
  4. package/.eslintrc.js +104 -0
  5. package/esm/abis/Erc20.json +223 -0
  6. package/esm/abis/SubStorage.json +17 -0
  7. package/esm/abis/UniMulticall.json +14 -0
  8. package/esm/abis/index.d.ts +9 -0
  9. package/esm/abis/index.js +18 -0
  10. package/esm/abis/legacy_AaveV2Subscriptions.json +8 -0
  11. package/esm/abis/legacy_AuthCheck.json +8 -0
  12. package/esm/abis/legacy_CompoundV2Subscriptions.json +9 -0
  13. package/esm/abis/legacy_MakerSubscriptions.json +9 -0
  14. package/esm/automation/private/Automation.d.ts +12 -0
  15. package/esm/automation/private/Automation.js +39 -0
  16. package/esm/automation/private/LegacyAutomation.d.ts +25 -0
  17. package/esm/automation/private/LegacyAutomation.js +102 -0
  18. package/esm/automation/private/LegacyProtocol.d.ts +20 -0
  19. package/esm/automation/private/LegacyProtocol.js +34 -0
  20. package/esm/automation/private/Protocol.d.ts +20 -0
  21. package/esm/automation/private/Protocol.js +34 -0
  22. package/esm/automation/private/StrategiesAutomation.d.ts +24 -0
  23. package/esm/automation/private/StrategiesAutomation.js +111 -0
  24. package/esm/automation/public/ArbitrumStrategies.d.ts +5 -0
  25. package/esm/automation/public/ArbitrumStrategies.js +7 -0
  26. package/esm/automation/public/EthereumStrategies.d.ts +5 -0
  27. package/esm/automation/public/EthereumStrategies.js +7 -0
  28. package/esm/automation/public/OptimismStrategies.d.ts +5 -0
  29. package/esm/automation/public/OptimismStrategies.js +7 -0
  30. package/esm/automation/public/legacy/LegacyAaveAutomation.d.ts +6 -0
  31. package/esm/automation/public/legacy/LegacyAaveAutomation.js +14 -0
  32. package/esm/automation/public/legacy/LegacyCompoundAutomation.d.ts +6 -0
  33. package/esm/automation/public/legacy/LegacyCompoundAutomation.js +14 -0
  34. package/esm/automation/public/legacy/LegacyMakerAutomation.d.ts +6 -0
  35. package/esm/automation/public/legacy/LegacyMakerAutomation.js +14 -0
  36. package/esm/configuration.d.ts +1 -0
  37. package/esm/configuration.js +9 -0
  38. package/esm/constants/index.d.ts +23 -0
  39. package/esm/constants/index.js +153 -0
  40. package/esm/index.d.ts +20 -0
  41. package/esm/index.js +22 -0
  42. package/esm/services/contractService.d.ts +11 -0
  43. package/esm/services/contractService.js +40 -0
  44. package/esm/services/ethereumService.d.ts +7 -0
  45. package/esm/services/ethereumService.js +34 -0
  46. package/esm/services/strategiesService.d.ts +2 -0
  47. package/esm/services/strategiesService.js +244 -0
  48. package/esm/services/strategySubService.d.ts +32 -0
  49. package/esm/services/strategySubService.js +91 -0
  50. package/esm/services/subDataService.d.ts +62 -0
  51. package/esm/services/subDataService.js +148 -0
  52. package/esm/services/triggerService.d.ts +89 -0
  53. package/esm/services/triggerService.js +141 -0
  54. package/esm/services/utils.d.ts +24 -0
  55. package/esm/services/utils.js +78 -0
  56. package/esm/types/contracts/generated/Erc20.d.ts +53 -0
  57. package/esm/types/contracts/generated/Erc20.js +4 -0
  58. package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.d.ts +129 -0
  59. package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.js +4 -0
  60. package/esm/types/contracts/generated/Legacy_AuthCheck.d.ts +20 -0
  61. package/esm/types/contracts/generated/Legacy_AuthCheck.js +4 -0
  62. package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.d.ts +128 -0
  63. package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +4 -0
  64. package/esm/types/contracts/generated/Legacy_MakerSubscriptions.d.ts +246 -0
  65. package/esm/types/contracts/generated/Legacy_MakerSubscriptions.js +4 -0
  66. package/esm/types/contracts/generated/SubStorage.d.ts +114 -0
  67. package/esm/types/contracts/generated/SubStorage.js +4 -0
  68. package/esm/types/contracts/generated/UniMulticall.d.ts +55 -0
  69. package/esm/types/contracts/generated/UniMulticall.js +4 -0
  70. package/esm/types/contracts/generated/index.d.ts +7 -0
  71. package/esm/types/contracts/generated/index.js +1 -0
  72. package/esm/types/contracts/generated/types.d.ts +54 -0
  73. package/esm/types/contracts/generated/types.js +1 -0
  74. package/esm/types/enums.d.ts +97 -0
  75. package/esm/types/enums.js +113 -0
  76. package/esm/types/index.d.ts +180 -0
  77. package/esm/types/index.js +1 -0
  78. package/package.json +66 -0
  79. package/scripts/generateContractTypes.js +39 -0
  80. package/src/abis/Erc20.json +223 -0
  81. package/src/abis/SubStorage.json +17 -0
  82. package/src/abis/UniMulticall.json +14 -0
  83. package/src/abis/index.ts +28 -0
  84. package/src/abis/legacy_AaveV2Subscriptions.json +8 -0
  85. package/src/abis/legacy_AuthCheck.json +8 -0
  86. package/src/abis/legacy_CompoundV2Subscriptions.json +9 -0
  87. package/src/abis/legacy_MakerSubscriptions.json +9 -0
  88. package/src/automation/private/Automation.ts +44 -0
  89. package/src/automation/private/LegacyAutomation.ts +124 -0
  90. package/src/automation/private/LegacyProtocol.ts +45 -0
  91. package/src/automation/private/Protocol.ts +45 -0
  92. package/src/automation/private/StrategiesAutomation.ts +157 -0
  93. package/src/automation/public/ArbitrumStrategies.ts +10 -0
  94. package/src/automation/public/EthereumStrategies.ts +10 -0
  95. package/src/automation/public/OptimismStrategies.ts +10 -0
  96. package/src/automation/public/legacy/LegacyAaveAutomation.ts +20 -0
  97. package/src/automation/public/legacy/LegacyCompoundAutomation.ts +20 -0
  98. package/src/automation/public/legacy/LegacyMakerAutomation.ts +20 -0
  99. package/src/configuration.ts +11 -0
  100. package/src/constants/index.ts +173 -0
  101. package/src/index.ts +38 -0
  102. package/src/services/contractService.ts +65 -0
  103. package/src/services/ethereumService.ts +55 -0
  104. package/src/services/strategiesService.ts +336 -0
  105. package/src/services/strategySubService.ts +202 -0
  106. package/src/services/subDataService.ts +212 -0
  107. package/src/services/triggerService.ts +173 -0
  108. package/src/services/utils.ts +101 -0
  109. package/src/types/contracts/generated/Erc20.ts +95 -0
  110. package/src/types/contracts/generated/Legacy_AaveV2Subscriptions.ts +207 -0
  111. package/src/types/contracts/generated/Legacy_AuthCheck.ts +41 -0
  112. package/src/types/contracts/generated/Legacy_CompoundV2Subscriptions.ts +205 -0
  113. package/src/types/contracts/generated/Legacy_MakerSubscriptions.ts +338 -0
  114. package/src/types/contracts/generated/SubStorage.ts +196 -0
  115. package/src/types/contracts/generated/UniMulticall.ts +83 -0
  116. package/src/types/contracts/generated/index.ts +10 -0
  117. package/src/types/contracts/generated/types.ts +73 -0
  118. package/src/types/enums.ts +108 -0
  119. package/src/types/index.ts +217 -0
  120. package/src/types/typings/process.d.ts +9 -0
  121. package/tsconfig.json +79 -0
  122. package/umd/web3.d.ts +28961 -0
  123. package/webpack.umd.js +52 -0
@@ -0,0 +1,25 @@
1
+ import type Web3 from 'web3';
2
+ import type { EthereumAddress, Position, Interfaces, Contract, PlaceholderType } from '../../types';
3
+ import type { Legacy_AaveV2Subscriptions, Legacy_CompoundV2Subscriptions, Legacy_MakerSubscriptions, Legacy_AuthCheck } from '../../types/contracts/generated';
4
+ import Automation from './Automation';
5
+ import { ChainId } from '../../types/enums';
6
+ export default class LegacyAutomation extends Automation {
7
+ protected chainId: ChainId;
8
+ protected web3: Web3;
9
+ protected monitorAddress: EthereumAddress;
10
+ protected subscriptionsContract: Contract.WithMeta<Legacy_MakerSubscriptions | Legacy_AaveV2Subscriptions | Legacy_CompoundV2Subscriptions>;
11
+ protected authCheckerContract: Contract.WithMeta<Legacy_AuthCheck>;
12
+ protected protocol: Interfaces.LegacyProtocol;
13
+ constructor(args: Interfaces.LegacyAutomation<Legacy_MakerSubscriptions | Legacy_AaveV2Subscriptions | Legacy_CompoundV2Subscriptions>);
14
+ protected assertSubscriptionContract(): void;
15
+ protected assertProtocol(): void;
16
+ protected assertMonitorAddress(): void;
17
+ protected assertLegacy(): void;
18
+ protected isMonitorAuthorized(address: EthereumAddress, caller: EthereumAddress): Promise<boolean>;
19
+ protected isMonitorAuthorizedMulticall(addresses: EthereumAddress[], caller: EthereumAddress): Promise<boolean[]>;
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[]>;
25
+ }
@@ -0,0 +1,102 @@
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 { 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 {
16
+ constructor(args) {
17
+ super();
18
+ this.chainId = ChainId.Ethereum;
19
+ this.web3 = args.provider;
20
+ this.subscriptionsContract = args.subscriptionsJson;
21
+ this.monitorAddress = args.monitorAddress;
22
+ this.protocol = args.protocol;
23
+ this.authCheckerContract = makeAuthCheckerContract(this.web3, this.chainId);
24
+ this.assertLegacy();
25
+ }
26
+ assertSubscriptionContract() {
27
+ if (isUndefined(this.subscriptionsContract)) {
28
+ throw new Error(`Assertion for property 'subscriptionsContract' failed. \nGot: '${this.subscriptionsContract}.`);
29
+ }
30
+ }
31
+ assertProtocol() {
32
+ if (isUndefined(this.protocol)) {
33
+ throw new Error(`Assertion for property 'protocol' failed. \nGot: '${this.protocol}.`);
34
+ }
35
+ }
36
+ assertMonitorAddress() {
37
+ if (!isAddress(this.monitorAddress)) {
38
+ throw new Error(`Assertion for property 'monitorAddress' failed. \nGot: '${this.monitorAddress}.`);
39
+ }
40
+ }
41
+ assertLegacy() {
42
+ this.assertProtocol();
43
+ this.assertMonitorAddress();
44
+ this.assertSubscriptionContract();
45
+ this.assert();
46
+ }
47
+ isMonitorAuthorized(address, caller) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ return this.authCheckerContract.contract.methods.canCall(caller, address, '0x1cff79cd').call();
50
+ });
51
+ }
52
+ isMonitorAuthorizedMulticall(addresses, caller) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ const authCheckerContract = this.authCheckerContract;
55
+ const defaultOptions = {
56
+ target: authCheckerContract.address,
57
+ abiItem: getAbiItem(authCheckerContract.abi, 'canCall'),
58
+ };
59
+ 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]);
61
+ });
62
+ }
63
+ // Aave and Compound use 'user' for property name
64
+ getOwnerPropName() {
65
+ return this.protocol.id === ProtocolIdentifiers.LegacyAutomation.MakerDAO ? 'owner' : 'user';
66
+ }
67
+ _getSubscriptions(addresses) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ let subscriptions = yield this.subscriptionsContract.contract.methods.getSubscribers().call();
70
+ if (addresses) {
71
+ const _addresses = addresses.map(a => a.toLowerCase());
72
+ // @ts-ignore
73
+ subscriptions = subscriptions.filter(s => _addresses.includes(s[this.getOwnerPropName()]));
74
+ }
75
+ return subscriptions;
76
+ });
77
+ }
78
+ getParsedSubscriptions(addresses) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ let subscriptions = yield this._getSubscriptions(addresses);
81
+ // @ts-ignore
82
+ subscriptions = subscriptions.map(sub => ({
83
+ chainId: this.chainId,
84
+ owner: sub[this.getOwnerPropName()],
85
+ isEnabled: true,
86
+ protocol: this.protocol,
87
+ specific: Object.assign({}, sub),
88
+ }));
89
+ return subscriptions;
90
+ });
91
+ }
92
+ getSubscriptions() {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ return this.getParsedSubscriptions();
95
+ });
96
+ }
97
+ getSubscriptionsFor(addresses) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ return this.getParsedSubscriptions(addresses);
100
+ });
101
+ }
102
+ }
@@ -0,0 +1,20 @@
1
+ import type { Interfaces } from '../../types';
2
+ import type { ProtocolIdentifiers } from '../../types/enums';
3
+ export default class Protocol implements Interfaces.LegacyProtocol {
4
+ #private;
5
+ id: ProtocolIdentifiers.LegacyAutomation;
6
+ name: string;
7
+ version: string;
8
+ fullName: string;
9
+ constructor(args: {
10
+ id: ProtocolIdentifiers.LegacyAutomation;
11
+ });
12
+ private hasVersion;
13
+ private splitId;
14
+ /**
15
+ * @dev See naming convention at ProtocolIdentifiers declaration
16
+ */
17
+ private getVersion;
18
+ private getName;
19
+ private getFullName;
20
+ }
@@ -0,0 +1,34 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ 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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var _Protocol_versionSeparator;
7
+ export default class Protocol {
8
+ constructor(args) {
9
+ _Protocol_versionSeparator.set(this, '__');
10
+ this.id = args.id;
11
+ this.name = this.getName();
12
+ this.version = this.getVersion();
13
+ this.fullName = this.getFullName();
14
+ }
15
+ hasVersion() {
16
+ return this.id.indexOf(__classPrivateFieldGet(this, _Protocol_versionSeparator, "f")) !== -1;
17
+ }
18
+ splitId() {
19
+ return this.id.split(__classPrivateFieldGet(this, _Protocol_versionSeparator, "f"));
20
+ }
21
+ /**
22
+ * @dev See naming convention at ProtocolIdentifiers declaration
23
+ */
24
+ getVersion() {
25
+ return this.hasVersion() ? this.splitId().reverse()[0] : '';
26
+ }
27
+ getName() {
28
+ return this.hasVersion() ? this.splitId()[0] : this.id;
29
+ }
30
+ getFullName() {
31
+ return this.hasVersion() ? `${this.name} ${this.version}` : this.name;
32
+ }
33
+ }
34
+ _Protocol_versionSeparator = new WeakMap();
@@ -0,0 +1,20 @@
1
+ import type { Interfaces } from '../../types';
2
+ import type { ProtocolIdentifiers } from '../../types/enums';
3
+ export default class Protocol implements Interfaces.Protocol {
4
+ #private;
5
+ id: ProtocolIdentifiers.StrategiesAutomation;
6
+ name: string;
7
+ version: string;
8
+ fullName: string;
9
+ constructor(args: {
10
+ id: ProtocolIdentifiers.StrategiesAutomation;
11
+ });
12
+ private hasVersion;
13
+ private splitId;
14
+ /**
15
+ * @dev See naming convention at ProtocolIdentifiers declaration
16
+ */
17
+ private getVersion;
18
+ private getName;
19
+ private getFullName;
20
+ }
@@ -0,0 +1,34 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ 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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var _Protocol_versionSeparator;
7
+ export default class Protocol {
8
+ constructor(args) {
9
+ _Protocol_versionSeparator.set(this, '__');
10
+ this.id = args.id;
11
+ this.name = this.getName();
12
+ this.version = this.getVersion();
13
+ this.fullName = this.getFullName();
14
+ }
15
+ hasVersion() {
16
+ return this.id.indexOf(__classPrivateFieldGet(this, _Protocol_versionSeparator, "f")) !== -1;
17
+ }
18
+ splitId() {
19
+ return this.id.split(__classPrivateFieldGet(this, _Protocol_versionSeparator, "f"));
20
+ }
21
+ /**
22
+ * @dev See naming convention at ProtocolIdentifiers declaration
23
+ */
24
+ getVersion() {
25
+ return this.hasVersion() ? this.splitId().reverse()[0] : '';
26
+ }
27
+ getName() {
28
+ return this.hasVersion() ? this.splitId()[0] : this.id;
29
+ }
30
+ getFullName() {
31
+ return this.hasVersion() ? `${this.name} ${this.version}` : this.name;
32
+ }
33
+ }
34
+ _Protocol_versionSeparator = new WeakMap();
@@ -0,0 +1,24 @@
1
+ import type Web3 from 'web3';
2
+ import type { PastEventOptions } from 'web3-eth-contract';
3
+ import type { Position, Interfaces, EthereumAddress, SubscriptionOptions, Contract, ParseData } from '../../types';
4
+ import type { StrategyModel, SubStorage } from '../../types/contracts/generated/SubStorage';
5
+ import Automation from './Automation';
6
+ import type { ChainId } from '../../types/enums';
7
+ interface IStrategiesAutomation extends Interfaces.Automation {
8
+ chainId: ChainId;
9
+ }
10
+ export default class StrategiesAutomation extends Automation {
11
+ protected chainId: ChainId;
12
+ protected web3: Web3;
13
+ protected subStorageContract: Contract.WithMeta<SubStorage>;
14
+ constructor(args: IStrategiesAutomation);
15
+ protected getEventFromSubStorage(event: string, options?: PastEventOptions): Promise<import("web3-eth-contract").EventData[]>;
16
+ protected getStrategiesSubs(subIds: number[]): Promise<StrategyModel.StoredSubDataStructOutputStruct[]>;
17
+ protected getSubscriptionEventsFromSubStorage(options?: PastEventOptions): Promise<import("web3-eth-contract").EventData[]>;
18
+ protected getUpdateDataEventsFromSubStorage(options?: PastEventOptions): Promise<import("web3-eth-contract").EventData[]>;
19
+ protected getParsedSubscriptions(parseData: ParseData): Position.Automated | null;
20
+ protected _getSubscriptions(addresses?: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
21
+ getSubscriptions(options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
22
+ getSubscriptionsFor(addresses: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
23
+ }
24
+ export {};
@@ -0,0 +1,111 @@
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 { addToArrayIf, addToObjectIf, isDefined, } from '../../services/utils';
11
+ import { getAbiItem, makeSubStorageContract } from '../../services/contractService';
12
+ import { getEventsFromContract, multicall } from '../../services/ethereumService';
13
+ import Automation from './Automation';
14
+ import { parseStrategiesAutomatedPosition } from '../../services/strategiesService';
15
+ export default class StrategiesAutomation extends Automation {
16
+ constructor(args) {
17
+ super();
18
+ this.web3 = args.provider;
19
+ this.chainId = args.chainId;
20
+ this.subStorageContract = makeSubStorageContract(this.web3, this.chainId);
21
+ this.assert();
22
+ }
23
+ getEventFromSubStorage(event, options) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ return getEventsFromContract(this.subStorageContract, event, options);
26
+ });
27
+ }
28
+ getStrategiesSubs(subIds) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ const subStorageContract = this.subStorageContract;
31
+ const defaultOptions = {
32
+ target: subStorageContract.address,
33
+ abiItem: getAbiItem(subStorageContract.abi, 'strategiesSubs'),
34
+ };
35
+ const multicallCalls = subIds.map((subId) => (Object.assign(Object.assign({}, defaultOptions), { params: [subId] })));
36
+ return multicall(this.web3, this.chainId, multicallCalls);
37
+ });
38
+ }
39
+ getSubscriptionEventsFromSubStorage(options) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ return this.getEventFromSubStorage('Subscribe', options);
42
+ });
43
+ }
44
+ getUpdateDataEventsFromSubStorage(options) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ return this.getEventFromSubStorage('UpdateData', options);
47
+ });
48
+ }
49
+ getParsedSubscriptions(parseData) {
50
+ return parseStrategiesAutomatedPosition(parseData);
51
+ }
52
+ _getSubscriptions(addresses, options) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ const _options = Object.assign(Object.assign({}, addToObjectIf(isDefined(options), options)), addToObjectIf(isDefined(addresses), { filter: { proxy: addresses } }));
55
+ const subscriptionEvents = (yield this.getSubscriptionEventsFromSubStorage(_options)).map(e => e.returnValues); // TODO PlaceholderType
56
+ let subscriptions = [];
57
+ if (subscriptionEvents) {
58
+ // @ts-ignore
59
+ const strategiesSubs = yield this.getStrategiesSubs(subscriptionEvents.map((e) => e.subId));
60
+ subscriptions = yield Promise.all(strategiesSubs.map((sub, index) => __awaiter(this, void 0, void 0, function* () {
61
+ var _a;
62
+ let latestUpdate = subscriptionEvents[index];
63
+ if (latestUpdate.subHash !== (sub === null || sub === void 0 ? void 0 : sub.strategySubHash)) {
64
+ const updates = yield this.getUpdateDataEventsFromSubStorage({ filter: latestUpdate.subId });
65
+ 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);
66
+ }
67
+ return this.getParsedSubscriptions({
68
+ chainId: this.chainId,
69
+ subscriptionEventData: latestUpdate,
70
+ strategiesSubsData: sub,
71
+ });
72
+ })));
73
+ if (options === null || options === void 0 ? void 0 : options.mergeWithSameId) {
74
+ subscriptions = subscriptions.reduce((list, current) => {
75
+ const copyList = [...list];
76
+ if (isDefined(current)) {
77
+ if (current.specific.mergeWithSameId) {
78
+ const mergePairIndex = copyList.findIndex(s => (s && s.specific.mergeWithSameId
79
+ && s.strategy.strategyId === current.strategy.strategyId
80
+ && s.protocol.id === current.protocol.id));
81
+ if (mergePairIndex !== -1) {
82
+ const mergePair = copyList[mergePairIndex];
83
+ if (isDefined(mergePair)) {
84
+ copyList[mergePairIndex] = Object.assign(Object.assign(Object.assign({}, mergePair), current), { isEnabled: mergePair.isEnabled || current.isEnabled, subId: mergePair.subId, subIds: [...addToArrayIf(isDefined(mergePair.subIds), mergePair.subIds), current.subId], specific: Object.assign(Object.assign(Object.assign({}, mergePair.specific), current.specific), { mergeWithSameId: false }) });
85
+ return copyList;
86
+ }
87
+ }
88
+ }
89
+ }
90
+ else {
91
+ return copyList;
92
+ }
93
+ copyList.push(Object.assign(Object.assign({}, current), { subIds: [current.subId] }));
94
+ return copyList;
95
+ }, []);
96
+ }
97
+ }
98
+ return subscriptions;
99
+ });
100
+ }
101
+ getSubscriptions(options) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ return this._getSubscriptions(undefined, options);
104
+ });
105
+ }
106
+ getSubscriptionsFor(addresses, options) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ return this._getSubscriptions(addresses, options);
109
+ });
110
+ }
111
+ }
@@ -0,0 +1,5 @@
1
+ import type { Interfaces } from '../../types';
2
+ import StrategiesAutomation from '../private/StrategiesAutomation';
3
+ export default class ArbitrumStrategies extends StrategiesAutomation {
4
+ constructor(args: Interfaces.Automation);
5
+ }
@@ -0,0 +1,7 @@
1
+ import StrategiesAutomation from '../private/StrategiesAutomation';
2
+ import { ChainId } from '../../types/enums';
3
+ export default class ArbitrumStrategies extends StrategiesAutomation {
4
+ constructor(args) {
5
+ super(Object.assign(Object.assign({}, args), { chainId: ChainId.Arbitrum }));
6
+ }
7
+ }
@@ -0,0 +1,5 @@
1
+ import type { Interfaces } from '../../types';
2
+ import StrategiesAutomation from '../private/StrategiesAutomation';
3
+ export default class EthereumStrategies extends StrategiesAutomation {
4
+ constructor(args: Interfaces.Automation);
5
+ }
@@ -0,0 +1,7 @@
1
+ import StrategiesAutomation from '../private/StrategiesAutomation';
2
+ import { ChainId } from '../../types/enums';
3
+ export default class EthereumStrategies extends StrategiesAutomation {
4
+ constructor(args) {
5
+ super(Object.assign(Object.assign({}, args), { chainId: ChainId.Ethereum }));
6
+ }
7
+ }
@@ -0,0 +1,5 @@
1
+ import type { Interfaces } from '../../types';
2
+ import StrategiesAutomation from '../private/StrategiesAutomation';
3
+ export default class OptimismStrategies extends StrategiesAutomation {
4
+ constructor(args: Interfaces.Automation);
5
+ }
@@ -0,0 +1,7 @@
1
+ import StrategiesAutomation from '../private/StrategiesAutomation';
2
+ import { ChainId } from '../../types/enums';
3
+ export default class OptimismStrategies extends StrategiesAutomation {
4
+ constructor(args) {
5
+ super(Object.assign(Object.assign({}, args), { chainId: ChainId.Optimism }));
6
+ }
7
+ }
@@ -0,0 +1,6 @@
1
+ import type { Interfaces } from '../../../types';
2
+ import type { Legacy_AaveV2Subscriptions } from '../../../types/contracts/generated';
3
+ import LegacyAutomation from '../../private/LegacyAutomation';
4
+ export default class LegacyAaveAutomation extends LegacyAutomation {
5
+ constructor(args: Interfaces.LegacyAutomation<Legacy_AaveV2Subscriptions>);
6
+ }
@@ -0,0 +1,14 @@
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 {
6
+ constructor(args) {
7
+ super({
8
+ provider: args.provider,
9
+ subscriptionsJson: makeLegacySubscriptionContract(args.provider, AaveV2SubscriptionsJson),
10
+ monitorAddress: '0x380982902872836ceC629171DaeAF42EcC02226e',
11
+ protocol: LEGACY_PROTOCOLS.AaveV2,
12
+ });
13
+ }
14
+ }
@@ -0,0 +1,6 @@
1
+ import type { Interfaces } from '../../../types';
2
+ import type { Legacy_CompoundV2Subscriptions } from '../../../types/contracts/generated';
3
+ import LegacyAutomation from '../../private/LegacyAutomation';
4
+ export default class LegacyAaveAutomation extends LegacyAutomation {
5
+ constructor(args: Interfaces.LegacyAutomation<Legacy_CompoundV2Subscriptions>);
6
+ }
@@ -0,0 +1,14 @@
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 {
6
+ constructor(args) {
7
+ super({
8
+ provider: args.provider,
9
+ subscriptionsJson: makeLegacySubscriptionContract(args.provider, CompoundV2SubscriptionsJson),
10
+ monitorAddress: '0xB1cF8DE8e791E4Ed1Bd86c03E2fc1f14389Cb10a',
11
+ protocol: LEGACY_PROTOCOLS.CompoundV2,
12
+ });
13
+ }
14
+ }
@@ -0,0 +1,6 @@
1
+ import type { Interfaces } from '../../../types';
2
+ import type { Legacy_MakerSubscriptions } from '../../../types/contracts/generated';
3
+ import LegacyAutomation from '../../private/LegacyAutomation';
4
+ export default class LegacyMakerAutomation extends LegacyAutomation {
5
+ constructor(args: Interfaces.LegacyAutomation<Legacy_MakerSubscriptions>);
6
+ }
@@ -0,0 +1,14 @@
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 {
6
+ constructor(args) {
7
+ super({
8
+ provider: args.provider,
9
+ subscriptionsJson: makeLegacySubscriptionContract(args.provider, MakerSubscriptionsJson),
10
+ monitorAddress: '0x1816A86C4DA59395522a42b871bf11A4E96A1C7a',
11
+ protocol: LEGACY_PROTOCOLS.MakerDAO,
12
+ });
13
+ }
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import Web3 from 'web3';
2
+ import Dec from 'decimal.js';
3
+ process.mockedWeb3 = new Web3('');
4
+ Dec.set({
5
+ rounding: Dec.ROUND_DOWN,
6
+ toExpPos: 9e15,
7
+ toExpNeg: -9e15,
8
+ precision: 100,
9
+ });
@@ -0,0 +1,23 @@
1
+ import type { ArbitrumBundleInfo, BundlesInfo, EthereumAddress, Interfaces, MainnetBundleInfo, MainnetStrategiesInfo, OptimismBundleInfo, StrategiesInfo } from '../types';
2
+ import { ProtocolIdentifiers, Strategies, Bundles } from '../types/enums';
3
+ export declare const ZERO_ADDRESS: EthereumAddress;
4
+ export declare const PROTOCOLS: Record<keyof typeof ProtocolIdentifiers.StrategiesAutomation, Interfaces.Protocol>;
5
+ export declare const LEGACY_PROTOCOLS: Record<keyof typeof ProtocolIdentifiers.LegacyAutomation, Interfaces.LegacyProtocol>;
6
+ export declare const MAINNET_STRATEGIES_INFO: MainnetStrategiesInfo;
7
+ export declare const OPTIMISM_STRATEGIES_INFO: {};
8
+ export declare const ARBITRUM_STRATEGIES_INFO: {};
9
+ export declare const STRATEGIES_INFO: StrategiesInfo;
10
+ export declare const STRATEGY_IDS: {
11
+ 1: typeof Strategies.MainnetIds;
12
+ 10: typeof Strategies.OptimismIds;
13
+ 42161: typeof Strategies.ArbitrumIds;
14
+ };
15
+ export declare const MAINNET_BUNDLES_INFO: MainnetBundleInfo;
16
+ export declare const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo;
17
+ export declare const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo;
18
+ export declare const BUNDLES_INFO: BundlesInfo;
19
+ export declare const BUNDLE_IDS: {
20
+ 1: typeof Bundles.MainnetIds;
21
+ 10: typeof Bundles.OptimismIds;
22
+ 42161: typeof Bundles.ArbitrumIds;
23
+ };