Skip to content

Commit

Permalink
requires msg.sender own M3ter to deposit, mint, withdraw or redeem.
Browse files Browse the repository at this point in the history
  • Loading branch information
iChristwin committed Mar 1, 2024
1 parent 132d56a commit 91df7d9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/Solaxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.19;
import "./XRC20.sol";
import "./interfaces/ISolaxy.sol";
import {UD60x18, ud60x18} from "@prb/[email protected]/src/UD60x18.sol";
import {IERC721} from "@openzeppelin/[email protected]/interfaces/IERC721.sol";

/**
* @title Solaxy
Expand All @@ -15,6 +16,7 @@ contract Solaxy is XRC20, ISolaxy {
UD60x18 public constant slope = UD60x18.wrap(0.0025e18);
UD60x18 public constant halfSlope = UD60x18.wrap(0.00125e18);
ERC20 public constant DAI = ERC20(0x1CbAd85Aa66Ff3C12dc84C5881886EEB29C1bb9b);
IERC721 public constant M3ter = IERC721(0x36c042bad25f24c4Ad5391Bf52b1eA9ec811A9D3); // TODO: M3ter Address

/**
* @dev Constructs the Solaxy contract, initializing the DAI token and the fee address.
Expand All @@ -37,6 +39,7 @@ contract Solaxy is XRC20, ISolaxy {
* @dev See {IERC4626-deposit}.
*/
function deposit(uint256 assets, address receiver) external returns (uint256 shares) {
if (M3ter.balanceOf(msg.sender) < 1) revert RequiresM3ter();
shares = computeDeposit(assets, totalSupply());
_deposit(receiver, assets, shares);
}
Expand All @@ -45,6 +48,7 @@ contract Solaxy is XRC20, ISolaxy {
* @dev See {IERC4626-withdraw}.
*/
function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares) {
if (M3ter.balanceOf(msg.sender) < 1) revert RequiresM3ter();
uint256 fee;
(shares, fee) = computeWithdraw(assets, totalSupply());
_withdraw(receiver, owner, assets, shares, fee);
Expand All @@ -54,6 +58,7 @@ contract Solaxy is XRC20, ISolaxy {
* @dev See {IERC4626-mint}.
*/
function mint(uint256 shares, address receiver) external returns (uint256 assets) {
if (M3ter.balanceOf(msg.sender) < 1) revert RequiresM3ter();
assets = computeMint(shares, totalSupply());
_deposit(receiver, assets, shares);
}
Expand All @@ -62,6 +67,7 @@ contract Solaxy is XRC20, ISolaxy {
* @dev See {IERC4626-redeem}.
*/
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets) {
if (M3ter.balanceOf(msg.sender) < 1) revert RequiresM3ter();
uint256 fee;
(shares, assets, fee) = computeRedeem(shares, totalSupply());
_withdraw(receiver, owner, assets, shares, fee);
Expand All @@ -72,6 +78,7 @@ contract Solaxy is XRC20, ISolaxy {
* @param minSharesOut The minimum number of shares the sender expects to receive.
*/
function safeDeposit(uint256 assets, address receiver, uint256 minSharesOut) external returns (uint256 shares) {
if (M3ter.balanceOf(msg.sender) < 1) revert RequiresM3ter();
shares = computeDeposit(assets, totalSupply());
if (shares < minSharesOut) revert SlippageError();
_deposit(receiver, assets, shares);
Expand All @@ -85,6 +92,7 @@ contract Solaxy is XRC20, ISolaxy {
external
returns (uint256 shares)
{
if (M3ter.balanceOf(msg.sender) < 1) revert RequiresM3ter();
uint256 fee;
(shares, fee) = computeWithdraw(assets, totalSupply());
if (shares > maxSharesIn) revert SlippageError();
Expand All @@ -96,6 +104,7 @@ contract Solaxy is XRC20, ISolaxy {
* @param maxAssetsIn The maximum amount of assets the sender is willing to deposit.
*/
function safeMint(uint256 shares, address receiver, uint256 maxAssetsIn) external returns (uint256 assets) {
if (M3ter.balanceOf(msg.sender) < 1) revert RequiresM3ter();
assets = computeMint(shares, totalSupply());
if (assets > maxAssetsIn) revert SlippageError();
_deposit(receiver, assets, shares);
Expand All @@ -109,6 +118,7 @@ contract Solaxy is XRC20, ISolaxy {
external
returns (uint256 assets)
{
if (M3ter.balanceOf(msg.sender) < 1) revert RequiresM3ter();
uint256 fee;
(shares, assets, fee) = computeRedeem(shares, totalSupply());
if (assets < minAssetsOut) revert SlippageError();
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/ISolaxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ error Undersupply();
error CannotBeZero();
error SlippageError();
error TransferError();
error RequiresM3ter();

interface ISolaxy is IERC4626 {
function safeDeposit(uint256 assets, address receiver, uint256 minSharesOut) external returns (uint256 shares);
Expand Down
8 changes: 7 additions & 1 deletion test/Solaxy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import {Test} from "forge-std/Test.sol";
import {Solaxy} from "../src/Solaxy.sol";
import {PayableErr} from "../src/interfaces/ISolaxy.sol";
import {IERC20} from "@openzeppelin/[email protected]/interfaces/IERC20.sol";
import {IERC721} from "@openzeppelin/[email protected]/interfaces/IERC721.sol";

contract SolaxyTest is Test {
Solaxy public slx;
IERC20 public dai;
IERC721 public m3ter;
address public here;
address public slxAddress;
address public daiAddress;
address public m3terAddress;
uint256 public constant slxAmountIn = 6.795e18;
uint256 public constant slxAmountMinted = 10e18;
uint256 public constant slxAmountBurned = 5e18;
Expand All @@ -29,9 +32,12 @@ contract SolaxyTest is Test {

daiAddress = slx.asset();
dai = IERC20(daiAddress);

deal(daiAddress, here, oneMillionDaiBalance, true);
dai.approve(slxAddress, oneMillionDaiBalance);

m3ter = IERC721(0x36c042bad25f24c4Ad5391Bf52b1eA9ec811A9D3);
m3terAddress = address(m3ter);
dealERC721(m3terAddress, here, 1);
}

function testInitialBalanceWithNewSolaxyContract() public {
Expand Down

0 comments on commit 91df7d9

Please sign in to comment.