Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SC-466] Add testing support psm variant 2 #6

Merged
merged 10 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .assets/user-actions-overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions test/PSMVariant1Actions.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ abstract contract PSMVariant1ActionsBase is Test {
// Set the savings token to 1.25 conversion rate to keep the shares different
savingsToken.__setShareConversionRate(1.25e18);

// Put some existing gems into the PSM
gem.mint(address(psm), 1000e6);

actions = new PSMVariant1Actions(
address(psm),
address(savingsToken)
Expand Down
13 changes: 10 additions & 3 deletions test/PSMVariant2Actions.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import { PSMVariant2Mock } from "./mocks/PSMVariant2Mock.sol";

import { PSMVariant1Actions } from "src/PSMVariant1Actions.sol";

// NOTE: This test contract is demonstrate support for the second version of the PSM with the version 1 actions
// NOTE: This test contract demonstrates support for the second version of the PSM with the
// version 1 actions. For this reason, all of the code is identical to
// test/PSMVariant1Actions.t.sol, except for the setup and the redundant testing of the
// PSMVariant1Actions constructor. This can be seen by diffing the two files.
abstract contract PSMVariant2ActionsBase is Test {
lucas-manuel marked this conversation as resolved.
Show resolved Hide resolved

// 1 trillion max of each
Expand All @@ -26,19 +29,23 @@ abstract contract PSMVariant2ActionsBase is Test {
PSMVariant1Actions actions;

address receiver = makeAddr("receiver");
address pocket = makeAddr("pocket");

function setUp() public {
dai = new MockERC20('DAI', 'DAI', 18);
gem = new MockERC20('USDC', 'USDC', 6);

savingsToken = new ERC4626Mock(dai, 'Savings DAI', 'sDAI', 18);
psm = new PSMVariant2Mock(dai, gem);
psm = new PSMVariant2Mock(dai, gem, pocket);

// pocket will be the Coinbase wallet with an infinite approval
vm.prank(pocket);
gem.approve(address(psm), type(uint256).max);

// Set the savings token to 1.25 conversion rate to keep the shares different
savingsToken.__setShareConversionRate(1.25e18);

// Put some existing tokens into the PSM
gem.mint(address(psm), 1000e6);
dai.mint(address(psm), type(uint248).max); // Some big number of capacity

actions = new PSMVariant1Actions(
Expand Down
8 changes: 5 additions & 3 deletions test/mocks/PSMVariant2Mock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ contract PSMVariant2Mock {

MockERC20 public dai;
MockERC20 public gem;
address public pocket;

uint256 public tin;
uint256 public tout;

uint256 private to18ConversionFactor;

constructor(MockERC20 _dai, MockERC20 _gem) {
constructor(MockERC20 _dai, MockERC20 _gem, address _pocket) {
dai = _dai;
gem = _gem;
pocket = _pocket;
lucas-manuel marked this conversation as resolved.
Show resolved Hide resolved

to18ConversionFactor = 10 ** (18 - gem.decimals());
}
Expand All @@ -30,7 +32,7 @@ contract PSMVariant2Mock {
daiOutWad -= fee;
}
}
gem.transferFrom(msg.sender, address(this), gemAmt);
gem.transferFrom(msg.sender, pocket, gemAmt);
dai.transfer(usr, daiOutWad);
}

Expand All @@ -42,7 +44,7 @@ contract PSMVariant2Mock {
daiInWad += fee;
}
dai.transferFrom(msg.sender, address(this), daiInWad);
gem.transfer(usr, gemAmt);
gem.transferFrom(pocket, usr, gemAmt);
}

function __setTin(uint256 _tin) external {
Expand Down
Loading