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

chore(e2e/app): DRAFT deploy contracts to test SILK against #2356

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion contracts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ all: install-deps build bindings allocs ## Build contracts, generate bindings an
CORE_CONTRACTS := OmniPortal FeeOracleV1 Create3 TransparentUpgradeableProxy \
Staking Slashing OmniBridgeL1 OmniBridgeNative Omni WOmni \
PortalRegistry AllocPredeploys PingPong ProxyAdmin Admin \
OmniGasPump OmniGasStation
OmniGasPump OmniGasStation MockSymbioticVault MockToken

AVS_CONTRACTS := OmniAVS DelegationManager StrategyManager StrategyBase AVSDirectory \
avs/test/common/MockERC20.sol:MockERC20
Expand Down
307 changes: 307 additions & 0 deletions contracts/bindings/mocksymbioticvault.go

Large diffs are not rendered by default.

781 changes: 781 additions & 0 deletions contracts/bindings/mocktoken.go

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions contracts/core/.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ AllocPredeploys_Test:test_num_allocs() (gas: 1181152549)
AllocPredeploys_Test:test_predeploys() (gas: 1181134337)
AllocPredeploys_Test:test_preinstalls() (gas: 1181850775)
AllocPredeploys_Test:test_proxies() (gas: 1408777576)
FeeOracleV1_Test:test_bulkSetFeeParams() (gas: 172862)
FeeOracleV1_Test:test_feeFor() (gas: 122551)
FeeOracleV1_Test:test_setBaseGasLimit() (gas: 32208)
FeeOracleV1_Test:test_setGasPrice() (gas: 40996)
FeeOracleV1_Test:test_setManager() (gas: 45845)
FeeOracleV1_Test:test_setProtocolFee() (gas: 31442)
FeeOracleV1_Test:test_setToNativeRate() (gas: 41049)
FeeOracleV1_Test:test_bulkSetFeeParams() (gas: 173154)
FeeOracleV1_Test:test_feeFor() (gas: 122830)
FeeOracleV1_Test:test_setBaseGasLimit() (gas: 32375)
FeeOracleV1_Test:test_setGasPrice() (gas: 41034)
FeeOracleV1_Test:test_setManager() (gas: 45904)
FeeOracleV1_Test:test_setProtocolFee() (gas: 31610)
FeeOracleV1_Test:test_setToNativeRate() (gas: 41132)
FeeOracleV2_Test:test_bulkSetFeeParams() (gas: 119117)
FeeOracleV2_Test:test_feeFor() (gas: 103301)
FeeOracleV2_Test:test_setBaseGasLimit() (gas: 32009)
Expand Down
27 changes: 27 additions & 0 deletions contracts/core/test/silk/MockSymbioticVault.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity =0.8.24;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract MockSymbioticVault {
using SafeERC20 for IERC20;

address public immutable collateral;

mapping(address depositor => uint256 balance) public balances;

constructor(address newCollateral) {
collateral = newCollateral;
}

function deposit(address onBehalfOf, uint256 amount) external {
IERC20(collateral).safeTransferFrom(msg.sender, address(this), amount);
balances[onBehalfOf] += amount;
}

function withdraw(address to, uint256 amount) external {
balances[msg.sender] -= amount;
IERC20(collateral).safeTransfer(to, amount);
}
}
12 changes: 12 additions & 0 deletions contracts/core/test/silk/MockToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity =0.8.24;

import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MockToken is ERC20 {
constructor(string memory name_, string memory symbol_) ERC20(name_, symbol_) { }

function mint(address to, uint256 amount) external {
_mint(to, amount);
}
}
172 changes: 172 additions & 0 deletions e2e/app/mocksymbiotic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
package app

import (
"context"

"github.com/omni-network/omni/contracts/bindings"
"github.com/omni-network/omni/e2e/app/eoa"
"github.com/omni-network/omni/lib/errors"
"github.com/omni-network/omni/lib/log"

"github.com/ethereum/go-ethereum/common"
)

type TokenDeployment struct {
WstETH common.Address
RETH common.Address
METH common.Address
}

type SymbioticVaultDeployment struct {
WstETHVault common.Address
RETHVault common.Address
METHVault common.Address
}

func DeployMockSymbiotic(ctx context.Context, def Definition) (map[uint64]TokenDeployment, map[uint64]SymbioticVaultDeployment, error) {
deployedTokens, err := deployTokens(ctx, def)
if err != nil {
return nil, nil, errors.Wrap(err, "deploy tokens")
}

deployedVaults, err := deploySymbioticVaults(ctx, def, deployedTokens)
if err != nil {
return nil, nil, errors.Wrap(err, "deploy symbiotic vaults")
}

return deployedTokens, deployedVaults, nil
}

