@pancakeswap/multicall 3.2.3 → 3.3.0
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/dist/abis/IMulticall3.d.ts +237 -0
- package/dist/abis/IMulticall3.d.ts.map +1 -0
- package/dist/constants/contracts.d.ts +4 -0
- package/dist/constants/contracts.d.ts.map +1 -1
- package/dist/getMulticallContract.d.ts +2 -1
- package/dist/getMulticallContract.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +191 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +188 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -5
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
export declare const multicall3ABI: readonly [{
|
|
2
|
+
readonly inputs: readonly [{
|
|
3
|
+
readonly components: readonly [{
|
|
4
|
+
readonly internalType: "address";
|
|
5
|
+
readonly name: "target";
|
|
6
|
+
readonly type: "address";
|
|
7
|
+
}, {
|
|
8
|
+
readonly internalType: "bytes";
|
|
9
|
+
readonly name: "callData";
|
|
10
|
+
readonly type: "bytes";
|
|
11
|
+
}];
|
|
12
|
+
readonly internalType: "struct Multicall2.Call[]";
|
|
13
|
+
readonly name: "calls";
|
|
14
|
+
readonly type: "tuple[]";
|
|
15
|
+
}];
|
|
16
|
+
readonly name: "aggregate";
|
|
17
|
+
readonly outputs: readonly [{
|
|
18
|
+
readonly internalType: "uint256";
|
|
19
|
+
readonly name: "blockNumber";
|
|
20
|
+
readonly type: "uint256";
|
|
21
|
+
}, {
|
|
22
|
+
readonly internalType: "bytes[]";
|
|
23
|
+
readonly name: "returnData";
|
|
24
|
+
readonly type: "bytes[]";
|
|
25
|
+
}];
|
|
26
|
+
readonly stateMutability: "view";
|
|
27
|
+
readonly type: "function";
|
|
28
|
+
}, {
|
|
29
|
+
readonly inputs: readonly [{
|
|
30
|
+
readonly components: readonly [{
|
|
31
|
+
readonly internalType: "address";
|
|
32
|
+
readonly name: "target";
|
|
33
|
+
readonly type: "address";
|
|
34
|
+
}, {
|
|
35
|
+
readonly internalType: "bytes";
|
|
36
|
+
readonly name: "callData";
|
|
37
|
+
readonly type: "bytes";
|
|
38
|
+
}];
|
|
39
|
+
readonly internalType: "struct Multicall2.Call[]";
|
|
40
|
+
readonly name: "calls";
|
|
41
|
+
readonly type: "tuple[]";
|
|
42
|
+
}];
|
|
43
|
+
readonly name: "blockAndAggregate";
|
|
44
|
+
readonly outputs: readonly [{
|
|
45
|
+
readonly internalType: "uint256";
|
|
46
|
+
readonly name: "blockNumber";
|
|
47
|
+
readonly type: "uint256";
|
|
48
|
+
}, {
|
|
49
|
+
readonly internalType: "bytes32";
|
|
50
|
+
readonly name: "blockHash";
|
|
51
|
+
readonly type: "bytes32";
|
|
52
|
+
}, {
|
|
53
|
+
readonly components: readonly [{
|
|
54
|
+
readonly internalType: "bool";
|
|
55
|
+
readonly name: "success";
|
|
56
|
+
readonly type: "bool";
|
|
57
|
+
}, {
|
|
58
|
+
readonly internalType: "bytes";
|
|
59
|
+
readonly name: "returnData";
|
|
60
|
+
readonly type: "bytes";
|
|
61
|
+
}];
|
|
62
|
+
readonly internalType: "struct Multicall2.Result[]";
|
|
63
|
+
readonly name: "returnData";
|
|
64
|
+
readonly type: "tuple[]";
|
|
65
|
+
}];
|
|
66
|
+
readonly stateMutability: "nonpayable";
|
|
67
|
+
readonly type: "function";
|
|
68
|
+
}, {
|
|
69
|
+
readonly inputs: readonly [{
|
|
70
|
+
readonly internalType: "uint256";
|
|
71
|
+
readonly name: "blockNumber";
|
|
72
|
+
readonly type: "uint256";
|
|
73
|
+
}];
|
|
74
|
+
readonly name: "getBlockHash";
|
|
75
|
+
readonly outputs: readonly [{
|
|
76
|
+
readonly internalType: "bytes32";
|
|
77
|
+
readonly name: "blockHash";
|
|
78
|
+
readonly type: "bytes32";
|
|
79
|
+
}];
|
|
80
|
+
readonly stateMutability: "view";
|
|
81
|
+
readonly type: "function";
|
|
82
|
+
}, {
|
|
83
|
+
readonly inputs: readonly [];
|
|
84
|
+
readonly name: "getBlockNumber";
|
|
85
|
+
readonly outputs: readonly [{
|
|
86
|
+
readonly internalType: "uint256";
|
|
87
|
+
readonly name: "blockNumber";
|
|
88
|
+
readonly type: "uint256";
|
|
89
|
+
}];
|
|
90
|
+
readonly stateMutability: "view";
|
|
91
|
+
readonly type: "function";
|
|
92
|
+
}, {
|
|
93
|
+
readonly inputs: readonly [];
|
|
94
|
+
readonly name: "getCurrentBlockCoinbase";
|
|
95
|
+
readonly outputs: readonly [{
|
|
96
|
+
readonly internalType: "address";
|
|
97
|
+
readonly name: "coinbase";
|
|
98
|
+
readonly type: "address";
|
|
99
|
+
}];
|
|
100
|
+
readonly stateMutability: "view";
|
|
101
|
+
readonly type: "function";
|
|
102
|
+
}, {
|
|
103
|
+
readonly inputs: readonly [];
|
|
104
|
+
readonly name: "getCurrentBlockDifficulty";
|
|
105
|
+
readonly outputs: readonly [{
|
|
106
|
+
readonly internalType: "uint256";
|
|
107
|
+
readonly name: "difficulty";
|
|
108
|
+
readonly type: "uint256";
|
|
109
|
+
}];
|
|
110
|
+
readonly stateMutability: "view";
|
|
111
|
+
readonly type: "function";
|
|
112
|
+
}, {
|
|
113
|
+
readonly inputs: readonly [];
|
|
114
|
+
readonly name: "getCurrentBlockGasLimit";
|
|
115
|
+
readonly outputs: readonly [{
|
|
116
|
+
readonly internalType: "uint256";
|
|
117
|
+
readonly name: "gaslimit";
|
|
118
|
+
readonly type: "uint256";
|
|
119
|
+
}];
|
|
120
|
+
readonly stateMutability: "view";
|
|
121
|
+
readonly type: "function";
|
|
122
|
+
}, {
|
|
123
|
+
readonly inputs: readonly [];
|
|
124
|
+
readonly name: "getCurrentBlockTimestamp";
|
|
125
|
+
readonly outputs: readonly [{
|
|
126
|
+
readonly internalType: "uint256";
|
|
127
|
+
readonly name: "timestamp";
|
|
128
|
+
readonly type: "uint256";
|
|
129
|
+
}];
|
|
130
|
+
readonly stateMutability: "view";
|
|
131
|
+
readonly type: "function";
|
|
132
|
+
}, {
|
|
133
|
+
readonly inputs: readonly [{
|
|
134
|
+
readonly internalType: "address";
|
|
135
|
+
readonly name: "addr";
|
|
136
|
+
readonly type: "address";
|
|
137
|
+
}];
|
|
138
|
+
readonly name: "getEthBalance";
|
|
139
|
+
readonly outputs: readonly [{
|
|
140
|
+
readonly internalType: "uint256";
|
|
141
|
+
readonly name: "balance";
|
|
142
|
+
readonly type: "uint256";
|
|
143
|
+
}];
|
|
144
|
+
readonly stateMutability: "view";
|
|
145
|
+
readonly type: "function";
|
|
146
|
+
}, {
|
|
147
|
+
readonly inputs: readonly [];
|
|
148
|
+
readonly name: "getLastBlockHash";
|
|
149
|
+
readonly outputs: readonly [{
|
|
150
|
+
readonly internalType: "bytes32";
|
|
151
|
+
readonly name: "blockHash";
|
|
152
|
+
readonly type: "bytes32";
|
|
153
|
+
}];
|
|
154
|
+
readonly stateMutability: "view";
|
|
155
|
+
readonly type: "function";
|
|
156
|
+
}, {
|
|
157
|
+
readonly inputs: readonly [{
|
|
158
|
+
readonly internalType: "bool";
|
|
159
|
+
readonly name: "requireSuccess";
|
|
160
|
+
readonly type: "bool";
|
|
161
|
+
}, {
|
|
162
|
+
readonly components: readonly [{
|
|
163
|
+
readonly internalType: "address";
|
|
164
|
+
readonly name: "target";
|
|
165
|
+
readonly type: "address";
|
|
166
|
+
}, {
|
|
167
|
+
readonly internalType: "bytes";
|
|
168
|
+
readonly name: "callData";
|
|
169
|
+
readonly type: "bytes";
|
|
170
|
+
}];
|
|
171
|
+
readonly internalType: "struct Multicall2.Call[]";
|
|
172
|
+
readonly name: "calls";
|
|
173
|
+
readonly type: "tuple[]";
|
|
174
|
+
}];
|
|
175
|
+
readonly name: "tryAggregate";
|
|
176
|
+
readonly outputs: readonly [{
|
|
177
|
+
readonly components: readonly [{
|
|
178
|
+
readonly internalType: "bool";
|
|
179
|
+
readonly name: "success";
|
|
180
|
+
readonly type: "bool";
|
|
181
|
+
}, {
|
|
182
|
+
readonly internalType: "bytes";
|
|
183
|
+
readonly name: "returnData";
|
|
184
|
+
readonly type: "bytes";
|
|
185
|
+
}];
|
|
186
|
+
readonly internalType: "struct Multicall2.Result[]";
|
|
187
|
+
readonly name: "returnData";
|
|
188
|
+
readonly type: "tuple[]";
|
|
189
|
+
}];
|
|
190
|
+
readonly stateMutability: "view";
|
|
191
|
+
readonly type: "function";
|
|
192
|
+
}, {
|
|
193
|
+
readonly inputs: readonly [{
|
|
194
|
+
readonly internalType: "bool";
|
|
195
|
+
readonly name: "requireSuccess";
|
|
196
|
+
readonly type: "bool";
|
|
197
|
+
}, {
|
|
198
|
+
readonly components: readonly [{
|
|
199
|
+
readonly internalType: "address";
|
|
200
|
+
readonly name: "target";
|
|
201
|
+
readonly type: "address";
|
|
202
|
+
}, {
|
|
203
|
+
readonly internalType: "bytes";
|
|
204
|
+
readonly name: "callData";
|
|
205
|
+
readonly type: "bytes";
|
|
206
|
+
}];
|
|
207
|
+
readonly internalType: "struct Multicall2.Call[]";
|
|
208
|
+
readonly name: "calls";
|
|
209
|
+
readonly type: "tuple[]";
|
|
210
|
+
}];
|
|
211
|
+
readonly name: "tryBlockAndAggregate";
|
|
212
|
+
readonly outputs: readonly [{
|
|
213
|
+
readonly internalType: "uint256";
|
|
214
|
+
readonly name: "blockNumber";
|
|
215
|
+
readonly type: "uint256";
|
|
216
|
+
}, {
|
|
217
|
+
readonly internalType: "bytes32";
|
|
218
|
+
readonly name: "blockHash";
|
|
219
|
+
readonly type: "bytes32";
|
|
220
|
+
}, {
|
|
221
|
+
readonly components: readonly [{
|
|
222
|
+
readonly internalType: "bool";
|
|
223
|
+
readonly name: "success";
|
|
224
|
+
readonly type: "bool";
|
|
225
|
+
}, {
|
|
226
|
+
readonly internalType: "bytes";
|
|
227
|
+
readonly name: "returnData";
|
|
228
|
+
readonly type: "bytes";
|
|
229
|
+
}];
|
|
230
|
+
readonly internalType: "struct Multicall2.Result[]";
|
|
231
|
+
readonly name: "returnData";
|
|
232
|
+
readonly type: "tuple[]";
|
|
233
|
+
}];
|
|
234
|
+
readonly stateMutability: "view";
|
|
235
|
+
readonly type: "function";
|
|
236
|
+
}];
|
|
237
|
+
//# sourceMappingURL=IMulticall3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IMulticall3.d.ts","sourceRoot":"","sources":["../../src/abis/IMulticall3.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoKhB,CAAA"}
|
|
@@ -3,4 +3,8 @@ import { Address } from 'viem';
|
|
|
3
3
|
export declare const MULTICALL_ADDRESS: {
|
|
4
4
|
[key in ChainId]?: Address;
|
|
5
5
|
};
|
|
6
|
+
export declare const MULTICALL3_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11";
|
|
7
|
+
export declare const MULTICALL3_ADDRESSES: {
|
|
8
|
+
[key in ChainId]?: Address;
|
|
9
|
+
};
|
|
6
10
|
//# sourceMappingURL=contracts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../src/constants/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAE9B,eAAO,MAAM,iBAAiB,EAAE;KAAG,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,OAAO;CAoB3D,CAAA"}
|
|
1
|
+
{"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../src/constants/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAE9B,eAAO,MAAM,iBAAiB,EAAE;KAAG,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,OAAO;CAoB3D,CAAA;AAED,eAAO,MAAM,kBAAkB,+CAA+C,CAAA;AAE9E,eAAO,MAAM,oBAAoB,EAAE;KAChC,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,OAAO;CAgB3B,CAAA"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ChainId } from '@pancakeswap/chains';
|
|
2
|
-
import { GetContractReturnType, PublicClient } from 'viem';
|
|
2
|
+
import { GetContractReturnType, PublicClient, Address } from 'viem';
|
|
3
3
|
import { iMulticallABI } from './abis/IMulticall';
|
|
4
4
|
type Params = {
|
|
5
5
|
chainId: ChainId;
|
|
6
6
|
client?: PublicClient;
|
|
7
7
|
};
|
|
8
8
|
export declare function getMulticallContract({ chainId, client, }: Params): GetContractReturnType<typeof iMulticallABI, PublicClient>;
|
|
9
|
+
export declare function getMulticall3ContractAddress(chainId?: ChainId): Address;
|
|
9
10
|
export {};
|
|
10
11
|
//# sourceMappingURL=getMulticallContract.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMulticallContract.d.ts","sourceRoot":"","sources":["../src/getMulticallContract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAe,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"getMulticallContract.d.ts","sourceRoot":"","sources":["../src/getMulticallContract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAe,OAAO,EAAE,MAAM,MAAM,CAAA;AAGhF,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD,KAAK,MAAM,GAAG;IACZ,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,CAAC,EAAE,YAAY,CAAA;CACtB,CAAA;AAED,wBAAgB,oBAAoB,CAAC,EACnC,OAAO,EACP,MAAM,GACP,EAAE,MAAM,GAAG,qBAAqB,CAAC,OAAO,aAAa,EAAE,YAAY,CAAC,CAOpE;AAED,wBAAgB,4BAA4B,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAEvE"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,aAAa,CAAA;AAC3B,cAAc,wBAAwB,CAAA;AACtC,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,6BAA6B,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,wBAAwB,CAAA;AACtC,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,6BAA6B,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,23 @@ var MULTICALL_ADDRESS = {
|
|
|
27
27
|
[chains.ChainId.OPBNB_TESTNET]: "0x6A70ED893D85cf6D4059e1CF3e63a48e4D204D32",
|
|
28
28
|
[chains.ChainId.SCROLL_SEPOLIA]: "0x052a99849Ef2e13a5CB28275862991671D4b6fF5"
|
|
29
29
|
};
|
|
30
|
+
var MULTICALL3_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11";
|
|
31
|
+
var MULTICALL3_ADDRESSES = {
|
|
32
|
+
[chains.ChainId.ETHEREUM]: MULTICALL3_ADDRESS,
|
|
33
|
+
[chains.ChainId.GOERLI]: MULTICALL3_ADDRESS,
|
|
34
|
+
[chains.ChainId.BSC]: MULTICALL3_ADDRESS,
|
|
35
|
+
[chains.ChainId.BSC_TESTNET]: MULTICALL3_ADDRESS,
|
|
36
|
+
[chains.ChainId.ZKSYNC_TESTNET]: "0xF9cda624FBC7e059355ce98a31693d299FACd963",
|
|
37
|
+
[chains.ChainId.ZKSYNC]: "0xF9cda624FBC7e059355ce98a31693d299FACd963",
|
|
38
|
+
[chains.ChainId.ARBITRUM_ONE]: MULTICALL3_ADDRESS,
|
|
39
|
+
[chains.ChainId.ARBITRUM_GOERLI]: MULTICALL3_ADDRESS,
|
|
40
|
+
[chains.ChainId.POLYGON_ZKEVM]: MULTICALL3_ADDRESS,
|
|
41
|
+
[chains.ChainId.POLYGON_ZKEVM_TESTNET]: MULTICALL3_ADDRESS,
|
|
42
|
+
[chains.ChainId.OPBNB]: MULTICALL3_ADDRESS,
|
|
43
|
+
[chains.ChainId.OPBNB_TESTNET]: MULTICALL3_ADDRESS,
|
|
44
|
+
[chains.ChainId.BASE_TESTNET]: MULTICALL3_ADDRESS,
|
|
45
|
+
[chains.ChainId.SCROLL_SEPOLIA]: MULTICALL3_ADDRESS
|
|
46
|
+
};
|
|
30
47
|
var DEFAULT_BLOCK_CONFLICT_TOLERANCE = 0;
|
|
31
48
|
var BLOCK_CONFLICT_TOLERANCE = {
|
|
32
49
|
[chains.ChainId.BSC]: 3,
|
|
@@ -152,6 +169,9 @@ function getMulticallContract({
|
|
|
152
169
|
}
|
|
153
170
|
return viem.getContract({ abi: iMulticallABI, address, publicClient: client });
|
|
154
171
|
}
|
|
172
|
+
function getMulticall3ContractAddress(chainId) {
|
|
173
|
+
return MULTICALL3_ADDRESSES[chainId || chains.ChainId.BSC] || MULTICALL3_ADDRESS;
|
|
174
|
+
}
|
|
155
175
|
|
|
156
176
|
// src/getGasLimit.ts
|
|
157
177
|
function getDefaultGasLimit(chainId) {
|
|
@@ -182,6 +202,173 @@ async function getGasLimit({
|
|
|
182
202
|
return minGasLimit - gasBuffer;
|
|
183
203
|
}
|
|
184
204
|
|
|
205
|
+
// src/abis/IMulticall3.ts
|
|
206
|
+
var multicall3ABI = [
|
|
207
|
+
{
|
|
208
|
+
inputs: [
|
|
209
|
+
{
|
|
210
|
+
components: [
|
|
211
|
+
{ internalType: "address", name: "target", type: "address" },
|
|
212
|
+
{ internalType: "bytes", name: "callData", type: "bytes" }
|
|
213
|
+
],
|
|
214
|
+
internalType: "struct Multicall2.Call[]",
|
|
215
|
+
name: "calls",
|
|
216
|
+
type: "tuple[]"
|
|
217
|
+
}
|
|
218
|
+
],
|
|
219
|
+
name: "aggregate",
|
|
220
|
+
outputs: [
|
|
221
|
+
{ internalType: "uint256", name: "blockNumber", type: "uint256" },
|
|
222
|
+
{ internalType: "bytes[]", name: "returnData", type: "bytes[]" }
|
|
223
|
+
],
|
|
224
|
+
stateMutability: "view",
|
|
225
|
+
type: "function"
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
inputs: [
|
|
229
|
+
{
|
|
230
|
+
components: [
|
|
231
|
+
{ internalType: "address", name: "target", type: "address" },
|
|
232
|
+
{ internalType: "bytes", name: "callData", type: "bytes" }
|
|
233
|
+
],
|
|
234
|
+
internalType: "struct Multicall2.Call[]",
|
|
235
|
+
name: "calls",
|
|
236
|
+
type: "tuple[]"
|
|
237
|
+
}
|
|
238
|
+
],
|
|
239
|
+
name: "blockAndAggregate",
|
|
240
|
+
outputs: [
|
|
241
|
+
{ internalType: "uint256", name: "blockNumber", type: "uint256" },
|
|
242
|
+
{ internalType: "bytes32", name: "blockHash", type: "bytes32" },
|
|
243
|
+
{
|
|
244
|
+
components: [
|
|
245
|
+
{ internalType: "bool", name: "success", type: "bool" },
|
|
246
|
+
{ internalType: "bytes", name: "returnData", type: "bytes" }
|
|
247
|
+
],
|
|
248
|
+
internalType: "struct Multicall2.Result[]",
|
|
249
|
+
name: "returnData",
|
|
250
|
+
type: "tuple[]"
|
|
251
|
+
}
|
|
252
|
+
],
|
|
253
|
+
stateMutability: "nonpayable",
|
|
254
|
+
type: "function"
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
inputs: [{ internalType: "uint256", name: "blockNumber", type: "uint256" }],
|
|
258
|
+
name: "getBlockHash",
|
|
259
|
+
outputs: [{ internalType: "bytes32", name: "blockHash", type: "bytes32" }],
|
|
260
|
+
stateMutability: "view",
|
|
261
|
+
type: "function"
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
inputs: [],
|
|
265
|
+
name: "getBlockNumber",
|
|
266
|
+
outputs: [{ internalType: "uint256", name: "blockNumber", type: "uint256" }],
|
|
267
|
+
stateMutability: "view",
|
|
268
|
+
type: "function"
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
inputs: [],
|
|
272
|
+
name: "getCurrentBlockCoinbase",
|
|
273
|
+
outputs: [{ internalType: "address", name: "coinbase", type: "address" }],
|
|
274
|
+
stateMutability: "view",
|
|
275
|
+
type: "function"
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
inputs: [],
|
|
279
|
+
name: "getCurrentBlockDifficulty",
|
|
280
|
+
outputs: [{ internalType: "uint256", name: "difficulty", type: "uint256" }],
|
|
281
|
+
stateMutability: "view",
|
|
282
|
+
type: "function"
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
inputs: [],
|
|
286
|
+
name: "getCurrentBlockGasLimit",
|
|
287
|
+
outputs: [{ internalType: "uint256", name: "gaslimit", type: "uint256" }],
|
|
288
|
+
stateMutability: "view",
|
|
289
|
+
type: "function"
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
inputs: [],
|
|
293
|
+
name: "getCurrentBlockTimestamp",
|
|
294
|
+
outputs: [{ internalType: "uint256", name: "timestamp", type: "uint256" }],
|
|
295
|
+
stateMutability: "view",
|
|
296
|
+
type: "function"
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
inputs: [{ internalType: "address", name: "addr", type: "address" }],
|
|
300
|
+
name: "getEthBalance",
|
|
301
|
+
outputs: [{ internalType: "uint256", name: "balance", type: "uint256" }],
|
|
302
|
+
stateMutability: "view",
|
|
303
|
+
type: "function"
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
inputs: [],
|
|
307
|
+
name: "getLastBlockHash",
|
|
308
|
+
outputs: [{ internalType: "bytes32", name: "blockHash", type: "bytes32" }],
|
|
309
|
+
stateMutability: "view",
|
|
310
|
+
type: "function"
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
inputs: [
|
|
314
|
+
{ internalType: "bool", name: "requireSuccess", type: "bool" },
|
|
315
|
+
{
|
|
316
|
+
components: [
|
|
317
|
+
{ internalType: "address", name: "target", type: "address" },
|
|
318
|
+
{ internalType: "bytes", name: "callData", type: "bytes" }
|
|
319
|
+
],
|
|
320
|
+
internalType: "struct Multicall2.Call[]",
|
|
321
|
+
name: "calls",
|
|
322
|
+
type: "tuple[]"
|
|
323
|
+
}
|
|
324
|
+
],
|
|
325
|
+
name: "tryAggregate",
|
|
326
|
+
outputs: [
|
|
327
|
+
{
|
|
328
|
+
components: [
|
|
329
|
+
{ internalType: "bool", name: "success", type: "bool" },
|
|
330
|
+
{ internalType: "bytes", name: "returnData", type: "bytes" }
|
|
331
|
+
],
|
|
332
|
+
internalType: "struct Multicall2.Result[]",
|
|
333
|
+
name: "returnData",
|
|
334
|
+
type: "tuple[]"
|
|
335
|
+
}
|
|
336
|
+
],
|
|
337
|
+
stateMutability: "view",
|
|
338
|
+
type: "function"
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
inputs: [
|
|
342
|
+
{ internalType: "bool", name: "requireSuccess", type: "bool" },
|
|
343
|
+
{
|
|
344
|
+
components: [
|
|
345
|
+
{ internalType: "address", name: "target", type: "address" },
|
|
346
|
+
{ internalType: "bytes", name: "callData", type: "bytes" }
|
|
347
|
+
],
|
|
348
|
+
internalType: "struct Multicall2.Call[]",
|
|
349
|
+
name: "calls",
|
|
350
|
+
type: "tuple[]"
|
|
351
|
+
}
|
|
352
|
+
],
|
|
353
|
+
name: "tryBlockAndAggregate",
|
|
354
|
+
outputs: [
|
|
355
|
+
{ internalType: "uint256", name: "blockNumber", type: "uint256" },
|
|
356
|
+
{ internalType: "bytes32", name: "blockHash", type: "bytes32" },
|
|
357
|
+
{
|
|
358
|
+
components: [
|
|
359
|
+
{ internalType: "bool", name: "success", type: "bool" },
|
|
360
|
+
{ internalType: "bytes", name: "returnData", type: "bytes" }
|
|
361
|
+
],
|
|
362
|
+
internalType: "struct Multicall2.Result[]",
|
|
363
|
+
name: "returnData",
|
|
364
|
+
type: "tuple[]"
|
|
365
|
+
}
|
|
366
|
+
],
|
|
367
|
+
stateMutability: "view",
|
|
368
|
+
type: "function"
|
|
369
|
+
}
|
|
370
|
+
];
|
|
371
|
+
|
|
185
372
|
// src/getBlockConflictTolerance.ts
|
|
186
373
|
function getBlockConflictTolerance(chainId) {
|
|
187
374
|
return BLOCK_CONFLICT_TOLERANCE[chainId] || DEFAULT_BLOCK_CONFLICT_TOLERANCE;
|
|
@@ -312,14 +499,18 @@ exports.DEFAULT_GAS_BUFFER = DEFAULT_GAS_BUFFER;
|
|
|
312
499
|
exports.DEFAULT_GAS_BUFFER_BY_CHAIN = DEFAULT_GAS_BUFFER_BY_CHAIN;
|
|
313
500
|
exports.DEFAULT_GAS_LIMIT = DEFAULT_GAS_LIMIT;
|
|
314
501
|
exports.DEFAULT_GAS_LIMIT_BY_CHAIN = DEFAULT_GAS_LIMIT_BY_CHAIN;
|
|
502
|
+
exports.MULTICALL3_ADDRESS = MULTICALL3_ADDRESS;
|
|
503
|
+
exports.MULTICALL3_ADDRESSES = MULTICALL3_ADDRESSES;
|
|
315
504
|
exports.MULTICALL_ADDRESS = MULTICALL_ADDRESS;
|
|
316
505
|
exports.getBlockConflictTolerance = getBlockConflictTolerance;
|
|
317
506
|
exports.getDefaultGasBuffer = getDefaultGasBuffer;
|
|
318
507
|
exports.getDefaultGasLimit = getDefaultGasLimit;
|
|
319
508
|
exports.getGasLimit = getGasLimit;
|
|
320
509
|
exports.getGasLimitOnChain = getGasLimitOnChain;
|
|
510
|
+
exports.getMulticall3ContractAddress = getMulticall3ContractAddress;
|
|
321
511
|
exports.getMulticallContract = getMulticallContract;
|
|
322
512
|
exports.iMulticallABI = iMulticallABI;
|
|
513
|
+
exports.multicall3ABI = multicall3ABI;
|
|
323
514
|
exports.multicallByGasLimit = multicallByGasLimit;
|
|
324
515
|
//# sourceMappingURL=out.js.map
|
|
325
516
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../utils/toBigInt.ts","../src/constants/contracts.ts","../src/constants/blockConflictTolerance.ts","../src/constants/gasLimit.ts","../src/getMulticallContract.ts","../src/abis/IMulticall.ts","../src/getGasLimit.ts","../src/getBlockConflictTolerance.ts","../src/multicall.ts"],"names":["ChainId"],"mappings":";AAEO,SAAS,SAAS,KAAwB;AAC/C,SAAO,OAAO,IAAI,SAAS,CAAC;AAC9B;;;ACJA,SAAS,eAAe;AAGjB,IAAM,oBAAoD;AAAA,EAC/D,CAAC,QAAQ,MAAM,GAAG;AAAA,EAClB,CAAC,QAAQ,GAAG,GAAG;AAAA,EACf,CAAC,QAAQ,QAAQ,GAAG;AAAA,EACpB,CAAC,QAAQ,YAAY,GAAG;AAAA,EACxB,CAAC,QAAQ,aAAa,GAAG;AAAA,EACzB,CAAC,QAAQ,KAAK,GAAG;AAAA,EACjB,CAAC,QAAQ,IAAI,GAAG;AAAA,EAChB,CAAC,QAAQ,KAAK,GAAG;AAAA;AAAA,EAGjB,CAAC,QAAQ,WAAW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SAAO;AACT","sourcesContent":["import { BigintIsh } from '@pancakeswap/swap-sdk-core'\n\nexport function toBigInt(num: BigintIsh): bigint {\n return BigInt(num.toString())\n}\n","import { ChainId } from '@pancakeswap/chains'\nimport { Address } from 'viem'\n\nexport const MULTICALL_ADDRESS: { [key in ChainId]?: Address } = {\n [ChainId.ZKSYNC]: '0x95071cBD09184083E7F732a710c2e30c9882Fd5f',\n [ChainId.BSC]: '0x39eecaE833c944ebb94942Fa44CaE46e87a8Da17',\n [ChainId.ETHEREUM]: '0xC0916D7E360c31D5F6D0c497E6a36B7B0E80e3cf',\n [ChainId.ARBITRUM_ONE]: '0xbFfE39cDD04f0183e0493c1Deb6E275c5cf84AdF',\n [ChainId.POLYGON_ZKEVM]: '0xe05b539447B17630Cb087473F6b50E5c5f73FDeb',\n [ChainId.LINEA]: '0x6E6B30d65D605DAa4CaC65eB270100Ecca36b140',\n [ChainId.BASE]: '0x3EFaAb8D7A631cfF5ccF5f149d1Bbb3B5bfda2C0',\n [ChainId.OPBNB]: '0xeF1511D29fB37cb87E33339EeC9BE13AB46E3b50',\n\n // Testnets\n [ChainId.BSC_TESTNET]: '0xeeF6ff30cF5D5b8aBA0DE16A01d17A0697a275b5',\n [ChainId.GOERLI]: '0xD55CAFAB2Ffa1139Be46bc5C0b8259c620050dFC',\n [ChainId.ARBITRUM_GOERLI]: '0xe12a5c707Fb528acbE6117b20AF1f7c20b0A8077',\n [ChainId.POLYGON_ZKEVM_TESTNET]: '0x236e713bFF45adb30e25D1c29A887aBCb0Ea7E21',\n [ChainId.ZKSYNC_TESTNET]: '0x8A23CB45E5F4d5a1b2DB673663Ea2aAedc48acff',\n [ChainId.LINEA_TESTNET]: '0x990010b6DBA3e7faa025790bC0433A9f690c65F3',\n [ChainId.BASE_TESTNET]: '0x6F7f93D929d6FBaF16c245e42846EF21aee23437',\n [ChainId.OPBNB_TESTNET]: '0x6A70ED893D85cf6D4059e1CF3e63a48e4D204D32',\n [ChainId.SCROLL_SEPOLIA]: '0x052a99849Ef2e13a5CB28275862991671D4b6fF5',\n}\n","import { ChainId } from '@pancakeswap/chains'\n\nexport const DEFAULT_BLOCK_CONFLICT_TOLERANCE = 0\n\nexport const BLOCK_CONFLICT_TOLERANCE: { [key in ChainId]?: number } = {\n [ChainId.BSC]: 3,\n [ChainId.ETHEREUM]: 1,\n [ChainId.ARBITRUM_ONE]: 5,\n [ChainId.POLYGON_ZKEVM]: 1,\n [ChainId.ZKSYNC]: 3,\n [ChainId.LINEA]: 3,\n [ChainId.BASE]: 3,\n [ChainId.OPBNB]: 3,\n\n // Testnets\n [ChainId.BSC_TESTNET]: 3,\n [ChainId.GOERLI]: 1,\n [ChainId.ARBITRUM_GOERLI]: 5,\n [ChainId.POLYGON_ZKEVM_TESTNET]: 1,\n [ChainId.ZKSYNC_TESTNET]: 3,\n [ChainId.LINEA_TESTNET]: 3,\n [ChainId.OPBNB_TESTNET]: 3,\n [ChainId.BASE_TESTNET]: 3,\n [ChainId.SCROLL_SEPOLIA]: 3,\n}\n","import { ChainId } from '@pancakeswap/chains'\n\nexport const DEFAULT_GAS_LIMIT = 150000000n\n\nexport const DEFAULT_GAS_LIMIT_BY_CHAIN: { [key in ChainId]?: bigint } = {\n [ChainId.BSC]: 100000000n,\n [ChainId.ZKSYNC]: 500000000n,\n [ChainId.POLYGON_ZKEVM]: 1500000n,\n [ChainId.BASE]: 130000000n,\n}\n\nexport const DEFAULT_GAS_BUFFER = 3000000n\n\nexport const DEFAULT_GAS_BUFFER_BY_CHAIN: { [key in ChainId]?: bigint } = {\n [ChainId.BSC]: DEFAULT_GAS_BUFFER,\n [ChainId.POLYGON_ZKEVM]: 0n,\n}\n","import { ChainId } from '@pancakeswap/chains'\nimport { GetContractReturnType, PublicClient, getContract } from 'viem'\n\nimport { MULTICALL_ADDRESS } from './constants/contracts'\nimport { iMulticallABI } from './abis/IMulticall'\n\ntype Params = {\n chainId: ChainId\n client?: PublicClient\n}\n\nexport function getMulticallContract({\n chainId,\n client,\n}: Params): GetContractReturnType<typeof iMulticallABI, PublicClient> {\n const address = MULTICALL_ADDRESS[chainId]\n if (!address) {\n throw new Error(`PancakeMulticall not supported on chain ${chainId}`)\n }\n\n return getContract({ abi: iMulticallABI, address, publicClient: client })\n}\n","export const iMulticallABI = [\n {\n inputs: [],\n name: 'gasLeft',\n outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'gaslimit',\n outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [\n {\n components: [\n { internalType: 'address', name: 'target', type: 'address' },\n { internalType: 'uint256', name: 'gasLimit', type: 'uint256' },\n { internalType: 'bytes', name: 'callData', type: 'bytes' },\n ],\n internalType: 'struct MultiCallV2.Call[]',\n name: 'calls',\n type: 'tuple[]',\n },\n ],\n name: 'multicall',\n outputs: [\n { internalType: 'uint256', name: 'blockNumber', type: 'uint256' },\n {\n components: [\n { internalType: 'bool', name: 'success', type: 'bool' },\n { internalType: 'uint256', name: 'gasUsed', type: 'uint256' },\n { internalType: 'bytes', name: 'returnData', type: 'bytes' },\n ],\n internalType: 'struct MultiCallV2.Result[]',\n name: 'returnData',\n type: 'tuple[]',\n },\n ],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n {\n inputs: [\n {\n components: [\n { internalType: 'address', name: 'target', type: 'address' },\n { internalType: 'uint256', name: 'gasLimit', type: 'uint256' },\n { internalType: 'bytes', name: 'callData', type: 'bytes' },\n ],\n internalType: 'struct MultiCallV2.Call[]',\n name: 'calls',\n type: 'tuple[]',\n },\n { internalType: 'uint256', name: 'gasBuffer', type: 'uint256' },\n ],\n name: 'multicallWithGasLimitation',\n outputs: [\n { internalType: 'uint256', name: 'blockNumber', type: 'uint256' },\n {\n components: [\n { internalType: 'bool', name: 'success', type: 'bool' },\n { internalType: 'uint256', name: 'gasUsed', type: 'uint256' },\n { internalType: 'bytes', name: 'returnData', type: 'bytes' },\n ],\n internalType: 'struct MultiCallV2.Result[]',\n name: 'returnData',\n type: 'tuple[]',\n },\n { internalType: 'uint256', name: 'lastSuccessIndex', type: 'uint256' },\n ],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n]\n","import { BigintIsh } from '@pancakeswap/sdk'\nimport { ChainId } from '@pancakeswap/chains'\nimport { toBigInt } from '@pancakeswap/utils/toBigInt'\nimport { PublicClient } from 'viem'\n\nimport {\n DEFAULT_GAS_BUFFER,\n DEFAULT_GAS_BUFFER_BY_CHAIN,\n DEFAULT_GAS_LIMIT,\n DEFAULT_GAS_LIMIT_BY_CHAIN,\n} from './constants'\nimport { getMulticallContract } from './getMulticallContract'\n\nexport type GetGasLimitParams = {\n chainId: ChainId\n client?: PublicClient\n\n // If provided then would override the gas limit got from on chain\n gasLimit?: BigintIsh\n\n // The gas limit should be whichever is smaller between gasLimit and maxGasLimit\n maxGasLimit?: BigintIsh\n\n gasBuffer?: BigintIsh\n}\n\nexport function getDefaultGasLimit(chainId?: ChainId) {\n const gasLimitOnChain = chainId && DEFAULT_GAS_LIMIT_BY_CHAIN[chainId]\n return gasLimitOnChain !== undefined ? gasLimitOnChain : DEFAULT_GAS_LIMIT\n}\n\nexport function getDefaultGasBuffer(chainId?: ChainId) {\n const gasBufferOnChain = chainId && DEFAULT_GAS_BUFFER_BY_CHAIN[chainId]\n return gasBufferOnChain !== undefined ? gasBufferOnChain : DEFAULT_GAS_BUFFER\n}\n\nexport type GetGasLimitOnChainParams = Pick<GetGasLimitParams, 'chainId' | 'client'>\n\nexport async function getGasLimitOnChain({ chainId, client }: GetGasLimitOnChainParams) {\n const multicall = getMulticallContract({ chainId, client })\n const gasLeft = (await multicall.read.gasLeft()) as bigint\n return gasLeft\n}\n\nexport async function getGasLimit({\n chainId,\n gasLimit: gasLimitInput,\n maxGasLimit: maxGasLimitInput = getDefaultGasLimit(chainId),\n gasBuffer: gasBufferInput = getDefaultGasBuffer(chainId),\n client,\n}: GetGasLimitParams) {\n const gasLimitOverride = gasLimitInput && toBigInt(gasLimitInput)\n const maxGasLimit = toBigInt(maxGasLimitInput)\n const gasBuffer = toBigInt(gasBufferInput)\n\n const gasLimit = gasLimitOverride || (await getGasLimitOnChain({ chainId, client })) || maxGasLimit\n const minGasLimit = gasLimit < maxGasLimit ? gasLimit : maxGasLimit\n return minGasLimit - gasBuffer\n}\n","import { ChainId } from '@pancakeswap/chains'\n\nimport { BLOCK_CONFLICT_TOLERANCE, DEFAULT_BLOCK_CONFLICT_TOLERANCE } from './constants'\n\nexport function getBlockConflictTolerance(chainId: ChainId) {\n return BLOCK_CONFLICT_TOLERANCE[chainId] || DEFAULT_BLOCK_CONFLICT_TOLERANCE\n}\n","import { toBigInt } from '@pancakeswap/utils/toBigInt'\n\nimport { GetGasLimitParams, getDefaultGasBuffer, getGasLimit } from './getGasLimit'\nimport { MulticallRequestWithGas } from './types'\nimport { getMulticallContract } from './getMulticallContract'\nimport { getBlockConflictTolerance } from './getBlockConflictTolerance'\n\nexport type CallByGasLimitParams = GetGasLimitParams & {\n // Normally we expect to get quotes from within the same block\n // But for some chains like BSC the block time is quite short so need some extra tolerance\n // 0 means no block conflict and all the multicall results should be queried within the same block\n blockConflictTolerance?: number\n\n // Treat unexecuted calls as failed calls\n dropUnexecutedCalls?: boolean\n}\n\nexport async function multicallByGasLimit(\n calls: MulticallRequestWithGas[],\n { chainId, gasBuffer = getDefaultGasBuffer(chainId), client, dropUnexecutedCalls, ...rest }: CallByGasLimitParams,\n) {\n const gasLimit = await getGasLimit({\n chainId,\n gasBuffer,\n client,\n ...rest,\n })\n const callChunks = splitCallsIntoChunks(calls, gasLimit)\n return callByChunks(callChunks, { gasBuffer, client, chainId, dropUnexecutedCalls })\n}\n\ntype CallParams = Pick<\n CallByGasLimitParams,\n 'chainId' | 'client' | 'gasBuffer' | 'blockConflictTolerance' | 'dropUnexecutedCalls'\n>\n\nexport type SingleCallResult = {\n result: string\n gasUsed: bigint\n success: boolean\n}\n\nexport type CallResult = {\n results: SingleCallResult[]\n // Will be the greatest block number if block conflict tolerance is not 0\n blockNumber: bigint\n}\n\nexport type MulticallReturn = CallResult & {\n lastSuccessIndex: number\n}\n\ntype CallReturnFromContract = [bigint, { success: boolean; gasUsed: bigint; returnData: string }[], bigint]\n\nfunction formatCallReturn([blockNumber, results, successIndex]: CallReturnFromContract): MulticallReturn {\n const lastSuccessIndex = Number(successIndex)\n return {\n lastSuccessIndex,\n blockNumber,\n results: results.slice(0, lastSuccessIndex + 1).map(({ gasUsed, success, returnData }) => ({\n gasUsed,\n success,\n result: returnData,\n })),\n }\n}\n\nasync function call(calls: MulticallRequestWithGas[], params: CallParams): Promise<CallResult> {\n const {\n chainId,\n client,\n gasBuffer = getDefaultGasBuffer(chainId),\n blockConflictTolerance = getBlockConflictTolerance(chainId),\n dropUnexecutedCalls = false,\n } = params\n if (!calls.length) {\n return {\n results: [],\n blockNumber: 0n,\n }\n }\n\n const contract = getMulticallContract({ chainId, client })\n const { result } = await contract.simulate.multicallWithGasLimitation([calls, gasBuffer])\n const { results, lastSuccessIndex, blockNumber } = formatCallReturn(result as CallReturnFromContract)\n if (lastSuccessIndex === calls.length - 1) {\n return {\n results,\n blockNumber,\n }\n }\n console.warn(\n `Gas limit reached. Total num of ${calls.length} calls. First ${\n lastSuccessIndex + 1\n } calls executed. The remaining ${\n calls.length - lastSuccessIndex - 1\n } calls are not executed. Pls try adjust the gas limit per call.`,\n )\n const remainingCalls = calls.slice(lastSuccessIndex + 1)\n if (dropUnexecutedCalls) {\n return {\n results: [...results, ...remainingCalls.map(() => ({ result: '0x', gasUsed: 0n, success: false }))],\n blockNumber,\n }\n }\n const { results: remainingResults, blockNumber: nextBlockNumber } = await call(\n calls.slice(lastSuccessIndex + 1),\n params,\n )\n if (Number(nextBlockNumber - blockNumber) > blockConflictTolerance) {\n throw new Error(\n `Multicall failed because of block conflict. Latest calls are made at block ${nextBlockNumber} while last calls made at block ${blockNumber}. Block conflict tolerance is ${blockConflictTolerance}`,\n )\n }\n return {\n results: [...results, ...remainingResults],\n // Use the latest block number\n blockNumber: nextBlockNumber,\n }\n}\n\nasync function callByChunks(chunks: MulticallRequestWithGas[][], params: CallParams): Promise<CallResult> {\n const { blockConflictTolerance = getBlockConflictTolerance(params.chainId) } = params\n const callReturns = await Promise.all(chunks.map((chunk) => call(chunk, params)))\n\n let minBlock = 0n\n let maxBlock = 0n\n let results: SingleCallResult[] = []\n for (const { results: callResults, blockNumber } of callReturns) {\n if (minBlock === 0n || blockNumber < minBlock) {\n minBlock = blockNumber\n }\n if (blockNumber > maxBlock) {\n maxBlock = blockNumber\n }\n if (Number(maxBlock - minBlock) > blockConflictTolerance) {\n throw new Error(\n `Multicall failed because of block conflict. Min block is ${minBlock} while max block is ${maxBlock}. Block conflict tolerance is ${blockConflictTolerance}`,\n )\n }\n results = [...results, ...callResults]\n }\n return {\n results,\n blockNumber: maxBlock,\n }\n}\n\nfunction splitCallsIntoChunks(calls: MulticallRequestWithGas[], gasLimit: bigint): MulticallRequestWithGas[][] {\n const chunks: MulticallRequestWithGas[][] = [[]]\n\n let gasLeft = gasLimit\n for (const callRequest of calls) {\n const { target, callData, gasLimit: gasCostLimit } = callRequest\n const singleGasLimit = toBigInt(gasCostLimit)\n const currentChunk = chunks[chunks.length - 1]\n if (singleGasLimit > gasLeft) {\n chunks.push([callRequest])\n gasLeft = gasLimit - singleGasLimit\n\n // Single call exceeds the gas limit\n if (gasLeft < 0n) {\n console.warn(\n `Multicall request may fail as the gas cost of a single call exceeds the gas limit ${gasLimit}. Gas cost: ${singleGasLimit}. To: ${target}. Data: ${callData}`,\n )\n }\n continue\n }\n\n currentChunk.push(callRequest)\n gasLeft -= singleGasLimit\n }\n\n return chunks\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../utils/toBigInt.ts","../src/constants/contracts.ts","../src/constants/blockConflictTolerance.ts","../src/constants/gasLimit.ts","../src/getMulticallContract.ts","../src/abis/IMulticall.ts","../src/getGasLimit.ts","../src/abis/IM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,aAAO,KAAK,CAAC,WAAW,CAAC;AACzB,gBAAU,WAAW;AAGrB,UAAI,UAAU,IAAI;AAChB,gBAAQ;AAAA,UACN,qFAAqF,uBAAuB,uBAAuB,iBAAiB;AAAA,QACtJ;AAAA,MACF;AACA;AAAA,IACF;AAEA,iBAAa,KAAK,WAAW;AAC7B,eAAW;AAAA,EACb;AAEA,SAAO;AACT","sourcesContent":["import { BigintIsh } from '@pancakeswap/swap-sdk-core'\n\nexport function toBigInt(num: BigintIsh): bigint {\n return BigInt(num.toString())\n}\n","import { ChainId } from '@pancakeswap/chains'\nimport { Address } from 'viem'\n\nexport const MULTICALL_ADDRESS: { [key in ChainId]?: Address } = {\n [ChainId.ZKSYNC]: '0x95071cBD09184083E7F732a710c2e30c9882Fd5f',\n [ChainId.BSC]: '0x39eecaE833c944ebb94942Fa44CaE46e87a8Da17',\n [ChainId.ETHEREUM]: '0xC0916D7E360c31D5F6D0c497E6a36B7B0E80e3cf',\n [ChainId.ARBITRUM_ONE]: '0xbFfE39cDD04f0183e0493c1Deb6E275c5cf84AdF',\n [ChainId.POLYGON_ZKEVM]: '0xe05b539447B17630Cb087473F6b50E5c5f73FDeb',\n [ChainId.LINEA]: '0x6E6B30d65D605DAa4CaC65eB270100Ecca36b140',\n [ChainId.BASE]: '0x3EFaAb8D7A631cfF5ccF5f149d1Bbb3B5bfda2C0',\n [ChainId.OPBNB]: '0xeF1511D29fB37cb87E33339EeC9BE13AB46E3b50',\n\n // Testnets\n [ChainId.BSC_TESTNET]: '0xeeF6ff30cF5D5b8aBA0DE16A01d17A0697a275b5',\n [ChainId.GOERLI]: '0xD55CAFAB2Ffa1139Be46bc5C0b8259c620050dFC',\n [ChainId.ARBITRUM_GOERLI]: '0xe12a5c707Fb528acbE6117b20AF1f7c20b0A8077',\n [ChainId.POLYGON_ZKEVM_TESTNET]: '0x236e713bFF45adb30e25D1c29A887aBCb0Ea7E21',\n [ChainId.ZKSYNC_TESTNET]: '0x8A23CB45E5F4d5a1b2DB673663Ea2aAedc48acff',\n [ChainId.LINEA_TESTNET]: '0x990010b6DBA3e7faa025790bC0433A9f690c65F3',\n [ChainId.BASE_TESTNET]: '0x6F7f93D929d6FBaF16c245e42846EF21aee23437',\n [ChainId.OPBNB_TESTNET]: '0x6A70ED893D85cf6D4059e1CF3e63a48e4D204D32',\n [ChainId.SCROLL_SEPOLIA]: '0x052a99849Ef2e13a5CB28275862991671D4b6fF5',\n}\n\nexport const MULTICALL3_ADDRESS = '0xcA11bde05977b3631167028862bE2a173976CA11'\n\nexport const MULTICALL3_ADDRESSES: {\n [key in ChainId]?: Address\n} = {\n [ChainId.ETHEREUM]: MULTICALL3_ADDRESS,\n [ChainId.GOERLI]: MULTICALL3_ADDRESS,\n [ChainId.BSC]: MULTICALL3_ADDRESS,\n [ChainId.BSC_TESTNET]: MULTICALL3_ADDRESS,\n [ChainId.ZKSYNC_TESTNET]: '0xF9cda624FBC7e059355ce98a31693d299FACd963',\n [ChainId.ZKSYNC]: '0xF9cda624FBC7e059355ce98a31693d299FACd963',\n [ChainId.ARBITRUM_ONE]: MULTICALL3_ADDRESS,\n [ChainId.ARBITRUM_GOERLI]: MULTICALL3_ADDRESS,\n [ChainId.POLYGON_ZKEVM]: MULTICALL3_ADDRESS,\n [ChainId.POLYGON_ZKEVM_TESTNET]: MULTICALL3_ADDRESS,\n [ChainId.OPBNB]: MULTICALL3_ADDRESS,\n [ChainId.OPBNB_TESTNET]: MULTICALL3_ADDRESS,\n [ChainId.BASE_TESTNET]: MULTICALL3_ADDRESS,\n [ChainId.SCROLL_SEPOLIA]: MULTICALL3_ADDRESS,\n}\n","import { ChainId } from '@pancakeswap/chains'\n\nexport const DEFAULT_BLOCK_CONFLICT_TOLERANCE = 0\n\nexport const BLOCK_CONFLICT_TOLERANCE: { [key in ChainId]?: number } = {\n [ChainId.BSC]: 3,\n [ChainId.ETHEREUM]: 1,\n [ChainId.ARBITRUM_ONE]: 5,\n [ChainId.POLYGON_ZKEVM]: 1,\n [ChainId.ZKSYNC]: 3,\n [ChainId.LINEA]: 3,\n [ChainId.BASE]: 3,\n [ChainId.OPBNB]: 3,\n\n // Testnets\n [ChainId.BSC_TESTNET]: 3,\n [ChainId.GOERLI]: 1,\n [ChainId.ARBITRUM_GOERLI]: 5,\n [ChainId.POLYGON_ZKEVM_TESTNET]: 1,\n [ChainId.ZKSYNC_TESTNET]: 3,\n [ChainId.LINEA_TESTNET]: 3,\n [ChainId.OPBNB_TESTNET]: 3,\n [ChainId.BASE_TESTNET]: 3,\n [ChainId.SCROLL_SEPOLIA]: 3,\n}\n","import { ChainId } from '@pancakeswap/chains'\n\nexport const DEFAULT_GAS_LIMIT = 150000000n\n\nexport const DEFAULT_GAS_LIMIT_BY_CHAIN: { [key in ChainId]?: bigint } = {\n [ChainId.BSC]: 100000000n,\n [ChainId.ZKSYNC]: 500000000n,\n [ChainId.POLYGON_ZKEVM]: 1500000n,\n [ChainId.BASE]: 130000000n,\n}\n\nexport const DEFAULT_GAS_BUFFER = 3000000n\n\nexport const DEFAULT_GAS_BUFFER_BY_CHAIN: { [key in ChainId]?: bigint } = {\n [ChainId.BSC]: DEFAULT_GAS_BUFFER,\n [ChainId.POLYGON_ZKEVM]: 0n,\n}\n","import { ChainId } from '@pancakeswap/chains'\nimport { GetContractReturnType, PublicClient, getContract, Address } from 'viem'\n\nimport { MULTICALL_ADDRESS, MULTICALL3_ADDRESSES, MULTICALL3_ADDRESS } from './constants/contracts'\nimport { iMulticallABI } from './abis/IMulticall'\n\ntype Params = {\n chainId: ChainId\n client?: PublicClient\n}\n\nexport function getMulticallContract({\n chainId,\n client,\n}: Params): GetContractReturnType<typeof iMulticallABI, PublicClient> {\n const address = MULTICALL_ADDRESS[chainId]\n if (!address) {\n throw new Error(`PancakeMulticall not supported on chain ${chainId}`)\n }\n\n return getContract({ abi: iMulticallABI, address, publicClient: client })\n}\n\nexport function getMulticall3ContractAddress(chainId?: ChainId): Address {\n return MULTICALL3_ADDRESSES[chainId || ChainId.BSC] || MULTICALL3_ADDRESS\n}\n","export const iMulticallABI = [\n {\n inputs: [],\n name: 'gasLeft',\n outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'gaslimit',\n outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [\n {\n components: [\n { internalType: 'address', name: 'target', type: 'address' },\n { internalType: 'uint256', name: 'gasLimit', type: 'uint256' },\n { internalType: 'bytes', name: 'callData', type: 'bytes' },\n ],\n internalType: 'struct MultiCallV2.Call[]',\n name: 'calls',\n type: 'tuple[]',\n },\n ],\n name: 'multicall',\n outputs: [\n { internalType: 'uint256', name: 'blockNumber', type: 'uint256' },\n {\n components: [\n { internalType: 'bool', name: 'success', type: 'bool' },\n { internalType: 'uint256', name: 'gasUsed', type: 'uint256' },\n { internalType: 'bytes', name: 'returnData', type: 'bytes' },\n ],\n internalType: 'struct MultiCallV2.Result[]',\n name: 'returnData',\n type: 'tuple[]',\n },\n ],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n {\n inputs: [\n {\n components: [\n { internalType: 'address', name: 'target', type: 'address' },\n { internalType: 'uint256', name: 'gasLimit', type: 'uint256' },\n { internalType: 'bytes', name: 'callData', type: 'bytes' },\n ],\n internalType: 'struct MultiCallV2.Call[]',\n name: 'calls',\n type: 'tuple[]',\n },\n { internalType: 'uint256', name: 'gasBuffer', type: 'uint256' },\n ],\n name: 'multicallWithGasLimitation',\n outputs: [\n { internalType: 'uint256', name: 'blockNumber', type: 'uint256' },\n {\n components: [\n { internalType: 'bool', name: 'success', type: 'bool' },\n { internalType: 'uint256', name: 'gasUsed', type: 'uint256' },\n { internalType: 'bytes', name: 'returnData', type: 'bytes' },\n ],\n internalType: 'struct MultiCallV2.Result[]',\n name: 'returnData',\n type: 'tuple[]',\n },\n { internalType: 'uint256', name: 'lastSuccessIndex', type: 'uint256' },\n ],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n]\n","import { BigintIsh } from '@pancakeswap/sdk'\nimport { ChainId } from '@pancakeswap/chains'\nimport { toBigInt } from '@pancakeswap/utils/toBigInt'\nimport { PublicClient } from 'viem'\n\nimport {\n DEFAULT_GAS_BUFFER,\n DEFAULT_GAS_BUFFER_BY_CHAIN,\n DEFAULT_GAS_LIMIT,\n DEFAULT_GAS_LIMIT_BY_CHAIN,\n} from './constants'\nimport { getMulticallContract } from './getMulticallContract'\n\nexport type GetGasLimitParams = {\n chainId: ChainId\n client?: PublicClient\n\n // If provided then would override the gas limit got from on chain\n gasLimit?: BigintIsh\n\n // The gas limit should be whichever is smaller between gasLimit and maxGasLimit\n maxGasLimit?: BigintIsh\n\n gasBuffer?: BigintIsh\n}\n\nexport function getDefaultGasLimit(chainId?: ChainId) {\n const gasLimitOnChain = chainId && DEFAULT_GAS_LIMIT_BY_CHAIN[chainId]\n return gasLimitOnChain !== undefined ? gasLimitOnChain : DEFAULT_GAS_LIMIT\n}\n\nexport function getDefaultGasBuffer(chainId?: ChainId) {\n const gasBufferOnChain = chainId && DEFAULT_GAS_BUFFER_BY_CHAIN[chainId]\n return gasBufferOnChain !== undefined ? gasBufferOnChain : DEFAULT_GAS_BUFFER\n}\n\nexport type GetGasLimitOnChainParams = Pick<GetGasLimitParams, 'chainId' | 'client'>\n\nexport async function getGasLimitOnChain({ chainId, client }: GetGasLimitOnChainParams) {\n const multicall = getMulticallContract({ chainId, client })\n const gasLeft = (await multicall.read.gasLeft()) as bigint\n return gasLeft\n}\n\nexport async function getGasLimit({\n chainId,\n gasLimit: gasLimitInput,\n maxGasLimit: maxGasLimitInput = getDefaultGasLimit(chainId),\n gasBuffer: gasBufferInput = getDefaultGasBuffer(chainId),\n client,\n}: GetGasLimitParams) {\n const gasLimitOverride = gasLimitInput && toBigInt(gasLimitInput)\n const maxGasLimit = toBigInt(maxGasLimitInput)\n const gasBuffer = toBigInt(gasBufferInput)\n\n const gasLimit = gasLimitOverride || (await getGasLimitOnChain({ chainId, client })) || maxGasLimit\n const minGasLimit = gasLimit < maxGasLimit ? gasLimit : maxGasLimit\n return minGasLimit - gasBuffer\n}\n","export const multicall3ABI = [\n {\n inputs: [\n {\n components: [\n { internalType: 'address', name: 'target', type: 'address' },\n { internalType: 'bytes', name: 'callData', type: 'bytes' },\n ],\n internalType: 'struct Multicall2.Call[]',\n name: 'calls',\n type: 'tuple[]',\n },\n ],\n name: 'aggregate',\n outputs: [\n { internalType: 'uint256', name: 'blockNumber', type: 'uint256' },\n { internalType: 'bytes[]', name: 'returnData', type: 'bytes[]' },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [\n {\n components: [\n { internalType: 'address', name: 'target', type: 'address' },\n { internalType: 'bytes', name: 'callData', type: 'bytes' },\n ],\n internalType: 'struct Multicall2.Call[]',\n name: 'calls',\n type: 'tuple[]',\n },\n ],\n name: 'blockAndAggregate',\n outputs: [\n { internalType: 'uint256', name: 'blockNumber', type: 'uint256' },\n { internalType: 'bytes32', name: 'blockHash', type: 'bytes32' },\n {\n components: [\n { internalType: 'bool', name: 'success', type: 'bool' },\n { internalType: 'bytes', name: 'returnData', type: 'bytes' },\n ],\n internalType: 'struct Multicall2.Result[]',\n name: 'returnData',\n type: 'tuple[]',\n },\n ],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n {\n inputs: [{ internalType: 'uint256', name: 'blockNumber', type: 'uint256' }],\n name: 'getBlockHash',\n outputs: [{ internalType: 'bytes32', name: 'blockHash', type: 'bytes32' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'getBlockNumber',\n outputs: [{ internalType: 'uint256', name: 'blockNumber', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'getCurrentBlockCoinbase',\n outputs: [{ internalType: 'address', name: 'coinbase', type: 'address' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'getCurrentBlockDifficulty',\n outputs: [{ internalType: 'uint256', name: 'difficulty', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'getCurrentBlockGasLimit',\n outputs: [{ internalType: 'uint256', name: 'gaslimit', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'getCurrentBlockTimestamp',\n outputs: [{ internalType: 'uint256', name: 'timestamp', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [{ internalType: 'address', name: 'addr', type: 'address' }],\n name: 'getEthBalance',\n outputs: [{ internalType: 'uint256', name: 'balance', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'getLastBlockHash',\n outputs: [{ internalType: 'bytes32', name: 'blockHash', type: 'bytes32' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [\n { internalType: 'bool', name: 'requireSuccess', type: 'bool' },\n {\n components: [\n { internalType: 'address', name: 'target', type: 'address' },\n { internalType: 'bytes', name: 'callData', type: 'bytes' },\n ],\n internalType: 'struct Multicall2.Call[]',\n name: 'calls',\n type: 'tuple[]',\n },\n ],\n name: 'tryAggregate',\n outputs: [\n {\n components: [\n { internalType: 'bool', name: 'success', type: 'bool' },\n { internalType: 'bytes', name: 'returnData', type: 'bytes' },\n ],\n internalType: 'struct Multicall2.Result[]',\n name: 'returnData',\n type: 'tuple[]',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [\n { internalType: 'bool', name: 'requireSuccess', type: 'bool' },\n {\n components: [\n { internalType: 'address', name: 'target', type: 'address' },\n { internalType: 'bytes', name: 'callData', type: 'bytes' },\n ],\n internalType: 'struct Multicall2.Call[]',\n name: 'calls',\n type: 'tuple[]',\n },\n ],\n name: 'tryBlockAndAggregate',\n outputs: [\n { internalType: 'uint256', name: 'blockNumber', type: 'uint256' },\n { internalType: 'bytes32', name: 'blockHash', type: 'bytes32' },\n {\n components: [\n { internalType: 'bool', name: 'success', type: 'bool' },\n { internalType: 'bytes', name: 'returnData', type: 'bytes' },\n ],\n internalType: 'struct Multicall2.Result[]',\n name: 'returnData',\n type: 'tuple[]',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n] as const\n","import { ChainId } from '@pancakeswap/chains'\n\nimport { BLOCK_CONFLICT_TOLERANCE, DEFAULT_BLOCK_CONFLICT_TOLERANCE } from './constants'\n\nexport function getBlockConflictTolerance(chainId: ChainId) {\n return BLOCK_CONFLICT_TOLERANCE[chainId] || DEFAULT_BLOCK_CONFLICT_TOLERANCE\n}\n","import { toBigInt } from '@pancakeswap/utils/toBigInt'\n\nimport { GetGasLimitParams, getDefaultGasBuffer, getGasLimit } from './getGasLimit'\nimport { MulticallRequestWithGas } from './types'\nimport { getMulticallContract } from './getMulticallContract'\nimport { getBlockConflictTolerance } from './getBlockConflictTolerance'\n\nexport type CallByGasLimitParams = GetGasLimitParams & {\n // Normally we expect to get quotes from within the same block\n // But for some chains like BSC the block time is quite short so need some extra tolerance\n // 0 means no block conflict and all the multicall results should be queried within the same block\n blockConflictTolerance?: number\n\n // Treat unexecuted calls as failed calls\n dropUnexecutedCalls?: boolean\n}\n\nexport async function multicallByGasLimit(\n calls: MulticallRequestWithGas[],\n { chainId, gasBuffer = getDefaultGasBuffer(chainId), client, dropUnexecutedCalls, ...rest }: CallByGasLimitParams,\n) {\n const gasLimit = await getGasLimit({\n chainId,\n gasBuffer,\n client,\n ...rest,\n })\n const callChunks = splitCallsIntoChunks(calls, gasLimit)\n return callByChunks(callChunks, { gasBuffer, client, chainId, dropUnexecutedCalls })\n}\n\ntype CallParams = Pick<\n CallByGasLimitParams,\n 'chainId' | 'client' | 'gasBuffer' | 'blockConflictTolerance' | 'dropUnexecutedCalls'\n>\n\nexport type SingleCallResult = {\n result: string\n gasUsed: bigint\n success: boolean\n}\n\nexport type CallResult = {\n results: SingleCallResult[]\n // Will be the greatest block number if block conflict tolerance is not 0\n blockNumber: bigint\n}\n\nexport type MulticallReturn = CallResult & {\n lastSuccessIndex: number\n}\n\ntype CallReturnFromContract = [bigint, { success: boolean; gasUsed: bigint; returnData: string }[], bigint]\n\nfunction formatCallReturn([blockNumber, results, successIndex]: CallReturnFromContract): MulticallReturn {\n const lastSuccessIndex = Number(successIndex)\n return {\n lastSuccessIndex,\n blockNumber,\n results: results.slice(0, lastSuccessIndex + 1).map(({ gasUsed, success, returnData }) => ({\n gasUsed,\n success,\n result: returnData,\n })),\n }\n}\n\nasync function call(calls: MulticallRequestWithGas[], params: CallParams): Promise<CallResult> {\n const {\n chainId,\n client,\n gasBuffer = getDefaultGasBuffer(chainId),\n blockConflictTolerance = getBlockConflictTolerance(chainId),\n dropUnexecutedCalls = false,\n } = params\n if (!calls.length) {\n return {\n results: [],\n blockNumber: 0n,\n }\n }\n\n const contract = getMulticallContract({ chainId, client })\n const { result } = await contract.simulate.multicallWithGasLimitation([calls, gasBuffer])\n const { results, lastSuccessIndex, blockNumber } = formatCallReturn(result as CallReturnFromContract)\n if (lastSuccessIndex === calls.length - 1) {\n return {\n results,\n blockNumber,\n }\n }\n console.warn(\n `Gas limit reached. Total num of ${calls.length} calls. First ${\n lastSuccessIndex + 1\n } calls executed. The remaining ${\n calls.length - lastSuccessIndex - 1\n } calls are not executed. Pls try adjust the gas limit per call.`,\n )\n const remainingCalls = calls.slice(lastSuccessIndex + 1)\n if (dropUnexecutedCalls) {\n return {\n results: [...results, ...remainingCalls.map(() => ({ result: '0x', gasUsed: 0n, success: false }))],\n blockNumber,\n }\n }\n const { results: remainingResults, blockNumber: nextBlockNumber } = await call(\n calls.slice(lastSuccessIndex + 1),\n params,\n )\n if (Number(nextBlockNumber - blockNumber) > blockConflictTolerance) {\n throw new Error(\n `Multicall failed because of block conflict. Latest calls are made at block ${nextBlockNumber} while last calls made at block ${blockNumber}. Block conflict tolerance is ${blockConflictTolerance}`,\n )\n }\n return {\n results: [...results, ...remainingResults],\n // Use the latest block number\n blockNumber: nextBlockNumber,\n }\n}\n\nasync function callByChunks(chunks: MulticallRequestWithGas[][], params: CallParams): Promise<CallResult> {\n const { blockConflictTolerance = getBlockConflictTolerance(params.chainId) } = params\n const callReturns = await Promise.all(chunks.map((chunk) => call(chunk, params)))\n\n let minBlock = 0n\n let maxBlock = 0n\n let results: SingleCallResult[] = []\n for (const { results: callResults, blockNumber } of callReturns) {\n if (minBlock === 0n || blockNumber < minBlock) {\n minBlock = blockNumber\n }\n if (blockNumber > maxBlock) {\n maxBlock = blockNumber\n }\n if (Number(maxBlock - minBlock) > blockConflictTolerance) {\n throw new Error(\n `Multicall failed because of block conflict. Min block is ${minBlock} while max block is ${maxBlock}. Block conflict tolerance is ${blockConflictTolerance}`,\n )\n }\n results = [...results, ...callResults]\n }\n return {\n results,\n blockNumber: maxBlock,\n }\n}\n\nfunction splitCallsIntoChunks(calls: MulticallRequestWithGas[], gasLimit: bigint): MulticallRequestWithGas[][] {\n const chunks: MulticallRequestWithGas[][] = [[]]\n\n let gasLeft = gasLimit\n for (const callRequest of calls) {\n const { target, callData, gasLimit: gasCostLimit } = callRequest\n const singleGasLimit = toBigInt(gasCostLimit)\n const currentChunk = chunks[chunks.length - 1]\n if (singleGasLimit > gasLeft) {\n chunks.push([callRequest])\n gasLeft = gasLimit - singleGasLimit\n\n // Single call exceeds the gas limit\n if (gasLeft < 0n) {\n console.warn(\n `Multicall request may fail as the gas cost of a single call exceeds the gas limit ${gasLimit}. Gas cost: ${singleGasLimit}. To: ${target}. Data: ${callData}`,\n )\n }\n continue\n }\n\n currentChunk.push(callRequest)\n gasLeft -= singleGasLimit\n }\n\n return chunks\n}\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -25,6 +25,23 @@ var MULTICALL_ADDRESS = {
|
|
|
25
25
|
[ChainId.OPBNB_TESTNET]: "0x6A70ED893D85cf6D4059e1CF3e63a48e4D204D32",
|
|
26
26
|
[ChainId.SCROLL_SEPOLIA]: "0x052a99849Ef2e13a5CB28275862991671D4b6fF5"
|
|
27
27
|
};
|
|
28
|
+
var MULTICALL3_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11";
|
|
29
|
+
var MULTICALL3_ADDRESSES = {
|
|
30
|
+
[ChainId.ETHEREUM]: MULTICALL3_ADDRESS,
|
|
31
|
+
[ChainId.GOERLI]: MULTICALL3_ADDRESS,
|
|
32
|
+
[ChainId.BSC]: MULTICALL3_ADDRESS,
|
|
33
|
+
[ChainId.BSC_TESTNET]: MULTICALL3_ADDRESS,
|
|
34
|
+
[ChainId.ZKSYNC_TESTNET]: "0xF9cda624FBC7e059355ce98a31693d299FACd963",
|
|
35
|
+
[ChainId.ZKSYNC]: "0xF9cda624FBC7e059355ce98a31693d299FACd963",
|
|
36
|
+
[ChainId.ARBITRUM_ONE]: MULTICALL3_ADDRESS,
|
|
37
|
+
[ChainId.ARBITRUM_GOERLI]: MULTICALL3_ADDRESS,
|
|
38
|
+
[ChainId.POLYGON_ZKEVM]: MULTICALL3_ADDRESS,
|
|
39
|
+
[ChainId.POLYGON_ZKEVM_TESTNET]: MULTICALL3_ADDRESS,
|
|
40
|
+
[ChainId.OPBNB]: MULTICALL3_ADDRESS,
|
|
41
|
+
[ChainId.OPBNB_TESTNET]: MULTICALL3_ADDRESS,
|
|
42
|
+
[ChainId.BASE_TESTNET]: MULTICALL3_ADDRESS,
|
|
43
|
+
[ChainId.SCROLL_SEPOLIA]: MULTICALL3_ADDRESS
|
|
44
|
+
};
|
|
28
45
|
var DEFAULT_BLOCK_CONFLICT_TOLERANCE = 0;
|
|
29
46
|
var BLOCK_CONFLICT_TOLERANCE = {
|
|
30
47
|
[ChainId.BSC]: 3,
|
|
@@ -150,6 +167,9 @@ function getMulticallContract({
|
|
|
150
167
|
}
|
|
151
168
|
return getContract({ abi: iMulticallABI, address, publicClient: client });
|
|
152
169
|
}
|
|
170
|
+
function getMulticall3ContractAddress(chainId) {
|
|
171
|
+
return MULTICALL3_ADDRESSES[chainId || ChainId.BSC] || MULTICALL3_ADDRESS;
|
|
172
|
+
}
|
|
153
173
|
|
|
154
174
|
// src/getGasLimit.ts
|
|
155
175
|
function getDefaultGasLimit(chainId) {
|
|
@@ -180,6 +200,173 @@ async function getGasLimit({
|
|
|
180
200
|
return minGasLimit - gasBuffer;
|
|
181
201
|
}
|
|
182
202
|
|
|
203
|
+
// src/abis/IMulticall3.ts
|
|
204
|
+
var multicall3ABI = [
|
|
205
|
+
{
|
|
206
|
+
inputs: [
|
|
207
|
+
{
|
|
208
|
+
components: [
|
|
209
|
+
{ internalType: "address", name: "target", type: "address" },
|
|
210
|
+
{ internalType: "bytes", name: "callData", type: "bytes" }
|
|
211
|
+
],
|
|
212
|
+
internalType: "struct Multicall2.Call[]",
|
|
213
|
+
name: "calls",
|
|
214
|
+
type: "tuple[]"
|
|
215
|
+
}
|
|
216
|
+
],
|
|
217
|
+
name: "aggregate",
|
|
218
|
+
outputs: [
|
|
219
|
+
{ internalType: "uint256", name: "blockNumber", type: "uint256" },
|
|
220
|
+
{ internalType: "bytes[]", name: "returnData", type: "bytes[]" }
|
|
221
|
+
],
|
|
222
|
+
stateMutability: "view",
|
|
223
|
+
type: "function"
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
inputs: [
|
|
227
|
+
{
|
|
228
|
+
components: [
|
|
229
|
+
{ internalType: "address", name: "target", type: "address" },
|
|
230
|
+
{ internalType: "bytes", name: "callData", type: "bytes" }
|
|
231
|
+
],
|
|
232
|
+
internalType: "struct Multicall2.Call[]",
|
|
233
|
+
name: "calls",
|
|
234
|
+
type: "tuple[]"
|
|
235
|
+
}
|
|
236
|
+
],
|
|
237
|
+
name: "blockAndAggregate",
|
|
238
|
+
outputs: [
|
|
239
|
+
{ internalType: "uint256", name: "blockNumber", type: "uint256" },
|
|
240
|
+
{ internalType: "bytes32", name: "blockHash", type: "bytes32" },
|
|
241
|
+
{
|
|
242
|
+
components: [
|
|
243
|
+
{ internalType: "bool", name: "success", type: "bool" },
|
|
244
|
+
{ internalType: "bytes", name: "returnData", type: "bytes" }
|
|
245
|
+
],
|
|
246
|
+
internalType: "struct Multicall2.Result[]",
|
|
247
|
+
name: "returnData",
|
|
248
|
+
type: "tuple[]"
|
|
249
|
+
}
|
|
250
|
+
],
|
|
251
|
+
stateMutability: "nonpayable",
|
|
252
|
+
type: "function"
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
inputs: [{ internalType: "uint256", name: "blockNumber", type: "uint256" }],
|
|
256
|
+
name: "getBlockHash",
|
|
257
|
+
outputs: [{ internalType: "bytes32", name: "blockHash", type: "bytes32" }],
|
|
258
|
+
stateMutability: "view",
|
|
259
|
+
type: "function"
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
inputs: [],
|
|
263
|
+
name: "getBlockNumber",
|
|
264
|
+
outputs: [{ internalType: "uint256", name: "blockNumber", type: "uint256" }],
|
|
265
|
+
stateMutability: "view",
|
|
266
|
+
type: "function"
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
inputs: [],
|
|
270
|
+
name: "getCurrentBlockCoinbase",
|
|
271
|
+
outputs: [{ internalType: "address", name: "coinbase", type: "address" }],
|
|
272
|
+
stateMutability: "view",
|
|
273
|
+
type: "function"
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
inputs: [],
|
|
277
|
+
name: "getCurrentBlockDifficulty",
|
|
278
|
+
outputs: [{ internalType: "uint256", name: "difficulty", type: "uint256" }],
|
|
279
|
+
stateMutability: "view",
|
|
280
|
+
type: "function"
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
inputs: [],
|
|
284
|
+
name: "getCurrentBlockGasLimit",
|
|
285
|
+
outputs: [{ internalType: "uint256", name: "gaslimit", type: "uint256" }],
|
|
286
|
+
stateMutability: "view",
|
|
287
|
+
type: "function"
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
inputs: [],
|
|
291
|
+
name: "getCurrentBlockTimestamp",
|
|
292
|
+
outputs: [{ internalType: "uint256", name: "timestamp", type: "uint256" }],
|
|
293
|
+
stateMutability: "view",
|
|
294
|
+
type: "function"
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
inputs: [{ internalType: "address", name: "addr", type: "address" }],
|
|
298
|
+
name: "getEthBalance",
|
|
299
|
+
outputs: [{ internalType: "uint256", name: "balance", type: "uint256" }],
|
|
300
|
+
stateMutability: "view",
|
|
301
|
+
type: "function"
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
inputs: [],
|
|
305
|
+
name: "getLastBlockHash",
|
|
306
|
+
outputs: [{ internalType: "bytes32", name: "blockHash", type: "bytes32" }],
|
|
307
|
+
stateMutability: "view",
|
|
308
|
+
type: "function"
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
inputs: [
|
|
312
|
+
{ internalType: "bool", name: "requireSuccess", type: "bool" },
|
|
313
|
+
{
|
|
314
|
+
components: [
|
|
315
|
+
{ internalType: "address", name: "target", type: "address" },
|
|
316
|
+
{ internalType: "bytes", name: "callData", type: "bytes" }
|
|
317
|
+
],
|
|
318
|
+
internalType: "struct Multicall2.Call[]",
|
|
319
|
+
name: "calls",
|
|
320
|
+
type: "tuple[]"
|
|
321
|
+
}
|
|
322
|
+
],
|
|
323
|
+
name: "tryAggregate",
|
|
324
|
+
outputs: [
|
|
325
|
+
{
|
|
326
|
+
components: [
|
|
327
|
+
{ internalType: "bool", name: "success", type: "bool" },
|
|
328
|
+
{ internalType: "bytes", name: "returnData", type: "bytes" }
|
|
329
|
+
],
|
|
330
|
+
internalType: "struct Multicall2.Result[]",
|
|
331
|
+
name: "returnData",
|
|
332
|
+
type: "tuple[]"
|
|
333
|
+
}
|
|
334
|
+
],
|
|
335
|
+
stateMutability: "view",
|
|
336
|
+
type: "function"
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
inputs: [
|
|
340
|
+
{ internalType: "bool", name: "requireSuccess", type: "bool" },
|
|
341
|
+
{
|
|
342
|
+
components: [
|
|
343
|
+
{ internalType: "address", name: "target", type: "address" },
|
|
344
|
+
{ internalType: "bytes", name: "callData", type: "bytes" }
|
|
345
|
+
],
|
|
346
|
+
internalType: "struct Multicall2.Call[]",
|
|
347
|
+
name: "calls",
|
|
348
|
+
type: "tuple[]"
|
|
349
|
+
}
|
|
350
|
+
],
|
|
351
|
+
name: "tryBlockAndAggregate",
|
|
352
|
+
outputs: [
|
|
353
|
+
{ internalType: "uint256", name: "blockNumber", type: "uint256" },
|
|
354
|
+
{ internalType: "bytes32", name: "blockHash", type: "bytes32" },
|
|
355
|
+
{
|
|
356
|
+
components: [
|
|
357
|
+
{ internalType: "bool", name: "success", type: "bool" },
|
|
358
|
+
{ internalType: "bytes", name: "returnData", type: "bytes" }
|
|
359
|
+
],
|
|
360
|
+
internalType: "struct Multicall2.Result[]",
|
|
361
|
+
name: "returnData",
|
|
362
|
+
type: "tuple[]"
|
|
363
|
+
}
|
|
364
|
+
],
|
|
365
|
+
stateMutability: "view",
|
|
366
|
+
type: "function"
|
|
367
|
+
}
|
|
368
|
+
];
|
|
369
|
+
|
|
183
370
|
// src/getBlockConflictTolerance.ts
|
|
184
371
|
function getBlockConflictTolerance(chainId) {
|
|
185
372
|
return BLOCK_CONFLICT_TOLERANCE[chainId] || DEFAULT_BLOCK_CONFLICT_TOLERANCE;
|
|
@@ -304,6 +491,6 @@ function splitCallsIntoChunks(calls, gasLimit) {
|
|
|
304
491
|
return chunks;
|
|
305
492
|
}
|
|
306
493
|
|
|
307
|
-
export { BLOCK_CONFLICT_TOLERANCE, DEFAULT_BLOCK_CONFLICT_TOLERANCE, DEFAULT_GAS_BUFFER, DEFAULT_GAS_BUFFER_BY_CHAIN, DEFAULT_GAS_LIMIT, DEFAULT_GAS_LIMIT_BY_CHAIN, MULTICALL_ADDRESS, getBlockConflictTolerance, getDefaultGasBuffer, getDefaultGasLimit, getGasLimit, getGasLimitOnChain, getMulticallContract, iMulticallABI, multicallByGasLimit };
|
|
494
|
+
export { BLOCK_CONFLICT_TOLERANCE, DEFAULT_BLOCK_CONFLICT_TOLERANCE, DEFAULT_GAS_BUFFER, DEFAULT_GAS_BUFFER_BY_CHAIN, DEFAULT_GAS_LIMIT, DEFAULT_GAS_LIMIT_BY_CHAIN, MULTICALL3_ADDRESS, MULTICALL3_ADDRESSES, MULTICALL_ADDRESS, getBlockConflictTolerance, getDefaultGasBuffer, getDefaultGasLimit, getGasLimit, getGasLimitOnChain, getMulticall3ContractAddress, getMulticallContract, iMulticallABI, multicall3ABI, multicallByGasLimit };
|
|
308
495
|
//# sourceMappingURL=out.js.map
|
|
309
496
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../utils/toBigInt.ts","../src/constants/contracts.ts","../src/constants/blockConflictTolerance.ts","../src/constants/gasLimit.ts","../src/getMulticallContract.ts","../src/abis/IMulticall.ts","../src/getGasLimit.ts","../src/getBlockConflictTolerance.ts","../src/multicall.ts"],"names":["ChainId"],"mappings":";AAEO,SAAS,SAAS,KAAwB;AAC/C,SAAO,OAAO,IAAI,SAAS,CAAC;AAC9B;;;ACJA,SAAS,eAAe;AAGjB,IAAM,oBAAoD;AAAA,EAC/D,CAAC,QAAQ,MAAM,GAAG;AAAA,EAClB,CAAC,QAAQ,GAAG,GAAG;AAAA,EACf,CAAC,QAAQ,QAAQ,GAAG;AAAA,EACpB,CAAC,QAAQ,YAAY,GAAG;AAAA,EACxB,CAAC,QAAQ,aAAa,GAAG;AAAA,EACzB,CAAC,QAAQ,KAAK,GAAG;AAAA,EACjB,CAAC,QAAQ,IAAI,GAAG;AAAA,EAChB,CAAC,QAAQ,KAAK,GAAG;AAAA;AAAA,EAGjB,CAAC,QAAQ,WAAW,GAAG;AAAA,EACvB,CAAC,QAAQ,MAAM,GAAG;AAAA,EAClB,CAAC,QAAQ,eAAe,GAAG;AAAA,EAC3B,CAAC,QAAQ,qBAAqB,GAAG;AAAA,EACjC,CAAC,QAAQ,cAAc,GAAG;AAAA,EAC1B,CAAC,QAAQ,aAAa,GAAG;AAAA,EAC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AAM,QAAQ,IAAI,OAAO,IAAI,CAAC,UAAU,KAAK,OAAO,MAAM,CAAC,CAAC;AAEhF,MAAI,WAAW;AACf,MAAI,WAAW;AACf,MAAI,UAA8B,CAAC;AACnC,aAAW,EAAE,SAAS,aAAa,YAAY,KAAK,aAAa;AAC/D,QAAI,aAAa,MAAM,cAAc,UAAU;AAC7C,iBAAW;AAAA,IACb;AACA,QAAI,cAAc,UAAU;AAC1B,iBAAW;AAAA,IACb;AACA,QAAI,OAAO,WAAW,QAAQ,IAAI,wBAAwB;AACxD,YAAM,IAAI;AAAA,QACR,4DAA4D,+BAA+B,yCAAyC;AAAA,MACtI;AAAA,IACF;AACA,cAAU,CAAC,GAAG,SAAS,GAAG,WAAW;AAAA,EACvC;AACA,SAAO;AAAA,IACL;AAAA,IACA,aAAa;AAAA,EACf;AACF;AAEA,SAAS,qBAAqB,OAAkC,UAA+C;AAC7G,QAAM,SAAsC,CAAC,CAAC,CAAC;AAE/C,MAAI,UAAU;AACd,aAAW,eAAe,OAAO;AAC/B,UAAM,EAAE,QAAQ,UAAU,UAAU,aAAa,IAAI;AACrD,UAAM,iBAAiB,SAAS,YAAY;AAC5C,UAAM,eAAe,OAAO,OAAO,SAAS,CAAC;AAC7C,QAAI,iBAAiB,SAAS;AAC5B,aAAO,KAAK,CAAC,WAAW,CAAC;AACzB,gBAAU,WAAW;AAGrB,UAAI,UAAU,IAAI;AAChB,gBAAQ;AAAA,UACN,qFAAqF,uBAAuB,uBAAuB,iBAAiB;AAAA,QACtJ;AAAA,MACF;AACA;AAAA,IACF;AAEA,iBAAa,KAAK,WAAW;AAC7B,eAAW;AAAA,EACb;AAEA,SAAO;AACT","sourcesContent":["import { BigintIsh } from '@pancakeswap/swap-sdk-core'\n\nexport function toBigInt(num: BigintIsh): bigint {\n return BigInt(num.toString())\n}\n","import { ChainId } from '@pancakeswap/chains'\nimport { Address } from 'viem'\n\nexport const MULTICALL_ADDRESS: { [key in ChainId]?: Address } = {\n [ChainId.ZKSYNC]: '0x95071cBD09184083E7F732a710c2e30c9882Fd5f',\n [ChainId.BSC]: '0x39eecaE833c944ebb94942Fa44CaE46e87a8Da17',\n [ChainId.ETHEREUM]: '0xC0916D7E360c31D5F6D0c497E6a36B7B0E80e3cf',\n [ChainId.ARBITRUM_ONE]: '0xbFfE39cDD04f0183e0493c1Deb6E275c5cf84AdF',\n [ChainId.POLYGON_ZKEVM]: '0xe05b539447B17630Cb087473F6b50E5c5f73FDeb',\n [ChainId.LINEA]: '0x6E6B30d65D605DAa4CaC65eB270100Ecca36b140',\n [ChainId.BASE]: '0x3EFaAb8D7A631cfF5ccF5f149d1Bbb3B5bfda2C0',\n [ChainId.OPBNB]: '0xeF1511D29fB37cb87E33339EeC9BE13AB46E3b50',\n\n // Testnets\n [ChainId.BSC_TESTNET]: '0xeeF6ff30cF5D5b8aBA0DE16A01d17A0697a275b5',\n [ChainId.GOERLI]: '0xD55CAFAB2Ffa1139Be46bc5C0b8259c620050dFC',\n [ChainId.ARBITRUM_GOERLI]: '0xe12a5c707Fb528acbE6117b20AF1f7c20b0A8077',\n [ChainId.POLYGON_ZKEVM_TESTNET]: '0x236e713bFF45adb30e25D1c29A887aBCb0Ea7E21',\n [ChainId.ZKSYNC_TESTNET]: '0x8A23CB45E5F4d5a1b2DB673663Ea2aAedc48acff',\n [ChainId.LINEA_TESTNET]: '0x990010b6DBA3e7faa025790bC0433A9f690c65F3',\n [ChainId.BASE_TESTNET]: '0x6F7f93D929d6FBaF16c245e42846EF21aee23437',\n [ChainId.OPBNB_TESTNET]: '0x6A70ED893D85cf6D4059e1CF3e63a48e4D204D32',\n [ChainId.SCROLL_SEPOLIA]: '0x052a99849Ef2e13a5CB28275862991671D4b6fF5',\n}\n","import { ChainId } from '@pancakeswap/chains'\n\nexport const DEFAULT_BLOCK_CONFLICT_TOLERANCE = 0\n\nexport const BLOCK_CONFLICT_TOLERANCE: { [key in ChainId]?: number } = {\n [ChainId.BSC]: 3,\n [ChainId.ETHEREUM]: 1,\n [ChainId.ARBITRUM_ONE]: 5,\n [ChainId.POLYGON_ZKEVM]: 1,\n [ChainId.ZKSYNC]: 3,\n [ChainId.LINEA]: 3,\n [ChainId.BASE]: 3,\n [ChainId.OPBNB]: 3,\n\n // Testnets\n [ChainId.BSC_TESTNET]: 3,\n [ChainId.GOERLI]: 1,\n [ChainId.ARBITRUM_GOERLI]: 5,\n [ChainId.POLYGON_ZKEVM_TESTNET]: 1,\n [ChainId.ZKSYNC_TESTNET]: 3,\n [ChainId.LINEA_TESTNET]: 3,\n [ChainId.OPBNB_TESTNET]: 3,\n [ChainId.BASE_TESTNET]: 3,\n [ChainId.SCROLL_SEPOLIA]: 3,\n}\n","import { ChainId } from '@pancakeswap/chains'\n\nexport const DEFAULT_GAS_LIMIT = 150000000n\n\nexport const DEFAULT_GAS_LIMIT_BY_CHAIN: { [key in ChainId]?: bigint } = {\n [ChainId.BSC]: 100000000n,\n [ChainId.ZKSYNC]: 500000000n,\n [ChainId.POLYGON_ZKEVM]: 1500000n,\n [ChainId.BASE]: 130000000n,\n}\n\nexport const DEFAULT_GAS_BUFFER = 3000000n\n\nexport const DEFAULT_GAS_BUFFER_BY_CHAIN: { [key in ChainId]?: bigint } = {\n [ChainId.BSC]: DEFAULT_GAS_BUFFER,\n [ChainId.POLYGON_ZKEVM]: 0n,\n}\n","import { ChainId } from '@pancakeswap/chains'\nimport { GetContractReturnType, PublicClient, getContract } from 'viem'\n\nimport { MULTICALL_ADDRESS } from './constants/contracts'\nimport { iMulticallABI } from './abis/IMulticall'\n\ntype Params = {\n chainId: ChainId\n client?: PublicClient\n}\n\nexport function getMulticallContract({\n chainId,\n client,\n}: Params): GetContractReturnType<typeof iMulticallABI, PublicClient> {\n const address = MULTICALL_ADDRESS[chainId]\n if (!address) {\n throw new Error(`PancakeMulticall not supported on chain ${chainId}`)\n }\n\n return getContract({ abi: iMulticallABI, address, publicClient: client })\n}\n","export const iMulticallABI = [\n {\n inputs: [],\n name: 'gasLeft',\n outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'gaslimit',\n outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [\n {\n components: [\n { internalType: 'address', name: 'target', type: 'address' },\n { internalType: 'uint256', name: 'gasLimit', type: 'uint256' },\n { internalType: 'bytes', name: 'callData', type: 'bytes' },\n ],\n internalType: 'struct MultiCallV2.Call[]',\n name: 'calls',\n type: 'tuple[]',\n },\n ],\n name: 'multicall',\n outputs: [\n { internalType: 'uint256', name: 'blockNumber', type: 'uint256' },\n {\n components: [\n { internalType: 'bool', name: 'success', type: 'bool' },\n { internalType: 'uint256', name: 'gasUsed', type: 'uint256' },\n { internalType: 'bytes', name: 'returnData', type: 'bytes' },\n ],\n internalType: 'struct MultiCallV2.Result[]',\n name: 'returnData',\n type: 'tuple[]',\n },\n ],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n {\n inputs: [\n {\n components: [\n { internalType: 'address', name: 'target', type: 'address' },\n { internalType: 'uint256', name: 'gasLimit', type: 'uint256' },\n { internalType: 'bytes', name: 'callData', type: 'bytes' },\n ],\n internalType: 'struct MultiCallV2.Call[]',\n name: 'calls',\n type: 'tuple[]',\n },\n { internalType: 'uint256', name: 'gasBuffer', type: 'uint256' },\n ],\n name: 'multicallWithGasLimitation',\n outputs: [\n { internalType: 'uint256', name: 'blockNumber', type: 'uint256' },\n {\n components: [\n { internalType: 'bool', name: 'success', type: 'bool' },\n { internalType: 'uint256', name: 'gasUsed', type: 'uint256' },\n { internalType: 'bytes', name: 'returnData', type: 'bytes' },\n ],\n internalType: 'struct MultiCallV2.Result[]',\n name: 'returnData',\n type: 'tuple[]',\n },\n { internalType: 'uint256', name: 'lastSuccessIndex', type: 'uint256' },\n ],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n]\n","import { BigintIsh } from '@pancakeswap/sdk'\nimport { ChainId } from '@pancakeswap/chains'\nimport { toBigInt } from '@pancakeswap/utils/toBigInt'\nimport { PublicClient } from 'viem'\n\nimport {\n DEFAULT_GAS_BUFFER,\n DEFAULT_GAS_BUFFER_BY_CHAIN,\n DEFAULT_GAS_LIMIT,\n DEFAULT_GAS_LIMIT_BY_CHAIN,\n} from './constants'\nimport { getMulticallContract } from './getMulticallContract'\n\nexport type GetGasLimitParams = {\n chainId: ChainId\n client?: PublicClient\n\n // If provided then would override the gas limit got from on chain\n gasLimit?: BigintIsh\n\n // The gas limit should be whichever is smaller between gasLimit and maxGasLimit\n maxGasLimit?: BigintIsh\n\n gasBuffer?: BigintIsh\n}\n\nexport function getDefaultGasLimit(chainId?: ChainId) {\n const gasLimitOnChain = chainId && DEFAULT_GAS_LIMIT_BY_CHAIN[chainId]\n return gasLimitOnChain !== undefined ? gasLimitOnChain : DEFAULT_GAS_LIMIT\n}\n\nexport function getDefaultGasBuffer(chainId?: ChainId) {\n const gasBufferOnChain = chainId && DEFAULT_GAS_BUFFER_BY_CHAIN[chainId]\n return gasBufferOnChain !== undefined ? gasBufferOnChain : DEFAULT_GAS_BUFFER\n}\n\nexport type GetGasLimitOnChainParams = Pick<GetGasLimitParams, 'chainId' | 'client'>\n\nexport async function getGasLimitOnChain({ chainId, client }: GetGasLimitOnChainParams) {\n const multicall = getMulticallContract({ chainId, client })\n const gasLeft = (await multicall.read.gasLeft()) as bigint\n return gasLeft\n}\n\nexport async function getGasLimit({\n chainId,\n gasLimit: gasLimitInput,\n maxGasLimit: maxGasLimitInput = getDefaultGasLimit(chainId),\n gasBuffer: gasBufferInput = getDefaultGasBuffer(chainId),\n client,\n}: GetGasLimitParams) {\n const gasLimitOverride = gasLimitInput && toBigInt(gasLimitInput)\n const maxGasLimit = toBigInt(maxGasLimitInput)\n const gasBuffer = toBigInt(gasBufferInput)\n\n const gasLimit = gasLimitOverride || (await getGasLimitOnChain({ chainId, client })) || maxGasLimit\n const minGasLimit = gasLimit < maxGasLimit ? gasLimit : maxGasLimit\n return minGasLimit - gasBuffer\n}\n","import { ChainId } from '@pancakeswap/chains'\n\nimport { BLOCK_CONFLICT_TOLERANCE, DEFAULT_BLOCK_CONFLICT_TOLERANCE } from './constants'\n\nexport function getBlockConflictTolerance(chainId: ChainId) {\n return BLOCK_CONFLICT_TOLERANCE[chainId] || DEFAULT_BLOCK_CONFLICT_TOLERANCE\n}\n","import { toBigInt } from '@pancakeswap/utils/toBigInt'\n\nimport { GetGasLimitParams, getDefaultGasBuffer, getGasLimit } from './getGasLimit'\nimport { MulticallRequestWithGas } from './types'\nimport { getMulticallContract } from './getMulticallContract'\nimport { getBlockConflictTolerance } from './getBlockConflictTolerance'\n\nexport type CallByGasLimitParams = GetGasLimitParams & {\n // Normally we expect to get quotes from within the same block\n // But for some chains like BSC the block time is quite short so need some extra tolerance\n // 0 means no block conflict and all the multicall results should be queried within the same block\n blockConflictTolerance?: number\n\n // Treat unexecuted calls as failed calls\n dropUnexecutedCalls?: boolean\n}\n\nexport async function multicallByGasLimit(\n calls: MulticallRequestWithGas[],\n { chainId, gasBuffer = getDefaultGasBuffer(chainId), client, dropUnexecutedCalls, ...rest }: CallByGasLimitParams,\n) {\n const gasLimit = await getGasLimit({\n chainId,\n gasBuffer,\n client,\n ...rest,\n })\n const callChunks = splitCallsIntoChunks(calls, gasLimit)\n return callByChunks(callChunks, { gasBuffer, client, chainId, dropUnexecutedCalls })\n}\n\ntype CallParams = Pick<\n CallByGasLimitParams,\n 'chainId' | 'client' | 'gasBuffer' | 'blockConflictTolerance' | 'dropUnexecutedCalls'\n>\n\nexport type SingleCallResult = {\n result: string\n gasUsed: bigint\n success: boolean\n}\n\nexport type CallResult = {\n results: SingleCallResult[]\n // Will be the greatest block number if block conflict tolerance is not 0\n blockNumber: bigint\n}\n\nexport type MulticallReturn = CallResult & {\n lastSuccessIndex: number\n}\n\ntype CallReturnFromContract = [bigint, { success: boolean; gasUsed: bigint; returnData: string }[], bigint]\n\nfunction formatCallReturn([blockNumber, results, successIndex]: CallReturnFromContract): MulticallReturn {\n const lastSuccessIndex = Number(successIndex)\n return {\n lastSuccessIndex,\n blockNumber,\n results: results.slice(0, lastSuccessIndex + 1).map(({ gasUsed, success, returnData }) => ({\n gasUsed,\n success,\n result: returnData,\n })),\n }\n}\n\nasync function call(calls: MulticallRequestWithGas[], params: CallParams): Promise<CallResult> {\n const {\n chainId,\n client,\n gasBuffer = getDefaultGasBuffer(chainId),\n blockConflictTolerance = getBlockConflictTolerance(chainId),\n dropUnexecutedCalls = false,\n } = params\n if (!calls.length) {\n return {\n results: [],\n blockNumber: 0n,\n }\n }\n\n const contract = getMulticallContract({ chainId, client })\n const { result } = await contract.simulate.multicallWithGasLimitation([calls, gasBuffer])\n const { results, lastSuccessIndex, blockNumber } = formatCallReturn(result as CallReturnFromContract)\n if (lastSuccessIndex === calls.length - 1) {\n return {\n results,\n blockNumber,\n }\n }\n console.warn(\n `Gas limit reached. Total num of ${calls.length} calls. First ${\n lastSuccessIndex + 1\n } calls executed. The remaining ${\n calls.length - lastSuccessIndex - 1\n } calls are not executed. Pls try adjust the gas limit per call.`,\n )\n const remainingCalls = calls.slice(lastSuccessIndex + 1)\n if (dropUnexecutedCalls) {\n return {\n results: [...results, ...remainingCalls.map(() => ({ result: '0x', gasUsed: 0n, success: false }))],\n blockNumber,\n }\n }\n const { results: remainingResults, blockNumber: nextBlockNumber } = await call(\n calls.slice(lastSuccessIndex + 1),\n params,\n )\n if (Number(nextBlockNumber - blockNumber) > blockConflictTolerance) {\n throw new Error(\n `Multicall failed because of block conflict. Latest calls are made at block ${nextBlockNumber} while last calls made at block ${blockNumber}. Block conflict tolerance is ${blockConflictTolerance}`,\n )\n }\n return {\n results: [...results, ...remainingResults],\n // Use the latest block number\n blockNumber: nextBlockNumber,\n }\n}\n\nasync function callByChunks(chunks: MulticallRequestWithGas[][], params: CallParams): Promise<CallResult> {\n const { blockConflictTolerance = getBlockConflictTolerance(params.chainId) } = params\n const callReturns = await Promise.all(chunks.map((chunk) => call(chunk, params)))\n\n let minBlock = 0n\n let maxBlock = 0n\n let results: SingleCallResult[] = []\n for (const { results: callResults, blockNumber } of callReturns) {\n if (minBlock === 0n || blockNumber < minBlock) {\n minBlock = blockNumber\n }\n if (blockNumber > maxBlock) {\n maxBlock = blockNumber\n }\n if (Number(maxBlock - minBlock) > blockConflictTolerance) {\n throw new Error(\n `Multicall failed because of block conflict. Min block is ${minBlock} while max block is ${maxBlock}. Block conflict tolerance is ${blockConflictTolerance}`,\n )\n }\n results = [...results, ...callResults]\n }\n return {\n results,\n blockNumber: maxBlock,\n }\n}\n\nfunction splitCallsIntoChunks(calls: MulticallRequestWithGas[], gasLimit: bigint): MulticallRequestWithGas[][] {\n const chunks: MulticallRequestWithGas[][] = [[]]\n\n let gasLeft = gasLimit\n for (const callRequest of calls) {\n const { target, callData, gasLimit: gasCostLimit } = callRequest\n const singleGasLimit = toBigInt(gasCostLimit)\n const currentChunk = chunks[chunks.length - 1]\n if (singleGasLimit > gasLeft) {\n chunks.push([callRequest])\n gasLeft = gasLimit - singleGasLimit\n\n // Single call exceeds the gas limit\n if (gasLeft < 0n) {\n console.warn(\n `Multicall request may fail as the gas cost of a single call exceeds the gas limit ${gasLimit}. Gas cost: ${singleGasLimit}. To: ${target}. Data: ${callData}`,\n )\n }\n continue\n }\n\n currentChunk.push(callRequest)\n gasLeft -= singleGasLimit\n }\n\n return chunks\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../utils/toBigInt.ts","../src/constants/contracts.ts","../src/constants/blockConflictTolerance.ts","../src/constants/gasLimit.ts","../src/getMulticallContract.ts","../src/abis/IMulticall.ts","../src/getGasLimit.ts","../src/abis/IMulticall3.ts","../src/getBlockConflictTolerance.ts","../src/multicall.ts"],"names":["ChainId"],"mappings":";AAEO,SAAS,SAAS,KAAwB;AAC/C,SAAO,OAAO,IAAI,SAAS,CAAC;AAC9B;;;ACJA,SAAS,eAAe;AAGjB,IAAM,oBAAoD;AAAA,EAC/D,CAAC,QAAQ,MAAM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eAAW;AAAA,EACb;AAEA,SAAO;AACT","sourcesContent":["import { BigintIsh } from '@pancakeswap/swap-sdk-core'\n\nexport function toBigInt(num: BigintIsh): bigint {\n return BigInt(num.toString())\n}\n","import { ChainId } from '@pancakeswap/chains'\nimport { Address } from 'viem'\n\nexport const MULTICALL_ADDRESS: { [key in ChainId]?: Address } = {\n [ChainId.ZKSYNC]: '0x95071cBD09184083E7F732a710c2e30c9882Fd5f',\n [ChainId.BSC]: '0x39eecaE833c944ebb94942Fa44CaE46e87a8Da17',\n [ChainId.ETHEREUM]: '0xC0916D7E360c31D5F6D0c497E6a36B7B0E80e3cf',\n [ChainId.ARBITRUM_ONE]: '0xbFfE39cDD04f0183e0493c1Deb6E275c5cf84AdF',\n [ChainId.POLYGON_ZKEVM]: '0xe05b539447B17630Cb087473F6b50E5c5f73FDeb',\n [ChainId.LINEA]: '0x6E6B30d65D605DAa4CaC65eB270100Ecca36b140',\n [ChainId.BASE]: '0x3EFaAb8D7A631cfF5ccF5f149d1Bbb3B5bfda2C0',\n [ChainId.OPBNB]: '0xeF1511D29fB37cb87E33339EeC9BE13AB46E3b50',\n\n // Testnets\n [ChainId.BSC_TESTNET]: '0xeeF6ff30cF5D5b8aBA0DE16A01d17A0697a275b5',\n [ChainId.GOERLI]: '0xD55CAFAB2Ffa1139Be46bc5C0b8259c620050dFC',\n [ChainId.ARBITRUM_GOERLI]: '0xe12a5c707Fb528acbE6117b20AF1f7c20b0A8077',\n [ChainId.POLYGON_ZKEVM_TESTNET]: '0x236e713bFF45adb30e25D1c29A887aBCb0Ea7E21',\n [ChainId.ZKSYNC_TESTNET]: '0x8A23CB45E5F4d5a1b2DB673663Ea2aAedc48acff',\n [ChainId.LINEA_TESTNET]: '0x990010b6DBA3e7faa025790bC0433A9f690c65F3',\n [ChainId.BASE_TESTNET]: '0x6F7f93D929d6FBaF16c245e42846EF21aee23437',\n [ChainId.OPBNB_TESTNET]: '0x6A70ED893D85cf6D4059e1CF3e63a48e4D204D32',\n [ChainId.SCROLL_SEPOLIA]: '0x052a99849Ef2e13a5CB28275862991671D4b6fF5',\n}\n\nexport const MULTICALL3_ADDRESS = '0xcA11bde05977b3631167028862bE2a173976CA11'\n\nexport const MULTICALL3_ADDRESSES: {\n [key in ChainId]?: Address\n} = {\n [ChainId.ETHEREUM]: MULTICALL3_ADDRESS,\n [ChainId.GOERLI]: MULTICALL3_ADDRESS,\n [ChainId.BSC]: MULTICALL3_ADDRESS,\n [ChainId.BSC_TESTNET]: MULTICALL3_ADDRESS,\n [ChainId.ZKSYNC_TESTNET]: '0xF9cda624FBC7e059355ce98a31693d299FACd963',\n [ChainId.ZKSYNC]: '0xF9cda624FBC7e059355ce98a31693d299FACd963',\n [ChainId.ARBITRUM_ONE]: MULTICALL3_ADDRESS,\n [ChainId.ARBITRUM_GOERLI]: MULTICALL3_ADDRESS,\n [ChainId.POLYGON_ZKEVM]: MULTICALL3_ADDRESS,\n [ChainId.POLYGON_ZKEVM_TESTNET]: MULTICALL3_ADDRESS,\n [ChainId.OPBNB]: MULTICALL3_ADDRESS,\n [ChainId.OPBNB_TESTNET]: MULTICALL3_ADDRESS,\n [ChainId.BASE_TESTNET]: MULTICALL3_ADDRESS,\n [ChainId.SCROLL_SEPOLIA]: MULTICALL3_ADDRESS,\n}\n","import { ChainId } from '@pancakeswap/chains'\n\nexport const DEFAULT_BLOCK_CONFLICT_TOLERANCE = 0\n\nexport const BLOCK_CONFLICT_TOLERANCE: { [key in ChainId]?: number } = {\n [ChainId.BSC]: 3,\n [ChainId.ETHEREUM]: 1,\n [ChainId.ARBITRUM_ONE]: 5,\n [ChainId.POLYGON_ZKEVM]: 1,\n [ChainId.ZKSYNC]: 3,\n [ChainId.LINEA]: 3,\n [ChainId.BASE]: 3,\n [ChainId.OPBNB]: 3,\n\n // Testnets\n [ChainId.BSC_TESTNET]: 3,\n [ChainId.GOERLI]: 1,\n [ChainId.ARBITRUM_GOERLI]: 5,\n [ChainId.POLYGON_ZKEVM_TESTNET]: 1,\n [ChainId.ZKSYNC_TESTNET]: 3,\n [ChainId.LINEA_TESTNET]: 3,\n [ChainId.OPBNB_TESTNET]: 3,\n [ChainId.BASE_TESTNET]: 3,\n [ChainId.SCROLL_SEPOLIA]: 3,\n}\n","import { ChainId } from '@pancakeswap/chains'\n\nexport const DEFAULT_GAS_LIMIT = 150000000n\n\nexport const DEFAULT_GAS_LIMIT_BY_CHAIN: { [key in ChainId]?: bigint } = {\n [ChainId.BSC]: 100000000n,\n [ChainId.ZKSYNC]: 500000000n,\n [ChainId.POLYGON_ZKEVM]: 1500000n,\n [ChainId.BASE]: 130000000n,\n}\n\nexport const DEFAULT_GAS_BUFFER = 3000000n\n\nexport const DEFAULT_GAS_BUFFER_BY_CHAIN: { [key in ChainId]?: bigint } = {\n [ChainId.BSC]: DEFAULT_GAS_BUFFER,\n [ChainId.POLYGON_ZKEVM]: 0n,\n}\n","import { ChainId } from '@pancakeswap/chains'\nimport { GetContractReturnType, PublicClient, getContract, Address } from 'viem'\n\nimport { MULTICALL_ADDRESS, MULTICALL3_ADDRESSES, MULTICALL3_ADDRESS } from './constants/contracts'\nimport { iMulticallABI } from './abis/IMulticall'\n\ntype Params = {\n chainId: ChainId\n client?: PublicClient\n}\n\nexport function getMulticallContract({\n chainId,\n client,\n}: Params): GetContractReturnType<typeof iMulticallABI, PublicClient> {\n const address = MULTICALL_ADDRESS[chainId]\n if (!address) {\n throw new Error(`PancakeMulticall not supported on chain ${chainId}`)\n }\n\n return getContract({ abi: iMulticallABI, address, publicClient: client })\n}\n\nexport function getMulticall3ContractAddress(chainId?: ChainId): Address {\n return MULTICALL3_ADDRESSES[chainId || ChainId.BSC] || MULTICALL3_ADDRESS\n}\n","export const iMulticallABI = [\n {\n inputs: [],\n name: 'gasLeft',\n outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'gaslimit',\n outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [\n {\n components: [\n { internalType: 'address', name: 'target', type: 'address' },\n { internalType: 'uint256', name: 'gasLimit', type: 'uint256' },\n { internalType: 'bytes', name: 'callData', type: 'bytes' },\n ],\n internalType: 'struct MultiCallV2.Call[]',\n name: 'calls',\n type: 'tuple[]',\n },\n ],\n name: 'multicall',\n outputs: [\n { internalType: 'uint256', name: 'blockNumber', type: 'uint256' },\n {\n components: [\n { internalType: 'bool', name: 'success', type: 'bool' },\n { internalType: 'uint256', name: 'gasUsed', type: 'uint256' },\n { internalType: 'bytes', name: 'returnData', type: 'bytes' },\n ],\n internalType: 'struct MultiCallV2.Result[]',\n name: 'returnData',\n type: 'tuple[]',\n },\n ],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n {\n inputs: [\n {\n components: [\n { internalType: 'address', name: 'target', type: 'address' },\n { internalType: 'uint256', name: 'gasLimit', type: 'uint256' },\n { internalType: 'bytes', name: 'callData', type: 'bytes' },\n ],\n internalType: 'struct MultiCallV2.Call[]',\n name: 'calls',\n type: 'tuple[]',\n },\n { internalType: 'uint256', name: 'gasBuffer', type: 'uint256' },\n ],\n name: 'multicallWithGasLimitation',\n outputs: [\n { internalType: 'uint256', name: 'blockNumber', type: 'uint256' },\n {\n components: [\n { internalType: 'bool', name: 'success', type: 'bool' },\n { internalType: 'uint256', name: 'gasUsed', type: 'uint256' },\n { internalType: 'bytes', name: 'returnData', type: 'bytes' },\n ],\n internalType: 'struct MultiCallV2.Result[]',\n name: 'returnData',\n type: 'tuple[]',\n },\n { internalType: 'uint256', name: 'lastSuccessIndex', type: 'uint256' },\n ],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n]\n","import { BigintIsh } from '@pancakeswap/sdk'\nimport { ChainId } from '@pancakeswap/chains'\nimport { toBigInt } from '@pancakeswap/utils/toBigInt'\nimport { PublicClient } from 'viem'\n\nimport {\n DEFAULT_GAS_BUFFER,\n DEFAULT_GAS_BUFFER_BY_CHAIN,\n DEFAULT_GAS_LIMIT,\n DEFAULT_GAS_LIMIT_BY_CHAIN,\n} from './constants'\nimport { getMulticallContract } from './getMulticallContract'\n\nexport type GetGasLimitParams = {\n chainId: ChainId\n client?: PublicClient\n\n // If provided then would override the gas limit got from on chain\n gasLimit?: BigintIsh\n\n // The gas limit should be whichever is smaller between gasLimit and maxGasLimit\n maxGasLimit?: BigintIsh\n\n gasBuffer?: BigintIsh\n}\n\nexport function getDefaultGasLimit(chainId?: ChainId) {\n const gasLimitOnChain = chainId && DEFAULT_GAS_LIMIT_BY_CHAIN[chainId]\n return gasLimitOnChain !== undefined ? gasLimitOnChain : DEFAULT_GAS_LIMIT\n}\n\nexport function getDefaultGasBuffer(chainId?: ChainId) {\n const gasBufferOnChain = chainId && DEFAULT_GAS_BUFFER_BY_CHAIN[chainId]\n return gasBufferOnChain !== undefined ? gasBufferOnChain : DEFAULT_GAS_BUFFER\n}\n\nexport type GetGasLimitOnChainParams = Pick<GetGasLimitParams, 'chainId' | 'client'>\n\nexport async function getGasLimitOnChain({ chainId, client }: GetGasLimitOnChainParams) {\n const multicall = getMulticallContract({ chainId, client })\n const gasLeft = (await multicall.read.gasLeft()) as bigint\n return gasLeft\n}\n\nexport async function getGasLimit({\n chainId,\n gasLimit: gasLimitInput,\n maxGasLimit: maxGasLimitInput = getDefaultGasLimit(chainId),\n gasBuffer: gasBufferInput = getDefaultGasBuffer(chainId),\n client,\n}: GetGasLimitParams) {\n const gasLimitOverride = gasLimitInput && toBigInt(gasLimitInput)\n const maxGasLimit = toBigInt(maxGasLimitInput)\n const gasBuffer = toBigInt(gasBufferInput)\n\n const gasLimit = gasLimitOverride || (await getGasLimitOnChain({ chainId, client })) || maxGasLimit\n const minGasLimit = gasLimit < maxGasLimit ? gasLimit : maxGasLimit\n return minGasLimit - gasBuffer\n}\n","export const multicall3ABI = [\n {\n inputs: [\n {\n components: [\n { internalType: 'address', name: 'target', type: 'address' },\n { internalType: 'bytes', name: 'callData', type: 'bytes' },\n ],\n internalType: 'struct Multicall2.Call[]',\n name: 'calls',\n type: 'tuple[]',\n },\n ],\n name: 'aggregate',\n outputs: [\n { internalType: 'uint256', name: 'blockNumber', type: 'uint256' },\n { internalType: 'bytes[]', name: 'returnData', type: 'bytes[]' },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [\n {\n components: [\n { internalType: 'address', name: 'target', type: 'address' },\n { internalType: 'bytes', name: 'callData', type: 'bytes' },\n ],\n internalType: 'struct Multicall2.Call[]',\n name: 'calls',\n type: 'tuple[]',\n },\n ],\n name: 'blockAndAggregate',\n outputs: [\n { internalType: 'uint256', name: 'blockNumber', type: 'uint256' },\n { internalType: 'bytes32', name: 'blockHash', type: 'bytes32' },\n {\n components: [\n { internalType: 'bool', name: 'success', type: 'bool' },\n { internalType: 'bytes', name: 'returnData', type: 'bytes' },\n ],\n internalType: 'struct Multicall2.Result[]',\n name: 'returnData',\n type: 'tuple[]',\n },\n ],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n {\n inputs: [{ internalType: 'uint256', name: 'blockNumber', type: 'uint256' }],\n name: 'getBlockHash',\n outputs: [{ internalType: 'bytes32', name: 'blockHash', type: 'bytes32' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'getBlockNumber',\n outputs: [{ internalType: 'uint256', name: 'blockNumber', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'getCurrentBlockCoinbase',\n outputs: [{ internalType: 'address', name: 'coinbase', type: 'address' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'getCurrentBlockDifficulty',\n outputs: [{ internalType: 'uint256', name: 'difficulty', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'getCurrentBlockGasLimit',\n outputs: [{ internalType: 'uint256', name: 'gaslimit', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'getCurrentBlockTimestamp',\n outputs: [{ internalType: 'uint256', name: 'timestamp', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [{ internalType: 'address', name: 'addr', type: 'address' }],\n name: 'getEthBalance',\n outputs: [{ internalType: 'uint256', name: 'balance', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'getLastBlockHash',\n outputs: [{ internalType: 'bytes32', name: 'blockHash', type: 'bytes32' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [\n { internalType: 'bool', name: 'requireSuccess', type: 'bool' },\n {\n components: [\n { internalType: 'address', name: 'target', type: 'address' },\n { internalType: 'bytes', name: 'callData', type: 'bytes' },\n ],\n internalType: 'struct Multicall2.Call[]',\n name: 'calls',\n type: 'tuple[]',\n },\n ],\n name: 'tryAggregate',\n outputs: [\n {\n components: [\n { internalType: 'bool', name: 'success', type: 'bool' },\n { internalType: 'bytes', name: 'returnData', type: 'bytes' },\n ],\n internalType: 'struct Multicall2.Result[]',\n name: 'returnData',\n type: 'tuple[]',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [\n { internalType: 'bool', name: 'requireSuccess', type: 'bool' },\n {\n components: [\n { internalType: 'address', name: 'target', type: 'address' },\n { internalType: 'bytes', name: 'callData', type: 'bytes' },\n ],\n internalType: 'struct Multicall2.Call[]',\n name: 'calls',\n type: 'tuple[]',\n },\n ],\n name: 'tryBlockAndAggregate',\n outputs: [\n { internalType: 'uint256', name: 'blockNumber', type: 'uint256' },\n { internalType: 'bytes32', name: 'blockHash', type: 'bytes32' },\n {\n components: [\n { internalType: 'bool', name: 'success', type: 'bool' },\n { internalType: 'bytes', name: 'returnData', type: 'bytes' },\n ],\n internalType: 'struct Multicall2.Result[]',\n name: 'returnData',\n type: 'tuple[]',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n] as const\n","import { ChainId } from '@pancakeswap/chains'\n\nimport { BLOCK_CONFLICT_TOLERANCE, DEFAULT_BLOCK_CONFLICT_TOLERANCE } from './constants'\n\nexport function getBlockConflictTolerance(chainId: ChainId) {\n return BLOCK_CONFLICT_TOLERANCE[chainId] || DEFAULT_BLOCK_CONFLICT_TOLERANCE\n}\n","import { toBigInt } from '@pancakeswap/utils/toBigInt'\n\nimport { GetGasLimitParams, getDefaultGasBuffer, getGasLimit } from './getGasLimit'\nimport { MulticallRequestWithGas } from './types'\nimport { getMulticallContract } from './getMulticallContract'\nimport { getBlockConflictTolerance } from './getBlockConflictTolerance'\n\nexport type CallByGasLimitParams = GetGasLimitParams & {\n // Normally we expect to get quotes from within the same block\n // But for some chains like BSC the block time is quite short so need some extra tolerance\n // 0 means no block conflict and all the multicall results should be queried within the same block\n blockConflictTolerance?: number\n\n // Treat unexecuted calls as failed calls\n dropUnexecutedCalls?: boolean\n}\n\nexport async function multicallByGasLimit(\n calls: MulticallRequestWithGas[],\n { chainId, gasBuffer = getDefaultGasBuffer(chainId), client, dropUnexecutedCalls, ...rest }: CallByGasLimitParams,\n) {\n const gasLimit = await getGasLimit({\n chainId,\n gasBuffer,\n client,\n ...rest,\n })\n const callChunks = splitCallsIntoChunks(calls, gasLimit)\n return callByChunks(callChunks, { gasBuffer, client, chainId, dropUnexecutedCalls })\n}\n\ntype CallParams = Pick<\n CallByGasLimitParams,\n 'chainId' | 'client' | 'gasBuffer' | 'blockConflictTolerance' | 'dropUnexecutedCalls'\n>\n\nexport type SingleCallResult = {\n result: string\n gasUsed: bigint\n success: boolean\n}\n\nexport type CallResult = {\n results: SingleCallResult[]\n // Will be the greatest block number if block conflict tolerance is not 0\n blockNumber: bigint\n}\n\nexport type MulticallReturn = CallResult & {\n lastSuccessIndex: number\n}\n\ntype CallReturnFromContract = [bigint, { success: boolean; gasUsed: bigint; returnData: string }[], bigint]\n\nfunction formatCallReturn([blockNumber, results, successIndex]: CallReturnFromContract): MulticallReturn {\n const lastSuccessIndex = Number(successIndex)\n return {\n lastSuccessIndex,\n blockNumber,\n results: results.slice(0, lastSuccessIndex + 1).map(({ gasUsed, success, returnData }) => ({\n gasUsed,\n success,\n result: returnData,\n })),\n }\n}\n\nasync function call(calls: MulticallRequestWithGas[], params: CallParams): Promise<CallResult> {\n const {\n chainId,\n client,\n gasBuffer = getDefaultGasBuffer(chainId),\n blockConflictTolerance = getBlockConflictTolerance(chainId),\n dropUnexecutedCalls = false,\n } = params\n if (!calls.length) {\n return {\n results: [],\n blockNumber: 0n,\n }\n }\n\n const contract = getMulticallContract({ chainId, client })\n const { result } = await contract.simulate.multicallWithGasLimitation([calls, gasBuffer])\n const { results, lastSuccessIndex, blockNumber } = formatCallReturn(result as CallReturnFromContract)\n if (lastSuccessIndex === calls.length - 1) {\n return {\n results,\n blockNumber,\n }\n }\n console.warn(\n `Gas limit reached. Total num of ${calls.length} calls. First ${\n lastSuccessIndex + 1\n } calls executed. The remaining ${\n calls.length - lastSuccessIndex - 1\n } calls are not executed. Pls try adjust the gas limit per call.`,\n )\n const remainingCalls = calls.slice(lastSuccessIndex + 1)\n if (dropUnexecutedCalls) {\n return {\n results: [...results, ...remainingCalls.map(() => ({ result: '0x', gasUsed: 0n, success: false }))],\n blockNumber,\n }\n }\n const { results: remainingResults, blockNumber: nextBlockNumber } = await call(\n calls.slice(lastSuccessIndex + 1),\n params,\n )\n if (Number(nextBlockNumber - blockNumber) > blockConflictTolerance) {\n throw new Error(\n `Multicall failed because of block conflict. Latest calls are made at block ${nextBlockNumber} while last calls made at block ${blockNumber}. Block conflict tolerance is ${blockConflictTolerance}`,\n )\n }\n return {\n results: [...results, ...remainingResults],\n // Use the latest block number\n blockNumber: nextBlockNumber,\n }\n}\n\nasync function callByChunks(chunks: MulticallRequestWithGas[][], params: CallParams): Promise<CallResult> {\n const { blockConflictTolerance = getBlockConflictTolerance(params.chainId) } = params\n const callReturns = await Promise.all(chunks.map((chunk) => call(chunk, params)))\n\n let minBlock = 0n\n let maxBlock = 0n\n let results: SingleCallResult[] = []\n for (const { results: callResults, blockNumber } of callReturns) {\n if (minBlock === 0n || blockNumber < minBlock) {\n minBlock = blockNumber\n }\n if (blockNumber > maxBlock) {\n maxBlock = blockNumber\n }\n if (Number(maxBlock - minBlock) > blockConflictTolerance) {\n throw new Error(\n `Multicall failed because of block conflict. Min block is ${minBlock} while max block is ${maxBlock}. Block conflict tolerance is ${blockConflictTolerance}`,\n )\n }\n results = [...results, ...callResults]\n }\n return {\n results,\n blockNumber: maxBlock,\n }\n}\n\nfunction splitCallsIntoChunks(calls: MulticallRequestWithGas[], gasLimit: bigint): MulticallRequestWithGas[][] {\n const chunks: MulticallRequestWithGas[][] = [[]]\n\n let gasLeft = gasLimit\n for (const callRequest of calls) {\n const { target, callData, gasLimit: gasCostLimit } = callRequest\n const singleGasLimit = toBigInt(gasCostLimit)\n const currentChunk = chunks[chunks.length - 1]\n if (singleGasLimit > gasLeft) {\n chunks.push([callRequest])\n gasLeft = gasLimit - singleGasLimit\n\n // Single call exceeds the gas limit\n if (gasLeft < 0n) {\n console.warn(\n `Multicall request may fail as the gas cost of a single call exceeds the gas limit ${gasLimit}. Gas cost: ${singleGasLimit}. To: ${target}. Data: ${callData}`,\n )\n }\n continue\n }\n\n currentChunk.push(callRequest)\n gasLeft -= singleGasLimit\n }\n\n return chunks\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pancakeswap/multicall",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -9,16 +9,14 @@
|
|
|
9
9
|
"types": "dist/index.d.ts",
|
|
10
10
|
"module": "dist/index.mjs",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"viem": "
|
|
12
|
+
"viem": "1.15.1",
|
|
13
13
|
"@pancakeswap/sdk": "5.7.2",
|
|
14
14
|
"@pancakeswap/chains": "0.3.0"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"tsup": "^6.7.0",
|
|
18
|
-
"typescript": "^5.1.3",
|
|
19
|
-
"vitest": "^0.27.2",
|
|
20
18
|
"@pancakeswap/tsconfig": "0.0.0",
|
|
21
|
-
"@pancakeswap/utils": "5.0.
|
|
19
|
+
"@pancakeswap/utils": "5.0.7"
|
|
22
20
|
},
|
|
23
21
|
"exports": {
|
|
24
22
|
"./package.json": "./package.json",
|