Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/subgraph staking #178

Merged
merged 27 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1e44e0f
update KVStore contract
leric7 Jan 15, 2023
ccd7964
update husky pre commit
leric7 Jan 15, 2023
cf5d52b
add subgraph for staking/slashing
leric7 Jan 16, 2023
34a9d0a
Merge branch 'feat/staking-slashing' into feat/subgraph-staking
leric7 Jan 16, 2023
8ae67e9
update subgraph
leric7 Jan 16, 2023
bfe467f
update dependency
leric7 Jan 16, 2023
ce78774
fix leader initialization in subgraph
leric7 Jan 16, 2023
0d92e3d
fix kvstore test
leric7 Jan 16, 2023
da9c270
fix kvstore test
leric7 Jan 16, 2023
c1aa5aa
add staking subgraph test
leric7 Jan 16, 2023
fd2a670
update staking subgraph and test
leric7 Jan 16, 2023
9179c6c
update staking subgraph and test
leric7 Jan 16, 2023
a4f62b2
fix subgraph template
leric7 Jan 16, 2023
d7570fb
fix subgraph test
leric7 Jan 16, 2023
e742d46
fix matchstick config
leric7 Jan 16, 2023
70aad77
fix subgraph dependency
leric7 Jan 16, 2023
e077da0
fix subgraph test
leric7 Jan 16, 2023
07e18d4
update subgraph schema
leric7 Jan 16, 2023
4b286d6
Merge branch 'feat/staking-slashing' into feat/subgraph-staking
leric7 Jan 16, 2023
6854aee
fix subgraph test
leric7 Jan 16, 2023
1dcd827
fix staking subgraph;
leric7 Jan 16, 2023
8e68013
fix subgraph test
leric7 Jan 16, 2023
7038d5d
update staking subgraph test
leric7 Jan 16, 2023
78ccea4
Merge branch 'feat/staking-slashing' into feat/subgraph-staking
leric7 Jan 17, 2023
1ea783d
update contract addresses for subgraph
leric7 Jan 17, 2023
2e3e82a
use goerli for subgraph test
leric7 Jan 17, 2023
b61e606
Merge branch 'feat/staking-slashing' into feat/subgraph-staking
leric7 Jan 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/sdk/typescript/subgraph/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ generated/
subgraph.yaml

