diff --git a/CHANGELOG.md b/CHANGELOG.md index 5216b53e4..2fed6340a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/contracts/spells/4_3_0.sol b/contracts/spells/4_3_0.sol index d5e6a5df4..7e3fd7125 100644 --- a/contracts/spells/4_3_0.sol +++ b/contracts/spells/4_3_0.sol @@ -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. @@ -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 @@ -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 && @@ -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( diff --git a/docs/deployment-variables.md b/docs/deployment-variables.md index fed0031c0..5f6f1aa02 100644 --- a/docs/deployment-variables.md +++ b/docs/deployment-variables.md @@ -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 diff --git a/tasks/validation/proposals/4_3_0.ts b/tasks/validation/proposals/4_3_0.ts index ea83e3668..b4b1fb839 100644 --- a/tasks/validation/proposals/4_3_0.ts +++ b/tasks/validation/proposals/4_3_0.ts @@ -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 => { // Confirm governor is Anastasius const anastasius = await hre.ethers.getContractAt('Governance', governorAddress) @@ -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' diff --git a/tasks/validation/spells/4.3.0.ts b/tasks/validation/spells/4.3.0.ts index 28bb3f36d..5e1ee3f96 100644 --- a/tasks/validation/spells/4.3.0.ts +++ b/tasks/validation/spells/4.3.0.ts @@ -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[] } = { @@ -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 @@ -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)) ||