Skip to content

Commit c95eb96

Browse files
committed
test: update mock with preview methods
1 parent e5545c8 commit c95eb96

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/test/mocks/MockUSTBSubscriptionRedemption.sol

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
99
contract MockUSTBSubscription {
1010
using SafeERC20 for IERC20;
1111

12+
uint256 constant USDC_PRECISION = 1e6;
13+
uint256 constant SUPERSTATE_TOKEN_PRECISION = 1e6;
14+
uint256 constant CHAINLINK_FEED_PRECISION = 1e8;
15+
1216
address public immutable asset;
1317
address public immutable liquidity;
1418
uint256 public USTBPrice;
@@ -48,6 +52,31 @@ contract MockUSTBSubscription {
4852
IERC20(liquidity).safeTransferFrom(msg.sender, address(this), USDCAmount);
4953
}
5054

55+
function calculateUsdcOut(
56+
uint256 superstateTokenInAmount
57+
) public view returns (uint256 usdcOutAmount, uint256 usdPerUstbChainlinkRaw) {
58+
usdPerUstbChainlinkRaw = 1_100_000_000; // 11 USDC/USTB
59+
uint256 fee = 500; // in BPS
60+
61+
usdcOutAmount =
62+
(superstateTokenInAmount * usdPerUstbChainlinkRaw * USDC_PRECISION) /
63+
(CHAINLINK_FEED_PRECISION * SUPERSTATE_TOKEN_PRECISION);
64+
65+
usdcOutAmount = (usdcOutAmount * (10_000 - fee)) / 10_000;
66+
}
67+
68+
function calculateUstbIn(
69+
uint256 usdcOutAmount
70+
) public view returns (uint256 ustbInAmount, uint256 usdPerUstbChainlinkRaw) {
71+
uint256 fee = 500; // in BPS
72+
uint256 usdcOutAmountWithFee = usdcOutAmount * (10_000 + fee);
73+
usdPerUstbChainlinkRaw = 1_100_000_000; // 11 USDC/USTB
74+
75+
ustbInAmount =
76+
(usdcOutAmountWithFee * CHAINLINK_FEED_PRECISION * SUPERSTATE_TOKEN_PRECISION) /
77+
(usdPerUstbChainlinkRaw * USDC_PRECISION);
78+
}
79+
5180
/**
5281
* @notice Set the price of USTB, amount of USDC for 1 USTB. USTB/USDC both have 6 decimals.
5382
* @param newPrice The new price of USTB

0 commit comments

Comments
 (0)