|
| 1 | +package protocol |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "math/big" |
| 6 | + "sync" |
| 7 | + |
| 8 | + "github.com/ethereum/go-ethereum/accounts/abi/bind" |
| 9 | + "github.com/ethereum/go-ethereum/common" |
| 10 | + |
| 11 | + "github.com/rocket-pool/smartnode/bindings/dao/protocol" |
| 12 | + "github.com/rocket-pool/smartnode/bindings/rocketpool" |
| 13 | + "github.com/rocket-pool/smartnode/bindings/types" |
| 14 | + "github.com/rocket-pool/smartnode/bindings/utils/eth" |
| 15 | +) |
| 16 | + |
| 17 | +// Config |
| 18 | +const ( |
| 19 | + NodeSettingsContractName string = "rocketDAOProtocolSettingsNode" |
| 20 | + MinimumPerMinipoolStakeSettingPath string = "node.per.minipool.stake.minimum" |
| 21 | + MaximumPerMinipoolStakeSettingPath string = "node.per.minipool.stake.maximum" |
| 22 | +) |
| 23 | + |
| 24 | +// The minimum RPL stake per minipool as a fraction of assigned user ETH |
| 25 | +func GetMinimumPerMinipoolStake(rp *rocketpool.RocketPool, opts *bind.CallOpts) (float64, error) { |
| 26 | + nodeSettingsContract, err := getNodeSettingsContract(rp, opts) |
| 27 | + if err != nil { |
| 28 | + return 0, err |
| 29 | + } |
| 30 | + value := new(*big.Int) |
| 31 | + if err := nodeSettingsContract.Call(opts, value, "getMinimumPerMinipoolStake"); err != nil { |
| 32 | + return 0, fmt.Errorf("error getting minimum RPL stake per minipool: %w", err) |
| 33 | + } |
| 34 | + return eth.WeiToEth(*value), nil |
| 35 | +} |
| 36 | +func ProposeMinimumPerMinipoolStake(rp *rocketpool.RocketPool, value *big.Int, blockNumber uint32, treeNodes []types.VotingTreeNode, opts *bind.TransactOpts) (uint64, common.Hash, error) { |
| 37 | + return protocol.ProposeSetUint(rp, fmt.Sprintf("set %s", MinimumPerMinipoolStakeSettingPath), NodeSettingsContractName, MinimumPerMinipoolStakeSettingPath, value, blockNumber, treeNodes, opts) |
| 38 | +} |
| 39 | +func EstimateProposeMinimumPerMinipoolStakeGas(rp *rocketpool.RocketPool, value *big.Int, blockNumber uint32, treeNodes []types.VotingTreeNode, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { |
| 40 | + return protocol.EstimateProposeSetUintGas(rp, fmt.Sprintf("set %s", MinimumPerMinipoolStakeSettingPath), NodeSettingsContractName, MinimumPerMinipoolStakeSettingPath, value, blockNumber, treeNodes, opts) |
| 41 | +} |
| 42 | + |
| 43 | +// The minimum RPL stake per minipool as a fraction of assigned user ETH |
| 44 | +func GetMinimumPerMinipoolStakeRaw(rp *rocketpool.RocketPool, opts *bind.CallOpts) (*big.Int, error) { |
| 45 | + nodeSettingsContract, err := getNodeSettingsContract(rp, opts) |
| 46 | + if err != nil { |
| 47 | + return nil, err |
| 48 | + } |
| 49 | + value := new(*big.Int) |
| 50 | + if err := nodeSettingsContract.Call(opts, value, "getMinimumPerMinipoolStake"); err != nil { |
| 51 | + return nil, fmt.Errorf("error getting minimum RPL stake per minipool: %w", err) |
| 52 | + } |
| 53 | + return *value, nil |
| 54 | +} |
| 55 | + |
| 56 | +// The maximum RPL stake per minipool as a fraction of assigned user ETH |
| 57 | +func GetMaximumPerMinipoolStake(rp *rocketpool.RocketPool, opts *bind.CallOpts) (float64, error) { |
| 58 | + nodeSettingsContract, err := getNodeSettingsContract(rp, opts) |
| 59 | + if err != nil { |
| 60 | + return 0, err |
| 61 | + } |
| 62 | + value := new(*big.Int) |
| 63 | + if err := nodeSettingsContract.Call(opts, value, "getMaximumPerMinipoolStake"); err != nil { |
| 64 | + return 0, fmt.Errorf("error getting maximum RPL stake per minipool: %w", err) |
| 65 | + } |
| 66 | + return eth.WeiToEth(*value), nil |
| 67 | +} |
| 68 | +func ProposeMaximumPerMinipoolStake(rp *rocketpool.RocketPool, value *big.Int, blockNumber uint32, treeNodes []types.VotingTreeNode, opts *bind.TransactOpts) (uint64, common.Hash, error) { |
| 69 | + return protocol.ProposeSetUint(rp, fmt.Sprintf("set %s", MaximumPerMinipoolStakeSettingPath), NodeSettingsContractName, MaximumPerMinipoolStakeSettingPath, value, blockNumber, treeNodes, opts) |
| 70 | +} |
| 71 | +func EstimateProposeMaximumPerMinipoolStakeGas(rp *rocketpool.RocketPool, value *big.Int, blockNumber uint32, treeNodes []types.VotingTreeNode, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { |
| 72 | + return protocol.EstimateProposeSetUintGas(rp, fmt.Sprintf("set %s", MaximumPerMinipoolStakeSettingPath), NodeSettingsContractName, MaximumPerMinipoolStakeSettingPath, value, blockNumber, treeNodes, opts) |
| 73 | +} |
| 74 | + |
| 75 | +// The maximum RPL stake per minipool as a fraction of assigned user ETH |
| 76 | +func GetMaximumPerMinipoolStakeRaw(rp *rocketpool.RocketPool, opts *bind.CallOpts) (*big.Int, error) { |
| 77 | + nodeSettingsContract, err := getNodeSettingsContract(rp, opts) |
| 78 | + if err != nil { |
| 79 | + return nil, err |
| 80 | + } |
| 81 | + value := new(*big.Int) |
| 82 | + if err := nodeSettingsContract.Call(opts, value, "getMaximumPerMinipoolStake"); err != nil { |
| 83 | + return nil, fmt.Errorf("error getting maximum RPL stake per minipool: %w", err) |
| 84 | + } |
| 85 | + return *value, nil |
| 86 | +} |
| 87 | + |
| 88 | +// Get contracts |
| 89 | +var nodeSettingsContractLock sync.Mutex |
| 90 | + |
| 91 | +func getNodeSettingsContract(rp *rocketpool.RocketPool, opts *bind.CallOpts) (*rocketpool.Contract, error) { |
| 92 | + nodeSettingsContractLock.Lock() |
| 93 | + defer nodeSettingsContractLock.Unlock() |
| 94 | + return rp.GetContract(NodeSettingsContractName, opts) |
| 95 | +} |
0 commit comments