Skip to content

Commit

Permalink
Merged PR 9: Add Effective Stake support for the RP-15 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
jclapis committed May 26, 2021
2 parents 6e72501 + f5df68c commit 55d24f4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 24 deletions.
24 changes: 19 additions & 5 deletions network/prices.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,43 @@ func GetRPLPrice(rp *rocketpool.RocketPool, opts *bind.CallOpts) (*big.Int, erro


// Estimate the gas of SubmitPrices
func EstimateSubmitPricesGas(rp *rocketpool.RocketPool, block uint64, rplPrice *big.Int, opts *bind.TransactOpts) (rocketpool.GasInfo, error) {
func EstimateSubmitPricesGas(rp *rocketpool.RocketPool, block uint64, rplPrice *big.Int, effectiveRplStake *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)
return rocketNetworkPrices.GetTransactionGasInfo(opts, "submitPrices", big.NewInt(int64(block)), rplPrice, effectiveRplStake)
}


// Submit network prices for an epoch
func SubmitPrices(rp *rocketpool.RocketPool, block uint64, rplPrice *big.Int, opts *bind.TransactOpts) (common.Hash, error) {
// Submit network prices and total effective RPL stake for an epoch
func SubmitPrices(rp *rocketpool.RocketPool, block uint64, rplPrice, effectiveRplStake *big.Int, opts *bind.TransactOpts) (common.Hash, error) {
rocketNetworkPrices, err := getRocketNetworkPrices(rp)
if err != nil {
return common.Hash{}, err
}
hash, err := rocketNetworkPrices.Transact(opts, "submitPrices", big.NewInt(int64(block)), rplPrice)
hash, err := rocketNetworkPrices.Transact(opts, "submitPrices", big.NewInt(int64(block)), rplPrice, effectiveRplStake)
if err != nil {
return common.Hash{}, fmt.Errorf("Could not submit network prices: %w", err)
}
return hash, nil
}


// Check if the network is currently in consensus about the RPL price, or if it is still reaching consensus
func InConsensus(rp *rocketpool.RocketPool, opts *bind.CallOpts) (bool, error) {
rocketNetworkPrices, err := getRocketNetworkPrices(rp)
if err != nil {
return false, err
}
isInConsensus := new(bool)
if err := rocketNetworkPrices.Call(opts, isInConsensus, "inConsensus"); err != nil {
return false, fmt.Errorf("Could not get consensus status: %w", err)
}
return *isInConsensus, nil
}


// Get contracts
var rocketNetworkPricesLock sync.Mutex
func getRocketNetworkPrices(rp *rocketpool.RocketPool) (*rocketpool.Contract, error) {
Expand Down
14 changes: 14 additions & 0 deletions node/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ func WithdrawRPL(rp *rocketpool.RocketPool, rplAmount *big.Int, opts *bind.Trans
}


// Calculate total effective RPL stake
func CalculateTotalEffectiveRPLStake(rp *rocketpool.RocketPool, offset, limit, rplPrice *big.Int, opts *bind.CallOpts) (*big.Int, error) {
rocketNodeStaking, err := getRocketNodeStaking(rp)
if err != nil {
return nil, err
}
totalEffectiveRplStake := new(*big.Int)
if err := rocketNodeStaking.Call(opts, totalEffectiveRplStake, "calculateTotalEffectiveRPLStake", offset, limit, rplPrice); err != nil {
return nil, fmt.Errorf("Could not get total effective RPL stake: %w", err)
}
return *totalEffectiveRplStake, nil
}


// Get contracts
var rocketNodeStakingLock sync.Mutex
func getRocketNodeStaking(rp *rocketpool.RocketPool) (*rocketpool.Contract, error) {
Expand Down
26 changes: 13 additions & 13 deletions tests/auction/auction_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package auction

import (
"math/big"
"testing"

"github.com/rocket-pool/rocketpool-go/auction"
"github.com/rocket-pool/rocketpool-go/network"
"github.com/rocket-pool/rocketpool-go/settings/protocol"
"github.com/rocket-pool/rocketpool-go/tokens"
"github.com/rocket-pool/rocketpool-go/utils/eth"

auctionutils "github.com/rocket-pool/rocketpool-go/tests/testutils/auction"
"github.com/rocket-pool/rocketpool-go/tests/testutils/evm"
nodeutils "github.com/rocket-pool/rocketpool-go/tests/testutils/node"
"math/big"
"testing"

"github.com/rocket-pool/rocketpool-go/auction"
"github.com/rocket-pool/rocketpool-go/network"
"github.com/rocket-pool/rocketpool-go/settings/protocol"
"github.com/rocket-pool/rocketpool-go/tokens"
"github.com/rocket-pool/rocketpool-go/utils/eth"

auctionutils "github.com/rocket-pool/rocketpool-go/tests/testutils/auction"
"github.com/rocket-pool/rocketpool-go/tests/testutils/evm"
nodeutils "github.com/rocket-pool/rocketpool-go/tests/testutils/node"
)


Expand Down Expand Up @@ -98,7 +98,7 @@ func TestLotDetails(t *testing.T) {
if err := nodeutils.RegisterTrustedNode(rp, ownerAccount, trustedNodeAccount); err != nil { t.Fatal(err) }

// Set network parameters
if _, err := network.SubmitPrices(rp, 1, eth.EthToWei(1), trustedNodeAccount.GetTransactor()); err != nil { t.Fatal(err) }
if _, err := network.SubmitPrices(rp, 1, eth.EthToWei(1), eth.EthToWei(24), trustedNodeAccount.GetTransactor()); err != nil { t.Fatal(err) }
if _, err := protocol.BootstrapLotStartingPriceRatio(rp, 1.0, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }
if _, err := protocol.BootstrapLotReservePriceRatio(rp, 0.5, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }
if _, err := protocol.BootstrapLotMaximumEthValue(rp, eth.EthToWei(10), ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }
Expand Down
13 changes: 7 additions & 6 deletions tests/network/prices_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package network

import (
"testing"
"testing"

"github.com/rocket-pool/rocketpool-go/network"
"github.com/rocket-pool/rocketpool-go/utils/eth"
"github.com/rocket-pool/rocketpool-go/network"
"github.com/rocket-pool/rocketpool-go/utils/eth"

"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"
)


Expand All @@ -23,7 +23,8 @@ func TestSubmitPrices(t *testing.T) {
// Submit prices
var pricesBlock uint64 = 100
rplPrice := eth.EthToWei(1000)
if _, err := network.SubmitPrices(rp, pricesBlock, rplPrice, trustedNodeAccount.GetTransactor()); err != nil {
effectiveRplStake := eth.EthToWei(24000)
if _, err := network.SubmitPrices(rp, pricesBlock, rplPrice, effectiveRplStake, trustedNodeAccount.GetTransactor()); err != nil {
t.Fatal(err)
}

Expand Down

0 comments on commit 55d24f4

Please sign in to comment.