Skip to content
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- Prevent unregistering RSR.
- Document the governance trust assumptions: governance is honest, and the Guardian cancels malicious proposals.
- Compile `BackingManagerP1` with 100 optimizer runs so it stays under the contract size limit.
- Add the `Upgrade4_3_0` spell to upgrade eUSD, ETH+, USD3, and bsdETH from 4.2.0. The spell rotates each RTokenAsset; no other assets are redeployed.
- Add the `Upgrade4_3_0` spell to upgrade eUSD, ETH+, USD3, and bsdETH from 4.2.0. The spell rotates each RTokenAsset; no other assets are redeployed. It also takes a `newTradingDelay` and sets it on the BackingManager, so each community can choose `tradingDelay` for its new meaning.

## Rounding Changes

Expand Down
17 changes: 16 additions & 1 deletion contracts/spells/4_3_0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ bytes32 constant MAIN_OWNER_ROLE = bytes32("OWNER");
*
* The spell rotates the RTokenAsset, keeping its maxTradeVolume. No other assets are changed.
*
* The spell also sets the BackingManager's tradingDelay, because its meaning changes in 4.3.0.
* Before 4.3.0 it delays trading after every basket change. From 4.3.0 it only delays trading
* after an emergency basket change: the permissionless refresh after a collateral default.
* newTradingDelay must be at least the current tradingDelay: the delay should only increase.
*
* MAIN_OWNER_ROLE is automatically renounced after casting. Governance is unchanged.
*
* The spell() function should be called by the timelock owning Main.
Expand Down Expand Up @@ -92,7 +97,8 @@ contract Upgrade4_3_0 is Versioned {
// Cast once-per-rToken. Caller MUST be the timelock owning Main.
/// @dev Requirement: this contract has admin of RToken via MAIN_OWNER_ROLE
/// @param rToken The RToken to upgrade
function castSpell(IRToken rToken) external {
/// @param newTradingDelay {s} The tradingDelay to set on the BackingManager
function castSpell(IRToken rToken, uint48 newTradingDelay) external {
require(keccak256(abi.encodePacked(rToken.version())) == PRIOR_VERSION_HASH, Err(2));

// Can only be cast once per supported RToken
Expand Down Expand Up @@ -131,6 +137,12 @@ contract Upgrade4_3_0 is Versioned {
stRSR: main.stRSR()
});

// tradingDelay should only increase
require(
newTradingDelay >= TestIBackingManager(address(proxy.backingManager)).tradingDelay(),
Err(14)
);

// No ongoing trades
require(
proxy.backingManager.tradesOpen() == 0 &&
Expand Down Expand Up @@ -185,6 +197,9 @@ contract Upgrade4_3_0 is Versioned {
require(proxy.basketHandler.status() == CollateralStatus.SOUND, Err(11));
}

// Set tradingDelay for its 4.3.0 meaning
TestIBackingManager(address(proxy.backingManager)).setTradingDelay(newTradingDelay);

// Rotate RTokenAsset
require(
proxy.assetRegistry.registerNewRTokenAsset(
Expand Down
4 changes: 3 additions & 1 deletion docs/deployment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ Reasonable range: 1 to 31536000

Dimension: `{seconds}`

The trading delay is how many seconds should pass after the basket has been changed before a trade can be opened. In the long term this can be set to 0 after MEV searchers are firmly integrated, but at the start it may be useful to have a delay before trading in order to avoid worst-case prices.
The trading delay is how many seconds should pass after an emergency basket change, the permissionless refresh after a collateral default, before a trade can be opened. Basket changes made by governance skip the delay. A delay gives governance time to choose a better basket before the protocol starts rebalancing on its own. Issuance against the new basket is still allowed during the delay.

Before 4.3.0, the delay applied after every basket change.

Default value: `0` = 0s
Reasonable range: 0 to 604800
Expand Down
5 changes: 3 additions & 2 deletions tasks/validation/proposals/4_3_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export const proposal_4_3_0 = async (
rTokenAddress: string,
governorAddress: string,
timelockAddress: string,
spellAddress: string
spellAddress: string,
newTradingDelay: number // {s}
): Promise<Proposal> => {
// Confirm governor is Anastasius
const anastasius = await hre.ethers.getContractAt('Governance', governorAddress)
Expand Down Expand Up @@ -65,7 +66,7 @@ export const proposal_4_3_0 = async (
// Build proposal
txs.push(
await main.populateTransaction.grantRole(MAIN_OWNER_ROLE, spell.address),
await spell.populateTransaction.castSpell(rTokenAddress)
await spell.populateTransaction.castSpell(rTokenAddress, newTradingDelay)
)

const description = '4.3.0 Upgrade - Core Contracts'
Expand Down
13 changes: 12 additions & 1 deletion tasks/validation/spells/4.3.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import { Upgrade4_3_0 } from '#/typechain'
const VERSION_4_3_0_HASH = '0xdef94dbdd8411ae515cefcb56b153df454453010a1f4c881b3daa7ed18db793a'
const DEFAULT_ADMIN_ROLE = '0x0000000000000000000000000000000000000000000000000000000000000000'

// Test value, to check the spell sets it. Each community chooses its own.
const NEW_TRADING_DELAY = 86400 // {s} 1 day

// RTokenAssets that integrations read directly instead of looking up in the AssetRegistry.
// They must keep pricing correctly after the upgrade.
const PINNED_RTOKEN_ASSETS: { [rToken: string]: string[] } = {
Expand Down Expand Up @@ -181,7 +184,8 @@ task('4.3.0', 'Upgrade to 4.3.0').setAction(async (_, hre) => {
deployment.rToken,
anastasius.address,
deployment.timelock,
spell.address
spell.address,
NEW_TRADING_DELAY
)
result.rtoken = deployment.rToken
result.governor = anastasius.address
Expand Down Expand Up @@ -225,6 +229,13 @@ task('4.3.0', 'Upgrade to 4.3.0').setAction(async (_, hre) => {
throw new Error('basket changed during upgrade')
}
if (await basketHandler.tradingDelayBypassed()) throw new Error('trading delay bypassed')
const backingManager = await hre.ethers.getContractAt(
'BackingManagerP1',
await main.backingManager()
)
if ((await backingManager.tradingDelay()) != NEW_TRADING_DELAY) {
throw new Error('tradingDelay not set')
}

if (
(await main.hasRole(MAIN_OWNER_ROLE, spell.address)) ||
Expand Down
Loading