From eac361fde8076d067d511265afafb18aed16958c Mon Sep 17 00:00:00 2001 From: beer-1 Date: Mon, 6 Jan 2025 15:49:24 +0900 Subject: [PATCH] update factory address in wrapper when factory contract has been updated --- app/upgrade.go | 96 ++++++++++--------- x/evm/contracts/erc20_wrapper/ERC20Wrapper.go | 25 ++++- .../contracts/erc20_wrapper/ERC20Wrapper.sol | 10 +- x/evm/keeper/erc20.go | 19 +++- x/evm/keeper/genesis.go | 20 +++- x/evm/keeper/genesis_test.go | 54 +++++++++++ x/evm/types/expected_keeper.go | 2 + 7 files changed, 176 insertions(+), 50 deletions(-) diff --git a/app/upgrade.go b/app/upgrade.go index ee4e13b0..aa2c88ef 100644 --- a/app/upgrade.go +++ b/app/upgrade.go @@ -22,7 +22,7 @@ import ( opchildtypes "github.com/initia-labs/OPinit/x/opchild/types" ) -const upgradeName = "0.6.7" +const upgradeName = "0.6.8" // RegisterUpgradeHandlers returns upgrade handlers func (app *MinitiaApp) RegisterUpgradeHandlers(cfg module.Configurator) { @@ -49,14 +49,14 @@ func (app *MinitiaApp) RegisterUpgradeHandlers(cfg module.Configurator) { //////////////////////////// MINIEVM /////////////////////////////////// - // deploy and store erc20 wrapper contract address + // try to deploy and store erc20 wrapper contract address if err := app.EVMKeeper.DeployERC20Wrapper(ctx); err != nil && // ignore contract address collision error (contract already deployed) !strings.Contains(err.Error(), vm.ErrContractAddressCollision.Error()) { return nil, err } - // deploy and store erc20 factory contract address + // try to deploy and store erc20 factory contract address if err := app.EVMKeeper.DeployERC20Factory(ctx); err != nil && // ignore contract address collision error (contract already deployed) !strings.Contains(err.Error(), vm.ErrContractAddressCollision.Error()) { @@ -67,47 +67,7 @@ func (app *MinitiaApp) RegisterUpgradeHandlers(cfg module.Configurator) { // address collision error is ignored because it means that the contract has already been deployed // and the erc20 contracts have already been updated. // - code := hexutil.MustDecode(erc20.Erc20MetaData.Bin) - - // runtime code - initCodeOP := common.Hex2Bytes("5ff3fe") - initCodePos := bytes.Index(code, initCodeOP) - code = code[initCodePos+3:] - - // code hash - codeHash := crypto.Keccak256Hash(code).Bytes() - - // iterate all erc20 contracts and replace contract code to new version - err = app.EVMKeeper.ERC20s.Walk(ctx, nil, func(contractAddr []byte) (bool, error) { - acc := app.AccountKeeper.GetAccount(ctx, contractAddr) - if acc == nil { - return true, fmt.Errorf("account not found for contract address %s", contractAddr) - } - - contractAcc, ok := acc.(*evmtypes.ContractAccount) - if !ok { - return true, fmt.Errorf("account is not a contract account for contract address %s", contractAddr) - } - - contractAcc.CodeHash = codeHash - app.AccountKeeper.SetAccount(ctx, contractAcc) - - // set code - codeKey := append(contractAddr, append(state.CodeKeyPrefix, codeHash...)...) - err := app.EVMKeeper.VMStore.Set(ctx, codeKey, code) - if err != nil { - return true, err - } - - // set code size - codeSizeKey := append(contractAddr, append(state.CodeSizeKeyPrefix, codeHash...)...) - err = app.EVMKeeper.VMStore.Set(ctx, codeSizeKey, uint64ToBytes(uint64(len(code)))) - if err != nil { - return true, err - } - - return false, nil - }) + err = app.updateERC20s(ctx) if err != nil { return nil, err } @@ -118,6 +78,54 @@ func (app *MinitiaApp) RegisterUpgradeHandlers(cfg module.Configurator) { ) } +// updateERC20s updates all erc20 contracts to the new version +// - update contract code +// - update contract code hash +// - update contract code size +func (app *MinitiaApp) updateERC20s(ctx context.Context) error { + code := hexutil.MustDecode(erc20.Erc20MetaData.Bin) + + // runtime code + initCodeOP := common.Hex2Bytes("5ff3fe") + initCodePos := bytes.Index(code, initCodeOP) + code = code[initCodePos+3:] + + // code hash + codeHash := crypto.Keccak256Hash(code).Bytes() + + // iterate all erc20 contracts and replace contract code to new version + return app.EVMKeeper.ERC20s.Walk(ctx, nil, func(contractAddr []byte) (bool, error) { + acc := app.AccountKeeper.GetAccount(ctx, contractAddr) + if acc == nil { + return true, fmt.Errorf("account not found for contract address %s", contractAddr) + } + + contractAcc, ok := acc.(*evmtypes.ContractAccount) + if !ok { + return true, fmt.Errorf("account is not a contract account for contract address %s", contractAddr) + } + + contractAcc.CodeHash = codeHash + app.AccountKeeper.SetAccount(ctx, contractAcc) + + // set code + codeKey := append(contractAddr, append(state.CodeKeyPrefix, codeHash...)...) + err := app.EVMKeeper.VMStore.Set(ctx, codeKey, code) + if err != nil { + return true, err + } + + // set code size + codeSizeKey := append(contractAddr, append(state.CodeSizeKeyPrefix, codeHash...)...) + err = app.EVMKeeper.VMStore.Set(ctx, codeSizeKey, uint64ToBytes(uint64(len(code)))) + if err != nil { + return true, err + } + + return false, nil + }) +} + func uint64ToBytes(v uint64) []byte { bz := make([]byte, 8) binary.BigEndian.PutUint64(bz, v) diff --git a/x/evm/contracts/erc20_wrapper/ERC20Wrapper.go b/x/evm/contracts/erc20_wrapper/ERC20Wrapper.go index a18f3d95..a93612d8 100644 --- a/x/evm/contracts/erc20_wrapper/ERC20Wrapper.go +++ b/x/evm/contracts/erc20_wrapper/ERC20Wrapper.go @@ -31,8 +31,8 @@ var ( // Erc20WrapperMetaData contains all meta data concerning the Erc20Wrapper contract. var Erc20WrapperMetaData = &bind.MetaData{ - ABI: "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"erc20Factory\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"length\",\"type\":\"uint256\"}],\"name\":\"StringsInsufficientHexLength\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"factory\",\"outputs\":[{\"internalType\":\"contractERC20Factory\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"callback_id\",\"type\":\"uint64\"},{\"internalType\":\"bool\",\"name\":\"success\",\"type\":\"bool\"}],\"name\":\"ibc_ack\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"callback_id\",\"type\":\"uint64\"}],\"name\":\"ibc_timeout\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"originToken\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"receiver\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"wrappedAmt\",\"type\":\"uint256\"}],\"name\":\"unwrap\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"channel\",\"type\":\"string\"},{\"internalType\":\"address\",\"name\":\"token\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"receiver\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"timeout\",\"type\":\"uint256\"}],\"name\":\"wrap\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"wrappedTokens\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]", - Bin: "0x60a06040525f8060146101000a81548167ffffffffffffffff021916908367ffffffffffffffff160217905550348015610037575f80fd5b50604051612d24380380612d2483398181016040528101906100599190610130565b335f806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508073ffffffffffffffffffffffffffffffffffffffff1660808173ffffffffffffffffffffffffffffffffffffffff16815250505061015b565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6100ff826100d6565b9050919050565b61010f816100f5565b8114610119575f80fd5b50565b5f8151905061012a81610106565b92915050565b5f60208284031215610145576101446100d2565b5b5f6101528482850161011c565b91505092915050565b608051612baa61017a5f395f81816109a70152610fd00152612baa5ff3fe608060405234801561000f575f80fd5b5060043610610091575f3560e01c80638da5cb5b116100645780638da5cb5b146101195780639a11143214610137578063c45a015514610153578063d5c6b50414610171578063f2fde38b146101a157610091565b806301ffc9a7146100955780630d4f1f9d146100c557806331a503f0146100e15780638cc7104f146100fd575b5f80fd5b6100af60048036038101906100aa91906118d6565b6101bd565b6040516100bc919061191b565b60405180910390f35b6100df60048036038101906100da919061199b565b610226565b005b6100fb60048036038101906100f691906119d9565b6102a7565b005b61011760048036038101906101129190611a91565b610321565b005b610121610569565b60405161012e9190611af0565b60405180910390f35b610151600480360381019061014c9190611c45565b61058c565b005b61015b6109a5565b6040516101689190611d4f565b60405180910390f35b61018b60048036038101906101869190611d68565b6109c9565b6040516101989190611af0565b60405180910390f35b6101bb60048036038101906101b69190611d68565b6109f9565b005b5f7f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b3073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610294576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161028b90611e13565b60405180910390fd5b806102a3576102a282610b41565b5b5050565b3073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610315576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161030c90611e13565b60405180910390fd5b61031e81610b41565b50565b5f60015f8573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690505f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16036103ef576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103e690611e7b565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff166379cc679033846040518363ffffffff1660e01b815260040161042a929190611ea8565b6020604051808303815f875af1158015610446573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061046a9190611ee3565b505f6104e48360068773ffffffffffffffffffffffffffffffffffffffff1663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156104bb573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906104df9190611f44565b610e6f565b90508473ffffffffffffffffffffffffffffffffffffffff1663a9059cbb85836040518363ffffffff1660e01b8152600401610521929190611ea8565b6020604051808303815f875af115801561053d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105619190611ee3565b505050505050565b5f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b61059584610f3e565b8373ffffffffffffffffffffffffffffffffffffffff166323b872dd3330856040518463ffffffff1660e01b81526004016105d293929190611f6f565b6020604051808303815f875af11580156105ee573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106129190611ee3565b505f61068c838673ffffffffffffffffffffffffffffffffffffffff1663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610661573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106859190611f44565b6006610e6f565b905060015f8673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166340c10f1930836040518363ffffffff1660e01b8152600401610725929190611ea8565b5f604051808303815f87803b15801561073c575f80fd5b505af115801561074e573d5f803e3d5ffd5b5050505060015f60148282829054906101000a900467ffffffffffffffff166107779190611fd1565b92506101000a81548167ffffffffffffffff021916908367ffffffffffffffff16021790555060405180606001604052803373ffffffffffffffffffffffffffffffffffffffff1681526020018673ffffffffffffffffffffffffffffffffffffffff1681526020018281525060025f8060149054906101000a900467ffffffffffffffff1667ffffffffffffffff1667ffffffffffffffff1681526020019081526020015f205f820151815f015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506020820151816001015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550604082015181600201559050505f61091f8760015f8973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff16848689611278565b905060f173ffffffffffffffffffffffffffffffffffffffff1663d46f64e6826040518263ffffffff1660e01b815260040161095b919061205c565b6020604051808303815f875af1158015610977573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061099b9190611ee3565b5050505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6001602052805f5260405f205f915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b5f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610a4f575f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610a86575f80fd5b8073ffffffffffffffffffffffffffffffffffffffff165f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3805f806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b5f60025f8367ffffffffffffffff1667ffffffffffffffff1681526020019081526020015f206040518060600160405290815f82015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001600182015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200160028201548152505090505f60015f836020015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690505f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610cf9576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610cf090611e7b565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff166342966c6883604001516040518263ffffffff1660e01b8152600401610d36919061207c565b5f604051808303815f87803b158015610d4d575f80fd5b505af1158015610d5f573d5f803e3d5ffd5b505050505f610de483604001516006856020015173ffffffffffffffffffffffffffffffffffffffff1663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610dbb573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ddf9190611f44565b610e6f565b9050826020015173ffffffffffffffffffffffffffffffffffffffff1663a9059cbb845f0151836040518363ffffffff1660e01b8152600401610e28929190611ea8565b6020604051808303815f875af1158015610e44573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e689190611ee3565b5050505050565b5f8160ff168360ff161115610eb0575f8284610e8b9190612095565b60ff16600a610e9a91906121f8565b90508085610ea8919061226f565b915050610ef5565b8160ff168360ff161015610ef0575f8383610ecb9190612095565b60ff16600a610eda91906121f8565b90508085610ee8919061229f565b915050610ef4565b8390505b5b5f8103610f37576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f2e9061232a565b60405180910390fd5b9392505050565b5f73ffffffffffffffffffffffffffffffffffffffff1660015f8373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1603611275575f7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff166306ef1a866040518060400160405280600781526020017f57726170706564000000000000000000000000000000000000000000000000008152508473ffffffffffffffffffffffffffffffffffffffff166306fdde036040518163ffffffff1660e01b81526004015f60405180830381865afa158015611088573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f820116820180604052508101906110b091906123b6565b6040516020016110c1929190612437565b6040516020818303038152906040526040518060400160405280600181526020017f57000000000000000000000000000000000000000000000000000000000000008152508573ffffffffffffffffffffffffffffffffffffffff166395d89b416040518163ffffffff1660e01b81526004015f60405180830381865afa15801561114e573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061117691906123b6565b604051602001611187929190612437565b60405160208183030381529060405260066040518463ffffffff1660e01b81526004016111b693929190612469565b6020604051808303815f875af11580156111d2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111f691906124c0565b90508060015f8473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550505b50565b60608560f173ffffffffffffffffffffffffffffffffffffffff166381cf0f6a876040518263ffffffff1660e01b81526004016112b59190611af0565b5f604051808303815f875af11580156112d0573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f820116820180604052508101906112f891906123b6565b611301866113ea565b60f173ffffffffffffffffffffffffffffffffffffffff16636af32a55306040518263ffffffff1660e01b815260040161133b9190611af0565b5f604051808303815f875af1158015611356573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061137e91906123b6565b85611388886113ea565b6113b05f60149054906101000a900467ffffffffffffffff1667ffffffffffffffff166113ea565b6113b9306114b4565b6040516020016113d098979695949392919061298f565b604051602081830303815290604052905095945050505050565b60605f60016113f8846114e1565b0190505f8167ffffffffffffffff81111561141657611415611b21565b5b6040519080825280601f01601f1916602001820160405280156114485781602001600182028036833780820191505090505b5090505f82602001820190505b6001156114a9578080600190039150507f3031323334353637383961626364656600000000000000000000000000000000600a86061a8153600a858161149e5761149d612242565b5b0494505f8503611455575b819350505050919050565b60606114da8273ffffffffffffffffffffffffffffffffffffffff16601460ff16611632565b9050919050565b5f805f90507a184f03e93ff9f4daa797ed6e38ed64bf6a1f010000000000000000831061153d577a184f03e93ff9f4daa797ed6e38ed64bf6a1f010000000000000000838161153357611532612242565b5b0492506040810190505b6d04ee2d6d415b85acef8100000000831061157a576d04ee2d6d415b85acef810000000083816115705761156f612242565b5b0492506020810190505b662386f26fc1000083106115a957662386f26fc10000838161159f5761159e612242565b5b0492506010810190505b6305f5e10083106115d2576305f5e10083816115c8576115c7612242565b5b0492506008810190505b61271083106115f75761271083816115ed576115ec612242565b5b0492506004810190505b6064831061161a57606483816116105761160f612242565b5b0492506002810190505b600a8310611629576001810190505b80915050919050565b60605f8390505f6002846002611648919061229f565b6116529190612ac6565b67ffffffffffffffff81111561166b5761166a611b21565b5b6040519080825280601f01601f19166020018201604052801561169d5781602001600182028036833780820191505090505b5090507f3000000000000000000000000000000000000000000000000000000000000000815f815181106116d4576116d3612af9565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053507f78000000000000000000000000000000000000000000000000000000000000008160018151811061173757611736612af9565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505f6001856002611775919061229f565b61177f9190612ac6565b90505b600181111561181e577f3031323334353637383961626364656600000000000000000000000000000000600f8416601081106117c1576117c0612af9565b5b1a60f81b8282815181106117d8576117d7612af9565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a905350600483901c92508061181790612b26565b9050611782565b505f82146118655784846040517fe22e27eb00000000000000000000000000000000000000000000000000000000815260040161185c929190612b4d565b60405180910390fd5b809250505092915050565b5f604051905090565b5f80fd5b5f80fd5b5f7fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b6118b581611881565b81146118bf575f80fd5b50565b5f813590506118d0816118ac565b92915050565b5f602082840312156118eb576118ea611879565b5b5f6118f8848285016118c2565b91505092915050565b5f8115159050919050565b61191581611901565b82525050565b5f60208201905061192e5f83018461190c565b92915050565b5f67ffffffffffffffff82169050919050565b61195081611934565b811461195a575f80fd5b50565b5f8135905061196b81611947565b92915050565b61197a81611901565b8114611984575f80fd5b50565b5f8135905061199581611971565b92915050565b5f80604083850312156119b1576119b0611879565b5b5f6119be8582860161195d565b92505060206119cf85828601611987565b9150509250929050565b5f602082840312156119ee576119ed611879565b5b5f6119fb8482850161195d565b91505092915050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f611a2d82611a04565b9050919050565b611a3d81611a23565b8114611a47575f80fd5b50565b5f81359050611a5881611a34565b92915050565b5f819050919050565b611a7081611a5e565b8114611a7a575f80fd5b50565b5f81359050611a8b81611a67565b92915050565b5f805f60608486031215611aa857611aa7611879565b5b5f611ab586828701611a4a565b9350506020611ac686828701611a4a565b9250506040611ad786828701611a7d565b9150509250925092565b611aea81611a23565b82525050565b5f602082019050611b035f830184611ae1565b92915050565b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b611b5782611b11565b810181811067ffffffffffffffff82111715611b7657611b75611b21565b5b80604052505050565b5f611b88611870565b9050611b948282611b4e565b919050565b5f67ffffffffffffffff821115611bb357611bb2611b21565b5b611bbc82611b11565b9050602081019050919050565b828183375f83830152505050565b5f611be9611be484611b99565b611b7f565b905082815260208101848484011115611c0557611c04611b0d565b5b611c10848285611bc9565b509392505050565b5f82601f830112611c2c57611c2b611b09565b5b8135611c3c848260208601611bd7565b91505092915050565b5f805f805f60a08688031215611c5e57611c5d611879565b5b5f86013567ffffffffffffffff811115611c7b57611c7a61187d565b5b611c8788828901611c18565b9550506020611c9888828901611a4a565b945050604086013567ffffffffffffffff811115611cb957611cb861187d565b5b611cc588828901611c18565b9350506060611cd688828901611a7d565b9250506080611ce788828901611a7d565b9150509295509295909350565b5f819050919050565b5f611d17611d12611d0d84611a04565b611cf4565b611a04565b9050919050565b5f611d2882611cfd565b9050919050565b5f611d3982611d1e565b9050919050565b611d4981611d2f565b82525050565b5f602082019050611d625f830184611d40565b92915050565b5f60208284031215611d7d57611d7c611879565b5b5f611d8a84828501611a4a565b91505092915050565b5f82825260208201905092915050565b7f6f6e6c792074686520636f6e747261637420697473656c662063616e2063616c5f8201527f6c20746869732066756e6374696f6e0000000000000000000000000000000000602082015250565b5f611dfd602f83611d93565b9150611e0882611da3565b604082019050919050565b5f6020820190508181035f830152611e2a81611df1565b9050919050565b7f7772617070656420746f6b656e20646f65736e277420657869737400000000005f82015250565b5f611e65601b83611d93565b9150611e7082611e31565b602082019050919050565b5f6020820190508181035f830152611e9281611e59565b9050919050565b611ea281611a5e565b82525050565b5f604082019050611ebb5f830185611ae1565b611ec86020830184611e99565b9392505050565b5f81519050611edd81611971565b92915050565b5f60208284031215611ef857611ef7611879565b5b5f611f0584828501611ecf565b91505092915050565b5f60ff82169050919050565b611f2381611f0e565b8114611f2d575f80fd5b50565b5f81519050611f3e81611f1a565b92915050565b5f60208284031215611f5957611f58611879565b5b5f611f6684828501611f30565b91505092915050565b5f606082019050611f825f830186611ae1565b611f8f6020830185611ae1565b611f9c6040830184611e99565b949350505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f611fdb82611934565b9150611fe683611934565b9250828201905067ffffffffffffffff81111561200657612005611fa4565b5b92915050565b5f81519050919050565b8281835e5f83830152505050565b5f61202e8261200c565b6120388185611d93565b9350612048818560208601612016565b61205181611b11565b840191505092915050565b5f6020820190508181035f8301526120748184612024565b905092915050565b5f60208201905061208f5f830184611e99565b92915050565b5f61209f82611f0e565b91506120aa83611f0e565b9250828203905060ff8111156120c3576120c2611fa4565b5b92915050565b5f8160011c9050919050565b5f808291508390505b600185111561211e578086048111156120fa576120f9611fa4565b5b60018516156121095780820291505b8081029050612117856120c9565b94506120de565b94509492505050565b5f8261213657600190506121f1565b81612143575f90506121f1565b8160018114612159576002811461216357612192565b60019150506121f1565b60ff84111561217557612174611fa4565b5b8360020a91508482111561218c5761218b611fa4565b5b506121f1565b5060208310610133831016604e8410600b84101617156121c75782820a9050838111156121c2576121c1611fa4565b5b6121f1565b6121d484848460016120d5565b925090508184048111156121eb576121ea611fa4565b5b81810290505b9392505050565b5f61220282611a5e565b915061220d83611a5e565b925061223a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8484612127565b905092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f61227982611a5e565b915061228483611a5e565b92508261229457612293612242565b5b828204905092915050565b5f6122a982611a5e565b91506122b483611a5e565b92508282026122c281611a5e565b915082820484148315176122d9576122d8611fa4565b5b5092915050565b7f636f6e76657274656420616d6f756e74206973207a65726f00000000000000005f82015250565b5f612314601883611d93565b915061231f826122e0565b602082019050919050565b5f6020820190508181035f83015261234181612308565b9050919050565b5f61235a61235584611b99565b611b7f565b90508281526020810184848401111561237657612375611b0d565b5b612381848285612016565b509392505050565b5f82601f83011261239d5761239c611b09565b5b81516123ad848260208601612348565b91505092915050565b5f602082840312156123cb576123ca611879565b5b5f82015167ffffffffffffffff8111156123e8576123e761187d565b5b6123f484828501612389565b91505092915050565b5f81905092915050565b5f6124118261200c565b61241b81856123fd565b935061242b818560208601612016565b80840191505092915050565b5f6124428285612407565b915061244e8284612407565b91508190509392505050565b61246381611f0e565b82525050565b5f6060820190508181035f8301526124818186612024565b905081810360208301526124958185612024565b90506124a4604083018461245a565b949350505050565b5f815190506124ba81611a34565b92915050565b5f602082840312156124d5576124d4611879565b5b5f6124e2848285016124ac565b91505092915050565b7f7b224074797065223a20222f6962632e6170706c69636174696f6e732e7472615f8201527f6e736665722e76312e4d73675472616e73666572222c00000000000000000000602082015250565b5f6125456036836123fd565b9150612550826124eb565b603682019050919050565b7f22736f757263655f706f7274223a20227472616e73666572222c0000000000005f82015250565b5f61258f601a836123fd565b915061259a8261255b565b601a82019050919050565b7f22736f757263655f6368616e6e656c223a2022000000000000000000000000005f82015250565b5f6125d96013836123fd565b91506125e4826125a5565b601382019050919050565b7f222c0000000000000000000000000000000000000000000000000000000000005f82015250565b5f6126236002836123fd565b915061262e826125ef565b600282019050919050565b7f22746f6b656e223a207b202264656e6f6d223a202200000000000000000000005f82015250565b5f61266d6015836123fd565b915061267882612639565b601582019050919050565b7f22616d6f756e74223a20220000000000000000000000000000000000000000005f82015250565b5f6126b7600b836123fd565b91506126c282612683565b600b82019050919050565b7f227d2c00000000000000000000000000000000000000000000000000000000005f82015250565b5f6127016003836123fd565b915061270c826126cd565b600382019050919050565b7f2273656e646572223a20220000000000000000000000000000000000000000005f82015250565b5f61274b600b836123fd565b915061275682612717565b600b82019050919050565b7f227265636569766572223a2022000000000000000000000000000000000000005f82015250565b5f612795600d836123fd565b91506127a082612761565b600d82019050919050565b7f2274696d656f75745f686569676874223a207b227265766973696f6e5f6e756d5f8201527f626572223a202230222c227265766973696f6e5f686569676874223a2022302260208201527f7d2c000000000000000000000000000000000000000000000000000000000000604082015250565b5f61282b6042836123fd565b9150612836826127ab565b604282019050919050565b7f2274696d656f75745f74696d657374616d70223a2022000000000000000000005f82015250565b5f6128756016836123fd565b915061288082612841565b601682019050919050565b7f226d656d6f223a20227b5c2265766d5c223a207b5c226173796e635f63616c6c5f8201527f6261636b5c223a207b5c2269645c223a20000000000000000000000000000000602082015250565b5f6128e56031836123fd565b91506128f08261288b565b603182019050919050565b7f2c5c22636f6e74726163745f616464726573735c223a5c2200000000000000005f82015250565b5f61292f6018836123fd565b915061293a826128fb565b601882019050919050565b7f5c227d7d7d227d000000000000000000000000000000000000000000000000005f82015250565b5f6129796007836123fd565b915061298482612945565b600782019050919050565b5f61299982612539565b91506129a482612583565b91506129af826125cd565b91506129bb828b612407565b91506129c682612617565b91506129d182612661565b91506129dd828a612407565b91506129e882612617565b91506129f3826126ab565b91506129ff8289612407565b9150612a0a826126f5565b9150612a158261273f565b9150612a218288612407565b9150612a2c82612617565b9150612a3782612789565b9150612a438287612407565b9150612a4e82612617565b9150612a598261281f565b9150612a6482612869565b9150612a708286612407565b9150612a7b82612617565b9150612a86826128d9565b9150612a928285612407565b9150612a9d82612923565b9150612aa98284612407565b9150612ab48261296d565b91508190509998505050505050505050565b5f612ad082611a5e565b9150612adb83611a5e565b9250828201905080821115612af357612af2611fa4565b5b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f612b3082611a5e565b91505f8203612b4257612b41611fa4565b5b600182039050919050565b5f604082019050612b605f830185611e99565b612b6d6020830184611e99565b939250505056fea2646970667358221220d95a9dd66d4432f3d2051948acfdc88475473bfacb638290d7dadca8c3cbe87364736f6c63430008190033", + ABI: "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"erc20Factory\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"length\",\"type\":\"uint256\"}],\"name\":\"StringsInsufficientHexLength\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"factory\",\"outputs\":[{\"internalType\":\"contractERC20Factory\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"callback_id\",\"type\":\"uint64\"},{\"internalType\":\"bool\",\"name\":\"success\",\"type\":\"bool\"}],\"name\":\"ibc_ack\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"callback_id\",\"type\":\"uint64\"}],\"name\":\"ibc_timeout\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newFactory\",\"type\":\"address\"}],\"name\":\"setFactory\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"originToken\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"receiver\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"wrappedAmt\",\"type\":\"uint256\"}],\"name\":\"unwrap\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"channel\",\"type\":\"string\"},{\"internalType\":\"address\",\"name\":\"token\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"receiver\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"timeout\",\"type\":\"uint256\"}],\"name\":\"wrap\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"wrappedTokens\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]", + Bin: "0x60806040525f8060146101000a81548167ffffffffffffffff021916908367ffffffffffffffff160217905550348015610037575f80fd5b50604051612f37380380612f378339818101604052810190610059919061013c565b335f806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508060015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050610167565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61010b826100e2565b9050919050565b61011b81610101565b8114610125575f80fd5b50565b5f8151905061013681610112565b92915050565b5f60208284031215610151576101506100de565b5b5f61015e84828501610128565b91505092915050565b612dc3806101745f395ff3fe608060405234801561000f575f80fd5b506004361061009c575f3560e01c80638da5cb5b116100645780638da5cb5b146101405780639a1114321461015e578063c45a01551461017a578063d5c6b50414610198578063f2fde38b146101c85761009c565b806301ffc9a7146100a05780630d4f1f9d146100d057806331a503f0146100ec5780635bb47808146101085780638cc7104f14610124575b5f80fd5b6100ba60048036038101906100b59190611a1f565b6101e4565b6040516100c79190611a64565b60405180910390f35b6100ea60048036038101906100e59190611ae4565b61024d565b005b61010660048036038101906101019190611b22565b6102ce565b005b610122600480360381019061011d9190611ba7565b610348565b005b61013e60048036038101906101399190611c05565b610468565b005b6101486106b0565b6040516101559190611c64565b60405180910390f35b61017860048036038101906101739190611db9565b6106d3565b005b610182610aec565b60405161018f9190611ec3565b60405180910390f35b6101b260048036038101906101ad9190611ba7565b610b11565b6040516101bf9190611c64565b60405180910390f35b6101e260048036038101906101dd9190611ba7565b610b41565b005b5f7f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b3073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146102bb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102b290611f5c565b60405180910390fd5b806102ca576102c982610c89565b5b5050565b3073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461033c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161033390611f5c565b60405180910390fd5b61034581610c89565b50565b600173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146103b7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103ae90611fc4565b60405180910390fd5b5f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610425576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161041c9061202c565b60405180910390fd5b8060015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b5f60025f8573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690505f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610536576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161052d90612094565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff166379cc679033846040518363ffffffff1660e01b81526004016105719291906120c1565b6020604051808303815f875af115801561058d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105b191906120fc565b505f61062b8360068773ffffffffffffffffffffffffffffffffffffffff1663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610602573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610626919061215d565b610fb7565b90508473ffffffffffffffffffffffffffffffffffffffff1663a9059cbb85836040518363ffffffff1660e01b81526004016106689291906120c1565b6020604051808303815f875af1158015610684573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106a891906120fc565b505050505050565b5f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6106dc84611086565b8373ffffffffffffffffffffffffffffffffffffffff166323b872dd3330856040518463ffffffff1660e01b815260040161071993929190612188565b6020604051808303815f875af1158015610735573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061075991906120fc565b505f6107d3838673ffffffffffffffffffffffffffffffffffffffff1663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156107a8573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107cc919061215d565b6006610fb7565b905060025f8673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166340c10f1930836040518363ffffffff1660e01b815260040161086c9291906120c1565b5f604051808303815f87803b158015610883575f80fd5b505af1158015610895573d5f803e3d5ffd5b5050505060015f60148282829054906101000a900467ffffffffffffffff166108be91906121ea565b92506101000a81548167ffffffffffffffff021916908367ffffffffffffffff16021790555060405180606001604052803373ffffffffffffffffffffffffffffffffffffffff1681526020018673ffffffffffffffffffffffffffffffffffffffff1681526020018281525060035f8060149054906101000a900467ffffffffffffffff1667ffffffffffffffff1667ffffffffffffffff1681526020019081526020015f205f820151815f015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506020820151816001015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550604082015181600201559050505f610a668760025f8973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff168486896113c1565b905060f173ffffffffffffffffffffffffffffffffffffffff1663d46f64e6826040518263ffffffff1660e01b8152600401610aa29190612275565b6020604051808303815f875af1158015610abe573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ae291906120fc565b5050505050505050565b60015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6002602052805f5260405f205f915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b5f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610b97575f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610bce575f80fd5b8073ffffffffffffffffffffffffffffffffffffffff165f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3805f806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b5f60035f8367ffffffffffffffff1667ffffffffffffffff1681526020019081526020015f206040518060600160405290815f82015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001600182015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200160028201548152505090505f60025f836020015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690505f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610e41576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e3890612094565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff166342966c6883604001516040518263ffffffff1660e01b8152600401610e7e9190612295565b5f604051808303815f87803b158015610e95575f80fd5b505af1158015610ea7573d5f803e3d5ffd5b505050505f610f2c83604001516006856020015173ffffffffffffffffffffffffffffffffffffffff1663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f03573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f27919061215d565b610fb7565b9050826020015173ffffffffffffffffffffffffffffffffffffffff1663a9059cbb845f0151836040518363ffffffff1660e01b8152600401610f709291906120c1565b6020604051808303815f875af1158015610f8c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610fb091906120fc565b5050505050565b5f8160ff168360ff161115610ff8575f8284610fd391906122ae565b60ff16600a610fe29190612411565b90508085610ff09190612488565b91505061103d565b8160ff168360ff161015611038575f838361101391906122ae565b60ff16600a6110229190612411565b9050808561103091906124b8565b91505061103c565b8390505b5b5f810361107f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161107690612543565b60405180910390fd5b9392505050565b5f73ffffffffffffffffffffffffffffffffffffffff1660025f8373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16036113be575f60015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166306ef1a866040518060400160405280600781526020017f57726170706564000000000000000000000000000000000000000000000000008152508473ffffffffffffffffffffffffffffffffffffffff166306fdde036040518163ffffffff1660e01b81526004015f60405180830381865afa1580156111d1573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f820116820180604052508101906111f991906125cf565b60405160200161120a929190612650565b6040516020818303038152906040526040518060400160405280600181526020017f57000000000000000000000000000000000000000000000000000000000000008152508573ffffffffffffffffffffffffffffffffffffffff166395d89b416040518163ffffffff1660e01b81526004015f60405180830381865afa158015611297573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f820116820180604052508101906112bf91906125cf565b6040516020016112d0929190612650565b60405160208183030381529060405260066040518463ffffffff1660e01b81526004016112ff93929190612682565b6020604051808303815f875af115801561131b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061133f91906126d9565b90508060025f8473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550505b50565b60608560f173ffffffffffffffffffffffffffffffffffffffff166381cf0f6a876040518263ffffffff1660e01b81526004016113fe9190611c64565b5f604051808303815f875af1158015611419573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061144191906125cf565b61144a86611533565b60f173ffffffffffffffffffffffffffffffffffffffff16636af32a55306040518263ffffffff1660e01b81526004016114849190611c64565b5f604051808303815f875af115801561149f573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f820116820180604052508101906114c791906125cf565b856114d188611533565b6114f95f60149054906101000a900467ffffffffffffffff1667ffffffffffffffff16611533565b611502306115fd565b604051602001611519989796959493929190612ba8565b604051602081830303815290604052905095945050505050565b60605f60016115418461162a565b0190505f8167ffffffffffffffff81111561155f5761155e611c95565b5b6040519080825280601f01601f1916602001820160405280156115915781602001600182028036833780820191505090505b5090505f82602001820190505b6001156115f2578080600190039150507f3031323334353637383961626364656600000000000000000000000000000000600a86061a8153600a85816115e7576115e661245b565b5b0494505f850361159e575b819350505050919050565b60606116238273ffffffffffffffffffffffffffffffffffffffff16601460ff1661177b565b9050919050565b5f805f90507a184f03e93ff9f4daa797ed6e38ed64bf6a1f0100000000000000008310611686577a184f03e93ff9f4daa797ed6e38ed64bf6a1f010000000000000000838161167c5761167b61245b565b5b0492506040810190505b6d04ee2d6d415b85acef810000000083106116c3576d04ee2d6d415b85acef810000000083816116b9576116b861245b565b5b0492506020810190505b662386f26fc1000083106116f257662386f26fc1000083816116e8576116e761245b565b5b0492506010810190505b6305f5e100831061171b576305f5e10083816117115761171061245b565b5b0492506008810190505b61271083106117405761271083816117365761173561245b565b5b0492506004810190505b6064831061176357606483816117595761175861245b565b5b0492506002810190505b600a8310611772576001810190505b80915050919050565b60605f8390505f600284600261179191906124b8565b61179b9190612cdf565b67ffffffffffffffff8111156117b4576117b3611c95565b5b6040519080825280601f01601f1916602001820160405280156117e65781602001600182028036833780820191505090505b5090507f3000000000000000000000000000000000000000000000000000000000000000815f8151811061181d5761181c612d12565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053507f7800000000000000000000000000000000000000000000000000000000000000816001815181106118805761187f612d12565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505f60018560026118be91906124b8565b6118c89190612cdf565b90505b6001811115611967577f3031323334353637383961626364656600000000000000000000000000000000600f84166010811061190a57611909612d12565b5b1a60f81b82828151811061192157611920612d12565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a905350600483901c92508061196090612d3f565b90506118cb565b505f82146119ae5784846040517fe22e27eb0000000000000000000000000000000000000000000000000000000081526004016119a5929190612d66565b60405180910390fd5b809250505092915050565b5f604051905090565b5f80fd5b5f80fd5b5f7fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b6119fe816119ca565b8114611a08575f80fd5b50565b5f81359050611a19816119f5565b92915050565b5f60208284031215611a3457611a336119c2565b5b5f611a4184828501611a0b565b91505092915050565b5f8115159050919050565b611a5e81611a4a565b82525050565b5f602082019050611a775f830184611a55565b92915050565b5f67ffffffffffffffff82169050919050565b611a9981611a7d565b8114611aa3575f80fd5b50565b5f81359050611ab481611a90565b92915050565b611ac381611a4a565b8114611acd575f80fd5b50565b5f81359050611ade81611aba565b92915050565b5f8060408385031215611afa57611af96119c2565b5b5f611b0785828601611aa6565b9250506020611b1885828601611ad0565b9150509250929050565b5f60208284031215611b3757611b366119c2565b5b5f611b4484828501611aa6565b91505092915050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f611b7682611b4d565b9050919050565b611b8681611b6c565b8114611b90575f80fd5b50565b5f81359050611ba181611b7d565b92915050565b5f60208284031215611bbc57611bbb6119c2565b5b5f611bc984828501611b93565b91505092915050565b5f819050919050565b611be481611bd2565b8114611bee575f80fd5b50565b5f81359050611bff81611bdb565b92915050565b5f805f60608486031215611c1c57611c1b6119c2565b5b5f611c2986828701611b93565b9350506020611c3a86828701611b93565b9250506040611c4b86828701611bf1565b9150509250925092565b611c5e81611b6c565b82525050565b5f602082019050611c775f830184611c55565b92915050565b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b611ccb82611c85565b810181811067ffffffffffffffff82111715611cea57611ce9611c95565b5b80604052505050565b5f611cfc6119b9565b9050611d088282611cc2565b919050565b5f67ffffffffffffffff821115611d2757611d26611c95565b5b611d3082611c85565b9050602081019050919050565b828183375f83830152505050565b5f611d5d611d5884611d0d565b611cf3565b905082815260208101848484011115611d7957611d78611c81565b5b611d84848285611d3d565b509392505050565b5f82601f830112611da057611d9f611c7d565b5b8135611db0848260208601611d4b565b91505092915050565b5f805f805f60a08688031215611dd257611dd16119c2565b5b5f86013567ffffffffffffffff811115611def57611dee6119c6565b5b611dfb88828901611d8c565b9550506020611e0c88828901611b93565b945050604086013567ffffffffffffffff811115611e2d57611e2c6119c6565b5b611e3988828901611d8c565b9350506060611e4a88828901611bf1565b9250506080611e5b88828901611bf1565b9150509295509295909350565b5f819050919050565b5f611e8b611e86611e8184611b4d565b611e68565b611b4d565b9050919050565b5f611e9c82611e71565b9050919050565b5f611ead82611e92565b9050919050565b611ebd81611ea3565b82525050565b5f602082019050611ed65f830184611eb4565b92915050565b5f82825260208201905092915050565b7f6f6e6c792074686520636f6e747261637420697473656c662063616e2063616c5f8201527f6c20746869732066756e6374696f6e0000000000000000000000000000000000602082015250565b5f611f46602f83611edc565b9150611f5182611eec565b604082019050919050565b5f6020820190508181035f830152611f7381611f3a565b9050919050565b7f45524332303a2063616c6c6572206973206e6f742074686520636861696e00005f82015250565b5f611fae601e83611edc565b9150611fb982611f7a565b602082019050919050565b5f6020820190508181035f830152611fdb81611fa2565b9050919050565b7f696e76616c696420666163746f727920616464726573730000000000000000005f82015250565b5f612016601783611edc565b915061202182611fe2565b602082019050919050565b5f6020820190508181035f8301526120438161200a565b9050919050565b7f7772617070656420746f6b656e20646f65736e277420657869737400000000005f82015250565b5f61207e601b83611edc565b91506120898261204a565b602082019050919050565b5f6020820190508181035f8301526120ab81612072565b9050919050565b6120bb81611bd2565b82525050565b5f6040820190506120d45f830185611c55565b6120e160208301846120b2565b9392505050565b5f815190506120f681611aba565b92915050565b5f60208284031215612111576121106119c2565b5b5f61211e848285016120e8565b91505092915050565b5f60ff82169050919050565b61213c81612127565b8114612146575f80fd5b50565b5f8151905061215781612133565b92915050565b5f60208284031215612172576121716119c2565b5b5f61217f84828501612149565b91505092915050565b5f60608201905061219b5f830186611c55565b6121a86020830185611c55565b6121b560408301846120b2565b949350505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f6121f482611a7d565b91506121ff83611a7d565b9250828201905067ffffffffffffffff81111561221f5761221e6121bd565b5b92915050565b5f81519050919050565b8281835e5f83830152505050565b5f61224782612225565b6122518185611edc565b935061226181856020860161222f565b61226a81611c85565b840191505092915050565b5f6020820190508181035f83015261228d818461223d565b905092915050565b5f6020820190506122a85f8301846120b2565b92915050565b5f6122b882612127565b91506122c383612127565b9250828203905060ff8111156122dc576122db6121bd565b5b92915050565b5f8160011c9050919050565b5f808291508390505b600185111561233757808604811115612313576123126121bd565b5b60018516156123225780820291505b8081029050612330856122e2565b94506122f7565b94509492505050565b5f8261234f576001905061240a565b8161235c575f905061240a565b8160018114612372576002811461237c576123ab565b600191505061240a565b60ff84111561238e5761238d6121bd565b5b8360020a9150848211156123a5576123a46121bd565b5b5061240a565b5060208310610133831016604e8410600b84101617156123e05782820a9050838111156123db576123da6121bd565b5b61240a565b6123ed84848460016122ee565b92509050818404811115612404576124036121bd565b5b81810290505b9392505050565b5f61241b82611bd2565b915061242683611bd2565b92506124537fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8484612340565b905092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f61249282611bd2565b915061249d83611bd2565b9250826124ad576124ac61245b565b5b828204905092915050565b5f6124c282611bd2565b91506124cd83611bd2565b92508282026124db81611bd2565b915082820484148315176124f2576124f16121bd565b5b5092915050565b7f636f6e76657274656420616d6f756e74206973207a65726f00000000000000005f82015250565b5f61252d601883611edc565b9150612538826124f9565b602082019050919050565b5f6020820190508181035f83015261255a81612521565b9050919050565b5f61257361256e84611d0d565b611cf3565b90508281526020810184848401111561258f5761258e611c81565b5b61259a84828561222f565b509392505050565b5f82601f8301126125b6576125b5611c7d565b5b81516125c6848260208601612561565b91505092915050565b5f602082840312156125e4576125e36119c2565b5b5f82015167ffffffffffffffff811115612601576126006119c6565b5b61260d848285016125a2565b91505092915050565b5f81905092915050565b5f61262a82612225565b6126348185612616565b935061264481856020860161222f565b80840191505092915050565b5f61265b8285612620565b91506126678284612620565b91508190509392505050565b61267c81612127565b82525050565b5f6060820190508181035f83015261269a818661223d565b905081810360208301526126ae818561223d565b90506126bd6040830184612673565b949350505050565b5f815190506126d381611b7d565b92915050565b5f602082840312156126ee576126ed6119c2565b5b5f6126fb848285016126c5565b91505092915050565b7f7b224074797065223a20222f6962632e6170706c69636174696f6e732e7472615f8201527f6e736665722e76312e4d73675472616e73666572222c00000000000000000000602082015250565b5f61275e603683612616565b915061276982612704565b603682019050919050565b7f22736f757263655f706f7274223a20227472616e73666572222c0000000000005f82015250565b5f6127a8601a83612616565b91506127b382612774565b601a82019050919050565b7f22736f757263655f6368616e6e656c223a2022000000000000000000000000005f82015250565b5f6127f2601383612616565b91506127fd826127be565b601382019050919050565b7f222c0000000000000000000000000000000000000000000000000000000000005f82015250565b5f61283c600283612616565b915061284782612808565b600282019050919050565b7f22746f6b656e223a207b202264656e6f6d223a202200000000000000000000005f82015250565b5f612886601583612616565b915061289182612852565b601582019050919050565b7f22616d6f756e74223a20220000000000000000000000000000000000000000005f82015250565b5f6128d0600b83612616565b91506128db8261289c565b600b82019050919050565b7f227d2c00000000000000000000000000000000000000000000000000000000005f82015250565b5f61291a600383612616565b9150612925826128e6565b600382019050919050565b7f2273656e646572223a20220000000000000000000000000000000000000000005f82015250565b5f612964600b83612616565b915061296f82612930565b600b82019050919050565b7f227265636569766572223a2022000000000000000000000000000000000000005f82015250565b5f6129ae600d83612616565b91506129b98261297a565b600d82019050919050565b7f2274696d656f75745f686569676874223a207b227265766973696f6e5f6e756d5f8201527f626572223a202230222c227265766973696f6e5f686569676874223a2022302260208201527f7d2c000000000000000000000000000000000000000000000000000000000000604082015250565b5f612a44604283612616565b9150612a4f826129c4565b604282019050919050565b7f2274696d656f75745f74696d657374616d70223a2022000000000000000000005f82015250565b5f612a8e601683612616565b9150612a9982612a5a565b601682019050919050565b7f226d656d6f223a20227b5c2265766d5c223a207b5c226173796e635f63616c6c5f8201527f6261636b5c223a207b5c2269645c223a20000000000000000000000000000000602082015250565b5f612afe603183612616565b9150612b0982612aa4565b603182019050919050565b7f2c5c22636f6e74726163745f616464726573735c223a5c2200000000000000005f82015250565b5f612b48601883612616565b9150612b5382612b14565b601882019050919050565b7f5c227d7d7d227d000000000000000000000000000000000000000000000000005f82015250565b5f612b92600783612616565b9150612b9d82612b5e565b600782019050919050565b5f612bb282612752565b9150612bbd8261279c565b9150612bc8826127e6565b9150612bd4828b612620565b9150612bdf82612830565b9150612bea8261287a565b9150612bf6828a612620565b9150612c0182612830565b9150612c0c826128c4565b9150612c188289612620565b9150612c238261290e565b9150612c2e82612958565b9150612c3a8288612620565b9150612c4582612830565b9150612c50826129a2565b9150612c5c8287612620565b9150612c6782612830565b9150612c7282612a38565b9150612c7d82612a82565b9150612c898286612620565b9150612c9482612830565b9150612c9f82612af2565b9150612cab8285612620565b9150612cb682612b3c565b9150612cc28284612620565b9150612ccd82612b86565b91508190509998505050505050505050565b5f612ce982611bd2565b9150612cf483611bd2565b9250828201905080821115612d0c57612d0b6121bd565b5b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f612d4982611bd2565b91505f8203612d5b57612d5a6121bd565b5b600182039050919050565b5f604082019050612d795f8301856120b2565b612d8660208301846120b2565b939250505056fea2646970667358221220c92aa6411413595f1f3adde815cbd463b8b06039ef1ceb6acaaca4dc03ebf49264736f6c63430008190033", } // Erc20WrapperABI is the input ABI used to generate the binding from. @@ -368,6 +368,27 @@ func (_Erc20Wrapper *Erc20WrapperTransactorSession) IbcTimeout(callback_id uint6 return _Erc20Wrapper.Contract.IbcTimeout(&_Erc20Wrapper.TransactOpts, callback_id) } +// SetFactory is a paid mutator transaction binding the contract method 0x5bb47808. +// +// Solidity: function setFactory(address newFactory) returns() +func (_Erc20Wrapper *Erc20WrapperTransactor) SetFactory(opts *bind.TransactOpts, newFactory common.Address) (*types.Transaction, error) { + return _Erc20Wrapper.contract.Transact(opts, "setFactory", newFactory) +} + +// SetFactory is a paid mutator transaction binding the contract method 0x5bb47808. +// +// Solidity: function setFactory(address newFactory) returns() +func (_Erc20Wrapper *Erc20WrapperSession) SetFactory(newFactory common.Address) (*types.Transaction, error) { + return _Erc20Wrapper.Contract.SetFactory(&_Erc20Wrapper.TransactOpts, newFactory) +} + +// SetFactory is a paid mutator transaction binding the contract method 0x5bb47808. +// +// Solidity: function setFactory(address newFactory) returns() +func (_Erc20Wrapper *Erc20WrapperTransactorSession) SetFactory(newFactory common.Address) (*types.Transaction, error) { + return _Erc20Wrapper.Contract.SetFactory(&_Erc20Wrapper.TransactOpts, newFactory) +} + // TransferOwnership is a paid mutator transaction binding the contract method 0xf2fde38b. // // Solidity: function transferOwnership(address newOwner) returns() diff --git a/x/evm/contracts/erc20_wrapper/ERC20Wrapper.sol b/x/evm/contracts/erc20_wrapper/ERC20Wrapper.sol index c8cab570..e33328ce 100644 --- a/x/evm/contracts/erc20_wrapper/ERC20Wrapper.sol +++ b/x/evm/contracts/erc20_wrapper/ERC20Wrapper.sol @@ -10,7 +10,7 @@ import "../erc20_acl/ERC20ACL.sol"; import "../i_ibc_async_callback/IIBCAsyncCallback.sol"; import {ERC165, IERC165} from "../erc165/ERC165.sol"; -contract ERC20Wrapper is Ownable, ERC165, IIBCAsyncCallback { +contract ERC20Wrapper is Ownable, ERC165, IIBCAsyncCallback, ERC20ACL { struct IbcCallBack { address sender; address originToken; @@ -21,7 +21,7 @@ contract ERC20Wrapper is Ownable, ERC165, IIBCAsyncCallback { string constant NAME_PREFIX = "Wrapped"; string constant SYMBOL_PREFIX = "W"; uint64 callBackId = 0; - ERC20Factory public immutable factory; + ERC20Factory public factory; mapping(address => address) public wrappedTokens; // origin -> wrapped mapping(uint64 => IbcCallBack) private ibcCallBack; // id -> CallBackInfo @@ -29,6 +29,12 @@ contract ERC20Wrapper is Ownable, ERC165, IIBCAsyncCallback { factory = ERC20Factory(erc20Factory); } + // This function can only be called by the chain at upgrade. + function setFactory(address newFactory) external onlyChain { + require(newFactory != address(0), "invalid factory address"); + factory = ERC20Factory(newFactory); + } + modifier onlyContract() { require( msg.sender == address(this), diff --git a/x/evm/keeper/erc20.go b/x/evm/keeper/erc20.go index aeee9977..417cf76a 100644 --- a/x/evm/keeper/erc20.go +++ b/x/evm/keeper/erc20.go @@ -19,6 +19,7 @@ import ( "github.com/initia-labs/minievm/x/evm/contracts/erc20" "github.com/initia-labs/minievm/x/evm/contracts/erc20_factory" + "github.com/initia-labs/minievm/x/evm/contracts/erc20_wrapper" "github.com/initia-labs/minievm/x/evm/types" ) @@ -29,6 +30,7 @@ type ERC20Keeper struct { ERC20Bin []byte ERC20ABI *abi.ABI ERC20FactoryABI *abi.ABI + ERC20WrapperABI *abi.ABI } func NewERC20Keeper(k *Keeper) (types.IERC20Keeper, error) { @@ -42,12 +44,17 @@ func NewERC20Keeper(k *Keeper) (types.IERC20Keeper, error) { return ERC20Keeper{}, err } + wrapperABI, err := erc20_wrapper.Erc20WrapperMetaData.GetAbi() + if err != nil { + return ERC20Keeper{}, err + } + erc20Bin, err := hexutil.Decode(erc20.Erc20Bin) if err != nil { return ERC20Keeper{}, err } - return &ERC20Keeper{k, erc20Bin, erc20ABI, factoryABI}, nil + return &ERC20Keeper{k, erc20Bin, erc20ABI, factoryABI, wrapperABI}, nil } // GetERC20ABI implements IERC20Keeper. @@ -55,6 +62,16 @@ func (k ERC20Keeper) GetERC20ABI() *abi.ABI { return k.ERC20ABI } +// GetERC20FactoryABI implements IERC20Keeper. +func (K ERC20Keeper) GetERC20FactoryABI() *abi.ABI { + return K.ERC20FactoryABI +} + +// GetERC20WrapperABI implements IERC20Keeper. +func (K ERC20Keeper) GetERC20WrapperABI() *abi.ABI { + return K.ERC20WrapperABI +} + // BurnCoins implements IERC20Keeper. func (k ERC20Keeper) BurnCoins(ctx context.Context, addr sdk.AccAddress, amount sdk.Coins) error { evmAddr, err := k.convertToEVMAddress(ctx, addr, false) diff --git a/x/evm/keeper/genesis.go b/x/evm/keeper/genesis.go index ab8b7ceb..581f6b12 100644 --- a/x/evm/keeper/genesis.go +++ b/x/evm/keeper/genesis.go @@ -62,7 +62,25 @@ func (k Keeper) DeployERC20Factory(ctx context.Context) error { return err } - return k.ERC20FactoryAddr.Set(ctx, factoryAddr.Bytes()) + err = k.ERC20FactoryAddr.Set(ctx, factoryAddr.Bytes()) + if err != nil { + return err + } + + wrapperAddr, err := k.ERC20WrapperAddr.Get(ctx) + if err == nil { + inputBz, err := k.ERC20Keeper().GetERC20WrapperABI().Pack("setFactory", common.BytesToAddress(factoryAddr.Bytes())) + if err != nil { + return err + } + + _, _, err = k.EVMCall(ctx, types.StdAddress, common.BytesToAddress(wrapperAddr), inputBz, nil, nil) + if err != nil { + return err + } + } + + return nil } // DeployERC20Wrapper deploys the ERC20 wrapper contract and stores the address in the keeper. diff --git a/x/evm/keeper/genesis_test.go b/x/evm/keeper/genesis_test.go index 54f4c2b4..ad20544e 100644 --- a/x/evm/keeper/genesis_test.go +++ b/x/evm/keeper/genesis_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "testing" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" "github.com/initia-labs/minievm/x/evm/contracts/erc20_wrapper" "github.com/initia-labs/minievm/x/evm/types" @@ -103,3 +104,56 @@ func Test_Initialize(t *testing.T) { require.Equal(t, expectedFactoryAddr, factoryAddr) } + +func Test_DeployERC20Factory(t *testing.T) { + ctx, input := createTestInput(t, false, false) + + // set random factory address and check if it is set correctly + err := input.EVMKeeper.ERC20FactoryAddr.Set(ctx, common.HexToAddress("0x123").Bytes()) + require.NoError(t, err) + + // set params + input.EVMKeeper.Params.Set(ctx, types.DefaultParams()) + + factoryAddr, err := input.EVMKeeper.GetERC20FactoryAddr(ctx) + require.NoError(t, err) + + require.Equal(t, common.HexToAddress("0x123"), factoryAddr) + + // deploy wrapper contract and check if the factory address is set correctly + err = input.EVMKeeper.DeployERC20Wrapper(ctx) + require.NoError(t, err) + + expectedFactoryAddr, err := input.EVMKeeper.GetERC20FactoryAddr(ctx) + require.NoError(t, err) + + require.Equal(t, expectedFactoryAddr, queryFactoryAddressFromWrapper(t, ctx, input)) + + // deploy factory contract again and check if the factory address is set correctly + err = input.EVMKeeper.DeployERC20Factory(ctx) + require.NoError(t, err) + + expectedFactoryAddr, err = input.EVMKeeper.GetERC20FactoryAddr(ctx) + require.NoError(t, err) + + require.Equal(t, expectedFactoryAddr, queryFactoryAddressFromWrapper(t, ctx, input)) + require.NotEqual(t, factoryAddr, expectedFactoryAddr) +} + +func queryFactoryAddressFromWrapper(t *testing.T, ctx sdk.Context, input TestKeepers) common.Address { + wrapperAddr, err := input.EVMKeeper.GetERC20WrapperAddr(ctx) + require.NoError(t, err) + + caller := common.HexToAddress("0x0") + abi, err := erc20_wrapper.Erc20WrapperMetaData.GetAbi() + require.NoError(t, err) + + viewArg, err := abi.Pack("factory") + require.NoError(t, err) + + factoryAddrBytes, err := input.EVMKeeper.EVMStaticCall(ctx, caller, wrapperAddr, viewArg, nil) + require.NoError(t, err) + + factoryAddr := common.BytesToAddress(factoryAddrBytes) + return factoryAddr +} diff --git a/x/evm/types/expected_keeper.go b/x/evm/types/expected_keeper.go index be205f67..02cafe8d 100644 --- a/x/evm/types/expected_keeper.go +++ b/x/evm/types/expected_keeper.go @@ -66,6 +66,8 @@ type IERC20Keeper interface { // ABI GetERC20ABI() *abi.ABI + GetERC20FactoryABI() *abi.ABI + GetERC20WrapperABI() *abi.ABI // erc20 queries GetDecimals(ctx context.Context, denom string) (uint8, error)