-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/psm #2
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
Conversation
0xtj24
commented
Jul 18, 2025
- Add PSM
- Add Controller
- Add PSMFed
🛡️ Immunefi PR ReviewsThanks for submitting this PR for review! We’ve assigned 6 code reviewer(s) to take a look. They’ll provide feedback here as soon as possible. This review is based on the current state of your pull request. If you make changes after the review starts, they won’t be reflected here. To ensure the review includes your latest updates, you’ll need to open a new pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look good to me
Added few comments
- Alzhan
| uint256 profit = amountOut > supply ? amountOut - supply : 0; | ||
| if (profit > 0) { | ||
| vault.withdraw(profit, gov, address(this)); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add event here
- Alzhan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in c54c252
| */ | ||
| function setSupplyCap(uint256 newSupplyCap) external onlyGov { | ||
| uint256 oldSupplyCap = supplyCap; | ||
| supplyCap = newSupplyCap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add check that new supplyCap is >= supply
- Alzhan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to also be able to lower the cap below the supply so it cannot expand but only contract if gov decides to lower it
src/PSM.sol
Outdated
|
|
||
| collateral.safeTransferFrom(msg.sender, address(this), collateralAmountIn); | ||
| collateral.approve(address(vault), collateralAmountIn); | ||
| vault.deposit(collateralAmountIn, address(this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for extra safety might want to require > 0 shares minted. protects against edge case where vault is empty and a deposit is front run, to round it down to 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in aa73378
Also added a check for minTotalSupply set by gov to ensure that a min shares have been minted to expand mitigation for an inflation attack
src/PSM.sol
Outdated
| */ | ||
| function buy(address to, uint256 collateralAmountIn) public { | ||
| require(collateralAmountIn > 0, "Amount must be > 0"); | ||
| require(controller.onBuy(msg.sender, collateralAmountIn), "Denied by controller"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: the to address is not also passed through to the controller for access control, or any arbitrary logic that may go into the controller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in aa73378
src/PSM.sol
Outdated
| collateral.approve(address(vault), collateralAmountIn); | ||
| vault.deposit(collateralAmountIn, address(this)); | ||
| DOLA.safeTransfer(to, amountOut); | ||
| emit Buy(msg.sender, collateralAmountIn, amountOut); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ordering of event parameters is incorrect according to the definition.
event Buy(address indexed user, uint256 purchased, uint256 spent);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in c54c252
src/PSM.sol
Outdated
| function takeProfit() public { | ||
| uint256 vaultBal = vault.balanceOf(address(this)); | ||
| uint256 amountOut = vault.previewRedeem(vaultBal); | ||
| uint256 profit = amountOut > supply ? amountOut - supply : 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: could simplify by making getProfit() function public and using here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in c54c252
src/PSM.sol
Outdated
| require(collateralBalance >= minCollateralAmount, "Insufficient collateral balance for migration"); | ||
| if (collateralBalance > 0) { | ||
| collateral.approve(address(vault), collateralBalance); | ||
| vault.deposit(collateralBalance, address(this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar as above, could add a check for > 0 shares returned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * @param minCollateralAmount Minimum amount of collateral to be deposited in the new vault. | ||
| * @param minSharesOut Minimum amount of shares to receive from the new vault. | ||
| */ | ||
| function migrate(address newVault, uint256 minCollateralAmount, uint256 minSharesOut) external onlyGov { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minTotalSupply check should apply here to the new vault
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case we already have a minSharesOut which fully mitigates an inflation attack or you refer we shouldn't migrate to a new vault if the minTotalSupply is not met?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in 37c62c9
|
LGTM |