// deployTokens deploys OmniGasPump contracts to all chains except Omni's EVM.
func deployTokens(ctx context.Context, def Definition) (map[uint64]TokenDeployment, error) {
tokens := []struct {
name string
symbol string
}{
{"Wrapped Staked ETH", "wstETH"},
{"Rocket Pool ETH", "rETH"},
{"Mantle ETH", "mETH"},
}

// Track deployed token addresses per chain
deployments := make(map[uint64]TokenDeployment)

for _, chain := range def.Testnet.EVMChains() {
backend, err := def.Backends().Backend(chain.ChainID)
if err != nil {
return nil, errors.Wrap(err, "backend", "chain", chain.Name)
}

deployer := eoa.MustAddress(def.Testnet.Network, eoa.RoleDeployer)
auth, err := backend.BindOpts(ctx, deployer)
if err != nil {
return nil, errors.Wrap(err, "failed to get TransactionOpts for bindings")
}

var deployment TokenDeployment
// Deploy each token
for i, token := range tokens {
addr, _ /* tx */, mockToken, err := bindings.DeployMockToken(auth, backend, token.name, token.symbol)
// receipt, _ := backend.WaitMined(ctx, tx)
if err != nil {
return nil, errors.Wrap(
err,
"failed to deploy mock token",
"chain", chain.Name,
"token", token.symbol,
)
}

// Store address in deployment struct
switch i {
case 0:
deployment.WstETH = addr
case 1:
deployment.RETH = addr
case 2:
deployment.METH = addr
}
Comment on lines +80 to +87
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this is a bit fragile. Do we need TokenDeployment to be a struct? Can it be a simple map, and then we simply do deployment[token.name] = addr?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, or something like:

token := struct {
   setter func(common.Address)
   ..
}{
  {
    setter: func(addr common.Addrss) { deployment.WstETH = addr }
  }
  ....
}

token.SetAddress(addr)


log.Info(ctx, "Token deployed",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets make this debug, info should only be main workflow steps, this is a sub-step

"token", mockToken.Name,
"symbol", token.symbol,
"chain", chain.Name,
"address", addr.Hex(),
// "txid", receipt.TxHash.Hex()
)
}

deployments[chain.ChainID] = deployment
}

return deployments, nil
}

func deploySymbioticVaults(ctx context.Context, def Definition, deployedTokens map[uint64]TokenDeployment) (map[uint64]SymbioticVaultDeployment, error) {
vaults := []string{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest combining this and tokens above into a single package-level struct.

"wstETH Vault",
"rETH Vault",
"mETH Vault",
}

// Track deployed vault addresses per chain
deployments := make(map[uint64]SymbioticVaultDeployment)

for _, chain := range def.Testnet.EVMChains() {
tokens := deployedTokens[chain.ChainID]

backend, err := def.Backends().Backend(chain.ChainID)
if err != nil {
return nil, errors.Wrap(err, "backend", "chain", chain.Name)
}

deployer := eoa.MustAddress(def.Testnet.Network, eoa.RoleDeployer)
auth, err := backend.BindOpts(ctx, deployer)
if err != nil {
return nil, errors.Wrap(err, "failed to get TransactionOpts for bindings")
}

var deployment SymbioticVaultDeployment
// Deploy each vault
for i, vault := range vaults {
var tokenAddr common.Address
switch i {
case 0:
tokenAddr = tokens.WstETH
case 1:
tokenAddr = tokens.RETH
case 2:
tokenAddr = tokens.METH
}

addr, _ /* transactionType */, _ /* mockVault */, err := bindings.DeployMockSymbioticVault(auth, backend, tokenAddr)
if err != nil {
return nil, errors.Wrap(
err,
"failed to deploy mock symbiotic vault",
"chain", chain.Name,
"vault", vault,
)
}

// Store address in deployment struct
switch i {
case 0:
deployment.WstETHVault = addr
case 1:
deployment.RETHVault = addr
case 2:
deployment.METHVault = addr
}

log.Info(ctx, "Symbiotic vault deployed",
"vault", vault,
"chain", chain.Name,
"address", addr.Hex())
}

deployments[chain.ChainID] = deployment
}

return deployments, nil
}
4 changes: 4 additions & 0 deletions e2e/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ func Deploy(ctx context.Context, def Definition, cfg DeployConfig) (*pingpong.XD
if err := DeployGasApp(ctx, def); err != nil {
return nil, err
}

if _ /* tokenDeployments */, _ /* vaultDeployments */, err := DeployMockSymbiotic(ctx, def); err != nil {
return nil, err
}
}

if err := setupTokenBridge(ctx, def); err != nil {
Expand Down
Loading