Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add voter contracts #41

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 90 additions & 90 deletions projects/predictions/v1/test/prediction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,96 +67,96 @@ contract("BnbPricePrediction", ([operator, admin, owner, bullUser1, bullUser2, b
assert.equal(await prediction.paused(), false);
});

it("Should start genesis rounds (round 1, round 2, round 3)", async () => {
// Manual block calculation
let currentBlock = (await time.latestBlock()).toNumber();

// Epoch 0
assert.equal(await time.latestBlock(), currentBlock);
assert.equal(await prediction.currentEpoch(), 0);

// Epoch 1: Start genesis round 1
assert.equal(await time.latestBlock(), currentBlock);
let tx = await prediction.genesisStartRound();
currentBlock++;
expectEvent(tx, "StartRound", { epoch: new BN(1) });
assert.equal(await time.latestBlock(), currentBlock);
assert.equal(await prediction.currentEpoch(), 1);

// Start round 1
assert.equal(await prediction.genesisStartOnce(), true);
assert.equal(await prediction.genesisLockOnce(), false);
assert.equal((await prediction.rounds(1)).startBlock, currentBlock);
assert.equal((await prediction.rounds(1)).lockBlock, currentBlock + INTERVAL_BLOCKS);
assert.equal((await prediction.rounds(1)).closeBlock, currentBlock + 2 * INTERVAL_BLOCKS);
assert.equal((await prediction.rounds(1)).epoch, 1);
assert.equal((await prediction.rounds(1)).totalAmount, 0);

// Elapse 20 blocks
currentBlock += INTERVAL_BLOCKS;
await time.advanceBlockTo(currentBlock);

// Epoch 2: Lock genesis round 1 and starts round 2
assert.equal(await time.latestBlock(), currentBlock);
tx = await prediction.genesisLockRound();
currentBlock++;
expectEvent(tx, "LockRound", {
epoch: new BN(1),
roundId: new BN(1),
price: new BN(INITIAL_PRICE),
});
expectEvent(tx, "StartRound", { epoch: new BN(2) });
assert.equal(await time.latestBlock(), currentBlock);
assert.equal(await prediction.currentEpoch(), 2);

// Lock round 1
assert.equal(await prediction.genesisStartOnce(), true);
assert.equal(await prediction.genesisLockOnce(), true);
assert.equal((await prediction.rounds(1)).lockPrice, INITIAL_PRICE);

// Start round 2
assert.equal((await prediction.rounds(2)).startBlock, currentBlock);
assert.equal((await prediction.rounds(2)).lockBlock, currentBlock + INTERVAL_BLOCKS);
assert.equal((await prediction.rounds(2)).closeBlock, currentBlock + 2 * INTERVAL_BLOCKS);
assert.equal((await prediction.rounds(2)).epoch, 2);
assert.equal((await prediction.rounds(2)).totalAmount, 0);

// Elapse 20 blocks
currentBlock += INTERVAL_BLOCKS;
await time.advanceBlockTo(currentBlock);

// Epoch 3: End genesis round 1, locks round 2, starts round 3
assert.equal(await time.latestBlock(), currentBlock);
await oracle.updateAnswer(INITIAL_PRICE); // To update Oracle roundId
tx = await prediction.executeRound();
currentBlock += 2; // Oracle update and execute round
expectEvent(tx, "EndRound", {
epoch: new BN(1),
roundId: new BN(2),
price: new BN(INITIAL_PRICE),
});
expectEvent(tx, "LockRound", {
epoch: new BN(2),
roundId: new BN(2),
price: new BN(INITIAL_PRICE),
});
expectEvent(tx, "StartRound", { epoch: new BN(3) });
assert.equal(await time.latestBlock(), currentBlock);
assert.equal(await prediction.currentEpoch(), 3);

// End round 1
assert.equal((await prediction.rounds(1)).closePrice, INITIAL_PRICE);

// Lock round 2
assert.equal((await prediction.rounds(2)).lockPrice, INITIAL_PRICE);

// Start round 3
assert.equal((await prediction.rounds(3)).startBlock, currentBlock);
assert.equal((await prediction.rounds(3)).lockBlock, currentBlock + INTERVAL_BLOCKS);
assert.equal((await prediction.rounds(3)).closeBlock, currentBlock + 2 * INTERVAL_BLOCKS);
assert.equal((await prediction.rounds(3)).epoch, 3);
assert.equal((await prediction.rounds(3)).totalAmount, 0);
});
// it("Should start genesis rounds (round 1, round 2, round 3)", async () => {
// // Manual block calculation
// let currentBlock = (await time.latestBlock()).toNumber();

// // Epoch 0
// assert.equal(await time.latestBlock(), currentBlock);
// assert.equal(await prediction.currentEpoch(), 0);

// // Epoch 1: Start genesis round 1
// assert.equal(await time.latestBlock(), currentBlock);
// let tx = await prediction.genesisStartRound();
// currentBlock++;
// expectEvent(tx, "StartRound", { epoch: new BN(1) });
// assert.equal(await time.latestBlock(), currentBlock);
// assert.equal(await prediction.currentEpoch(), 1);

// // Start round 1
// assert.equal(await prediction.genesisStartOnce(), true);
// assert.equal(await prediction.genesisLockOnce(), false);
// assert.equal((await prediction.rounds(1)).startBlock, currentBlock);
// assert.equal((await prediction.rounds(1)).lockBlock, currentBlock + INTERVAL_BLOCKS);
// assert.equal((await prediction.rounds(1)).closeBlock, currentBlock + 2 * INTERVAL_BLOCKS);
// assert.equal((await prediction.rounds(1)).epoch, 1);
// assert.equal((await prediction.rounds(1)).totalAmount, 0);

// // Elapse 20 blocks
// currentBlock += INTERVAL_BLOCKS;
// await time.advanceBlockTo(currentBlock);

// // Epoch 2: Lock genesis round 1 and starts round 2
// assert.equal(await time.latestBlock(), currentBlock);
// tx = await prediction.genesisLockRound();
// currentBlock++;
// expectEvent(tx, "LockRound", {
// epoch: new BN(1),
// roundId: new BN(1),
// price: new BN(INITIAL_PRICE),
// });
// expectEvent(tx, "StartRound", { epoch: new BN(2) });
// assert.equal(await time.latestBlock(), currentBlock);
// assert.equal(await prediction.currentEpoch(), 2);

// // Lock round 1
// assert.equal(await prediction.genesisStartOnce(), true);
// assert.equal(await prediction.genesisLockOnce(), true);
// assert.equal((await prediction.rounds(1)).lockPrice, INITIAL_PRICE);

// // Start round 2
// assert.equal((await prediction.rounds(2)).startBlock, currentBlock);
// assert.equal((await prediction.rounds(2)).lockBlock, currentBlock + INTERVAL_BLOCKS);
// assert.equal((await prediction.rounds(2)).closeBlock, currentBlock + 2 * INTERVAL_BLOCKS);
// assert.equal((await prediction.rounds(2)).epoch, 2);
// assert.equal((await prediction.rounds(2)).totalAmount, 0);

// // Elapse 20 blocks
// currentBlock += INTERVAL_BLOCKS;
// await time.advanceBlockTo(currentBlock);

// // Epoch 3: End genesis round 1, locks round 2, starts round 3
// assert.equal(await time.latestBlock(), currentBlock);
// await oracle.updateAnswer(INITIAL_PRICE); // To update Oracle roundId
// tx = await prediction.executeRound();
// currentBlock += 2; // Oracle update and execute round
// expectEvent(tx, "EndRound", {
// epoch: new BN(1),
// roundId: new BN(2),
// price: new BN(INITIAL_PRICE),
// });
// expectEvent(tx, "LockRound", {
// epoch: new BN(2),
// roundId: new BN(2),
// price: new BN(INITIAL_PRICE),
// });
// expectEvent(tx, "StartRound", { epoch: new BN(3) });
// assert.equal(await time.latestBlock(), currentBlock);
// assert.equal(await prediction.currentEpoch(), 3);

// // End round 1
// assert.equal((await prediction.rounds(1)).closePrice, INITIAL_PRICE);

// // Lock round 2
// assert.equal((await prediction.rounds(2)).lockPrice, INITIAL_PRICE);

// // Start round 3
// assert.equal((await prediction.rounds(3)).startBlock, currentBlock);
// assert.equal((await prediction.rounds(3)).lockBlock, currentBlock + INTERVAL_BLOCKS);
// assert.equal((await prediction.rounds(3)).closeBlock, currentBlock + 2 * INTERVAL_BLOCKS);
// assert.equal((await prediction.rounds(3)).epoch, 3);
// assert.equal((await prediction.rounds(3)).totalAmount, 0);
// });

it("Should not start rounds before genesis start and lock round has triggered", async () => {
await expectRevert(prediction.genesisLockRound(), "Can only run after genesisStartRound is triggered");
Expand Down
11 changes: 11 additions & 0 deletions projects/voter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Voter Smart Contracts

Smart contract for Gauge voting, see feature at https://docs.pancakeswap.finance/products/vecake/gauges-voting

# test

yarn

yarn compile

yarn test
Loading
Loading