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
b5d7b43b
Unverified
Commit
b5d7b43b
authored
Aug 15, 2023
by
Wyatt Barnes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Solve merge conflict
parent
671a92c8
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
4028 additions
and
2807 deletions
+4028
-2807
.prettierignore
packages/web3.js-plugin-fee-estimation/.prettierignore
+7
-0
.prettierrc.cjs
packages/web3.js-plugin-fee-estimation/.prettierrc.cjs
+3
-0
CHANGELOG.md
packages/web3.js-plugin-fee-estimation/CHANGELOG.md
+1
-0
LICENSE
packages/web3.js-plugin-fee-estimation/LICENSE
+21
-0
README.md
packages/web3.js-plugin-fee-estimation/README.md
+600
-0
package.json
packages/web3.js-plugin-fee-estimation/package.json
+45
-0
plugin.spec.ts
packages/web3.js-plugin-fee-estimation/src/plugin.spec.ts
+241
-0
plugin.ts
packages/web3.js-plugin-fee-estimation/src/plugin.ts
+337
-0
tsconfig.json
packages/web3.js-plugin-fee-estimation/tsconfig.json
+15
-0
tsup.config.ts
packages/web3.js-plugin-fee-estimation/tsup.config.ts
+13
-0
vite.config.ts
packages/web3.js-plugin-fee-estimation/vite.config.ts
+11
-0
pnpm-lock.yaml
pnpm-lock.yaml
+2734
-2807
No files found.
packages/web3.js-plugin-fee-estimation/.prettierignore
0 → 100644
View file @
b5d7b43b
artifacts
cache
typechain
.deps
.envrc
.env
/dist/
packages/web3.js-plugin-fee-estimation/.prettierrc.cjs
0 → 100644
View file @
b5d7b43b
module.exports = {
...require('../../.prettierrc.js'),
}
packages/web3.js-plugin-fee-estimation/CHANGELOG.md
0 → 100644
View file @
b5d7b43b
# @eth-optimism/web3.js-plugin-fee-estimation
packages/web3.js-plugin-fee-estimation/LICENSE
0 → 100644
View file @
b5d7b43b
MIT License
Copyright (c) 2022 Optimism
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
packages/web3.js-plugin-fee-estimation/README.md
0 → 100644
View file @
b5d7b43b
This diff is collapsed.
Click to expand it.
packages/web3.js-plugin-fee-estimation/package.json
0 → 100644
View file @
b5d7b43b
{
"name"
:
"@eth-optimism/web3.js-plugin-fee-estimation"
,
"version"
:
"0.1.0"
,
"description"
:
"A Web3.js plugin for doing OP-Chain gas estimation"
,
"license"
:
"MIT"
,
"repository"
:
{
"type"
:
"git"
,
"url"
:
"https://github.com/ethereum-optimism/optimism.git"
,
"directory"
:
"packages/web3js-plugin-fee-estimation"
},
"homepage"
:
"https://optimism.io"
,
"type"
:
"module"
,
"main"
:
"dist/plugin.js"
,
"module"
:
"dist/plugin.mjs"
,
"types"
:
"src/plugin.ts"
,
"files"
:
[
"dist/"
,
"src/"
],
"scripts"
:
{
"build"
:
"tsup"
,
"lint"
:
"prettier --check ."
,
"lint:fix"
:
"prettier --write ."
,
"test"
:
"vitest"
,
"test:coverage"
:
"vitest run --coverage"
,
"typecheck"
:
"tsc --noEmit"
},
"devDependencies"
:
{
"@eth-optimism/contracts-ts"
:
"workspace:^"
,
"@vitest/coverage-istanbul"
:
"^0.33.0"
,
"tsup"
:
"^7.1.0"
,
"typescript"
:
"^5.1.6"
,
"viem"
:
"^1.3.1"
,
"vite"
:
"^4.4.6"
,
"vitest"
:
"^0.33.0"
},
"dependencies"
:
{
"@ethereumjs/rlp"
:
"^4.0.1"
,
"web3-eth"
:
"^4.0.3"
,
"web3-eth-accounts"
:
"^4.0.3"
},
"peerDependencies"
:
{
"web3"
:
">= 4.0.3 < 5.x"
}
}
packages/web3.js-plugin-fee-estimation/src/plugin.spec.ts
0 → 100644
View file @
b5d7b43b
import
{
beforeAll
,
describe
,
expect
,
test
}
from
'
vitest
'
import
Web3
,
{
Contract
,
FMT_BYTES
,
FMT_NUMBER
}
from
'
web3
'
import
{
l2StandardBridgeABI
,
l2StandardBridgeAddress
,
optimistABI
,
optimistAddress
,
}
from
'
@eth-optimism/contracts-ts
'
import
OptimismFeeEstimationPlugin
from
'
./plugin
'
const
provider
=
process
.
env
.
VITE_L2_RPC_URL
??
'
https://mainnet.optimism.io
'
describe
(
'
OptimismFeeEstimationPlugin
'
,
()
=>
{
let
web3
:
Web3
beforeAll
(()
=>
{
web3
=
new
Web3
(
provider
)
web3
.
registerPlugin
(
new
OptimismFeeEstimationPlugin
())
})
test
(
'
should be registered under .op namespace
'
,
()
=>
expect
(
web3
.
op
).
toBeDefined
())
describe
(
'
should return a bigint by default
'
,
()
=>
{
test
(
'
getBaseFee
'
,
async
()
=>
expect
(
typeof
(
await
web3
.
op
.
getBaseFee
())).
toBe
(
'
bigint
'
))
test
(
'
getDecimals should return 6n
'
,
async
()
=>
expect
(
await
web3
.
op
.
getDecimals
()).
toBe
(
BigInt
(
6
)))
test
(
'
getGasPrice
'
,
async
()
=>
expect
(
typeof
(
await
web3
.
op
.
getGasPrice
())).
toBe
(
'
bigint
'
))
test
(
'
getL1BaseFee
'
,
async
()
=>
expect
(
typeof
(
await
web3
.
op
.
getL1BaseFee
())).
toBe
(
'
bigint
'
))
test
(
'
getOverhead should return 188n
'
,
async
()
=>
expect
(
await
web3
.
op
.
getOverhead
()).
toBe
(
BigInt
(
188
)))
test
(
'
getScalar should return 684000n
'
,
async
()
=>
expect
(
await
web3
.
op
.
getScalar
()).
toBe
(
BigInt
(
684000
)))
})
describe
(
'
should return a number
'
,
()
=>
{
const
numberFormat
=
{
number
:
FMT_NUMBER
.
NUMBER
,
bytes
:
FMT_BYTES
.
HEX
}
test
(
'
getBaseFee
'
,
async
()
=>
expect
(
typeof
(
await
web3
.
op
.
getBaseFee
(
numberFormat
))).
toBe
(
'
number
'
))
test
(
'
getDecimals should return 6
'
,
async
()
=>
expect
(
await
web3
.
op
.
getDecimals
(
numberFormat
)).
toBe
(
6
))
test
(
'
getGasPrice
'
,
async
()
=>
expect
(
typeof
(
await
web3
.
op
.
getGasPrice
(
numberFormat
))).
toBe
(
'
number
'
))
test
(
'
getL1BaseFee
'
,
async
()
=>
expect
(
typeof
(
await
web3
.
op
.
getL1BaseFee
(
numberFormat
))).
toBe
(
'
number
'
))
test
(
'
getOverhead should return 188
'
,
async
()
=>
expect
(
await
web3
.
op
.
getOverhead
(
numberFormat
)).
toBe
(
188
))
test
(
'
getScalar should return 684000
'
,
async
()
=>
expect
(
await
web3
.
op
.
getScalar
(
numberFormat
)).
toBe
(
684000
))
})
test
(
'
getVersion should return the string 1.0.0
'
,
async
()
=>
expect
(
await
web3
.
op
.
getVersion
()).
toBe
(
'
1.0.0
'
))
describe
(
'
Contract transaction gas estimates - optimistABI.burn
'
,
()
=>
{
let
optimistContract
:
Contract
<
typeof
optimistABI
>
let
encodedBurnMethod
:
string
beforeAll
(()
=>
{
optimistContract
=
new
web3
.
eth
.
Contract
(
optimistABI
)
encodedBurnMethod
=
optimistContract
.
methods
.
burn
(
'
0x77194aa25a06f932c10c0f25090f3046af2c85a6
'
)
.
encodeABI
()
})
describe
(
'
should return a bigint by default
'
,
()
=>
{
test
(
'
getL1Fee
'
,
async
()
=>
{
expect
(
typeof
(
await
web3
.
op
.
getL1Fee
({
chainId
:
'
0xa
'
,
data
:
encodedBurnMethod
,
type
:
'
0x2
'
,
}))
).
toBe
(
'
bigint
'
)
})
test
(
'
getL1GasUsed should return 1884n
'
,
async
()
=>
expect
(
await
web3
.
op
.
getL1GasUsed
({
chainId
:
'
0xa
'
,
data
:
encodedBurnMethod
,
type
:
'
0x2
'
,
})
).
toBe
(
BigInt
(
1884
)))
test
(
'
estimateFees
'
,
async
()
=>
expect
(
typeof
(
await
web3
.
op
.
estimateFees
({
chainId
:
10
,
data
:
encodedBurnMethod
,
type
:
2
,
to
:
optimistAddress
[
10
],
from
:
'
0x77194aa25a06f932c10c0f25090f3046af2c85a6
'
,
}))
).
toBe
(
'
bigint
'
))
test
(
'
getL2Fee
'
,
async
()
=>
{
expect
(
typeof
(
await
web3
.
op
.
getL2Fee
({
chainId
:
'
0xa
'
,
data
:
encodedBurnMethod
,
type
:
'
0x2
'
,
to
:
optimistAddress
[
10
],
from
:
'
0x77194aa25a06f932c10c0f25090f3046af2c85a6
'
,
}))
).
toBe
(
'
bigint
'
)
})
test
(
'
estimateFees
'
,
async
()
=>
expect
(
typeof
(
await
web3
.
op
.
estimateFees
(
{
chainId
:
10
,
data
:
encodedBurnMethod
,
type
:
2
,
to
:
optimistAddress
[
10
],
from
:
'
0x77194aa25a06f932c10c0f25090f3046af2c85a6
'
,
},
{
blockNumber
:
107028270
}
))
).
toBe
(
'
bigint
'
))
})
describe
(
'
should return a hexString
'
,
()
=>
{
const
hexStringFormat
=
{
number
:
FMT_NUMBER
.
HEX
,
bytes
:
FMT_BYTES
.
HEX
}
test
(
'
getL1Fee
'
,
async
()
=>
{
expect
(
typeof
(
await
web3
.
op
.
getL1Fee
(
{
chainId
:
'
0xa
'
,
data
:
encodedBurnMethod
,
type
:
'
0x2
'
,
},
hexStringFormat
))
).
toBe
(
'
string
'
)
})
test
(
'
getL1GasUsed should return 0x75c
'
,
async
()
=>
expect
(
await
web3
.
op
.
getL1GasUsed
(
{
chainId
:
'
0xa
'
,
data
:
encodedBurnMethod
,
type
:
'
0x2
'
,
},
hexStringFormat
)
).
toBe
(
'
0x75c
'
))
test
(
'
estimateFees
'
,
async
()
=>
expect
(
typeof
(
await
web3
.
op
.
estimateFees
(
{
chainId
:
10
,
data
:
encodedBurnMethod
,
type
:
2
,
to
:
optimistAddress
[
10
],
from
:
'
0x77194aa25a06f932c10c0f25090f3046af2c85a6
'
,
},
{
returnFormat
:
hexStringFormat
}
))
).
toBe
(
'
string
'
))
})
})
describe
(
'
Contract transaction gas estimates - l2StandardBridgeABI.withdraw
'
,
()
=>
{
let
l2BridgeContract
:
Contract
<
typeof
l2StandardBridgeABI
>
let
encodedWithdrawMethod
:
string
beforeAll
(()
=>
{
l2BridgeContract
=
new
Contract
(
l2StandardBridgeABI
,
l2StandardBridgeAddress
[
420
]
)
encodedWithdrawMethod
=
l2BridgeContract
.
methods
.
withdraw
(
// l2 token address
'
0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000
'
,
// amount
Web3
.
utils
.
toWei
(
'
0.00000001
'
,
'
ether
'
),
// l1 gas
0
,
// extra data
'
0x00
'
)
.
encodeABI
()
})
describe
(
'
should return a bigint by default
'
,
()
=>
{
test
(
'
getL1Fee
'
,
async
()
=>
{
expect
(
typeof
(
await
web3
.
op
.
getL1Fee
({
chainId
:
'
0xa
'
,
data
:
encodedWithdrawMethod
,
type
:
'
0x2
'
,
}))
).
toBe
(
'
bigint
'
)
})
test
(
'
getL1GasUsed should return 2592n
'
,
async
()
=>
expect
(
await
web3
.
op
.
getL1GasUsed
({
chainId
:
'
0xa
'
,
data
:
encodedWithdrawMethod
,
type
:
'
0x2
'
,
})
).
toBe
(
BigInt
(
2592
)))
test
(
'
estimateFees
'
,
async
()
=>
expect
(
typeof
(
await
web3
.
op
.
estimateFees
({
chainId
:
10
,
data
:
encodedWithdrawMethod
,
value
:
Web3
.
utils
.
toWei
(
'
0.00000001
'
,
'
ether
'
),
type
:
2
,
to
:
l2StandardBridgeAddress
[
420
],
from
:
'
0x6387a88a199120aD52Dd9742C7430847d3cB2CD4
'
,
maxFeePerGas
:
Web3
.
utils
.
toWei
(
'
0.2
'
,
'
gwei
'
),
maxPriorityFeePerGas
:
Web3
.
utils
.
toWei
(
'
0.1
'
,
'
gwei
'
),
}))
).
toBe
(
'
bigint
'
))
})
})
})
packages/web3.js-plugin-fee-estimation/src/plugin.ts
0 → 100644
View file @
b5d7b43b
This diff is collapsed.
Click to expand it.
packages/web3.js-plugin-fee-estimation/tsconfig.json
0 → 100644
View file @
b5d7b43b
{
"extends"
:
"../../tsconfig.json"
,
"compilerOptions"
:
{
"outDir"
:
"./dist"
,
"baseUrl"
:
"./src"
,
"strict"
:
true
,
"skipLibCheck"
:
true
,
"module"
:
"ESNext"
,
"moduleResolution"
:
"node"
,
"jsx"
:
"react"
,
"target"
:
"ESNext"
,
"noEmit"
:
true
},
"include"
:
[
"./src"
]
}
packages/web3.js-plugin-fee-estimation/tsup.config.ts
0 → 100644
View file @
b5d7b43b
import
{
defineConfig
}
from
'
tsup
'
import
packageJson
from
'
./package.json
'
// @see https://tsup.egoist.dev/
export
default
defineConfig
({
name
:
packageJson
.
name
,
entry
:
[
'
src/plugin.ts
'
],
outDir
:
'
dist
'
,
format
:
[
'
esm
'
,
'
cjs
'
],
splitting
:
false
,
sourcemap
:
true
,
clean
:
false
,
})
packages/web3.js-plugin-fee-estimation/vite.config.ts
0 → 100644
View file @
b5d7b43b
import
{
defineConfig
}
from
'
vitest/config
'
// @see https://vitest.dev/config/
export
default
defineConfig
({
test
:
{
environment
:
'
jsdom
'
,
coverage
:
{
provider
:
'
istanbul
'
,
},
},
})
pnpm-lock.yaml
View file @
b5d7b43b
This diff is collapsed.
Click to expand it.
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