Skip to content

Commit e71a417

Browse files
tsudmiunxnn
andauthored
Refactor operator onboarding (#37)
* Refactor validator registration entity * Update Oracles abi * Add deploy step * Update validatorsRegistration Co-authored-by: Andrey Pronin <[email protected]>
1 parent 257e053 commit e71a417

File tree

10 files changed

+140
-24
lines changed

10 files changed

+140
-24
lines changed

.github/workflows/deploy.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- "!*"
7+
tags:
8+
- "v*"
9+
10+
jobs:
11+
docker:
12+
name: Deploy Subgraphs
13+
runs-on: ubuntu-latest
14+
container: node:16-alpine
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v2
18+
- run: |
19+
yarn install
20+
yarn prepare:mainnet
21+
yarn run codegen
22+
yarn run build
23+
yarn global add @graphprotocol/graph-cli
24+
graph auth https://api.thegraph.com/deploy/ ${{ secrets.THEGRAPH_TOKEN }}
25+
yarn deploy:mainnet
26+
name: Deploy

config/goerli.json

+2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"future_fund_address": "0x1867c96601bc5fe24f685d112314b8f3fe228d5a",
1010
"uniswap_v3_factory_address": "0x1f98431c8ad98523631ae4a59f267346ea31f984",
1111
"uniswap_v3_position_manager_address": "0xc36442b4a4522e871399cd717abdd847ab11fe88",
12+
"validator_registration_address": "0xff50ed3d0ec03ac01d4c79aad74928bff48a7b2b",
1213
"contract_checker_address": "0x85ee326f839bc430655a3fad447837072ef52c2f",
1314
"contract_checker_deployment_block": "5797179",
15+
"ethereum_validators_deposit_root_start_block": "6060000",
1416
"oracles_update_period": "3600"
1517
}

config/mainnet.json

+2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"future_fund_address": "0xf91aa4a655b6f43243ed4c2853f3508314daa2ab",
1010
"uniswap_v3_factory_address": "0x1f98431c8ad98523631ae4a59f267346ea31f984",
1111
"uniswap_v3_position_manager_address": "0xc36442b4a4522e871399cd717abdd847ab11fe88",
12+
"validator_registration_address": "0x00000000219ab540356cbb839cbe05303d7705fa",
1213
"contract_checker_address": "0xfc1fc7257aea7c7c08a498594dca97ce5a72fdcb",
1314
"contract_checker_deployment_block": "13748882",
15+
"ethereum_validators_deposit_root_start_block": "13848500",
1416
"oracles_update_period": "86400"
1517
}

packages/constants/index.template.ts

+8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export let POOL_ADDRESS = Address.fromString(
4747
"{{ pool_address }}{{^pool_address}}0x0000000000000000000000000000000000000000{{/pool_address}}"
4848
);
4949

50+
export let VALIDATOR_REGISTRATION_ADDRESS = Address.fromString(
51+
"{{ validator_registration_address }}{{^validator_registration_address}}0x0000000000000000000000000000000000000000{{/validator_registration_address}}"
52+
);
53+
5054
export let CONTRACT_CHECKER_ADDRESS = Address.fromString(
5155
"{{ contract_checker_address }}{{^contract_checker_address}}0x0000000000000000000000000000000000000000{{/contract_checker_address}}"
5256
);
@@ -55,6 +59,10 @@ export let CONTRACT_CHECKER_DEPLOYMENT_BLOCK = BigInt.fromString(
5559
"{{ contract_checker_deployment_block }}{{^contract_checker_deployment_block}}0{{/contract_checker_deployment_block}}"
5660
);
5761

62+
export let ETHEREUM_VALIDATORS_DEPOSIT_ROOT_START_BLOCK = BigInt.fromString(
63+
"{{ ethereum_validators_deposit_root_start_block }}{{^ethereum_validators_deposit_root_start_block}}0{{/ethereum_validators_deposit_root_start_block}}"
64+
);
65+
5866
export let ORACLES_UPDATE_PERIOD = BigInt.fromString(
5967
"{{ oracles_update_period }}{{^oracles_update_period}}0{{/oracles_update_period}}"
6068
);

subgraphs/ethereum/packages/abis/ValidatorRegistration.json

+54
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,59 @@
3535
],
3636
"name": "DepositEvent",
3737
"type": "event"
38+
},
39+
{
40+
"inputs": [
41+
{
42+
"internalType": "bytes",
43+
"name": "pubkey",
44+
"type": "bytes"
45+
},
46+
{
47+
"internalType": "bytes",
48+
"name": "withdrawal_credentials",
49+
"type": "bytes"
50+
},
51+
{
52+
"internalType": "bytes",
53+
"name": "signature",
54+
"type": "bytes"
55+
},
56+
{
57+
"internalType": "bytes32",
58+
"name": "deposit_data_root",
59+
"type": "bytes32"
60+
}
61+
],
62+
"name": "deposit",
63+
"outputs": [],
64+
"stateMutability": "payable",
65+
"type": "function"
66+
},
67+
{
68+
"inputs": [],
69+
"name": "get_deposit_count",
70+
"outputs": [
71+
{
72+
"internalType": "bytes",
73+
"name": "",
74+
"type": "bytes"
75+
}
76+
],
77+
"stateMutability": "view",
78+
"type": "function"
79+
},
80+
{
81+
"inputs": [],
82+
"name": "get_deposit_root",
83+
"outputs": [
84+
{
85+
"internalType": "bytes32",
86+
"name": "",
87+
"type": "bytes32"
88+
}
89+
],
90+
"stateMutability": "view",
91+
"type": "function"
3892
}
3993
]

