Skip to content

Commit

Permalink
Storage pack Checkpoint enum
Browse files Browse the repository at this point in the history
  • Loading branch information
elenadimitrova committed Feb 13, 2023
1 parent 928394e commit 349afb3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions contracts/governance/src/IZeroExVotes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pragma solidity ^0.8.17;
interface IZeroExVotes {
struct Checkpoint {
uint32 fromBlock;
uint224 votes;
uint224 quadraticVotes;
uint96 votes;
uint48 quadraticVotes;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions contracts/governance/src/ZeroExVotes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ contract ZeroExVotes is IZeroExVotes {
// Remove the entire source delegator's sqrt balance from delegatee's voting power.
// `srcDelegateBalance` is value _after_ transfer so add the amount that was transferred.
if (pos > 0)
oldCkptSrcDelegate.quadraticVotes -= SafeCast.toUint224(Math.sqrt(srcDelegateBalance + amount));
oldCkptSrcDelegate.quadraticVotes -= SafeCast.toUint48(Math.sqrt(srcDelegateBalance + amount));

uint256 newLinearBalance = oldCkptSrcDelegate.votes - amount;
uint256 newQuadraticBalance = oldCkptSrcDelegate.quadraticVotes + Math.sqrt(srcDelegateBalance);
Expand All @@ -197,7 +197,7 @@ contract ZeroExVotes is IZeroExVotes {
// Remove the entire destination delegator's sqrt balance from delegatee's voting power.
// `dstDelegateBalance` is value _after_ transfer so remove the amount that was transferred.
if (pos > 0)
oldCkptDstDelegate.quadraticVotes -= SafeCast.toUint224(Math.sqrt(dstDelegateBalance - amount));
oldCkptDstDelegate.quadraticVotes -= SafeCast.toUint48(Math.sqrt(dstDelegateBalance - amount));

uint256 newLinearBalance = oldCkptDstDelegate.votes + amount;
uint256 newQuadraticBalance = oldCkptDstDelegate.quadraticVotes + Math.sqrt(dstDelegateBalance);
Expand Down Expand Up @@ -283,14 +283,14 @@ contract ZeroExVotes is IZeroExVotes {

if (pos > 0 && _unsafeAccess(ckpts, pos - 1).fromBlock == block.number) {
Checkpoint storage chpt = _unsafeAccess(ckpts, pos - 1);
chpt.votes = SafeCast.toUint224(voteWeight);
chpt.quadraticVotes = SafeCast.toUint224(quadraticVoteWeight);
chpt.votes = SafeCast.toUint96(voteWeight);
chpt.quadraticVotes = SafeCast.toUint48(quadraticVoteWeight);
} else {
ckpts.push(
Checkpoint({
fromBlock: SafeCast.toUint32(block.number),
votes: SafeCast.toUint224(voteWeight),
quadraticVotes: SafeCast.toUint224(quadraticVoteWeight)
votes: SafeCast.toUint96(voteWeight),
quadraticVotes: SafeCast.toUint48(quadraticVoteWeight)
})
);
}
Expand Down

0 comments on commit 349afb3

Please sign in to comment.