diff --git a/precompiles/distribution/IDistribution.abi b/precompiles/distribution/IDistribution.abi new file mode 100644 index 00000000..b092e5aa --- /dev/null +++ b/precompiles/distribution/IDistribution.abi @@ -0,0 +1,523 @@ +[ + { + "inputs": [], + "name": "CommunityPool", + "outputs": [ + { + "components": [ + { + "internalType": "string", + "name": "denom", + "type": "string" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "internalType": "struct DecCoin[]", + "name": "pool", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "delegatorAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "validatorAddress", + "type": "address" + } + ], + "name": "delegationRewards", + "outputs": [ + { + "components": [ + { + "internalType": "string", + "name": "denom", + "type": "string" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "internalType": "struct DecCoin[]", + "name": "rewards", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "delegatorAddress", + "type": "address" + } + ], + "name": "delegationTotalRewards", + "outputs": [ + { + "components": [ + { + "internalType": "address", + "name": "validatorAddress", + "type": "address" + }, + { + "components": [ + { + "internalType": "string", + "name": "denom", + "type": "string" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "internalType": "struct DecCoin[]", + "name": "reward", + "type": "tuple[]" + } + ], + "internalType": "struct DelegationDelegatorReward[]", + "name": "rewards", + "type": "tuple[]" + }, + { + "components": [ + { + "internalType": "string", + "name": "denom", + "type": "string" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "internalType": "struct DecCoin[]", + "name": "total", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "delegatorAddress", + "type": "address" + } + ], + "name": "delegatorValidators", + "outputs": [ + { + "internalType": "address[]", + "name": "validators", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "delegatorAddress", + "type": "address" + } + ], + "name": "delegatorWithdrawAddress", + "outputs": [ + { + "internalType": "address", + "name": "withdrawAddress", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "depositor", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "fundCommunityPool", + "outputs": [ + { + "internalType": "bool", + "name": "success", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "params", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "communityTax", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseProposerReward", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "bonusProposerReward", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "withdrawAddrEnabled", + "type": "bool" + } + ], + "internalType": "struct Params", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "delegatorAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "withdrawerAddress", + "type": "address" + } + ], + "name": "setWithdrawAddress", + "outputs": [ + { + "internalType": "bool", + "name": "success", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "validatorAddress", + "type": "string" + } + ], + "name": "validatorCommission", + "outputs": [ + { + "components": [ + { + "internalType": "string", + "name": "denom", + "type": "string" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "internalType": "struct DecCoin[]", + "name": "commission", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "validatorAddress", + "type": "address" + } + ], + "name": "validatorDistributionInfo", + "outputs": [ + { + "components": [ + { + "internalType": "address", + "name": "operatorAddress", + "type": "address" + }, + { + "components": [ + { + "internalType": "string", + "name": "denom", + "type": "string" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "internalType": "struct DecCoin[]", + "name": "selfBondRewards", + "type": "tuple[]" + }, + { + "components": [ + { + "internalType": "string", + "name": "denom", + "type": "string" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "internalType": "struct DecCoin[]", + "name": "commission", + "type": "tuple[]" + } + ], + "internalType": "struct ValidatorDistributionInfoResponse", + "name": "distributionInfo", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "validatorAddress", + "type": "address" + } + ], + "name": "validatorOutstandingRewards", + "outputs": [ + { + "components": [ + { + "internalType": "string", + "name": "denom", + "type": "string" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "internalType": "struct DecCoin[]", + "name": "rewards", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "validatorAddress", + "type": "address" + }, + { + "internalType": "uint64", + "name": "startingHeight", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "endingHeight", + "type": "uint64" + }, + { + "components": [ + { + "internalType": "bytes", + "name": "key", + "type": "bytes" + }, + { + "internalType": "uint64", + "name": "offset", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "limit", + "type": "uint64" + }, + { + "internalType": "bool", + "name": "countTotal", + "type": "bool" + }, + { + "internalType": "bool", + "name": "reverse", + "type": "bool" + } + ], + "internalType": "struct PageRequest", + "name": "pageRequest", + "type": "tuple" + } + ], + "name": "validatorSlashes", + "outputs": [ + { + "components": [ + { + "internalType": "uint64", + "name": "validatorPeriod", + "type": "uint64" + }, + { + "internalType": "uint256", + "name": "fraction", + "type": "uint256" + } + ], + "internalType": "struct ValidatorSlashEvent[]", + "name": "slashes", + "type": "tuple[]" + }, + { + "components": [ + { + "internalType": "bytes", + "name": "nextKey", + "type": "bytes" + }, + { + "internalType": "uint64", + "name": "total", + "type": "uint64" + } + ], + "internalType": "struct PageResponse", + "name": "pageResponse", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "delegatorAddress", + "type": "address" + }, + { + "internalType": "string", + "name": "validatorAddress", + "type": "string" + } + ], + "name": "withdrawDelegatorRewards", + "outputs": [ + { + "components": [ + { + "internalType": "string", + "name": "denom", + "type": "string" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "internalType": "struct Coin[]", + "name": "amount", + "type": "tuple[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "validatorAddress", + "type": "address" + } + ], + "name": "withdrawValidatorCommission", + "outputs": [ + { + "components": [ + { + "internalType": "string", + "name": "denom", + "type": "string" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "internalType": "struct Coin[]", + "name": "amount", + "type": "tuple[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/precompiles/distribution/contract.go b/precompiles/distribution/contract.go new file mode 100644 index 00000000..3d7b54ae --- /dev/null +++ b/precompiles/distribution/contract.go @@ -0,0 +1,602 @@ +// Code generated - DO NOT EDIT. +// This file is a generated binding and any manual changes will be lost. + +package distribution + +import ( + "errors" + "math/big" + "strings" + + ethereum "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/event" +) + +// Reference imports to suppress errors if they are not otherwise used. +var ( + _ = errors.New + _ = big.NewInt + _ = strings.NewReader + _ = ethereum.NotFound + _ = bind.Bind + _ = common.Big1 + _ = types.BloomLookup + _ = event.NewSubscription +) + +// DistributionMetaData contains all meta data concerning the Distribution contract. +var DistributionMetaData = &bind.MetaData{ + ABI: "[{\"inputs\":[],\"name\":\"CommunityPool\",\"outputs\":[{\"components\":[{\"internalType\":\"string\",\"name\":\"denom\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"internalType\":\"structDecCoin[]\",\"name\":\"pool\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"delegatorAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"validatorAddress\",\"type\":\"address\"}],\"name\":\"delegationRewards\",\"outputs\":[{\"components\":[{\"internalType\":\"string\",\"name\":\"denom\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"internalType\":\"structDecCoin[]\",\"name\":\"rewards\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"delegatorAddress\",\"type\":\"address\"}],\"name\":\"delegationTotalRewards\",\"outputs\":[{\"components\":[{\"internalType\":\"address\",\"name\":\"validatorAddress\",\"type\":\"address\"},{\"components\":[{\"internalType\":\"string\",\"name\":\"denom\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"internalType\":\"structDecCoin[]\",\"name\":\"reward\",\"type\":\"tuple[]\"}],\"internalType\":\"structDelegationDelegatorReward[]\",\"name\":\"rewards\",\"type\":\"tuple[]\"},{\"components\":[{\"internalType\":\"string\",\"name\":\"denom\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"internalType\":\"structDecCoin[]\",\"name\":\"total\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"delegatorAddress\",\"type\":\"address\"}],\"name\":\"delegatorValidators\",\"outputs\":[{\"internalType\":\"address[]\",\"name\":\"validators\",\"type\":\"address[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"delegatorAddress\",\"type\":\"address\"}],\"name\":\"delegatorWithdrawAddress\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"withdrawAddress\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"depositor\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"fundCommunityPool\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"success\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"params\",\"outputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"communityTax\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"baseProposerReward\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"bonusProposerReward\",\"type\":\"uint256\"},{\"internalType\":\"bool\",\"name\":\"withdrawAddrEnabled\",\"type\":\"bool\"}],\"internalType\":\"structParams\",\"name\":\"\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"delegatorAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"withdrawerAddress\",\"type\":\"address\"}],\"name\":\"setWithdrawAddress\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"success\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"validatorAddress\",\"type\":\"string\"}],\"name\":\"validatorCommission\",\"outputs\":[{\"components\":[{\"internalType\":\"string\",\"name\":\"denom\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"internalType\":\"structDecCoin[]\",\"name\":\"commission\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"validatorAddress\",\"type\":\"address\"}],\"name\":\"validatorDistributionInfo\",\"outputs\":[{\"components\":[{\"internalType\":\"address\",\"name\":\"operatorAddress\",\"type\":\"address\"},{\"components\":[{\"internalType\":\"string\",\"name\":\"denom\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"internalType\":\"structDecCoin[]\",\"name\":\"selfBondRewards\",\"type\":\"tuple[]\"},{\"components\":[{\"internalType\":\"string\",\"name\":\"denom\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"internalType\":\"structDecCoin[]\",\"name\":\"commission\",\"type\":\"tuple[]\"}],\"internalType\":\"structValidatorDistributionInfoResponse\",\"name\":\"distributionInfo\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"validatorAddress\",\"type\":\"address\"}],\"name\":\"validatorOutstandingRewards\",\"outputs\":[{\"components\":[{\"internalType\":\"string\",\"name\":\"denom\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"internalType\":\"structDecCoin[]\",\"name\":\"rewards\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"validatorAddress\",\"type\":\"address\"},{\"internalType\":\"uint64\",\"name\":\"startingHeight\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"endingHeight\",\"type\":\"uint64\"},{\"components\":[{\"internalType\":\"bytes\",\"name\":\"key\",\"type\":\"bytes\"},{\"internalType\":\"uint64\",\"name\":\"offset\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"limit\",\"type\":\"uint64\"},{\"internalType\":\"bool\",\"name\":\"countTotal\",\"type\":\"bool\"},{\"internalType\":\"bool\",\"name\":\"reverse\",\"type\":\"bool\"}],\"internalType\":\"structPageRequest\",\"name\":\"pageRequest\",\"type\":\"tuple\"}],\"name\":\"validatorSlashes\",\"outputs\":[{\"components\":[{\"internalType\":\"uint64\",\"name\":\"validatorPeriod\",\"type\":\"uint64\"},{\"internalType\":\"uint256\",\"name\":\"fraction\",\"type\":\"uint256\"}],\"internalType\":\"structValidatorSlashEvent[]\",\"name\":\"slashes\",\"type\":\"tuple[]\"},{\"components\":[{\"internalType\":\"bytes\",\"name\":\"nextKey\",\"type\":\"bytes\"},{\"internalType\":\"uint64\",\"name\":\"total\",\"type\":\"uint64\"}],\"internalType\":\"structPageResponse\",\"name\":\"pageResponse\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"delegatorAddress\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"validatorAddress\",\"type\":\"string\"}],\"name\":\"withdrawDelegatorRewards\",\"outputs\":[{\"components\":[{\"internalType\":\"string\",\"name\":\"denom\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"internalType\":\"structCoin[]\",\"name\":\"amount\",\"type\":\"tuple[]\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"validatorAddress\",\"type\":\"address\"}],\"name\":\"withdrawValidatorCommission\",\"outputs\":[{\"components\":[{\"internalType\":\"string\",\"name\":\"denom\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"internalType\":\"structCoin[]\",\"name\":\"amount\",\"type\":\"tuple[]\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", +} + +// DistributionABI is the input ABI used to generate the binding from. +// Deprecated: Use DistributionMetaData.ABI instead. +var DistributionABI = DistributionMetaData.ABI + +// Distribution is an auto generated Go binding around an Ethereum contract. +type Distribution struct { + DistributionCaller // Read-only binding to the contract + DistributionTransactor // Write-only binding to the contract + DistributionFilterer // Log filterer for contract events +} + +// DistributionCaller is an auto generated read-only Go binding around an Ethereum contract. +type DistributionCaller struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// DistributionTransactor is an auto generated write-only Go binding around an Ethereum contract. +type DistributionTransactor struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// DistributionFilterer is an auto generated log filtering Go binding around an Ethereum contract events. +type DistributionFilterer struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// DistributionSession is an auto generated Go binding around an Ethereum contract, +// with pre-set call and transact options. +type DistributionSession struct { + Contract *Distribution // Generic contract binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// DistributionCallerSession is an auto generated read-only Go binding around an Ethereum contract, +// with pre-set call options. +type DistributionCallerSession struct { + Contract *DistributionCaller // Generic contract caller binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session +} + +// DistributionTransactorSession is an auto generated write-only Go binding around an Ethereum contract, +// with pre-set transact options. +type DistributionTransactorSession struct { + Contract *DistributionTransactor // Generic contract transactor binding to set the session for + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// DistributionRaw is an auto generated low-level Go binding around an Ethereum contract. +type DistributionRaw struct { + Contract *Distribution // Generic contract binding to access the raw methods on +} + +// DistributionCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. +type DistributionCallerRaw struct { + Contract *DistributionCaller // Generic read-only contract binding to access the raw methods on +} + +// DistributionTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. +type DistributionTransactorRaw struct { + Contract *DistributionTransactor // Generic write-only contract binding to access the raw methods on +} + +// NewDistribution creates a new instance of Distribution, bound to a specific deployed contract. +func NewDistribution(address common.Address, backend bind.ContractBackend) (*Distribution, error) { + contract, err := bindDistribution(address, backend, backend, backend) + if err != nil { + return nil, err + } + return &Distribution{DistributionCaller: DistributionCaller{contract: contract}, DistributionTransactor: DistributionTransactor{contract: contract}, DistributionFilterer: DistributionFilterer{contract: contract}}, nil +} + +// NewDistributionCaller creates a new read-only instance of Distribution, bound to a specific deployed contract. +func NewDistributionCaller(address common.Address, caller bind.ContractCaller) (*DistributionCaller, error) { + contract, err := bindDistribution(address, caller, nil, nil) + if err != nil { + return nil, err + } + return &DistributionCaller{contract: contract}, nil +} + +// NewDistributionTransactor creates a new write-only instance of Distribution, bound to a specific deployed contract. +func NewDistributionTransactor(address common.Address, transactor bind.ContractTransactor) (*DistributionTransactor, error) { + contract, err := bindDistribution(address, nil, transactor, nil) + if err != nil { + return nil, err + } + return &DistributionTransactor{contract: contract}, nil +} + +// NewDistributionFilterer creates a new log filterer instance of Distribution, bound to a specific deployed contract. +func NewDistributionFilterer(address common.Address, filterer bind.ContractFilterer) (*DistributionFilterer, error) { + contract, err := bindDistribution(address, nil, nil, filterer) + if err != nil { + return nil, err + } + return &DistributionFilterer{contract: contract}, nil +} + +// bindDistribution binds a generic wrapper to an already deployed contract. +func bindDistribution(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { + parsed, err := abi.JSON(strings.NewReader(DistributionABI)) + if err != nil { + return nil, err + } + return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil +} + +// Call invokes the (constant) contract method with params as input values and +// sets the output to result. The result type might be a single field for simple +// returns, a slice of interfaces for anonymous returns and a struct for named +// returns. +func (_Distribution *DistributionRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error { + return _Distribution.Contract.DistributionCaller.contract.Call(opts, result, method, params...) +} + +// Transfer initiates a plain transaction to move funds to the contract, calling +// its default method if one is available. +func (_Distribution *DistributionRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _Distribution.Contract.DistributionTransactor.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_Distribution *DistributionRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _Distribution.Contract.DistributionTransactor.contract.Transact(opts, method, params...) +} + +// Call invokes the (constant) contract method with params as input values and +// sets the output to result. The result type might be a single field for simple +// returns, a slice of interfaces for anonymous returns and a struct for named +// returns. +func (_Distribution *DistributionCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error { + return _Distribution.Contract.contract.Call(opts, result, method, params...) +} + +// Transfer initiates a plain transaction to move funds to the contract, calling +// its default method if one is available. +func (_Distribution *DistributionTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _Distribution.Contract.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_Distribution *DistributionTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _Distribution.Contract.contract.Transact(opts, method, params...) +} + +// CommunityPool is a free data retrieval call binding the contract method 0x5637d7c9. +// +// Solidity: function CommunityPool() view returns((string,uint256)[] pool) +func (_Distribution *DistributionCaller) CommunityPool(opts *bind.CallOpts) ([]DecCoin, error) { + var out []interface{} + err := _Distribution.contract.Call(opts, &out, "CommunityPool") + + if err != nil { + return *new([]DecCoin), err + } + + out0 := *abi.ConvertType(out[0], new([]DecCoin)).(*[]DecCoin) + + return out0, err + +} + +// CommunityPool is a free data retrieval call binding the contract method 0x5637d7c9. +// +// Solidity: function CommunityPool() view returns((string,uint256)[] pool) +func (_Distribution *DistributionSession) CommunityPool() ([]DecCoin, error) { + return _Distribution.Contract.CommunityPool(&_Distribution.CallOpts) +} + +// CommunityPool is a free data retrieval call binding the contract method 0x5637d7c9. +// +// Solidity: function CommunityPool() view returns((string,uint256)[] pool) +func (_Distribution *DistributionCallerSession) CommunityPool() ([]DecCoin, error) { + return _Distribution.Contract.CommunityPool(&_Distribution.CallOpts) +} + +// DelegationRewards is a free data retrieval call binding the contract method 0xc9a21b7b. +// +// Solidity: function delegationRewards(address delegatorAddress, address validatorAddress) view returns((string,uint256)[] rewards) +func (_Distribution *DistributionCaller) DelegationRewards(opts *bind.CallOpts, delegatorAddress common.Address, validatorAddress common.Address) ([]DecCoin, error) { + var out []interface{} + err := _Distribution.contract.Call(opts, &out, "delegationRewards", delegatorAddress, validatorAddress) + + if err != nil { + return *new([]DecCoin), err + } + + out0 := *abi.ConvertType(out[0], new([]DecCoin)).(*[]DecCoin) + + return out0, err + +} + +// DelegationRewards is a free data retrieval call binding the contract method 0xc9a21b7b. +// +// Solidity: function delegationRewards(address delegatorAddress, address validatorAddress) view returns((string,uint256)[] rewards) +func (_Distribution *DistributionSession) DelegationRewards(delegatorAddress common.Address, validatorAddress common.Address) ([]DecCoin, error) { + return _Distribution.Contract.DelegationRewards(&_Distribution.CallOpts, delegatorAddress, validatorAddress) +} + +// DelegationRewards is a free data retrieval call binding the contract method 0xc9a21b7b. +// +// Solidity: function delegationRewards(address delegatorAddress, address validatorAddress) view returns((string,uint256)[] rewards) +func (_Distribution *DistributionCallerSession) DelegationRewards(delegatorAddress common.Address, validatorAddress common.Address) ([]DecCoin, error) { + return _Distribution.Contract.DelegationRewards(&_Distribution.CallOpts, delegatorAddress, validatorAddress) +} + +// DelegationTotalRewards is a free data retrieval call binding the contract method 0x54be1a28. +// +// Solidity: function delegationTotalRewards(address delegatorAddress) view returns((address,(string,uint256)[])[] rewards, (string,uint256)[] total) +func (_Distribution *DistributionCaller) DelegationTotalRewards(opts *bind.CallOpts, delegatorAddress common.Address) (struct { + Rewards []DelegationDelegatorReward + Total []DecCoin +}, error) { + var out []interface{} + err := _Distribution.contract.Call(opts, &out, "delegationTotalRewards", delegatorAddress) + + outstruct := new(struct { + Rewards []DelegationDelegatorReward + Total []DecCoin + }) + if err != nil { + return *outstruct, err + } + + outstruct.Rewards = *abi.ConvertType(out[0], new([]DelegationDelegatorReward)).(*[]DelegationDelegatorReward) + outstruct.Total = *abi.ConvertType(out[1], new([]DecCoin)).(*[]DecCoin) + + return *outstruct, err + +} + +// DelegationTotalRewards is a free data retrieval call binding the contract method 0x54be1a28. +// +// Solidity: function delegationTotalRewards(address delegatorAddress) view returns((address,(string,uint256)[])[] rewards, (string,uint256)[] total) +func (_Distribution *DistributionSession) DelegationTotalRewards(delegatorAddress common.Address) (struct { + Rewards []DelegationDelegatorReward + Total []DecCoin +}, error) { + return _Distribution.Contract.DelegationTotalRewards(&_Distribution.CallOpts, delegatorAddress) +} + +// DelegationTotalRewards is a free data retrieval call binding the contract method 0x54be1a28. +// +// Solidity: function delegationTotalRewards(address delegatorAddress) view returns((address,(string,uint256)[])[] rewards, (string,uint256)[] total) +func (_Distribution *DistributionCallerSession) DelegationTotalRewards(delegatorAddress common.Address) (struct { + Rewards []DelegationDelegatorReward + Total []DecCoin +}, error) { + return _Distribution.Contract.DelegationTotalRewards(&_Distribution.CallOpts, delegatorAddress) +} + +// DelegatorValidators is a free data retrieval call binding the contract method 0xa66cb605. +// +// Solidity: function delegatorValidators(address delegatorAddress) view returns(address[] validators) +func (_Distribution *DistributionCaller) DelegatorValidators(opts *bind.CallOpts, delegatorAddress common.Address) ([]common.Address, error) { + var out []interface{} + err := _Distribution.contract.Call(opts, &out, "delegatorValidators", delegatorAddress) + + if err != nil { + return *new([]common.Address), err + } + + out0 := *abi.ConvertType(out[0], new([]common.Address)).(*[]common.Address) + + return out0, err + +} + +// DelegatorValidators is a free data retrieval call binding the contract method 0xa66cb605. +// +// Solidity: function delegatorValidators(address delegatorAddress) view returns(address[] validators) +func (_Distribution *DistributionSession) DelegatorValidators(delegatorAddress common.Address) ([]common.Address, error) { + return _Distribution.Contract.DelegatorValidators(&_Distribution.CallOpts, delegatorAddress) +} + +// DelegatorValidators is a free data retrieval call binding the contract method 0xa66cb605. +// +// Solidity: function delegatorValidators(address delegatorAddress) view returns(address[] validators) +func (_Distribution *DistributionCallerSession) DelegatorValidators(delegatorAddress common.Address) ([]common.Address, error) { + return _Distribution.Contract.DelegatorValidators(&_Distribution.CallOpts, delegatorAddress) +} + +// DelegatorWithdrawAddress is a free data retrieval call binding the contract method 0x5431f450. +// +// Solidity: function delegatorWithdrawAddress(address delegatorAddress) view returns(address withdrawAddress) +func (_Distribution *DistributionCaller) DelegatorWithdrawAddress(opts *bind.CallOpts, delegatorAddress common.Address) (common.Address, error) { + var out []interface{} + err := _Distribution.contract.Call(opts, &out, "delegatorWithdrawAddress", delegatorAddress) + + if err != nil { + return *new(common.Address), err + } + + out0 := *abi.ConvertType(out[0], new(common.Address)).(*common.Address) + + return out0, err + +} + +// DelegatorWithdrawAddress is a free data retrieval call binding the contract method 0x5431f450. +// +// Solidity: function delegatorWithdrawAddress(address delegatorAddress) view returns(address withdrawAddress) +func (_Distribution *DistributionSession) DelegatorWithdrawAddress(delegatorAddress common.Address) (common.Address, error) { + return _Distribution.Contract.DelegatorWithdrawAddress(&_Distribution.CallOpts, delegatorAddress) +} + +// DelegatorWithdrawAddress is a free data retrieval call binding the contract method 0x5431f450. +// +// Solidity: function delegatorWithdrawAddress(address delegatorAddress) view returns(address withdrawAddress) +func (_Distribution *DistributionCallerSession) DelegatorWithdrawAddress(delegatorAddress common.Address) (common.Address, error) { + return _Distribution.Contract.DelegatorWithdrawAddress(&_Distribution.CallOpts, delegatorAddress) +} + +// Params is a free data retrieval call binding the contract method 0xcff0ab96. +// +// Solidity: function params() view returns((uint256,uint256,uint256,bool)) +func (_Distribution *DistributionCaller) Params(opts *bind.CallOpts) (Params, error) { + var out []interface{} + err := _Distribution.contract.Call(opts, &out, "params") + + if err != nil { + return *new(Params), err + } + + out0 := *abi.ConvertType(out[0], new(Params)).(*Params) + + return out0, err + +} + +// Params is a free data retrieval call binding the contract method 0xcff0ab96. +// +// Solidity: function params() view returns((uint256,uint256,uint256,bool)) +func (_Distribution *DistributionSession) Params() (Params, error) { + return _Distribution.Contract.Params(&_Distribution.CallOpts) +} + +// Params is a free data retrieval call binding the contract method 0xcff0ab96. +// +// Solidity: function params() view returns((uint256,uint256,uint256,bool)) +func (_Distribution *DistributionCallerSession) Params() (Params, error) { + return _Distribution.Contract.Params(&_Distribution.CallOpts) +} + +// ValidatorCommission is a free data retrieval call binding the contract method 0x3dd40f78. +// +// Solidity: function validatorCommission(string validatorAddress) view returns((string,uint256)[] commission) +func (_Distribution *DistributionCaller) ValidatorCommission(opts *bind.CallOpts, validatorAddress string) ([]DecCoin, error) { + var out []interface{} + err := _Distribution.contract.Call(opts, &out, "validatorCommission", validatorAddress) + + if err != nil { + return *new([]DecCoin), err + } + + out0 := *abi.ConvertType(out[0], new([]DecCoin)).(*[]DecCoin) + + return out0, err + +} + +// ValidatorCommission is a free data retrieval call binding the contract method 0x3dd40f78. +// +// Solidity: function validatorCommission(string validatorAddress) view returns((string,uint256)[] commission) +func (_Distribution *DistributionSession) ValidatorCommission(validatorAddress string) ([]DecCoin, error) { + return _Distribution.Contract.ValidatorCommission(&_Distribution.CallOpts, validatorAddress) +} + +// ValidatorCommission is a free data retrieval call binding the contract method 0x3dd40f78. +// +// Solidity: function validatorCommission(string validatorAddress) view returns((string,uint256)[] commission) +func (_Distribution *DistributionCallerSession) ValidatorCommission(validatorAddress string) ([]DecCoin, error) { + return _Distribution.Contract.ValidatorCommission(&_Distribution.CallOpts, validatorAddress) +} + +// ValidatorDistributionInfo is a free data retrieval call binding the contract method 0x7240b338. +// +// Solidity: function validatorDistributionInfo(address validatorAddress) view returns((address,(string,uint256)[],(string,uint256)[]) distributionInfo) +func (_Distribution *DistributionCaller) ValidatorDistributionInfo(opts *bind.CallOpts, validatorAddress common.Address) (ValidatorDistributionInfoResponse, error) { + var out []interface{} + err := _Distribution.contract.Call(opts, &out, "validatorDistributionInfo", validatorAddress) + + if err != nil { + return *new(ValidatorDistributionInfoResponse), err + } + + out0 := *abi.ConvertType(out[0], new(ValidatorDistributionInfoResponse)).(*ValidatorDistributionInfoResponse) + + return out0, err + +} + +// ValidatorDistributionInfo is a free data retrieval call binding the contract method 0x7240b338. +// +// Solidity: function validatorDistributionInfo(address validatorAddress) view returns((address,(string,uint256)[],(string,uint256)[]) distributionInfo) +func (_Distribution *DistributionSession) ValidatorDistributionInfo(validatorAddress common.Address) (ValidatorDistributionInfoResponse, error) { + return _Distribution.Contract.ValidatorDistributionInfo(&_Distribution.CallOpts, validatorAddress) +} + +// ValidatorDistributionInfo is a free data retrieval call binding the contract method 0x7240b338. +// +// Solidity: function validatorDistributionInfo(address validatorAddress) view returns((address,(string,uint256)[],(string,uint256)[]) distributionInfo) +func (_Distribution *DistributionCallerSession) ValidatorDistributionInfo(validatorAddress common.Address) (ValidatorDistributionInfoResponse, error) { + return _Distribution.Contract.ValidatorDistributionInfo(&_Distribution.CallOpts, validatorAddress) +} + +// ValidatorOutstandingRewards is a free data retrieval call binding the contract method 0xf28e9b39. +// +// Solidity: function validatorOutstandingRewards(address validatorAddress) view returns((string,uint256)[] rewards) +func (_Distribution *DistributionCaller) ValidatorOutstandingRewards(opts *bind.CallOpts, validatorAddress common.Address) ([]DecCoin, error) { + var out []interface{} + err := _Distribution.contract.Call(opts, &out, "validatorOutstandingRewards", validatorAddress) + + if err != nil { + return *new([]DecCoin), err + } + + out0 := *abi.ConvertType(out[0], new([]DecCoin)).(*[]DecCoin) + + return out0, err + +} + +// ValidatorOutstandingRewards is a free data retrieval call binding the contract method 0xf28e9b39. +// +// Solidity: function validatorOutstandingRewards(address validatorAddress) view returns((string,uint256)[] rewards) +func (_Distribution *DistributionSession) ValidatorOutstandingRewards(validatorAddress common.Address) ([]DecCoin, error) { + return _Distribution.Contract.ValidatorOutstandingRewards(&_Distribution.CallOpts, validatorAddress) +} + +// ValidatorOutstandingRewards is a free data retrieval call binding the contract method 0xf28e9b39. +// +// Solidity: function validatorOutstandingRewards(address validatorAddress) view returns((string,uint256)[] rewards) +func (_Distribution *DistributionCallerSession) ValidatorOutstandingRewards(validatorAddress common.Address) ([]DecCoin, error) { + return _Distribution.Contract.ValidatorOutstandingRewards(&_Distribution.CallOpts, validatorAddress) +} + +// ValidatorSlashes is a free data retrieval call binding the contract method 0xbd2e5693. +// +// Solidity: function validatorSlashes(address validatorAddress, uint64 startingHeight, uint64 endingHeight, (bytes,uint64,uint64,bool,bool) pageRequest) view returns((uint64,uint256)[] slashes, (bytes,uint64) pageResponse) +func (_Distribution *DistributionCaller) ValidatorSlashes(opts *bind.CallOpts, validatorAddress common.Address, startingHeight uint64, endingHeight uint64, pageRequest PageRequest) (struct { + Slashes []ValidatorSlashEvent + PageResponse PageResponse +}, error) { + var out []interface{} + err := _Distribution.contract.Call(opts, &out, "validatorSlashes", validatorAddress, startingHeight, endingHeight, pageRequest) + + outstruct := new(struct { + Slashes []ValidatorSlashEvent + PageResponse PageResponse + }) + if err != nil { + return *outstruct, err + } + + outstruct.Slashes = *abi.ConvertType(out[0], new([]ValidatorSlashEvent)).(*[]ValidatorSlashEvent) + outstruct.PageResponse = *abi.ConvertType(out[1], new(PageResponse)).(*PageResponse) + + return *outstruct, err + +} + +// ValidatorSlashes is a free data retrieval call binding the contract method 0xbd2e5693. +// +// Solidity: function validatorSlashes(address validatorAddress, uint64 startingHeight, uint64 endingHeight, (bytes,uint64,uint64,bool,bool) pageRequest) view returns((uint64,uint256)[] slashes, (bytes,uint64) pageResponse) +func (_Distribution *DistributionSession) ValidatorSlashes(validatorAddress common.Address, startingHeight uint64, endingHeight uint64, pageRequest PageRequest) (struct { + Slashes []ValidatorSlashEvent + PageResponse PageResponse +}, error) { + return _Distribution.Contract.ValidatorSlashes(&_Distribution.CallOpts, validatorAddress, startingHeight, endingHeight, pageRequest) +} + +// ValidatorSlashes is a free data retrieval call binding the contract method 0xbd2e5693. +// +// Solidity: function validatorSlashes(address validatorAddress, uint64 startingHeight, uint64 endingHeight, (bytes,uint64,uint64,bool,bool) pageRequest) view returns((uint64,uint256)[] slashes, (bytes,uint64) pageResponse) +func (_Distribution *DistributionCallerSession) ValidatorSlashes(validatorAddress common.Address, startingHeight uint64, endingHeight uint64, pageRequest PageRequest) (struct { + Slashes []ValidatorSlashEvent + PageResponse PageResponse +}, error) { + return _Distribution.Contract.ValidatorSlashes(&_Distribution.CallOpts, validatorAddress, startingHeight, endingHeight, pageRequest) +} + +// FundCommunityPool is a paid mutator transaction binding the contract method 0xed41d0b6. +// +// Solidity: function fundCommunityPool(address depositor, uint256 amount) returns(bool success) +func (_Distribution *DistributionTransactor) FundCommunityPool(opts *bind.TransactOpts, depositor common.Address, amount *big.Int) (*types.Transaction, error) { + return _Distribution.contract.Transact(opts, "fundCommunityPool", depositor, amount) +} + +// FundCommunityPool is a paid mutator transaction binding the contract method 0xed41d0b6. +// +// Solidity: function fundCommunityPool(address depositor, uint256 amount) returns(bool success) +func (_Distribution *DistributionSession) FundCommunityPool(depositor common.Address, amount *big.Int) (*types.Transaction, error) { + return _Distribution.Contract.FundCommunityPool(&_Distribution.TransactOpts, depositor, amount) +} + +// FundCommunityPool is a paid mutator transaction binding the contract method 0xed41d0b6. +// +// Solidity: function fundCommunityPool(address depositor, uint256 amount) returns(bool success) +func (_Distribution *DistributionTransactorSession) FundCommunityPool(depositor common.Address, amount *big.Int) (*types.Transaction, error) { + return _Distribution.Contract.FundCommunityPool(&_Distribution.TransactOpts, depositor, amount) +} + +// SetWithdrawAddress is a paid mutator transaction binding the contract method 0xe59a2f99. +// +// Solidity: function setWithdrawAddress(address delegatorAddress, address withdrawerAddress) returns(bool success) +func (_Distribution *DistributionTransactor) SetWithdrawAddress(opts *bind.TransactOpts, delegatorAddress common.Address, withdrawerAddress common.Address) (*types.Transaction, error) { + return _Distribution.contract.Transact(opts, "setWithdrawAddress", delegatorAddress, withdrawerAddress) +} + +// SetWithdrawAddress is a paid mutator transaction binding the contract method 0xe59a2f99. +// +// Solidity: function setWithdrawAddress(address delegatorAddress, address withdrawerAddress) returns(bool success) +func (_Distribution *DistributionSession) SetWithdrawAddress(delegatorAddress common.Address, withdrawerAddress common.Address) (*types.Transaction, error) { + return _Distribution.Contract.SetWithdrawAddress(&_Distribution.TransactOpts, delegatorAddress, withdrawerAddress) +} + +// SetWithdrawAddress is a paid mutator transaction binding the contract method 0xe59a2f99. +// +// Solidity: function setWithdrawAddress(address delegatorAddress, address withdrawerAddress) returns(bool success) +func (_Distribution *DistributionTransactorSession) SetWithdrawAddress(delegatorAddress common.Address, withdrawerAddress common.Address) (*types.Transaction, error) { + return _Distribution.Contract.SetWithdrawAddress(&_Distribution.TransactOpts, delegatorAddress, withdrawerAddress) +} + +// WithdrawDelegatorRewards is a paid mutator transaction binding the contract method 0xb46a8d61. +// +// Solidity: function withdrawDelegatorRewards(address delegatorAddress, string validatorAddress) returns((string,uint256)[] amount) +func (_Distribution *DistributionTransactor) WithdrawDelegatorRewards(opts *bind.TransactOpts, delegatorAddress common.Address, validatorAddress string) (*types.Transaction, error) { + return _Distribution.contract.Transact(opts, "withdrawDelegatorRewards", delegatorAddress, validatorAddress) +} + +// WithdrawDelegatorRewards is a paid mutator transaction binding the contract method 0xb46a8d61. +// +// Solidity: function withdrawDelegatorRewards(address delegatorAddress, string validatorAddress) returns((string,uint256)[] amount) +func (_Distribution *DistributionSession) WithdrawDelegatorRewards(delegatorAddress common.Address, validatorAddress string) (*types.Transaction, error) { + return _Distribution.Contract.WithdrawDelegatorRewards(&_Distribution.TransactOpts, delegatorAddress, validatorAddress) +} + +// WithdrawDelegatorRewards is a paid mutator transaction binding the contract method 0xb46a8d61. +// +// Solidity: function withdrawDelegatorRewards(address delegatorAddress, string validatorAddress) returns((string,uint256)[] amount) +func (_Distribution *DistributionTransactorSession) WithdrawDelegatorRewards(delegatorAddress common.Address, validatorAddress string) (*types.Transaction, error) { + return _Distribution.Contract.WithdrawDelegatorRewards(&_Distribution.TransactOpts, delegatorAddress, validatorAddress) +} + +// WithdrawValidatorCommission is a paid mutator transaction binding the contract method 0x11fc0bfe. +// +// Solidity: function withdrawValidatorCommission(address validatorAddress) returns((string,uint256)[] amount) +func (_Distribution *DistributionTransactor) WithdrawValidatorCommission(opts *bind.TransactOpts, validatorAddress common.Address) (*types.Transaction, error) { + return _Distribution.contract.Transact(opts, "withdrawValidatorCommission", validatorAddress) +} + +// WithdrawValidatorCommission is a paid mutator transaction binding the contract method 0x11fc0bfe. +// +// Solidity: function withdrawValidatorCommission(address validatorAddress) returns((string,uint256)[] amount) +func (_Distribution *DistributionSession) WithdrawValidatorCommission(validatorAddress common.Address) (*types.Transaction, error) { + return _Distribution.Contract.WithdrawValidatorCommission(&_Distribution.TransactOpts, validatorAddress) +} + +// WithdrawValidatorCommission is a paid mutator transaction binding the contract method 0x11fc0bfe. +// +// Solidity: function withdrawValidatorCommission(address validatorAddress) returns((string,uint256)[] amount) +func (_Distribution *DistributionTransactorSession) WithdrawValidatorCommission(validatorAddress common.Address) (*types.Transaction, error) { + return _Distribution.Contract.WithdrawValidatorCommission(&_Distribution.TransactOpts, validatorAddress) +} diff --git a/precompiles/distribution/distribution.go b/precompiles/distribution/distribution.go new file mode 100644 index 00000000..e60ffa7f --- /dev/null +++ b/precompiles/distribution/distribution.go @@ -0,0 +1,135 @@ +package distribution + +import ( + "strings" + + precompiles_common "github.com/0glabs/0g-chain/precompiles/common" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/vm" +) + +const ( + PrecompileAddress = "0x0000000000000000000000000000000000001003" + + // tx + DistributionFunctionSetWithdrawAddress = "setWithdrawAddress" + DistributionFunctionWithdrawDelegatorRewards = "withdrawDelegatorRewards" + DistributionFunctionWithdrawValidatorCommission = "withdrawValidatorCommission" + DistributionFunctionFundCommunityPool = "fundCommunityPool" + // query + DistributionFunctionParams = "params" + DistributionFunctionValidatorDistributionInfo = "validatorDistributionInfo" + DistributionFunctionValidatorOutstandingRewards = "validatorOutstandingRewards" + DistributionFunctionValidatorCommission = "validatorCommission" + DistributionFunctionValidatorSlashes = "validatorSlashes" + DistributionFunctionDelegationRewards = "delegationRewards" + DistributionFunctionDelegationTotalRewards = "delegationTotalRewards" + DistributionFunctionDelegatorValidators = "delegatorValidators" + DistributionFunctionDelegatorWithdrawAddress = "delegatorWithdrawAddress" + DistributionFunctionCommunityPool = "CommunityPool" +) + +var _ vm.PrecompiledContract = &DistributionPrecompile{} +var _ precompiles_common.PrecompileCommon = &DistributionPrecompile{} + +type DistributionPrecompile struct { + abi abi.ABI + distributionKeeper distributionkeeper.Keeper +} + +func NewDistributionPrecompile(distributionKeeper distributionkeeper.Keeper) (*DistributionPrecompile, error) { + abi, err := abi.JSON(strings.NewReader(DistributionABI)) + if err != nil { + return nil, err + } + return &DistributionPrecompile{ + abi: abi, + distributionKeeper: distributionKeeper, + }, nil +} + +// Address implements vm.PrecompiledContract. +func (d *DistributionPrecompile) Address() common.Address { + return common.HexToAddress(PrecompileAddress) +} + +// RequiredGas implements vm.PrecompiledContract. +func (d *DistributionPrecompile) RequiredGas(input []byte) uint64 { + return 0 +} + +func (d *DistributionPrecompile) Abi() *abi.ABI { + return &d.abi +} + +func (d *DistributionPrecompile) IsTx(method string) bool { + switch method { + case DistributionFunctionSetWithdrawAddress, + DistributionFunctionWithdrawDelegatorRewards, + DistributionFunctionWithdrawValidatorCommission, + DistributionFunctionFundCommunityPool: + return true + default: + return false + } +} + +func (d *DistributionPrecompile) KVGasConfig() storetypes.GasConfig { + return storetypes.KVGasConfig() +} + +// Run implements vm.PrecompiledContract. +func (d *DistributionPrecompile) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([]byte, error) { + ctx, stateDB, method, initialGas, args, err := precompiles_common.InitializePrecompileCall(d, evm, contract, readonly) + if err != nil { + return nil, err + } + + var bz []byte + switch method.Name { + // queries + case DistributionFunctionParams: + bz, err = d.Params(ctx, evm, method, args) + case DistributionFunctionValidatorDistributionInfo: + bz, err = d.ValidatorDistributionInfo(ctx, evm, method, args) + case DistributionFunctionValidatorOutstandingRewards: + bz, err = d.ValidatorOutstankingRewards(ctx, evm, method, args) + case DistributionFunctionValidatorCommission: + bz, err = d.ValidatorCommission(ctx, evm, method, args) + case DistributionFunctionValidatorSlashes: + bz, err = d.ValidatorSlashes(ctx, evm, method, args) + case DistributionFunctionDelegationRewards: + bz, err = d.DelegationRewards(ctx, evm, method, args) + case DistributionFunctionDelegationTotalRewards: + bz, err = d.DelegationTotalRewards(ctx, evm, method, args) + case DistributionFunctionDelegatorValidators: + bz, err = d.DelegatorValidators(ctx, evm, method, args) + case DistributionFunctionDelegatorWithdrawAddress: + bz, err = d.DelegatorWithdrawAddress(ctx, evm, method, args) + case DistributionFunctionCommunityPool: + bz, err = d.CommunityPool(ctx, evm, method, args) + // txs + case DistributionFunctionSetWithdrawAddress: + bz, err = d.CreateValidator(ctx, evm, stateDB, contract, method, args) + case DistributionFunctionWithdrawDelegatorRewards: + bz, err = d.EditValidator(ctx, evm, stateDB, contract, method, args) + case DistributionFunctionWithdrawValidatorCommission: + bz, err = d.Delegate(ctx, evm, stateDB, contract, method, args) + case DistributionFunctionFundCommunityPool: + bz, err = d.BeginRedelegate(ctx, evm, stateDB, contract, method, args) + } + + if err != nil { + return nil, err + } + + cost := ctx.GasMeter().GasConsumed() - initialGas + + if !contract.UseGas(cost) { + return nil, vm.ErrOutOfGas + } + return bz, nil +} diff --git a/precompiles/distribution/query.go b/precompiles/distribution/query.go new file mode 100644 index 00000000..78e93ab7 --- /dev/null +++ b/precompiles/distribution/query.go @@ -0,0 +1,172 @@ +package distribution + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/core/vm" +) + +func (d *DistributionPrecompile) Params(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) { + req, err := NewQueryParamsRequest(args) + if err != nil { + return nil, err + } + response, err := distributionkeeper.Querier{Keeper: d.distributionKeeper}.Params(ctx, req) + if err != nil { + return nil, err + } + + return method.Outputs.Pack(convertParams(response.Params)) +} + +func (d *DistributionPrecompile) ValidatorDistributionInfo(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) { + req, err := NewQueryValidatorDistributionInfoRequest(args) + if err != nil { + return nil, err + } + response, err := distributionkeeper.Querier{Keeper: d.distributionKeeper}.ValidatorDistributionInfo(ctx, req) + if err != nil { + return nil, err + } + + res, err := convertValidatorDistributionInfoResponse(response) + if err != nil { + return nil, err + } + + return method.Outputs.Pack(res) +} + +func (d *DistributionPrecompile) ValidatorOutstankingRewards(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) { + req, err := NewQueryValidatorOutstankingRewardsRequest(args) + if err != nil { + return nil, err + } + + response, err := distributionkeeper.Querier{Keeper: d.distributionKeeper}.ValidatorOutstandingRewards(ctx, req) + if err != nil { + return nil, err + } + + return method.Outputs.Pack(convertValidatorOutstandingRewardsResponse(response)) +} + +func (d *DistributionPrecompile) ValidatorCommission(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) { + req, err := NewQueryValidatorCommissionRequest(args) + if err != nil { + return nil, err + } + + response, err := distributionkeeper.Querier{Keeper: d.distributionKeeper}.ValidatorCommission(ctx, req) + if err != nil { + return nil, err + } + + return method.Outputs.Pack(convertValidatorCommissionResponse(response)) +} + +func (d *DistributionPrecompile) ValidatorSlashes(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) { + req, err := NewQueryValidatorSlashesRequest(args) + if err != nil { + return nil, err + } + + response, err := distributionkeeper.Querier{Keeper: d.distributionKeeper}.ValidatorSlashes(ctx, req) + if err != nil { + return nil, err + } + + slashes := make([]ValidatorSlashEvent, len(response.Slashes)) + for i, slash := range response.Slashes { + slashes[i] = convertValidatorSlashEvent(slash) + } + paginationResult := convertPageResponse(response.Pagination) + + return method.Outputs.Pack(slashes, paginationResult) +} + +func (d *DistributionPrecompile) DelegationRewards(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) { + req, err := NewQueryDelegationRewardsRequest(args) + if err != nil { + return nil, err + } + + response, err := distributionkeeper.Querier{Keeper: d.distributionKeeper}.DelegationRewards(ctx, req) + if err != nil { + return nil, err + } + + return method.Outputs.Pack(convertDelegationRewardsResponse(response)) +} + +func (d *DistributionPrecompile) DelegationTotalRewards(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) { + req, err := NewQueryDelegationTotalRewardsRequest(args) + if err != nil { + return nil, err + } + + response, err := distributionkeeper.Querier{Keeper: d.distributionKeeper}.DelegationTotalRewards(ctx, req) + if err != nil { + return nil, err + } + + rewards, total, err := convertDelegationTotalRewardsResponse(response) + if err != nil { + return nil, err + } + + return method.Outputs.Pack(rewards, total) +} + +func (d *DistributionPrecompile) DelegatorValidators(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) { + req, err := NewQueryDelegatorValidatorsRequest(args) + if err != nil { + return nil, err + } + + response, err := distributionkeeper.Querier{Keeper: d.distributionKeeper}.DelegatorValidators(ctx, req) + if err != nil { + return nil, err + } + + validators, err := convertDelegatorValidatorsResponse(response) + if err != nil { + return nil, err + } + + return method.Outputs.Pack(validators) +} + +func (d *DistributionPrecompile) DelegatorWithdrawAddress(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) { + req, err := NewQueryDelegatorWithdrawAddressRequest(args) + if err != nil { + return nil, err + } + + response, err := distributionkeeper.Querier{Keeper: d.distributionKeeper}.DelegatorWithdrawAddress(ctx, req) + if err != nil { + return nil, err + } + + withdrawAddress, err := convertWithdrawAddress(response.WithdrawAddress) + if err != nil { + return nil, err + } + + return method.Outputs.Pack(withdrawAddress) +} + +func (d *DistributionPrecompile) CommunityPool(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) { + req, err := NewQueryCommunityPoolRequest(args) + if err != nil { + return nil, err + } + + response, err := distributionkeeper.Querier{Keeper: d.distributionKeeper}.CommunityPool(ctx, req) + if err != nil { + return nil, err + } + + return method.Outputs.Pack(convertCommunityPoolResponse(response)) +} diff --git a/precompiles/distribution/types.go b/precompiles/distribution/types.go new file mode 100644 index 00000000..811bfeeb --- /dev/null +++ b/precompiles/distribution/types.go @@ -0,0 +1,305 @@ +package distribution + +import ( + "fmt" + "math/big" + + precompiles_common "github.com/0glabs/0g-chain/precompiles/common" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/ethereum/go-ethereum/common" +) + +// Coin is an auto generated low-level Go binding around an user-defined struct. +type Coin = struct { + Denom string `json:"denom"` + Amount *big.Int `json:"amount"` +} + +// DecCoin is an auto generated low-level Go binding around an user-defined struct. +type DecCoin = struct { + Denom string `json:"denom"` + Amount *big.Int `json:"amount"` +} + +// DelegationDelegatorReward is an auto generated low-level Go binding around an user-defined struct. +type DelegationDelegatorReward = struct { + ValidatorAddress common.Address `json:"validatorAddress"` + Reward []DecCoin `json:"reward"` +} + +// PageRequest is an auto generated low-level Go binding around an user-defined struct. +type PageRequest = struct { + Key []byte `json:"key"` + Offset uint64 `json:"offset"` + Limit uint64 `json:"limit"` + CountTotal bool `json:"countTotal"` + Reverse bool `json:"reverse"` +} + +// PageResponse is an auto generated low-level Go binding around an user-defined struct. +type PageResponse = struct { + NextKey []byte `json:"nextKey"` + Total uint64 `json:"total"` +} + +// Params is an auto generated low-level Go binding around an user-defined struct. +type Params = struct { + CommunityTax *big.Int `json:"communityTax"` + BaseProposerReward *big.Int `json:"baseProposerReward"` + BonusProposerReward *big.Int `json:"bonusProposerReward"` + WithdrawAddrEnabled bool `json:"withdrawAddrEnabled"` +} + +// ValidatorDistributionInfoResponse is an auto generated low-level Go binding around an user-defined struct. +type ValidatorDistributionInfoResponse = struct { + OperatorAddress common.Address `json:"operatorAddress"` + SelfBondRewards []DecCoin `json:"selfBondRewards"` + Commission []DecCoin `json:"commission"` +} + +// ValidatorSlashEvent is an auto generated low-level Go binding around an user-defined struct. +type ValidatorSlashEvent = struct { + ValidatorPeriod uint64 `json:"validatorPeriod"` + Fraction *big.Int `json:"fraction"` +} + +func NewQueryParamsRequest(args []interface{}) (*distributiontypes.QueryParamsRequest, error) { + if len(args) != 0 { + return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 0, len(args)) + } + + return &distributiontypes.QueryParamsRequest{}, nil +} + +func convertParams(params distributiontypes.Params) Params { + return Params{ + CommunityTax: params.CommunityTax.BigInt(), + BaseProposerReward: params.BaseProposerReward.BigInt(), + BonusProposerReward: params.BonusProposerReward.BigInt(), + WithdrawAddrEnabled: params.WithdrawAddrEnabled, + } +} + +func NewQueryValidatorDistributionInfoRequest(args []interface{}) (*distributiontypes.QueryValidatorDistributionInfoRequest, error) { + if len(args) != 1 { + return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 1, len(args)) + } + + validator := args[0].(common.Address) + + return &distributiontypes.QueryValidatorDistributionInfoRequest{ + ValidatorAddress: sdk.ValAddress(validator.Bytes()).String(), + }, nil +} + +func convertDecCoins(coins github_com_cosmos_cosmos_sdk_types.DecCoins) []DecCoin { + ans := make([]DecCoin, len(coins)) + for i, coin := range coins { + ans[i] = DecCoin{ + Denom: coin.Denom, + Amount: coin.Amount.TruncateInt().BigInt(), + } + } + return ans +} + +func convertValidatorDistributionInfoResponse(response *distributiontypes.QueryValidatorDistributionInfoResponse) (ValidatorDistributionInfoResponse, error) { + operatorAddress, err := sdk.ValAddressFromBech32(response.OperatorAddress) + if err != nil { + return ValidatorDistributionInfoResponse{}, err + } + return ValidatorDistributionInfoResponse{ + OperatorAddress: common.BytesToAddress(operatorAddress.Bytes()), + SelfBondRewards: convertDecCoins(response.SelfBondRewards), + Commission: convertDecCoins(response.Commission), + }, nil +} + +func NewQueryValidatorOutstankingRewardsRequest(args []interface{}) (*distributiontypes.QueryValidatorOutstandingRewardsRequest, error) { + if len(args) != 1 { + return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 1, len(args)) + } + + validator := args[0].(common.Address) + + return &distributiontypes.QueryValidatorOutstandingRewardsRequest{ + ValidatorAddress: sdk.ValAddress(validator.Bytes()).String(), + }, nil +} + +func convertValidatorOutstandingRewardsResponse(response *distributiontypes.QueryValidatorOutstandingRewardsResponse) []DecCoin { + return convertDecCoins(response.Rewards.Rewards) +} + +func NewQueryValidatorCommissionRequest(args []interface{}) (*distributiontypes.QueryValidatorCommissionRequest, error) { + if len(args) != 1 { + return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 1, len(args)) + } + + validator := args[0].(common.Address) + + return &distributiontypes.QueryValidatorCommissionRequest{ + ValidatorAddress: sdk.ValAddress(validator.Bytes()).String(), + }, nil +} + +func convertValidatorCommissionResponse(response *distributiontypes.QueryValidatorCommissionResponse) []DecCoin { + return convertDecCoins(response.Commission.Commission) +} + +func convertQueryPageRequest(pagination PageRequest) *query.PageRequest { + return &query.PageRequest{ + Key: pagination.Key, + Offset: pagination.Offset, + Limit: pagination.Limit, + CountTotal: pagination.CountTotal, + Reverse: pagination.Reverse, + } +} + +func NewQueryValidatorSlashesRequest(args []interface{}) (*distributiontypes.QueryValidatorSlashesRequest, error) { + if len(args) != 4 { + return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 4, len(args)) + } + + validator := args[0].(common.Address) + + return &distributiontypes.QueryValidatorSlashesRequest{ + ValidatorAddress: sdk.ValAddress(validator.Bytes()).String(), + StartingHeight: args[1].(uint64), + EndingHeight: args[2].(uint64), + Pagination: convertQueryPageRequest(args[3].(PageRequest)), + }, nil +} + +func convertValidatorSlashEvent(slash distributiontypes.ValidatorSlashEvent) ValidatorSlashEvent { + return ValidatorSlashEvent{ + ValidatorPeriod: slash.ValidatorPeriod, + Fraction: slash.Fraction.BigInt(), + } +} + +func convertPageResponse(pagination *query.PageResponse) PageResponse { + if pagination == nil { + return PageResponse{ + NextKey: make([]byte, 0), + Total: 1, + } + } + return PageResponse{ + NextKey: pagination.NextKey, + Total: pagination.Total, + } +} + +func NewQueryDelegationRewardsRequest(args []interface{}) (*distributiontypes.QueryDelegationRewardsRequest, error) { + if len(args) != 2 { + return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 2, len(args)) + } + + delegator := args[0].(common.Address) + validator := args[1].(common.Address) + + return &distributiontypes.QueryDelegationRewardsRequest{ + DelegatorAddress: sdk.AccAddress(delegator.Bytes()).String(), + ValidatorAddress: sdk.ValAddress(validator.Bytes()).String(), + }, nil +} + +func convertDelegationRewardsResponse(response *distributiontypes.QueryDelegationRewardsResponse) []DecCoin { + return convertDecCoins(response.Rewards) +} + +func NewQueryDelegationTotalRewardsRequest(args []interface{}) (*distributiontypes.QueryDelegationTotalRewardsRequest, error) { + if len(args) != 1 { + return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 1, len(args)) + } + + delegator := args[0].(common.Address) + + return &distributiontypes.QueryDelegationTotalRewardsRequest{ + DelegatorAddress: sdk.AccAddress(delegator.Bytes()).String(), + }, nil +} + +func convertDelegationDelegatorReward(reward distributiontypes.DelegationDelegatorReward) (DelegationDelegatorReward, error) { + validatorAddress, err := sdk.ValAddressFromBech32(reward.ValidatorAddress) + if err != nil { + return DelegationDelegatorReward{}, err + } + return DelegationDelegatorReward{ + ValidatorAddress: common.BytesToAddress(validatorAddress.Bytes()), + Reward: convertDecCoins(reward.Reward), + }, nil +} + +func convertDelegationTotalRewardsResponse(response *distributiontypes.QueryDelegationTotalRewardsResponse) ([]DelegationDelegatorReward, []DecCoin, error) { + rewards := make([]DelegationDelegatorReward, len(response.Rewards)) + var err error + for i, reward := range response.Rewards { + rewards[i], err = convertDelegationDelegatorReward(reward) + if err != nil { + return nil, nil, err + } + } + return rewards, convertDecCoins(response.Total), nil +} + +func NewQueryDelegatorValidatorsRequest(args []interface{}) (*distributiontypes.QueryDelegatorValidatorsRequest, error) { + if len(args) != 1 { + return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 1, len(args)) + } + + delegator := args[0].(common.Address) + + return &distributiontypes.QueryDelegatorValidatorsRequest{ + DelegatorAddress: sdk.AccAddress(delegator.Bytes()).String(), + }, nil +} + +func convertDelegatorValidatorsResponse(response *distributiontypes.QueryDelegatorValidatorsResponse) ([]common.Address, error) { + validators := make([]common.Address, len(response.Validators)) + for i, addr := range response.Validators { + validatorAddress, err := sdk.ValAddressFromBech32(addr) + if err != nil { + return nil, err + } + validators[i] = common.BytesToAddress(validatorAddress.Bytes()) + } + return validators, nil +} + +func NewQueryDelegatorWithdrawAddressRequest(args []interface{}) (*distributiontypes.QueryDelegatorWithdrawAddressRequest, error) { + if len(args) != 1 { + return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 1, len(args)) + } + + delegator := args[0].(common.Address) + + return &distributiontypes.QueryDelegatorWithdrawAddressRequest{ + DelegatorAddress: sdk.AccAddress(delegator.Bytes()).String(), + }, nil +} + +func convertWithdrawAddress(addr string) (common.Address, error) { + withdrawAddress, err := sdk.AccAddressFromBech32(addr) + if err != nil { + return common.Address{}, err + } + return common.Address(withdrawAddress.Bytes()), nil +} + +func NewQueryCommunityPoolRequest(args []interface{}) (*distributiontypes.QueryCommunityPoolRequest, error) { + if len(args) != 0 { + return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 0, len(args)) + } + + return &distributiontypes.QueryCommunityPoolRequest{}, nil +} + +func convertCommunityPoolResponse(response *distributiontypes.QueryCommunityPoolResponse) []DecCoin { + return convertDecCoins(response.Pool) +} diff --git a/precompiles/interfaces/contracts/IDistribution.sol b/precompiles/interfaces/contracts/IDistribution.sol new file mode 100644 index 00000000..99453089 --- /dev/null +++ b/precompiles/interfaces/contracts/IDistribution.sol @@ -0,0 +1,165 @@ +// SPDX-License-Identifier: LGPL-3.0-only +pragma solidity >=0.8.0; + +import "./types.sol"; + +struct Params { + uint communityTax; + uint baseProposerReward; + uint bonusProposerReward; + bool withdrawAddrEnabled; +} + +struct ValidatorDistributionInfoResponse { + address operatorAddress; + DecCoin[] selfBondRewards; + DecCoin[] commission; +} + +struct ValidatorSlashEvent { + uint64 validatorPeriod; + uint fraction; // 18 decimals +} + +struct DelegationDelegatorReward { + address validatorAddress; + DecCoin[] reward; +} + +interface IDistribution { + /*=== events ===*/ + + /*=== cosmos tx ===*/ + + /** + * @dev SetWithdrawAddress defines a method to change the withdraw address for a delegator (or validator self-delegation). + * cosmos grpc: rpc SetWithdrawAddress(MsgSetWithdrawAddress) returns (MsgSetWithdrawAddressResponse); + */ + function setWithdrawAddress( + address delegatorAddress, + address withdrawerAddress + ) external returns (bool success); + + /** + * @dev WithdrawDelegatorReward defines a method to withdraw rewards of delegator from a single validator. + * cosmos grpc: rpc WithdrawDelegatorReward(MsgWithdrawDelegatorReward) returns (MsgWithdrawDelegatorRewardResponse); + */ + function withdrawDelegatorRewards( + address delegatorAddress, + string memory validatorAddress + ) external returns (Coin[] calldata amount); + + /** + * @dev WithdrawValidatorCommission defines a method to withdraw the full commission to the validator address. + * cosmos grpc: rpc WithdrawValidatorCommission(MsgWithdrawValidatorCommission) returns (MsgWithdrawValidatorCommissionResponse); + */ + function withdrawValidatorCommission( + address validatorAddress + ) external returns (Coin[] calldata amount); + + /** + * @dev FundCommunityPool defines a method to allow an account to directly fund the community pool. + * cosmos grpc: rpc FundCommunityPool(MsgFundCommunityPool) returns (MsgFundCommunityPoolResponse); + */ + function fundCommunityPool( + address depositor, + uint256 amount + ) external returns (bool success); + + /*=== cosmos query ===*/ + + /** + * @dev Params queries params of the distribution module. + * cosmos grpc: rpc Params(QueryParamsRequest) returns (QueryParamsResponse); + */ + function params() external view returns (Params memory); + + /** + * @dev ValidatorDistributionInfo queries validator commission and self-delegation rewards for validator + * cosmos grpc: rpc ValidatorDistributionInfo(QueryValidatorDistributionInfoRequest) returns (QueryValidatorDistributionInfoResponse); + */ + function validatorDistributionInfo( + address validatorAddress + ) + external + view + returns (ValidatorDistributionInfoResponse memory distributionInfo); + + /** + * @dev ValidatorOutstandingRewards queries rewards of a validator address. + * cosmos grpc: rpc ValidatorOutstandingRewards(QueryValidatorOutstandingRewardsRequest) returns (QueryValidatorOutstandingRewardsResponse); + */ + function validatorOutstandingRewards( + address validatorAddress + ) external view returns (DecCoin[] memory rewards); + + /** + * @dev ValidatorCommission queries accumulated commission for a validator. + * cosmos grpc: rpc ValidatorCommission(QueryValidatorCommissionRequest) returns (QueryValidatorCommissionResponse); + */ + function validatorCommission( + string memory validatorAddress + ) external view returns (DecCoin[] memory commission); + + /** + * @dev ValidatorSlashes queries slash events of a validator. + * cosmos grpc: rpc ValidatorSlashes(QueryValidatorSlashesRequest) returns (QueryValidatorSlashesResponse); + */ + function validatorSlashes( + address validatorAddress, + uint64 startingHeight, + uint64 endingHeight, + PageRequest calldata pageRequest + ) + external + view + returns ( + ValidatorSlashEvent[] memory slashes, + PageResponse calldata pageResponse + ); + + /** + * @dev DelegationRewards queries the total rewards accrued by a delegation. + * cosmos grpc: rpc DelegationRewards(QueryDelegationRewardsRequest) returns (QueryDelegationRewardsResponse); + */ + function delegationRewards( + address delegatorAddress, + address validatorAddress + ) external view returns (DecCoin[] memory rewards); + + /** + * @dev DelegationTotalRewards queries the total rewards accrued by a each validator. + * cosmos grpc: rpc DelegationTotalRewards(QueryDelegationTotalRewardsRequest) returns (QueryDelegationTotalRewardsResponse); + */ + function delegationTotalRewards( + address delegatorAddress + ) + external + view + returns ( + DelegationDelegatorReward[] memory rewards, + DecCoin[] memory total + ); + + /** + * @dev DelegatorValidators queries the validators of a delegator. + * cosmos grpc: rpc DelegatorValidators(QueryDelegatorValidatorsRequest) returns (QueryDelegatorValidatorsResponse); + */ + function delegatorValidators( + address delegatorAddress + ) external view returns (address[] memory validators); + + /** + * @dev DelegatorWithdrawAddress queries withdraw address of a delegator. + * cosmos grpc: rpc DelegatorWithdrawAddress(QueryDelegatorWithdrawAddressRequest) returns (QueryDelegatorWithdrawAddressResponse); + */ + function delegatorWithdrawAddress( + address delegatorAddress + ) external view returns (address withdrawAddress); + + /** + * @dev CommunityPool queries the community pool coins. + * cosmos grpc: rpc CommunityPool(QueryCommunityPoolRequest) returns (QueryCommunityPoolResponse); + */ + function CommunityPool() external view returns (DecCoin[] memory pool); +} diff --git a/precompiles/interfaces/contracts/IStaking.sol b/precompiles/interfaces/contracts/IStaking.sol index ad458cb8..09fef3b1 100644 --- a/precompiles/interfaces/contracts/IStaking.sol +++ b/precompiles/interfaces/contracts/IStaking.sol @@ -1,6 +1,8 @@ // SPDX-License-Identifier: LGPL-3.0-only pragma solidity >=0.8.0; +import "./types.sol"; + /** * @dev Description defines a validator description */ @@ -160,19 +162,6 @@ struct NullableUint { uint value; } -struct PageRequest { - bytes key; - uint64 offset; - uint64 limit; - bool countTotal; - bool reverse; -} - -struct PageResponse { - bytes nextKey; - uint64 total; -} - interface IStaking { /*=== cosmos tx ===*/ diff --git a/precompiles/interfaces/contracts/types.sol b/precompiles/interfaces/contracts/types.sol new file mode 100644 index 00000000..8c420c0e --- /dev/null +++ b/precompiles/interfaces/contracts/types.sol @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: LGPL-3.0-only +pragma solidity >=0.8.0; + +/** + * @dev cosmos.base.v1beta1.Coin + */ +struct Coin { + string denom; + uint amount; +} + +/** + * @dev cosmos.base.v1beta1.DecCoin + * 18 decimals + */ +struct DecCoin { + string denom; + uint amount; +} + +/** + * @dev cosmos.base.query.v1beta1.PageRequest + */ +struct PageRequest { + bytes key; + uint64 offset; + uint64 limit; + bool countTotal; + bool reverse; +} + +/** + * @dev cosmos.base.query.v1beta1.PageResponse + */ +struct PageResponse { + bytes nextKey; + uint64 total; +}