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

Integrated upgradeable Ethereum contracts #326

Merged
merged 2 commits into from
Aug 22, 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
157 changes: 156 additions & 1 deletion clients/ethereum/contract/Bridge.go

Large diffs are not rendered by default.

157 changes: 156 additions & 1 deletion clients/ethereum/contract/ERC20Safe.go

Large diffs are not rendered by default.

157 changes: 156 additions & 1 deletion clients/ethereum/contract/MintBurnERC20.go

Large diffs are not rendered by default.

48 changes: 45 additions & 3 deletions integrationTests/relayers/slowTests/framework/ethereumHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ const (
genericERC20Bytecode = "testdata/contracts/eth/GenericERC20.hex"
mintBurnERC20ABI = "testdata/contracts/eth/MintBurnERC20.abi.json"
mintBurnERC20Bytecode = "testdata/contracts/eth/MintBurnERC20.hex"
proxyABI = "testdata/contracts/eth/Proxy.abi.json"
proxyBytecode = "testdata/contracts/eth/Proxy.hex"

proxyInitializeFunction = "initialize"
)

// EthereumHandler will handle all the operations on the Ethereum side
Expand Down Expand Up @@ -99,7 +103,7 @@ func NewEthereumHandler(
// DeployContracts will deploy all required contracts on Ethereum side
func (handler *EthereumHandler) DeployContracts(ctx context.Context) {
// deploy safe
handler.SafeAddress = handler.DeployContract(ctx, erc20SafeABI, erc20SafeBytecode)
handler.SafeAddress = handler.DeployUpgradeableContract(ctx, erc20SafeABI, erc20SafeBytecode)
ethSafeContract, err := contract.NewERC20Safe(handler.SafeAddress, handler.SimulatedChain.Client())
require.NoError(handler, err)
handler.SafeContract = ethSafeContract
Expand All @@ -110,7 +114,7 @@ func (handler *EthereumHandler) DeployContracts(ctx context.Context) {
ethRelayersAddresses = append(ethRelayersAddresses, relayerKeys.EthAddress)
}
quorumInt, _ := big.NewInt(0).SetString(handler.Quorum, 10)
handler.BridgeAddress = handler.DeployContract(ctx, bridgeABI, bridgeBytecode, ethRelayersAddresses, quorumInt, handler.SafeAddress)
handler.BridgeAddress = handler.DeployUpgradeableContract(ctx, bridgeABI, bridgeBytecode, ethRelayersAddresses, quorumInt, handler.SafeAddress)
handler.BridgeContract, err = contract.NewBridge(handler.BridgeAddress, handler.SimulatedChain.Client())
require.NoError(handler, err)

Expand Down Expand Up @@ -160,6 +164,44 @@ func (handler *EthereumHandler) DeployContract(
return contractAddress
}

// DeployUpgradeableContract can deploy an upgradeable Ethereum contract
func (handler *EthereumHandler) DeployUpgradeableContract(
ctx context.Context,
abiFile string,
bytecodeFile string,
params ...interface{},
) common.Address {
abiBytes, err := os.ReadFile(abiFile)
require.NoError(handler, err)
parsed, err := abi.JSON(bytes.NewReader(abiBytes))
require.NoError(handler, err)

contractBytes, err := os.ReadFile(bytecodeFile)
require.NoError(handler, err)

contractAuth, _ := bind.NewKeyedTransactorWithChainID(handler.OwnerKeys.EthSK, handler.ChainID)
contractAddress, tx, _, err := bind.DeployContract(contractAuth, parsed, common.FromHex(converters.TrimWhiteSpaceCharacters(string(contractBytes))), handler.SimulatedChain.Client()) // no parameters on the logic contract constructor
require.NoError(handler, err)
handler.SimulatedChain.Commit()

handler.checkEthTxResult(ctx, tx.Hash())

log.Info("deployed eth logic contract", "from file", bytecodeFile, "address", contractAddress.Hex())

packedParams, err := parsed.Pack(proxyInitializeFunction, params...)
require.NoError(handler, err)
proxyParams := []interface{}{
contractAddress,
handler.OwnerKeys.EthAddress, // make the owner of the logic contract the admin for the proxy
packedParams,
}
proxyAddress := handler.DeployContract(ctx, proxyABI, proxyBytecode, proxyParams...)

log.Info("deployed proxy contract", "address", proxyAddress.Hex())

return proxyAddress // return the proxy to test that it behaves just the same as the logic contract
}

func (handler *EthereumHandler) checkEthTxResult(ctx context.Context, hash common.Hash) {
receipt, err := handler.SimulatedChain.Client().TransactionReceipt(ctx, hash)
require.NoError(handler, err)
Expand Down Expand Up @@ -228,7 +270,7 @@ func (handler *EthereumHandler) IssueAndWhitelistToken(ctx context.Context, para

func (handler *EthereumHandler) deployTestERC20Contract(ctx context.Context, params IssueTokenParams) (common.Address, ERC20Contract) {
if params.IsMintBurnOnEth {
ethMintBurnAddress := handler.DeployContract(
ethMintBurnAddress := handler.DeployUpgradeableContract(
ctx,
mintBurnERC20ABI,
mintBurnERC20Bytecode,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
[
{
"inputs": [
{
"internalType": "address[]",
"name": "board",
"type": "address[]"
},
{
"internalType": "uint256",
"name": "initialQuorum",
"type": "uint256"
},
{
"internalType": "contract ERC20Safe",
"name": "erc20Safe",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
"inputs": [],
"name": "InvalidInitialization",
"type": "error"
},
{
"inputs": [],
"name": "NotInitializing",
"type": "error"
},
{
"anonymous": false,
Expand All @@ -39,6 +28,19 @@
"name": "AdminRoleTransferred",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "version",
"type": "uint64"
}
],
"name": "Initialized",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down Expand Up @@ -389,6 +391,29 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address[]",
"name": "board",
"type": "address[]"
},
{
"internalType": "uint256",
"name": "initialQuorum",
"type": "uint256"
},
{
"internalType": "contract ERC20Safe",
"name": "erc20Safe",
"type": "address"
}
],
"name": "initialize",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
"name": "FailedInnerCall",
"type": "error"
},
{
"inputs": [],
"name": "InvalidInitialization",
"type": "error"
},
{
"inputs": [],
"name": "NotInitializing",
"type": "error"
},
{
"inputs": [
{
Expand Down Expand Up @@ -119,6 +129,19 @@
"name": "ERC20SCDeposit",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "version",
"type": "uint64"
}
],
"name": "Initialized",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down Expand Up @@ -534,6 +557,13 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "initialize",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "isAnyBatchInProgress",
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
[
{
"inputs": [
{
"internalType": "string",
"name": "name",
"type": "string"
},
{
"internalType": "string",
"name": "symbol",
"type": "string"
},
{
"internalType": "uint8",
"name": "providedNumDecimals",
"type": "uint8"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "AccessControlBadConfirmation",
Expand Down Expand Up @@ -138,6 +117,16 @@
"name": "ERC20InvalidSpender",
"type": "error"
},
{
"inputs": [],
"name": "InvalidInitialization",
"type": "error"
},
{
"inputs": [],
"name": "NotInitializing",
"type": "error"
},
{
"anonymous": false,
"inputs": [
Expand All @@ -163,6 +152,19 @@
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "version",
"type": "uint64"
}
],
"name": "Initialized",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down Expand Up @@ -461,6 +463,29 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "name",
"type": "string"
},
{
"internalType": "string",
"name": "symbol",
"type": "string"
},
{
"internalType": "uint8",
"name": "providedNumDecimals",
"type": "uint8"
}
],
"name": "initialize",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down

Large diffs are not rendered by default.

Loading
Loading