@super-protocol/sdk-js 0.15.3-beta.1 → 0.15.3-beta.2
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/build/connectors/BaseConnector.d.ts +2 -0
- package/build/connectors/BlockchainConnector.js +4 -0
- package/build/constants.d.ts +2 -0
- package/build/constants.js +3 -1
- package/build/store.d.ts +2 -0
- package/build/store.js +2 -0
- package/build/types/Web3.d.ts +1 -0
- package/build/utils/TxManager.d.ts +3 -1
- package/build/utils/TxManager.js +30 -16
- package/package.json +2 -1
|
@@ -69,6 +69,10 @@ class BlockchainConnector extends BaseConnector_1.BaseConnector {
|
|
|
69
69
|
store_1.default.gasLimitMultiplier = config.gasLimitMultiplier;
|
|
70
70
|
if (config === null || config === void 0 ? void 0 : config.gasPriceMultiplier)
|
|
71
71
|
store_1.default.gasPriceMultiplier = config.gasPriceMultiplier;
|
|
72
|
+
if (config === null || config === void 0 ? void 0 : config.txConcurrency)
|
|
73
|
+
store_1.default.txConcurrency = config.txConcurrency;
|
|
74
|
+
if (config === null || config === void 0 ? void 0 : config.txIntervalMs)
|
|
75
|
+
store_1.default.txIntervalMs = config.txIntervalMs;
|
|
72
76
|
Superpro_1.default.address = config.contractAddress;
|
|
73
77
|
this.contract = new store_1.default.web3Https.eth.Contract(app_json_1.default.abi, Superpro_1.default.address);
|
|
74
78
|
TxManager_1.default.init(store_1.default.web3Https);
|
package/build/constants.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export declare const defaultGasLimit = 7000000;
|
|
|
3
3
|
export declare const defaultGasPrice = "3000000000";
|
|
4
4
|
export declare const defaultGasPriceMultiplier = 1;
|
|
5
5
|
export declare const defaultGasLimitMultiplier = 1.2;
|
|
6
|
+
export declare const txConcurrency = 30;
|
|
7
|
+
export declare const txIntervalMs = 500;
|
|
6
8
|
export declare const ONE_DAY: number;
|
|
7
9
|
export declare const BLOCK_SIZE_TO_FETCH_TRANSACTION = 500;
|
|
8
10
|
export declare const POLYGON_MATIC_EVENT_PATH = "0x0000000000000000000000000000000000001010";
|
package/build/constants.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BLOCKCHAIN_CALL_RETRY_INTERVAL = exports.BLOCKCHAIN_CALL_RETRY_ATTEMPTS = exports.POLYGON_MATIC_EVENT_PATH = exports.BLOCK_SIZE_TO_FETCH_TRANSACTION = exports.ONE_DAY = exports.defaultGasLimitMultiplier = exports.defaultGasPriceMultiplier = exports.defaultGasPrice = exports.defaultGasLimit = exports.defaultBlockchainUrl = void 0;
|
|
3
|
+
exports.BLOCKCHAIN_CALL_RETRY_INTERVAL = exports.BLOCKCHAIN_CALL_RETRY_ATTEMPTS = exports.POLYGON_MATIC_EVENT_PATH = exports.BLOCK_SIZE_TO_FETCH_TRANSACTION = exports.ONE_DAY = exports.txIntervalMs = exports.txConcurrency = exports.defaultGasLimitMultiplier = exports.defaultGasPriceMultiplier = exports.defaultGasPrice = exports.defaultGasLimit = exports.defaultBlockchainUrl = void 0;
|
|
4
4
|
exports.defaultBlockchainUrl = "http://127.0.0.1:8545";
|
|
5
5
|
exports.defaultGasLimit = 7000000;
|
|
6
6
|
exports.defaultGasPrice = "3000000000";
|
|
7
7
|
exports.defaultGasPriceMultiplier = 1;
|
|
8
8
|
exports.defaultGasLimitMultiplier = 1.2;
|
|
9
|
+
exports.txConcurrency = 30;
|
|
10
|
+
exports.txIntervalMs = 500;
|
|
9
11
|
exports.ONE_DAY = 24 * 60 * 60;
|
|
10
12
|
exports.BLOCK_SIZE_TO_FETCH_TRANSACTION = 500;
|
|
11
13
|
exports.POLYGON_MATIC_EVENT_PATH = "0x0000000000000000000000000000000000001010";
|
package/build/store.d.ts
CHANGED
package/build/store.js
CHANGED
|
@@ -9,6 +9,8 @@ const store = {
|
|
|
9
9
|
gasLimitMultiplier: constants_1.defaultGasLimitMultiplier,
|
|
10
10
|
gasPriceMultiplier: constants_1.defaultGasPriceMultiplier,
|
|
11
11
|
gasPrice: undefined,
|
|
12
|
+
txConcurrency: constants_1.txConcurrency,
|
|
13
|
+
txIntervalMs: constants_1.txIntervalMs,
|
|
12
14
|
keys: {},
|
|
13
15
|
};
|
|
14
16
|
exports.default = store;
|
package/build/types/Web3.d.ts
CHANGED
|
@@ -19,11 +19,13 @@ declare class TxManager {
|
|
|
19
19
|
private static web3;
|
|
20
20
|
private static logger;
|
|
21
21
|
private static nonceTrackers;
|
|
22
|
+
private static queues;
|
|
22
23
|
static init(web3: Web3): void;
|
|
23
24
|
private static checkIfInitialized;
|
|
24
25
|
static initAccount(address: string): Promise<void>;
|
|
25
26
|
static execute(method: (...args: ArgumentsType) => MethodReturnType, args: ArgumentsType, transactionOptions?: TransactionOptions, to?: string): Promise<TransactionReceipt>;
|
|
27
|
+
static publishTransaction(txData: Record<string, any>, transactionOptions?: TransactionOptions, transactionCall?: MethodReturnType): Promise<any>;
|
|
26
28
|
static dryRun(method: (...args: ArgumentsType) => MethodReturnType, args: ArgumentsType, transactionOptions?: TransactionOptions): Promise<any>;
|
|
27
|
-
static
|
|
29
|
+
private static _publishTransaction;
|
|
28
30
|
}
|
|
29
31
|
export default TxManager;
|
package/build/utils/TxManager.js
CHANGED
|
@@ -20,6 +20,7 @@ const utils_1 = require("../utils");
|
|
|
20
20
|
const Superpro_1 = __importDefault(require("../staticModels/Superpro"));
|
|
21
21
|
const constants_1 = require("../constants");
|
|
22
22
|
const lodash_1 = __importDefault(require("lodash"));
|
|
23
|
+
const bottleneck_1 = __importDefault(require("bottleneck"));
|
|
23
24
|
class Web3TransactionError extends Error {
|
|
24
25
|
constructor(originalError, message) {
|
|
25
26
|
super(message);
|
|
@@ -61,6 +62,24 @@ class TxManager {
|
|
|
61
62
|
return yield TxManager.publishTransaction(txData, transactionOptions, transaction);
|
|
62
63
|
});
|
|
63
64
|
}
|
|
65
|
+
static publishTransaction(txData, transactionOptions, transactionCall) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
this.checkIfInitialized();
|
|
68
|
+
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
69
|
+
const options = yield (0, utils_1.createTransactionOptions)(Object.assign({}, transactionOptions));
|
|
70
|
+
options.web3 = (transactionOptions === null || transactionOptions === void 0 ? void 0 : transactionOptions.web3) || this.web3;
|
|
71
|
+
if (!options.from) {
|
|
72
|
+
throw Error("From account is undefined. You should pass it to transactionOptions or init action account.");
|
|
73
|
+
}
|
|
74
|
+
if (!this.queues[options.from]) {
|
|
75
|
+
this.queues[options.from] = new bottleneck_1.default({
|
|
76
|
+
maxConcurrent: store_1.default.txConcurrency,
|
|
77
|
+
minTime: store_1.default.txIntervalMs,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return this.queues[options.from].schedule(() => __awaiter(this, void 0, void 0, function* () { return TxManager._publishTransaction(txData, options, transactionCall); }));
|
|
81
|
+
});
|
|
82
|
+
}
|
|
64
83
|
static dryRun(method, args, transactionOptions) {
|
|
65
84
|
var _a;
|
|
66
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -77,17 +96,11 @@ class TxManager {
|
|
|
77
96
|
}
|
|
78
97
|
});
|
|
79
98
|
}
|
|
80
|
-
static
|
|
99
|
+
static _publishTransaction(txData, transactionOptions, transactionCall) {
|
|
81
100
|
var _a;
|
|
82
101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
|
|
84
|
-
(
|
|
85
|
-
const web3 = (transactionOptions === null || transactionOptions === void 0 ? void 0 : transactionOptions.web3) || this.web3;
|
|
86
|
-
const options = yield (0, utils_1.createTransactionOptions)(Object.assign({}, transactionOptions));
|
|
87
|
-
if (!options.from) {
|
|
88
|
-
throw Error("From account is undefined. You should pass it to transactionOptions or init action account.");
|
|
89
|
-
}
|
|
90
|
-
txData = Object.assign(Object.assign({}, options), txData);
|
|
102
|
+
const { web3 } = transactionOptions;
|
|
103
|
+
txData = Object.assign(Object.assign({}, transactionOptions), txData);
|
|
91
104
|
if (transactionCall) {
|
|
92
105
|
let estimatedGas;
|
|
93
106
|
try {
|
|
@@ -101,25 +114,25 @@ class TxManager {
|
|
|
101
114
|
txData.gas = Math.ceil(txData.gas * store_1.default.gasLimitMultiplier);
|
|
102
115
|
// defaultGasLimit is max gas limit
|
|
103
116
|
txData.gas = txData.gas < constants_1.defaultGasLimit ? txData.gas : constants_1.defaultGasLimit;
|
|
104
|
-
if (
|
|
105
|
-
if (
|
|
117
|
+
if (transactionOptions.gas) {
|
|
118
|
+
if (transactionOptions.gas < estimatedGas) {
|
|
106
119
|
TxManager.logger.warn({
|
|
107
120
|
estimated: estimatedGas,
|
|
108
|
-
specified:
|
|
121
|
+
specified: transactionOptions.gas,
|
|
109
122
|
}, "Fail to calculate estimated gas");
|
|
110
123
|
}
|
|
111
|
-
txData.gas =
|
|
124
|
+
txData.gas = transactionOptions.gas;
|
|
112
125
|
}
|
|
113
126
|
txData.gasPrice = Math.ceil(txData.gasPrice * store_1.default.gasPriceMultiplier);
|
|
114
127
|
}
|
|
115
128
|
let nonceTracker;
|
|
116
129
|
// TODO: Consider a better way to organize different strategies for publishing transactions.
|
|
117
|
-
if (!(0, utils_1.checkForUsingExternalTxManager)(transactionOptions) && this.nonceTrackers[
|
|
118
|
-
nonceTracker = this.nonceTrackers[
|
|
130
|
+
if (!(0, utils_1.checkForUsingExternalTxManager)(transactionOptions) && this.nonceTrackers[transactionOptions.from]) {
|
|
131
|
+
nonceTracker = this.nonceTrackers[transactionOptions.from];
|
|
119
132
|
yield nonceTracker.onTransactionStartPublishing();
|
|
120
133
|
txData.nonce = nonceTracker.consumeNonce();
|
|
121
134
|
}
|
|
122
|
-
const signingKey = store_1.default.keys[
|
|
135
|
+
const signingKey = store_1.default.keys[transactionOptions.from];
|
|
123
136
|
try {
|
|
124
137
|
let transactionResultData;
|
|
125
138
|
if (signingKey) {
|
|
@@ -165,4 +178,5 @@ class TxManager {
|
|
|
165
178
|
}
|
|
166
179
|
TxManager.logger = logger_1.default.child({ className: "TxManager" });
|
|
167
180
|
TxManager.nonceTrackers = {};
|
|
181
|
+
TxManager.queues = {};
|
|
168
182
|
exports.default = TxManager;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@super-protocol/sdk-js",
|
|
3
|
-
"version": "0.15.3-beta.
|
|
3
|
+
"version": "0.15.3-beta.2",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"@super-protocol/tee-lib": "^0.1.2",
|
|
58
58
|
"@super-protocol/uplink-nodejs": "1.2.16",
|
|
59
59
|
"aws-sdk": "^2.1418.0",
|
|
60
|
+
"bottleneck": "^2.19.5",
|
|
60
61
|
"ethers": "^5.5.3",
|
|
61
62
|
"hybrid-crypto-js": "^0.2.4",
|
|
62
63
|
"lodash": "^4.17.21",
|