Skip to content
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

feat(e2e/solve): add symbiotic target #2605

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions contracts/solve/script/MintMockToken.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity =0.8.24;

import { MockToken } from "test/utils/MockToken.sol";
import { Script } from "forge-std/Script.sol";

contract MintMockToken is Script {
function run(address token, address to) public {
vm.startBroadcast();
MockToken(token).mint(to, 1000 ether);
vm.stopBroadcast();
}
}
22 changes: 9 additions & 13 deletions e2e/solve/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/omni-network/omni/e2e/solve/devapp"
"github.com/omni-network/omni/e2e/solve/symbiotic"
"github.com/omni-network/omni/lib/contracts/solveinbox"
"github.com/omni-network/omni/lib/contracts/solveoutbox"
"github.com/omni-network/omni/lib/errors"
Expand All @@ -22,22 +23,17 @@ func DeployContracts(ctx context.Context, network netconf.Network, backends ethb
}

log.Info(ctx, "Deploying solve contracts")
if err := deployBoxes(ctx, network, backends); err != nil {
return errors.Wrap(err, "deploy boxes")
}

var eg errgroup.Group

eg.Go(func() error {
if err := deployBoxes(ctx, network, backends); err != nil {
return errors.Wrap(err, "deploy boxes")
}

return devapp.AllowOutboxCalls(ctx, network, backends)
})
eg.Go(func() error {
return devapp.Deploy(ctx, network, backends)
})

eg.Go(func() error { return devapp.AllowOutboxCalls(ctx, network, backends) })
eg.Go(func() error { return devapp.Deploy(ctx, network, backends) })
eg.Go(func() error { return symbiotic.FundSolver(ctx, network.ID, backends) })
eg.Go(func() error { return symbiotic.AllowOutboxCalls(ctx, network, backends) })
if err := eg.Wait(); err != nil {
return errors.Wrap(err, "deploy solver contracts")
return errors.Wrap(err, "setup solver devnet")
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions e2e/solve/devapp/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
// Deploy deploys the mock tokens and vaults to devnet.
func Deploy(ctx context.Context, network netconf.Network, backends ethbackend.Backends) error {
if network.ID != netconf.Devnet {
return errors.New("onl devnet")
return errors.New("only devnet")
}

l1Backend, err := backends.Backend(static.L1.ChainID)
Expand Down Expand Up @@ -91,7 +91,7 @@ func fundSolver(ctx context.Context, backend *ethbackend.Backend, tokenAddr comm
// AllowOutboxCalls allows the outbox to call the L1 vault deposit method.
func AllowOutboxCalls(ctx context.Context, network netconf.Network, backends ethbackend.Backends) error {
if network.ID != netconf.Devnet {
return errors.New("onl devnet")
return errors.New("only devnet")
}

addrs, err := contracts.GetAddresses(ctx, network.ID)
Expand Down
157 changes: 157 additions & 0 deletions e2e/solve/symbiotic/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package symbiotic

import (
"context"

"github.com/omni-network/omni/contracts/bindings"
"github.com/omni-network/omni/e2e/app/eoa"
"github.com/omni-network/omni/e2e/solve/devapp"
"github.com/omni-network/omni/lib/cast"
"github.com/omni-network/omni/lib/contracts"
"github.com/omni-network/omni/lib/errors"
"github.com/omni-network/omni/lib/ethclient/ethbackend"
"github.com/omni-network/omni/lib/evmchain"
"github.com/omni-network/omni/lib/netconf"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"

_ "embed"
)

type App struct {
L1wstETHCollateral common.Address
L1wstETH common.Address
L2wstETH common.Address
L1 evmchain.Metadata
L2 evmchain.Metadata
}

var (
//go:embed default-collateral-abi.json
collateralABIJSON []byte

collateralABI = mustParseABI(collateralABIJSON)
depositABI = mustGetMethod(collateralABI, "deposit")

mockL1 = mustChainMeta(evmchain.IDMockL1) // should be forked from holesky
mockL2 = mustChainMeta(evmchain.IDMockL2)
holesky = mustChainMeta(evmchain.IDHolesky)
baseSepolia = mustChainMeta(evmchain.IDBaseSepolia)
)

func GetApp(network netconf.ID) (App, error) {
app := App{
// holesky wsETH collateral
L1wstETHCollateral: common.HexToAddress("0x23e98253f372ee29910e22986fe75bb287b011fc"),
// holesky wsETH
L1wstETH: common.HexToAddress("0x8d09a4502cc8cf1547ad300e066060d043f6982d"),
// use mintable devapp mintable mock token, base sepolia has no canonical wsETH
L2wstETH: devapp.GetApp().L2Token,
}

if network == netconf.Devnet {
app.L1 = mockL1
app.L2 = mockL2

return app, nil
}

if network == netconf.Staging {
app.L1 = holesky
app.L2 = baseSepolia

return app, nil
}

return App{}, errors.New("unsupported network", "network", network)
}

func MustGetApp(network netconf.ID) App {
app, err := GetApp(network)
if err != nil {
panic(err)
}

return app
}

// AllowOutboxCalls allows the outbox to call the L1 wstETH collateral contract.
func AllowOutboxCalls(ctx context.Context, network netconf.Network, backends ethbackend.Backends) error {
app, err := GetApp(network.ID)
if err != nil {
return errors.Wrap(err, "get app")
}

addrs, err := contracts.GetAddresses(ctx, network.ID)
if err != nil {
return errors.Wrap(err, "get addresses")
}

l1Backend, err := backends.Backend(app.L1.ChainID)
if err != nil {
return errors.Wrap(err, "backend mock l1")
}

if err := allowCalls(ctx, app, l1Backend, addrs.SolveOutbox); err != nil {
return errors.Wrap(err, "allow calls")
}

return nil
}

// allowCalls allows the outbox to call the L1 wstETH collateral deposit method.
func allowCalls(ctx context.Context, app App, backend *ethbackend.Backend, outboxAddr common.Address) error {
outbox, err := bindings.NewSolveOutbox(outboxAddr, backend)
if err != nil {
return errors.Wrap(err, "new solve outbox")
}

manager := eoa.MustAddress(netconf.Devnet, eoa.RoleManager)

txOpts, err := backend.BindOpts(ctx, manager)
if err != nil {
return errors.Wrap(err, "bind opts")
}

depositID, err := cast.Array4(depositABI.ID[:4])
if err != nil {
return err
}

tx, err := outbox.SetAllowedCall(txOpts, app.L1wstETHCollateral, depositID, true)
if err != nil {
return errors.Wrap(err, "set allowed call")
} else if _, err := backend.WaitMined(ctx, tx); err != nil {
return errors.Wrap(err, "wait mined")
}

return nil
}

func mustParseABI(json []byte) *abi.ABI {
var abi abi.ABI
if err := abi.UnmarshalJSON(json); err != nil {
panic(err)
}

return &abi
}

func mustGetMethod(abi *abi.ABI, name string) abi.Method {
method, ok := abi.Methods[name]
if !ok {
panic(errors.New("missing method", "name", name))
}

return method
}

func mustChainMeta(chainID uint64) evmchain.Metadata {
meta, ok := evmchain.MetadataByID(chainID)
if !ok {
panic(errors.New("missing chain meta", "chain_id", chainID))
}

return meta
}
Loading
Loading