@pancakeswap/multicall 2.0.0 → 3.0.1
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/README.md +75 -0
- package/dist/abis/IMulticall.d.ts +36 -0
- package/dist/abis/IMulticall.d.ts.map +1 -0
- package/dist/constants/blockConflictTolerance.d.ts +6 -0
- package/dist/constants/blockConflictTolerance.d.ts.map +1 -0
- package/dist/constants/contracts.d.ts +6 -0
- package/dist/constants/contracts.d.ts.map +1 -0
- package/dist/constants/gasLimit.d.ts +10 -0
- package/dist/constants/gasLimit.d.ts.map +1 -0
- package/dist/constants/index.d.ts +4 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/getBlockConflictTolerance.d.ts +3 -0
- package/dist/getBlockConflictTolerance.d.ts.map +1 -0
- package/dist/getGasLimit.d.ts +15 -0
- package/dist/getGasLimit.d.ts.map +1 -0
- package/dist/getMulticallContract.d.ts +10 -0
- package/dist/getMulticallContract.d.ts.map +1 -0
- package/dist/index.d.ts +8 -54
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +244 -262
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +231 -261
- package/dist/index.mjs.map +1 -0
- package/dist/multicall.d.ts +19 -0
- package/dist/multicall.d.ts.map +1 -0
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +16 -12
- package/CHANGELOG.md +0 -25
- package/Multicall.json +0 -236
- package/index.ts +0 -138
- package/tsconfig.json +0 -11
- package/tsup.config.ts +0 -11
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Pancake Multicall
|
|
2
|
+
|
|
3
|
+
Enhanced multicall sdk to safely make multicalls within the gas limit.
|
|
4
|
+
|
|
5
|
+
Inspired by the [1inch multicall](https://github.com/1inch/multicall).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
$ pnpm add @pancakeswap/multicall @pancakeswap/sdk viem
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Basic usage
|
|
16
|
+
|
|
17
|
+
By default the calls will be splitted into chunks based on gas limit of each call and the rpc call gas limit of the chain
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { ChainId } from '@pancakeswap/sdk'
|
|
21
|
+
import { multicallByGasLimit, MulticallRequestWithGas } from '@pancakeswap/multicall'
|
|
22
|
+
|
|
23
|
+
const calls: MulticallRequestWithGas[] = [
|
|
24
|
+
{
|
|
25
|
+
// Target contract to call
|
|
26
|
+
target: '0x',
|
|
27
|
+
// Encoded call data
|
|
28
|
+
callData: '',
|
|
29
|
+
// The maximum gas limit set to this single call
|
|
30
|
+
gasLimit: 1_000_000,
|
|
31
|
+
},
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
const { results, blockNumber } = await multicallByGasLimit(calls, {
|
|
35
|
+
chainId: ChainId.BSC,
|
|
36
|
+
|
|
37
|
+
// Rpc client. Please refer to `PublicClient` from viem
|
|
38
|
+
client,
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
for (const { success, result, gasUsed } of results) {
|
|
42
|
+
if (success) {
|
|
43
|
+
// Decode result
|
|
44
|
+
decodeResult(result)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Advanced usage
|
|
50
|
+
|
|
51
|
+
The rpc call gas limit can be overriden if provided. Once provided, the multicall sdk won't ask for the gas limit from on chain.
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
const { results, blockNumber } = await multicallByGasLimit(calls, {
|
|
55
|
+
chainId: ChainId.BSC,
|
|
56
|
+
client,
|
|
57
|
+
gasLimit: 150_000_000,
|
|
58
|
+
})
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Other utilities
|
|
62
|
+
|
|
63
|
+
### Get multicall gas limit
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { ChainId } from '@pancakeswap/sdk'
|
|
67
|
+
import { getGasLimitOnChain } from '@pancakeswap/multicall'
|
|
68
|
+
|
|
69
|
+
// Get the rpc call gas limit of the specified chain
|
|
70
|
+
const gasLimit = await getGasLimitOnChain(ChainId.BSC)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Supported chains
|
|
74
|
+
|
|
75
|
+
For supported chains and contract addresses, please refer to [multicall contracts](https://github.com/pancakeswap/pancake-frontend/blob/develop/packages/multicall/src/constants/contracts.ts).
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare const iMulticallABI: {
|
|
2
|
+
inputs: ({
|
|
3
|
+
components: {
|
|
4
|
+
internalType: string;
|
|
5
|
+
name: string;
|
|
6
|
+
type: string;
|
|
7
|
+
}[];
|
|
8
|
+
internalType: string;
|
|
9
|
+
name: string;
|
|
10
|
+
type: string;
|
|
11
|
+
} | {
|
|
12
|
+
internalType: string;
|
|
13
|
+
name: string;
|
|
14
|
+
type: string;
|
|
15
|
+
components?: undefined;
|
|
16
|
+
})[];
|
|
17
|
+
name: string;
|
|
18
|
+
outputs: ({
|
|
19
|
+
internalType: string;
|
|
20
|
+
name: string;
|
|
21
|
+
type: string;
|
|
22
|
+
components?: undefined;
|
|
23
|
+
} | {
|
|
24
|
+
components: {
|
|
25
|
+
internalType: string;
|
|
26
|
+
name: string;
|
|
27
|
+
type: string;
|
|
28
|
+
}[];
|
|
29
|
+
internalType: string;
|
|
30
|
+
name: string;
|
|
31
|
+
type: string;
|
|
32
|
+
})[];
|
|
33
|
+
stateMutability: string;
|
|
34
|
+
type: string;
|
|
35
|
+
}[];
|
|
36
|
+
//# sourceMappingURL=IMulticall.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IMulticall.d.ts","sourceRoot":"","sources":["../../src/abis/IMulticall.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6EzB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blockConflictTolerance.d.ts","sourceRoot":"","sources":["../../src/constants/blockConflictTolerance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE1C,eAAO,MAAM,gCAAgC,IAAI,CAAA;AAEjD,eAAO,MAAM,wBAAwB,EAAE;KAAG,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,MAAM;CAmBjE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../src/constants/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAE9B,eAAO,MAAM,iBAAiB,EAAE;KAAG,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,OAAO;CAmB3D,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ChainId } from '@pancakeswap/sdk';
|
|
2
|
+
export declare const DEFAULT_GAS_LIMIT = 150000000n;
|
|
3
|
+
export declare const DEFAULT_GAS_LIMIT_BY_CHAIN: {
|
|
4
|
+
[key in ChainId]?: bigint;
|
|
5
|
+
};
|
|
6
|
+
export declare const DEFAULT_GAS_BUFFER = 3000000n;
|
|
7
|
+
export declare const DEFAULT_GAS_BUFFER_BY_CHAIN: {
|
|
8
|
+
[key in ChainId]?: bigint;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=gasLimit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gasLimit.d.ts","sourceRoot":"","sources":["../../src/constants/gasLimit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE1C,eAAO,MAAM,iBAAiB,aAAa,CAAA;AAE3C,eAAO,MAAM,0BAA0B,EAAE;KAAG,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,MAAM;CAInE,CAAA;AAED,eAAO,MAAM,kBAAkB,WAAW,CAAA;AAE1C,eAAO,MAAM,2BAA2B,EAAE;KAAG,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,MAAM;CAGpE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,0BAA0B,CAAA;AACxC,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getBlockConflictTolerance.d.ts","sourceRoot":"","sources":["../src/getBlockConflictTolerance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAI1C,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,UAEzD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BigintIsh, ChainId } from '@pancakeswap/sdk';
|
|
2
|
+
import { PublicClient } from 'viem';
|
|
3
|
+
export type GetGasLimitParams = {
|
|
4
|
+
chainId: ChainId;
|
|
5
|
+
client?: PublicClient;
|
|
6
|
+
gasLimit?: BigintIsh;
|
|
7
|
+
maxGasLimit?: BigintIsh;
|
|
8
|
+
gasBuffer?: BigintIsh;
|
|
9
|
+
};
|
|
10
|
+
export declare function getDefaultGasLimit(chainId?: ChainId): bigint;
|
|
11
|
+
export declare function getDefaultGasBuffer(chainId?: ChainId): bigint;
|
|
12
|
+
export type GetGasLimitOnChainParams = Pick<GetGasLimitParams, 'chainId' | 'client'>;
|
|
13
|
+
export declare function getGasLimitOnChain({ chainId, client }: GetGasLimitOnChainParams): Promise<bigint>;
|
|
14
|
+
export declare function getGasLimit({ chainId, gasLimit: gasLimitInput, maxGasLimit: maxGasLimitInput, gasBuffer: gasBufferInput, client, }: GetGasLimitParams): Promise<bigint>;
|
|
15
|
+
//# sourceMappingURL=getGasLimit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getGasLimit.d.ts","sourceRoot":"","sources":["../src/getGasLimit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAUnC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,CAAC,EAAE,YAAY,CAAA;IAGrB,QAAQ,CAAC,EAAE,SAAS,CAAA;IAGpB,WAAW,CAAC,EAAE,SAAS,CAAA;IAEvB,SAAS,CAAC,EAAE,SAAS,CAAA;CACtB,CAAA;AAED,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,OAAO,UAGnD;AAED,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,OAAO,UAGpD;AAED,MAAM,MAAM,wBAAwB,GAAG,IAAI,CAAC,iBAAiB,EAAE,SAAS,GAAG,QAAQ,CAAC,CAAA;AAEpF,wBAAsB,kBAAkB,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,wBAAwB,mBAIrF;AAED,wBAAsB,WAAW,CAAC,EAChC,OAAO,EACP,QAAQ,EAAE,aAAa,EACvB,WAAW,EAAE,gBAA8C,EAC3D,SAAS,EAAE,cAA6C,EACxD,MAAM,GACP,EAAE,iBAAiB,mBAQnB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ChainId } from '@pancakeswap/sdk';
|
|
2
|
+
import { GetContractReturnType, PublicClient } from 'viem';
|
|
3
|
+
import { iMulticallABI } from './abis/IMulticall';
|
|
4
|
+
type Params = {
|
|
5
|
+
chainId: ChainId;
|
|
6
|
+
client?: PublicClient;
|
|
7
|
+
};
|
|
8
|
+
export declare function getMulticallContract({ chainId, client, }: Params): GetContractReturnType<typeof iMulticallABI, PublicClient>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=getMulticallContract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMulticallContract.d.ts","sourceRoot":"","sources":["../src/getMulticallContract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAe,MAAM,MAAM,CAAA;AAGvE,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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,54 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
readonly 56: "0xcA11bde05977b3631167028862bE2a173976CA11";
|
|
10
|
-
readonly 97: "0xcA11bde05977b3631167028862bE2a173976CA11";
|
|
11
|
-
};
|
|
12
|
-
declare const getMulticallContract: (chainId: ChainId, provider: Provider) => Contract | null;
|
|
13
|
-
interface Call {
|
|
14
|
-
address: string;
|
|
15
|
-
name: string;
|
|
16
|
-
params?: any[];
|
|
17
|
-
}
|
|
18
|
-
interface MulticallOptions extends CallOverrides {
|
|
19
|
-
requireSuccess?: boolean;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Multicall V2 uses the new "tryAggregate" function. It is different in 2 ways
|
|
23
|
-
*
|
|
24
|
-
* 1. If "requireSuccess" is false multicall will not bail out if one of the calls fails
|
|
25
|
-
* 2. The return includes a boolean whether the call was successful e.g. [wasSuccessful, callResult]
|
|
26
|
-
*/
|
|
27
|
-
interface MulticallV2Params {
|
|
28
|
-
abi: any[] | any;
|
|
29
|
-
calls: Call[];
|
|
30
|
-
chainId?: ChainId;
|
|
31
|
-
options?: MulticallOptions;
|
|
32
|
-
provider?: Provider;
|
|
33
|
-
}
|
|
34
|
-
interface CallV3 extends Call {
|
|
35
|
-
abi: any[] | any;
|
|
36
|
-
allowFailure?: boolean;
|
|
37
|
-
}
|
|
38
|
-
interface MulticallV3Params {
|
|
39
|
-
calls: CallV3[];
|
|
40
|
-
chainId?: ChainId;
|
|
41
|
-
allowFailure?: boolean;
|
|
42
|
-
overrides?: CallOverrides;
|
|
43
|
-
}
|
|
44
|
-
type MultiCallV2 = <T = any>(params: MulticallV2Params) => Promise<T>;
|
|
45
|
-
type MultiCall = <T = any>(abi: any[], calls: Call[], chainId?: ChainId) => Promise<T>;
|
|
46
|
-
declare function createMulticall<TProvider extends Provider>(provider: ({ chainId }: {
|
|
47
|
-
chainId?: number | undefined;
|
|
48
|
-
}) => TProvider): {
|
|
49
|
-
multicall: MultiCall;
|
|
50
|
-
multicallv2: MultiCallV2;
|
|
51
|
-
multicallv3: ({ calls, chainId, allowFailure, overrides }: MulticallV3Params) => Promise<any>;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export { Call, CallV3, MultiCall, MultiCallV2, MulticallOptions, createMulticall, getMulticallContract, multicallAddresses };
|
|
1
|
+
export * from './getGasLimit';
|
|
2
|
+
export * from './abis/IMulticall';
|
|
3
|
+
export * from './constants';
|
|
4
|
+
export * from './getMulticallContract';
|
|
5
|
+
export * from './multicall';
|
|
6
|
+
export * from './types';
|
|
7
|
+
export * from './getBlockConflictTolerance';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|