Skip to content

Commit

Permalink
Merge pull request #649 from rocket-pool/v2-remove-hardcoded-message-…
Browse files Browse the repository at this point in the history
…stakerpl

V2 fixed outdated and hardcoded value in stake rpl
  • Loading branch information
0xfornax authored Sep 25, 2024
2 parents f6e98ba + ae99112 commit 4b63eab
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
5 changes: 4 additions & 1 deletion rocketpool-cli/commands/node/stake-rpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ func nodeStakeRpl(c *cli.Context) error {

// Run the stake TX
validated, err := tx.HandleTx(c, rp, stakeResponse.Data.StakeTxInfo,
fmt.Sprintf("Are you sure you want to stake %.6f RPL? You will not be able to unstake this RPL until you exit your validators and close your minipools, or reach over 100%% collateral!", math.RoundDown(eth.WeiToEth(amountWei), 6)),
fmt.Sprintf("Are you sure you want to stake %.6f RPL? You will not be able to unstake this RPL until you exit your validators and close your minipools, or reach %.6f staked RPL (%.0f%% of bonded eth)!",
math.RoundDown(eth.WeiToEth(amountWei), 6),
math.RoundDown(eth.WeiToEth(status.Data.MaximumRplStake), 6),
eth.WeiToEth(status.Data.MaximumStakeFraction)*100),
"staking RPL",
"Staking RPL...",
)
Expand Down
13 changes: 13 additions & 0 deletions rocketpool-daemon/api/node/stake-rpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/gorilla/mux"
batch "github.com/rocket-pool/batch-query"
"github.com/rocket-pool/rocketpool-go/v2/dao/protocol"
"github.com/rocket-pool/rocketpool-go/v2/node"
"github.com/rocket-pool/rocketpool-go/v2/rocketpool"
"github.com/rocket-pool/rocketpool-go/v2/tokens"

"github.com/rocket-pool/node-manager-core/api/server"
"github.com/rocket-pool/node-manager-core/api/types"
"github.com/rocket-pool/node-manager-core/eth"
"github.com/rocket-pool/node-manager-core/utils/input"
"github.com/rocket-pool/smartnode/v2/rocketpool-daemon/common/utils"
"github.com/rocket-pool/smartnode/v2/shared/types/api"
Expand Down Expand Up @@ -60,6 +62,7 @@ type nodeStakeRplContext struct {
node *node.Node
balance *big.Int
allowance *big.Int
pSettings *protocol.ProtocolDaoSettings
}

func (c *nodeStakeRplContext) Initialize() (types.ResponseStatus, error) {
Expand All @@ -86,19 +89,29 @@ func (c *nodeStakeRplContext) Initialize() (types.ResponseStatus, error) {
if err != nil {
return types.ResponseStatus_Error, fmt.Errorf("error creating RocketNodeStaking binding: %w", err)
}
pMgr, err := protocol.NewProtocolDaoManager(c.rp)
if err != nil {
return types.ResponseStatus_Error, fmt.Errorf("error creating pDAO manager binding: %w", err)
}
c.pSettings = pMgr.Settings
c.nsAddress = rns.Address
return types.ResponseStatus_Success, nil
}

func (c *nodeStakeRplContext) GetState(mc *batch.MultiCaller) {
c.rpl.BalanceOf(mc, &c.balance, c.nodeAddress)
c.rpl.GetAllowance(mc, &c.allowance, c.nodeAddress, c.nsAddress)
eth.AddQueryablesToMulticall(mc,
c.node.MaximumRplStake,
)
}

func (c *nodeStakeRplContext) PrepareData(data *api.NodeStakeRplData, opts *bind.TransactOpts) (types.ResponseStatus, error) {
data.InsufficientBalance = (c.amount.Cmp(c.balance) > 0)
data.Allowance = c.allowance
data.CanStake = !(data.InsufficientBalance)
data.MaximumStakeFraction = c.pSettings.Node.MaximumPerMinipoolStake.Raw()
data.MaximumRplStake = c.node.MaximumRplStake.Get()

if data.CanStake {
if c.allowance.Cmp(c.amount) < 0 {
Expand Down
12 changes: 7 additions & 5 deletions shared/types/api/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,13 @@ type NodeSwapRplData struct {
}

type NodeStakeRplData struct {
CanStake bool `json:"canStake"`
InsufficientBalance bool `json:"insufficientBalance"`
Allowance *big.Int `json:"allowance"`
ApproveTxInfo *eth.TransactionInfo `json:"approveTxInfo"`
StakeTxInfo *eth.TransactionInfo `json:"stakeTxInfo"`
CanStake bool `json:"canStake"`
InsufficientBalance bool `json:"insufficientBalance"`
Allowance *big.Int `json:"allowance"`
ApproveTxInfo *eth.TransactionInfo `json:"approveTxInfo"`
StakeTxInfo *eth.TransactionInfo `json:"stakeTxInfo"`
MaximumStakeFraction *big.Int `json:"maximumStakeFraction"`
MaximumRplStake *big.Int `json:"maximumRplStake"`
}

type NodeSetStakeRplForAllowedData struct {
Expand Down

0 comments on commit 4b63eab

Please sign in to comment.