Skip to content

Conversation

@0xtj24
Copy link
Collaborator

@0xtj24 0xtj24 commented Jul 18, 2025

  • Add PSM
  • Add Controller
  • Add PSMFed

@immunefi-magnus
Copy link

immunefi-magnus bot commented Jul 18, 2025

🛡️ Immunefi PR Reviews

Thanks 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.

Copy link

@immunefi-magnus immunefi-magnus bot left a 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));
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add event here

  • Alzhan

Copy link
Collaborator Author

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;

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

Copy link
Collaborator Author

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));
Copy link

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.

Copy link
Collaborator Author

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");
Copy link

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.

Copy link
Collaborator Author

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);
Copy link

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);

Copy link
Collaborator Author

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;
Copy link

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

Copy link
Collaborator Author

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));
Copy link

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in [c54c252] by adding a minSharesOut param (c54c252)

* @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 {
Copy link
Member

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

Copy link
Collaborator Author

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 37c62c9

@nourharidy
Copy link
Member

LGTM

@0xtj24 0xtj24 merged commit 06eb2b3 into main Aug 11, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants