diff --git a/src/VoteDelegate.sol b/src/VoteDelegate.sol index 07fe161..d230343 100644 --- a/src/VoteDelegate.sol +++ b/src/VoteDelegate.sol @@ -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); @@ -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 --- diff --git a/test/VoteDelegate.t.sol b/test/VoteDelegate.t.sol index f924e5a..baf1277 100644 --- a/test/VoteDelegate.t.sol +++ b/test/VoteDelegate.t.sol @@ -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); @@ -43,6 +47,8 @@ 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); @@ -50,7 +56,7 @@ contract VoteDelegateTest is DssTest { 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())); @@ -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 { @@ -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); @@ -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 @@ -103,12 +108,12 @@ 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); @@ -116,7 +121,7 @@ contract VoteDelegateTest is DssTest { 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 @@ -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); @@ -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 @@ -152,12 +157,12 @@ 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); @@ -165,7 +170,7 @@ contract VoteDelegateTest is DssTest { 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; @@ -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); @@ -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; @@ -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); } diff --git a/test/VoteDelegateFactory.t.sol b/test/VoteDelegateFactory.t.sol index 67db667..99b0d95 100644 --- a/test/VoteDelegateFactory.t.sol +++ b/test/VoteDelegateFactory.t.sol @@ -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));