Skip to content

Commit

Permalink
added QuorumUnreached event
Browse files Browse the repository at this point in the history
  • Loading branch information
kevandee committed Sep 15, 2023
1 parent 6d6a74b commit 4ca28e7
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
13 changes: 13 additions & 0 deletions DaoPools/abis/DaoPool.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@
"name": "QuorumReached",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "proposalId",
"type": "uint256"
}
],
"name": "QuorumUnreached",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down
11 changes: 11 additions & 0 deletions DaoPools/src/mappings/DaoPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ProposalCreated,
ProposalExecuted,
QuorumReached,
QuorumUnreached,
RewardClaimed,
VoteChanged,
VotingRewardClaimed,
Expand Down Expand Up @@ -489,6 +490,16 @@ export function onQuorumReached(event: QuorumReached): void {
pool.save();
}

export function onQuorumUnreached(event: QuorumUnreached): void {
let pool = getDaoPool(event.address);
let proposal = getProposal(pool, event.params.proposalId);

proposal.quorumReachedTimestamp = BigInt.zero();

proposal.save();
pool.save();
}

function recalculateAPR(voterInPool: VoterInPool, rewardCredited: BigInt, currentTimestamp: BigInt): void {
if (voterInPool.totalLockedUSD.notEqual(BigInt.zero()) && currentTimestamp.notEqual(voterInPool.joinedTimestamp)) {
let RLRatio = rewardCredited.times(BigInt.fromI32(PERCENTAGE_NUMERATOR)).div(voterInPool.totalLockedUSD);
Expand Down
2 changes: 2 additions & 0 deletions DaoPools/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ templates:
handler: onProposalExecuted
- event: QuorumReached(uint256,uint256)
handler: onQuorumReached
- event: QuorumUnreached(uint256)
handler: onQuorumUnreached
- event: RewardClaimed(uint256,address,address,uint256) # id, msg.sender, token, amount
handler: onRewardClaimed
- event: VotingRewardClaimed(uint256,address,address,(uint256,uint256,uint256))
Expand Down
58 changes: 58 additions & 0 deletions DaoPools/tests/DaoPool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
DelegatorRewardsClaimed,
QuorumReached,
VotingRewardClaimed,
QuorumUnreached,
} from "../generated/templates/DaoPool/DaoPool";
import {
onDelegated,
Expand All @@ -37,6 +38,7 @@ import {
onDelegatorRewardsClaimed,
onQuorumReached,
onVotingRewardClaimed,
onQuorumUnreached,
} from "../src/mappings/DaoPool";
import { PRICE_FEED_ADDRESS } from "../src/entities/global/globals";
import { ProposalSettings } from "../generated/schema";
Expand Down Expand Up @@ -250,6 +252,24 @@ function createQuorumReached(
return event;
}

function createQuorumUnreached(
proposalId: BigInt,
contractSender: Address,
block: ethereum.Block,
tx: ethereum.Transaction
): QuorumUnreached {
let event = changetype<QuorumUnreached>(newMockEvent());
event.parameters = new Array();

event.parameters.push(new ethereum.EventParam("proposalId", ethereum.Value.fromUnsignedBigInt(proposalId)));

event.block = block;
event.transaction = tx;
event.address = contractSender;

return event;
}

function createDeposited(
amount: BigInt,
nfts: Array<BigInt>,
Expand Down Expand Up @@ -1125,6 +1145,44 @@ describe("DaoPool", () => {
);
});

test("should handle QuorumUnreached", () => {
let proposalId = BigInt.fromI32(1);

let reachedEvent = createQuorumReached(proposalId, block.timestamp, contractSender, block, tx);

onQuorumReached(reachedEvent);

assert.fieldEquals(
"Proposal",
contractSender.concatI32(proposalId.toI32()).toHexString(),
"id",
contractSender.concatI32(proposalId.toI32()).toHexString()
);
assert.fieldEquals(
"Proposal",
contractSender.concatI32(proposalId.toI32()).toHexString(),
"quorumReachedTimestamp",
block.timestamp.toString()
);

let unreachedEvent = createQuorumUnreached(proposalId, contractSender, block, tx);

onQuorumUnreached(unreachedEvent);

assert.fieldEquals(
"Proposal",
contractSender.concatI32(proposalId.toI32()).toHexString(),
"id",
contractSender.concatI32(proposalId.toI32()).toHexString()
);
assert.fieldEquals(
"Proposal",
contractSender.concatI32(proposalId.toI32()).toHexString(),
"quorumReachedTimestamp",
"0"
);
});

test("should handle ProposalExecuted", () => {
let proposalId = BigInt.fromI32(1);
let isFor = true;
Expand Down

0 comments on commit 4ca28e7

Please sign in to comment.