@pancakeswap/multicall 0.0.2 → 1.0.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.
@@ -2,15 +2,15 @@ warning package.json: No license field
2
2
  $ tsup
3
3
  CLI Building entry: {"index":"index.ts"}
4
4
  CLI Using tsconfig: tsconfig.json
5
- CLI tsup v5.12.9
5
+ CLI tsup v6.6.3
6
6
  CLI Using tsup config: /home/runner/work/pancake-frontend/pancake-frontend/packages/multicall/tsup.config.ts
7
- CLI Target: node12
7
+ CLI Target: node14
8
8
  ESM Build start
9
9
  CJS Build start
10
- ESM ⚡️ Build success in 20ms
11
- CJS ⚡️ Build success in 20ms
12
- ESM dist/index.mjs 9.98 KB
13
- CJS dist/index.js 11.20 KB
10
+ CJS dist/index.js 10.71 KB
11
+ CJS ⚡️ Build success in 389ms
12
+ ESM dist/index.mjs 10.57 KB
13
+ ESM ⚡️ Build success in 391ms
14
14
  DTS Build start
15
- DTS ⚡️ Build success in 2877ms
16
- DTS dist/index.d.ts 1.74 KB
15
+ DTS ⚡️ Build success in 9625ms
16
+ DTS dist/index.d.ts 2.03 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @pancakeswap/multicall
2
2
 
3
+ ## 1.0.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 65fbb250a: Bump version
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [65fbb250a]
12
+ - @pancakeswap/sdk@3.2.0
13
+
3
14
  ## 0.0.2
4
15
 
5
16
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  import { Contract, CallOverrides } from '@ethersproject/contracts';
2
2
  import { Provider } from '@ethersproject/providers';
3
3
  import { ChainId } from '@pancakeswap/sdk';
4
+ import { Multicallv3Typed, Multicallv2Typed } from '@pancakeswap/utils/abitype';
4
5
 
