-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
272 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Sepolia | ||
export let leverageZappers = [ | ||
"0x709b1d298f202e0b0a72fd92769d7f81e9dc5911", | ||
"0x75e7f939aec5ca455e4e32cd4b6567b70323bd4a", | ||
"0x78b88fc6043810c4d3f0e6af84310620f91cf721", | ||
]; | ||
export let governanceDeploymentInitiatives = [ | ||
"0x510f6888fd475A7b81C3652696eb807374d65400", // UniV4Donations | ||
]; | ||
|
||
// Mainnet | ||
// export let leverageZappers = []; | ||
// export let governanceDeploymentInitiatives = []; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,30 @@ | ||
{ | ||
"local": { | ||
"BoldToken": { | ||
"address": "0x21a6370b245c05fade18c601f5efa23e1a3c9833" | ||
"address": "0x324331e016663950856622e1d1a062cfe4df3006" | ||
}, | ||
"Governance": { | ||
"address": "0x79fdb65c20e75f8961d54f6714d2fcc4c30d1073" | ||
} | ||
}, | ||
"mainnet": { | ||
"BoldToken": { | ||
"address": "0x0000000000000000000000000000000000000000", | ||
"startBlock": 0 | ||
}, | ||
"Governance": { | ||
"address": "0x0000000000000000000000000000000000000000", | ||
"startBlock": 0 | ||
} | ||
}, | ||
"sepolia": { | ||
"BoldToken": { | ||
"address": "0x21a6370b245c05fade18c601f5efa23e1a3c9833", | ||
"startBlock": 6684588 | ||
"address": "0x31764dcd10fff1514db117e3db84b48b30db5b43", | ||
"startBlock": 6889790 | ||
}, | ||
"Governance": { | ||
"address": "0x79fdb65c20e75f8961d54f6714d2fcc4c30d1073", | ||
"startBlock": 6959313 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts"; | ||
import { governanceDeploymentInitiatives } from "../addresses"; | ||
import { | ||
AllocateLQTY as AllocateLQTYEvent, | ||
ClaimForInitiative as ClaimForInitiativeEvent, | ||
DepositLQTY as DepositLQTYEvent, | ||
Governance as GovernanceContract, | ||
RegisterInitiative as RegisterInitiativeEvent, | ||
SnapshotVotesForInitiative as SnapshotVotesForInitiativeEvent, | ||
UnregisterInitiative as UnregisterInitiativeEvent, | ||
WithdrawLQTY as WithdrawLQTYEvent, | ||
} from "../generated/Governance/Governance"; | ||
import { GovernanceAllocation, GovernanceInitiative, GovernanceStats, GovernanceUser } from "../generated/schema"; | ||
|
||
function initialize(block: ethereum.Block): void { | ||
// Initial governance initiatives passed to the constructor (no event emitted) | ||
for (let i = 0; i < governanceDeploymentInitiatives.length; i++) { | ||
let initiative = new GovernanceInitiative(governanceDeploymentInitiatives[i]); | ||
initiative.registeredAt = block.timestamp; | ||
initiative.registeredAtEpoch = 1; | ||
initiative.registrant = Address.zero(); | ||
initiative.totalBoldClaimed = BigInt.fromI32(0); | ||
initiative.totalVetos = BigInt.fromI32(0); | ||
initiative.totalVotes = BigInt.fromI32(0); | ||
initiative.save(); | ||
} | ||
|
||
// Create initial stats | ||
let stats = new GovernanceStats("stats"); | ||
stats.totalLQTYStaked = BigInt.fromI32(0); | ||
stats.totalInitiatives = 0; | ||
stats.save(); | ||
} | ||
|
||
export function handleBlock(block: ethereum.Block): void { | ||
if (GovernanceStats.load("stats") === null) { | ||
initialize(block); | ||
} | ||
} | ||
|
||
export function handleRegisterInitiative(event: RegisterInitiativeEvent): void { | ||
let initiative = new GovernanceInitiative(event.params.initiative.toHex()); | ||
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(); | ||
} | ||
|
||
export function handleUnregisterInitiative(event: UnregisterInitiativeEvent): void { | ||
let initiative = GovernanceInitiative.load(event.params.initiative.toHex()); | ||
if (initiative) { | ||
initiative.unregisteredAt = event.block.timestamp; | ||
initiative.unregisteredAtEpoch = event.params.atEpoch; | ||
initiative.save(); | ||
} | ||
} | ||
|
||
export function handleSnapshotVotesForInitiative(event: SnapshotVotesForInitiativeEvent): void { | ||
let initiative = GovernanceInitiative.load(event.params.initiative.toHex()); | ||
if (initiative) { | ||
initiative.lastVoteSnapshotEpoch = event.params.forEpoch; | ||
initiative.lastVoteSnapshotVotes = event.params.votes; | ||
initiative.save(); | ||
} | ||
} | ||
|
||
export function handleDepositLQTY(event: DepositLQTYEvent): void { | ||
let user = GovernanceUser.load(event.params.user.toHex()); | ||
if (user === null) { | ||
user = new GovernanceUser(event.params.user.toHex()); | ||
} | ||
|
||
let governance = GovernanceContract.bind(event.address); | ||
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.save(); | ||
} | ||
|
||
export function handleWithdrawLQTY(event: WithdrawLQTYEvent): void { | ||
let user = GovernanceUser.load(event.params.user.toHex()); | ||
if (user === null) { | ||
return; | ||
} | ||
|
||
let governance = GovernanceContract.bind(event.address); | ||
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.save(); | ||
} | ||
|
||
export function handleAllocateLQTY(event: AllocateLQTYEvent): void { | ||
let userId = event.params.user.toHex(); | ||
let initiativeId = event.params.initiative.toHex(); | ||
let allocationId = initiativeId + ":" + userId; | ||
|
||
let user = GovernanceUser.load(userId); | ||
let initiative = GovernanceInitiative.load(initiativeId); | ||
|
||
if (!user || !initiative) { | ||
return; | ||
} | ||
|
||
let allocation = GovernanceAllocation.load(allocationId); | ||
if (allocation === null) { | ||
allocation = new GovernanceAllocation(allocationId); | ||
allocation.user = user.id; | ||
allocation.initiative = initiative.id; | ||
allocation.voteLQTY = BigInt.fromI32(0); | ||
allocation.vetoLQTY = BigInt.fromI32(0); | ||
} | ||
|
||
// 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; | ||
|
||
allocation.save(); | ||
user.save(); | ||
initiative.save(); | ||
} | ||
|
||
function getStats(): GovernanceStats { | ||
let stats = GovernanceStats.load("stats"); | ||
if (stats === null) { | ||
throw new Error("Stats entity not found"); | ||
} | ||
return stats; | ||
} | ||
|
||
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.save(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters