Skip to content

Commit

Permalink
Subgraph: udpate Governance (#661)
Browse files Browse the repository at this point in the history
- Update ABI
- Remove unused properties from the schema
- AssemblyScript fixes
  • Loading branch information
bpierre authored Dec 19, 2024
1 parent c5f2089 commit 713d043
Show file tree
Hide file tree
Showing 5 changed files with 748 additions and 40 deletions.
723 changes: 722 additions & 1 deletion subgraph/abi/Governance.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions subgraph/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
},
"sepolia": {
"BoldToken": {
"address": "0x620ce1130f7c63457784cdfa31cfccbfb6be5029",
"startBlock": 7129282
"address": "0x6ecf96d1f30cd98c0b58d6b12ea8ae014c52464d",
"startBlock": 7279144
},
"Governance": {
"address": "0x16fda5823f296c24125be4976fd6cec9fab9da2e",
"startBlock": 7129475
"address": "0xd7eae81178b97e49e6471f398f0486a7c2e43721",
"startBlock": 7279317
}
}
}
14 changes: 5 additions & 9 deletions subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ type InterestBatch @entity {
type GovernanceUser @entity {
id: ID! # "userAddress", e.g. "0x0000000000000000000000000000000000000000"
allocatedLQTY: BigInt!
averageStakingTimestamp: BigInt!
allocations: [GovernanceAllocation!]! @derivedFrom(field: "user")
}

Expand All @@ -129,22 +128,19 @@ type GovernanceAllocation @entity {
initiative: GovernanceInitiative!
voteLQTY: BigInt!
vetoLQTY: BigInt!
atEpoch: Int!
atEpoch: BigInt!
}

type GovernanceInitiative @entity {
id: ID! # "initiativeAddress", e.g. "0x0000000000000000000000000000000000000000"
lastClaimEpoch: Int
lastVoteSnapshotEpoch: Int
lastClaimEpoch: BigInt
lastVoteSnapshotEpoch: BigInt
lastVoteSnapshotVotes: BigInt
registeredAt: BigInt!
registeredAtEpoch: Int!
registeredAtEpoch: BigInt!
registrant: Bytes!
totalBoldClaimed: BigInt!
totalVetos: BigInt!
totalVotes: BigInt!
unregisteredAt: BigInt
unregisteredAtEpoch: Int
unregisteredAtEpoch: BigInt
}

type GovernanceStats @entity {
Expand Down
19 changes: 4 additions & 15 deletions subgraph/src/Governance.mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ function initialize(block: ethereum.Block): void {
for (let i = 0; i < governanceDeploymentInitiatives.length; i++) {
let initiative = new GovernanceInitiative(governanceDeploymentInitiatives[i]);
initiative.registeredAt = block.timestamp;
initiative.registeredAtEpoch = 1;
initiative.registeredAtEpoch = BigInt.fromI32(1);
initiative.registrant = Address.zero();
initiative.totalBoldClaimed = BigInt.fromI32(0);
initiative.totalVetos = BigInt.fromI32(0);
initiative.totalVotes = BigInt.fromI32(0);
initiative.save();
}

Expand All @@ -43,9 +40,6 @@ export function handleRegisterInitiative(event: RegisterInitiativeEvent): void {
initiative.registeredAt = event.block.timestamp;
initiative.registeredAtEpoch = event.params.atEpoch;
initiative.registrant = event.params.registrant;
initiative.totalBoldClaimed = BigInt.fromI32(0);
initiative.totalVetos = BigInt.fromI32(0);
initiative.totalVotes = BigInt.fromI32(0);
initiative.save();
}

Expand Down Expand Up @@ -77,11 +71,10 @@ export function handleDepositLQTY(event: DepositLQTYEvent): void {
let userState = governance.userStates(event.params.user);

user.allocatedLQTY = userState.getAllocatedLQTY();
user.averageStakingTimestamp = userState.getAverageStakingTimestamp();
user.save();

let stats = getStats();
stats.totalLQTYStaked = stats.totalLQTYStaked.plus(event.params.depositedLQTY);
stats.totalLQTYStaked = stats.totalLQTYStaked.plus(event.params.lqtyAmount);
stats.save();
}

Expand All @@ -95,11 +88,10 @@ export function handleWithdrawLQTY(event: WithdrawLQTYEvent): void {
let userState = governance.userStates(event.params.user);

user.allocatedLQTY = userState.getAllocatedLQTY();
user.averageStakingTimestamp = userState.getAverageStakingTimestamp();
user.save();

let stats = getStats();
stats.totalLQTYStaked = stats.totalLQTYStaked.minus(event.params.withdrawnLQTY);
stats.totalLQTYStaked = stats.totalLQTYStaked.minus(event.params.lqtySent);
stats.save();
}

Expand Down Expand Up @@ -127,12 +119,10 @@ export function handleAllocateLQTY(event: AllocateLQTYEvent): void {
// votes
allocation.voteLQTY = allocation.voteLQTY.plus(event.params.deltaVoteLQTY);
user.allocatedLQTY = user.allocatedLQTY.plus(event.params.deltaVoteLQTY);
initiative.totalVotes = initiative.totalVotes.plus(event.params.deltaVoteLQTY);

// vetos
allocation.vetoLQTY = allocation.vetoLQTY.plus(event.params.deltaVetoLQTY);
user.allocatedLQTY = user.allocatedLQTY.plus(event.params.deltaVetoLQTY);
initiative.totalVetos = initiative.totalVetos.plus(event.params.deltaVetoLQTY);

allocation.atEpoch = event.params.atEpoch;

Expand All @@ -152,8 +142,7 @@ function getStats(): GovernanceStats {
export function handleClaimForInitiative(event: ClaimForInitiativeEvent): void {
let initiative = GovernanceInitiative.load(event.params.initiative.toHex());
if (initiative) {
initiative.totalBoldClaimed = initiative.totalBoldClaimed.plus(event.params.bold);
initiative.lastClaimEpoch = event.params.forEpoch.toI32();
initiative.lastClaimEpoch = event.params.forEpoch;
initiative.save();
}
}
24 changes: 13 additions & 11 deletions subgraph/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ dataSources:
name: BoldToken
source:
abi: BoldToken
address: "0x620ce1130f7c63457784cdfa31cfccbfb6be5029"
startBlock: 7129282
address: "0x6ecf96d1f30cd98c0b58d6b12ea8ae014c52464d"
startBlock: 7279144
mapping:
kind: ethereum/events
apiVersion: 0.0.9
Expand Down Expand Up @@ -36,8 +36,8 @@ dataSources:
name: Governance
source:
abi: Governance
address: "0x16fda5823f296c24125be4976fd6cec9fab9da2e"
startBlock: 7129475
address: "0xd7eae81178b97e49e6471f398f0486a7c2e43721"
startBlock: 7279317
mapping:
kind: ethereum/events
apiVersion: 0.0.9
Expand All @@ -51,19 +51,21 @@ dataSources:
- name: Governance
file: ./abi/Governance.json
eventHandlers:
- event: AllocateLQTY(address,address,int256,int256,uint16)
- event: AllocateLQTY(indexed address,indexed address,int256,int256,uint256,bool)
handler: handleAllocateLQTY
- event: ClaimForInitiative(address,uint256,uint256)
- event: ClaimForInitiative(indexed address,uint256,uint256,bool)
handler: handleClaimForInitiative
- event: DepositLQTY(address,uint256)
- event: DepositLQTY(indexed
address,address,uint256,uint256,uint256,uint256,uint256)
handler: handleDepositLQTY
- event: RegisterInitiative(address,address,uint16)
- event: RegisterInitiative(address,address,uint256,bool)
handler: handleRegisterInitiative
- event: SnapshotVotesForInitiative(address,uint240,uint16)
- event: SnapshotVotesForInitiative(indexed address,uint256,uint256,uint256)
handler: handleSnapshotVotesForInitiative
- event: UnregisterInitiative(address,uint16)
- event: UnregisterInitiative(address,uint256,bool)
handler: handleUnregisterInitiative
- event: WithdrawLQTY(address,uint256,uint256,uint256)
- event: WithdrawLQTY(indexed
address,address,uint256,uint256,uint256,uint256,uint256,uint256)
handler: handleWithdrawLQTY
blockHandlers:
- handler: handleBlock
Expand Down

0 comments on commit 713d043

Please sign in to comment.