6
+ type TMulticallv3Typed = typeof Multicallv3Typed;
7
+ type TMulticallv2Typed = typeof Multicallv2Typed;
5
8
  declare const multicallAddresses: {
6
9
  1: string;
7
10
  4: string;
@@ -25,7 +28,7 @@ interface MulticallOptions extends CallOverrides {
25
28
  * 2. The return includes a boolean whether the call was successful e.g. [wasSuccessful, callResult]
26
29
  */
27
30
  interface MulticallV2Params {
28
- abi: any[];
31
+ abi: any[] | any;
29
32
  calls: Call[];
30
33
  chainId?: ChainId;
31
34
  options?: MulticallOptions;
@@ -41,14 +44,16 @@ interface MulticallV3Params {
41
44
  allowFailure?: boolean;
42
45
  overrides?: CallOverrides;
43
46
  }
44
- declare type MultiCallV2 = <T = any>(params: MulticallV2Params) => Promise<T>;
45
- declare type MultiCall = <T = any>(abi: any[], calls: Call[], chainId?: ChainId) => Promise<T>;
47
+ type MultiCallV2 = <T = any>(params: MulticallV2Params) => Promise<T>;
48
+ type MultiCall = <T = any>(abi: any[], calls: Call[], chainId?: ChainId) => Promise<T>;
46
49
  declare function createMulticall<TProvider extends Provider>(provider: ({ chainId }: {
47
50
  chainId?: number | undefined;
48
51
  }) => TProvider): {
49
52
  multicall: MultiCall;
50
53
  multicallv2: MultiCallV2;
51
54
  multicallv3: ({ calls, chainId, allowFailure, overrides }: MulticallV3Params) => Promise<any>;
55
+ multicallv3Typed: typeof Multicallv3Typed;
56
+ multicallv2Typed: typeof Multicallv2Typed;
52
57
  };
53
58
 
54
- export { Call, CallV3, MultiCall, MultiCallV2, MulticallOptions, createMulticall, getMulticallContract, multicallAddresses };
59
+ export { Call, CallV3, MultiCall, MultiCallV2, MulticallOptions, TMulticallv2Typed, TMulticallv3Typed, createMulticall, getMulticallContract, multicallAddresses };
package/dist/index.js CHANGED
@@ -1,33 +1,10 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
2
+
3
+ var abi = require('@ethersproject/abi');
4
+ var contracts = require('@ethersproject/contracts');
5
+ var sdk = require('@pancakeswap/sdk');
19
6
 
20
7
  // index.ts
21
- var multicall_exports = {};
22
- __export(multicall_exports, {
23
- createMulticall: () => createMulticall,
24
- getMulticallContract: () => getMulticallContract,
25
- multicallAddresses: () => multicallAddresses
26
- });
27
- module.exports = __toCommonJS(multicall_exports);
28
- var import_abi = require("@ethersproject/abi");
29
- var import_contracts = require("@ethersproject/contracts");
30
- var import_sdk = require("@pancakeswap/sdk");
31
8
 
32
9
  // Multicall.json
33
10
  var Multicall_default = [
@@ -277,16 +254,16 @@ var multicallAddresses = {
277
254
  };
278
255
  var getMulticallContract = (chainId, provider) => {
279
256
  if (multicallAddresses[chainId]) {
280
- return new import_contracts.Contract(multicallAddresses[chainId], Multicall_default, provider);
257
+ return new contracts.Contract(multicallAddresses[chainId], Multicall_default, provider);
281
258
  }
282
259
  return null;
283
260
  };
284
261
  function createMulticall(provider) {
285
- const multicall = async (abi, calls, chainId = import_sdk.ChainId.BSC) => {
262
+ const multicall = async (abi$1, calls, chainId = sdk.ChainId.BSC) => {
286
263
  const multi = getMulticallContract(chainId, provider({ chainId }));
287
264
  if (!multi)
288
265
  throw new Error(`Multicall Provider missing for ${chainId}`);
289
- const itf = new import_abi.Interface(abi);
266
+ const itf = new abi.Interface(abi$1);
290
267
  const calldata = calls.map((call) => ({
291
268
  target: call.address.toLowerCase(),
292
269
  callData: itf.encodeFunctionData(call.name, call.params)
@@ -295,12 +272,12 @@ function createMulticall(provider) {
295
272
  const res = returnData.map((call, i) => itf.decodeFunctionResult(calls[i].name, call));
296
273
  return res;
297
274
  };
298
- const multicallv2 = async ({ abi, calls, chainId = import_sdk.ChainId.BSC, options, provider: _provider }) => {
275
+ const multicallv2 = async ({ abi: abi$1, calls, chainId = sdk.ChainId.BSC, options, provider: _provider }) => {
299
276
  const { requireSuccess = true, ...overrides } = options || {};
300
277
  const multi = getMulticallContract(chainId, _provider || provider({ chainId }));
301
278
  if (!multi)
302
279
  throw new Error(`Multicall Provider missing for ${chainId}`);
303
- const itf = new import_abi.Interface(abi);
280
+ const itf = new abi.Interface(abi$1);
304
281
  const calldata = calls.map((call) => ({
305
282
  target: call.address.toLowerCase(),
306
283
  callData: itf.encodeFunctionData(call.name, call.params)
@@ -312,41 +289,65 @@ function createMulticall(provider) {
312
289
  });
313
290
  return res;
314
291
  };
315
- const multicallv3 = async ({ calls, chainId = import_sdk.ChainId.BSC, allowFailure, overrides }) => {
292
+ const multicallv3 = async ({ calls, chainId = sdk.ChainId.BSC, allowFailure, overrides }) => {
316
293
  const multi = getMulticallContract(chainId, provider({ chainId }));
317
294
  if (!multi)
318
295
  throw new Error(`Multicall Provider missing for ${chainId}`);
319
- const _calls = calls.map(({ abi, address, name, params, allowFailure: _allowFailure }) => {
320
- const contract = new import_contracts.Contract(address, abi);
321
- const callData = contract.interface.encodeFunctionData(name, params != null ? params : []);
322
- if (!contract[name])
296
+ const interfaceCache = /* @__PURE__ */ new WeakMap();
297
+ const _calls = calls.map(({ abi: abi$1, address, name, params, allowFailure: _allowFailure }) => {
298
+ let itf = interfaceCache.get(abi$1);
299
+ if (!itf) {
300
+ itf = new abi.Interface(abi$1);
301
+ interfaceCache.set(abi$1, itf);
302
+ }
303
+ if (!itf.fragments.some((fragment) => fragment.name === name))
323
304
  console.error(`${name} missing on ${address}`);
305
+ const callData = itf.encodeFunctionData(name, params ?? []);
324
306
  return {
325
- target: address,
307
+ target: address.toLowerCase(),
326
308
  allowFailure: allowFailure || _allowFailure,
327
309
  callData
328
310
  };
329
311
  });
330
- const result = await multi.callStatic.aggregate3([...[_calls], ...overrides ? [overrides] : []]);
312
+ const result = await multi.callStatic.aggregate3(_calls, ...overrides ? [overrides] : []);
331
313
  return result.map((call, i) => {
332
314
  const { returnData, success } = call;
333
315
  if (!success || returnData === "0x")
334
316
  return null;
335
- const { address, abi, name } = calls[i];
336
- const contract = new import_contracts.Contract(address, abi);
337
- const decoded = contract.interface.decodeFunctionResult(name, returnData);
317
+ const { abi, name } = calls[i];
318
+ const itf = interfaceCache.get(abi);
319
+ const decoded = itf == null ? void 0 : itf.decodeFunctionResult(name, returnData);
338
320
  return decoded;
339
321
  });
340
322
  };
323
+ const multicallv3Typed = async ({ calls, allowFailure, chainId, overrides }) => {
324
+ return multicallv3({
325
+ // @ts-ignore
326
+ calls,
327
+ allowFailure,
328
+ chainId,
329
+ overrides
330
+ });
331
+ };
332
+ const multicallv2Typed = async ({ abi, calls, chainId, options }) => {
333
+ return multicallv2({
334
+ // @ts-ignore
335
+ abi,
336
+ // @ts-ignore
337
+ calls,
338
+ chainId,
339
+ options
340
+ });
341
+ };
341
342
  return {
342
343
  multicall,
343
344
  multicallv2,
344
- multicallv3
345
+ multicallv3,
346
+ multicallv3Typed,
347
+ multicallv2Typed
345
348
  };
346
349
  }
347
- // Annotate the CommonJS export names for ESM import in node:
348
- 0 && (module.exports = {
349
- createMulticall,
350
- getMulticallContract,
351
- multicallAddresses
352
- });
350
+
351
+ exports.createMulticall = createMulticall;
352
+ exports.getMulticallContract = getMulticallContract;
353
+ exports.multicallAddresses = multicallAddresses;
package/dist/index.mjs CHANGED
@@ -1,7 +1,8 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { Contract } from '@ethersproject/contracts';
3
+ import { ChainId } from '@pancakeswap/sdk';
4
+
1
5
  // index.ts
2
- import { Interface } from "@ethersproject/abi";
3
- import { Contract } from "@ethersproject/contracts";
4
- import { ChainId } from "@pancakeswap/sdk";
5
6
 
6
7
  // Multicall.json
7
8
  var Multicall_default = [
@@ -290,36 +291,59 @@ function createMulticall(provider) {
290
291
  const multi = getMulticallContract(chainId, provider({ chainId }));
291
292
  if (!multi)
292
293
  throw new Error(`Multicall Provider missing for ${chainId}`);
294
+ const interfaceCache = /* @__PURE__ */ new WeakMap();
293
295
  const _calls = calls.map(({ abi, address, name, params, allowFailure: _allowFailure }) => {
294
- const contract = new Contract(address, abi);
295
- const callData = contract.interface.encodeFunctionData(name, params != null ? params : []);
296
- if (!contract[name])
296
+ let itf = interfaceCache.get(abi);
297
+ if (!itf) {
298
+ itf = new Interface(abi);
299
+ interfaceCache.set(abi, itf);
300
+ }
301
+ if (!itf.fragments.some((fragment) => fragment.name === name))
297
302
  console.error(`${name} missing on ${address}`);
303
+ const callData = itf.encodeFunctionData(name, params ?? []);
298
304
  return {
299
- target: address,
305
+ target: address.toLowerCase(),
300
306
  allowFailure: allowFailure || _allowFailure,
301
307
  callData
302
308
  };
303
309
  });
304
- const result = await multi.callStatic.aggregate3([...[_calls], ...overrides ? [overrides] : []]);
310
+ const result = await multi.callStatic.aggregate3(_calls, ...overrides ? [overrides] : []);
305
311
  return result.map((call, i) => {
306
312
  const { returnData, success } = call;
307
313
  if (!success || returnData === "0x")
308
314
  return null;
309
- const { address, abi, name } = calls[i];
310
- const contract = new Contract(address, abi);
311
- const decoded = contract.interface.decodeFunctionResult(name, returnData);
315
+ const { abi, name } = calls[i];
316
+ const itf = interfaceCache.get(abi);
317
+ const decoded = itf == null ? void 0 : itf.decodeFunctionResult(name, returnData);
312
318
  return decoded;
313
319
  });
314
320
  };
321
+ const multicallv3Typed = async ({ calls, allowFailure, chainId, overrides }) => {
322
+ return multicallv3({
323
+ // @ts-ignore
324
+ calls,
325
+ allowFailure,
326
+ chainId,
327
+ overrides
328
+ });
329
+ };
330
+ const multicallv2Typed = async ({ abi, calls, chainId, options }) => {
331
+ return multicallv2({
332
+ // @ts-ignore
333
+ abi,
334
+ // @ts-ignore
335
+ calls,
336
+ chainId,
337
+ options
338
+ });
339
+ };
315
340
  return {
316
341
  multicall,
317
342
  multicallv2,
318
- multicallv3
343
+ multicallv3,
344
+ multicallv3Typed,
345
+ multicallv2Typed
319
346
  };
320
347
  }
321
- export {
322
- createMulticall,
323
- getMulticallContract,
324
- multicallAddresses
325
- };
348
+
349
+ export { createMulticall, getMulticallContract, multicallAddresses };
package/index.ts CHANGED
@@ -1,10 +1,14 @@
1
- import { Interface } from '@ethersproject/abi'
1
+ import { Interface, Fragment } from '@ethersproject/abi'
2
2
  import { CallOverrides, Contract } from '@ethersproject/contracts'
3
3
  import { Provider } from '@ethersproject/providers'
4
4
  import { ChainId } from '@pancakeswap/sdk'
5
+ import type { Multicallv2Typed, Multicallv3Typed } from '@pancakeswap/utils/abitype'
5
6
 
6
7
  import multicallAbi from './Multicall.json'
7
8
 
9
+ export type TMulticallv3Typed = typeof Multicallv3Typed
10
+ export type TMulticallv2Typed = typeof Multicallv2Typed
11
+
8
12
  export const multicallAddresses = {
9
13
  1: '0xcA11bde05977b3631167028862bE2a173976CA11',
10
14
  4: '0xcA11bde05977b3631167028862bE2a173976CA11',
@@ -37,7 +41,7 @@ export interface MulticallOptions extends CallOverrides {
37
41
  * 2. The return includes a boolean whether the call was successful e.g. [wasSuccessful, callResult]
38
42
  */
39
43
  interface MulticallV2Params {
40
- abi: any[]
44
+ abi: any[] | any
41
45
  calls: Call[]
42
46
  chainId?: ChainId
43
47
  options?: MulticallOptions
@@ -101,32 +105,61 @@ export function createMulticall<TProvider extends Provider>(
101
105
  const multicallv3 = async ({ calls, chainId = ChainId.BSC, allowFailure, overrides }: MulticallV3Params) => {
102
106
  const multi = getMulticallContract(chainId, provider({ chainId }))
103
107
  if (!multi) throw new Error(`Multicall Provider missing for ${chainId}`)
108
+ const interfaceCache = new WeakMap()
104
109
  const _calls = calls.map(({ abi, address, name, params, allowFailure: _allowFailure }) => {
105
- const contract = new Contract(address, abi)
106
- const callData = contract.interface.encodeFunctionData(name, params ?? [])
107
- if (!contract[name]) console.error(`${name} missing on ${address}`)
110
+ let itf = interfaceCache.get(abi)
111
+ if (!itf) {
112
+ itf = new Interface(abi)
113
+ interfaceCache.set(abi, itf)
114
+ }
115
+ if (!itf.fragments.some((fragment: Fragment) => fragment.name === name))
116
+ console.error(`${name} missing on ${address}`)
117
+ const callData = itf.encodeFunctionData(name, params ?? [])
108
118
  return {
109
- target: address,
119
+ target: address.toLowerCase(),
110
120
  allowFailure: allowFailure || _allowFailure,
111
121
  callData,
112
122
  }
113
123
  })
114
124
 
115
- const result = await multi.callStatic.aggregate3([...[_calls], ...(overrides ? [overrides] : [])])
125
+ const result = await multi.callStatic.aggregate3(_calls, ...(overrides ? [overrides] : []))
116
126
 
117
127
  return result.map((call: any, i: number) => {
118
128
  const { returnData, success } = call
119
129
  if (!success || returnData === '0x') return null
120
- const { address, abi, name } = calls[i]
121
- const contract = new Contract(address, abi)
122
- const decoded = contract.interface.decodeFunctionResult(name, returnData)
130
+ const { abi, name } = calls[i]
131
+ const itf = interfaceCache.get(abi)
132
+ const decoded = itf?.decodeFunctionResult(name, returnData)
123
133
  return decoded
124
134
  })
125
135
  }
126
136
 
137
+ const multicallv3Typed: typeof Multicallv3Typed = async ({ calls, allowFailure, chainId, overrides }) => {
138
+ return multicallv3({
139
+ // @ts-ignore
140
+ calls,
141
+ allowFailure,
142
+ chainId,
143
+ overrides,
144
+ })
145
+ }
146
+
147
+ const multicallv2Typed: typeof Multicallv2Typed = async ({ abi, calls, chainId, options }) => {
148
+ return multicallv2({
149
+ // @ts-ignore
150
+ abi,
151
+ // @ts-ignore
152
+ calls,
153
+ chainId,
154
+ options,
155
+ })
156
+ }
157
+
127
158
  return {
128
159
  multicall,
129
160
  multicallv2,
130
161
  multicallv3,
162
+ multicallv3Typed,
163
+ multicallv2Typed,
131
164
  }
132
165
  }
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@pancakeswap/multicall",
3
- "version": "0.0.2",
3
+ "version": "1.0.0",
4
4
  "sideEffects": false,
5
5
  "scripts": {
6
6
  "build": "tsup",
7
+ "dev": "tsup --watch",
7
8
  "prepublishOnly": "yarn run build",
8
9
  "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
9
10
  },
10
11
  "peerDependencies": {
11
- "@pancakeswap/sdk": "^3.1.0"
12
+ "@pancakeswap/sdk": "^3.2.0"
12
13
  },
13
14
  "dependencies": {
14
15
  "@ethersproject/abi": "^5.0.0",
@@ -16,10 +17,10 @@
16
17
  "@ethersproject/providers": "^5.0.0"
17
18
  },
18
19
  "devDependencies": {
19
- "@pancakeswap/sdk": "^3.1.0",
20
+ "@pancakeswap/sdk": "*",
20
21
  "tsconfig": "*",
21
- "tsup": "^5.10.1",
22
- "typescript": "^4.5.3"
22
+ "tsup": "^6.6.3",
23
+ "typescript": "^4.9.4"
23
24
  },
24
25
  "exports": {
25
26
  "./package.json": "./package.json",
package/tsconfig.json CHANGED
@@ -1,6 +1,8 @@
1
1
  {
2
- "extends": "tsconfig/react-library",
2
+ "extends": "tsconfig/base",
3
+ "include": ["./index.ts"],
3
4
  "compilerOptions": {
5
+ "outDir": "./dist",
4
6
  "esModuleInterop": true,
5
7
  "resolveJsonModule": true,
6
8
  "isolatedModules": true,
package/tsup.config.ts CHANGED
@@ -6,4 +6,6 @@ export default defineConfig({
6
6
  },
7
7
  format: ['esm', 'cjs'],
8
8
  dts: true,
9
+ treeshake: true,
10
+ splitting: true,
9
11
  })