Skip to content

Commit

Permalink
added delegatedUSD 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 26a133c commit 50fd0c7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions DaoPools/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ type VoterInPoolPair @entity {
delegatee: VoterInPool!

delegatedAmount: BigInt!
delegatedUSD: BigInt!
delegatedNfts: [BigInt!]!

history: [DelegationHistory!]! @derivedFrom(field: "pair")
Expand Down
1 change: 1 addition & 0 deletions DaoPools/src/entities/Voters/VoterInPoolPair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function getVoterInPoolPair(from: VoterInPool, to: VoterInPool): VoterInP
pair.delegatee = to.id;

pair.delegatedAmount = BigInt.zero();
pair.delegatedUSD = BigInt.zero();
pair.delegatedNfts = new Array<BigInt>();
}

Expand Down
6 changes: 6 additions & 0 deletions DaoPools/src/mappings/DaoPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export function onDelegated(event: Delegated): void {

pair.delegatedAmount = pair.delegatedAmount.plus(event.params.amount);
pair.delegatedNfts = pushUnique<BigInt>(pair.delegatedNfts, event.params.nfts);
pair.delegatedUSD = pair.delegatedUSD.plus(usdAmount);

pool.totalCurrentTokenDelegated = pool.totalCurrentTokenDelegated.plus(event.params.amount);
pool.totalCurrentNFTDelegated = pushUnique<BigInt>(pool.totalCurrentNFTDelegated, event.params.nfts);
Expand All @@ -116,6 +117,11 @@ export function onDelegated(event: Delegated): void {

pair.delegatedAmount = pair.delegatedAmount.minus(event.params.amount);
pair.delegatedNfts = remove<BigInt>(pair.delegatedNfts, event.params.nfts);
if (usdAmount.gt(pair.delegatedUSD)) {
pair.delegatedUSD = BigInt.zero();
} else {
pair.delegatedUSD = pair.delegatedUSD.minus(usdAmount);
}

if (pair.delegatedAmount.equals(BigInt.zero()) && pair.delegatedNfts.length == 0) {
toVoterInPool.currentDelegatorsCount = toVoterInPool.currentDelegatorsCount.minus(BigInt.fromI32(1));
Expand Down
2 changes: 2 additions & 0 deletions DaoPools/tests/DaoPool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ describe("DaoPool", () => {
"delegatedAmount",
amount.toString()
);
assert.fieldEquals("VoterInPoolPair", contractSender.concat(from).concat(to).toHexString(), "delegatedUSD", "200");
assert.fieldEquals(
"VoterInPoolPair",
contractSender.concat(from).concat(to).toHexString(),
Expand Down Expand Up @@ -649,6 +650,7 @@ describe("DaoPool", () => {
"delegatedAmount",
amount1.minus(amount2).toString()
);
assert.fieldEquals("VoterInPoolPair", contractSender.concat(from).concat(to).toHexString(), "delegatedUSD", "100");
assert.fieldEquals(
"VoterInPoolPair",
contractSender.concat(from).concat(to).toHexString(),
Expand Down

0 comments on commit 50fd0c7

Please sign in to comment.