-
-
Notifications
You must be signed in to change notification settings - Fork 743
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
feat: Add support for linea_estimateGas #2525
Conversation
|
@wantedsystem is attempting to deploy a commit to the Wevm Team on Vercel. A member of the Team first needs to authorize it. |
try { | ||
// Try with the public endpoint | ||
const publicClient = createPublicClient({ | ||
chain: client.chain.id === linea.id ? linea : lineaTestnet, | ||
transport: http(), | ||
}) | ||
lineaEstimateGasResponse = await getAction( | ||
publicClient, | ||
lineaEstimateGas, | ||
'lineaEstimateGas', | ||
)({ | ||
data: request.data, | ||
to: request.to, | ||
...request, | ||
} as unknown as EstimateGasParameters) | ||
} catch (_err) { |
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.
Consumers can set up fallback
transport if they want this behavior.
try { | |
// Try with the public endpoint | |
const publicClient = createPublicClient({ | |
chain: client.chain.id === linea.id ? linea : lineaTestnet, | |
transport: http(), | |
}) | |
lineaEstimateGasResponse = await getAction( | |
publicClient, | |
lineaEstimateGas, | |
'lineaEstimateGas', | |
)({ | |
data: request.data, | |
to: request.to, | |
...request, | |
} as unknown as EstimateGasParameters) | |
} catch (_err) { |
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.
Hey @jxom thanks for reviewing ! Could you please confirm if I need to change transport: http()
to transport: fallback([http(), webSocket()])
here ?
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.
I mean we can omit this section of code, and just rely on fallback mechanisms that the consumer defines.
const adjustedBaseFee = | ||
(BigInt(baseFeePerGas) * BigInt(BASE_FEE_PER_GAS_MARGIN * 100)) / | ||
BigInt(100) |
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.
Can we rely on multiply
here? This is default to 1.2
, but can be adjusted to 1.35
via chain.fees.baseFeeMultiplier
const adjustedBaseFee = | |
(BigInt(baseFeePerGas) * BigInt(BASE_FEE_PER_GAS_MARGIN * 100)) / | |
BigInt(100) | |
const adjustedBaseFee = multiply(BigInt(baseFeePerGas)) |
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.
hey @jxom we will keep the default value 1.2
Attempting to test this end-to-end, but I am running into issues on Linea Sepolia that the method
What RPC URL can I use to test this end-to-end? |
Hey @jxom It will be available soon -i'll keep you posted |
src/chains/definitions/linea.ts
Outdated
fees: { | ||
// Override the fees calculation to accurately price the fees | ||
// on Linea using the rpc call linea_estimateGas | ||
estimateFeesPerGas: lineaEstimateFeesPerGas, | ||
async defaultPriorityFee(args): Promise<bigint> { | ||
const { maxPriorityFeePerGas } = await lineaEstimateFeesPerGas({ | ||
client: args.client, | ||
request: args.request, | ||
type: 'eip1559', | ||
} as any) | ||
|
||
if (maxPriorityFeePerGas === undefined) { | ||
throw new Error('maxPriorityFeePerGas is undefined') | ||
} | ||
|
||
return maxPriorityFeePerGas | ||
}, | ||
}, |
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.
Can you set up a shared chainConfig
object and spread it into the Linea chain definitions? (Similar to how things are set up for OP Stack and Zksync support.)
// src/linea/chainConfig.ts
import type { Chain } from '../types/chain.js'
export const chainConfig = {
fees: {
// Override the fees calculation to accurately price the fees
// on Linea using the rpc call linea_estimateGas
async estimateFeesPerGas(args) { ... },
async defaultPriorityFee(args) { ... },
},
} as const satisfies Pick<Chain, 'fees'>
// src/chains/definitions/linea.ts
import { chainConfig } from '../../linea/chainConfig.js'
import { defineChain } from '../../utils/chain/defineChain.js'
export const linea = /*#__PURE__*/ defineChain({
...chainConfig,
id: 59_144,
name: 'Linea Mainnet',
// other properties ...
})
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.
See previous comment on linea.ts
about chainConfig
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.
Let's move to src/linea/utils/estimateFeesPerGas.ts
or inline into chainConfig
.
* value: 0n, | ||
* }) | ||
*/ | ||
export async function lineaEstimateGas< |
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.
Let's drop the linea
prefix since it will be namespaced by the import 'viem/linea'
.
TAccount extends Account | undefined = undefined, | ||
>( | ||
client: Client<Transport, TChain, TAccount>, | ||
args: EstimateGasParameters<TChain>, |
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.
Let's add a type for EstimateGasParameters
import type { EstimateGasParameters as base_EstimateGasParameters } from '../../actions/public/estimateGas.js'
export type EstimateGasParameters = base_EstimateGasParameters
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.
Can you provide more informations on what to do here ?
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.
type AssertRequestParameters, | ||
assertRequest, | ||
} from '../../utils/transaction/assertRequest.js' | ||
import type { LineaEstimateGasReturnType } from '../types/fee.js' |
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.
Let's add this return type directly to this file
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 are also using it in src/linea/utils/estimateFeesPerGas.ts
so we had to duplicate the type here as well
src/linea/types/rpc.ts
Outdated
{ | ||
Method: 'linea_estimateGas' | ||
Parameters?: any | ||
ReturnType: LineaEstimateGasReturnType |
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.
Let's inline ReturnType
. Duplication is fine in this case.
ReturnType: LineaEstimateGasReturnType | |
ReturnType: { | |
gasLimit: Hex | |
baseFeePerGas: Hex | |
priorityFeePerGas: Hex | |
} |
src/linea/types/rpc.ts
Outdated
*/ | ||
{ | ||
Method: 'linea_estimateGas' | ||
Parameters?: any |
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.
Let's type this. See EIP-1993 types for inspiration.
src/linea/types/fee.ts
Outdated
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.
Let's colocate these with their actions/utils and export from those places as needed.
Since there are a few outstanding comments, going to convert this to a draft. |
You can test now for Linea Mainnet
And for Linea Sepolia :
|
Hey @jxom you had the opportunity to test ? |
Superseded by #2665 |
Linea, a layer 2 blockchain, supports the Ethereum EIP-1559 gas price model, known for making transaction fees more predictable. Unlike the base Ethereum layer, Linea aims to offer a more stable and cost-effective approach to handling transaction fees. For detailed information, you can visit Linea's Gas Fees Documentation.
To further enhance the efficiency of transaction fee calculations, Linea has introduced a new RPC method designed to provide the best gas price estimates. This new method is documented in detail here.
The introduction of this new RPC method necessitates changes in how web3 libraries calculate gas prices. Traditionally, these libraries used the eth_gasPrice method. Linea's update shifts this approach to utilize the newly introduced linea_estimateGas method.
Detailed summary
PR-Codex overview
This PR adds Linea and Linea Testnet chains with gas estimation and fee calculation support.
Detailed summary
lineaEstimateGas
andlineaEstimateFeesPerGas
functions