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
2fbe51dc
Commit
2fbe51dc
authored
Aug 05, 2023
by
Will Cory
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(fee-estimation): Multiply gas fee in estimate gas
parent
747876d0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
21 deletions
+33
-21
README.md
packages/fee-estimation/README.md
+3
-5
estimateFees.spec.ts
packages/fee-estimation/src/estimateFees.spec.ts
+27
-14
estimateFees.ts
packages/fee-estimation/src/estimateFees.ts
+3
-2
No files found.
packages/fee-estimation/README.md
View file @
2fbe51dc
...
...
@@ -37,11 +37,9 @@ yarn add @eth-optimism/fee-estimation
### Basic Usage
```
ts
import
{
estimateFees
,
}
from
'
@eth-optimism/fee-estimation
'
import
{
optimistABI
}
from
'
@eth-optimism/contracts-ts
'
import
{
viemClient
}
from
'
./viem-client
'
import
{
estimateFees
}
from
'
@eth-optimism/fee-estimation
'
import
{
optimistABI
}
from
'
@eth-optimism/contracts-ts
'
import
{
viemClient
}
from
'
./viem-client
'
const
optimistOwnerAddress
=
'
0x77194aa25a06f932c10c0f25090f3046af2c85a6
'
as
const
...
...
packages/fee-estimation/src/estimateFees.spec.ts
View file @
2fbe51dc
...
...
@@ -24,6 +24,19 @@ import {
}
from
'
@eth-optimism/contracts-ts
'
import
{
parseEther
,
parseGwei
}
from
'
viem
'
vi
.
mock
(
'
viem
'
,
async
()
=>
{
const
_viem
=
(
await
vi
.
importActual
(
'
viem
'
))
as
any
return
{
...
_viem
,
// no way to get historical gas price
createPublicClient
:
(...
args
:
[
any
])
=>
{
const
client
=
_viem
.
createPublicClient
(...
args
)
client
.
getGasPrice
=
async
()
=>
parseGwei
(
'
0.00000042
'
)
return
client
},
}
})
// using this optimist https://optimistic.etherscan.io/tx/0xaa291efba7ea40b0742e5ff84a1e7831a2eb6c2fc35001fa03ba80fd3b609dc9
const
blockNumber
=
BigInt
(
107028270
)
const
optimistOwnerAddress
=
...
...
@@ -95,44 +108,44 @@ beforeEach(() => {
test
(
'
estimateFees should return correct fees
'
,
async
()
=>
{
// burn
const
res
=
await
estimateFees
({
...
paramsWithRpcUrl
,
...
functionDataBurn
})
expect
(
res
).
toMatchInlineSnapshot
(
'
20573
185261089
n
'
)
expect
(
formatEther
(
res
)).
toMatchInlineSnapshot
(
'
"0.000020573
185261089
"
'
)
expect
(
res
).
toMatchInlineSnapshot
(
'
20573
203833264
n
'
)
expect
(
formatEther
(
res
)).
toMatchInlineSnapshot
(
'
"0.000020573
203833264
"
'
)
expect
(
await
estimateFees
({
...
paramsWithRpcUrl
,
...
functionDataBurn
})
).
toMatchInlineSnapshot
(
'
20573
185261089
n
'
)
).
toMatchInlineSnapshot
(
'
20573
203833264
n
'
)
expect
(
await
estimateFees
({
...
paramsWithViemClient
,
...
functionDataBurn
})
).
toMatchInlineSnapshot
(
'
20573
185261089
n
'
)
).
toMatchInlineSnapshot
(
'
20573
203833264
n
'
)
expect
(
await
estimateFees
({
...
paramsWithRpcUrl
,
...
functionDataBurnWithPriorityFees
,
})
).
toMatchInlineSnapshot
(
'
215369
74118090
n
'
)
).
toMatchInlineSnapshot
(
'
215369
92690265
n
'
)
// what is the l2 and l1 part of the fees for reference?
const
l1Fee
=
await
getL1Fee
({
...
paramsWithRpcUrl
,
...
functionDataBurn
})
const
l2Fee
=
res
-
l1Fee
expect
(
l1Fee
).
toMatchInlineSnapshot
(
'
20573185216764n
'
)
expect
(
formatEther
(
l1Fee
)).
toMatchInlineSnapshot
(
'
"0.000020573185216764"
'
)
expect
(
l2Fee
).
toMatchInlineSnapshot
(
'
44325
n
'
)
expect
(
formatEther
(
l2Fee
)).
toMatchInlineSnapshot
(
'
"0.0000000000
0004432
5"
'
)
expect
(
l2Fee
).
toMatchInlineSnapshot
(
'
18616500
n
'
)
expect
(
formatEther
(
l2Fee
)).
toMatchInlineSnapshot
(
'
"0.0000000000
18616
5"
'
)
// withdraw
const
res2
=
await
estimateFees
({
...
paramsWithRpcUrlWithdraw
,
...
functionDataWithdraw
,
})
expect
(
res2
).
toMatchInlineSnapshot
(
'
628570
3901638
0n
'
)
expect
(
res2
).
toMatchInlineSnapshot
(
'
628570
9024751
0n
'
)
expect
(
await
estimateFees
({
...
paramsWithRpcUrlWithdraw
,
...
functionDataWithdraw
})
).
toMatchInlineSnapshot
(
'
628570
3901638
0n
'
)
).
toMatchInlineSnapshot
(
'
628570
9024751
0n
'
)
expect
(
await
estimateFees
({
...
paramsWithRpcUrlWithdraw
,
...
functionDataWithdraw
})
).
toMatchInlineSnapshot
(
'
628570
3901638
0n
'
)
).
toMatchInlineSnapshot
(
'
628570
9024751
0n
'
)
expect
(
await
estimateFees
({
...
paramsWithRpcUrlWithdraw
,
...
functionDataWithdraw
})
).
toMatchInlineSnapshot
(
'
628570
3901638
0n
'
)
expect
(
formatEther
(
res2
)).
toMatchInlineSnapshot
(
'
"0.0000628570
3901638
"
'
)
).
toMatchInlineSnapshot
(
'
628570
9024751
0n
'
)
expect
(
formatEther
(
res2
)).
toMatchInlineSnapshot
(
'
"0.0000628570
9024751
"
'
)
// what is the l2 and l1 part of the fees for reference?
const
l1Fee2
=
await
getL1Fee
({
...
paramsWithRpcUrlWithdraw
,
...
...
@@ -141,8 +154,8 @@ test('estimateFees should return correct fees', async () => {
const
l2Fee2
=
res2
-
l1Fee
expect
(
l1Fee2
).
toMatchInlineSnapshot
(
'
62857038894110n
'
)
expect
(
formatEther
(
l1Fee2
)).
toMatchInlineSnapshot
(
'
"0.00006285703889411"
'
)
expect
(
l2Fee2
).
toMatchInlineSnapshot
(
'
42283
85379961
6n
'
)
expect
(
formatEther
(
l2Fee2
)).
toMatchInlineSnapshot
(
'
"0.000042283
85379961
6"
'
)
expect
(
l2Fee2
).
toMatchInlineSnapshot
(
'
42283
90503074
6n
'
)
expect
(
formatEther
(
l2Fee2
)).
toMatchInlineSnapshot
(
'
"0.000042283
90503074
6"
'
)
})
test
(
'
baseFee should return the correct result
'
,
async
()
=>
{
...
...
packages/fee-estimation/src/estimateFees.ts
View file @
2fbe51dc
...
...
@@ -332,7 +332,7 @@ export const estimateFees: EstimateFees = async (options) => {
args
:
options
.
args
,
functionName
:
options
.
functionName
,
}
as
EncodeFunctionDataParameters
)
const
[
l1Fee
,
l2
Fe
e
]
=
await
Promise
.
all
([
const
[
l1Fee
,
l2
Gas
,
l2GasPric
e
]
=
await
Promise
.
all
([
getL1Fee
({
...
options
,
// account must be undefined or else viem will return undefined
...
...
@@ -347,6 +347,7 @@ export const estimateFees: EstimateFees = async (options) => {
data
:
encodedFunctionData
,
value
:
options
.
value
,
}
as
EstimateGasParameters
<
typeof
chains
.
optimism
>
),
client
.
getGasPrice
(),
])
return
l1Fee
+
l2
Fe
e
return
l1Fee
+
l2
Gas
*
l2GasPric
e
}
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