From fcc6e4ec40a03f0b20c971aca7c8ce354655ebc1 Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Mon, 3 May 2021 23:33:43 -0400 Subject: [PATCH 1/8] Added gas estimators for all of the transactions --- auction/auction.go | 40 ++++++++++ dao/protocol/dao.go | 40 ++++++++++ dao/trustednode/actions.go | 40 ++++++++++ dao/trustednode/dao.go | 44 +++++++++++ dao/trustednode/proposals.go | 142 ++++++++++++++++++++++++++++++++++ deposit/deposit.go | 20 +++++ minipool/minipool-contract.go | 38 ++++++++- minipool/status.go | 10 +++ network/balances.go | 10 +++ network/prices.go | 10 +++ node/deposit.go | 10 +++ node/node.go | 40 ++++++++++ node/staking.go | 20 +++++ rewards/node.go | 10 +++ rewards/rewards.go | 6 ++ rewards/trusted-node.go | 10 +++ tokens/reth.go | 40 ++++++++++ tokens/rpl-fixed.go | 30 +++++++ tokens/rpl.go | 50 ++++++++++++ tokens/tokens.go | 18 +++++ 20 files changed, 627 insertions(+), 1 deletion(-) diff --git a/auction/auction.go b/auction/auction.go index 19d5d48f..d3daea28 100644 --- a/auction/auction.go +++ b/auction/auction.go @@ -509,6 +509,16 @@ func GetLotAddressBidAmount(rp *rocketpool.RocketPool, lotIndex uint64, bidder c } +// Estimate the gas of CreateLot +func EstimateCreateLotGas(rp *rocketpool.RocketPool, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketAuctionManager, err := getRocketAuctionManager(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketAuctionManager.GetTransactionGasInfo(opts, "createLot") +} + + // Create a new lot func CreateLot(rp *rocketpool.RocketPool, opts *bind.TransactOpts) (uint64, common.Hash, error) { rocketAuctionManager, err := getRocketAuctionManager(rp) @@ -527,6 +537,16 @@ func CreateLot(rp *rocketpool.RocketPool, opts *bind.TransactOpts) (uint64, comm } +// Estimate the gas of PlaceBid +func EstimatePlaceBidGas(rp *rocketpool.RocketPool, lotIndex uint64, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketAuctionManager, err := getRocketAuctionManager(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketAuctionManager.GetTransactionGasInfo(opts, "placeBid", big.NewInt(int64(lotIndex))) +} + + // Place a bid on a lot func PlaceBid(rp *rocketpool.RocketPool, lotIndex uint64, opts *bind.TransactOpts) (common.Hash, error) { rocketAuctionManager, err := getRocketAuctionManager(rp) @@ -541,6 +561,16 @@ func PlaceBid(rp *rocketpool.RocketPool, lotIndex uint64, opts *bind.TransactOpt } +// Estimate the gas of ClaimBid +func EstimateClaimBidGas(rp *rocketpool.RocketPool, lotIndex uint64, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketAuctionManager, err := getRocketAuctionManager(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketAuctionManager.GetTransactionGasInfo(opts, "claimBid", big.NewInt(int64(lotIndex))) +} + + // Claim RPL from a lot that was bid on func ClaimBid(rp *rocketpool.RocketPool, lotIndex uint64, opts *bind.TransactOpts) (common.Hash, error) { rocketAuctionManager, err := getRocketAuctionManager(rp) @@ -555,6 +585,16 @@ func ClaimBid(rp *rocketpool.RocketPool, lotIndex uint64, opts *bind.TransactOpt } +// Estimate the gas of RecoverUnclaimedRPL +func EstimateRecoverUnclaimedRPLGas(rp *rocketpool.RocketPool, lotIndex uint64, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketAuctionManager, err := getRocketAuctionManager(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketAuctionManager.GetTransactionGasInfo(opts, "recoverUnclaimedRPL", big.NewInt(int64(lotIndex))) +} + + // Recover unclaimed RPL from a lot func RecoverUnclaimedRPL(rp *rocketpool.RocketPool, lotIndex uint64, opts *bind.TransactOpts) (common.Hash, error) { rocketAuctionManager, err := getRocketAuctionManager(rp) diff --git a/dao/protocol/dao.go b/dao/protocol/dao.go index 3a03153b..1abbf849 100644 --- a/dao/protocol/dao.go +++ b/dao/protocol/dao.go @@ -12,6 +12,16 @@ import ( "github.com/rocket-pool/rocketpool-go/utils/eth" ) +// Estimate the gas of BootstrapBool +func EstimateBootstrapBoolGas(rp *rocketpool.RocketPool, contractName, settingPath string, value bool, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDAOProtocol, err := getRocketDAOProtocol(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketDAOProtocol.GetTransactionGasInfo(opts, "bootstrapSettingBool", contractName, settingPath, value) +} + + // Bootstrap a bool setting func BootstrapBool(rp *rocketpool.RocketPool, contractName, settingPath string, value bool, opts *bind.TransactOpts) (common.Hash, error) { rocketDAOProtocol, err := getRocketDAOProtocol(rp) @@ -26,6 +36,16 @@ func BootstrapBool(rp *rocketpool.RocketPool, contractName, settingPath string, } +// Estimate the gas of BootstrapUint +func EstimateBootstrapUintGas(rp *rocketpool.RocketPool, contractName, settingPath string, value *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDAOProtocol, err := getRocketDAOProtocol(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketDAOProtocol.GetTransactionGasInfo(opts, "bootstrapSettingUint", contractName, settingPath, value) +} + + // Bootstrap a uint256 setting func BootstrapUint(rp *rocketpool.RocketPool, contractName, settingPath string, value *big.Int, opts *bind.TransactOpts) (common.Hash, error) { rocketDAOProtocol, err := getRocketDAOProtocol(rp) @@ -40,6 +60,16 @@ func BootstrapUint(rp *rocketpool.RocketPool, contractName, settingPath string, } +// Estimate the gas of BootstrapAddress +func EstimateBootstrapAddressGas(rp *rocketpool.RocketPool, contractName, settingPath string, value common.Address, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDAOProtocol, err := getRocketDAOProtocol(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketDAOProtocol.GetTransactionGasInfo(opts, "bootstrapSettingAddress", contractName, settingPath, value) +} + + // Bootstrap an address setting func BootstrapAddress(rp *rocketpool.RocketPool, contractName, settingPath string, value common.Address, opts *bind.TransactOpts) (common.Hash, error) { rocketDAOProtocol, err := getRocketDAOProtocol(rp) @@ -54,6 +84,16 @@ func BootstrapAddress(rp *rocketpool.RocketPool, contractName, settingPath strin } +// Estimate the gas of BootstrapClaimer +func EstimateBootstrapClaimerGas(rp *rocketpool.RocketPool, contractName string, amount float64, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDAOProtocol, err := getRocketDAOProtocol(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketDAOProtocol.GetTransactionGasInfo(opts, "bootstrapSettingClaimer", contractName, eth.EthToWei(amount)) +} + + // Bootstrap a rewards claimer func BootstrapClaimer(rp *rocketpool.RocketPool, contractName string, amount float64, opts *bind.TransactOpts) (common.Hash, error) { rocketDAOProtocol, err := getRocketDAOProtocol(rp) diff --git a/dao/trustednode/actions.go b/dao/trustednode/actions.go index f6965941..74aef923 100644 --- a/dao/trustednode/actions.go +++ b/dao/trustednode/actions.go @@ -10,6 +10,16 @@ import ( "github.com/rocket-pool/rocketpool-go/rocketpool" ) +// Estimate the gas of Join +func EstimateJoinGas(rp *rocketpool.RocketPool, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDAONodeTrustedActions, err := getRocketDAONodeTrustedActions(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketDAONodeTrustedActions.GetTransactionGasInfo(opts, "actionJoin") +} + + // Join the trusted node DAO // Requires an executed invite proposal func Join(rp *rocketpool.RocketPool, opts *bind.TransactOpts) (common.Hash, error) { @@ -25,6 +35,16 @@ func Join(rp *rocketpool.RocketPool, opts *bind.TransactOpts) (common.Hash, erro } +// Estimate the gas of Leave +func EstimateLeaveGas(rp *rocketpool.RocketPool, rplBondRefundAddress common.Address, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDAONodeTrustedActions, err := getRocketDAONodeTrustedActions(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketDAONodeTrustedActions.GetTransactionGasInfo(opts, "actionLeave", rplBondRefundAddress) +} + + // Leave the trusted node DAO // Requires an executed leave proposal func Leave(rp *rocketpool.RocketPool, rplBondRefundAddress common.Address, opts *bind.TransactOpts) (common.Hash, error) { @@ -40,6 +60,16 @@ func Leave(rp *rocketpool.RocketPool, rplBondRefundAddress common.Address, opts } +// Estimate the gas of MakeChallenge +func EstimateMakeChallengeGas(rp *rocketpool.RocketPool, memberAddress common.Address, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDAONodeTrustedActions, err := getRocketDAONodeTrustedActions(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketDAONodeTrustedActions.GetTransactionGasInfo(opts, "actionChallengeMake", memberAddress) +} + + // Make a challenge against a node func MakeChallenge(rp *rocketpool.RocketPool, memberAddress common.Address, opts *bind.TransactOpts) (common.Hash, error) { rocketDAONodeTrustedActions, err := getRocketDAONodeTrustedActions(rp) @@ -54,6 +84,16 @@ func MakeChallenge(rp *rocketpool.RocketPool, memberAddress common.Address, opts } +// Estimate the gas of DecideChallenge +func EstimateDecideChallengeGas(rp *rocketpool.RocketPool, memberAddress common.Address, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDAONodeTrustedActions, err := getRocketDAONodeTrustedActions(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketDAONodeTrustedActions.GetTransactionGasInfo(opts, "actionChallengeDecide", memberAddress) +} + + // Decide a challenge against a node func DecideChallenge(rp *rocketpool.RocketPool, memberAddress common.Address, opts *bind.TransactOpts) (common.Hash, error) { rocketDAONodeTrustedActions, err := getRocketDAONodeTrustedActions(rp) diff --git a/dao/trustednode/dao.go b/dao/trustednode/dao.go index 93e16fc2..852be62b 100644 --- a/dao/trustednode/dao.go +++ b/dao/trustednode/dao.go @@ -357,6 +357,16 @@ func GetMemberIsChallenged(rp *rocketpool.RocketPool, memberAddress common.Addre } +// Estimate the gas of BootstrapBool +func EstimateBootstrapBoolGas(rp *rocketpool.RocketPool, contractName, settingPath string, value bool, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDAONodeTrusted, err := getRocketDAONodeTrusted(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketDAONodeTrusted.GetTransactionGasInfo(opts, "bootstrapSettingBool", contractName, settingPath, value) +} + + // Bootstrap a bool setting func BootstrapBool(rp *rocketpool.RocketPool, contractName, settingPath string, value bool, opts *bind.TransactOpts) (common.Hash, error) { rocketDAONodeTrusted, err := getRocketDAONodeTrusted(rp) @@ -371,6 +381,16 @@ func BootstrapBool(rp *rocketpool.RocketPool, contractName, settingPath string, } +// Estimate the gas of BootstrapUint +func EstimateBootstrapUintGas(rp *rocketpool.RocketPool, contractName, settingPath string, value *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDAONodeTrusted, err := getRocketDAONodeTrusted(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketDAONodeTrusted.GetTransactionGasInfo(opts, "bootstrapSettingUint", contractName, settingPath, value) +} + + // Bootstrap a uint256 setting func BootstrapUint(rp *rocketpool.RocketPool, contractName, settingPath string, value *big.Int, opts *bind.TransactOpts) (common.Hash, error) { rocketDAONodeTrusted, err := getRocketDAONodeTrusted(rp) @@ -385,6 +405,16 @@ func BootstrapUint(rp *rocketpool.RocketPool, contractName, settingPath string, } +// Estimate the gas of BootstrapMember +func EstimateBootstrapMemberGas(rp *rocketpool.RocketPool, id, email string, nodeAddress common.Address, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDAONodeTrusted, err := getRocketDAONodeTrusted(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketDAONodeTrusted.GetTransactionGasInfo(opts, "bootstrapMember", id, email, nodeAddress) +} + + // Bootstrap a DAO member func BootstrapMember(rp *rocketpool.RocketPool, id, email string, nodeAddress common.Address, opts *bind.TransactOpts) (common.Hash, error) { rocketDAONodeTrusted, err := getRocketDAONodeTrusted(rp) @@ -399,6 +429,20 @@ func BootstrapMember(rp *rocketpool.RocketPool, id, email string, nodeAddress co } +// Estimate the gas of BootstrapUpgrade +func EstimateBootstrapUpgradeGas(rp *rocketpool.RocketPool, upgradeType, contractName, contractAbi string, contractAddress common.Address, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + compressedAbi, err := rocketpool.EncodeAbiStr(contractAbi) + if err != nil { + return rocketpool.GasInfo{}, err + } + rocketDAONodeTrusted, err := getRocketDAONodeTrusted(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketDAONodeTrusted.GetTransactionGasInfo(opts, "bootstrapUpgrade", upgradeType, contractName, compressedAbi, contractAddress) +} + + // Bootstrap a contract upgrade func BootstrapUpgrade(rp *rocketpool.RocketPool, upgradeType, contractName, contractAbi string, contractAddress common.Address, opts *bind.TransactOpts) (common.Hash, error) { compressedAbi, err := rocketpool.EncodeAbiStr(contractAbi) diff --git a/dao/trustednode/proposals.go b/dao/trustednode/proposals.go index d5750e46..c817c948 100644 --- a/dao/trustednode/proposals.go +++ b/dao/trustednode/proposals.go @@ -12,6 +12,20 @@ import ( "github.com/rocket-pool/rocketpool-go/rocketpool" ) +// Estimate the gas of ProposeInviteMember +func EstimateProposeInviteMemberGas(rp *rocketpool.RocketPool, message string, newMemberAddress common.Address, newMemberId, newMemberEmail string, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDAONodeTrustedProposals, err := getRocketDAONodeTrustedProposals(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + payload, err := rocketDAONodeTrustedProposals.ABI.Pack("proposalInvite", newMemberId, newMemberEmail, newMemberAddress) + if err != nil { + return rocketpool.GasInfo{}, fmt.Errorf("Could not encode invite member proposal payload: %w", err) + } + return EstimateProposalGas(rp, message, payload, opts) +} + + // Submit a proposal to invite a new member to the trusted node DAO func ProposeInviteMember(rp *rocketpool.RocketPool, message string, newMemberAddress common.Address, newMemberId, newMemberEmail string, opts *bind.TransactOpts) (uint64, common.Hash, error) { rocketDAONodeTrustedProposals, err := getRocketDAONodeTrustedProposals(rp) @@ -26,6 +40,20 @@ func ProposeInviteMember(rp *rocketpool.RocketPool, message string, newMemberAdd } +// Estimate the gas of ProposeMemberLeave +func EstimateProposeMemberLeaveGas(rp *rocketpool.RocketPool, message string, memberAddress common.Address, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDAONodeTrustedProposals, err := getRocketDAONodeTrustedProposals(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + payload, err := rocketDAONodeTrustedProposals.ABI.Pack("proposalLeave", memberAddress) + if err != nil { + return rocketpool.GasInfo{}, fmt.Errorf("Could not encode member leave proposal payload: %w", err) + } + return EstimateProposalGas(rp, message, payload, opts) +} + + // Submit a proposal for a member to leave the trusted node DAO func ProposeMemberLeave(rp *rocketpool.RocketPool, message string, memberAddress common.Address, opts *bind.TransactOpts) (uint64, common.Hash, error) { rocketDAONodeTrustedProposals, err := getRocketDAONodeTrustedProposals(rp) @@ -40,6 +68,20 @@ func ProposeMemberLeave(rp *rocketpool.RocketPool, message string, memberAddress } +// Estimate the gas of ProposeReplaceMember +func EstimateProposeReplaceMemberGas(rp *rocketpool.RocketPool, message string, memberAddress, newMemberAddress common.Address, newMemberId, newMemberEmail string, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDAONodeTrustedProposals, err := getRocketDAONodeTrustedProposals(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + payload, err := rocketDAONodeTrustedProposals.ABI.Pack("proposalReplace", memberAddress, newMemberId, newMemberEmail, newMemberAddress) + if err != nil { + return rocketpool.GasInfo{}, fmt.Errorf("Could not encode replace member proposal payload: %w", err) + } + return EstimateProposalGas(rp, message, payload, opts) +} + + // Submit a proposal to replace a member in the trusted node DAO func ProposeReplaceMember(rp *rocketpool.RocketPool, message string, memberAddress, newMemberAddress common.Address, newMemberId, newMemberEmail string, opts *bind.TransactOpts) (uint64, common.Hash, error) { rocketDAONodeTrustedProposals, err := getRocketDAONodeTrustedProposals(rp) @@ -54,6 +96,20 @@ func ProposeReplaceMember(rp *rocketpool.RocketPool, message string, memberAddre } +// Estimate the gas of ProposeKickMember +func EstimateProposeKickMemberGas(rp *rocketpool.RocketPool, message string, memberAddress common.Address, rplFineAmount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDAONodeTrustedProposals, err := getRocketDAONodeTrustedProposals(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + payload, err := rocketDAONodeTrustedProposals.ABI.Pack("proposalKick", memberAddress, rplFineAmount) + if err != nil { + return rocketpool.GasInfo{}, fmt.Errorf("Could not encode kick member proposal payload: %w", err) + } + return EstimateProposalGas(rp, message, payload, opts) +} + + // Submit a proposal to kick a member from the trusted node DAO func ProposeKickMember(rp *rocketpool.RocketPool, message string, memberAddress common.Address, rplFineAmount *big.Int, opts *bind.TransactOpts) (uint64, common.Hash, error) { rocketDAONodeTrustedProposals, err := getRocketDAONodeTrustedProposals(rp) @@ -68,6 +124,20 @@ func ProposeKickMember(rp *rocketpool.RocketPool, message string, memberAddress } +// Estimate the gas of ProposeSetBool +func EstimateProposeSetBoolGas(rp *rocketpool.RocketPool, message, contractName, settingPath string, value bool, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDAONodeTrustedProposals, err := getRocketDAONodeTrustedProposals(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + payload, err := rocketDAONodeTrustedProposals.ABI.Pack("proposalSettingBool", contractName, settingPath, value) + if err != nil { + return rocketpool.GasInfo{}, fmt.Errorf("Could not encode set bool setting proposal payload: %w", err) + } + return EstimateProposalGas(rp, message, payload, opts) +} + + // Submit a proposal to update a bool trusted node DAO setting func ProposeSetBool(rp *rocketpool.RocketPool, message, contractName, settingPath string, value bool, opts *bind.TransactOpts) (uint64, common.Hash, error) { rocketDAONodeTrustedProposals, err := getRocketDAONodeTrustedProposals(rp) @@ -82,6 +152,20 @@ func ProposeSetBool(rp *rocketpool.RocketPool, message, contractName, settingPat } +// Estimate the gas of ProposeSetUint +func EstimateProposeSetUintGas(rp *rocketpool.RocketPool, message, contractName, settingPath string, value *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDAONodeTrustedProposals, err := getRocketDAONodeTrustedProposals(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + payload, err := rocketDAONodeTrustedProposals.ABI.Pack("proposalSettingUint", contractName, settingPath, value) + if err != nil { + return rocketpool.GasInfo{}, fmt.Errorf("Could not encode set uint setting proposal payload: %w", err) + } + return EstimateProposalGas(rp, message, payload, opts) +} + + // Submit a proposal to update a uint trusted node DAO setting func ProposeSetUint(rp *rocketpool.RocketPool, message, contractName, settingPath string, value *big.Int, opts *bind.TransactOpts) (uint64, common.Hash, error) { rocketDAONodeTrustedProposals, err := getRocketDAONodeTrustedProposals(rp) @@ -96,6 +180,24 @@ func ProposeSetUint(rp *rocketpool.RocketPool, message, contractName, settingPat } +// Estimate the gas of ProposeUpgradeContract +func EstimateProposeUpgradeContractGas(rp *rocketpool.RocketPool, message, upgradeType, contractName, contractAbi string, contractAddress common.Address, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + compressedAbi, err := rocketpool.EncodeAbiStr(contractAbi) + if err != nil { + return rocketpool.GasInfo{}, err + } + rocketDAONodeTrustedProposals, err := getRocketDAONodeTrustedProposals(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + payload, err := rocketDAONodeTrustedProposals.ABI.Pack("proposalUpgrade", upgradeType, contractName, compressedAbi, contractAddress) + if err != nil { + return rocketpool.GasInfo{}, fmt.Errorf("Could not encode upgrade contract proposal payload: %w", err) + } + return EstimateProposalGas(rp, message, payload, opts) +} + + // Submit a proposal to upgrade a contract func ProposeUpgradeContract(rp *rocketpool.RocketPool, message, upgradeType, contractName, contractAbi string, contractAddress common.Address, opts *bind.TransactOpts) (uint64, common.Hash, error) { compressedAbi, err := rocketpool.EncodeAbiStr(contractAbi) @@ -114,6 +216,16 @@ func ProposeUpgradeContract(rp *rocketpool.RocketPool, message, upgradeType, con } +// Estimate the gas of a proposal submission +func EstimateProposalGas(rp *rocketpool.RocketPool, message string, payload []byte, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDAONodeTrustedProposals, err := getRocketDAONodeTrustedProposals(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketDAONodeTrustedProposals.GetTransactionGasInfo(opts, "propose", message, payload) +} + + // Submit a trusted node DAO proposal // Returns the ID of the new proposal func SubmitProposal(rp *rocketpool.RocketPool, message string, payload []byte, opts *bind.TransactOpts) (uint64, common.Hash, error) { @@ -133,6 +245,16 @@ func SubmitProposal(rp *rocketpool.RocketPool, message string, payload []byte, o } +// Estimate the gas of CancelProposal +func EstimateCancelProposalGas(rp *rocketpool.RocketPool, proposalId uint64, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDAONodeTrustedProposals, err := getRocketDAONodeTrustedProposals(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketDAONodeTrustedProposals.GetTransactionGasInfo(opts, "cancel", big.NewInt(int64(proposalId))) +} + + // Cancel a submitted proposal func CancelProposal(rp *rocketpool.RocketPool, proposalId uint64, opts *bind.TransactOpts) (common.Hash, error) { rocketDAONodeTrustedProposals, err := getRocketDAONodeTrustedProposals(rp) @@ -147,6 +269,16 @@ func CancelProposal(rp *rocketpool.RocketPool, proposalId uint64, opts *bind.Tra } +// Estimate the gas of VoteOnProposal +func EstimateVoteOnProposalGas(rp *rocketpool.RocketPool, proposalId uint64, support bool, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDAONodeTrustedProposals, err := getRocketDAONodeTrustedProposals(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketDAONodeTrustedProposals.GetTransactionGasInfo(opts, "vote", big.NewInt(int64(proposalId)), support) +} + + // Vote on a submitted proposal func VoteOnProposal(rp *rocketpool.RocketPool, proposalId uint64, support bool, opts *bind.TransactOpts) (common.Hash, error) { rocketDAONodeTrustedProposals, err := getRocketDAONodeTrustedProposals(rp) @@ -161,6 +293,16 @@ func VoteOnProposal(rp *rocketpool.RocketPool, proposalId uint64, support bool, } +// Estimate the gas of ExecuteProposal +func EstimateExecuteProposalGas(rp *rocketpool.RocketPool, proposalId uint64, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDAONodeTrustedProposals, err := getRocketDAONodeTrustedProposals(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketDAONodeTrustedProposals.GetTransactionGasInfo(opts, "execute", big.NewInt(int64(proposalId))) +} + + // Execute a submitted proposal func ExecuteProposal(rp *rocketpool.RocketPool, proposalId uint64, opts *bind.TransactOpts) (common.Hash, error) { rocketDAONodeTrustedProposals, err := getRocketDAONodeTrustedProposals(rp) diff --git a/deposit/deposit.go b/deposit/deposit.go index c76ac4b8..41b1de9e 100644 --- a/deposit/deposit.go +++ b/deposit/deposit.go @@ -39,6 +39,16 @@ func GetExcessBalance(rp *rocketpool.RocketPool, opts *bind.CallOpts) (*big.Int, } +// Estimate the gas of Deposit +func EstimateDepositGas(rp *rocketpool.RocketPool, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDepositPool, err := getRocketDepositPool(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketDepositPool.GetTransactionGasInfo(opts, "deposit") +} + + // Make a deposit func Deposit(rp *rocketpool.RocketPool, opts *bind.TransactOpts) (common.Hash, error) { rocketDepositPool, err := getRocketDepositPool(rp) @@ -53,6 +63,16 @@ func Deposit(rp *rocketpool.RocketPool, opts *bind.TransactOpts) (common.Hash, e } +// Estimate the gas of AssignDeposits +func EstimateAssignDepositsGas(rp *rocketpool.RocketPool, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketDepositPool, err := getRocketDepositPool(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketDepositPool.GetTransactionGasInfo(opts, "assignDeposits") +} + + // Assign deposits func AssignDeposits(rp *rocketpool.RocketPool, opts *bind.TransactOpts) (common.Hash, error) { rocketDepositPool, err := getRocketDepositPool(rp) diff --git a/minipool/minipool-contract.go b/minipool/minipool-contract.go index 44259ee4..46b3097d 100644 --- a/minipool/minipool-contract.go +++ b/minipool/minipool-contract.go @@ -347,6 +347,12 @@ func (mp *Minipool) GetWithdrawalCredentials(opts *bind.CallOpts) (common.Hash, } +// Estimate the gas of Refund +func (mp *Minipool) EstimateRefundGas(opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + return mp.Contract.GetTransactionGasInfo(opts, "refund") +} + + // Refund node ETH from the minipool func (mp *Minipool) Refund(opts *bind.TransactOpts) (common.Hash, error) { hash, err := mp.Contract.Transact(opts, "refund") @@ -357,12 +363,18 @@ func (mp *Minipool) Refund(opts *bind.TransactOpts) (common.Hash, error) { } +// Estimate the gas of Payout +func (mp *Minipool) EstimatePayoutGas(confirm bool, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + return mp.Contract.GetTransactionGasInfo(opts, "payout", confirm) +} + + // Payout withdrawn ETH func (mp *Minipool) Payout(confirm bool, opts *bind.TransactOpts) (common.Hash, error) { if !confirm { return common.Hash{}, fmt.Errorf("Could not payout minipool %s: confirmation flag must be set to true", mp.Address.Hex()) } - hash, err := mp.Contract.Transact(opts, "payout", true) + hash, err := mp.Contract.Transact(opts, "payout", confirm) if err != nil { return common.Hash{}, fmt.Errorf("Could not payout minipool %s: %w", mp.Address.Hex(), err) } @@ -370,6 +382,12 @@ func (mp *Minipool) Payout(confirm bool, opts *bind.TransactOpts) (common.Hash, } +// Estimate the gas of Stake +func (mp *Minipool) EstimateStakeGas(validatorPubkey rptypes.ValidatorPubkey, validatorSignature rptypes.ValidatorSignature, depositDataRoot common.Hash, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + return mp.Contract.GetTransactionGasInfo(opts, "stake", validatorPubkey[:], validatorSignature[:], depositDataRoot) +} + + // Progress the prelaunch minipool to staking func (mp *Minipool) Stake(validatorPubkey rptypes.ValidatorPubkey, validatorSignature rptypes.ValidatorSignature, depositDataRoot common.Hash, opts *bind.TransactOpts) (common.Hash, error) { hash, err := mp.Contract.Transact(opts, "stake", validatorPubkey[:], validatorSignature[:], depositDataRoot) @@ -380,6 +398,12 @@ func (mp *Minipool) Stake(validatorPubkey rptypes.ValidatorPubkey, validatorSign } +// Estimate the gas of Withdraw +func (mp *Minipool) EstimateWithdrawGas(opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + return mp.Contract.GetTransactionGasInfo(opts, "withdraw") +} + + // Withdraw node balances & rewards from the withdrawable minipool and close it func (mp *Minipool) Withdraw(opts *bind.TransactOpts) (common.Hash, error) { hash, err := mp.Contract.Transact(opts, "withdraw") @@ -390,6 +414,12 @@ func (mp *Minipool) Withdraw(opts *bind.TransactOpts) (common.Hash, error) { } +// Estimate the gas of Dissolve +func (mp *Minipool) EstimateDissolveGas(opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + return mp.Contract.GetTransactionGasInfo(opts, "dissolve") +} + + // Dissolve the initialized or prelaunch minipool func (mp *Minipool) Dissolve(opts *bind.TransactOpts) (common.Hash, error) { hash, err := mp.Contract.Transact(opts, "dissolve") @@ -400,6 +430,12 @@ func (mp *Minipool) Dissolve(opts *bind.TransactOpts) (common.Hash, error) { } +// Estimate the gas of Close +func (mp *Minipool) EstimateCloseGas(opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + return mp.Contract.GetTransactionGasInfo(opts, "close") +} + + // Withdraw node balances from the dissolved minipool and close it func (mp *Minipool) Close(opts *bind.TransactOpts) (common.Hash, error) { hash, err := mp.Contract.Transact(opts, "close") diff --git a/minipool/status.go b/minipool/status.go index 3e8086c6..c654a166 100644 --- a/minipool/status.go +++ b/minipool/status.go @@ -26,6 +26,16 @@ func GetMinipoolNodeRewardAmount(rp *rocketpool.RocketPool, nodeFee float64, use } +// Estimate the gas of SubmitMinipoolWithdrawable +func EstimateSubmitMinipoolWithdrawableGas(rp *rocketpool.RocketPool, minipoolAddress common.Address, stakingStartBalance, stakingEndBalance *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketMinipoolStatus, err := getRocketMinipoolStatus(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketMinipoolStatus.GetTransactionGasInfo(opts, "submitMinipoolWithdrawable", minipoolAddress, stakingStartBalance, stakingEndBalance) +} + + // Submit a minipool withdrawable event func SubmitMinipoolWithdrawable(rp *rocketpool.RocketPool, minipoolAddress common.Address, stakingStartBalance, stakingEndBalance *big.Int, opts *bind.TransactOpts) (common.Hash, error) { rocketMinipoolStatus, err := getRocketMinipoolStatus(rp) diff --git a/network/balances.go b/network/balances.go index e4d8ffba..6d08e357 100644 --- a/network/balances.go +++ b/network/balances.go @@ -82,6 +82,16 @@ func GetETHUtilizationRate(rp *rocketpool.RocketPool, opts *bind.CallOpts) (floa } +// Estimate the gas of SubmitBalances +func EstimateSubmitBalancesGas(rp *rocketpool.RocketPool, block uint64, totalEth, stakingEth, rethSupply *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketNetworkBalances, err := getRocketNetworkBalances(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketNetworkBalances.GetTransactionGasInfo(opts, "submitBalances", big.NewInt(int64(block)), totalEth, stakingEth, rethSupply) +} + + // Submit network balances for an epoch func SubmitBalances(rp *rocketpool.RocketPool, block uint64, totalEth, stakingEth, rethSupply *big.Int, opts *bind.TransactOpts) (common.Hash, error) { rocketNetworkBalances, err := getRocketNetworkBalances(rp) diff --git a/network/prices.go b/network/prices.go index 3509eaee..25d2a26b 100644 --- a/network/prices.go +++ b/network/prices.go @@ -39,6 +39,16 @@ func GetRPLPrice(rp *rocketpool.RocketPool, opts *bind.CallOpts) (*big.Int, erro } +// Estimate the gas of Deposit +func EstimateDepositGas(rp *rocketpool.RocketPool, block uint64, rplPrice *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketNetworkPrices, err := getRocketNetworkPrices(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketNetworkPrices.GetTransactionGasInfo(opts, "submitPrices", big.NewInt(int64(block)), rplPrice) +} + + // Submit network prices for an epoch func SubmitPrices(rp *rocketpool.RocketPool, block uint64, rplPrice *big.Int, opts *bind.TransactOpts) (common.Hash, error) { rocketNetworkPrices, err := getRocketNetworkPrices(rp) diff --git a/node/deposit.go b/node/deposit.go index f43ad302..1ac16e8e 100644 --- a/node/deposit.go +++ b/node/deposit.go @@ -11,6 +11,16 @@ import ( "github.com/rocket-pool/rocketpool-go/utils/eth" ) +// Estimate the gas of Deposit +func EstimateDepositGas(rp *rocketpool.RocketPool, minimumNodeFee float64, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketNodeDeposit, err := getRocketNodeDeposit(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketNodeDeposit.GetTransactionGasInfo(opts, "deposit", eth.EthToWei(minimumNodeFee)) +} + + // Make a node deposit func Deposit(rp *rocketpool.RocketPool, minimumNodeFee float64, opts *bind.TransactOpts) (common.Hash, error) { rocketNodeDeposit, err := getRocketNodeDeposit(rp) diff --git a/node/node.go b/node/node.go index 1121043b..4e033bc9 100644 --- a/node/node.go +++ b/node/node.go @@ -222,6 +222,16 @@ func GetNodeTimezoneLocation(rp *rocketpool.RocketPool, nodeAddress common.Addre } +// Estimate the gas of RegisterNode +func EstimateRegisterNodeGas(rp *rocketpool.RocketPool, timezoneLocation string, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketNodeManager, err := getRocketNodeManager(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketNodeManager.GetTransactionGasInfo(opts, "registerNode", timezoneLocation) +} + + // Register a node func RegisterNode(rp *rocketpool.RocketPool, timezoneLocation string, opts *bind.TransactOpts) (common.Hash, error) { rocketNodeManager, err := getRocketNodeManager(rp) @@ -236,6 +246,16 @@ func RegisterNode(rp *rocketpool.RocketPool, timezoneLocation string, opts *bind } +// Estimate the gas of SetWithdrawalAddress +func EstimateSetWithdrawalAddressGas(rp *rocketpool.RocketPool, nodeAddress common.Address, withdrawalAddress common.Address, confirm bool, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketNodeManager, err := getRocketNodeManager(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketNodeManager.GetTransactionGasInfo(opts, "setWithdrawalAddress", nodeAddress, withdrawalAddress, confirm) +} + + // Set a node's withdrawal address func SetWithdrawalAddress(rp *rocketpool.RocketPool, nodeAddress common.Address, withdrawalAddress common.Address, confirm bool, opts *bind.TransactOpts) (common.Hash, error) { rocketNodeManager, err := getRocketNodeManager(rp) @@ -250,6 +270,16 @@ func SetWithdrawalAddress(rp *rocketpool.RocketPool, nodeAddress common.Address, } +// Estimate the gas of ConfirmWithdrawalAddress +func EstimateConfirmWithdrawalAddressGas(rp *rocketpool.RocketPool, nodeAddress common.Address, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketNodeManager, err := getRocketNodeManager(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketNodeManager.GetTransactionGasInfo(opts, "confirmWithdrawalAddress", nodeAddress) +} + + // Set a node's withdrawal address func ConfirmWithdrawalAddress(rp *rocketpool.RocketPool, nodeAddress common.Address, opts *bind.TransactOpts) (common.Hash, error) { rocketNodeManager, err := getRocketNodeManager(rp) @@ -264,6 +294,16 @@ func ConfirmWithdrawalAddress(rp *rocketpool.RocketPool, nodeAddress common.Addr } +// Estimate the gas of SetTimezoneLocation +func EstimateSetTimezoneLocationGas(rp *rocketpool.RocketPool, timezoneLocation string, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketNodeManager, err := getRocketNodeManager(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketNodeManager.GetTransactionGasInfo(opts, "setTimezoneLocation", timezoneLocation) +} + + // Set a node's timezone location func SetTimezoneLocation(rp *rocketpool.RocketPool, timezoneLocation string, opts *bind.TransactOpts) (common.Hash, error) { rocketNodeManager, err := getRocketNodeManager(rp) diff --git a/node/staking.go b/node/staking.go index 334ef006..43cea93b 100644 --- a/node/staking.go +++ b/node/staking.go @@ -109,6 +109,16 @@ func GetNodeMinipoolLimit(rp *rocketpool.RocketPool, nodeAddress common.Address, } +// Estimate the gas of Stake +func EstimateStakeGas(rp *rocketpool.RocketPool, rplAmount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketNodeStaking, err := getRocketNodeStaking(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketNodeStaking.GetTransactionGasInfo(opts, "stakeRPL", rplAmount) +} + + // Stake RPL func StakeRPL(rp *rocketpool.RocketPool, rplAmount *big.Int, opts *bind.TransactOpts) (common.Hash, error) { rocketNodeStaking, err := getRocketNodeStaking(rp) @@ -123,6 +133,16 @@ func StakeRPL(rp *rocketpool.RocketPool, rplAmount *big.Int, opts *bind.Transact } +// Estimate the gas of WithdrawRPL +func EstimateWithdrawRPLGas(rp *rocketpool.RocketPool, rplAmount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketNodeStaking, err := getRocketNodeStaking(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketNodeStaking.GetTransactionGasInfo(opts, "withdrawRPL", rplAmount) +} + + // Withdraw staked RPL func WithdrawRPL(rp *rocketpool.RocketPool, rplAmount *big.Int, opts *bind.TransactOpts) (common.Hash, error) { rocketNodeStaking, err := getRocketNodeStaking(rp) diff --git a/rewards/node.go b/rewards/node.go index cf9a6c75..6de2426c 100644 --- a/rewards/node.go +++ b/rewards/node.go @@ -50,6 +50,16 @@ func GetNodeClaimRewardsAmount(rp *rocketpool.RocketPool, claimerAddress common. } +// Estimate the gas of ClaimNodeRewards +func EstimateClaimNodeRewardsGas(rp *rocketpool.RocketPool, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketClaimNode, err := getRocketClaimNode(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return estimateClaimGas(rocketClaimNode, opts) +} + + // Claim node rewards func ClaimNodeRewards(rp *rocketpool.RocketPool, opts *bind.TransactOpts) (common.Hash, error) { rocketClaimNode, err := getRocketClaimNode(rp) diff --git a/rewards/rewards.go b/rewards/rewards.go index 4ebc2584..48edcec6 100644 --- a/rewards/rewards.go +++ b/rewards/rewards.go @@ -53,6 +53,12 @@ func getClaimRewardsAmount(claimsContract *rocketpool.Contract, claimsName strin } +// Estimate the gas of claim +func estimateClaimGas(claimsContract *rocketpool.Contract, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + return claimsContract.GetTransactionGasInfo(opts, "claim") +} + + // Claim rewards func claim(claimsContract *rocketpool.Contract, claimsName string, opts *bind.TransactOpts) (common.Hash, error) { hash, err := claimsContract.Transact(opts, "claim") diff --git a/rewards/trusted-node.go b/rewards/trusted-node.go index 03b547c1..edf2466d 100644 --- a/rewards/trusted-node.go +++ b/rewards/trusted-node.go @@ -50,6 +50,16 @@ func GetTrustedNodeClaimRewardsAmount(rp *rocketpool.RocketPool, claimerAddress } +// Estimate the gas of ClaimTrustedNodeRewards +func EstimateClaimTrustedNodeRewardsGas(rp *rocketpool.RocketPool, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketClaimTrustedNode, err := getRocketClaimTrustedNode(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return estimateClaimGas(rocketClaimTrustedNode, opts) +} + + // Claim trusted node rewards func ClaimTrustedNodeRewards(rp *rocketpool.RocketPool, opts *bind.TransactOpts) (common.Hash, error) { rocketClaimTrustedNode, err := getRocketClaimTrustedNode(rp) diff --git a/tokens/reth.go b/tokens/reth.go index a232ea6b..2a9125e1 100644 --- a/tokens/reth.go +++ b/tokens/reth.go @@ -46,6 +46,16 @@ func GetRETHAllowance(rp *rocketpool.RocketPool, owner, spender common.Address, } +// Estimate the gas of TransferRETH +func EstimateTransferRETHGas(rp *rocketpool.RocketPool, to common.Address, amount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketTokenRETH, err := getRocketTokenRETH(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return estimateTransferGas(rocketTokenRETH, "rETH", to, amount, opts) +} + + // Transfer rETH func TransferRETH(rp *rocketpool.RocketPool, to common.Address, amount *big.Int, opts *bind.TransactOpts) (common.Hash, error) { rocketTokenRETH, err := getRocketTokenRETH(rp) @@ -56,6 +66,16 @@ func TransferRETH(rp *rocketpool.RocketPool, to common.Address, amount *big.Int, } +// Estimate the gas of ApproveRETH +func EstimateApproveRETHGas(rp *rocketpool.RocketPool, spender common.Address, amount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketTokenRETH, err := getRocketTokenRETH(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return estimateApproveGas(rocketTokenRETH, "rETH", spender, amount, opts) +} + + // Approve a rETH spender func ApproveRETH(rp *rocketpool.RocketPool, spender common.Address, amount *big.Int, opts *bind.TransactOpts) (common.Hash, error) { rocketTokenRETH, err := getRocketTokenRETH(rp) @@ -66,6 +86,16 @@ func ApproveRETH(rp *rocketpool.RocketPool, spender common.Address, amount *big. } +// Estimate the gas of TransferFromRETH +func EstimateTransferFromRETHGas(rp *rocketpool.RocketPool, from, to common.Address, amount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketTokenRETH, err := getRocketTokenRETH(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return estimateTransferFromGas(rocketTokenRETH, "rETH", from, to, amount, opts) +} + + // Transfer rETH from a sender func TransferFromRETH(rp *rocketpool.RocketPool, from, to common.Address, amount *big.Int, opts *bind.TransactOpts) (common.Hash, error) { rocketTokenRETH, err := getRocketTokenRETH(rp) @@ -161,6 +191,16 @@ func GetRETHCollateralRate(rp *rocketpool.RocketPool, opts *bind.CallOpts) (floa } +// Estimate the gas of BurnRETH +func EstimateBurnRETHGas(rp *rocketpool.RocketPool, amount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketTokenRETH, err := getRocketTokenRETH(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketTokenRETH.GetTransactionGasInfo(opts, "burn", amount) +} + + // Burn rETH for ETH func BurnRETH(rp *rocketpool.RocketPool, amount *big.Int, opts *bind.TransactOpts) (common.Hash, error) { rocketTokenRETH, err := getRocketTokenRETH(rp) diff --git a/tokens/rpl-fixed.go b/tokens/rpl-fixed.go index 6e777ddd..203910dd 100644 --- a/tokens/rpl-fixed.go +++ b/tokens/rpl-fixed.go @@ -44,6 +44,16 @@ func GetFixedSupplyRPLAllowance(rp *rocketpool.RocketPool, owner, spender common } +// Estimate the gas of TransferFixedSupplyRPL +func EstimateTransferFixedSupplyRPLGas(rp *rocketpool.RocketPool, to common.Address, amount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketTokenFixedSupplyRPL, err := getRocketTokenRPLFixedSupply(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return estimateTransferGas(rocketTokenFixedSupplyRPL, "fixed-supply RPL", to, amount, opts) +} + + // Transfer fixed-supply RPL func TransferFixedSupplyRPL(rp *rocketpool.RocketPool, to common.Address, amount *big.Int, opts *bind.TransactOpts) (common.Hash, error) { rocketTokenFixedSupplyRPL, err := getRocketTokenRPLFixedSupply(rp) @@ -54,6 +64,16 @@ func TransferFixedSupplyRPL(rp *rocketpool.RocketPool, to common.Address, amount } +// Estimate the gas of ApproveFixedSupplyRPL +func EstimateApproveFixedSupplyRPLGas(rp *rocketpool.RocketPool, spender common.Address, amount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketTokenFixedSupplyRPL, err := getRocketTokenRPLFixedSupply(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return estimateApproveGas(rocketTokenFixedSupplyRPL, "fixed-supply RPL", spender, amount, opts) +} + + // Approve an fixed-supply RPL spender func ApproveFixedSupplyRPL(rp *rocketpool.RocketPool, spender common.Address, amount *big.Int, opts *bind.TransactOpts) (common.Hash, error) { rocketTokenFixedSupplyRPL, err := getRocketTokenRPLFixedSupply(rp) @@ -64,6 +84,16 @@ func ApproveFixedSupplyRPL(rp *rocketpool.RocketPool, spender common.Address, am } +// Estimate the gas of TransferFromFixedSupplyRPL +func EstimateTransferFromFixedSupplyRPLGas(rp *rocketpool.RocketPool, from, to common.Address, amount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketTokenFixedSupplyRPL, err := getRocketTokenRPLFixedSupply(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return estimateTransferFromGas(rocketTokenFixedSupplyRPL, "fixed-supply RPL", from, to, amount, opts) +} + + // Transfer fixed-supply RPL from a sender func TransferFromFixedSupplyRPL(rp *rocketpool.RocketPool, from, to common.Address, amount *big.Int, opts *bind.TransactOpts) (common.Hash, error) { rocketTokenFixedSupplyRPL, err := getRocketTokenRPLFixedSupply(rp) diff --git a/tokens/rpl.go b/tokens/rpl.go index f3520e60..eeb0fe7e 100644 --- a/tokens/rpl.go +++ b/tokens/rpl.go @@ -45,6 +45,16 @@ func GetRPLAllowance(rp *rocketpool.RocketPool, owner, spender common.Address, o } +// Estimate the gas of TransferRPL +func EstimateTransferRPLGas(rp *rocketpool.RocketPool, to common.Address, amount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketTokenRPL, err := getRocketTokenRPL(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return estimateTransferGas(rocketTokenRPL, "RPL", to, amount, opts) +} + + // Transfer RPL func TransferRPL(rp *rocketpool.RocketPool, to common.Address, amount *big.Int, opts *bind.TransactOpts) (common.Hash, error) { rocketTokenRPL, err := getRocketTokenRPL(rp) @@ -55,6 +65,16 @@ func TransferRPL(rp *rocketpool.RocketPool, to common.Address, amount *big.Int, } +// Estimate the gas of ApproveRPL +func EstimateApproveRPLGas(rp *rocketpool.RocketPool, spender common.Address, amount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketTokenRPL, err := getRocketTokenRPL(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return estimateApproveGas(rocketTokenRPL, "RPL", spender, amount, opts) +} + + // Approve an RPL spender func ApproveRPL(rp *rocketpool.RocketPool, spender common.Address, amount *big.Int, opts *bind.TransactOpts) (common.Hash, error) { rocketTokenRPL, err := getRocketTokenRPL(rp) @@ -65,6 +85,16 @@ func ApproveRPL(rp *rocketpool.RocketPool, spender common.Address, amount *big.I } +// Estimate the gas of TransferFromRPL +func EstimateTransferFromRPLGas(rp *rocketpool.RocketPool, from, to common.Address, amount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketTokenRPL, err := getRocketTokenRPL(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return estimateTransferFromGas(rocketTokenRPL, "RPL", from, to, amount, opts) +} + + // Transfer RPL from a sender func TransferFromRPL(rp *rocketpool.RocketPool, from, to common.Address, amount *big.Int, opts *bind.TransactOpts) (common.Hash, error) { rocketTokenRPL, err := getRocketTokenRPL(rp) @@ -80,6 +110,16 @@ func TransferFromRPL(rp *rocketpool.RocketPool, from, to common.Address, amount // +// Estimate the gas of MintInflationRPL +func EstimateMintInflationRPLGas(rp *rocketpool.RocketPool, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketTokenRPL, err := getRocketTokenRPL(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketTokenRPL.GetTransactionGasInfo(opts, "inflationMintTokens") +} + + // Mint new RPL tokens from inflation func MintInflationRPL(rp *rocketpool.RocketPool, opts *bind.TransactOpts) (common.Hash, error) { rocketTokenRPL, err := getRocketTokenRPL(rp) @@ -94,6 +134,16 @@ func MintInflationRPL(rp *rocketpool.RocketPool, opts *bind.TransactOpts) (commo } +// Estimate the gas of SwapFixedSupplyRPLForRPL +func EstimateSwapFixedSupplyRPLForRPLtGas(rp *rocketpool.RocketPool, amount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + rocketTokenRPL, err := getRocketTokenRPL(rp) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketTokenRPL.GetTransactionGasInfo(opts, "swapTokens", amount) +} + + // Swap fixed-supply RPL for new RPL tokens func SwapFixedSupplyRPLForRPL(rp *rocketpool.RocketPool, amount *big.Int, opts *bind.TransactOpts) (common.Hash, error) { rocketTokenRPL, err := getRocketTokenRPL(rp) diff --git a/tokens/tokens.go b/tokens/tokens.go index e912348c..82ffc56f 100644 --- a/tokens/tokens.go +++ b/tokens/tokens.go @@ -111,6 +111,12 @@ func allowance(tokenContract *rocketpool.Contract, tokenName string, owner, spen } +// Estimate the gas of transfer +func estimateTransferGas(tokenContract *rocketpool.Contract, tokenName string, to common.Address, amount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + return tokenContract.GetTransactionGasInfo(opts, "transfer", to, amount) +} + + // Transfer tokens to an address func transfer(tokenContract *rocketpool.Contract, tokenName string, to common.Address, amount *big.Int, opts *bind.TransactOpts) (common.Hash, error) { hash, err := tokenContract.Transact(opts, "transfer", to, amount) @@ -121,6 +127,12 @@ func transfer(tokenContract *rocketpool.Contract, tokenName string, to common.Ad } +// Estimate the gas of approve +func estimateApproveGas(tokenContract *rocketpool.Contract, tokenName string, spender common.Address, amount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + return tokenContract.GetTransactionGasInfo(opts, "approve", spender, amount) +} + + // Approve a token allowance for a spender func approve(tokenContract *rocketpool.Contract, tokenName string, spender common.Address, amount *big.Int, opts *bind.TransactOpts) (common.Hash, error) { hash, err := tokenContract.Transact(opts, "approve", spender, amount) @@ -131,6 +143,12 @@ func approve(tokenContract *rocketpool.Contract, tokenName string, spender commo } +// Estimate the gas of transferFrom +func estimateTransferFromGas(tokenContract *rocketpool.Contract, tokenName string, from, to common.Address, amount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + return tokenContract.GetTransactionGasInfo(opts, "transferFrom", from, to, amount) +} + + // Transfer tokens from a sender to an address func transferFrom(tokenContract *rocketpool.Contract, tokenName string, from, to common.Address, amount *big.Int, opts *bind.TransactOpts) (common.Hash, error) { hash, err := tokenContract.Transact(opts, "transferFrom", from, to, amount) From 3ba5c9711d810bbc965e7c1a6010a65e8d2efce5 Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Tue, 4 May 2021 00:38:40 -0400 Subject: [PATCH 2/8] Added a gas estimator for sending ETH itself --- utils/eth/transactions.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/utils/eth/transactions.go b/utils/eth/transactions.go index 69ca2e78..b4946cb0 100644 --- a/utils/eth/transactions.go +++ b/utils/eth/transactions.go @@ -9,8 +9,47 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethclient" + "github.com/rocket-pool/rocketpool-go/rocketpool" ) +// Estimate the gas of SendTransaction +func EstimateSendTransactionGas(client *ethclient.Client, toAddress common.Address, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + + // User-defined settings + response := rocketpool.GasInfo { + ReqGasPrice: opts.GasPrice, + ReqGasLimit: opts.GasLimit, + } + + // Set default value + value := opts.Value + if value == nil { + value = big.NewInt(0) + } + + // Get suggested gas price + gasPrice, err := client.SuggestGasPrice(context.Background()) + if err != nil { + return rocketpool.GasInfo{}, err + } + response.EstGasPrice = gasPrice + + // Estimate gas limit + gasLimit, err := client.EstimateGas(context.Background(), ethereum.CallMsg{ + From: opts.From, + To: &toAddress, + GasPrice: gasPrice, + Value: value, + }) + if err != nil { + return rocketpool.GasInfo{}, err + } + response.EstGasLimit = gasLimit + + return response, err +} + + // Send a transaction to an address func SendTransaction(client *ethclient.Client, toAddress common.Address, opts *bind.TransactOpts) (common.Hash, error) { var err error From 832bf5a259bab2e93e18153cd4c6c97d018074f7 Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Wed, 5 May 2021 01:04:53 -0400 Subject: [PATCH 3/8] Typo fix --- tokens/rpl.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tokens/rpl.go b/tokens/rpl.go index eeb0fe7e..567f1858 100644 --- a/tokens/rpl.go +++ b/tokens/rpl.go @@ -135,7 +135,7 @@ func MintInflationRPL(rp *rocketpool.RocketPool, opts *bind.TransactOpts) (commo // Estimate the gas of SwapFixedSupplyRPLForRPL -func EstimateSwapFixedSupplyRPLForRPLtGas(rp *rocketpool.RocketPool, amount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { +func EstimateSwapFixedSupplyRPLForRPLGas(rp *rocketpool.RocketPool, amount *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { rocketTokenRPL, err := getRocketTokenRPL(rp) if err != nil { return rocketpool.GasInfo{}, err From fcf25901f065b9eb2c9a89b234c00442571cafb0 Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Wed, 5 May 2021 22:48:32 -0400 Subject: [PATCH 4/8] Added gas estimators to the ODAO settings functions --- settings/trustednode/members.go | 18 ++++++++++++++++++ settings/trustednode/proposals.go | 15 +++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/settings/trustednode/members.go b/settings/trustednode/members.go index cfa6c8a1..64d80d8f 100644 --- a/settings/trustednode/members.go +++ b/settings/trustednode/members.go @@ -43,6 +43,9 @@ func BootstrapQuorum(rp *rocketpool.RocketPool, value float64, opts *bind.Transa func ProposeQuorum(rp *rocketpool.RocketPool, value float64, opts *bind.TransactOpts) (uint64, common.Hash, error) { return trustednodedao.ProposeSetUint(rp, fmt.Sprintf("set %s", QuorumSettingPath), MembersSettingsContractName, QuorumSettingPath, eth.EthToWei(value), opts) } +func EstimateProposeQuorumGas(rp *rocketpool.RocketPool, value float64, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + return trustednodedao.EstimateProposeSetUintGas(rp, fmt.Sprintf("set %s", QuorumSettingPath), MembersSettingsContractName, QuorumSettingPath, eth.EthToWei(value), opts) +} // RPL bond required for a member @@ -63,6 +66,9 @@ func BootstrapRPLBond(rp *rocketpool.RocketPool, value *big.Int, opts *bind.Tran func ProposeRPLBond(rp *rocketpool.RocketPool, value *big.Int, opts *bind.TransactOpts) (uint64, common.Hash, error) { return trustednodedao.ProposeSetUint(rp, fmt.Sprintf("set %s", RPLBondSettingPath), MembersSettingsContractName, RPLBondSettingPath, value, opts) } +func EstimateProposeRPLBondGas(rp *rocketpool.RocketPool, value *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + return trustednodedao.EstimateProposeSetUintGas(rp, fmt.Sprintf("set %s", RPLBondSettingPath), MembersSettingsContractName, RPLBondSettingPath, value, opts) +} // The maximum number of unbonded minipools a member can run @@ -83,6 +89,9 @@ func BootstrapMinipoolUnbondedMax(rp *rocketpool.RocketPool, value uint64, opts func ProposeMinipoolUnbondedMax(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (uint64, common.Hash, error) { return trustednodedao.ProposeSetUint(rp, fmt.Sprintf("set %s", MinipoolUnbondedMaxSettingPath), MembersSettingsContractName, MinipoolUnbondedMaxSettingPath, big.NewInt(int64(value)), opts) } +func EstimateProposeMinipoolUnbondedMaxGas(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + return trustednodedao.EstimateProposeSetUintGas(rp, fmt.Sprintf("set %s", MinipoolUnbondedMaxSettingPath), MembersSettingsContractName, MinipoolUnbondedMaxSettingPath, big.NewInt(int64(value)), opts) +} // The period a member must wait for before submitting another challenge, in blocks @@ -103,6 +112,9 @@ func BootstrapChallengeCooldown(rp *rocketpool.RocketPool, value uint64, opts *b func ProposeChallengeCooldown(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (uint64, common.Hash, error) { return trustednodedao.ProposeSetUint(rp, fmt.Sprintf("set %s", ChallengeCooldownSettingPath), MembersSettingsContractName, ChallengeCooldownSettingPath, big.NewInt(int64(value)), opts) } +func EstimateProposeChallengeCooldownGas(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + return trustednodedao.EstimateProposeSetUintGas(rp, fmt.Sprintf("set %s", ChallengeCooldownSettingPath), MembersSettingsContractName, ChallengeCooldownSettingPath, big.NewInt(int64(value)), opts) +} // The period during which a member can respond to a challenge, in blocks @@ -123,6 +135,9 @@ func BootstrapChallengeWindow(rp *rocketpool.RocketPool, value uint64, opts *bin func ProposeChallengeWindow(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (uint64, common.Hash, error) { return trustednodedao.ProposeSetUint(rp, fmt.Sprintf("set %s", ChallengeWindowSettingPath), MembersSettingsContractName, ChallengeWindowSettingPath, big.NewInt(int64(value)), opts) } +func EstimateProposeChallengeWindowGas(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + return trustednodedao.EstimateProposeSetUintGas(rp, fmt.Sprintf("set %s", ChallengeWindowSettingPath), MembersSettingsContractName, ChallengeWindowSettingPath, big.NewInt(int64(value)), opts) +} // The fee for a non-member to challenge a member, in wei @@ -143,6 +158,9 @@ func BootstrapChallengeCost(rp *rocketpool.RocketPool, value *big.Int, opts *bin func ProposeChallengeCost(rp *rocketpool.RocketPool, value *big.Int, opts *bind.TransactOpts) (uint64, common.Hash, error) { return trustednodedao.ProposeSetUint(rp, fmt.Sprintf("set %s", ChallengeCostSettingPath), MembersSettingsContractName, ChallengeCostSettingPath, value, opts) } +func EstimateProposeChallengeCostGas(rp *rocketpool.RocketPool, value *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + return trustednodedao.EstimateProposeSetUintGas(rp, fmt.Sprintf("set %s", ChallengeCostSettingPath), MembersSettingsContractName, ChallengeCostSettingPath, value, opts) +} // Get contracts diff --git a/settings/trustednode/proposals.go b/settings/trustednode/proposals.go index 0b87e569..18eaccf8 100644 --- a/settings/trustednode/proposals.go +++ b/settings/trustednode/proposals.go @@ -41,6 +41,9 @@ func BootstrapProposalCooldown(rp *rocketpool.RocketPool, value uint64, opts *bi func ProposeProposalCooldown(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (uint64, common.Hash, error) { return trustednodedao.ProposeSetUint(rp, fmt.Sprintf("set %s", CooldownSettingPath), ProposalsSettingsContractName, CooldownSettingPath, big.NewInt(int64(value)), opts) } +func EstimateProposeProposalCooldownGas(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + return trustednodedao.EstimateProposeSetUintGas(rp, fmt.Sprintf("set %s", CooldownSettingPath), ProposalsSettingsContractName, CooldownSettingPath, big.NewInt(int64(value)), opts) +} // The period a proposal can be voted on for in blocks @@ -61,6 +64,9 @@ func BootstrapProposalVoteBlocks(rp *rocketpool.RocketPool, value uint64, opts * func ProposeProposalVoteBlocks(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (uint64, common.Hash, error) { return trustednodedao.ProposeSetUint(rp, fmt.Sprintf("set %s", VoteBlocksSettingPath), ProposalsSettingsContractName, VoteBlocksSettingPath, big.NewInt(int64(value)), opts) } +func EstimateProposeProposalVoteBlocksGas(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + return trustednodedao.EstimateProposeSetUintGas(rp, fmt.Sprintf("set %s", VoteBlocksSettingPath), ProposalsSettingsContractName, VoteBlocksSettingPath, big.NewInt(int64(value)), opts) +} // The delay after creation before a proposal can be voted on in blocks @@ -81,6 +87,9 @@ func BootstrapProposalVoteDelayBlocks(rp *rocketpool.RocketPool, value uint64, o func ProposeProposalVoteDelayBlocks(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (uint64, common.Hash, error) { return trustednodedao.ProposeSetUint(rp, fmt.Sprintf("set %s", VoteDelayBlocksSettingPath), ProposalsSettingsContractName, VoteDelayBlocksSettingPath, big.NewInt(int64(value)), opts) } +func EstimateProposeProposalVoteDelayBlocksGas(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + return trustednodedao.EstimateProposeSetUintGas(rp, fmt.Sprintf("set %s", VoteDelayBlocksSettingPath), ProposalsSettingsContractName, VoteDelayBlocksSettingPath, big.NewInt(int64(value)), opts) +} // The period during which a passed proposal can be executed in blocks @@ -101,6 +110,9 @@ func BootstrapProposalExecuteBlocks(rp *rocketpool.RocketPool, value uint64, opt func ProposeProposalExecuteBlocks(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (uint64, common.Hash, error) { return trustednodedao.ProposeSetUint(rp, fmt.Sprintf("set %s", ExecuteBlocksSettingPath), ProposalsSettingsContractName, ExecuteBlocksSettingPath, big.NewInt(int64(value)), opts) } +func EstimateProposeProposalExecuteBlocksGas(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + return trustednodedao.EstimateProposeSetUintGas(rp, fmt.Sprintf("set %s", ExecuteBlocksSettingPath), ProposalsSettingsContractName, ExecuteBlocksSettingPath, big.NewInt(int64(value)), opts) +} // The period during which an action can be performed on an executed proposal in blocks @@ -121,6 +133,9 @@ func BootstrapProposalActionBlocks(rp *rocketpool.RocketPool, value uint64, opts func ProposeProposalActionBlocks(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (uint64, common.Hash, error) { return trustednodedao.ProposeSetUint(rp, fmt.Sprintf("set %s", ActionBlocksSettingPath), ProposalsSettingsContractName, ActionBlocksSettingPath, big.NewInt(int64(value)), opts) } +func EstimateProposeProposalActionBlocksGas(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { + return trustednodedao.EstimateProposeSetUintGas(rp, fmt.Sprintf("set %s", ActionBlocksSettingPath), ProposalsSettingsContractName, ActionBlocksSettingPath, big.NewInt(int64(value)), opts) +} // Get contracts From a0ed5ca12883a6d08448ab564f4d49203c792399 Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Sun, 9 May 2021 23:02:10 -0400 Subject: [PATCH 5/8] Changed the gas estimator to use a multiplier instead of a flat pad --- rocketpool/contract.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/rocketpool/contract.go b/rocketpool/contract.go index e7f132bb..b4e19456 100644 --- a/rocketpool/contract.go +++ b/rocketpool/contract.go @@ -1,24 +1,24 @@ package rocketpool import ( - "bytes" - "context" - "errors" - "fmt" - "math/big" - "reflect" - - "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/ethclient" + "bytes" + "context" + "errors" + "fmt" + "math/big" + "reflect" + + "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/ethclient" ) // Transaction settings const ( - GasLimitPadding = 100000 + GasLimitMultiplier float64 = 1.5 MaxGasLimit = 12000000 ) @@ -175,7 +175,7 @@ func (c *Contract) estimateGasLimit(opts *bind.TransactOpts, input []byte) (uint } // Pad and return gas limit - gasLimit += GasLimitPadding + gasLimit = uint64(float64(gasLimit) * GasLimitMultiplier) if gasLimit > MaxGasLimit { gasLimit = MaxGasLimit } return gasLimit, nil From 9e182fa0d1816c6f3aaaec22c302e71cae75bf38 Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Mon, 10 May 2021 00:19:16 -0400 Subject: [PATCH 6/8] Added email validation --- dao/trustednode/dao.go | 13 +++++++++++-- dao/trustednode/proposals.go | 25 +++++++++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/dao/trustednode/dao.go b/dao/trustednode/dao.go index 852be62b..7baf06e4 100644 --- a/dao/trustednode/dao.go +++ b/dao/trustednode/dao.go @@ -3,6 +3,7 @@ package trustednode import ( "fmt" "math/big" + "net/mail" "sync" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -411,7 +412,11 @@ func EstimateBootstrapMemberGas(rp *rocketpool.RocketPool, id, email string, nod if err != nil { return rocketpool.GasInfo{}, err } - return rocketDAONodeTrusted.GetTransactionGasInfo(opts, "bootstrapMember", id, email, nodeAddress) + address, err := mail.ParseAddress(email) + if err != nil { + return rocketpool.GasInfo{}, err + } + return rocketDAONodeTrusted.GetTransactionGasInfo(opts, "bootstrapMember", id, address.Address, nodeAddress) } @@ -421,7 +426,11 @@ func BootstrapMember(rp *rocketpool.RocketPool, id, email string, nodeAddress co if err != nil { return common.Hash{}, err } - hash, err := rocketDAONodeTrusted.Transact(opts, "bootstrapMember", id, email, nodeAddress) + address, err := mail.ParseAddress(email) + if err != nil { + return common.Hash{}, err + } + hash, err := rocketDAONodeTrusted.Transact(opts, "bootstrapMember", id, address.Address, nodeAddress) if err != nil { return common.Hash{}, fmt.Errorf("Could not bootstrap trusted node member %s: %w", id, err) } diff --git a/dao/trustednode/proposals.go b/dao/trustednode/proposals.go index c817c948..16eed20f 100644 --- a/dao/trustednode/proposals.go +++ b/dao/trustednode/proposals.go @@ -3,6 +3,7 @@ package trustednode import ( "fmt" "math/big" + "net/mail" "sync" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -18,7 +19,11 @@ func EstimateProposeInviteMemberGas(rp *rocketpool.RocketPool, message string, n if err != nil { return rocketpool.GasInfo{}, err } - payload, err := rocketDAONodeTrustedProposals.ABI.Pack("proposalInvite", newMemberId, newMemberEmail, newMemberAddress) + emailAddress, err := mail.ParseAddress(newMemberEmail) + if err != nil { + return rocketpool.GasInfo{}, err + } + payload, err := rocketDAONodeTrustedProposals.ABI.Pack("proposalInvite", newMemberId, emailAddress.Address, newMemberAddress) if err != nil { return rocketpool.GasInfo{}, fmt.Errorf("Could not encode invite member proposal payload: %w", err) } @@ -32,7 +37,11 @@ func ProposeInviteMember(rp *rocketpool.RocketPool, message string, newMemberAdd if err != nil { return 0, common.Hash{}, err } - payload, err := rocketDAONodeTrustedProposals.ABI.Pack("proposalInvite", newMemberId, newMemberEmail, newMemberAddress) + emailAddress, err := mail.ParseAddress(newMemberEmail) + if err != nil { + return 0, common.Hash{}, err + } + payload, err := rocketDAONodeTrustedProposals.ABI.Pack("proposalInvite", newMemberId, emailAddress.Address, newMemberAddress) if err != nil { return 0, common.Hash{}, fmt.Errorf("Could not encode invite member proposal payload: %w", err) } @@ -74,7 +83,11 @@ func EstimateProposeReplaceMemberGas(rp *rocketpool.RocketPool, message string, if err != nil { return rocketpool.GasInfo{}, err } - payload, err := rocketDAONodeTrustedProposals.ABI.Pack("proposalReplace", memberAddress, newMemberId, newMemberEmail, newMemberAddress) + emailAddress, err := mail.ParseAddress(newMemberEmail) + if err != nil { + return rocketpool.GasInfo{}, err + } + payload, err := rocketDAONodeTrustedProposals.ABI.Pack("proposalReplace", memberAddress, newMemberId, emailAddress.Address, newMemberAddress) if err != nil { return rocketpool.GasInfo{}, fmt.Errorf("Could not encode replace member proposal payload: %w", err) } @@ -88,7 +101,11 @@ func ProposeReplaceMember(rp *rocketpool.RocketPool, message string, memberAddre if err != nil { return 0, common.Hash{}, err } - payload, err := rocketDAONodeTrustedProposals.ABI.Pack("proposalReplace", memberAddress, newMemberId, newMemberEmail, newMemberAddress) + emailAddress, err := mail.ParseAddress(newMemberEmail) + if err != nil { + return 0, common.Hash{}, err + } + payload, err := rocketDAONodeTrustedProposals.ABI.Pack("proposalReplace", memberAddress, newMemberId, emailAddress.Address, newMemberAddress) if err != nil { return 0, common.Hash{}, fmt.Errorf("Could not encode replace member proposal payload: %w", err) } From e31351964248ab61274e991d90e2a3ac2fe61f0f Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Thu, 13 May 2021 00:41:58 -0400 Subject: [PATCH 7/8] Updated inflation and reward functions with timing instead of blocks --- node/staking.go | 12 +++---- settings/protocol/inflation.go | 20 +++++------ settings/protocol/rewards.go | 18 +++++----- tests/node/staking_test.go | 42 +++++++++++------------ tests/rewards/node_test.go | 34 +++++++++--------- tests/rewards/trusted_node_test.go | 24 +++++++------ tests/settings/protocol/inflation_test.go | 30 ++++++++-------- tests/settings/protocol/rewards_test.go | 24 ++++++------- tests/tokens/rpl_test.go | 22 ++++++------ 9 files changed, 117 insertions(+), 109 deletions(-) diff --git a/node/staking.go b/node/staking.go index 43cea93b..f6713fcb 100644 --- a/node/staking.go +++ b/node/staking.go @@ -81,17 +81,17 @@ func GetNodeMinimumRPLStake(rp *rocketpool.RocketPool, nodeAddress common.Addres } -// Get the block a node last staked RPL at -func GetNodeRPLStakedBlock(rp *rocketpool.RocketPool, nodeAddress common.Address, opts *bind.CallOpts) (uint64, error) { +// Get the time a node last staked RPL +func GetNodeRPLStakedTime(rp *rocketpool.RocketPool, nodeAddress common.Address, opts *bind.CallOpts) (uint64, error) { rocketNodeStaking, err := getRocketNodeStaking(rp) if err != nil { return 0, err } - nodeRplStakedBlock := new(*big.Int) - if err := rocketNodeStaking.Call(opts, nodeRplStakedBlock, "getNodeRPLStakedBlock", nodeAddress); err != nil { - return 0, fmt.Errorf("Could not get node RPL staked block: %w", err) + nodeRplStakedTime := new(*big.Int) + if err := rocketNodeStaking.Call(opts, nodeRplStakedTime, "getNodeRPLStakedTime", nodeAddress); err != nil { + return 0, fmt.Errorf("Could not get node RPL staked time: %w", err) } - return (*nodeRplStakedBlock).Uint64(), nil + return (*nodeRplStakedTime).Uint64(), nil } diff --git a/settings/protocol/inflation.go b/settings/protocol/inflation.go index 8cef9b63..abf01901 100644 --- a/settings/protocol/inflation.go +++ b/settings/protocol/inflation.go @@ -34,36 +34,36 @@ func BootstrapInflationIntervalRate(rp *rocketpool.RocketPool, value float64, op } -// RPL inflation interval in blocks -func GetInflationIntervalBlocks(rp *rocketpool.RocketPool, opts *bind.CallOpts) (uint64, error) { +// RPL inflation interval time +func GetInflationIntervalTime(rp *rocketpool.RocketPool, opts *bind.CallOpts) (uint64, error) { inflationSettingsContract, err := getInflationSettingsContract(rp) if err != nil { return 0, err } value := new(*big.Int) - if err := inflationSettingsContract.Call(opts, value, "getInflationIntervalBlocks"); err != nil { + if err := inflationSettingsContract.Call(opts, value, "getInflationIntervalTime"); err != nil { return 0, fmt.Errorf("Could not get inflation interval: %w", err) } return (*value).Uint64(), nil } -func BootstrapInflationIntervalBlocks(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (common.Hash, error) { - return protocoldao.BootstrapUint(rp, InflationSettingsContractName, "rpl.inflation.interval.blocks", big.NewInt(int64(value)), opts) +func BootstrapInflationIntervalTime(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (common.Hash, error) { + return protocoldao.BootstrapUint(rp, InflationSettingsContractName, "rpl.inflation.interval.time", big.NewInt(int64(value)), opts) } -// RPL inflation start block -func GetInflationStartBlock(rp *rocketpool.RocketPool, opts *bind.CallOpts) (uint64, error) { +// RPL inflation start time +func GetInflationStartTime(rp *rocketpool.RocketPool, opts *bind.CallOpts) (uint64, error) { inflationSettingsContract, err := getInflationSettingsContract(rp) if err != nil { return 0, err } value := new(*big.Int) - if err := inflationSettingsContract.Call(opts, value, "getInflationIntervalStartBlock"); err != nil { - return 0, fmt.Errorf("Could not get inflation start block: %w", err) + if err := inflationSettingsContract.Call(opts, value, "getInflationIntervalStartTime"); err != nil { + return 0, fmt.Errorf("Could not get inflation start time: %w", err) } return (*value).Uint64(), nil } -func BootstrapInflationStartBlock(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (common.Hash, error) { +func BootstrapInflationStartTime(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (common.Hash, error) { return protocoldao.BootstrapUint(rp, InflationSettingsContractName, "rpl.inflation.interval.start", big.NewInt(int64(value)), opts) } diff --git a/settings/protocol/rewards.go b/settings/protocol/rewards.go index 508ec7c3..a0e06f29 100644 --- a/settings/protocol/rewards.go +++ b/settings/protocol/rewards.go @@ -31,15 +31,15 @@ func GetRewardsClaimerPerc(rp *rocketpool.RocketPool, contractName string, opts } -// The block that a claimer's share was last updated at -func GetRewardsClaimerPercBlockUpdated(rp *rocketpool.RocketPool, contractName string, opts *bind.CallOpts) (uint64, error) { +// The time that a claimer's share was last updated +func GetRewardsClaimerPercTimeUpdated(rp *rocketpool.RocketPool, contractName string, opts *bind.CallOpts) (uint64, error) { rewardsSettingsContract, err := getRewardsSettingsContract(rp) if err != nil { return 0, err } value := new(*big.Int) - if err := rewardsSettingsContract.Call(opts, value, "getRewardsClaimerPercBlockUpdated", contractName); err != nil { - return 0, fmt.Errorf("Could not get rewards claimer updated block: %w", err) + if err := rewardsSettingsContract.Call(opts, value, "getRewardsClaimerPercTimeUpdated", contractName); err != nil { + return 0, fmt.Errorf("Could not get rewards claimer updated time: %w", err) } return (*value).Uint64(), nil } @@ -59,20 +59,20 @@ func GetRewardsClaimersPercTotal(rp *rocketpool.RocketPool, opts *bind.CallOpts) } -// Rewards claim interval in blocks -func GetRewardsClaimIntervalBlocks(rp *rocketpool.RocketPool, opts *bind.CallOpts) (uint64, error) { +// Rewards claim interval time +func GetRewardsClaimIntervalTime(rp *rocketpool.RocketPool, opts *bind.CallOpts) (uint64, error) { rewardsSettingsContract, err := getRewardsSettingsContract(rp) if err != nil { return 0, err } value := new(*big.Int) - if err := rewardsSettingsContract.Call(opts, value, "getRewardsClaimIntervalBlocks"); err != nil { + if err := rewardsSettingsContract.Call(opts, value, "getRewardsClaimIntervalTime"); err != nil { return 0, fmt.Errorf("Could not get rewards claim interval: %w", err) } return (*value).Uint64(), nil } -func BootstrapRewardsClaimIntervalBlocks(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (common.Hash, error) { - return protocoldao.BootstrapUint(rp, RewardsSettingsContractName, "rpl.rewards.claim.period.blocks", big.NewInt(int64(value)), opts) +func BootstrapRewardsClaimIntervalTime(rp *rocketpool.RocketPool, value uint64, opts *bind.TransactOpts) (common.Hash, error) { + return protocoldao.BootstrapUint(rp, RewardsSettingsContractName, "rpl.rewards.claim.period.time", big.NewInt(int64(value)), opts) } diff --git a/tests/node/staking_test.go b/tests/node/staking_test.go index d1dd912d..7819556e 100644 --- a/tests/node/staking_test.go +++ b/tests/node/staking_test.go @@ -1,18 +1,18 @@ package node import ( - "math/big" - "testing" - - "github.com/rocket-pool/rocketpool-go/node" - "github.com/rocket-pool/rocketpool-go/settings/protocol" - "github.com/rocket-pool/rocketpool-go/tokens" - "github.com/rocket-pool/rocketpool-go/utils/eth" - - "github.com/rocket-pool/rocketpool-go/tests/testutils/evm" - minipoolutils "github.com/rocket-pool/rocketpool-go/tests/testutils/minipool" - nodeutils "github.com/rocket-pool/rocketpool-go/tests/testutils/node" - rplutils "github.com/rocket-pool/rocketpool-go/tests/testutils/tokens/rpl" + "math/big" + "testing" + + "github.com/rocket-pool/rocketpool-go/node" + "github.com/rocket-pool/rocketpool-go/settings/protocol" + "github.com/rocket-pool/rocketpool-go/tokens" + "github.com/rocket-pool/rocketpool-go/utils/eth" + + "github.com/rocket-pool/rocketpool-go/tests/testutils/evm" + minipoolutils "github.com/rocket-pool/rocketpool-go/tests/testutils/minipool" + nodeutils "github.com/rocket-pool/rocketpool-go/tests/testutils/node" + rplutils "github.com/rocket-pool/rocketpool-go/tests/testutils/tokens/rpl" ) @@ -65,10 +65,10 @@ func TestStakeRPL(t *testing.T) { } else if nodeMinimumRplStake.Cmp(big.NewInt(0)) != 0 { t.Errorf("Incorrect initial node minimum RPL stake %s", nodeMinimumRplStake.String()) } - if nodeRplStakedBlock, err := node.GetNodeRPLStakedBlock(rp, nodeAccount.Address, nil); err != nil { + if nodeRplStakedTime, err := node.GetNodeRPLStakedTime(rp, nodeAccount.Address, nil); err != nil { t.Error(err) - } else if nodeRplStakedBlock != 0 { - t.Errorf("Incorrect initial node RPL staked block %d", nodeRplStakedBlock) + } else if nodeRplStakedTime != 0 { + t.Errorf("Incorrect initial node RPL staked time %d", nodeRplStakedTime) } if nodeMinipoolLimit, err := node.GetNodeMinipoolLimit(rp, nodeAccount.Address, nil); err != nil { t.Error(err) @@ -107,10 +107,10 @@ func TestStakeRPL(t *testing.T) { } else if nodeMinimumRplStake.Cmp(big.NewInt(0)) != 0 { t.Errorf("Incorrect updated node minimum RPL stake 1 %s", nodeMinimumRplStake.String()) } - if nodeRplStakedBlock, err := node.GetNodeRPLStakedBlock(rp, nodeAccount.Address, nil); err != nil { + if nodeRplStakedTime, err := node.GetNodeRPLStakedTime(rp, nodeAccount.Address, nil); err != nil { t.Error(err) - } else if nodeRplStakedBlock == 0 { - t.Errorf("Incorrect updated node RPL staked block 1 %d", nodeRplStakedBlock) + } else if nodeRplStakedTime == 0 { + t.Errorf("Incorrect updated node RPL staked time 1 %d", nodeRplStakedTime) } if nodeMinipoolLimit, err := node.GetNodeMinipoolLimit(rp, nodeAccount.Address, nil); err != nil { t.Error(err) @@ -161,9 +161,9 @@ func TestWithdrawRPL(t *testing.T) { if err := nodeutils.StakeRPL(rp, ownerAccount, nodeAccount, rplAmount); err != nil { t.Fatal(err) } // Get & set rewards claim interval - rewardsClaimIntervalBlocks, err := protocol.GetRewardsClaimIntervalBlocks(rp, nil) + rewardsClaimIntervalTime, err := protocol.GetRewardsClaimIntervalTime(rp, nil) if err != nil { t.Fatal(err) } - if _, err := protocol.BootstrapRewardsClaimIntervalBlocks(rp, 0, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) } + if _, err := protocol.BootstrapRewardsClaimIntervalTime(rp, 0, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) } // Check initial staking details if totalRplStake, err := node.GetTotalRPLStake(rp, nil); err != nil { @@ -195,7 +195,7 @@ func TestWithdrawRPL(t *testing.T) { } // Reset rewards claim interval - if _, err := protocol.BootstrapRewardsClaimIntervalBlocks(rp, rewardsClaimIntervalBlocks, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) } + if _, err := protocol.BootstrapRewardsClaimIntervalTime(rp, rewardsClaimIntervalTime, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) } } diff --git a/tests/rewards/node_test.go b/tests/rewards/node_test.go index d1e1e0c2..b8f9885d 100644 --- a/tests/rewards/node_test.go +++ b/tests/rewards/node_test.go @@ -1,23 +1,25 @@ package rewards import ( - "context" - "math/big" - "testing" - - "github.com/rocket-pool/rocketpool-go/node" - "github.com/rocket-pool/rocketpool-go/rewards" - "github.com/rocket-pool/rocketpool-go/settings/protocol" - "github.com/rocket-pool/rocketpool-go/tokens" - "github.com/rocket-pool/rocketpool-go/utils/eth" - - "github.com/rocket-pool/rocketpool-go/tests/testutils/evm" - minipoolutils "github.com/rocket-pool/rocketpool-go/tests/testutils/minipool" + "context" + "math/big" + "testing" + + "github.com/rocket-pool/rocketpool-go/node" + "github.com/rocket-pool/rocketpool-go/rewards" + "github.com/rocket-pool/rocketpool-go/settings/protocol" + "github.com/rocket-pool/rocketpool-go/tokens" + "github.com/rocket-pool/rocketpool-go/utils/eth" + + "github.com/rocket-pool/rocketpool-go/tests/testutils/evm" + minipoolutils "github.com/rocket-pool/rocketpool-go/tests/testutils/minipool" ) func TestNodeRewards(t *testing.T) { + var secondsPerBlock uint64 = 12 + // State snapshotting if err := evm.TakeSnapshot(); err != nil { t.Fatal(err) } t.Cleanup(func() { if err := evm.RevertSnapshot(); err != nil { t.Fatal(err) } }) @@ -26,8 +28,8 @@ func TestNodeRewards(t *testing.T) { if _, err := node.RegisterNode(rp, "Australia/Brisbane", nodeAccount.GetTransactor()); err != nil { t.Fatal(err) } // Set network parameters - if _, err := protocol.BootstrapRewardsClaimIntervalBlocks(rp, 5, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) } - if _, err := protocol.BootstrapInflationIntervalBlocks(rp, 5, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) } + if _, err := protocol.BootstrapRewardsClaimIntervalTime(rp, 5 * secondsPerBlock, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) } + if _, err := protocol.BootstrapInflationIntervalTime(rp, 5 * secondsPerBlock, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) } // Get & check node claims enabled status if claimsEnabled, err := rewards.GetNodeClaimsEnabled(rp, nil); err != nil { @@ -44,7 +46,7 @@ func TestNodeRewards(t *testing.T) { } // Mine blocks until node claims are possible - if err := evm.MineBlocks(5); err != nil { t.Fatal(err) } + if err := evm.MineBlocks(10); err != nil { t.Fatal(err) } // Get & check updated node claim possible status if nodeClaimPossible, err := rewards.GetNodeClaimPossible(rp, nodeAccount.Address, nil); err != nil { @@ -80,7 +82,7 @@ func TestNodeRewards(t *testing.T) { // Start RPL inflation if header, err := rp.Client.HeaderByNumber(context.Background(), nil); err != nil { t.Fatal(err) - } else if _, err := protocol.BootstrapInflationStartBlock(rp, header.Number.Uint64() + 2, ownerAccount.GetTransactor()); err != nil { + } else if _, err := protocol.BootstrapInflationStartTime(rp, (header.Number.Uint64() + 2) * secondsPerBlock, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) } diff --git a/tests/rewards/trusted_node_test.go b/tests/rewards/trusted_node_test.go index d2fb0dd5..2b0910b0 100644 --- a/tests/rewards/trusted_node_test.go +++ b/tests/rewards/trusted_node_test.go @@ -1,21 +1,23 @@ package rewards import ( - "context" - "math/big" - "testing" + "context" + "math/big" + "testing" - "github.com/rocket-pool/rocketpool-go/rewards" - "github.com/rocket-pool/rocketpool-go/settings/protocol" - "github.com/rocket-pool/rocketpool-go/tokens" + "github.com/rocket-pool/rocketpool-go/rewards" + "github.com/rocket-pool/rocketpool-go/settings/protocol" + "github.com/rocket-pool/rocketpool-go/tokens" - "github.com/rocket-pool/rocketpool-go/tests/testutils/evm" - nodeutils "github.com/rocket-pool/rocketpool-go/tests/testutils/node" + "github.com/rocket-pool/rocketpool-go/tests/testutils/evm" + nodeutils "github.com/rocket-pool/rocketpool-go/tests/testutils/node" ) func TestTrustedNodeRewards(t *testing.T) { + var secondsPerBlock uint64 = 12 + // State snapshotting if err := evm.TakeSnapshot(); err != nil { t.Fatal(err) } t.Cleanup(func() { if err := evm.RevertSnapshot(); err != nil { t.Fatal(err) } }) @@ -24,8 +26,8 @@ func TestTrustedNodeRewards(t *testing.T) { if err := nodeutils.RegisterTrustedNode(rp, ownerAccount, trustedNodeAccount); err != nil { t.Fatal(err) } // Set network parameters - if _, err := protocol.BootstrapRewardsClaimIntervalBlocks(rp, 5, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) } - if _, err := protocol.BootstrapInflationIntervalBlocks(rp, 5, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) } + if _, err := protocol.BootstrapRewardsClaimIntervalTime(rp, 5 * secondsPerBlock, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) } + if _, err := protocol.BootstrapInflationIntervalTime(rp, 5 * secondsPerBlock, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) } // Get & check trusted node claims enabled status if claimsEnabled, err := rewards.GetTrustedNodeClaimsEnabled(rp, nil); err != nil { @@ -68,7 +70,7 @@ func TestTrustedNodeRewards(t *testing.T) { // Start RPL inflation if header, err := rp.Client.HeaderByNumber(context.Background(), nil); err != nil { t.Fatal(err) - } else if _, err := protocol.BootstrapInflationStartBlock(rp, header.Number.Uint64() + 2, ownerAccount.GetTransactor()); err != nil { + } else if _, err := protocol.BootstrapInflationStartTime(rp, (header.Number.Uint64() + 2) * secondsPerBlock, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) } diff --git a/tests/settings/protocol/inflation_test.go b/tests/settings/protocol/inflation_test.go index d2fad6b0..59fee7d3 100644 --- a/tests/settings/protocol/inflation_test.go +++ b/tests/settings/protocol/inflation_test.go @@ -1,16 +1,18 @@ package protocol import ( - "testing" + "testing" - "github.com/rocket-pool/rocketpool-go/settings/protocol" + "github.com/rocket-pool/rocketpool-go/settings/protocol" - "github.com/rocket-pool/rocketpool-go/tests/testutils/evm" + "github.com/rocket-pool/rocketpool-go/tests/testutils/evm" ) func TestInflationSettings(t *testing.T) { + var secondsPerBlock uint64 = 12 + // State snapshotting if err := evm.TakeSnapshot(); err != nil { t.Fatal(err) } t.Cleanup(func() { if err := evm.RevertSnapshot(); err != nil { t.Fatal(err) } }) @@ -25,24 +27,24 @@ func TestInflationSettings(t *testing.T) { t.Error("Incorrect inflation interval rate value") } - // Set & get inflation interval blocks - var inflationIntervalBlocks uint64 = 1 - if _, err := protocol.BootstrapInflationIntervalBlocks(rp, inflationIntervalBlocks, ownerAccount.GetTransactor()); err != nil { + // Set & get inflation interval time + var inflationIntervalTime uint64 = 1 * secondsPerBlock + if _, err := protocol.BootstrapInflationIntervalTime(rp, inflationIntervalTime, ownerAccount.GetTransactor()); err != nil { t.Error(err) - } else if value, err := protocol.GetInflationIntervalBlocks(rp, nil); err != nil { + } else if value, err := protocol.GetInflationIntervalTime(rp, nil); err != nil { t.Error(err) - } else if value != inflationIntervalBlocks { - t.Error("Incorrect inflation interval blocks value") + } else if value != inflationIntervalTime { + t.Error("Incorrect inflation interval time value") } // Set & get inflation start block - var inflationStartBlock uint64 = 1000000 - if _, err := protocol.BootstrapInflationStartBlock(rp, inflationStartBlock, ownerAccount.GetTransactor()); err != nil { + var inflationStartTime uint64 = 1000000 * secondsPerBlock + if _, err := protocol.BootstrapInflationStartTime(rp, inflationStartTime, ownerAccount.GetTransactor()); err != nil { t.Error(err) - } else if value, err := protocol.GetInflationStartBlock(rp, nil); err != nil { + } else if value, err := protocol.GetInflationStartTime(rp, nil); err != nil { t.Error(err) - } else if value != inflationStartBlock { - t.Error("Incorrect inflation start block value") + } else if value != inflationStartTime { + t.Error("Incorrect inflation start time value") } } diff --git a/tests/settings/protocol/rewards_test.go b/tests/settings/protocol/rewards_test.go index 2260c4df..2f3a8293 100644 --- a/tests/settings/protocol/rewards_test.go +++ b/tests/settings/protocol/rewards_test.go @@ -1,12 +1,12 @@ package protocol import ( - "testing" + "testing" - protocoldao "github.com/rocket-pool/rocketpool-go/dao/protocol" - protocolsettings "github.com/rocket-pool/rocketpool-go/settings/protocol" + protocoldao "github.com/rocket-pool/rocketpool-go/dao/protocol" + protocolsettings "github.com/rocket-pool/rocketpool-go/settings/protocol" - "github.com/rocket-pool/rocketpool-go/tests/testutils/evm" + "github.com/rocket-pool/rocketpool-go/tests/testutils/evm" ) @@ -26,10 +26,10 @@ func TestRewardsSettings(t *testing.T) { } else if value != claimerPerc { t.Errorf("Incorrect rewards claimer percent %f", value) } - if value, err := protocolsettings.GetRewardsClaimerPercBlockUpdated(rp, "rocketClaimNode", nil); err != nil { + if value, err := protocolsettings.GetRewardsClaimerPercTimeUpdated(rp, "rocketClaimNode", nil); err != nil { t.Error(err) } else if value == 0 { - t.Errorf("Incorrect rewards claimer percent block updated %d", value) + t.Errorf("Incorrect rewards claimer percent time updated %d", value) } if value, err := protocolsettings.GetRewardsClaimersPercTotal(rp, nil); err != nil { t.Error(err) @@ -38,14 +38,14 @@ func TestRewardsSettings(t *testing.T) { } } - // Set & get rewards claim interval blocks - var rewardsClaimIntervalBlocks uint64 = 1 - if _, err := protocolsettings.BootstrapRewardsClaimIntervalBlocks(rp, rewardsClaimIntervalBlocks, ownerAccount.GetTransactor()); err != nil { + // Set & get rewards claim interval time + var rewardsClaimIntervalTime uint64 = 1 + if _, err := protocolsettings.BootstrapRewardsClaimIntervalTime(rp, rewardsClaimIntervalTime, ownerAccount.GetTransactor()); err != nil { t.Error(err) - } else if value, err := protocolsettings.GetRewardsClaimIntervalBlocks(rp, nil); err != nil { + } else if value, err := protocolsettings.GetRewardsClaimIntervalTime(rp, nil); err != nil { t.Error(err) - } else if value != rewardsClaimIntervalBlocks { - t.Error("Incorrect rewards claim interval blocks value") + } else if value != rewardsClaimIntervalTime { + t.Error("Incorrect rewards claim interval time value") } } diff --git a/tests/tokens/rpl_test.go b/tests/tokens/rpl_test.go index c88a8acb..9b2445ca 100644 --- a/tests/tokens/rpl_test.go +++ b/tests/tokens/rpl_test.go @@ -1,17 +1,17 @@ package tokens import ( - "context" - "testing" + "context" + "testing" - "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common" - "github.com/rocket-pool/rocketpool-go/settings/protocol" - "github.com/rocket-pool/rocketpool-go/tokens" - "github.com/rocket-pool/rocketpool-go/utils/eth" + "github.com/rocket-pool/rocketpool-go/settings/protocol" + "github.com/rocket-pool/rocketpool-go/tokens" + "github.com/rocket-pool/rocketpool-go/utils/eth" - "github.com/rocket-pool/rocketpool-go/tests/testutils/evm" - rplutils "github.com/rocket-pool/rocketpool-go/tests/testutils/tokens/rpl" + "github.com/rocket-pool/rocketpool-go/tests/testutils/evm" + rplutils "github.com/rocket-pool/rocketpool-go/tests/testutils/tokens/rpl" ) @@ -111,17 +111,19 @@ func TestTransferFromRPL(t *testing.T) { func TestMintInflationRPL(t *testing.T) { + var secondsPerBlock uint64 = 12 + // State snapshotting if err := evm.TakeSnapshot(); err != nil { t.Fatal(err) } t.Cleanup(func() { if err := evm.RevertSnapshot(); err != nil { t.Fatal(err) } }) // Set network parameters - if _, err := protocol.BootstrapInflationIntervalBlocks(rp, 5, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) } + if _, err := protocol.BootstrapInflationIntervalTime(rp, 5 * secondsPerBlock, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) } // Start RPL inflation if header, err := rp.Client.HeaderByNumber(context.Background(), nil); err != nil { t.Fatal(err) - } else if _, err := protocol.BootstrapInflationStartBlock(rp, header.Number.Uint64() + 2, ownerAccount.GetTransactor()); err != nil { + } else if _, err := protocol.BootstrapInflationStartTime(rp, (header.Number.Uint64() + 2) * secondsPerBlock, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) } From a6a1634d9d2d71991a27613e0d798454cff2dae0 Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Thu, 13 May 2021 00:56:45 -0400 Subject: [PATCH 8/8] Added time advancing to the unit tests --- tests/rewards/node_test.go | 4 +++- tests/rewards/trusted_node_test.go | 2 ++ tests/testutils/evm/mining.go | 21 ++++++++++++++++++--- tests/tokens/rpl_test.go | 1 + 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/tests/rewards/node_test.go b/tests/rewards/node_test.go index b8f9885d..1ab1c2e4 100644 --- a/tests/rewards/node_test.go +++ b/tests/rewards/node_test.go @@ -46,7 +46,8 @@ func TestNodeRewards(t *testing.T) { } // Mine blocks until node claims are possible - if err := evm.MineBlocks(10); err != nil { t.Fatal(err) } + if err := evm.MineBlocks(5); err != nil { t.Fatal(err) } + if err := evm.IncreaseTime(5 * secondsPerBlock); err != nil { t.Fatal(err) } // Get & check updated node claim possible status if nodeClaimPossible, err := rewards.GetNodeClaimPossible(rp, nodeAccount.Address, nil); err != nil { @@ -88,6 +89,7 @@ func TestNodeRewards(t *testing.T) { // Mine blocks until rewards are available if err := evm.MineBlocks(10); err != nil { t.Fatal(err) } + if err := evm.IncreaseTime(10 * secondsPerBlock); err != nil { t.Fatal(err) } // Get & check updated node claim rewards amount if rewardsAmount, err := rewards.GetNodeClaimRewardsAmount(rp, nodeAccount.Address, nil); err != nil { diff --git a/tests/rewards/trusted_node_test.go b/tests/rewards/trusted_node_test.go index 2b0910b0..be087792 100644 --- a/tests/rewards/trusted_node_test.go +++ b/tests/rewards/trusted_node_test.go @@ -45,6 +45,7 @@ func TestTrustedNodeRewards(t *testing.T) { // Mine blocks until trusted node claims are possible if err := evm.MineBlocks(5); err != nil { t.Fatal(err) } + if err := evm.IncreaseTime(5 * secondsPerBlock); err != nil { t.Fatal(err) } // Get & check updated trusted node claim possible status if nodeClaimPossible, err := rewards.GetTrustedNodeClaimPossible(rp, trustedNodeAccount.Address, nil); err != nil { @@ -76,6 +77,7 @@ func TestTrustedNodeRewards(t *testing.T) { // Mine blocks until rewards are available if err := evm.MineBlocks(10); err != nil { t.Fatal(err) } + if err := evm.IncreaseTime(10 * secondsPerBlock); err != nil { t.Fatal(err) } // Get & check updated trusted node claim rewards amount if rewardsAmount, err := rewards.GetTrustedNodeClaimRewardsAmount(rp, trustedNodeAccount.Address, nil); err != nil { diff --git a/tests/testutils/evm/mining.go b/tests/testutils/evm/mining.go index 78a72c59..e205482e 100644 --- a/tests/testutils/evm/mining.go +++ b/tests/testutils/evm/mining.go @@ -1,12 +1,11 @@ package evm import ( - "github.com/ethereum/go-ethereum/rpc" + "github.com/ethereum/go-ethereum/rpc" - "github.com/rocket-pool/rocketpool-go/tests" + "github.com/rocket-pool/rocketpool-go/tests" ) - // Mine a number of blocks func MineBlocks(numBlocks int) error { @@ -24,3 +23,19 @@ func MineBlocks(numBlocks int) error { } + +// Fast forward to some number of seconds +func IncreaseTime(time uint64) error { + + // Initialize RPC client + client, err := rpc.Dial(tests.Eth1ProviderAddress) + if err != nil { return err } + + // Make RPC calls + if err := client.Call(nil, "evm_increaseTime", time); err != nil { return err } + + // Return + return nil + +} + diff --git a/tests/tokens/rpl_test.go b/tests/tokens/rpl_test.go index 9b2445ca..c397558d 100644 --- a/tests/tokens/rpl_test.go +++ b/tests/tokens/rpl_test.go @@ -129,6 +129,7 @@ func TestMintInflationRPL(t *testing.T) { // Mine blocks until rewards are available if err := evm.MineBlocks(10); err != nil { t.Fatal(err) } + if err := evm.IncreaseTime(10 * secondsPerBlock); err != nil { t.Fatal(err) } // Get initial total supply rplTotalSupply1, err := tokens.GetRPLTotalSupply(rp, nil)