Skip to content
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
52 changes: 52 additions & 0 deletions bindings/rewards/rewards.go
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all new code in this file should be in a new function

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rewards

import (
"context"
"fmt"
"math/big"
"sync"
Expand Down Expand Up @@ -230,6 +231,15 @@ func SubmitRewardSnapshot(rp *rocketpool.RocketPool, submission RewardSubmission

// Get the event info for a rewards snapshot using the Atlas getter
func GetRewardsEvent(rp *rocketpool.RocketPool, index uint64, rocketRewardsPoolAddresses []common.Address, opts *bind.CallOpts) (bool, RewardsEvent, error) {
// Check if the client is requesting interval 0 on mainnet, then return the hardcoded RewardsEvent
data, ok, err := getMainnetInterval0RewardsEvent(rp, index)
if err != nil {
return false, RewardsEvent{}, err
}
if ok {
return true, data, nil
}

// Get contracts
rocketRewardsPool, err := getRocketRewardsPool(rp, opts)
if err != nil {
Expand Down Expand Up @@ -317,6 +327,48 @@ func GetRewardsEvent(rp *rocketpool.RocketPool, index uint64, rocketRewardsPoolA
return true, eventData, nil
}

// Check if the client is requesting interval 0 on mainnet, then return the hardcoded RewardsEvent
func getMainnetInterval0RewardsEvent(rp *rocketpool.RocketPool, index uint64) (RewardsEvent, bool, error) {
if index != 0 {
return RewardsEvent{}, false, nil
}
// Check if the ec is synced to mainnet
chainID, err := rp.Client.ChainID(context.Background())
if err != nil {
return RewardsEvent{}, false, fmt.Errorf("error getting chainID: %w", err)
}
if chainID.Cmp(big.NewInt(1)) != 0 {
return RewardsEvent{}, false, nil
}

// Hardcoded RewardsEvent for interval 0 on mainnet
treasuryRPL := new(big.Int)
treasuryRPL.SetString("10633670478560109530497", 10)
trustedNodeRPL := new(big.Int)
trustedNodeRPL.SetString("10633670478560109529794", 10)
nodeRPL := new(big.Int)
nodeRPL.SetString("49623795566613844471758", 10)

eventDataInterval_0 := RewardsEvent{
Index: big.NewInt(0),
ExecutionBlock: big.NewInt(15451078),
ConsensusBlock: big.NewInt(4598879),
IntervalsPassed: big.NewInt(1),
TreasuryRPL: treasuryRPL,
TrustedNodeRPL: []*big.Int{trustedNodeRPL},
NodeRPL: []*big.Int{nodeRPL},
NodeETH: []*big.Int{big.NewInt(0)},
UserETH: big.NewInt(0),
MerkleRoot: common.HexToHash("0xb839fa0f5842bf3c8f19091361889fb0f1cb399d64b8da476d372b7de7a93463"),
MerkleTreeCID: "bafybeidrck3sz24acv32h56xdb7ruarxq52oci32del7moxqtief3do73y",
IntervalStartTime: time.Unix(1659591339, 0),
IntervalEndTime: time.Unix(1662010539, 0),
SubmissionTime: time.Unix(1662011717, 0),
}

return eventDataInterval_0, true, nil
}

// Get contracts
var rocketRewardsPoolLock sync.Mutex

Expand Down
3 changes: 3 additions & 0 deletions bindings/rocketpool/ec-interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,7 @@ type ExecutionClient interface {
// SyncProgress retrieves the current progress of the sync algorithm. If there's
// no sync currently running, it returns nil.
SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error)

// ChainID retrieves the current chain ID
ChainID(ctx context.Context) (*big.Int, error)
}
11 changes: 11 additions & 0 deletions shared/services/ec-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,17 @@ func (p *ExecutionClientManager) SyncProgress(ctx context.Context) (*ethereum.Sy
return result.(*ethereum.SyncProgress), err
}

// BlockNumber returns the most recent block number
func (p *ExecutionClientManager) ChainID(ctx context.Context) (*big.Int, error) {
result, err := p.runFunction(func(client *ethclient.Client) (interface{}, error) {
return client.ChainID(ctx)
})
if err != nil {
return nil, err
}
return result.(*big.Int), err
}

/// ==================
/// Internal functions
/// ==================
Expand Down
Loading