Skip to content

Commit

Permalink
Release gnosis subgraphs (#48)
Browse files Browse the repository at this point in the history
* Release gnosis subgraphs

* Fix period duration calculation
  • Loading branch information
tsudmi authored Feb 27, 2022
1 parent 83a460a commit 4d85468
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 58 deletions.
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"]
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
"rules": {
"prefer-const": "off"
}
}
2 changes: 1 addition & 1 deletion .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
matrix:
node: ['14.x']
os: [ubuntu-latest]
network: ['goerli', 'perm_goerli', 'mainnet']
network: ['goerli', 'perm_goerli', 'gnosis', 'mainnet']

runs-on: ${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
network: ['goerli', 'perm_goerli', 'mainnet']
network: ['goerli', 'perm_goerli', 'gnosis', 'mainnet']

runs-on: ${{ matrix.os }}

Expand Down
17 changes: 17 additions & 0 deletions config/gnosis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"staked_eth_token_address": "0x9aebd2322d3d5fb69324a3cfe380dd11bc3694d2",
"reward_eth_token_address": "0x6ffa613ed41585b1c1e517a78d140cfbd68be639",
"stakewise_token_address": "0xfda94f056346d2320d4b5e468d6ad099b2277746",
"merkle_distributor_address": "0x8c8f5bf28081984527dd94c627f591e28db7e7a0",
"merkle_drop_address": "0x0000000000000000000000000000000000000000",
"pool_address": "0x9e6631d118c28b3d61c68f14ff30a99f7e91963a",
"dao_address": "0x8737f638e9af54e89ed9e1234dbc68b115cd169e",
"future_fund_address": "0x8737f638e9af54e89ed9e1234dbc68b115cd169e",
"uniswap_v3_factory_address": "0x0000000000000000000000000000000000000000",
"uniswap_v3_position_manager_address": "0x0000000000000000000000000000000000000000",
"validator_registration_address": "0x0b98057ea310f4d31f2a452b414647007d1645d9",
"contract_checker_address": "0x814f9c8c0269f11996138c77cc16a3a7f0a36b0c",
"contract_checker_deployment_block": "20759530",
"ethereum_validators_deposit_root_start_block": "20760606",
"oracles_update_period": "86400"
}
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stakewise-subgraphs",
"version": "1.1.0",
"version": "1.1.1",
"description": "Subgraphs for the StakeWise Protocol",
"repository": "https://github.com/stakewise/subgraphs",
"license": "AGPL-3.0-only",
Expand All @@ -12,12 +12,14 @@
"scripts": {
"build:goerli": "yarn workspaces run build:goerli",
"build:perm_goerli": "yarn workspaces run build:perm_goerli",
"build:gnosis": "yarn workspaces run build:gnosis",
"build:mainnet": "yarn workspaces run build:mainnet",
"create:local": "yarn workspaces run create:local",
"deploy:goerli": "yarn workspaces run deploy:goerli",
"deploy:perm_goerli": "yarn workspaces run deploy:perm_goerli",
"deploy:gnosis": "yarn workspaces run deploy:gnosis",
"deploy:mainnet": "yarn workspaces run deploy:mainnet",
"deploy:local": "yarn workspaces run deploy:local"
"deploy:local": "yarn workspaces run deploy:local",
"create:local": "yarn workspaces run create:local"
},
"devDependencies": {
"@graphprotocol/graph-cli": "0.26.0",
Expand Down
9 changes: 6 additions & 3 deletions packages/constants/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
{
"name": "const",
"version": "1.1.0",
"version": "1.1.1",
"license": "AGPL-3.0-only",
"main": "index.ts",
"scripts": {
"prepare:goerli": "mustache ../../config/goerli.json index.template.ts > index.ts",
"prepare:perm_goerli": "mustache ../../config/perm_goerli.json index.template.ts > index.ts",
"prepare:mainnet": "mustache ../../config/mainnet.json index.template.ts > index.ts",
"prepare:gnosis": "mustache ../../config/gnosis.json index.template.ts > index.ts",
"build:goerli": "yarn prepare:goerli",
"build:perm_goerli": "yarn prepare:perm_goerli",
"build:mainnet": "yarn prepare:mainnet",
"create:local": "true",
"build:gnosis": "yarn prepare:gnosis",
"deploy:goerli": "yarn build:goerli",
"deploy:perm_goerli": "yarn build:perm_goerli",
"deploy:mainnet": "yarn build:mainnet",
"deploy:local": "true"
"deploy:gnosis": "yarn build:gnosis",
"deploy:local": "true",
"create:local": "true"
}
}
7 changes: 7 additions & 0 deletions subgraphs/ethereum/config/gnosis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"network": "xdai",
"validatorRegistration": {
"address": "0x0b98057ea310f4d31f2a452b414647007d1645d9",
"startBlock": "19469076"
}
}
15 changes: 9 additions & 6 deletions subgraphs/ethereum/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
{
"name": "ethereum",
"version": "1.1.0",
"version": "1.1.1",
"license": "AGPL-3.0-only",
"scripts": {
"prepare:goerli": "mustache config/goerli.json subgraph.template.yaml > subgraph.yaml",
"prepare:mainnet": "mustache config/mainnet.json subgraph.template.yaml > subgraph.yaml",
"prepare:perm_goerli": "true",
"prepare:gnosis": "mustache config/gnosis.json subgraph.template.yaml > subgraph.yaml",
"prepare:mainnet": "mustache config/mainnet.json subgraph.template.yaml > subgraph.yaml",
"build:goerli": "yarn prepare:goerli && graph codegen subgraph.yaml && graph build subgraph.yaml",
"build:mainnet": "yarn prepare:mainnet && graph codegen subgraph.yaml && graph build subgraph.yaml",
"build:perm_goerli": "yarn prepare:perm_goerli",
"create:local": "graph create --node $GRAPH_NODE_URL stakewise/ethereum",
"deploy:mainnet": "yarn build:mainnet && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ stakewise/ethereum-mainnet",
"build:gnosis": "yarn prepare:gnosis && graph codegen subgraph.yaml && graph build subgraph.yaml",
"build:mainnet": "yarn prepare:mainnet && graph codegen subgraph.yaml && graph build subgraph.yaml",
"deploy:goerli": "yarn build:goerli && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ stakewise/ethereum-goerli",
"deploy:perm_goerli": "yarn build:perm_goerli",
"deploy:local": "graph deploy --version-label 1.1.0 --node $GRAPH_NODE_URL --ipfs $IPFS_URL stakewise/ethereum"
"deploy:gnosis": "yarn build:gnosis && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ stakewise/ethereum-gnosis",
"deploy:mainnet": "yarn build:mainnet && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ stakewise/ethereum-mainnet",
"deploy:local": "graph deploy --version-label 1.1.1 --node $GRAPH_NODE_URL --ipfs $IPFS_URL stakewise/ethereum",
"create:local": "graph create --node $GRAPH_NODE_URL stakewise/ethereum"
}
}
15 changes: 9 additions & 6 deletions subgraphs/rari-fuse/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
{
"name": "rari-fuse",
"version": "1.1.0",
"version": "1.1.1",
"license": "AGPL-3.0-only",
"scripts": {
"prepare:goerli": "true",
"prepare:mainnet": "mustache config/mainnet.json subgraph.template.yaml > subgraph.yaml",
"prepare:perm_goerli": "true",
"prepare:gnosis": "true",
"prepare:mainnet": "mustache config/mainnet.json subgraph.template.yaml > subgraph.yaml",
"build:goerli": "yarn prepare:goerli",
"build:mainnet": "yarn prepare:mainnet && graph codegen subgraph.yaml && graph build subgraph.yaml",
"build:perm_goerli": "yarn prepare:perm_goerli",
"create:local": "graph create --node $GRAPH_NODE_URL stakewise/rari-fuse",
"deploy:mainnet": "yarn build:mainnet && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ stakewise/rari-fuse-mainnet",
"build:gnosis": "yarn prepare:gnosis",
"build:mainnet": "yarn prepare:mainnet && graph codegen subgraph.yaml && graph build subgraph.yaml",
"deploy:goerli": "yarn build:goerli",
"deploy:perm_goerli": "yarn build:perm_goerli",
"deploy:local": "graph deploy --version-label 1.1.0 --node $GRAPH_NODE_URL --ipfs $IPFS_URL stakewise/rari-fuse"
"deploy:gnosis": "yarn build:gnosis",
"deploy:mainnet": "yarn build:mainnet && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ stakewise/rari-fuse-mainnet",
"deploy:local": "graph deploy --version-label 1.1.1 --node $GRAPH_NODE_URL --ipfs $IPFS_URL stakewise/rari-fuse",
"create:local": "graph create --node $GRAPH_NODE_URL stakewise/rari-fuse"
}
}
39 changes: 39 additions & 0 deletions subgraphs/stakewise/config/gnosis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"network": "xdai",
"pool": {
"address": "0x9e6631d118c28b3d61c68f14ff30a99f7e91963a",
"startBlock": "20759537"
},
"poolValidators": {
"address": "0xc8d8b1d8c37925cdf106c955ac330739ef4e9362",
"startBlock": "20759540"
},
"merkleDistributor": {
"address": "0x8c8f5bf28081984527dd94c627f591e28db7e7a0",
"startBlock": "20759551"
},
"vestingEscrowFactory": {
"address": "0x0000000000000000000000000000000000000000",
"startBlock": "20759551"
},
"oracles": {
"address": "0xd0f5ddaed2d8bae1f451d2a11ffae1806f2ee1a5",
"startBlock": "20759554"
},
"stakeWiseToken": {
"address": "0xfda94f056346d2320d4b5e468d6ad099b2277746",
"startBlock": "20299140"
},
"stakedEthToken": {
"address": "0x9aebd2322d3d5fb69324a3cfe380dd11bc3694d2",
"startBlock": "20759547"
},
"rewardEthToken": {
"address": "0x6ffa613ed41585b1c1e517a78d140cfbd68be639",
"startBlock": "20759544"
},
"roles": {
"address": "0x814f9c8c0269f11996138c77cc16a3a7f0a36b0c",
"startBlock": "20759534"
}
}
9 changes: 6 additions & 3 deletions subgraphs/stakewise/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
{
"name": "stakewise",
"version": "1.1.0",
"version": "1.1.1",
"license": "AGPL-3.0-only",
"scripts": {
"prepare:goerli": "mustache config/goerli.json subgraph.template.yaml > subgraph.yaml",
"prepare:perm_goerli": "mustache config/perm_goerli.json subgraph.template.yaml > subgraph.yaml",
"prepare:gnosis": "mustache config/gnosis.json subgraph.template.yaml > subgraph.yaml",
"prepare:mainnet": "mustache config/mainnet.json subgraph.template.yaml > subgraph.yaml",
"build:goerli": "yarn prepare:goerli && graph codegen subgraph.yaml && graph build subgraph.yaml",
"build:perm_goerli": "yarn prepare:perm_goerli && graph codegen subgraph.yaml && graph build subgraph.yaml",
"build:mainnet": "yarn prepare:mainnet && graph codegen subgraph.yaml && graph build subgraph.yaml",
"create:local": "graph create --node $GRAPH_NODE_URL stakewise/stakewise",
"build:gnosis": "yarn prepare:gnosis && graph codegen subgraph.yaml && graph build subgraph.yaml",
"deploy:goerli": "yarn build:goerli && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ stakewise/stakewise-goerli",
"deploy:perm_goerli": "yarn build:perm_goerli && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ stakewise/stakewise-perm-goerli",
"deploy:gnosis": "yarn build:gnosis && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ stakewise/stakewise-gnosis",
"deploy:mainnet": "yarn build:mainnet && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ stakewise/stakewise-mainnet",
"deploy:local": "graph deploy --version-label 1.1.0 --node $GRAPH_NODE_URL --ipfs $IPFS_URL stakewise/stakewise"
"deploy:local": "graph deploy --version-label 1.1.1 --node $GRAPH_NODE_URL --ipfs $IPFS_URL stakewise/stakewise",
"create:local": "graph create --node $GRAPH_NODE_URL stakewise/stakewise"
}
}
3 changes: 3 additions & 0 deletions subgraphs/stakewise/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ type RewardEthToken @entity {

"The current rewards update timestamp"
updatedAtTimestamp: BigInt!

"The total number of staking reward updates"
updatesCount: BigInt!
}

"""
Expand Down
27 changes: 17 additions & 10 deletions subgraphs/stakewise/src/entities/rewardEthToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,38 @@ export function createOrLoadRewardEthToken(): RewardEthToken {
rewardEthToken.protocolPeriodReward = BIG_INT_ZERO;
rewardEthToken.updatedAtBlock = BIG_INT_ZERO;
rewardEthToken.updatedAtTimestamp = BIG_INT_ZERO;
rewardEthToken.updatesCount = BIG_INT_ZERO;
rewardEthToken.save();
}
return rewardEthToken as RewardEthToken;
}

export function createStakingRewardsSnapshot(
snapshotId: string,
lastUpdateTimestamp: BigInt,
newSnapshotId: BigInt,
totalStaked: BigInt,
periodTotalRewards: BigInt,
periodProtocolRewards: BigInt,
block: ethereum.Block
): void {
let snapshot = new StakingRewardsSnapshot(snapshotId);

let snapshotId0 = newSnapshotId.minus(BigInt.fromString("2")).toString();
let snapshot0 = StakingRewardsSnapshot.load(snapshotId0);
let snapshotId1 = newSnapshotId.minus(BigInt.fromString("1")).toString();
let snapshot1 = StakingRewardsSnapshot.load(snapshotId1);
let periodDuration = BIG_INT_ZERO;
let submitDuration = block.timestamp.minus(lastUpdateTimestamp);
if (submitDuration.le(ORACLES_UPDATE_PERIOD)) {
periodDuration = submitDuration
} else {
while (periodDuration.plus(ORACLES_UPDATE_PERIOD).lt(submitDuration)) {
periodDuration = periodDuration.plus(ORACLES_UPDATE_PERIOD);
if (snapshot0 != null && snapshot1 != null) {
let periodStart = snapshot0.createdAtTimestamp;
while (periodStart.plus(ORACLES_UPDATE_PERIOD).lt(snapshot1.createdAtTimestamp)) {
periodStart = periodStart.plus(ORACLES_UPDATE_PERIOD);
}

let periodEnd = snapshot1.createdAtTimestamp;
while (periodEnd.plus(ORACLES_UPDATE_PERIOD).lt(block.timestamp)) {
periodEnd = periodEnd.plus(ORACLES_UPDATE_PERIOD);
}
periodDuration = periodEnd.minus(periodStart);
}

let snapshot = new StakingRewardsSnapshot(newSnapshotId.toString());
snapshot.periodTotalRewards = periodTotalRewards;
snapshot.periodProtocolRewards = periodProtocolRewards;
snapshot.periodDuration = periodDuration;
Expand Down
29 changes: 10 additions & 19 deletions subgraphs/stakewise/src/mappings/rewardEthToken.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { log } from "@graphprotocol/graph-ts";
import { ADDRESS_ZERO, BIG_INT_ZERO, CONTRACT_CHECKER_ADDRESS } from "const";
import { ADDRESS_ZERO, BIG_INT_ONE, BIG_INT_ZERO, CONTRACT_CHECKER_ADDRESS } from "const";
import {
createOrLoadNetwork,
createOrLoadRewardEthToken,
Expand All @@ -22,19 +22,16 @@ export function handleRewardsUpdatedV0(event: RewardsUpdatedV0): void {
let rewardEthToken = createOrLoadRewardEthToken();
let pool = createOrLoadPool();

let snapshotId = event.transaction.hash
.toHexString()
.concat("-")
.concat(event.logIndex.toString());
let updatesCount = rewardEthToken.updatesCount.plus(BIG_INT_ONE);
createStakingRewardsSnapshot(
snapshotId,
rewardEthToken.updatedAtTimestamp,
updatesCount,
pool.totalStaked,
event.params.periodRewards,
BIG_INT_ZERO,
event.block
);

rewardEthToken.updatesCount = updatesCount;
rewardEthToken.rewardPerStakedEthToken = event.params.rewardPerToken;
rewardEthToken.totalRewards = event.params.totalRewards;
rewardEthToken.updatedAtBlock = event.block.number;
Expand All @@ -54,19 +51,16 @@ export function handleRewardsUpdatedV1(event: RewardsUpdatedV1): void {
let rewardEthToken = createOrLoadRewardEthToken();
let pool = createOrLoadPool();

let snapshotId = event.transaction.hash
.toHexString()
.concat("-")
.concat(event.logIndex.toString());
let updatesCount = rewardEthToken.updatesCount.plus(BIG_INT_ONE);
createStakingRewardsSnapshot(
snapshotId,
rewardEthToken.updatedAtTimestamp,
updatesCount,
pool.totalStaked,
event.params.periodRewards,
BIG_INT_ZERO,
event.block
);

rewardEthToken.updatesCount = updatesCount;
rewardEthToken.rewardPerStakedEthToken = event.params.rewardPerToken;
rewardEthToken.totalRewards = event.params.totalRewards;
rewardEthToken.updatedAtBlock = event.block.number;
Expand All @@ -85,20 +79,17 @@ export function handleRewardsUpdatedV1(event: RewardsUpdatedV1): void {
export function handleRewardsUpdatedV2(event: RewardsUpdatedV2): void {
let rewardEthToken = createOrLoadRewardEthToken();
let pool = createOrLoadPool();
let snapshotId = event.transaction.hash
.toHexString()
.concat("-")
.concat(event.logIndex.toString());

let newUpdatesCount = rewardEthToken.updatesCount.plus(BIG_INT_ONE);
createStakingRewardsSnapshot(
snapshotId,
rewardEthToken.updatedAtTimestamp,
rewardEthToken.updatesCount,
pool.totalStaked,
event.params.periodRewards,
event.params.protocolReward,
event.block
);

rewardEthToken.updatesCount = newUpdatesCount;
rewardEthToken.rewardPerStakedEthToken = event.params.rewardPerToken;
rewardEthToken.protocolPeriodReward =
rewardEthToken.protocolPeriodReward.plus(event.params.protocolReward);
Expand Down
9 changes: 6 additions & 3 deletions subgraphs/uniswap-v3/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
{
"name": "uniswap-v3",
"version": "1.1.0",
"version": "1.1.1",
"license": "AGPL-3.0-only",
"scripts": {
"prepare:goerli": "mustache config/goerli.json subgraph.template.yaml > subgraph.yaml",
"prepare:perm_goerli": "true",
"prepare:gnosis": "true",
"prepare:mainnet": "mustache config/mainnet.json subgraph.template.yaml > subgraph.yaml",
"build:goerli": "yarn prepare:goerli && graph codegen subgraph.yaml && graph build subgraph.yaml",
"build:perm_goerli": "yarn prepare:perm_goerli",
"build:gnosis": "yarn prepare:gnosis",
"build:mainnet": "yarn prepare:mainnet && graph codegen subgraph.yaml && graph build subgraph.yaml",
"create:local": "graph create --node $GRAPH_NODE_URL stakewise/uniswap-v3",
"deploy:goerli": "yarn build:goerli && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ stakewise/uniswap-v3-goerli",
"deploy:perm_goerli": "yarn build:perm_goerli",
"deploy:gnosis": "yarn build:gnosis",
"deploy:mainnet": "yarn build:mainnet && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ stakewise/uniswap-v3-mainnet",
"deploy:local": "graph deploy --version-label 1.1.0 --node $GRAPH_NODE_URL --ipfs $IPFS_URL stakewise/uniswap-v3"
"deploy:local": "graph deploy --version-label 1.1.1 --node $GRAPH_NODE_URL --ipfs $IPFS_URL stakewise/uniswap-v3",
"create:local": "graph create --node $GRAPH_NODE_URL stakewise/uniswap-v3"
}
}
Loading

0 comments on commit 4d85468

Please sign in to comment.