Skip to content

Commit

Permalink
Refactor operator onboarding (#37)
Browse files Browse the repository at this point in the history
* Refactor validator registration entity

* Update Oracles abi

* Add deploy step

* Update validatorsRegistration

Co-authored-by: Andrey Pronin <[email protected]>
  • Loading branch information
tsudmi and unxnn authored Dec 21, 2021
1 parent 257e053 commit e71a417
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 24 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Deploy

on:
push:
branches:
- "!*"
tags:
- "v*"

jobs:
docker:
name: Deploy Subgraphs
runs-on: ubuntu-latest
container: node:16-alpine
steps:
- name: Checkout code
uses: actions/checkout@v2
- run: |
yarn install
yarn prepare:mainnet
yarn run codegen
yarn run build
yarn global add @graphprotocol/graph-cli
graph auth https://api.thegraph.com/deploy/ ${{ secrets.THEGRAPH_TOKEN }}
yarn deploy:mainnet
name: Deploy
2 changes: 2 additions & 0 deletions config/goerli.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"future_fund_address": "0x1867c96601bc5fe24f685d112314b8f3fe228d5a",
"uniswap_v3_factory_address": "0x1f98431c8ad98523631ae4a59f267346ea31f984",
"uniswap_v3_position_manager_address": "0xc36442b4a4522e871399cd717abdd847ab11fe88",
"validator_registration_address": "0xff50ed3d0ec03ac01d4c79aad74928bff48a7b2b",
"contract_checker_address": "0x85ee326f839bc430655a3fad447837072ef52c2f",
"contract_checker_deployment_block": "5797179",
"ethereum_validators_deposit_root_start_block": "6060000",
"oracles_update_period": "3600"
}
2 changes: 2 additions & 0 deletions config/mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"future_fund_address": "0xf91aa4a655b6f43243ed4c2853f3508314daa2ab",
"uniswap_v3_factory_address": "0x1f98431c8ad98523631ae4a59f267346ea31f984",
"uniswap_v3_position_manager_address": "0xc36442b4a4522e871399cd717abdd847ab11fe88",
"validator_registration_address": "0x00000000219ab540356cbb839cbe05303d7705fa",
"contract_checker_address": "0xfc1fc7257aea7c7c08a498594dca97ce5a72fdcb",
"contract_checker_deployment_block": "13748882",
"ethereum_validators_deposit_root_start_block": "13848500",
"oracles_update_period": "86400"
}
8 changes: 8 additions & 0 deletions packages/constants/index.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export let POOL_ADDRESS = Address.fromString(
"{{ pool_address }}{{^pool_address}}0x0000000000000000000000000000000000000000{{/pool_address}}"
);

export let VALIDATOR_REGISTRATION_ADDRESS = Address.fromString(
"{{ validator_registration_address }}{{^validator_registration_address}}0x0000000000000000000000000000000000000000{{/validator_registration_address}}"
);

export let CONTRACT_CHECKER_ADDRESS = Address.fromString(
"{{ contract_checker_address }}{{^contract_checker_address}}0x0000000000000000000000000000000000000000{{/contract_checker_address}}"
);
Expand All @@ -55,6 +59,10 @@ export let CONTRACT_CHECKER_DEPLOYMENT_BLOCK = BigInt.fromString(
"{{ contract_checker_deployment_block }}{{^contract_checker_deployment_block}}0{{/contract_checker_deployment_block}}"
);

export let ETHEREUM_VALIDATORS_DEPOSIT_ROOT_START_BLOCK = BigInt.fromString(
"{{ ethereum_validators_deposit_root_start_block }}{{^ethereum_validators_deposit_root_start_block}}0{{/ethereum_validators_deposit_root_start_block}}"
);

