|
| 1 | +pragma solidity ^0.8.10; |
| 2 | + |
| 3 | +import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; |
| 4 | +import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol'; |
| 5 | + |
| 6 | +/** |
| 7 | + * @title MockUSTBSubscription |
| 8 | + */ |
| 9 | +contract MockUSTBSubscription { |
| 10 | + using SafeERC20 for IERC20; |
| 11 | + |
| 12 | + address public immutable asset; |
| 13 | + address public immutable liquidity; |
| 14 | + uint256 public USTBPrice; |
| 15 | + |
| 16 | + /** |
| 17 | + * @param _asset Address of asset token, ie USTB |
| 18 | + * @param _liquidity Address of liquidity token, ie USDC |
| 19 | + */ |
| 20 | + constructor(address _asset, address _liquidity, uint256 _price) { |
| 21 | + asset = _asset; |
| 22 | + liquidity = _liquidity; |
| 23 | + setUSTBPrice(_price); |
| 24 | + } |
| 25 | + |
| 26 | + function test_coverage_ignore() public virtual { |
| 27 | + // Intentionally left blank. |
| 28 | + // Excludes contract from coverage. |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * @notice Subscribe to the asset token (USTB) in exchange for the liquidity token (USDC) |
| 33 | + * @param amount The amount of the USDC token to exchange, in base units |
| 34 | + */ |
| 35 | + function subscribe(uint256 amount) external { |
| 36 | + uint256 USTBAmount = amount / USTBPrice; |
| 37 | + IERC20(liquidity).safeTransferFrom(msg.sender, address(this), amount); |
| 38 | + IERC20(asset).safeTransfer(msg.sender, USTBAmount); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * @notice Redeem the asset token (USTB) in exchange for the liquidity token (USDC) |
| 43 | + * @param amount The amount of the USTB token to exchange, in base units |
| 44 | + */ |
| 45 | + function redeem(uint256 amount) external { |
| 46 | + uint256 USDCAmount = amount * USTBPrice; |
| 47 | + IERC20(asset).safeTransfer(msg.sender, amount); |
| 48 | + IERC20(liquidity).safeTransferFrom(msg.sender, address(this), USDCAmount); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @notice Set the price of USTB, amount of USDC for 1 USTB. Accounts for decimal mismatch. |
| 53 | + * @param newPrice The new price of USTB |
| 54 | + */ |
| 55 | + function setUSTBPrice(uint256 newPrice) public { |
| 56 | + USTBPrice = newPrice; |
| 57 | + } |
| 58 | +} |
0 commit comments