|
| 1 | +package deposit |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "math/big" |
| 6 | + |
| 7 | + "github.com/ethereum/go-ethereum/accounts/abi/bind" |
| 8 | + "github.com/ethereum/go-ethereum/common" |
| 9 | + "github.com/rocket-pool/smartnode/bindings/rocketpool" |
| 10 | +) |
| 11 | + |
| 12 | +// Estimate the gas required to exit the validator queue |
| 13 | +func EstimateExitQueueGas(rp *rocketpool.RocketPool, validatorIndex uint64, expressQueue bool, opts *bind.TransactOpts) (rocketpool.GasInfo, error) { |
| 14 | + rocketDepositPool, err := getRocketDepositPool(rp, nil) |
| 15 | + if err != nil { |
| 16 | + return rocketpool.GasInfo{}, err |
| 17 | + } |
| 18 | + validatorIndexBig := big.NewInt(int64(validatorIndex)) |
| 19 | + return rocketDepositPool.GetTransactionGasInfo(opts, "exitQueue", validatorIndexBig, expressQueue) |
| 20 | +} |
| 21 | + |
| 22 | +// Exit the validator queue |
| 23 | +func ExitQueue(rp *rocketpool.RocketPool, validatorIndex uint64, expressQueue bool, opts *bind.TransactOpts) (common.Hash, error) { |
| 24 | + rocketDepositPool, err := getRocketDepositPool(rp, nil) |
| 25 | + if err != nil { |
| 26 | + return common.Hash{}, err |
| 27 | + } |
| 28 | + validatorIndexBig := big.NewInt(int64(validatorIndex)) |
| 29 | + tx, err := rocketDepositPool.Transact(opts, "exitQueue", validatorIndexBig, expressQueue) |
| 30 | + if err != nil { |
| 31 | + return common.Hash{}, fmt.Errorf("error exiting validator queue: %w", err) |
| 32 | + } |
| 33 | + return tx.Hash(), nil |
| 34 | +} |
| 35 | + |
| 36 | +// Struct to hold queue top (address of the validator at the top of the queue and a boolean indicating if the assignment is possible) |
| 37 | +type QueueTop struct { |
| 38 | + Receiver common.Address `abi:"receiver"` |
| 39 | + AssignmentPossible bool `abi:"assignmentPossible"` |
| 40 | + HeadMovedBlock *big.Int `abi:"headMovedBlock"` |
| 41 | +} |
| 42 | + |
| 43 | +func GetQueueTop(rp *rocketpool.RocketPool, opts *bind.CallOpts) (QueueTop, error) { |
| 44 | + rocketDepositPool, err := getRocketDepositPool(rp, opts) |
| 45 | + if err != nil { |
| 46 | + return QueueTop{}, err |
| 47 | + } |
| 48 | + queueTop := new(QueueTop) |
| 49 | + if err := rocketDepositPool.Call(opts, queueTop, "getQueueTop"); err != nil { |
| 50 | + return QueueTop{}, fmt.Errorf("error getting queue top: %w", err) |
| 51 | + } |
| 52 | + return *queueTop, nil |
| 53 | +} |
| 54 | + |
| 55 | +func GetTotalQueueLength(rp *rocketpool.RocketPool, opts *bind.CallOpts) (uint32, error) { |
| 56 | + rocketDepositPool, err := getRocketDepositPool(rp, opts) |
| 57 | + if err != nil { |
| 58 | + return 0, err |
| 59 | + } |
| 60 | + totalLength := new(*big.Int) |
| 61 | + if err := rocketDepositPool.Call(opts, totalLength, "getTotalQueueLength"); err != nil { |
| 62 | + return 0, fmt.Errorf("error getting total queue length: %w", err) |
| 63 | + } |
| 64 | + return uint32((*totalLength).Uint64()), nil |
| 65 | +} |
| 66 | + |
| 67 | +func GetExpressQueueLength(rp *rocketpool.RocketPool, opts *bind.CallOpts) (uint32, error) { |
| 68 | + rocketDepositPool, err := getRocketDepositPool(rp, opts) |
| 69 | + if err != nil { |
| 70 | + return 0, err |
| 71 | + } |
| 72 | + length := new(*big.Int) |
| 73 | + if err := rocketDepositPool.Call(opts, length, "getExpressQueueLength"); err != nil { |
| 74 | + return 0, fmt.Errorf("error getting express queue length: %w", err) |
| 75 | + } |
| 76 | + return uint32((*length).Uint64()), nil |
| 77 | +} |
| 78 | + |
| 79 | +func GetStandardQueueLength(rp *rocketpool.RocketPool, opts *bind.CallOpts) (uint32, error) { |
| 80 | + rocketDepositPool, err := getRocketDepositPool(rp, opts) |
| 81 | + if err != nil { |
| 82 | + return 0, err |
| 83 | + } |
| 84 | + length := new(*big.Int) |
| 85 | + if err := rocketDepositPool.Call(opts, length, "getStandardQueueLength"); err != nil { |
| 86 | + return 0, fmt.Errorf("error getting standard queue length: %w", err) |
| 87 | + } |
| 88 | + return uint32((*length).Uint64()), nil |
| 89 | +} |
0 commit comments