export let ORACLES_UPDATE_PERIOD = BigInt.fromString(
"{{ oracles_update_period }}{{^oracles_update_period}}0{{/oracles_update_period}}"
);
54 changes: 54 additions & 0 deletions subgraphs/ethereum/packages/abis/ValidatorRegistration.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,59 @@
],
"name": "DepositEvent",
"type": "event"
},
{
"inputs": [
{
"internalType": "bytes",
"name": "pubkey",
"type": "bytes"
},
{
"internalType": "bytes",
"name": "withdrawal_credentials",
"type": "bytes"
},
{
"internalType": "bytes",
"name": "signature",
"type": "bytes"
},
{
"internalType": "bytes32",
"name": "deposit_data_root",
"type": "bytes32"
}
],
"name": "deposit",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [],
"name": "get_deposit_count",
"outputs": [
{
"internalType": "bytes",
"name": "",
"type": "bytes"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "get_deposit_root",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
}
]
9 changes: 6 additions & 3 deletions subgraphs/ethereum/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
Eth2 Validator registration
"""
type ValidatorRegistration @entity {
"The validator public key"
"Set to `transaction hash-log index`"
id: ID!

"The validator public key"
publicKey: Bytes!

"The validator withdrawal credentials"
withdrawalCredentials: Bytes!

"The registration index (little endian)"
index: Bytes!
"The validators deposit root"
validatorsDepositRoot: Bytes!

"The block number the registration was created at"
createdAtBlock: BigInt!
Expand Down
45 changes: 33 additions & 12 deletions subgraphs/ethereum/src/mappings/validatorRegistration.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
import { ethereum, log } from "@graphprotocol/graph-ts";
import { DepositEvent } from "../../generated/ValidatorRegistration/ValidatorRegistration";
import {
BYTES_ZERO,
VALIDATOR_REGISTRATION_ADDRESS,
ETHEREUM_VALIDATORS_DEPOSIT_ROOT_START_BLOCK,
} from "const";
import {
DepositEvent,
ValidatorRegistration as ValidatorRegistrationContract,
} from "../../generated/ValidatorRegistration/ValidatorRegistration";
import { Block, ValidatorRegistration } from "../../generated/schema";

export function handleDepositEvent(event: DepositEvent): void {
let publicKey = event.params.pubkey.toHexString();
let validator = ValidatorRegistration.load(publicKey);
let registrationId = event.transaction.hash
.toHexString()
.concat("-")
.concat(event.logIndex.toString());
let registration = new ValidatorRegistration(registrationId);
registration.publicKey = event.params.pubkey;
registration.withdrawalCredentials = event.params.withdrawal_credentials;
registration.createdAtBlock = event.block.number;
registration.createdAtTimestamp = event.block.timestamp;

if (validator == null) {
validator = new ValidatorRegistration(publicKey);
validator.withdrawalCredentials = event.params.withdrawal_credentials;
validator.index = event.params.index;
validator.createdAtBlock = event.block.number;
validator.createdAtTimestamp = event.block.timestamp;
validator.save();
if (event.block.number.ge(ETHEREUM_VALIDATORS_DEPOSIT_ROOT_START_BLOCK)) {
let contract = ValidatorRegistrationContract.bind(
VALIDATOR_REGISTRATION_ADDRESS
);
let depositRootCall = contract.try_get_deposit_root();
if (!depositRootCall.reverted) {
registration.validatorsDepositRoot = depositRootCall.value;
} else {
registration.validatorsDepositRoot = BYTES_ZERO;
}
} else {
registration.validatorsDepositRoot = BYTES_ZERO;
}

registration.save();
log.info("[VRC] DepositEvent publicKey={} withdrawalCredentials={}", [
validator.id,
validator.withdrawalCredentials.toHexString(),
registration.id,
registration.withdrawalCredentials.toHexString(),
]);
}

Expand Down
8 changes: 4 additions & 4 deletions subgraphs/stakewise/config/goerli.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"startBlock": "4468087"
},
"poolValidators": {
"address": "0x908c06affda0ffdbb4578629aa8ccff372e510b6",
"startBlock": "6049456"
"address": "0x3a2a4c01bc8595e168a90ba6f04bb8a9feac2acb",
"startBlock": "6061101"
},
"merkleDistributor": {
"address": "0x6ef0172b79131c66c7012db3545d637b116feb12",
Expand All @@ -17,8 +17,8 @@
"startBlock": "4623211"
},
"oracles": {
"address": "0x4bbaa17efd71683dcb9c769dd38e7674994fe38d",
"startBlock": "6049460"
"address": "0x531b9d9cb268e88d53a87890699bbe31326a6f08",
"startBlock": "6061103"
},
"stakeWiseToken": {
"address": "0x0e2497aacec2755d831e4afdea25b4ef1b823855",
Expand Down
8 changes: 4 additions & 4 deletions subgraphs/stakewise/config/mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"startBlock": "11726298"
},
"poolValidators": {
"address": "0x0e75786cb831bee6d4484031af12490ab528c770",
"startBlock": "13776563"
"address": "0x002932e11e95dc84c17ed5f94a0439645d8a97bc",
"startBlock": "13848249"
},
"merkleDistributor": {
"address": "0xa3f21010e8b9a3930996c8849df38f9ca3647c20",
Expand All @@ -17,8 +17,8 @@
"startBlock": "12271843"
},
"oracles": {
"address": "0xe949060ace386d5e277de217703b17a2547f24c0",
"startBlock": "13776565"
"address": "0x8a887282e67ff41d36c0b7537eab035291461acd",
"startBlock": "13848254"
},
"stakeWiseToken": {
"address": "0x48c3399719b582dd63eb5aadf12a40b4c3f52fa2",
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/stakewise/packages/abis/Oracles.json
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@
},
{
"internalType": "bytes32",
"name": "validatorsDepositCount",
"name": "validatorsDepositRoot",
"type": "bytes32"
},
{
Expand Down

0 comments on commit e71a417

Please sign in to comment.