Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 fixed outdated and hardcoded value in stake rpl #649

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading