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

Simplify a few functions, add json decorators to some structs #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
80 changes: 41 additions & 39 deletions utils/state/minipool.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,42 @@ const (
// Complete details for a minipool
type NativeMinipoolDetails struct {
// Redstone
Exists bool
MinipoolAddress common.Address
Pubkey types.ValidatorPubkey
StatusRaw uint8
StatusBlock *big.Int
StatusTime *big.Int
Finalised bool
DepositTypeRaw uint8
NodeFee *big.Int
NodeDepositBalance *big.Int
NodeDepositAssigned bool
UserDepositBalance *big.Int
UserDepositAssigned bool
UserDepositAssignedTime *big.Int
UseLatestDelegate bool
Delegate common.Address
PreviousDelegate common.Address
EffectiveDelegate common.Address
PenaltyCount *big.Int
PenaltyRate *big.Int
NodeAddress common.Address
Version uint8
Balance *big.Int // Contract balance
DistributableBalance *big.Int // Contract balance minus node op refund
NodeShareOfBalance *big.Int // Result of calculateNodeShare(contract balance)
UserShareOfBalance *big.Int // Result of calculateUserShare(contract balance)
NodeRefundBalance *big.Int
WithdrawalCredentials common.Hash
Status types.MinipoolStatus
DepositType types.MinipoolDeposit
NodeShareOfBalanceIncludingBeacon *big.Int // Must call CalculateCompleteMinipoolShares to get this
UserShareOfBalanceIncludingBeacon *big.Int // Must call CalculateCompleteMinipoolShares to get this
NodeShareOfBeaconBalance *big.Int // Must call CalculateCompleteMinipoolShares to get this
UserShareOfBeaconBalance *big.Int // Must call CalculateCompleteMinipoolShares to get this
Exists bool `json:"exists"`
MinipoolAddress common.Address `json:"minipool_address"`
Pubkey types.ValidatorPubkey `json:"pubkey"`
StatusRaw uint8 `json:"status_raw"`
StatusBlock *big.Int `json:"status_block"`
StatusTime *big.Int `json:"status_time"`
Finalised bool `json:"finalised"`
DepositTypeRaw uint8 `json:"deposit_type_raw"`
NodeFee *big.Int `json:"node_fee"`
NodeDepositBalance *big.Int `json:"node_deposit_balance"`
NodeDepositAssigned bool `json:"node_deposit_assigned"`
UserDepositBalance *big.Int `json:"user_deposit_balance"`
UserDepositAssigned bool `json:"user_deposit_assigned"`
UserDepositAssignedTime *big.Int `json:"user_deposit_assigned_time"`
UseLatestDelegate bool `json:"use_latest_delegate"`
Delegate common.Address `json:"delegate"`
PreviousDelegate common.Address `json:"previous_delegate"`
EffectiveDelegate common.Address `json:"effective_delegate"`
PenaltyCount *big.Int `json:"penalty_count"`
PenaltyRate *big.Int `json:"penalty_rate"`
NodeAddress common.Address `json:"node_address"`
Version uint8 `json:"version"`
Balance *big.Int `json:"balance"`
DistributableBalance *big.Int `json:"distributable_balance"`
NodeShareOfBalance *big.Int `json:"node_share_of_balance"` // Result of calculateNodeShare(contract balance)
UserShareOfBalance *big.Int `json:"user_share_of_balance"` // Result of calculateUserShare(contract balance)
NodeRefundBalance *big.Int `json:"node_refund_balance"`
WithdrawalCredentials common.Hash `json:"withdrawal_credentials"`
Status types.MinipoolStatus `json:"status"`
DepositType types.MinipoolDeposit `json:"deposit_type"`

// Must call CalculateCompleteMinipoolShares to get these
NodeShareOfBalanceIncludingBeacon *big.Int `json:"node_share_of_balance_including_beacon"`
UserShareOfBalanceIncludingBeacon *big.Int `json:"user_share_of_balance_including_beacon"`
NodeShareOfBeaconBalance *big.Int `json:"node_share_of_beacon_balance"`
UserShareOfBeaconBalance *big.Int `json:"user_share_of_beacon_balance"`

// Atlas
UserDistributed bool
Expand Down Expand Up @@ -93,7 +95,7 @@ func GetNativeMinipoolDetails(rp *rocketpool.RocketPool, contracts *NetworkContr
return NativeMinipoolDetails{}, fmt.Errorf("error executing multicall: %w", err)
}

fixupMinipoolDetails(rp, &details, opts)
fixupMinipoolDetails(&details)

return details, nil
}
Expand Down Expand Up @@ -426,7 +428,7 @@ func getBulkMinipoolDetails(rp *rocketpool.RocketPool, contracts *NetworkContrac
for j := i; j < max; j++ {
details := &minipoolDetails[j]
details.Version = versions[j]
addMinipoolShareCalls(rp, contracts, mc, details, opts)
addMinipoolShareCalls(rp, mc, details, opts)
}
_, err = mc.FlexibleCall(true, opts)
if err != nil {
Expand All @@ -443,7 +445,7 @@ func getBulkMinipoolDetails(rp *rocketpool.RocketPool, contracts *NetworkContrac

// Postprocess the minipools
for i := range minipoolDetails {
fixupMinipoolDetails(rp, &minipoolDetails[i], opts)
fixupMinipoolDetails(&minipoolDetails[i])
}

return minipoolDetails, nil
Expand Down Expand Up @@ -519,7 +521,7 @@ func addMinipoolDetailsCalls(rp *rocketpool.RocketPool, contracts *NetworkContra
}

// Add the calls for the minipool node and user share to the multicaller
func addMinipoolShareCalls(rp *rocketpool.RocketPool, contracts *NetworkContracts, mc *multicall.MultiCaller, details *NativeMinipoolDetails, opts *bind.CallOpts) error {
func addMinipoolShareCalls(rp *rocketpool.RocketPool, mc *multicall.MultiCaller, details *NativeMinipoolDetails, opts *bind.CallOpts) error {
// Create the minipool contract binding
address := details.MinipoolAddress
mp, err := minipool.NewMinipoolFromVersion(rp, address, details.Version, opts)
Expand All @@ -541,7 +543,7 @@ func addMinipoolShareCalls(rp *rocketpool.RocketPool, contracts *NetworkContract
}

// Fixes a minipool details struct with supplemental logic
func fixupMinipoolDetails(rp *rocketpool.RocketPool, details *NativeMinipoolDetails, opts *bind.CallOpts) error {
func fixupMinipoolDetails(details *NativeMinipoolDetails) error {

details.Status = types.MinipoolStatus(details.StatusRaw)
details.DepositType = types.MinipoolDeposit(details.DepositTypeRaw)
Expand Down
80 changes: 40 additions & 40 deletions utils/state/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,50 +20,50 @@ const (

type NetworkDetails struct {
// Redstone
RplPrice *big.Int
MinCollateralFraction *big.Int
MaxCollateralFraction *big.Int
IntervalDuration time.Duration
IntervalStart time.Time
NodeOperatorRewardsPercent *big.Int
TrustedNodeOperatorRewardsPercent *big.Int
ProtocolDaoRewardsPercent *big.Int
PendingRPLRewards *big.Int
RewardIndex uint64
ScrubPeriod time.Duration
SmoothingPoolAddress common.Address
DepositPoolBalance *big.Int
DepositPoolExcess *big.Int
QueueCapacity minipool.QueueCapacity
QueueLength *big.Int
RPLInflationIntervalRate *big.Int
RPLTotalSupply *big.Int
PricesBlock uint64
LatestReportablePricesBlock uint64
ETHUtilizationRate float64
StakingETHBalance *big.Int
RETHExchangeRate float64
TotalETHBalance *big.Int
RETHBalance *big.Int
TotalRETHSupply *big.Int
TotalRPLStake *big.Int
SmoothingPoolBalance *big.Int
NodeFee float64
BalancesBlock *big.Int
LatestReportableBalancesBlock uint64
SubmitBalancesEnabled bool
SubmitPricesEnabled bool
MinipoolLaunchTimeout *big.Int
RplPrice *big.Int `json:"rpl_price"`
MinCollateralFraction *big.Int `json:"min_collateral_fraction"`
MaxCollateralFraction *big.Int `json:"max_collateral_fraction"`
IntervalDuration time.Duration `json:"interval_duration"`
IntervalStart time.Time `json:"interval_start"`
NodeOperatorRewardsPercent *big.Int `json:"node_operator_rewards_percent"`
TrustedNodeOperatorRewardsPercent *big.Int `json:"trusted_node_operator_rewards_percent"`
ProtocolDaoRewardsPercent *big.Int `json:"protocol_dao_rewards_percent"`
PendingRPLRewards *big.Int `json:"pending_rpl_rewards"`
RewardIndex uint64 `json:"reward_index"`
ScrubPeriod time.Duration `json:"scrub_period"`
SmoothingPoolAddress common.Address `json:"smoothing_pool_address"`
DepositPoolBalance *big.Int `json:"deposit_pool_balance"`
DepositPoolExcess *big.Int `json:"deposit_pool_excess"`
QueueCapacity minipool.QueueCapacity `json:"queue_capacity"`
QueueLength *big.Int `json:"queue_length"`
RPLInflationIntervalRate *big.Int `json:"rpl_inflation_interval_rate"`
RPLTotalSupply *big.Int `json:"rpl_total_supply"`
PricesBlock uint64 `json:"prices_block"`
LatestReportablePricesBlock uint64 `json:"latest_reportable_prices_block"`
ETHUtilizationRate float64 `json:"eth_utilization_rate"`
StakingETHBalance *big.Int `json:"staking_eth_balance"`
RETHExchangeRate float64 `json:"reth_exchange_rate"`
TotalETHBalance *big.Int `json:"total_eth_balance"`
RETHBalance *big.Int `json:"reth_balance"`
TotalRETHSupply *big.Int `json:"total_reth_supply"`
TotalRPLStake *big.Int `json:"total_rpl_stake"`
SmoothingPoolBalance *big.Int `json:"smoothing_pool_balance"`
NodeFee float64 `json:"node_fee"`
BalancesBlock *big.Int `json:"balances_block"`
LatestReportableBalancesBlock uint64 `json:"latest_reportable_balances_block"`
SubmitBalancesEnabled bool `json:"submit_balances_enabled"`
SubmitPricesEnabled bool `json:"submit_prices_enabled"`
MinipoolLaunchTimeout *big.Int `json:"minipool_launch_timeout"`

// Atlas
PromotionScrubPeriod time.Duration
BondReductionWindowStart time.Duration
BondReductionWindowLength time.Duration
DepositPoolUserBalance *big.Int
PromotionScrubPeriod time.Duration `json:"promotion_scrub_period"`
BondReductionWindowStart time.Duration `json:"bond_reduction_window_start"`
BondReductionWindowLength time.Duration `json:"bond_reduction_window_length"`
DepositPoolUserBalance *big.Int `json:"deposit_pool_user_balance"`

// Houston
PricesSubmissionFrequency uint64
BalancesSubmissionFrequency uint64
PricesSubmissionFrequency uint64 `json:"prices_submission_frequency"`
BalancesSubmissionFrequency uint64 `json:"balances_submission_frequency"`
}

// Create a snapshot of all of the network's details
Expand Down
56 changes: 28 additions & 28 deletions utils/state/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,34 @@ const (

// Complete details for a node
type NativeNodeDetails struct {
Exists bool
RegistrationTime *big.Int
TimezoneLocation string
FeeDistributorInitialised bool
FeeDistributorAddress common.Address
RewardNetwork *big.Int
RplStake *big.Int
EffectiveRPLStake *big.Int
MinimumRPLStake *big.Int
MaximumRPLStake *big.Int
EthMatched *big.Int
EthMatchedLimit *big.Int
MinipoolCount *big.Int
BalanceETH *big.Int
BalanceRETH *big.Int
BalanceRPL *big.Int
BalanceOldRPL *big.Int
DepositCreditBalance *big.Int
DistributorBalanceUserETH *big.Int // Must call CalculateAverageFeeAndDistributorShares to get this
DistributorBalanceNodeETH *big.Int // Must call CalculateAverageFeeAndDistributorShares to get this
WithdrawalAddress common.Address
PendingWithdrawalAddress common.Address
SmoothingPoolRegistrationState bool
SmoothingPoolRegistrationChanged *big.Int
NodeAddress common.Address
AverageNodeFee *big.Int // Must call CalculateAverageFeeAndDistributorShares to get this
CollateralisationRatio *big.Int
DistributorBalance *big.Int
Exists bool `json:"exists"`
RegistrationTime *big.Int `json:"registration_time"`
TimezoneLocation string `json:"timezone_location"`
FeeDistributorInitialised bool `json:"fee_distributor_initialised"`
FeeDistributorAddress common.Address `json:"fee_distributor_address"`
RewardNetwork *big.Int `json:"reward_network"`
RplStake *big.Int `json:"rpl_stake"`
EffectiveRPLStake *big.Int `json:"effective_rpl_stake"`
MinimumRPLStake *big.Int `json:"minimum_rpl_stake"`
MaximumRPLStake *big.Int `json:"maximum_rpl_stake"`
EthMatched *big.Int `json:"eth_matched"`
EthMatchedLimit *big.Int `json:"eth_matched_limit"`
MinipoolCount *big.Int `json:"minipool_count"`
BalanceETH *big.Int `json:"balance_eth"`
BalanceRETH *big.Int `json:"balance_reth"`
BalanceRPL *big.Int `json:"balance_rpl"`
BalanceOldRPL *big.Int `json:"balance_old_rpl"`
DepositCreditBalance *big.Int `json:"deposit_credit_balance"`
DistributorBalanceUserETH *big.Int `json:"distributor_balance_user_eth"` // Must call CalculateAverageFeeAndDistributorShares to get this
DistributorBalanceNodeETH *big.Int `json:"distributor_balance_node_eth"` // Must call CalculateAverageFeeAndDistributorShares to get this
WithdrawalAddress common.Address `json:"withdrawal_address"`
PendingWithdrawalAddress common.Address `json:"pending_withdrawal_address"`
SmoothingPoolRegistrationState bool `json:"smoothing_pool_registration_state"`
SmoothingPoolRegistrationChanged *big.Int `json:"smoothing_pool_registration_changed"`
NodeAddress common.Address `json:"node_address"`
AverageNodeFee *big.Int `json:"average_node_fee"` // Must call CalculateAverageFeeAndDistributorShares to get this
CollateralisationRatio *big.Int `json:"collateralisation_ratio"`
DistributorBalance *big.Int `json:"distributor_balance"`
}

// Gets the details for a node using the efficient multicall contract
Expand Down
12 changes: 6 additions & 6 deletions utils/state/odao.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ func GetOracleDaoMemberDetails(rp *rocketpool.RocketPool, contracts *NetworkCont
details := OracleDaoMemberDetails{}
details.Address = memberAddress

addOracleDaoMemberDetailsCalls(rp, contracts, contracts.Multicaller, &details, opts)
addOracleDaoMemberDetailsCalls(contracts, contracts.Multicaller, &details)

_, err := contracts.Multicaller.FlexibleCall(true, opts)
if err != nil {
return OracleDaoMemberDetails{}, fmt.Errorf("error executing multicall: %w", err)
}

fixupOracleDaoMemberDetails(rp, &details, opts)
fixupOracleDaoMemberDetails(&details)

return details, nil
}
Expand Down Expand Up @@ -142,7 +142,7 @@ func getOracleDaoDetails(rp *rocketpool.RocketPool, contracts *NetworkContracts,
details := &memberDetails[j]
details.Address = address

addOracleDaoMemberDetailsCalls(rp, contracts, mc, details, opts)
addOracleDaoMemberDetailsCalls(contracts, mc, details)
}
_, err = mc.FlexibleCall(true, opts)
if err != nil {
Expand All @@ -160,14 +160,14 @@ func getOracleDaoDetails(rp *rocketpool.RocketPool, contracts *NetworkContracts,
// Postprocessing
for i := range memberDetails {
details := &memberDetails[i]
fixupOracleDaoMemberDetails(rp, details, opts)
fixupOracleDaoMemberDetails(details)
}

return memberDetails, nil
}

// Add the Oracle DAO details getters to the multicaller
func addOracleDaoMemberDetailsCalls(rp *rocketpool.RocketPool, contracts *NetworkContracts, mc *multicall.MultiCaller, details *OracleDaoMemberDetails, opts *bind.CallOpts) error {
func addOracleDaoMemberDetailsCalls(contracts *NetworkContracts, mc *multicall.MultiCaller, details *OracleDaoMemberDetails) error {
address := details.Address
mc.AddCall(contracts.RocketDAONodeTrusted, &details.Exists, "getMemberIsValid", address)
mc.AddCall(contracts.RocketDAONodeTrusted, &details.ID, "getMemberID", address)
Expand All @@ -181,7 +181,7 @@ func addOracleDaoMemberDetailsCalls(rp *rocketpool.RocketPool, contracts *Networ
}

// Fixes a member details struct with supplemental logic
func fixupOracleDaoMemberDetails(rp *rocketpool.RocketPool, details *OracleDaoMemberDetails, opts *bind.CallOpts) error {
func fixupOracleDaoMemberDetails(details *OracleDaoMemberDetails) error {
details.JoinedTime = convertToTime(details.joinedTimeRaw)
details.LastProposalTime = convertToTime(details.lastProposalTimeRaw)
return nil
Expand Down
6 changes: 3 additions & 3 deletions utils/state/pdao.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func GetProtocolDaoProposalDetails(rp *rocketpool.RocketPool, contracts *Network
rawDetails := protocolDaoProposalDetailsRaw{}
details.ID = proposalID

addProposalCalls(rp, contracts, contracts.Multicaller, &rawDetails, opts)
addProposalCalls(contracts, contracts.Multicaller, &rawDetails)

_, err := contracts.Multicaller.FlexibleCall(true, opts)
if err != nil {
Expand Down Expand Up @@ -117,7 +117,7 @@ func getProposalDetails(rp *rocketpool.RocketPool, contracts *NetworkContracts,
details := &propDetailsRaw[j]
details.ID = id

addProposalCalls(rp, contracts, mc, details, opts)
addProposalCalls(contracts, mc, details)
}
_, err = mc.FlexibleCall(true, opts)
if err != nil {
Expand All @@ -144,7 +144,7 @@ func getProposalDetails(rp *rocketpool.RocketPool, contracts *NetworkContracts,
}

// Get the details of a proposal
func addProposalCalls(rp *rocketpool.RocketPool, contracts *NetworkContracts, mc *multicall.MultiCaller, details *protocolDaoProposalDetailsRaw, opts *bind.CallOpts) error {
func addProposalCalls(contracts *NetworkContracts, mc *multicall.MultiCaller, details *protocolDaoProposalDetailsRaw) error {
id := big.NewInt(0).SetUint64(details.ID)
mc.AddCall(contracts.RocketDAOProtocolProposal, &details.ProposerAddress, "getProposer", id)
mc.AddCall(contracts.RocketDAOProtocolProposal, &details.DAO, "getDAO", id)
Expand Down