-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add support for pre-existing OPSM #12099
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
93b0414
Add support for pre-existing OPSM
mslipper 5dd7acd
chore: add version identifer to Deployed event
mds1 8918174
chore: emit msg.sender in Deployed event
mds1 1138032
Merge remote-tracking branch 'upstream/develop' into feat/deployer-ex…
mslipper c19c441
Fix merge issues
mslipper 9c6f681
test: fix specs test
mds1 d7081c5
semver-lock
mslipper d385c32
code review updates
mslipper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package opcm | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/ethereum/go-ethereum" | ||
| "github.com/ethereum/go-ethereum/accounts/abi" | ||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/ethereum/go-ethereum/ethclient" | ||
| ) | ||
|
|
||
| type Contract struct { | ||
| addr common.Address | ||
| client *ethclient.Client | ||
| } | ||
|
|
||
| func NewContract(addr common.Address, client *ethclient.Client) *Contract { | ||
| return &Contract{addr: addr, client: client} | ||
| } | ||
|
|
||
| func (c *Contract) SuperchainConfig(ctx context.Context) (common.Address, error) { | ||
| return c.getAddress(ctx, "superchainConfig") | ||
| } | ||
|
|
||
| func (c *Contract) ProtocolVersions(ctx context.Context) (common.Address, error) { | ||
| return c.getAddress(ctx, "protocolVersions") | ||
| } | ||
|
|
||
| func (c *Contract) getAddress(ctx context.Context, name string) (common.Address, error) { | ||
| method := abi.NewMethod( | ||
| name, | ||
| name, | ||
| abi.Function, | ||
| "view", | ||
| true, | ||
| false, | ||
| abi.Arguments{}, | ||
| abi.Arguments{ | ||
| abi.Argument{ | ||
| Name: "address", | ||
| Type: mustType("address"), | ||
| Indexed: false, | ||
| }, | ||
| }, | ||
| ) | ||
|
|
||
| calldata, err := method.Inputs.Pack() | ||
| if err != nil { | ||
| return common.Address{}, fmt.Errorf("failed to pack inputs: %w", err) | ||
| } | ||
|
|
||
| msg := ethereum.CallMsg{ | ||
| To: &c.addr, | ||
| Data: append(bytes.Clone(method.ID), calldata...), | ||
| } | ||
| result, err := c.client.CallContract(ctx, msg, nil) | ||
| if err != nil { | ||
| return common.Address{}, fmt.Errorf("failed to call contract: %w", err) | ||
| } | ||
|
|
||
| out, err := method.Outputs.Unpack(result) | ||
| if err != nil { | ||
| return common.Address{}, fmt.Errorf("failed to unpack result: %w", err) | ||
| } | ||
| if len(out) != 1 { | ||
| return common.Address{}, fmt.Errorf("unexpected output length: %d", len(out)) | ||
| } | ||
| addr, ok := out[0].(common.Address) | ||
| if !ok { | ||
| return common.Address{}, fmt.Errorf("unexpected type: %T", out[0]) | ||
| } | ||
| return addr, nil | ||
| } | ||
|
|
||
| func mustType(t string) abi.Type { | ||
| typ, err := abi.NewType(t, "", nil) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| return typ | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.