-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: Add readMulticall route for batch contract reads #773
base: main
Are you sure you want to change the base?
Conversation
changelog |
New and removed dependencies detected. Learn more about Socket for GitHub ↗︎
🚮 Removed packages: npm/[email protected] |
// Encode each read call | ||
const encodedCalls = await Promise.all( | ||
calls.map(async (call) => { | ||
const contract = await getContract({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to await getContract btw
Reply: Static<typeof responseSchema>; | ||
}; | ||
|
||
export async function readMulticall(fastify: FastifyInstance) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit and non-blocking: I started calling route names readMulticallRoute
. The reason is we have so many exported functions that end up having the same name (for example: createAccessToken
might be the route, or the cached call, or the raw db call, who knows?)
So having that suffix is nice for clarity.
|
||
const readMulticallRequestSchema = Type.Object({ | ||
calls: Type.Array(readCallRequestItemSchema), | ||
multicallAddress: Type.Optional(Type.String()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a description so people know they don't need to set this:
Override a specific multicall contract. Defaults to Multicall3.
schema: { | ||
summary: "Batch read from multiple contracts", | ||
description: | ||
"Execute multiple contract read operations in a single call using Multicall3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO don't need to mention multicall3 as it's a low level implementation detail. You can refer to "using multicall" since that's a web3 concept.
value: 0n, | ||
}); | ||
|
||
const calldata = await resolvePromisedValue(transaction.data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use resolvePromisedValue. I should add a @deprecated
tag on the function. Use this instead:
import { encode } from "thirdweb";
const callData = await encode(transaction);
// stubbing gas values so that the call can be encoded | ||
maxFeePerGas: 30n, | ||
maxPriorityFeePerGas: 1n, | ||
value: 0n, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these need to be stubbed? What happens if we leave them undefined?
|
||
return { | ||
success, | ||
result: success ? bigNumberReplacer(decoded) : null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not need bigNumberReplacer. We're on v5 SDK which does not rely on ethers.
description: | ||
"Execute multiple contract read operations in a single call using Multicall3", | ||
tags: ["Contract"], | ||
operationId: "readMulticall", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readBatch
is preferred since "multicall" is the underlying approach but the use case is a batch read.
Test with example curl:
PR-Codex overview
This PR primarily focuses on adding support for batch reading multiple contract calls using
Multicall3
in thesrc/server/routes/contract/read/read-batch.ts
file. It also updates various dependencies to their latest versions.Detailed summary
thirdweb
dependency from5.61.3
to5.69.0
.readMulticall
function to handle batch read operations insrc/server/routes/contract/read/read-batch.ts
.readMulticall
insrc/server/routes/index.ts
.package.json
andyarn.lock
.