Created
February 7, 2023 21:11
-
-
Save davidlaprade/e51935fb76cf9bb56d4b4b43c3d62b2e to your computer and use it in GitHub Desktop.
Compound V3 Rebasing Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.8.13; | |
import "forge-std/Test.sol"; | |
import "forge-std/console2.sol"; | |
interface IComet { | |
function supply(address asset, uint amount) virtual external; | |
function balanceOf(address owner) virtual external view returns (uint256); | |
} | |
interface IERC20 { | |
function approve(address spender, uint256 amount) external returns (bool); | |
} | |
contract CometTest is Test { | |
IComet public comet = IComet(0xc3d688B66703497DAA19211EEdff47f25384cdc3); | |
IERC20 public constant USDC = IERC20(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48); | |
function testFork_BalanceInterestAccrual() public { | |
vm.createSelectFork( | |
"https://mainnet.infura.io/v3/xxxxx", | |
16579384 | |
); | |
address alice = makeAddr('alice'); | |
address bob = makeAddr('bob'); | |
deal(address(USDC), alice, 1 ether); | |
deal(address(USDC), bob, 1 ether); | |
assertEq(comet.balanceOf(alice), 0); | |
assertEq(comet.balanceOf(bob), 0); | |
vm.startPrank(alice); | |
USDC.approve(address(comet), type(uint).max); | |
comet.supply(address(USDC), 1 ether); | |
vm.stopPrank(); | |
assertEq(comet.balanceOf(alice), 1 ether - 1); | |
assertEq(comet.balanceOf(bob), 0); | |
vm.warp(block.timestamp + 60*60*24*365); // a year | |
// Alice's balance should have increased w/ the passing of time. | |
assertGt(comet.balanceOf(alice), 1 ether - 1); | |
assertEq(comet.balanceOf(bob), 0); | |
vm.startPrank(bob); | |
USDC.approve(address(comet), type(uint).max); | |
comet.supply(address(USDC), 1 ether); | |
vm.stopPrank(); | |
console2.log("alice balance", comet.balanceOf(alice)); | |
console2.log("bob balance", comet.balanceOf(bob)); | |
assertGt( | |
comet.balanceOf(alice), | |
comet.balanceOf(bob) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment