# Node Operator Registry

## Getting Node Operator Info

```solidity
/// @notice Node operator parameters and internal state
/// @param operatorOwner Admin address of the node operator
/// @param name Human-readable name
/// @param rewardAddress Address receiving performance rewards
/// @param withdrawalAddress Address receiving withdrawals and execution layer rewards
struct Operator {
    address operatorOwner;
    string name;
    address rewardAddress;
    address withdrawalAddress;
    KeyStat keyStat;
}

/// @notice Statistics of validator pubkeys from a node operator.
/// @param totalCount Total number of validator pubkeys uploaded to this contract
/// @param usedCount Number of validator pubkeys that are already used
/// @param verifiedCount Number of validator pubkeys that are verified by the contract owner
/// @param depositLimit Maximum number of usable validator pubkeys, set by the node operator
struct KeyStat {
    uint64 totalCount;
    uint64 usedCount;
    uint64 verifiedCount;
    uint64 depositLimit;
}
```

#### `NodeOperatorRegistry.getOperator(uint256 id) → Operator`

Getter for the operator record of the given `id`.

```sh
>>> nodeOperatorRegistry.getOperator(0)
operatorOwner: '0xe2F8CeFcDee51F48e3CE5c4Deea3095c43369b36'
name: 'InfStones'
rewardAddress: '0xe2F8CeFcDee51F48e3CE5c4Deea3095c43369b36'
withdrawalAddress: '0xbF4Db410a07b3864A45074313150779b5b99889E'
totalCount: '10'
usedCount: '2'
verifiedCount: '10'
depositLimit: '320'
```

#### `NodeOperatorRegistry.getOperators() → Operator[]`

Getter for an array of all existing operators’ records.

#### `NodeOperatorRegistry.getRewardAddress(uint256 id) → address`

Getter for the reward address of the given `id`.

```bash
>>> nodeOperatorRegistry.getRewardAddress(0)
'0xe2F8CeFcDee51F48e3CE5c4Deea3095c43369b36'
```

#### `NodeOperatorRegistry.getRewardAddresses() → address[]`

Getter for an array of all existing reward addresses.

#### `NodeOperatorRegistry.getWithdrawalAddress(uint256 id) → address`

Getter for the withdrawal manager address of the given `id`.

```bash
>>> nodeOperatorRegistry.getWithdrawalAddress(0)
'0xbF4Db410a07b3864A45074313150779b5b99889E'
```

#### `NodeOperatorRegistry.getWithdrawalAddresses() → address[]`

Getter for an array of all existing withdrawal managers’ addresses.

#### `NodeOperatorRegistry.getWithdrawalCredential(uint256 id) → bytes32`

Getter for the withdrawal credential of the given `id`. Unlike the withdrawal address, withdrawal credential is a piece of `bytes32` data including the withdrawal prefix (currently all Tranchess operators adopt **`ETH1_ADDRESS_WITHDRAWAL_PREFIX`**) and the withdrawal manager address.

```bash
>>> nodeOperatorRegistry.getWithdrawalCredential(0)
'0x010000000000000000000000bf4db410a07b3864a45074313150779b5b99889e'
```

#### `NodeOperatorRegistry.getKeyStat(uint256 id) → KeyStat`

Getter for the validator key status of the given `id`.

```bash
>>> nodeOperatorRegistry.getKeyStat(0)
totalCount: '10'
usedCount: '2'
verifiedCount: '10'
depositLimit: '320'
```

#### `NodeOperatorRegistry.getKeyStats() → KeyStat[]`

Getter for an array of all existing validator key status.

## Getting Validator Key Info

```solidity
/// @notice Storage for pubkey (48 bytes) and signature (96 bytes)
/// @param pubkey0 [0-32) bytes of the pubkey
/// @param pubkey1 [32-48) bytes of the pubkey
/// @param signature0 [0-32) bytes of the signature
/// @param signature1 [32-64) bytes of the signature
/// @param signature2 [64-96) bytes of the signature
struct Key {
    bytes32 pubkey0;
    bytes32 pubkey1; // Only the higher 16 bytes of the second slot are used
    bytes32 signature0;
    bytes32 signature1;
    bytes32 signature2;
}
```

#### `NodeOperatorRegistry.getKey(uint256 id, uint256 index) → Key`

