-
Notifications
You must be signed in to change notification settings - Fork 56
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
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); | ||
} | ||
} |
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); | ||
} | ||
} |
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 | ||
} | ||
|
||
log.Info(ctx, "Token deployed", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} |
There was a problem hiding this comment.
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 dodeployment[token.name] = addr
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, or something like: