Skip to content

Commit

Permalink
Remove IOU usage and MKR mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
oldchili committed Feb 18, 2025
1 parent 4b7c541 commit 38360fe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
3 changes: 0 additions & 3 deletions src/VoteDelegate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ interface GemLike {

interface ChiefLike {
function GOV() external view returns (GemLike);
function IOU() external view returns (GemLike);
function lock(uint256) external;
function free(uint256) external;
function vote(address[] calldata) external returns (bytes32);
Expand Down Expand Up @@ -61,9 +60,7 @@ contract VoteDelegate {
delegate = delegate_;

gov = ChiefLike(chief_).GOV();

gov.approve(chief_, type(uint256).max);
ChiefLike(chief_).IOU().approve(chief_, type(uint256).max);
}

// --- modifiers ---
Expand Down
37 changes: 21 additions & 16 deletions test/VoteDelegate.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ interface GemLikeExtended is GemLike {
function mint(address, uint256) external;
}

interface ChainlogLike {
function getAddress(bytes32) external view returns (address);
}

contract VoteDelegateTest is DssTest {
address constant c1 = address(0x1);
address constant c2 = address(0x2);
Expand All @@ -43,14 +47,16 @@ contract VoteDelegateTest is DssTest {
address delegator1 = address(222);
address delegator2 = address(333);

ChainlogLike constant chainlog = ChainlogLike(0xdA0Ab1e0017DEbCd72Be8599041a2aa3bA7e740F);

event Lock(address indexed usr, uint256 wad);
event Free(address indexed usr, uint256 wad);
event Voted(address indexed voter, uint256 indexed pollId, uint256 indexed optionId);

function setUp() public {
vm.createSelectFork(vm.envString("ETH_RPC_URL"));

chief = ChiefExtendedLike(0x0a3f6849f78076aefaDf113F5BED87720274dDC0);
chief = ChiefExtendedLike(chainlog.getAddress("MCD_ADM"));
polling = PollingLike(0xD3A9FE267852281a1e6307a1C37CDfD76d39b133);
gov = GemLikeExtended(address(chief.GOV()));

Expand All @@ -67,7 +73,6 @@ contract VoteDelegateTest is DssTest {
assertEq(proxy.delegate(), delegate);
assertEq(address(proxy.gov()), address(chief.GOV()));
assertEq(gov.allowance(address(proxy), address(chief)), type(uint256).max);
assertEq(GemLikeExtended(address(chief.IOU())).allowance(address(proxy), address(chief)), type(uint256).max);
}

function testModifiers() public {
Expand All @@ -83,7 +88,7 @@ contract VoteDelegateTest is DssTest {
}

function testProxyLockFree() public {
uint256 initialMKR = gov.balanceOf(address(chief));
uint256 initialGov = gov.balanceOf(address(chief));

vm.prank(delegate); gov.approve(address(proxy), type(uint256).max);

Expand All @@ -93,7 +98,7 @@ contract VoteDelegateTest is DssTest {
emit Lock(delegate, 100 ether);
vm.prank(delegate); proxy.lock(100 ether);
assertEq(gov.balanceOf(address(delegate)), 0);
assertEq(gov.balanceOf(address(chief)), initialMKR + 100 ether);
assertEq(gov.balanceOf(address(chief)), initialGov + 100 ether);
assertEq(proxy.stake(address(delegate)), 100 ether);

// Comply with Chief's flash loan protection
Expand All @@ -103,20 +108,20 @@ contract VoteDelegateTest is DssTest {
emit Free(delegate, 100 ether);
vm.prank(delegate); proxy.free(100 ether);
assertEq(gov.balanceOf(address(delegate)), 100 ether);
assertEq(gov.balanceOf(address(chief)), initialMKR);
assertEq(gov.balanceOf(address(chief)), initialGov);
assertEq(proxy.stake(address(delegate)), 0);
}

function testDelegatorLockFree() public {
uint256 initialMKR = gov.balanceOf(address(chief));
uint256 initialGov = gov.balanceOf(address(chief));

vm.prank(delegator1); gov.approve(address(proxy), type(uint256).max);

vm.expectEmit(true, true, true, true);
emit Lock(delegator1, 10_000 ether);
vm.prank(delegator1); proxy.lock(10_000 ether);
assertEq(gov.balanceOf(address(delegator1)), 0);
assertEq(gov.balanceOf(address(chief)), initialMKR + 10_000 ether);
assertEq(gov.balanceOf(address(chief)), initialGov + 10_000 ether);
assertEq(proxy.stake(address(delegator1)), 10_000 ether);

// Comply with Chief's flash loan protection
Expand All @@ -126,13 +131,13 @@ contract VoteDelegateTest is DssTest {
emit Free(delegator1, 10_000 ether);
vm.prank(delegator1); proxy.free(10_000 ether);
assertEq(gov.balanceOf(address(delegator1)), 10_000 ether);
assertEq(gov.balanceOf(address(chief)), initialMKR);
assertEq(gov.balanceOf(address(chief)), initialGov);
assertEq(proxy.stake(address(delegator1)), 0);
}

function testDelegatorLockFreeFuzz(uint256 wad_seed) public {
uint256 wad = wad_seed < 1 ether ? wad_seed += 1 ether : wad_seed % 20_000 ether;
uint256 initialMKR = gov.balanceOf(address(chief));
uint256 initialGov = gov.balanceOf(address(chief));

vm.prank(delegator2); gov.approve(address(proxy), type(uint256).max);

Expand All @@ -142,7 +147,7 @@ contract VoteDelegateTest is DssTest {
emit Lock(delegator2, wad);
vm.prank(delegator2); proxy.lock(wad);
assertEq(gov.balanceOf(address(delegator2)), delGovBalance - wad);
assertEq(gov.balanceOf(address(chief)), initialMKR + wad);
assertEq(gov.balanceOf(address(chief)), initialGov + wad);
assertEq(proxy.stake(address(delegator2)), wad);

// Comply with Chief's flash loan protection
Expand All @@ -152,20 +157,20 @@ contract VoteDelegateTest is DssTest {
emit Free(delegator2, wad);
vm.prank(delegator2); proxy.free(wad);
assertEq(gov.balanceOf(address(delegator2)), delGovBalance);
assertEq(gov.balanceOf(address(chief)), initialMKR);
assertEq(gov.balanceOf(address(chief)), initialGov);
assertEq(proxy.stake(address(delegator2)), 0);
}

function testDelegateVoting() public {
uint256 initialMKR = gov.balanceOf(address(chief));
uint256 initialGov = gov.balanceOf(address(chief));

vm.prank(delegate); gov.approve(address(proxy), type(uint256).max);
vm.prank(delegator1); gov.approve(address(proxy), type(uint256).max);

vm.prank(delegate); proxy.lock(100 ether);
vm.prank(delegator1); proxy.lock(10_000 ether);

assertEq(gov.balanceOf(address(chief)), initialMKR + 10_100 ether);
assertEq(gov.balanceOf(address(chief)), initialGov + 10_100 ether);

address[] memory yays = new address[](1);
yays[0] = c1;
Expand Down Expand Up @@ -202,7 +207,7 @@ contract VoteDelegateTest is DssTest {
function testDelegateVotingFuzz(uint256 wad_seed, uint256 wad2_seed) public {
uint256 wad = wad_seed < 1 ether ? wad_seed += 1 ether : wad_seed % 100 ether;
uint256 wad2 = wad2_seed < 1 ether ? wad2_seed += 1 ether : wad2_seed % 20_000 ether;
uint256 initialMKR = gov.balanceOf(address(chief));
uint256 initialGov = gov.balanceOf(address(chief));

vm.prank(delegate); gov.approve(address(proxy), type(uint256).max);
vm.prank(delegator2); gov.approve(address(proxy), type(uint256).max);
Expand All @@ -217,7 +222,7 @@ contract VoteDelegateTest is DssTest {
assertEq(gov.balanceOf(address(delegator2)), del2GovBalance - wad2);
assertEq(proxy.stake(address(delegate)), wad);
assertEq(proxy.stake(address(delegator2)), wad2);
assertEq(gov.balanceOf(address(chief)), initialMKR + wad + wad2);
assertEq(gov.balanceOf(address(chief)), initialGov + wad + wad2);

address[] memory yays = new address[](1);
yays[0] = c1;
Expand All @@ -238,7 +243,7 @@ contract VoteDelegateTest is DssTest {
vm.prank(delegate); proxy.lock(100 ether);
vm.prank(delegator1); proxy.lock(10_000 ether);

// Attempting to take more MKR than assigned in the stake mapping (having a greater total)
// Attempting to take more gov tokens than assigned in the stake mapping (having a greater total)
vm.expectRevert("VoteDelegate/insufficient-stake");
vm.prank(delegate); proxy.free(100 ether + 1);
}
Expand Down
8 changes: 7 additions & 1 deletion test/VoteDelegateFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,23 @@ import "dss-test/DssTest.sol";

import "src/VoteDelegateFactory.sol";

interface ChainlogLike {
function getAddress(bytes32) external view returns (address);
}

contract VoteDelegateFactoryTest is DssTest {
VoteDelegateFactory factory;
address chief;
address polling;

ChainlogLike constant chainlog = ChainlogLike(0xdA0Ab1e0017DEbCd72Be8599041a2aa3bA7e740F);

event CreateVoteDelegate(address indexed usr, address indexed voteDelegate);

function setUp() public {
vm.createSelectFork(vm.envString("ETH_RPC_URL"));

chief = 0x0a3f6849f78076aefaDf113F5BED87720274dDC0;
chief = chainlog.getAddress("MCD_ADM");
polling = 0xD3A9FE267852281a1e6307a1C37CDfD76d39b133;

factory = new VoteDelegateFactory(address(chief), address(polling));
Expand Down

0 comments on commit 38360fe

Please # to comment.