Skip to content

Commit

Permalink
added creationTimestamp field to VoterInPoolPair entity
Browse files Browse the repository at this point in the history
  • Loading branch information
kevandee committed Sep 8, 2023
1 parent 50fd0c7 commit bd42f6d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions DaoPools/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ type TreasuryDelegationHistory @entity(immutable: true) {
# @param delegateNfts the current delegated nfts
type VoterInPoolPair @entity {
id: Bytes! # pool address + from address + to address
creationTimestamp: BigInt!

delegator: VoterInPool!
delegatee: VoterInPool!

Expand Down
4 changes: 3 additions & 1 deletion DaoPools/src/entities/Voters/VoterInPoolPair.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { BigInt } from "@graphprotocol/graph-ts";
import { VoterInPool, VoterInPoolPair } from "../../../generated/schema";

export function getVoterInPoolPair(from: VoterInPool, to: VoterInPool): VoterInPoolPair {
export function getVoterInPoolPair(from: VoterInPool, to: VoterInPool, timestamp: BigInt): VoterInPoolPair {
let id = from.pool.concat(from.voter).concat(to.voter);
let pair = VoterInPoolPair.load(id);

if (pair == null) {
pair = new VoterInPoolPair(id);

pair.creationTimestamp = timestamp;

pair.delegator = from.id;
pair.delegatee = to.id;

Expand Down
2 changes: 1 addition & 1 deletion DaoPools/src/mappings/DaoPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function onDelegated(event: Delegated): void {
let toVoterInPool = getVoterInPool(pool, to, event.block.timestamp);
let fromVoterInPool = getVoterInPool(pool, from, event.block.timestamp);

let pair = getVoterInPoolPair(fromVoterInPool, toVoterInPool);
let pair = getVoterInPoolPair(fromVoterInPool, toVoterInPool, event.block.timestamp);

const usdAmount = getUSDValue(pool.erc20Token, event.params.amount);

Expand Down
12 changes: 12 additions & 0 deletions DaoPools/tests/DaoPool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,12 @@ describe("DaoPool", () => {
DelegationType.DELEGATE.toString()
);

assert.fieldEquals(
"VoterInPoolPair",
contractSender.concat(from).concat(to).toHexString(),
"creationTimestamp",
block.timestamp.toString()
);
assert.fieldEquals(
"VoterInPoolPair",
contractSender.concat(from).concat(to).toHexString(),
Expand Down Expand Up @@ -632,6 +638,12 @@ describe("DaoPool", () => {
DelegationType.UNDELEGATE.toString()
);

assert.fieldEquals(
"VoterInPoolPair",
contractSender.concat(from).concat(to).toHexString(),
"creationTimestamp",
block.timestamp.toString()
);
assert.fieldEquals(
"VoterInPoolPair",
contractSender.concat(from).concat(to).toHexString(),
Expand Down

0 comments on commit bd42f6d

Please sign in to comment.