-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1219 from reserve-protocol/registry-deployer
Add Registry Setup & Basket Normalization Spell
- Loading branch information
Showing
31 changed files
with
708 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
interface IRegistries { | ||
roleRegistry: string | ||
versionRegistry: string | ||
assetPluginRegistry: string | ||
daoFeeRegistry: string | ||
} | ||
|
||
interface IRegistryControl { | ||
owner: string | ||
feeRecipient: string | ||
} | ||
|
||
export interface RegistryChainRecord { | ||
registries: IRegistries | ||
registryControl: IRegistryControl | ||
} | ||
|
||
export const registryConfig: Record<string, RegistryChainRecord> = { | ||
'1': { | ||
registryControl: { | ||
owner: '0x0000000000000000000000000000000000000123', | ||
feeRecipient: '0x0000000000000000000000000000000000000123', | ||
}, | ||
registries: { | ||
roleRegistry: '', | ||
versionRegistry: '', | ||
assetPluginRegistry: '', | ||
daoFeeRegistry: '', | ||
}, | ||
}, | ||
} | ||
|
||
registryConfig['31337'] = registryConfig['1'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: BlueOak-1.0.0 | ||
pragma solidity 0.8.19; | ||
|
||
import "../p1/mixins/BasketLib.sol"; | ||
import "../p1/BasketHandler.sol"; | ||
import "../p1/Main.sol"; | ||
import "../interfaces/IDeployer.sol"; | ||
import "../interfaces/IMain.sol"; | ||
import "../p1/Deployer.sol"; | ||
|
||
/** | ||
* This spell is used by reweightable RTokens with rev 4.0.0 or later. | ||
* | ||
* This allows governance to normalize the basket by price at the time of setting it in place, | ||
* effectively allowing for a basket that is continous in USD terms. | ||
* | ||
* Before casting `setNormalizedBasket` function this contract must have `MAIN_OWNER_ROLE` of Main, | ||
* and should also revoke the said role at the end of the transaction. | ||
* | ||
* The spell function should be called by the timelock owning Main. Governance should NOT | ||
* grant this spell ownership without immediately executing the spell function after. | ||
*/ | ||
contract SpellBasketNormalizer { | ||
function setNormalizedBasket( | ||
IRToken rToken, | ||
IERC20[] calldata erc20s, | ||
uint192[] calldata targetAmts | ||
) external { | ||
require(erc20s.length == targetAmts.length, "SBN: mismatch"); | ||
|
||
MainP1 main = MainP1(address(rToken.main())); | ||
IAssetRegistry assetRegistry = main.assetRegistry(); | ||
IBasketHandler basketHandler = main.basketHandler(); | ||
|
||
require(BasketHandlerP1(address(basketHandler)).reweightable(), "SBN: reweightable"); | ||
|
||
assetRegistry.refresh(); | ||
(uint192 low, uint192 high) = basketHandler.price(false); | ||
|
||
uint192[] memory newTargetAmts = BasketLibP1.normalizeByPrice( | ||
assetRegistry, | ||
erc20s, | ||
targetAmts, | ||
(low + high + 1) / 2 | ||
); | ||
|
||
basketHandler.forceSetPrimeBasket(erc20s, newTargetAmts); | ||
|
||
main.revokeRole(main.OWNER_ROLE(), address(this)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Reweightable RTokens | ||
|
||
The protocol includes a flag to enable reweightable baskets for RTokens. This flag can only be set at the time of deployment and enables certain additional capabilities for the RToken while disabling others. | ||
|
||
In simple terms, a reweightable RToken can change the target units. For example, if an RToken is configured as 1 ETH + 1 BTC in the basket, only the reweightable RTokens can change it to something like 1 ETH + 1 BTC + 100 USD. | ||
|
||
In most cases, a non-reweightable RToken will suffice, we expect that to be 99% of all RTokens that exist. However, there are specific cases where you'd want to have reweightable RTokens such as ETFs. | ||
|
||
## Basket Normalization | ||
|
||
In reweightable RTokens, it's not a guarantee that during a basket change the USD value of the basket remains continuous at the time of the switch. You can easily see this property when, say, a basket switches from being 1 ETH to 1 ETH + 100 USD. The USD value of the basket will increase in this case, but the protocol doesn't have the extra funds (unless it seizes from the stRSR staking pool). | ||
|
||
To enable this functionality and to allow governance to make sure that the set baskets can keep the same price at the time of the switch, a spell `SpellBasketNormalizer` is provided in the spells directory. This spell can be used to set the basket in such a way that the USD value of the basket remains the same at the time of the switch. | ||
|
||
In order to use the spell, you must create a governance proposal granting the spell contract the `OWNER` role on the RToken then calling the `setNormalizedBasket` basket on the spell contract with appropriate parameters. See the `BasketNormalization` scenario test in the `test` directory for an example of how to use the spell. |
Oops, something went wrong.