Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
victorges committed Sep 18, 2023
1 parent a757293 commit 429b877
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
3 changes: 2 additions & 1 deletion contracts/bonding/BondingManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ contract BondingManager is ManagerProxyTarget, IBondingManager {
whenSystemNotPaused
currentRoundInitialized
autoClaimEarnings(msg.sender)
autoCheckpoint(msg.sender)
{
require(_recipient != address(0), "invalid recipient");
uint256 fees = delegators[msg.sender].fees;
Expand Down Expand Up @@ -352,7 +353,7 @@ contract BondingManager is ManagerProxyTarget, IBondingManager {
);

// Deduct what would have been the treasury rewards
uint256 treasuryRewards = MathUtils.percOf(rewards, treasuryRewardCutRate);
uint256 treasuryRewards = PreciseMathUtils.percOf(rewards, treasuryRewardCutRate);
rewards = rewards.sub(treasuryRewards);

uint256 transcoderCommissionRewards = MathUtils.percOf(rewards, earningsPool.transcoderRewardCut);
Expand Down
2 changes: 1 addition & 1 deletion contracts/bonding/IBondingVotes.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
pragma solidity 0.8.9;

import "../treasury/IVotes.sol";

Expand Down
42 changes: 42 additions & 0 deletions test/integration/BondingVotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,48 @@ describe("BondingVotes", () => {
await bondingManager.connect(delegator).bond(amount, transcoder.address)
}

it.only("should allow bonding to non transcoder", async () => {
const transcoder = signers[0]
const delegator = signers[1]
const delegator2 = signers[2]

// Initialize the first round ever
await nextRound()

for (const account of [transcoder, delegator]) {
await bondingManager.checkpointBondingState(account.address)
}

// Round R-2
await nextRound()

await bond(delegator, lptAmount(1), transcoder)
await bond(delegator2, lptAmount(2), delegator)

const expect = async (owner, amount) =>
assert.equal(
await bondingVotes
.getVotes(owner.address)
.then(bn => bn.toString()),
lptAmount(amount).toString()
)

// these are all problematic
await expect(delegator, 1)
await expect(delegator2, 2)
await expect(transcoder, 0)

// Round R-1
await nextRound()

await bond(transcoder, lptAmount(1), transcoder)
await bondingManager
.connect(transcoder)
.transcoder(50 * PERC_MULTIPLIER, 25 * PERC_MULTIPLIER)

await expect(transcoder, 2)
})

describe("single active transcoder", () => {
let transcoder
let delegator
Expand Down
26 changes: 26 additions & 0 deletions test/unit/GovernorCountingOverridable.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,32 @@ describe("GovernorCountingOverridable", () => {
).to.be.revertedWith("VoteAlreadyCast()")
})

it.only("Underflows when not enough votes", async () => {
const transcoder = signers[42]
const delegator = signers[43]

await votes.mint(delegator.address, ethers.utils.parseEther("20"))
await votes.mint(transcoder.address, ethers.utils.parseEther("10"))

// transcoder and delegator delegate to transcoder
await votes.connect(transcoder).delegate(transcoder.address)
await votes.connect(delegator).delegate(transcoder.address)

// transcoder votes
await governor
.connect(transcoder)
.castVote(proposalId, VoteType.For)
await expectVotes([0, 10, 0])

// delegator votes with more voting power than the total `_tally.forVotes`
await expect(
// Underflows in treasury/GovernorCountingOverridable.sol L205
governor
.connect(delegator)
.castVote(proposalId, VoteType.Against)
).to.be.reverted
})

describe("overrides", () => {
for (const transVote of Object.keys(VoteType)) {
describe(`transcoder votes ${transVote} first`, () => {
Expand Down

0 comments on commit 429b877

Please sign in to comment.