diff --git a/contract/types.go b/contract/types.go index 9bc035edf..67c0697d2 100644 --- a/contract/types.go +++ b/contract/types.go @@ -3,7 +3,11 @@ package contract import "github.com/ethereum/go-ethereum/accounts/abi" var ( + TypeAddress, _ = abi.NewType("address", "", nil) + TypeUint256, _ = abi.NewType("uint256", "", nil) TypeString, _ = abi.NewType("string", "", nil) + TypeBool, _ = abi.NewType("bool", "", nil) + TypeBytes32, _ = abi.NewType("bytes32", "", nil) TypeBytes, _ = abi.NewType("bytes", "", nil) TypeUint256Array, _ = abi.NewType("uint256[]", "", nil) ) diff --git a/x/evm/precompiles/crosschain/events.go b/x/evm/precompiles/crosschain/events.go index 57d028044..c1abd4ca0 100644 --- a/x/evm/precompiles/crosschain/events.go +++ b/x/evm/precompiles/crosschain/events.go @@ -3,7 +3,7 @@ package crosschain import ( "github.com/ethereum/go-ethereum/accounts/abi" - "github.com/functionx/fx-core/v7/x/evm/types" + "github.com/functionx/fx-core/v7/contract" ) var ( @@ -12,9 +12,9 @@ var ( CancelSendToExternalEventName, false, abi.Arguments{ - abi.Argument{Name: "sender", Type: types.TypeAddress, Indexed: true}, - abi.Argument{Name: "chain", Type: types.TypeString, Indexed: false}, - abi.Argument{Name: "txID", Type: types.TypeUint256, Indexed: false}, + abi.Argument{Name: "sender", Type: contract.TypeAddress, Indexed: true}, + abi.Argument{Name: "chain", Type: contract.TypeString, Indexed: false}, + abi.Argument{Name: "txID", Type: contract.TypeUint256, Indexed: false}, }) CrossChainEvent = abi.NewEvent( @@ -22,14 +22,14 @@ var ( CrossChainEventName, false, abi.Arguments{ - abi.Argument{Name: "sender", Type: types.TypeAddress, Indexed: true}, - abi.Argument{Name: "token", Type: types.TypeAddress, Indexed: true}, - abi.Argument{Name: "denom", Type: types.TypeString, Indexed: false}, - abi.Argument{Name: "receipt", Type: types.TypeString, Indexed: false}, - abi.Argument{Name: "amount", Type: types.TypeUint256, Indexed: false}, - abi.Argument{Name: "fee", Type: types.TypeUint256, Indexed: false}, - abi.Argument{Name: "target", Type: types.TypeBytes32, Indexed: false}, - abi.Argument{Name: "memo", Type: types.TypeString, Indexed: false}, + abi.Argument{Name: "sender", Type: contract.TypeAddress, Indexed: true}, + abi.Argument{Name: "token", Type: contract.TypeAddress, Indexed: true}, + abi.Argument{Name: "denom", Type: contract.TypeString, Indexed: false}, + abi.Argument{Name: "receipt", Type: contract.TypeString, Indexed: false}, + abi.Argument{Name: "amount", Type: contract.TypeUint256, Indexed: false}, + abi.Argument{Name: "fee", Type: contract.TypeUint256, Indexed: false}, + abi.Argument{Name: "target", Type: contract.TypeBytes32, Indexed: false}, + abi.Argument{Name: "memo", Type: contract.TypeString, Indexed: false}, }) IncreaseBridgeFeeEvent = abi.NewEvent( @@ -37,10 +37,10 @@ var ( IncreaseBridgeFeeEventName, false, abi.Arguments{ - abi.Argument{Name: "sender", Type: types.TypeAddress, Indexed: true}, - abi.Argument{Name: "token", Type: types.TypeAddress, Indexed: true}, - abi.Argument{Name: "chain", Type: types.TypeString, Indexed: false}, - abi.Argument{Name: "txID", Type: types.TypeUint256, Indexed: false}, - abi.Argument{Name: "fee", Type: types.TypeUint256, Indexed: false}, + abi.Argument{Name: "sender", Type: contract.TypeAddress, Indexed: true}, + abi.Argument{Name: "token", Type: contract.TypeAddress, Indexed: true}, + abi.Argument{Name: "chain", Type: contract.TypeString, Indexed: false}, + abi.Argument{Name: "txID", Type: contract.TypeUint256, Indexed: false}, + abi.Argument{Name: "fee", Type: contract.TypeUint256, Indexed: false}, }) ) diff --git a/x/evm/precompiles/crosschain/methods.go b/x/evm/precompiles/crosschain/methods.go index c64612b51..3aa2df091 100644 --- a/x/evm/precompiles/crosschain/methods.go +++ b/x/evm/precompiles/crosschain/methods.go @@ -7,8 +7,8 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" + "github.com/functionx/fx-core/v7/contract" crosschaintypes "github.com/functionx/fx-core/v7/x/crosschain/types" - "github.com/functionx/fx-core/v7/x/evm/types" ) // BridgeCoinAmountMethod query the amount of bridge coin @@ -17,11 +17,11 @@ var BridgeCoinAmountMethod = abi.NewMethod( BridgeCoinAmountMethodName, abi.Function, "view", false, false, abi.Arguments{ - abi.Argument{Name: "_token", Type: types.TypeAddress}, - abi.Argument{Name: "_target", Type: types.TypeBytes32}, + abi.Argument{Name: "_token", Type: contract.TypeAddress}, + abi.Argument{Name: "_target", Type: contract.TypeBytes32}, }, abi.Arguments{ - abi.Argument{Name: "_amount", Type: types.TypeUint256}, + abi.Argument{Name: "_amount", Type: contract.TypeUint256}, }, ) @@ -32,11 +32,11 @@ var ( CancelSendToExternalMethodName, abi.Function, "nonpayable", false, false, abi.Arguments{ - abi.Argument{Name: "_chain", Type: types.TypeString}, - abi.Argument{Name: "_txID", Type: types.TypeUint256}, + abi.Argument{Name: "_chain", Type: contract.TypeString}, + abi.Argument{Name: "_txID", Type: contract.TypeUint256}, }, abi.Arguments{ - abi.Argument{Name: "_result", Type: types.TypeBool}, + abi.Argument{Name: "_result", Type: contract.TypeBool}, }, ) @@ -47,15 +47,15 @@ var ( FIP20CrossChainMethodName, abi.Function, "nonpayable", false, false, abi.Arguments{ - abi.Argument{Name: "_sender", Type: types.TypeAddress}, - abi.Argument{Name: "_receipt", Type: types.TypeString}, - abi.Argument{Name: "_amount", Type: types.TypeUint256}, - abi.Argument{Name: "_fee", Type: types.TypeUint256}, - abi.Argument{Name: "_target", Type: types.TypeBytes32}, - abi.Argument{Name: "_memo", Type: types.TypeString}, + abi.Argument{Name: "_sender", Type: contract.TypeAddress}, + abi.Argument{Name: "_receipt", Type: contract.TypeString}, + abi.Argument{Name: "_amount", Type: contract.TypeUint256}, + abi.Argument{Name: "_fee", Type: contract.TypeUint256}, + abi.Argument{Name: "_target", Type: contract.TypeBytes32}, + abi.Argument{Name: "_memo", Type: contract.TypeString}, }, abi.Arguments{ - abi.Argument{Name: "_result", Type: types.TypeBool}, + abi.Argument{Name: "_result", Type: contract.TypeBool}, }, ) // CrossChainMethod cross chain with FIP20 token @@ -64,15 +64,15 @@ var ( CrossChainMethodName, abi.Function, "payable", false, false, abi.Arguments{ - abi.Argument{Name: "_token", Type: types.TypeAddress}, - abi.Argument{Name: "_receipt", Type: types.TypeString}, - abi.Argument{Name: "_amount", Type: types.TypeUint256}, - abi.Argument{Name: "_fee", Type: types.TypeUint256}, - abi.Argument{Name: "_target", Type: types.TypeBytes32}, - abi.Argument{Name: "_memo", Type: types.TypeString}, + abi.Argument{Name: "_token", Type: contract.TypeAddress}, + abi.Argument{Name: "_receipt", Type: contract.TypeString}, + abi.Argument{Name: "_amount", Type: contract.TypeUint256}, + abi.Argument{Name: "_fee", Type: contract.TypeUint256}, + abi.Argument{Name: "_target", Type: contract.TypeBytes32}, + abi.Argument{Name: "_memo", Type: contract.TypeString}, }, abi.Arguments{ - abi.Argument{Name: "_result", Type: types.TypeBool}, + abi.Argument{Name: "_result", Type: contract.TypeBool}, }, ) @@ -82,13 +82,13 @@ var ( IncreaseBridgeFeeMethodName, abi.Function, "payable", false, false, abi.Arguments{ - abi.Argument{Name: "_chain", Type: types.TypeString}, - abi.Argument{Name: "_txID", Type: types.TypeUint256}, - abi.Argument{Name: "_token", Type: types.TypeAddress}, - abi.Argument{Name: "_fee", Type: types.TypeUint256}, + abi.Argument{Name: "_chain", Type: contract.TypeString}, + abi.Argument{Name: "_txID", Type: contract.TypeUint256}, + abi.Argument{Name: "_token", Type: contract.TypeAddress}, + abi.Argument{Name: "_fee", Type: contract.TypeUint256}, }, abi.Arguments{ - abi.Argument{Name: "_result", Type: types.TypeBool}, + abi.Argument{Name: "_result", Type: contract.TypeBool}, }, ) ) diff --git a/x/evm/precompiles/staking/events.go b/x/evm/precompiles/staking/events.go index 6f60637ed..cbfae9091 100644 --- a/x/evm/precompiles/staking/events.go +++ b/x/evm/precompiles/staking/events.go @@ -3,7 +3,7 @@ package staking import ( "github.com/ethereum/go-ethereum/accounts/abi" - "github.com/functionx/fx-core/v7/x/evm/types" + "github.com/functionx/fx-core/v7/contract" ) var ( @@ -12,10 +12,10 @@ var ( ApproveSharesEventName, false, abi.Arguments{ - abi.Argument{Name: "owner", Type: types.TypeAddress, Indexed: true}, - abi.Argument{Name: "spender", Type: types.TypeAddress, Indexed: true}, - abi.Argument{Name: "validator", Type: types.TypeString, Indexed: false}, - abi.Argument{Name: "shares", Type: types.TypeUint256, Indexed: false}, + abi.Argument{Name: "owner", Type: contract.TypeAddress, Indexed: true}, + abi.Argument{Name: "spender", Type: contract.TypeAddress, Indexed: true}, + abi.Argument{Name: "validator", Type: contract.TypeString, Indexed: false}, + abi.Argument{Name: "shares", Type: contract.TypeUint256, Indexed: false}, }, ) @@ -24,10 +24,10 @@ var ( DelegateEventName, false, abi.Arguments{ - abi.Argument{Name: "delegator", Type: types.TypeAddress, Indexed: true}, - abi.Argument{Name: "validator", Type: types.TypeString, Indexed: false}, - abi.Argument{Name: "amount", Type: types.TypeUint256, Indexed: false}, - abi.Argument{Name: "shares", Type: types.TypeUint256, Indexed: false}, + abi.Argument{Name: "delegator", Type: contract.TypeAddress, Indexed: true}, + abi.Argument{Name: "validator", Type: contract.TypeString, Indexed: false}, + abi.Argument{Name: "amount", Type: contract.TypeUint256, Indexed: false}, + abi.Argument{Name: "shares", Type: contract.TypeUint256, Indexed: false}, }, ) @@ -36,11 +36,11 @@ var ( TransferSharesEventName, false, abi.Arguments{ - abi.Argument{Name: "from", Type: types.TypeAddress, Indexed: true}, - abi.Argument{Name: "to", Type: types.TypeAddress, Indexed: true}, - abi.Argument{Name: "validator", Type: types.TypeString, Indexed: false}, - abi.Argument{Name: "shares", Type: types.TypeUint256, Indexed: false}, - abi.Argument{Name: "token", Type: types.TypeUint256, Indexed: false}, + abi.Argument{Name: "from", Type: contract.TypeAddress, Indexed: true}, + abi.Argument{Name: "to", Type: contract.TypeAddress, Indexed: true}, + abi.Argument{Name: "validator", Type: contract.TypeString, Indexed: false}, + abi.Argument{Name: "shares", Type: contract.TypeUint256, Indexed: false}, + abi.Argument{Name: "token", Type: contract.TypeUint256, Indexed: false}, }, ) @@ -49,11 +49,11 @@ var ( UndelegateEventName, false, abi.Arguments{ - abi.Argument{Name: "sender", Type: types.TypeAddress, Indexed: true}, - abi.Argument{Name: "validator", Type: types.TypeString, Indexed: false}, - abi.Argument{Name: "shares", Type: types.TypeUint256, Indexed: false}, - abi.Argument{Name: "amount", Type: types.TypeUint256, Indexed: false}, - abi.Argument{Name: "completionTime", Type: types.TypeUint256, Indexed: false}, + abi.Argument{Name: "sender", Type: contract.TypeAddress, Indexed: true}, + abi.Argument{Name: "validator", Type: contract.TypeString, Indexed: false}, + abi.Argument{Name: "shares", Type: contract.TypeUint256, Indexed: false}, + abi.Argument{Name: "amount", Type: contract.TypeUint256, Indexed: false}, + abi.Argument{Name: "completionTime", Type: contract.TypeUint256, Indexed: false}, }, ) @@ -62,9 +62,9 @@ var ( WithdrawEventName, false, abi.Arguments{ - abi.Argument{Name: "sender", Type: types.TypeAddress, Indexed: true}, - abi.Argument{Name: "validator", Type: types.TypeString, Indexed: false}, - abi.Argument{Name: "reward", Type: types.TypeUint256, Indexed: false}, + abi.Argument{Name: "sender", Type: contract.TypeAddress, Indexed: true}, + abi.Argument{Name: "validator", Type: contract.TypeString, Indexed: false}, + abi.Argument{Name: "reward", Type: contract.TypeUint256, Indexed: false}, }, ) @@ -73,12 +73,12 @@ var ( RedelegateEventName, false, abi.Arguments{ - abi.Argument{Name: "sender", Type: types.TypeAddress, Indexed: true}, - abi.Argument{Name: "valSrc", Type: types.TypeString, Indexed: false}, - abi.Argument{Name: "valDst", Type: types.TypeString, Indexed: false}, - abi.Argument{Name: "shares", Type: types.TypeUint256, Indexed: false}, - abi.Argument{Name: "amount", Type: types.TypeUint256, Indexed: false}, - abi.Argument{Name: "completionTime", Type: types.TypeUint256, Indexed: false}, + abi.Argument{Name: "sender", Type: contract.TypeAddress, Indexed: true}, + abi.Argument{Name: "valSrc", Type: contract.TypeString, Indexed: false}, + abi.Argument{Name: "valDst", Type: contract.TypeString, Indexed: false}, + abi.Argument{Name: "shares", Type: contract.TypeUint256, Indexed: false}, + abi.Argument{Name: "amount", Type: contract.TypeUint256, Indexed: false}, + abi.Argument{Name: "completionTime", Type: contract.TypeUint256, Indexed: false}, }, ) ) diff --git a/x/evm/precompiles/staking/methods.go b/x/evm/precompiles/staking/methods.go index 7ff3f796a..d7b12473c 100644 --- a/x/evm/precompiles/staking/methods.go +++ b/x/evm/precompiles/staking/methods.go @@ -9,7 +9,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" - "github.com/functionx/fx-core/v7/x/evm/types" + "github.com/functionx/fx-core/v7/contract" ) var ( @@ -19,12 +19,12 @@ var ( AllowanceSharesMethodName, abi.Function, "view", false, false, abi.Arguments{ - abi.Argument{Name: "_val", Type: types.TypeString}, - abi.Argument{Name: "_owner", Type: types.TypeAddress}, - abi.Argument{Name: "_spender", Type: types.TypeAddress}, + abi.Argument{Name: "_val", Type: contract.TypeString}, + abi.Argument{Name: "_owner", Type: contract.TypeAddress}, + abi.Argument{Name: "_spender", Type: contract.TypeAddress}, }, abi.Arguments{ - abi.Argument{Name: "_shares", Type: types.TypeUint256}, + abi.Argument{Name: "_shares", Type: contract.TypeUint256}, }, ) @@ -34,12 +34,12 @@ var ( DelegationMethodName, abi.Function, "view", false, false, abi.Arguments{ - abi.Argument{Name: "_val", Type: types.TypeString}, - abi.Argument{Name: "_del", Type: types.TypeAddress}, + abi.Argument{Name: "_val", Type: contract.TypeString}, + abi.Argument{Name: "_del", Type: contract.TypeAddress}, }, abi.Arguments{ - abi.Argument{Name: "_shares", Type: types.TypeUint256}, - abi.Argument{Name: "_delegateAmount", Type: types.TypeUint256}, + abi.Argument{Name: "_shares", Type: contract.TypeUint256}, + abi.Argument{Name: "_delegateAmount", Type: contract.TypeUint256}, }, ) @@ -49,11 +49,11 @@ var ( DelegationRewardsMethodName, abi.Function, "view", false, false, abi.Arguments{ - abi.Argument{Name: "_val", Type: types.TypeString}, - abi.Argument{Name: "_del", Type: types.TypeAddress}, + abi.Argument{Name: "_val", Type: contract.TypeString}, + abi.Argument{Name: "_del", Type: contract.TypeAddress}, }, abi.Arguments{ - abi.Argument{Name: "_reward", Type: types.TypeUint256}, + abi.Argument{Name: "_reward", Type: contract.TypeUint256}, }, ) ) @@ -65,12 +65,12 @@ var ( ApproveSharesMethodName, abi.Function, "nonpayable", false, false, abi.Arguments{ - abi.Argument{Name: "_val", Type: types.TypeString}, - abi.Argument{Name: "_spender", Type: types.TypeAddress}, - abi.Argument{Name: "_shares", Type: types.TypeUint256}, + abi.Argument{Name: "_val", Type: contract.TypeString}, + abi.Argument{Name: "_spender", Type: contract.TypeAddress}, + abi.Argument{Name: "_shares", Type: contract.TypeUint256}, }, abi.Arguments{ - abi.Argument{Name: "_result", Type: types.TypeBool}, + abi.Argument{Name: "_result", Type: contract.TypeBool}, }, ) @@ -80,11 +80,11 @@ var ( DelegateMethodName, abi.Function, "payable", false, false, abi.Arguments{ - abi.Argument{Name: "_val", Type: types.TypeString}, + abi.Argument{Name: "_val", Type: contract.TypeString}, }, abi.Arguments{ - abi.Argument{Name: "_shares", Type: types.TypeUint256}, - abi.Argument{Name: "_reward", Type: types.TypeUint256}, + abi.Argument{Name: "_shares", Type: contract.TypeUint256}, + abi.Argument{Name: "_reward", Type: contract.TypeUint256}, }, ) @@ -94,13 +94,13 @@ var ( TransferSharesMethodName, abi.Function, "nonpayable", false, false, abi.Arguments{ - abi.Argument{Name: "_val", Type: types.TypeString}, - abi.Argument{Name: "_to", Type: types.TypeAddress}, - abi.Argument{Name: "_shares", Type: types.TypeUint256}, + abi.Argument{Name: "_val", Type: contract.TypeString}, + abi.Argument{Name: "_to", Type: contract.TypeAddress}, + abi.Argument{Name: "_shares", Type: contract.TypeUint256}, }, abi.Arguments{ - abi.Argument{Name: "_token", Type: types.TypeUint256}, - abi.Argument{Name: "_reward", Type: types.TypeUint256}, + abi.Argument{Name: "_token", Type: contract.TypeUint256}, + abi.Argument{Name: "_reward", Type: contract.TypeUint256}, }, ) @@ -110,14 +110,14 @@ var ( TransferFromSharesMethodName, abi.Function, "nonpayable", false, false, abi.Arguments{ - abi.Argument{Name: "_val", Type: types.TypeString}, - abi.Argument{Name: "_from", Type: types.TypeAddress}, - abi.Argument{Name: "_to", Type: types.TypeAddress}, - abi.Argument{Name: "_shares", Type: types.TypeUint256}, + abi.Argument{Name: "_val", Type: contract.TypeString}, + abi.Argument{Name: "_from", Type: contract.TypeAddress}, + abi.Argument{Name: "_to", Type: contract.TypeAddress}, + abi.Argument{Name: "_shares", Type: contract.TypeUint256}, }, abi.Arguments{ - abi.Argument{Name: "_token", Type: types.TypeUint256}, - abi.Argument{Name: "_reward", Type: types.TypeUint256}, + abi.Argument{Name: "_token", Type: contract.TypeUint256}, + abi.Argument{Name: "_reward", Type: contract.TypeUint256}, }, ) @@ -127,13 +127,13 @@ var ( UndelegateMethodName, abi.Function, "nonpayable", false, false, abi.Arguments{ - abi.Argument{Name: "_val", Type: types.TypeString}, - abi.Argument{Name: "_shares", Type: types.TypeUint256}, + abi.Argument{Name: "_val", Type: contract.TypeString}, + abi.Argument{Name: "_shares", Type: contract.TypeUint256}, }, abi.Arguments{ - abi.Argument{Name: "_amount", Type: types.TypeUint256}, - abi.Argument{Name: "_reward", Type: types.TypeUint256}, - abi.Argument{Name: "_completionTime", Type: types.TypeUint256}, + abi.Argument{Name: "_amount", Type: contract.TypeUint256}, + abi.Argument{Name: "_reward", Type: contract.TypeUint256}, + abi.Argument{Name: "_completionTime", Type: contract.TypeUint256}, }, ) @@ -143,10 +143,10 @@ var ( WithdrawMethodName, abi.Function, "nonpayable", false, false, abi.Arguments{ - abi.Argument{Name: "_val", Type: types.TypeString}, + abi.Argument{Name: "_val", Type: contract.TypeString}, }, abi.Arguments{ - abi.Argument{Name: "_reward", Type: types.TypeUint256}, + abi.Argument{Name: "_reward", Type: contract.TypeUint256}, }, ) @@ -156,14 +156,14 @@ var ( RedelegateMethodName, abi.Function, "nonpayable", false, false, abi.Arguments{ - abi.Argument{Name: "_valSrc", Type: types.TypeString}, - abi.Argument{Name: "_valDst", Type: types.TypeString}, - abi.Argument{Name: "_shares", Type: types.TypeUint256}, + abi.Argument{Name: "_valSrc", Type: contract.TypeString}, + abi.Argument{Name: "_valDst", Type: contract.TypeString}, + abi.Argument{Name: "_shares", Type: contract.TypeUint256}, }, abi.Arguments{ - abi.Argument{Name: "_amount", Type: types.TypeUint256}, - abi.Argument{Name: "_reward", Type: types.TypeUint256}, - abi.Argument{Name: "_completionTime", Type: types.TypeUint256}, + abi.Argument{Name: "_amount", Type: contract.TypeUint256}, + abi.Argument{Name: "_reward", Type: contract.TypeUint256}, + abi.Argument{Name: "_completionTime", Type: contract.TypeUint256}, }, ) ) diff --git a/x/evm/types/errors.go b/x/evm/types/errors.go index e5efbe5b8..b915579e0 100644 --- a/x/evm/types/errors.go +++ b/x/evm/types/errors.go @@ -6,6 +6,8 @@ import ( errorsmod "cosmossdk.io/errors" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/evmos/ethermint/x/evm/types" + + "github.com/functionx/fx-core/v7/contract" ) const ( @@ -19,6 +21,6 @@ var ( ) func PackRetError(str string) ([]byte, error) { - pack, _ := abi.Arguments{{Type: TypeString}}.Pack(str) + pack, _ := abi.Arguments{{Type: contract.TypeString}}.Pack(str) return pack, errors.New(str) } diff --git a/x/evm/types/precompiles.go b/x/evm/types/precompiles.go index c5932b47c..6faaa2dfa 100644 --- a/x/evm/types/precompiles.go +++ b/x/evm/types/precompiles.go @@ -7,14 +7,6 @@ import ( "github.com/ethereum/go-ethereum/common" ) -var ( - TypeAddress, _ = abi.NewType("address", "", nil) - TypeUint256, _ = abi.NewType("uint256", "", nil) - TypeString, _ = abi.NewType("string", "", nil) - TypeBool, _ = abi.NewType("bool", "", nil) - TypeBytes32, _ = abi.NewType("bytes32", "", nil) -) - func ParseMethodArgs(method abi.Method, v MethodArgs, data []byte) error { unpacked, err := method.Inputs.Unpack(data) if err != nil {