-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
requires msg.sender own M3ter to deposit, mint, withdraw or redeem.
- Loading branch information
1 parent
132d56a
commit 91df7d9
Showing
3 changed files
with
18 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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. | ||
|
@@ -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); | ||
} | ||
|
@@ -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); | ||
|
@@ -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); | ||
} | ||
|
@@ -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); | ||
|
@@ -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); | ||
|
@@ -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(); | ||
|
@@ -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); | ||
|
@@ -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(); | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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 { | ||
|