subgraphs/ethereum/schema.graphql

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
Eth2 Validator registration
33
"""
44
type ValidatorRegistration @entity {
5-
"The validator public key"
5+
"Set to `transaction hash-log index`"
66
id: ID!
77

8+
"The validator public key"
9+
publicKey: Bytes!
10+
811
"The validator withdrawal credentials"
912
withdrawalCredentials: Bytes!
1013

11-
"The registration index (little endian)"
12-
index: Bytes!
14+
"The validators deposit root"
15+
validatorsDepositRoot: Bytes!
1316

1417
"The block number the registration was created at"
1518
createdAtBlock: BigInt!

subgraphs/ethereum/src/mappings/validatorRegistration.ts

+33-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,44 @@
11
import { ethereum, log } from "@graphprotocol/graph-ts";
2-
import { DepositEvent } from "../../generated/ValidatorRegistration/ValidatorRegistration";
2+
import {
3+
BYTES_ZERO,
4+
VALIDATOR_REGISTRATION_ADDRESS,
5+
ETHEREUM_VALIDATORS_DEPOSIT_ROOT_START_BLOCK,
6+
} from "const";
7+
import {
8+
DepositEvent,
9+
ValidatorRegistration as ValidatorRegistrationContract,
10+
} from "../../generated/ValidatorRegistration/ValidatorRegistration";
311
import { Block, ValidatorRegistration } from "../../generated/schema";
412

513
export function handleDepositEvent(event: DepositEvent): void {
6-
let publicKey = event.params.pubkey.toHexString();
7-
let validator = ValidatorRegistration.load(publicKey);
14+
let registrationId = event.transaction.hash
15+
.toHexString()
16+
.concat("-")
17+
.concat(event.logIndex.toString());
18+
let registration = new ValidatorRegistration(registrationId);
19+
registration.publicKey = event.params.pubkey;
20+
registration.withdrawalCredentials = event.params.withdrawal_credentials;
21+
registration.createdAtBlock = event.block.number;
22+
registration.createdAtTimestamp = event.block.timestamp;
823

9-
if (validator == null) {
10-
validator = new ValidatorRegistration(publicKey);
11-
validator.withdrawalCredentials = event.params.withdrawal_credentials;
12-
validator.index = event.params.index;
13-
validator.createdAtBlock = event.block.number;
14-
validator.createdAtTimestamp = event.block.timestamp;
15-
validator.save();
24+
if (event.block.number.ge(ETHEREUM_VALIDATORS_DEPOSIT_ROOT_START_BLOCK)) {
25+
let contract = ValidatorRegistrationContract.bind(
26+
VALIDATOR_REGISTRATION_ADDRESS
27+
);
28+
let depositRootCall = contract.try_get_deposit_root();
29+
if (!depositRootCall.reverted) {
30+
registration.validatorsDepositRoot = depositRootCall.value;
31+
} else {
32+
registration.validatorsDepositRoot = BYTES_ZERO;
33+
}
34+
} else {
35+
registration.validatorsDepositRoot = BYTES_ZERO;
1636
}
1737

38+
registration.save();
1839
log.info("[VRC] DepositEvent publicKey={} withdrawalCredentials={}", [
19-
validator.id,
20-
validator.withdrawalCredentials.toHexString(),
40+
registration.id,
41+
registration.withdrawalCredentials.toHexString(),
2142
]);
2243
}
2344

subgraphs/stakewise/config/goerli.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"startBlock": "4468087"
66
},
77
"poolValidators": {
8-
"address": "0x908c06affda0ffdbb4578629aa8ccff372e510b6",
9-
"startBlock": "6049456"
8+
"address": "0x3a2a4c01bc8595e168a90ba6f04bb8a9feac2acb",
9+
"startBlock": "6061101"
1010
},
1111
"merkleDistributor": {
1212
"address": "0x6ef0172b79131c66c7012db3545d637b116feb12",
@@ -17,8 +17,8 @@
1717
"startBlock": "4623211"
1818
},
1919
"oracles": {
20-
"address": "0x4bbaa17efd71683dcb9c769dd38e7674994fe38d",
21-
"startBlock": "6049460"
20+
"address": "0x531b9d9cb268e88d53a87890699bbe31326a6f08",
21+
"startBlock": "6061103"
2222
},
2323
"stakeWiseToken": {
2424
"address": "0x0e2497aacec2755d831e4afdea25b4ef1b823855",

subgraphs/stakewise/config/mainnet.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"startBlock": "11726298"
66
},
77
"poolValidators": {
8-
"address": "0x0e75786cb831bee6d4484031af12490ab528c770",
9-
"startBlock": "13776563"
8+
"address": "0x002932e11e95dc84c17ed5f94a0439645d8a97bc",
9+
"startBlock": "13848249"
1010
},
1111
"merkleDistributor": {
1212
"address": "0xa3f21010e8b9a3930996c8849df38f9ca3647c20",
@@ -17,8 +17,8 @@
1717
"startBlock": "12271843"
1818
},
1919
"oracles": {
20-
"address": "0xe949060ace386d5e277de217703b17a2547f24c0",
21-
"startBlock": "13776565"
20+
"address": "0x8a887282e67ff41d36c0b7537eab035291461acd",
21+
"startBlock": "13848254"
2222
},
2323
"stakeWiseToken": {
2424
"address": "0x48c3399719b582dd63eb5aadf12a40b4c3f52fa2",

subgraphs/stakewise/packages/abis/Oracles.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@
627627
},
628628
{
629629
"internalType": "bytes32",
630-
"name": "validatorsDepositCount",
630+
"name": "validatorsDepositRoot",
631631
"type": "bytes32"
632632
},
633633
{

0 commit comments

Comments
 (0)