# Graph test generated
test/.bin
test/.latest.json
tests/.bin
tests/.latest.json
10 changes: 10 additions & 0 deletions packages/sdk/typescript/subgraph/config/goerli.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,15 @@
},
"Escrow": {
"abi": "./node_modules/@human-protocol/core/abis/Escrow.json"
},
"Staking": {
"address": "0x115df71Eb07F44Ab0019E98B1383768B8742dB18",
"startBlock": 8326533,
"abi": "./node_modules/@human-protocol/core/abis/Staking.json"
},
"KVStore": {
"address": "0x4e0cF75c0840c8E9664b257c32BFB760b5ed6ef5",
"startBlock": 8326276,
"abi": "./node_modules/@human-protocol/core/abis/KVStore.json"
}
}
10 changes: 10 additions & 0 deletions packages/sdk/typescript/subgraph/config/mumbai.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,15 @@
},
"Escrow": {
"abi": "./node_modules/@human-protocol/core/abis/Escrow.json"
},
"Staking": {
"address": "0xf421fD3eB97982C205966ebB514Ab2E435c6d5B7",
"startBlock": 31060831,
"abi": "./node_modules/@human-protocol/core/abis/Staking.json"
},
"KVStore": {
"address": "0x459EE403d060B84b5014605D6739cCFed32AFb96",
"startBlock": 31059244,
"abi": "./node_modules/@human-protocol/core/abis/KVStore.json"
}
}
1 change: 0 additions & 1 deletion packages/sdk/typescript/subgraph/matchstick.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
libsFolder: ../../../../node_modules
testsFolder: ./test
6 changes: 3 additions & 3 deletions packages/sdk/typescript/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"generate": "mustache ./config/$NETWORK.json template.yaml > subgraph.yaml && graph codegen",
"codegen": "graph codegen",
"build": "graph build",
"pretest": "NETWORK=matic yarn generate",
"pretest": "NETWORK=goerli yarn generate",
"test": "graph test",
"deploy": "graph deploy --node https://api.thegraph.com/deploy/ posix4e/humansubgraph",
"quickstart:matic": "NETWORK=matic yarn generate && graph create --node http://localhost:8020/ posix4e/humansubgraph",
Expand All @@ -35,8 +35,8 @@
],
"license": "MIT",
"devDependencies": {
"@graphprotocol/graph-cli": "^0.37.1",
"@graphprotocol/graph-ts": "^0.29.0",
"@graphprotocol/graph-cli": "0.37.1",
"@graphprotocol/graph-ts": "^0.27.0",
"@graphql-eslint/eslint-plugin": "^3.13.0",
"@human-protocol/core": "workspace:*",
"assemblyscript": "^0.25.1",
Expand Down
88 changes: 88 additions & 0 deletions packages/sdk/typescript/subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,91 @@ type EventDayData @entity {
dailyPendingEvents: BigInt!
dailyEscrowAmounts: BigInt!
}

type LeaderStatistics @entity {
id: ID!
leaders: BigInt!
}

type Leader @entity {
id: ID!
address: Bytes!
role: String!
amountStaked: BigInt!
amountAllocated: BigInt!
amountLocked: BigInt!
lockedUntilTimestamp: BigInt!
amountWithdrawn: BigInt!
amountSlashed: BigInt!
reputation: BigInt!
amountJobsLaunched: BigInt!
}

type DataSavedEvent @entity {
id: ID!
leader: Bytes! # address
key: String!
value: String!
block: BigInt!
timestamp: BigInt!
transaction: Bytes!
}

type StakeDepositedEvent @entity {
id: ID!
staker: Bytes! # address
amount: BigInt!
block: BigInt!
timestamp: BigInt!
transaction: Bytes!
}

type StakeLockedEvent @entity {
id: ID!
staker: Bytes! # address
amount: BigInt!
lockedUntilTimestamp: BigInt!
block: BigInt!
timestamp: BigInt!
transaction: Bytes!
}

type StakeWithdrawnEvent @entity {
id: ID!
staker: Bytes! # address
amount: BigInt!
block: BigInt!
timestamp: BigInt!
transaction: Bytes!
}

type StakeSlashedEvent @entity {
id: ID!
staker: Bytes! # address
amount: BigInt!
escrow: Bytes! # address
slasher: Bytes! # address
block: BigInt!
timestamp: BigInt!
transaction: Bytes!
}

type StakeAllocatedEvent @entity {
id: ID!
staker: Bytes! # address
amount: BigInt!
escrow: Bytes! # address
block: BigInt!
timestamp: BigInt!
transaction: Bytes!
}

type AllocationClosedEvent @entity {
id: ID!
staker: Bytes! # address
amount: BigInt!
escrow: Bytes! # address
block: BigInt!
timestamp: BigInt!
transaction: Bytes!
}
30 changes: 30 additions & 0 deletions packages/sdk/typescript/subgraph/src/mapping/KVStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { DataSavedEvent } from '../../generated/schema';
import { DataSaved } from '../../generated/KVStore/KVStore';
import { createOrLoadLeader } from './Staking';

export function handleDataSaved(event: DataSaved): void {
const id = `${event.transaction.hash.toHex()}-${event.logIndex.toString()}-${
event.block.timestamp
}`;

const entity = new DataSavedEvent(id);

entity.leader = event.params.sender;
entity.key = event.params.key;
entity.value = event.params.value;

entity.block = event.block.number;
entity.timestamp = event.block.timestamp;
entity.transaction = event.transaction.hash;

entity.save();

// Update leader role, if necessary
if (entity.key === 'role') {
const leaderId = event.params.sender.toHex();
const leader = createOrLoadLeader(leaderId, event.params.sender);

leader.role = entity.value;
leader.save();
}
}
Loading