polkamarkets-js 3.4.4 → 3.4.6
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/abis/Multicall3.json +1 -0
- package/package.json +1 -1
- package/src/Application.js +16 -0
- package/src/interfaces/index.js +1 -0
- package/src/models/Multicall3Contract.js +14 -0
- package/src/models/index.js +3 -1
- package/src/utils/Contract.js +54 -31
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"abi":[{"inputs":[{"components":[{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct Multicall3.Call[]","name":"calls","type":"tuple[]"}],"name":"aggregate","outputs":[{"internalType":"uint256","name":"blockNumber","type":"uint256"},{"internalType":"bytes[]","name":"returnData","type":"bytes[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"target","type":"address"},{"internalType":"bool","name":"allowFailure","type":"bool"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct Multicall3.Call3[]","name":"calls","type":"tuple[]"}],"name":"aggregate3","outputs":[{"components":[{"internalType":"bool","name":"success","type":"bool"},{"internalType":"bytes","name":"returnData","type":"bytes"}],"internalType":"struct Multicall3.Result[]","name":"returnData","type":"tuple[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"target","type":"address"},{"internalType":"bool","name":"allowFailure","type":"bool"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct Multicall3.Call3Value[]","name":"calls","type":"tuple[]"}],"name":"aggregate3Value","outputs":[{"components":[{"internalType":"bool","name":"success","type":"bool"},{"internalType":"bytes","name":"returnData","type":"bytes"}],"internalType":"struct Multicall3.Result[]","name":"returnData","type":"tuple[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct Multicall3.Call[]","name":"calls","type":"tuple[]"}],"name":"blockAndAggregate","outputs":[{"internalType":"uint256","name":"blockNumber","type":"uint256"},{"internalType":"bytes32","name":"blockHash","type":"bytes32"},{"components":[{"internalType":"bool","name":"success","type":"bool"},{"internalType":"bytes","name":"returnData","type":"bytes"}],"internalType":"struct Multicall3.Result[]","name":"returnData","type":"tuple[]"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"getBasefee","outputs":[{"internalType":"uint256","name":"basefee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"blockNumber","type":"uint256"}],"name":"getBlockHash","outputs":[{"internalType":"bytes32","name":"blockHash","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBlockNumber","outputs":[{"internalType":"uint256","name":"blockNumber","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getChainId","outputs":[{"internalType":"uint256","name":"chainid","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCurrentBlockCoinbase","outputs":[{"internalType":"address","name":"coinbase","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCurrentBlockDifficulty","outputs":[{"internalType":"uint256","name":"difficulty","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCurrentBlockGasLimit","outputs":[{"internalType":"uint256","name":"gaslimit","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCurrentBlockTimestamp","outputs":[{"internalType":"uint256","name":"timestamp","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"getEthBalance","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLastBlockHash","outputs":[{"internalType":"bytes32","name":"blockHash","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"requireSuccess","type":"bool"},{"components":[{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct Multicall3.Call[]","name":"calls","type":"tuple[]"}],"name":"tryAggregate","outputs":[{"components":[{"internalType":"bool","name":"success","type":"bool"},{"internalType":"bytes","name":"returnData","type":"bytes"}],"internalType":"struct Multicall3.Result[]","name":"returnData","type":"tuple[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bool","name":"requireSuccess","type":"bool"},{"components":[{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct Multicall3.Call[]","name":"calls","type":"tuple[]"}],"name":"tryBlockAndAggregate","outputs":[{"internalType":"uint256","name":"blockNumber","type":"uint256"},{"internalType":"bytes32","name":"blockHash","type":"bytes32"},{"components":[{"internalType":"bool","name":"success","type":"bool"},{"internalType":"bytes","name":"returnData","type":"bytes"}],"internalType":"struct Multicall3.Result[]","name":"returnData","type":"tuple[]"}],"stateMutability":"payable","type":"function"}]}
|
package/package.json
CHANGED
package/src/Application.js
CHANGED
|
@@ -18,6 +18,7 @@ const WETH9Contract = require("./models/index").WETH9Contract;
|
|
|
18
18
|
const ArbitrationContract = require("./models/index").ArbitrationContract;
|
|
19
19
|
const ArbitrationProxyContract = require("./models/index").ArbitrationProxyContract;
|
|
20
20
|
const MerkleRewardsDistributorContract = require("./models/index").MerkleRewardsDistributorContract;
|
|
21
|
+
const Multicall3Contract = require("./models/index").Multicall3Contract;
|
|
21
22
|
|
|
22
23
|
const DualProvider = require("./utils/DualProvider");
|
|
23
24
|
const Account = require('./utils/Account');
|
|
@@ -428,6 +429,21 @@ class Application {
|
|
|
428
429
|
}
|
|
429
430
|
}
|
|
430
431
|
|
|
432
|
+
/**
|
|
433
|
+
* @name getMulticall3Contract
|
|
434
|
+
* @param {Address} ContractAddress (Opt) If it is deployed
|
|
435
|
+
* @description Create a Multicall3 Contract
|
|
436
|
+
*/
|
|
437
|
+
getMulticall3Contract({ contractAddress = null } = {}) {
|
|
438
|
+
try {
|
|
439
|
+
return new Multicall3Contract({
|
|
440
|
+
...this.contractDefaultParams(contractAddress)
|
|
441
|
+
});
|
|
442
|
+
} catch (err) {
|
|
443
|
+
throw err;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
431
447
|
/***********/
|
|
432
448
|
/** UTILS **/
|
|
433
449
|
/***********/
|
package/src/interfaces/index.js
CHANGED
|
@@ -16,6 +16,7 @@ let index = {
|
|
|
16
16
|
predictionV3Querier: require("../../abis/PredictionMarketV3Querier.json"),
|
|
17
17
|
realitio: require("../../abis/RealitioERC20.json"),
|
|
18
18
|
merkleRewardsDistributor: require("../../abis/MerkleRewardsDistributor.json"),
|
|
19
|
+
multicall3: require("../../abis/Multicall3.json"),
|
|
19
20
|
voting: require("../../abis/Voting.json"),
|
|
20
21
|
weth: require("../../abis/WETH9.json"),
|
|
21
22
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const IContract = require('./IContract');
|
|
2
|
+
|
|
3
|
+
const multicall3 = require('../interfaces').multicall3;
|
|
4
|
+
|
|
5
|
+
class Multicall3Contract extends IContract {
|
|
6
|
+
constructor(params) {
|
|
7
|
+
super({ abi: multicall3, ...params });
|
|
8
|
+
// used by bepro-api routing (contract name in /call?contract=...)
|
|
9
|
+
this.contractName = 'multicall3';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = Multicall3Contract;
|
|
14
|
+
|
package/src/models/index.js
CHANGED
|
@@ -15,6 +15,7 @@ const WETH9Contract = require('./WETH9Contract');
|
|
|
15
15
|
const ArbitrationContract = require('./ArbitrationContract');
|
|
16
16
|
const ArbitrationProxyContract = require('./ArbitrationProxyContract');
|
|
17
17
|
const MerkleRewardsDistributorContract = require('./MerkleRewardsDistributorContract');
|
|
18
|
+
const Multicall3Contract = require('./Multicall3Contract');
|
|
18
19
|
|
|
19
20
|
module.exports = {
|
|
20
21
|
ERC20Contract,
|
|
@@ -33,5 +34,6 @@ module.exports = {
|
|
|
33
34
|
ArbitrationProxyContract,
|
|
34
35
|
PredictionMarketV3FactoryContract,
|
|
35
36
|
PredictionMarketV3ControllerContract,
|
|
36
|
-
MerkleRewardsDistributorContract
|
|
37
|
+
MerkleRewardsDistributorContract,
|
|
38
|
+
Multicall3Contract
|
|
37
39
|
}
|
package/src/utils/Contract.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
class Contract {
|
|
3
2
|
constructor(web3, contract_json, address) {
|
|
4
3
|
this.web3 = web3;
|
|
@@ -8,7 +7,7 @@ class Contract {
|
|
|
8
7
|
this.contract = new web3.eth.Contract(contract_json.abi, address);
|
|
9
8
|
}
|
|
10
9
|
|
|
11
|
-
async deploy(account, abi, byteCode, args = [], callback = () => {
|
|
10
|
+
async deploy(account, abi, byteCode, args = [], callback = () => {}) {
|
|
12
11
|
this.contract = new this.web3.eth.Contract(abi);
|
|
13
12
|
if (account) {
|
|
14
13
|
const data = this.contract.deploy({
|
|
@@ -16,11 +15,13 @@ class Contract {
|
|
|
16
15
|
arguments: args,
|
|
17
16
|
});
|
|
18
17
|
|
|
19
|
-
const rawTransaction = (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
const rawTransaction = (
|
|
19
|
+
await account.getAccount().signTransaction({
|
|
20
|
+
data: data.encodeABI(),
|
|
21
|
+
from: account.getAddress(),
|
|
22
|
+
gas: 5913388,
|
|
23
|
+
})
|
|
24
|
+
).rawTransaction;
|
|
24
25
|
|
|
25
26
|
return await this.web3.eth.sendSignedTransaction(rawTransaction);
|
|
26
27
|
} else {
|
|
@@ -36,47 +37,67 @@ class Contract {
|
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
async __metamaskDeploy({ byteCode, args, acc, callback = () => {
|
|
40
|
+
async __metamaskDeploy({ byteCode, args, acc, callback = () => {} }) {
|
|
40
41
|
return new Promise((resolve, reject) => {
|
|
41
42
|
try {
|
|
42
43
|
this.getContract()
|
|
43
44
|
.deploy({
|
|
44
45
|
data: byteCode,
|
|
45
46
|
arguments: args,
|
|
46
|
-
})
|
|
47
|
-
.
|
|
48
|
-
|
|
47
|
+
})
|
|
48
|
+
.send({ from: acc })
|
|
49
|
+
.on("confirmation", (confirmationNumber, receipt) => {
|
|
50
|
+
callback(confirmationNumber);
|
|
49
51
|
if (confirmationNumber > 0) {
|
|
50
52
|
resolve(receipt);
|
|
51
53
|
}
|
|
52
54
|
})
|
|
53
|
-
.on(
|
|
55
|
+
.on("error", (err) => {
|
|
56
|
+
reject(err);
|
|
57
|
+
});
|
|
54
58
|
} catch (err) {
|
|
55
59
|
reject(err);
|
|
56
60
|
}
|
|
57
|
-
})
|
|
61
|
+
});
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
async use(contract_json, address) {
|
|
61
65
|
this.json = contract_json;
|
|
62
66
|
this.abi = contract_json.abi;
|
|
63
67
|
this.address = address ? address : this.address;
|
|
64
|
-
this.contract = new this.web3.eth.Contract(
|
|
65
|
-
contract_json.abi,
|
|
66
|
-
this.address
|
|
67
|
-
);
|
|
68
|
+
this.contract = new this.web3.eth.Contract(contract_json.abi, this.address);
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
async
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
async getSmartGasPrice() {
|
|
72
|
+
try {
|
|
73
|
+
const baseGasPrice = await this.web3.eth.getGasPrice();
|
|
74
|
+
const latestBlock = await this.web3.eth.getBlock("latest");
|
|
75
|
+
const utilization = (latestBlock.gasUsed / latestBlock.gasLimit) * 100;
|
|
76
|
+
|
|
77
|
+
const baseGasPriceBigInt = BigInt(baseGasPrice);
|
|
78
|
+
|
|
79
|
+
// Continuous function: multiplier = 1.2 + 0.8 * (utilization/100)^2
|
|
80
|
+
// This creates a smooth curve from 1.2x to 2.0x with accelerated scaling at high utilization
|
|
81
|
+
const utilizationRatio = Math.min(utilization / 100, 1.0); // Cap at 100%
|
|
82
|
+
const multiplierFloat = 1.2 + 0.8 * Math.pow(utilizationRatio, 2);
|
|
83
|
+
const multiplier = Math.round(multiplierFloat * 100); // Convert to integer for BigInt math
|
|
84
|
+
|
|
85
|
+
const smartGasPrice = (baseGasPriceBigInt * BigInt(multiplier)) / BigInt(100);
|
|
86
|
+
return smartGasPrice.toString();
|
|
87
|
+
} catch (err) {
|
|
73
88
|
try {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
} catch (
|
|
89
|
+
const fallbackPrice = await this.web3.eth.getGasPrice();
|
|
90
|
+
return ((BigInt(fallbackPrice) * BigInt(200)) / BigInt(100)).toString();
|
|
91
|
+
} catch (fallbackErr) {
|
|
77
92
|
// should be non-blocking, defaulting to 10 gwei
|
|
78
|
-
|
|
93
|
+
return '10000000000';
|
|
79
94
|
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async send(account, byteCode, value = "0x0", callback = () => {}) {
|
|
99
|
+
return new Promise(async (resolve, reject) => {
|
|
100
|
+
const gasPrice = await this.getSmartGasPrice();
|
|
80
101
|
|
|
81
102
|
let tx = {
|
|
82
103
|
data: byteCode,
|
|
@@ -84,20 +105,22 @@ class Contract {
|
|
|
84
105
|
to: this.address,
|
|
85
106
|
gas: 4430000,
|
|
86
107
|
gasPrice,
|
|
87
|
-
value: value ? value :
|
|
88
|
-
}
|
|
108
|
+
value: value ? value : "0x0",
|
|
109
|
+
};
|
|
89
110
|
|
|
90
111
|
let result = await account.signTransaction(tx);
|
|
91
|
-
this.web3.eth
|
|
92
|
-
.
|
|
112
|
+
this.web3.eth
|
|
113
|
+
.sendSignedTransaction(result.rawTransaction)
|
|
114
|
+
.on("confirmation", (confirmationNumber, receipt) => {
|
|
93
115
|
callback(confirmationNumber);
|
|
94
116
|
if (confirmationNumber > 0) {
|
|
95
117
|
resolve(receipt);
|
|
96
118
|
}
|
|
97
119
|
})
|
|
98
|
-
.on(
|
|
99
|
-
|
|
100
|
-
|
|
120
|
+
.on("error", (err) => {
|
|
121
|
+
reject(err);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
101
124
|
}
|
|
102
125
|
|
|
103
126
|
getContract() {
|