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

accmumulate throttles during dissolve()/mint() #1197

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions contracts/p0/RToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ contract RTokenP0 is ComponentP0, ERC20PermitUpgradeable, IRToken {
/// @custom:protected
function mint(uint192 baskets) external exchangeRateIsValidAfter {
require(_msgSender() == address(main.backingManager()), "not backing manager");
issuanceThrottle.useAvailable(totalSupply(), 0);
redemptionThrottle.useAvailable(totalSupply(), 0);
_scaleUp(address(main.backingManager()), baskets);
}

Expand All @@ -285,6 +287,8 @@ contract RTokenP0 is ComponentP0, ERC20PermitUpgradeable, IRToken {
/// @custom:protected
function dissolve(uint256 amount) external exchangeRateIsValidAfter {
require(_msgSender() == address(main.backingManager()), "not backing manager");
issuanceThrottle.useAvailable(totalSupply(), 0);
redemptionThrottle.useAvailable(totalSupply(), 0);
_scaleDown(_msgSender(), amount);
}

Expand Down
13 changes: 12 additions & 1 deletion contracts/p1/RToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,12 @@ contract RTokenP1 is ComponentP1, ERC20PermitUpgradeable, IRToken {
// BU exchange rate cannot decrease, and it can only increase when < FIX_ONE.
function mint(uint192 baskets) external {
require(_msgSender() == address(backingManager), "not backing manager");
_scaleUp(address(backingManager), baskets, totalSupply());
uint256 supply = totalSupply();

// Accumulate the throttle before the supply change
issuanceThrottle.useAvailable(supply, 0);
redemptionThrottle.useAvailable(supply, 0);
_scaleUp(address(backingManager), baskets, supply);
}

/// Melt a quantity of RToken from the caller's account, increasing the basket rate
Expand All @@ -372,6 +377,7 @@ contract RTokenP1 is ComponentP1, ERC20PermitUpgradeable, IRToken {
require(caller == address(furnace), "furnace only");
_burn(caller, amtRToken);
emit Melted(amtRToken);
// do not update throttles: melting is frequent and always small
}

/// Burn an amount of RToken from caller's account and scale basketsNeeded down
Expand All @@ -387,6 +393,11 @@ contract RTokenP1 is ComponentP1, ERC20PermitUpgradeable, IRToken {
function dissolve(uint256 amount) external {
address caller = _msgSender();
require(caller == address(backingManager), "not backing manager");
uint256 supply = totalSupply();

// Accumulate the throttle before the supply change
issuanceThrottle.useAvailable(supply, 0);
redemptionThrottle.useAvailable(supply, 0);
_scaleDown(caller, amount);
}

Expand Down
Loading