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

Bunch of small changes #877

Merged
merged 12 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
7 changes: 7 additions & 0 deletions contracts/p0/AssetRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ contract AssetRegistryP0 is ComponentP0, IAssetRegistry {

/// Register an asset, unregistering any previous asset with the same ERC20.
function _registerIgnoringCollisions(IAsset asset) private returns (bool swapped) {
if (asset.isCollateral()) {
require(
ICollateral(address(asset)).status() == CollateralStatus.SOUND,
"collateral not sound"
);
}

if (_erc20s.contains(address(asset.erc20())) && assets[asset.erc20()] == asset)
return false;

Expand Down
9 changes: 9 additions & 0 deletions contracts/p1/AssetRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ contract AssetRegistryP1 is ComponentP1, IAssetRegistry {
}

/// Unregister an asset, requiring that it is already registered
/// Rewards are NOT claimed by default when unregistering due to security concerns.
/// If the collateral is secure, governance should claim rewards before unregistering.
/// @custom:governance
// checks: assets[asset.erc20()] == asset
// effects: assets' = assets - {asset.erc20():_} + {asset.erc20(), asset}
Expand Down Expand Up @@ -186,6 +188,13 @@ contract AssetRegistryP1 is ComponentP1, IAssetRegistry {
// effects: assets' = assets.set(asset.erc20(), asset)
// returns: assets[asset.erc20()] != asset
function _registerIgnoringCollisions(IAsset asset) private returns (bool swapped) {
if (asset.isCollateral()) {
akshatmittal marked this conversation as resolved.
Show resolved Hide resolved
require(
ICollateral(address(asset)).status() == CollateralStatus.SOUND,
"collateral not sound"
);
}

IERC20Metadata erc20 = asset.erc20();
if (_erc20s.contains(address(erc20))) {
if (assets[erc20] == asset) return false;
Expand Down
4 changes: 4 additions & 0 deletions contracts/p1/BackingManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ contract BackingManagerP1 is TradingP1, IBackingManager {

/// Settle a single trade. If the caller is the trade, try chaining into rebalance()
/// While this function is not nonReentrant, its two subsets each individually are
/// If the caller is a trade contract, initiate the next trade.
/// This is done in order to better align incentives,
/// and have the last bidder be the one to start the next auction.
/// This behaviour currently only happens for Dutch Trade.
/// @param sell The sell token in the trade
/// @return trade The ITrade contract settled
/// @custom:interaction
Expand Down
1 change: 0 additions & 1 deletion contracts/p1/mixins/Trading.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ abstract contract TradingP1 is Multicall, ComponentP1, ReentrancyGuardUpgradeabl
TradeRequest memory req,
TradePrices memory prices
) internal returns (ITrade trade) {
/* */
IERC20 sell = req.sell.erc20();
assert(address(trades[sell]) == address(0));

Expand Down
5 changes: 2 additions & 3 deletions docs/system-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ Some of the core contracts in our system regularly own ERC20 tokens. In each cas

### RToken Lifecycle

1. During SlowIssuance, the `RToken` transfers collateral tokens from the caller's address into itself.
2. At vesting time, the `RToken` contract mints new RToken to the recipient and transfers the held collateral to the `BackingManager`. If the `BasketHandler` has updated the basket since issuance began, then the collateral is instead returned to the recipient and no RToken is minted.
3. During redemption, RToken is burnt from the redeemer's account and they are transferred a prorata share of backing collateral from the `BackingManager`.
1. During minting, the `RToken` transfers collateral tokens from the caller's address into itself and mints new RToken to the caller's address. Minting amount must be less than the current throttle limit, or the transaction will revert.
2. During redemption, RToken is burnt from the redeemer's account and they are transferred a prorata share of backing collateral from the `BackingManager`.

## Protocol Assumptions

Expand Down
Loading