Getter for the validator key struct of the given `id` and `index`.

```bash
>>> nodeOperatorRegistry.getKey(0, 0)
pubkey0: '0xb1b620b54b1909fdf1defc96e60350040cf7fef3dbdfa75099f977c835331201'
pubkey1: '0x644fe9caa6d028dcef5c6d953cdc0d5900000000000000000000000000000000'
signature0: '0x9295c7c1e51c224999192156e0af16ed06a251fd6c90dcce88819642f5109486'
signature1: '0x4fe852dd979a1ec27ccab8dd704cd6170a361d5362d210cbba89a30c3ccda7ba'
signature2: '0x0fcfe368e52ee1a3551145c0a30dfcc21d2ffccd0525e725ed5543dbb34ce92e'
```

#### `NodeOperatorRegistry.getKeys(uint256 id, uint256 start, uint256 count) → Key[]`

Batch getter for the validator key struct of the given `id` and the range starting at `start` spanning `count` length.

#### `NodeOperatorRegistry.getPubkeys(uint256 id, uint256 start, uint256 count) → bytes[]`

Batch getter for the reconstructed validator keys of the given `id` and the range starting at `start` spanning `count` length.

```bash
>>> nodeOperatorRegistry.getPubkeys(0, 2, 3)
[
	'0xb9deda6df019981189155383b54ec08de0f2ee73f696900a487d3dddc0876e366134bd76c6153f37f1dcd27fcbfd8697',
	'0xb1b620b54b1909fdf1defc96e60350040cf7fef3dbdfa75099f977c835331201644fe9caa6d028dcef5c6d953cdc0d59',
	'0xa105b2b7c4212b10a62389fae02f58f49c1f1570ec3e5e0a41c46691ec2de464519d9c234b9bc1d834107a7644b570ec'
]
```

#### `NodeOperatorRegistry.getSignatures(uint256 id, uint256 start, uint256 count) → bytes[]`

Batch getter for the reconstructed validator signatures of the given `id` and the range starting at `start` spanning `count` length.

```bash
>>> nodeOperatorRegistry.getSignatures(0, 2, 3)
[
	'0x846dceeac17a53b49373c68166dbd2dfb5fa4a89ada44d4fdfa054f73b087beb6bc01bb31e89b06d8b88a724110ceb9f033c9d1bee995b74a79f7dae42dad5a584dc01a3f33b80a20ee2451490ae9b2203f1fdb1430f3a8502747cb821d4b05f',
	'0x9295c7c1e51c224999192156e0af16ed06a251fd6c90dcce88819642f51094864fe852dd979a1ec27ccab8dd704cd6170a361d5362d210cbba89a30c3ccda7ba0fcfe368e52ee1a3551145c0a30dfcc21d2ffccd0525e725ed5543dbb34ce92e',
	'0xa6b177f3e9787049caa502959be8d07409fd80b4e93b81f27c262b586eba471845e995d8fac26b705de97aadd19c02390be6a88cdeed5e4ed1a0225843d9e5c7bbdb79cb6dc3912f58ef498f78c1e63895c9cda3651e06c63e1080c0ee78b97c'
]
```

## Operating nodes

#### `NodeOperatorRegistry.addKeys(uint256 id, bytes calldata pubkeys, bytes calldata signatures)`

Batch add validator keys for `id`. `pubkeys` and `signatures` are the concatenated public keys and signatures without padding. `Id` node operator’s owner only.

#### `NodeOperatorRegistry.truncateUnusedKeys(uint256 id)`

Truncate all unused validator keys previously submitted for `id`. `Id` node operator’s owner only.

#### `NodeOperatorRegistry.updateRewardAddress(uint256 id, address newRewardAddress)`

Update the `operator.rewardAddress` to `newRewardAddress` for `id`. By default, the reward address is the same as `operator.operatorOwner`. `Id` node operator’s owner only.

#### `NodeOperatorRegistry.updateDepositLimit(uint256 id, uint64 newDepositLimit)`

Update the `operator.depositLimit` to `newDepositLimit` for `id`, which is the new maximal number of active validators the operator could get assigned. We recommend it to be the current total number of validator keys, but it could go beyond the current validator key total number. `Id` node operator’s owner only.
