@defisaver/automation-sdk 2.0.2 → 2.0.4
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 -275
- 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 +132 -105
- package/esm/services/strategySubService.js +90 -61
- package/esm/services/subDataService.d.ts +5 -0
- package/esm/services/subDataService.js +158 -145
- package/esm/services/triggerService.d.ts +5 -5
- package/esm/services/triggerService.js +124 -94
- 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.js +17 -14
- package/esm/types/index.js +2 -1
- package/package.json +11 -7
- package/src/automation/private/LegacyAutomation.ts +11 -10
- package/src/automation/private/StrategiesAutomation.ts +5 -6
- package/src/configuration.ts +0 -3
- package/src/index.ts +0 -1
- package/src/services/ethereumService.ts +6 -6
- package/src/services/strategiesService.ts +2 -2
- package/src/services/subDataService.ts +84 -76
- package/src/services/triggerService.ts +83 -83
- package/src/services/utils.test.ts +414 -0
- package/src/services/utils.ts +6 -7
- package/tsconfig.json +1 -1
- package/umd/index.js +7045 -4124
- package/src/types/typings/process.d.ts +0 -9
- package/yarn-error.log +0 -7233
package/esm/index.js
CHANGED
|
@@ -1,23 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
// TODO
|
|
2
3
|
// [] Check @ts-ignores and PlaceholderType
|
|
3
4
|
// [] Improve typing for subData, trigger and strategySub services
|
|
4
5
|
// [] Make possible to use any provider not only web3 (This requires changes throughout the package)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
|
+
if (mod && mod.__esModule) return mod;
|
|
24
|
+
var result = {};
|
|
25
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
26
|
+
__setModuleDefault(result, mod);
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
30
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
31
|
+
};
|
|
32
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
+
exports.strategiesService = exports.constants = exports.enums = exports.utils = exports.strategySubService = exports.subDataService = exports.triggerService = exports.ArbitrumStrategies = exports.OptimismStrategies = exports.EthereumStrategies = exports.LegacyCompoundAutomation = exports.LegacyAaveAutomation = exports.LegacyMakerAutomation = void 0;
|
|
34
|
+
require("./configuration");
|
|
35
|
+
const LegacyMakerAutomation_1 = __importDefault(require("./automation/public/legacy/LegacyMakerAutomation"));
|
|
36
|
+
exports.LegacyMakerAutomation = LegacyMakerAutomation_1.default;
|
|
37
|
+
const LegacyAaveAutomation_1 = __importDefault(require("./automation/public/legacy/LegacyAaveAutomation"));
|
|
38
|
+
exports.LegacyAaveAutomation = LegacyAaveAutomation_1.default;
|
|
39
|
+
const LegacyCompoundAutomation_1 = __importDefault(require("./automation/public/legacy/LegacyCompoundAutomation"));
|
|
40
|
+
exports.LegacyCompoundAutomation = LegacyCompoundAutomation_1.default;
|
|
41
|
+
const EthereumStrategies_1 = __importDefault(require("./automation/public/EthereumStrategies"));
|
|
42
|
+
exports.EthereumStrategies = EthereumStrategies_1.default;
|
|
43
|
+
const OptimismStrategies_1 = __importDefault(require("./automation/public/OptimismStrategies"));
|
|
44
|
+
exports.OptimismStrategies = OptimismStrategies_1.default;
|
|
45
|
+
const ArbitrumStrategies_1 = __importDefault(require("./automation/public/ArbitrumStrategies"));
|
|
46
|
+
exports.ArbitrumStrategies = ArbitrumStrategies_1.default;
|
|
47
|
+
const triggerService = __importStar(require("./services/triggerService"));
|
|
48
|
+
exports.triggerService = triggerService;
|
|
49
|
+
const subDataService = __importStar(require("./services/subDataService"));
|
|
50
|
+
exports.subDataService = subDataService;
|
|
51
|
+
const strategySubService = __importStar(require("./services/strategySubService"));
|
|
52
|
+
exports.strategySubService = strategySubService;
|
|
53
|
+
const strategiesService = __importStar(require("./services/strategiesService"));
|
|
54
|
+
exports.strategiesService = strategiesService;
|
|
55
|
+
const constants = __importStar(require("./constants"));
|
|
56
|
+
exports.constants = constants;
|
|
57
|
+
const enums = __importStar(require("./types/enums"));
|
|
58
|
+
exports.enums = enums;
|
|
59
|
+
const utils_1 = require("./services/utils");
|
|
20
60
|
const utils = {
|
|
21
|
-
getRatioStateInfoForAaveCloseStrategy, compareSubHashes, encodeSubId,
|
|
61
|
+
getRatioStateInfoForAaveCloseStrategy: utils_1.getRatioStateInfoForAaveCloseStrategy, compareSubHashes: utils_1.compareSubHashes, encodeSubId: utils_1.encodeSubId,
|
|
22
62
|
};
|
|
23
|
-
|
|
63
|
+
exports.utils = utils;
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeLegacySubscriptionContract = exports.makeAuthCheckerContract = exports.makeSubStorageContract = exports.makeUniMulticallContract = exports.getAbiItem = void 0;
|
|
4
|
+
const abis_1 = require("../abis");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const enums_1 = require("../types/enums");
|
|
7
|
+
function getAbiItem(abi, itemName) {
|
|
5
8
|
const abiItem = abi.find(i => i.name === itemName);
|
|
6
|
-
if (isDefined(abiItem)) {
|
|
9
|
+
if ((0, utils_1.isDefined)(abiItem)) {
|
|
7
10
|
return abiItem;
|
|
8
11
|
}
|
|
9
12
|
throw new Error(`Can't find abi item for itemName: ${itemName}`);
|
|
10
13
|
}
|
|
14
|
+
exports.getAbiItem = getAbiItem;
|
|
11
15
|
function makeContract(web3, contractJson, chainId) {
|
|
12
16
|
const { abi } = contractJson;
|
|
13
17
|
let _address = '';
|
|
@@ -15,7 +19,7 @@ function makeContract(web3, contractJson, chainId) {
|
|
|
15
19
|
if (contractJson.networks) {
|
|
16
20
|
const { address, createdBlock } = contractJson.networks[chainId];
|
|
17
21
|
_address = address;
|
|
18
|
-
if (isDefined(createdBlock)) {
|
|
22
|
+
if ((0, utils_1.isDefined)(createdBlock)) {
|
|
19
23
|
_createdBlock = createdBlock;
|
|
20
24
|
}
|
|
21
25
|
}
|
|
@@ -26,15 +30,19 @@ function makeContract(web3, contractJson, chainId) {
|
|
|
26
30
|
contract: new web3.eth.Contract(abi, _address),
|
|
27
31
|
};
|
|
28
32
|
}
|
|
29
|
-
|
|
30
|
-
return makeContract(web3, UniMulticallJson, chainId);
|
|
33
|
+
function makeUniMulticallContract(web3, chainId) {
|
|
34
|
+
return makeContract(web3, abis_1.UniMulticallJson, chainId);
|
|
31
35
|
}
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
exports.makeUniMulticallContract = makeUniMulticallContract;
|
|
37
|
+
function makeSubStorageContract(web3, chainId) {
|
|
38
|
+
return makeContract(web3, abis_1.SubStorageJson, chainId);
|
|
34
39
|
}
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
exports.makeSubStorageContract = makeSubStorageContract;
|
|
41
|
+
function makeAuthCheckerContract(web3, chainId) {
|
|
42
|
+
return makeContract(web3, abis_1.AuthCheckJson, chainId);
|
|
37
43
|
}
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
exports.makeAuthCheckerContract = makeAuthCheckerContract;
|
|
45
|
+
function makeLegacySubscriptionContract(web3, contractJson) {
|
|
46
|
+
return makeContract(web3, contractJson, enums_1.ChainId.Ethereum);
|
|
40
47
|
}
|
|
48
|
+
exports.makeLegacySubscriptionContract = makeLegacySubscriptionContract;
|
|
@@ -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,14 +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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
+
exports.getEventsFromContract = exports.multicall = void 0;
|
|
16
|
+
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
17
|
+
const contractService_1 = require("./contractService");
|
|
18
|
+
const utils_1 = require("./utils");
|
|
19
|
+
function multicall(web3, chainId, calls, block = 'latest') {
|
|
14
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
const multicallContract = makeUniMulticallContract(web3, chainId).contract;
|
|
21
|
+
const multicallContract = (0, contractService_1.makeUniMulticallContract)(web3, chainId).contract;
|
|
16
22
|
const formattedCalls = calls.map((call) => ({
|
|
17
|
-
callData:
|
|
23
|
+
callData: web3_eth_abi_1.default.encodeFunctionCall(call.abiItem, call.params),
|
|
18
24
|
target: call.target || '0x0',
|
|
19
25
|
gasLimit: call.gasLimit || 1e6,
|
|
20
26
|
}));
|
|
@@ -22,20 +28,22 @@ export function multicall(web3, chainId, calls, block = 'latest') {
|
|
|
22
28
|
let formattedResult = [];
|
|
23
29
|
callResult.returnData.forEach(([success, gasUsed, result], i) => {
|
|
24
30
|
const formattedRes = (result !== '0x'
|
|
25
|
-
?
|
|
31
|
+
? web3_eth_abi_1.default.decodeParameters(calls[i].abiItem.outputs, result)
|
|
26
32
|
: undefined);
|
|
27
33
|
formattedResult = [...formattedResult, formattedRes];
|
|
28
34
|
});
|
|
29
35
|
return formattedResult;
|
|
30
36
|
});
|
|
31
37
|
}
|
|
32
|
-
|
|
38
|
+
exports.multicall = multicall;
|
|
39
|
+
function getEventsFromContract(contractWithMeta, contractWithMetaFork, event, options) {
|
|
33
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
const events = yield contractWithMeta.contract.getPastEvents(event, Object.assign({}, addToObjectIf(isDefined(options), Object.assign(Object.assign({}, options), { fromBlock: contractWithMeta.createdBlock }))));
|
|
41
|
+
const events = yield contractWithMeta.contract.getPastEvents(event, Object.assign({}, (0, utils_1.addToObjectIf)((0, utils_1.isDefined)(options), Object.assign(Object.assign({}, options), { fromBlock: contractWithMeta.createdBlock }))));
|
|
35
42
|
let eventsFork = [];
|
|
36
43
|
if (contractWithMetaFork) {
|
|
37
|
-
eventsFork = yield contractWithMetaFork.contract.getPastEvents(event, Object.assign({}, addToObjectIf(isDefined(options), Object.assign(Object.assign({}, options), { toBlock: 'latest' }))));
|
|
44
|
+
eventsFork = yield contractWithMetaFork.contract.getPastEvents(event, Object.assign({}, (0, utils_1.addToObjectIf)((0, utils_1.isDefined)(options), Object.assign(Object.assign({}, options), { toBlock: 'latest' }))));
|
|
38
45
|
}
|
|
39
46
|
return [...events, ...eventsFork];
|
|
40
47
|
});
|
|
41
48
|
}
|
|
49
|
+
exports.getEventsFromContract = getEventsFromContract;
|