Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repo redemption haircut #14

Closed
wants to merge 5 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/Strategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ contract Strategy is BaseStrategy, Pausable, ReentrancyGuard {
uint256 public discountRateMarkup; // 1e18 (TODO: check this)
uint256 public repoTokenConcentrationLimit; // 1e18
mapping(address => bool) public repoTokenBlacklist;
mapping(address => uint256) public repoRedemptionHaircut;
bool public depositLock;

modifier notBlacklisted(address repoToken) {
Expand Down Expand Up @@ -129,6 +130,15 @@ contract Strategy is BaseStrategy, Pausable, ReentrancyGuard {
currTermController = ITermController(newTermController);
}

/**
* @notice Set the repo redemption haircut
* @param repoToken The address of the repo token
* @param haircut The repo redemption haircut in 18 decimals
*/
function setRepoRedemptionHaircut(address repoToken, uint256 haircut) external onlyManagement {
repoRedemptionHaircut[repoToken] = haircut;
}

/**
* @notice Set the discount rate adapter used to price repoTokens
* @param newAdapter The address of the new discount rate adapter
Expand Down Expand Up @@ -353,13 +363,14 @@ contract Strategy is BaseStrategy, Pausable, ReentrancyGuard {
);

uint256 discountRate = discountRateAdapter.getDiscountRate(repoToken);
uint256 repoRedemptionHaircutMantissa = repoRedemptionHaircut[repoToken] == 0 ? 1e18 : repoRedemptionHaircut[repoToken];
uint256 repoTokenPrecision = 10 ** ERC20(repoToken).decimals();
repoTokenAmountInBaseAssetPrecision = (ITermRepoToken(
repoToken
).redemptionValue() *
).redemptionValue() * repoRedemptionHaircutMantissa *
amount *
PURCHASE_TOKEN_PRECISION) /
(repoTokenPrecision * RepoTokenUtils.RATE_PRECISION);
(repoTokenPrecision * RepoTokenUtils.RATE_PRECISION * 1e18);
proceeds = RepoTokenUtils.calculatePresentValue(
repoTokenAmountInBaseAssetPrecision,
PURCHASE_TOKEN_PRECISION,
Expand Down Expand Up @@ -402,11 +413,12 @@ contract Strategy is BaseStrategy, Pausable, ReentrancyGuard {
(uint256 redemptionTimestamp, , , ) = ITermRepoToken(repoToken)
.config();
uint256 repoTokenPrecision = 10 ** ERC20(repoToken).decimals();
uint256 repoRedemptionHaircutMantissa = repoRedemptionHaircut[repoToken] == 0 ? 1e18 : repoRedemptionHaircut[repoToken];
uint256 repoTokenAmountInBaseAssetPrecision = (ITermRepoToken(repoToken)
.redemptionValue() *
.redemptionValue() * repoRedemptionHaircutMantissa *
amount *
PURCHASE_TOKEN_PRECISION) /
(repoTokenPrecision * RepoTokenUtils.RATE_PRECISION);
(repoTokenPrecision * RepoTokenUtils.RATE_PRECISION * 1e18);
return
RepoTokenUtils.calculatePresentValue(
repoTokenAmountInBaseAssetPrecision,
Expand Down Expand Up @@ -1026,11 +1038,12 @@ contract Strategy is BaseStrategy, Pausable, ReentrancyGuard {

// Calculate the repoToken amount in base asset precision
uint256 repoTokenPrecision = 10 ** ERC20(repoToken).decimals();
uint256 repoRedemptionHaircutMantissa = repoRedemptionHaircut[repoToken] == 0 ? 1e18 : repoRedemptionHaircut[repoToken];
uint256 repoTokenAmountInBaseAssetPrecision = (ITermRepoToken(repoToken)
.redemptionValue() *
.redemptionValue() * repoRedemptionHaircutMantissa *
repoTokenAmount *
PURCHASE_TOKEN_PRECISION) /
(repoTokenPrecision * RepoTokenUtils.RATE_PRECISION);
(repoTokenPrecision * RepoTokenUtils.RATE_PRECISION * 1e18);

// Calculate the proceeds from selling the repoToken
uint256 proceeds = RepoTokenUtils.calculatePresentValue(
Expand Down
Loading