@defisaver/automation-sdk 2.0.1 → 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.
- package/.eslintrc.js +1 -0
- package/esm/abis/index.js +27 -15
- package/esm/automation/private/Automation.js +9 -6
- package/esm/automation/private/LegacyAutomation.d.ts +5 -5
- package/esm/automation/private/LegacyAutomation.js +30 -23
- package/esm/automation/private/LegacyProtocol.js +4 -1
- package/esm/automation/private/Protocol.js +4 -1
- package/esm/automation/private/StrategiesAutomation.d.ts +2 -2
- package/esm/automation/private/StrategiesAutomation.js +27 -21
- package/esm/automation/public/ArbitrumStrategies.js +10 -4
- package/esm/automation/public/EthereumStrategies.js +10 -4
- package/esm/automation/public/OptimismStrategies.js +10 -4
- package/esm/automation/public/legacy/LegacyAaveAutomation.js +13 -7
- package/esm/automation/public/legacy/LegacyCompoundAutomation.js +13 -7
- package/esm/automation/public/legacy/LegacyMakerAutomation.js +13 -7
- package/esm/configuration.js +8 -5
- package/esm/constants/index.js +281 -265
- package/esm/index.js +57 -17
- package/esm/services/contractService.js +22 -14
- package/esm/services/ethereumService.js +18 -10
- package/esm/services/strategiesService.js +144 -100
- package/esm/services/strategySubService.d.ts +2 -0
- package/esm/services/strategySubService.js +100 -55
- package/esm/services/subDataService.d.ts +12 -0
- package/esm/services/subDataService.js +165 -127
- package/esm/services/triggerService.d.ts +8 -8
- package/esm/services/triggerService.js +125 -95
- package/esm/services/utils.js +82 -33
- package/esm/services/utils.test.d.ts +1 -0
- package/esm/services/utils.test.js +362 -0
- package/esm/types/contracts/generated/Erc20.js +2 -1
- package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.js +2 -1
- package/esm/types/contracts/generated/Legacy_AuthCheck.js +2 -1
- package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +2 -1
- package/esm/types/contracts/generated/Legacy_MakerSubscriptions.js +2 -1
- package/esm/types/contracts/generated/SubStorage.js +2 -1
- package/esm/types/contracts/generated/UniMulticall.js +2 -1
- package/esm/types/contracts/generated/index.js +2 -1
- package/esm/types/contracts/generated/types.js +2 -1
- package/esm/types/enums.d.ts +9 -1
- package/esm/types/enums.js +24 -12
- package/esm/types/index.js +2 -1
- package/package.json +12 -8
- package/src/automation/private/LegacyAutomation.ts +11 -10
- package/src/automation/private/StrategiesAutomation.ts +5 -6
- package/src/configuration.ts +0 -3
- package/src/constants/index.ts +10 -0
- package/src/index.ts +0 -1
- package/src/services/ethereumService.ts +6 -6
- package/src/services/strategiesService.ts +24 -0
- package/src/services/strategySubService.ts +30 -0
- package/src/services/subDataService.ts +104 -67
- package/src/services/triggerService.ts +86 -85
- package/src/services/utils.test.ts +414 -0
- package/src/services/utils.ts +6 -7
- package/src/types/enums.ts +9 -0
- package/tsconfig.json +1 -1
- package/umd/index.js +7142 -4138
- package/src/types/typings/process.d.ts +0 -9
- package/yarn-error.log +0 -7233
package/.eslintrc.js
CHANGED
package/esm/abis/index.js
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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(
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
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
|
-
|
|
11
|
-
|
|
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
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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:
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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;
|
package/esm/configuration.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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,
|