Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
3f1e7e62
Unverified
Commit
3f1e7e62
authored
May 27, 2021
by
Mark Tyneway
Committed by
GitHub
May 27, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
docs: core-utils (#964)
parent
e6e87ae1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
0 deletions
+36
-0
README.md
packages/core-utils/README.md
+36
-0
No files found.
packages/core-utils/README.md
View file @
3f1e7e62
...
@@ -22,3 +22,39 @@ $ yarn start
...
@@ -22,3 +22,39 @@ $ yarn start
$
yarn
test
$
yarn
test
$
yarn lint
$
yarn lint
```
```
### L2 Fees
The Layer 2 fee is encoded in
`tx.gasLimit`
. The Layer 2
`gasLimit`
is encoded
in the lower order bits of the
`tx.gasLimit`
. For this scheme to work, both the
L1 gas price and the L2 gas price must satisfy specific equations. There are
functions that help ensure that the correct gas prices are used.
-
`roundL1GasPrice`
-
`roundL2GasPrice`
The Layer 2 fee is based on both the cost of submitting the data to L1 as well
as the cost of execution on L2. To make libraries like
`ethers`
just work, the
return value of
`eth_estimateGas`
has been modified to return the fee. A new RPC
endpoint
`eth_estimateExecutionGas`
has been added that returns the L2 gas used.
To locally encode the
`tx.gasLimit`
, the
`L2GasLimit`
methods
`encode`
and
`decode`
should be used.
```
typescript
import
{
L2GasLimit
,
roundL1GasPrice
,
roundL2GasPrice
}
from
'
@eth-optimism/core-utils
'
import
{
JsonRpcProvider
}
from
'
ethers
'
const
provider
=
new
JsonRpcProvider
(
'
https://mainnet.optimism.io
'
)
const
gasLimit
=
await
provider
.
send
(
'
eth_estimateExecutionGas
'
,
[
tx
])
const
encoded
=
L2GasLimit
.
encode
({
data
:
'
0x
'
,
l1GasPrice
:
roundL1GasPrice
(
1
),
l2GasLimit
:
gasLimit
,
l2GasPrice
:
roundL2GasPrice
(
1
),
})
const
decoded
=
L2GasLimit
.
decode
(
encoded
)
assert
(
decoded
.
eq
(
gasLimit
))
```
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment