From 56fd2817c4e1c73fd442746267b7acd07f91f38a Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Mon, 16 Nov 2026 22:28:56 +0000 Subject: [PATCH 1/5] Set tradingDelay in the 4.3.0 spell 4.3.0 changes what tradingDelay delays: governance basket refreshes now skip it, so it only delays trading after a basket change governance did not make, such as a refresh after a default. castSpell takes a newTradingDelay so each community sets the value for its new meaning in the upgrade proposal. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- contracts/spells/4_3_0.sol | 11 ++++++++++- docs/deployment-variables.md | 4 +++- tasks/validation/proposals/4_3_0.ts | 5 +++-- tasks/validation/spells/4.3.0.ts | 13 ++++++++++++- 5 files changed, 29 insertions(+), 6 deletions(-) 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..663357e8a 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 a basket change that governance did not make, such as a refresh after a default. + * Pass the current value to leave it unchanged. + * * 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 @@ -185,6 +191,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..c51f6f78d 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 a basket change that governance did not make, such as a 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)) || From b5722ddcec54e4c13d2b5e6c8a273d787da863f8 Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Mon, 16 Nov 2026 22:29:28 +0000 Subject: [PATCH 2/5] Require a nonzero newTradingDelay in the 4.3.0 spell A zero delay starts automatic trading as soon as a defaulted basket is replaced, which is most likely a misconfiguration. Co-Authored-By: Claude Opus 5.5 --- contracts/spells/4_3_0.sol | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contracts/spells/4_3_0.sol b/contracts/spells/4_3_0.sol index 663357e8a..b4e68a259 100644 --- a/contracts/spells/4_3_0.sol +++ b/contracts/spells/4_3_0.sol @@ -31,7 +31,8 @@ bytes32 constant MAIN_OWNER_ROLE = bytes32("OWNER"); * 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 a basket change that governance did not make, such as a refresh after a default. - * Pass the current value to leave it unchanged. + * newTradingDelay must be nonzero: with 0, trading starts as soon as a defaulted basket is + * replaced, leaving governance no time to react. That is likely a misconfiguration. * * MAIN_OWNER_ROLE is automatically renounced after casting. Governance is unchanged. * @@ -99,6 +100,7 @@ contract Upgrade4_3_0 is Versioned { /// @param rToken The RToken to upgrade /// @param newTradingDelay {s} The tradingDelay to set on the BackingManager function castSpell(IRToken rToken, uint48 newTradingDelay) external { + require(newTradingDelay != 0, Err(14)); require(keccak256(abi.encodePacked(rToken.version())) == PRIOR_VERSION_HASH, Err(2)); // Can only be cast once per supported RToken From e3e06d406a3d57a77455a777669f10ab2ab148e6 Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Mon, 16 Nov 2026 22:32:48 +0000 Subject: [PATCH 3/5] Require newTradingDelay to be at least the current tradingDelay Co-Authored-By: Claude Opus 5.5 --- contracts/spells/4_3_0.sol | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/contracts/spells/4_3_0.sol b/contracts/spells/4_3_0.sol index b4e68a259..d2c026c4f 100644 --- a/contracts/spells/4_3_0.sol +++ b/contracts/spells/4_3_0.sol @@ -31,8 +31,9 @@ bytes32 constant MAIN_OWNER_ROLE = bytes32("OWNER"); * 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 a basket change that governance did not make, such as a refresh after a default. - * newTradingDelay must be nonzero: with 0, trading starts as soon as a defaulted basket is - * replaced, leaving governance no time to react. That is likely a misconfiguration. + * newTradingDelay must be nonzero and at least the current tradingDelay. The delay should only + * increase, and with 0 trading starts as soon as a defaulted basket is replaced, leaving + * governance no time to react. That is likely a misconfiguration. * * MAIN_OWNER_ROLE is automatically renounced after casting. Governance is unchanged. * @@ -100,7 +101,6 @@ contract Upgrade4_3_0 is Versioned { /// @param rToken The RToken to upgrade /// @param newTradingDelay {s} The tradingDelay to set on the BackingManager function castSpell(IRToken rToken, uint48 newTradingDelay) external { - require(newTradingDelay != 0, Err(14)); require(keccak256(abi.encodePacked(rToken.version())) == PRIOR_VERSION_HASH, Err(2)); // Can only be cast once per supported RToken @@ -139,6 +139,14 @@ contract Upgrade4_3_0 is Versioned { stRSR: main.stRSR() }); + // tradingDelay should only increase, and 0 is likely a misconfiguration + require( + newTradingDelay != 0 && + newTradingDelay >= + TestIBackingManager(address(proxy.backingManager)).tradingDelay(), + Err(14) + ); + // No ongoing trades require( proxy.backingManager.tradesOpen() == 0 && From 1bb84182a87afee73e03812a9e610c9259194f2d Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Mon, 16 Nov 2026 22:37:41 +0000 Subject: [PATCH 4/5] Only require newTradingDelay to be at least the current tradingDelay Co-Authored-By: Claude Opus 5.5 --- contracts/spells/4_3_0.sol | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/contracts/spells/4_3_0.sol b/contracts/spells/4_3_0.sol index d2c026c4f..ac11210f9 100644 --- a/contracts/spells/4_3_0.sol +++ b/contracts/spells/4_3_0.sol @@ -31,9 +31,7 @@ bytes32 constant MAIN_OWNER_ROLE = bytes32("OWNER"); * 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 a basket change that governance did not make, such as a refresh after a default. - * newTradingDelay must be nonzero and at least the current tradingDelay. The delay should only - * increase, and with 0 trading starts as soon as a defaulted basket is replaced, leaving - * governance no time to react. That is likely a misconfiguration. + * newTradingDelay must be at least the current tradingDelay: the delay should only increase. * * MAIN_OWNER_ROLE is automatically renounced after casting. Governance is unchanged. * @@ -139,11 +137,9 @@ contract Upgrade4_3_0 is Versioned { stRSR: main.stRSR() }); - // tradingDelay should only increase, and 0 is likely a misconfiguration + // tradingDelay should only increase require( - newTradingDelay != 0 && - newTradingDelay >= - TestIBackingManager(address(proxy.backingManager)).tradingDelay(), + newTradingDelay >= TestIBackingManager(address(proxy.backingManager)).tradingDelay(), Err(14) ); From 579acfcd1887cee303207fcfec492205f8b5a34a Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Mon, 16 Nov 2026 22:38:50 +0000 Subject: [PATCH 5/5] Describe default-triggered refreshes as emergency basket changes Co-Authored-By: Claude Opus 5.5 --- contracts/spells/4_3_0.sol | 2 +- docs/deployment-variables.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/spells/4_3_0.sol b/contracts/spells/4_3_0.sol index ac11210f9..7e3fd7125 100644 --- a/contracts/spells/4_3_0.sol +++ b/contracts/spells/4_3_0.sol @@ -30,7 +30,7 @@ bytes32 constant MAIN_OWNER_ROLE = bytes32("OWNER"); * * 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 a basket change that governance did not make, such as a refresh after a default. + * 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. diff --git a/docs/deployment-variables.md b/docs/deployment-variables.md index c51f6f78d..5f6f1aa02 100644 --- a/docs/deployment-variables.md +++ b/docs/deployment-variables.md @@ -64,7 +64,7 @@ Reasonable range: 1 to 31536000 Dimension: `{seconds}` -The trading delay is how many seconds should pass after a basket change that governance did not make, such as a 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. +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.