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
9b16d367
Commit
9b16d367
authored
Jun 26, 2023
by
Mark Tyneway
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-bindings: make gen fast
parent
2bb78664
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
98 additions
and
193 deletions
+98
-193
Makefile
op-bindings/Makefile
+2
-136
artifacts.json
op-bindings/artifacts.json
+35
-0
artifact.go
op-bindings/foundry/artifact.go
+5
-3
main.go
op-bindings/gen/main.go
+56
-3
gen_bindings.sh
op-bindings/gen_bindings.sh
+0
-51
No files found.
op-bindings/Makefile
View file @
9b16d367
...
...
@@ -4,40 +4,6 @@ pkg := bindings
all
:
version mkdir bindings more
bindings
:
l1block-bindings
\
l1-blocknumber-bindings
\
system-config-bindings
\
l1-cross-domain-messenger-bindings
\
l1-standard-bridge-bindings
\
l2-to-l1-message-passer-bindings
\
optimism-portal-bindings
\
l2-output-oracle-bindings
\
gas-price-oracle-bindings
\
legacy-message-passer-bindings
\
address-manager-bindings
\
l2-cross-domain-messenger-bindings
\
l2-standard-bridge-bindings
\
sequencer-fee-vault-bindings
\
optimism-mintable-erc20-factory-bindings
\
optimism-mintable-erc20-bindings
\
proxy-bindings
\
proxy-admin-bindings
\
erc20-bindings
\
weth9-bindings
\
deployer-whitelist-bindings
\
l2-erc721-bridge-bindings
\
l1-erc721-bridge-bindings
\
optimism-mintable-erc721-factory-bindings
\
l1-fee-vault-bindings
\
basefee-vault-bindings
\
legacy-erc20-eth-bindings
\
dispute-game-factory-bindings
\
fault-dispute-game-bindings
\
standard-bridge-bindings
\
cross-domain-messenger-bindings
\
cannon-mips
\
cannon-preimage-oracle
version
:
forge
--version
abigen
--version
...
...
@@ -47,111 +13,11 @@ compile:
yarn clean
&&
\
yarn build
system-config-bindings
:
compile
./gen_bindings.sh contracts/L1/SystemConfig.sol:SystemConfig
$(pkg)
l1-cross-domain-messenger-bindings
:
compile
./gen_bindings.sh contracts/L1/L1CrossDomainMessenger.sol:L1CrossDomainMessenger
$(pkg)
l1-standard-bridge-bindings
:
compile
./gen_bindings.sh contracts/L1/L1StandardBridge.sol:L1StandardBridge
$(pkg)
optimism-portal-bindings
:
compile
./gen_bindings.sh contracts/L1/OptimismPortal.sol:OptimismPortal
$(pkg)
l2-output-oracle-bindings
:
compile
./gen_bindings.sh contracts/L1/L2OutputOracle.sol:L2OutputOracle
$(pkg)
address-manager-bindings
:
compile
./gen_bindings.sh contracts/legacy/AddressManager.sol:AddressManager
$(pkg)
l1block-bindings
:
compile
./gen_bindings.sh contracts/L2/L1Block.sol:L1Block
$(pkg)
l2-to-l1-message-passer-bindings
:
compile
./gen_bindings.sh contracts/L2/L2ToL1MessagePasser.sol:L2ToL1MessagePasser
$(pkg)
gas-price-oracle-bindings
:
compile
./gen_bindings.sh contracts/L2/GasPriceOracle.sol:GasPriceOracle
$(pkg)
l2-cross-domain-messenger-bindings
:
compile
./gen_bindings.sh contracts/L2/L2CrossDomainMessenger.sol:L2CrossDomainMessenger
$(pkg)
l2-standard-bridge-bindings
:
compile
./gen_bindings.sh contracts/L2/L2StandardBridge.sol:L2StandardBridge
$(pkg)
l2-erc721-bridge-bindings
:
./gen_bindings.sh contracts/L2/L2ERC721Bridge.sol:L2ERC721Bridge
$(pkg)
l1-erc721-bridge-bindings
:
./gen_bindings.sh contracts/L1/L1ERC721Bridge.sol:L1ERC721Bridge
$(pkg)
optimism-mintable-erc721-factory-bindings
:
./gen_bindings.sh contracts/universal/OptimismMintableERC721Factory.sol:OptimismMintableERC721Factory
$(pkg)
sequencer-fee-vault-bindings
:
compile
./gen_bindings.sh contracts/L2/SequencerFeeVault.sol:SequencerFeeVault
$(pkg)
basefee-vault-bindings
:
compile
./gen_bindings.sh contracts/L2/BaseFeeVault.sol:BaseFeeVault
$(pkg)
l1-fee-vault-bindings
:
compile
./gen_bindings.sh contracts/L2/L1FeeVault.sol:L1FeeVault
$(pkg)
optimism-mintable-erc20-factory-bindings
:
compile
./gen_bindings.sh contracts/universal/OptimismMintableERC20Factory.sol:OptimismMintableERC20Factory
$(pkg)
optimism-mintable-erc20-bindings
:
compile
./gen_bindings.sh contracts/universal/OptimismMintableERC20.sol:OptimismMintableERC20
$(pkg)
legacy-erc20-eth-bindings
:
compile
./gen_bindings.sh contracts/legacy/LegacyERC20ETH.sol:LegacyERC20ETH
$(pkg)
proxy-bindings
:
compile
./gen_bindings.sh contracts/universal/Proxy.sol:Proxy
$(pkg)
proxy-admin-bindings
:
compile
./gen_bindings.sh contracts/universal/ProxyAdmin.sol:ProxyAdmin
$(pkg)
legacy-message-passer-bindings
:
compile
./gen_bindings.sh contracts/legacy/LegacyMessagePasser.sol:LegacyMessagePasser
$(pkg)
erc20-bindings
:
compile
./gen_bindings.sh node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol:ERC20
$(pkg)
weth9-bindings
:
compile
./gen_bindings.sh contracts/vendor/WETH9.sol:WETH9
$(pkg)
deployer-whitelist-bindings
:
compile
./gen_bindings.sh contracts/legacy/DeployerWhitelist.sol:DeployerWhitelist
$(pkg)
l1-blocknumber-bindings
:
compile
./gen_bindings.sh contracts/legacy/L1BlockNumber.sol:L1BlockNumber
$(pkg)
dispute-game-factory-bindings
:
compile
./gen_bindings.sh contracts/dispute/DisputeGameFactory.sol:DisputeGameFactory
$(pkg)
fault-dispute-game-bindings
:
compile
./gen_bindings.sh contracts/dispute/FaultDisputeGame.sol:FaultDisputeGame
$(pkg)
standard-bridge-bindings
:
compile
./gen_bindings.sh contracts/universal/StandardBridge.sol:StandardBridge
$(pkg)
cross-domain-messenger-bindings
:
compile
./gen_bindings.sh contracts/universal/CrossDomainMessenger.sol:CrossDomainMessenger
$(pkg)
cannon-mips
:
compile
./gen_bindings.sh contracts/cannon/MIPS.sol:MIPS
$(pkg)
cannon-preimage-oracle
:
compile
./gen_bindings.sh contracts/cannon/PreimageOracle.sol:PreimageOracle
$(pkg)
more
:
bindings
:
compile
go run ./gen/main.go
\
-forge-artifacts
../packages/contracts-bedrock/forge-artifacts
\
-out
./bindings
\
-contracts
SystemConfig,OptimismMintableERC20Factory,L2StandardBridge,L1BlockNumber,LegacyMessagePasser,DeployerWhitelist,Proxy,OptimismPortal,L2ToL1MessagePasser,L2CrossDomainMessenger,SequencerFeeVault,L1Block,LegacyERC20ETH,WETH9,GovernanceToken,L1CrossDomainMessenger,L2ERC721Bridge,OptimismMintableERC721Factory,ProxyAdmin,MIPS,PreimageOracle
\
-contracts
./artifacts.json
\
-source-maps
MIPS,PreimageOracle
\
-package
bindings
...
...
op-bindings/artifacts.json
0 → 100644
View file @
9b16d367
[
"SystemConfig"
,
"L1CrossDomainMessenger"
,
"L1StandardBridge"
,
"OptimismPortal"
,
"L2OutputOracle"
,
"AddressManager"
,
"L1Block"
,
"L2ToL1MessagePasser"
,
"GasPriceOracle"
,
"L2CrossDomainMessenger"
,
"L2StandardBridge"
,
"L2ERC721Bridge"
,
"L1ERC721Bridge"
,
"OptimismMintableERC721Factory"
,
"SequencerFeeVault"
,
"BaseFeeVault"
,
"L1FeeVault"
,
"OptimismMintableERC20Factory"
,
"OptimismMintableERC20"
,
"LegacyERC20ETH"
,
"Proxy"
,
"ProxyAdmin"
,
"LegacyMessagePasser"
,
"ERC20"
,
"WETH9"
,
"DeployerWhitelist"
,
"L1BlockNumber"
,
"DisputeGameFactory"
,
"FaultDisputeGame"
,
"StandardBridge"
,
"CrossDomainMessenger"
,
"MIPS"
,
"PreimageOracle"
]
op-bindings/foundry/artifact.go
View file @
9b16d367
...
...
@@ -4,13 +4,15 @@ import (
"encoding/json"
"github.com/ethereum-optimism/optimism/op-bindings/solc"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common/hexutil"
)
// Artifact represents a foundry compilation artifact.
// The Abi is specifically left as a json.RawMessage because
// round trip marshaling/unmarshaling of the abi.ABI type
// causes issues.
type
Artifact
struct
{
Abi
abi
.
ABI
`json:"abi"`
Abi
json
.
RawMessage
`json:"abi"`
StorageLayout
solc
.
StorageLayout
`json:"storageLayout"`
DeployedBytecode
DeployedBytecode
`json:"deployedBytecode"`
Bytecode
Bytecode
`json:"bytecode"`
...
...
op-bindings/gen/main.go
View file @
9b16d367
...
...
@@ -6,6 +6,7 @@ import (
"flag"
"log"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
...
...
@@ -35,12 +36,20 @@ func main() {
var
f
flags
flag
.
StringVar
(
&
f
.
ForgeArtifacts
,
"forge-artifacts"
,
""
,
"Forge artifacts directory, to load sourcemaps from, if available"
)
flag
.
StringVar
(
&
f
.
OutDir
,
"out"
,
""
,
"Output directory to put code in"
)
flag
.
StringVar
(
&
f
.
Contracts
,
"contracts"
,
"
"
,
"Comma-separated list of contracts to generate code
for"
)
flag
.
StringVar
(
&
f
.
Contracts
,
"contracts"
,
"
artifacts.json"
,
"Path to file containing list of contracts to generate bindings
for"
)
flag
.
StringVar
(
&
f
.
SourceMaps
,
"source-maps"
,
""
,
"Comma-separated list of contracts to generate source-maps for"
)
flag
.
StringVar
(
&
f
.
Package
,
"package"
,
"artifacts"
,
"Go package name"
)
flag
.
Parse
()
contracts
:=
strings
.
Split
(
f
.
Contracts
,
","
)
contractData
,
err
:=
os
.
ReadFile
(
f
.
Contracts
)
if
err
!=
nil
{
log
.
Fatal
(
"error reading contract list: %w
\n
"
,
err
)
}
contracts
:=
[]
string
{}
if
err
:=
json
.
Unmarshal
(
contractData
,
&
contracts
);
err
!=
nil
{
log
.
Fatal
(
"error parsing contract list: %w
\n
"
,
err
)
}
sourceMaps
:=
strings
.
Split
(
f
.
SourceMaps
,
","
)
sourceMapsSet
:=
make
(
map
[
string
]
struct
{})
for
_
,
k
:=
range
sourceMaps
{
...
...
@@ -53,10 +62,22 @@ func main() {
t
:=
template
.
Must
(
template
.
New
(
"artifact"
)
.
Parse
(
tmpl
))
// Make a temp dir to hold all the inputs for abigen
dir
,
err
:=
os
.
MkdirTemp
(
""
,
"op-bindings"
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
log
.
Printf
(
"Using package %s
\n
"
,
f
.
Package
)
defer
os
.
RemoveAll
(
dir
)
log
.
Printf
(
"created temp dir %s
\n
"
,
dir
)
for
_
,
name
:=
range
contracts
{
log
.
Printf
(
"generating code for %s
\n
"
,
name
)
forgeArtifactData
,
err
:=
os
.
ReadFile
(
path
.
Join
(
f
.
ForgeArtifacts
,
name
+
".sol"
,
name
+
".json"
))
if
errors
.
Is
(
err
,
os
.
ErrNotExist
)
{
log
.
Printf
(
"cannot find forge-artifact with source-map data
of %q
\n
"
,
name
)
log
.
Fatalf
(
"cannot find forge-artifact
of %q
\n
"
,
name
)
}
var
artifact
foundry
.
Artifact
...
...
@@ -67,6 +88,38 @@ func main() {
log
.
Fatalf
(
"error reading storage layout %s: %v
\n
"
,
name
,
err
)
}
rawAbi
:=
artifact
.
Abi
if
err
!=
nil
{
log
.
Fatalf
(
"error marshaling abi: %v
\n
"
,
err
)
}
abiFile
:=
path
.
Join
(
dir
,
name
+
".abi"
)
if
err
:=
os
.
WriteFile
(
abiFile
,
rawAbi
,
0
o600
);
err
!=
nil
{
log
.
Fatalf
(
"error writing file: %v
\n
"
,
err
)
}
rawBytecode
:=
artifact
.
Bytecode
.
Object
.
String
()
if
err
!=
nil
{
log
.
Fatalf
(
"error marshaling bytecode: %v
\n
"
,
err
)
}
bytecodeFile
:=
path
.
Join
(
dir
,
name
+
".bin"
)
if
err
:=
os
.
WriteFile
(
bytecodeFile
,
[]
byte
(
rawBytecode
),
0
o600
);
err
!=
nil
{
log
.
Fatalf
(
"error writing file: %v
\n
"
,
err
)
}
cwd
,
err
:=
os
.
Getwd
()
if
err
!=
nil
{
log
.
Fatalf
(
"error getting cwd: %v
\n
"
,
err
)
}
lowerName
:=
strings
.
ToLower
(
name
)
outFile
:=
path
.
Join
(
cwd
,
f
.
Package
,
lowerName
+
".go"
)
cmd
:=
exec
.
Command
(
"abigen"
,
"--abi"
,
abiFile
,
"--bin"
,
bytecodeFile
,
"--pkg"
,
f
.
Package
,
"--type"
,
name
,
"--out"
,
outFile
)
cmd
.
Stdout
=
os
.
Stdout
if
err
:=
cmd
.
Run
();
err
!=
nil
{
log
.
Fatalf
(
"error running abigen: %v
\n
"
,
err
)
}
storage
:=
artifact
.
StorageLayout
canonicalStorage
:=
ast
.
CanonicalizeASTIDs
(
&
storage
)
ser
,
err
:=
json
.
Marshal
(
canonicalStorage
)
...
...
op-bindings/gen_bindings.sh
deleted
100755 → 0
View file @
2bb78664
#/bin/bash
set
-eu
CONTRACTS_PATH
=
"../packages/contracts-bedrock/"
if
[
"$#"
-ne
2
]
;
then
echo
"This script takes 2 arguments - CONTRACT_NAME PACKAGE"
exit
1
fi
need_cmd
()
{
if
!
command
-v
"
$1
"
>
/dev/null 2>&1
;
then
echo
"need '
$1
' (command not found)"
exit
1
fi
}
need_cmd forge
need_cmd abigen
NAME
=
$1
# This can handle both fully qualified syntax or just
# the name of the contract.
# Fully qualified: path-to-contract-file:contract-name
TYPE
=
$(
echo
"
$NAME
"
|
cut
-d
':'
-f2
)
PACKAGE
=
$2
# Convert to lower case to respect golang package naming conventions
TYPE_LOWER
=
$(
echo
${
TYPE
}
|
tr
'[:upper:]'
'[:lower:]'
)
FILENAME
=
"
${
TYPE_LOWER
}
_deployed.go"
mkdir
-p
bin
TEMP
=
$(
mktemp
-d
)
CWD
=
$(
pwd
)
# Build contracts
cd
${
CONTRACTS_PATH
}
forge inspect
${
NAME
}
abi
>
${
TEMP
}
/
${
TYPE
}
.abi
forge inspect
${
NAME
}
bytecode
>
${
TEMP
}
/
${
TYPE
}
.bin
forge inspect
${
NAME
}
deployedBytecode
>
${
CWD
}
/bin/
${
TYPE_LOWER
}
_deployed.hex
# Run ABIGEN
cd
${
CWD
}
abigen
\
--abi
${
TEMP
}
/
${
TYPE
}
.abi
\
--bin
${
TEMP
}
/
${
TYPE
}
.bin
\
--pkg
${
PACKAGE
}
\
--type
${
TYPE
}
\
--out
./
${
PACKAGE
}
/
${
TYPE_LOWER
}
.go
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