From 6bd4427158a016d4098741ac21de0b360713031c Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Fri, 6 Nov 2026 18:20:03 +0000 Subject: [PATCH 1/5] 4.3.0 upgrade spell Add Upgrade4_3_0 for eUSD, ETH+, USD3, and bsdETH on 4.2.0. The spell upgrades through the DAO VersionRegistry, validates that all assets are supported for 4.3.0, and keeps the existing governance. Add the 4.3.0 fork validation task and proposal builder, point the validation constants at the current governance, and refresh stale whales. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + contracts/spells/4_3_0.sol | 206 +++++++++++++++++++++ tasks/index.ts | 1 + tasks/validation/proposals/4_3_0.ts | 74 ++++++++ tasks/validation/spells/4.3.0.ts | 218 +++++++++++++++++++++++ tasks/validation/utils/constants.ts | 16 +- tasks/validation/whales/whales_1.json | 8 +- tasks/validation/whales/whales_8453.json | 4 +- 8 files changed, 514 insertions(+), 14 deletions(-) create mode 100644 contracts/spells/4_3_0.sol create mode 100644 tasks/validation/proposals/4_3_0.ts create mode 100644 tasks/validation/spells/4.3.0.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 75f41f29f..db5065420 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +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. # 4.2.0 diff --git a/contracts/spells/4_3_0.sol b/contracts/spells/4_3_0.sol new file mode 100644 index 000000000..86aa7019a --- /dev/null +++ b/contracts/spells/4_3_0.sol @@ -0,0 +1,206 @@ +// SPDX-License-Identifier: BlueOak-1.0.0 +pragma solidity 0.8.28; + +import "../interfaces/IDeployer.sol"; +import "../mixins/Versioned.sol"; +import "../p1/Main.sol"; + +bytes32 constant MAIN_OWNER_ROLE = bytes32("OWNER"); + +/** + * The upgrade spell for the 4.3.0 release. Upgrading RToken must be on 4.2.0. + * + * Supported RTokens: + * Mainnet: + * - eUSD + * - ETH+ + * - USD3 + * Base: + * - bsdETH + * + * The spell can only be cast once per RToken. + * + * Before casting the spell: + * - the 4.3.0 deployer must be registered in the VersionRegistry + * - all currently registered assets must be valid for 4.3.0 in the AssetPluginRegistry; + * deprecated assets must be unregistered first + * - this contract must have MAIN_OWNER_ROLE of Main + * + * MAIN_OWNER_ROLE is automatically renounced after casting. Governance is unchanged. + * + * The spell() function should be called by the timelock owning Main. + * + */ +contract Upgrade4_3_0 is Versioned { + error Err(uint256 index); + + bytes32 public constant PRIOR_VERSION_HASH = keccak256(abi.encodePacked("4.2.0")); + bytes32 public constant NEW_VERSION_HASH = keccak256(abi.encodePacked("4.3.0")); + + // ======================================================================================= + + IDeployer.Registries public registries; + + IDeployer public deployer; + + // RToken => bool + mapping(IRToken => bool) public supported; + + bool public mainnet; // !mainnet | base + + // ======================================================================================= + + constructor(bool _mainnet) { + // we have to pass-in `_mainnet` because chainid is not reliable during testing + require(block.chainid == 1 || block.chainid == 31337 || block.chainid == 8453, Err(0)); + mainnet = _mainnet; + + if (_mainnet) { + // DAO registries (mainnet) + registries = IDeployer.Registries( + VersionRegistry(0xB031D7742367B92CcBEd0653B9a6341EFa47dd04), + AssetPluginRegistry(0x15A9e0CF2Fd9842B99E015E05073b5F0f58A1C29), + DAOFeeRegistry(0xec716deD4eABa060937D1a915F166E237039342B), + ITrustedFillerRegistry(0x279ccF56441fC74f1aAC39E7faC165Dec5A88B3A) + ); + + // Setup `supported` + supported[IRToken(0xA0d69E286B938e21CBf7E51D71F6A4c8918f482F)] = true; // eUSD + supported[IRToken(0xE72B141DF173b999AE7c1aDcbF60Cc9833Ce56a8)] = true; // ETH+ + supported[IRToken(0x0d86883FAf4FfD7aEb116390af37746F45b6f378)] = true; // USD3 + } else { + // DAO registries (base) + registries = IDeployer.Registries( + VersionRegistry(0xbD769ea5E93A4B232Cee08ED4C2a67Ff5Ba692Df), + AssetPluginRegistry(0x093c07787920eB34A0A0c7a09823510725Aee4Af), + DAOFeeRegistry(0x3513D2c7D2F51c678889CeC083E7D7Ae27b219aD), + ITrustedFillerRegistry(0x72DB5f49D0599C314E2f2FEDf6Fe33E1bA6C7A18) + ); + + // Setup `supported` + supported[IRToken(0xCb327b99fF831bF8223cCEd12B1338FF3aA322Ff)] = true; // bsdETH + } + + // 4.3.0 deployer, pinned from the VersionRegistry + deployer = registries.versionRegistry.deployments(NEW_VERSION_HASH); + require(address(deployer) != address(0), Err(1)); + require(keccak256(abi.encodePacked(deployer.version())) == NEW_VERSION_HASH, Err(1)); + } + + // 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 { + require(keccak256(abi.encodePacked(rToken.version())) == PRIOR_VERSION_HASH, Err(2)); + + // Can only be cast once per supported RToken + require(supported[rToken], Err(3)); + supported[rToken] = false; + + // validate caller is timelock + MainP1 main = MainP1(address(rToken.main())); + require( + main.hasRole(MAIN_OWNER_ROLE, msg.sender) && // security crux + main.hasRole(MAIN_OWNER_ROLE, address(this)), + Err(3) + ); + + // Registries should already be set to the DAO registries + require( + main.versionRegistry() == registries.versionRegistry && + main.assetPluginRegistry() == registries.assetPluginRegistry && + main.daoFeeRegistry() == registries.daoFeeRegistry, + Err(4) + ); + + // 4.3.0 should not have been deprecated since construction + require(!registries.versionRegistry.isDeprecated(NEW_VERSION_HASH), Err(5)); + + Components memory proxy = Components({ + assetRegistry: main.assetRegistry(), + basketHandler: main.basketHandler(), + backingManager: main.backingManager(), + broker: main.broker(), + distributor: main.distributor(), + furnace: main.furnace(), + rToken: rToken, + rTokenTrader: main.rTokenTrader(), + rsrTrader: main.rsrTrader(), + stRSR: main.stRSR() + }); + + // No ongoing trades + require( + proxy.backingManager.tradesOpen() == 0 && + proxy.rTokenTrader.tradesOpen() == 0 && + proxy.rsrTrader.tradesOpen() == 0, + Err(6) + ); + + // Main + Component upgrades + { + // Upgrade Main + main.upgradeMainTo(NEW_VERSION_HASH); + require(keccak256(abi.encodePacked(main.version())) == NEW_VERSION_HASH, Err(7)); + + // Upgrade components, validating all assets are supported for 4.3.0 afterwards + main.upgradeRTokenTo(NEW_VERSION_HASH, false, true); + + // Verify all components are upgraded + require( + keccak256(abi.encodePacked(proxy.assetRegistry.version())) == NEW_VERSION_HASH && + keccak256(abi.encodePacked(proxy.basketHandler.version())) == + NEW_VERSION_HASH && + keccak256(abi.encodePacked(proxy.backingManager.version())) == + NEW_VERSION_HASH && + keccak256(abi.encodePacked(proxy.broker.version())) == NEW_VERSION_HASH && + keccak256(abi.encodePacked(proxy.distributor.version())) == NEW_VERSION_HASH && + keccak256(abi.encodePacked(proxy.furnace.version())) == NEW_VERSION_HASH && + keccak256(abi.encodePacked(proxy.rToken.version())) == NEW_VERSION_HASH && + keccak256(abi.encodePacked(proxy.rTokenTrader.version())) == NEW_VERSION_HASH && + keccak256(abi.encodePacked(proxy.rsrTrader.version())) == NEW_VERSION_HASH && + keccak256(abi.encodePacked(proxy.stRSR.version())) == NEW_VERSION_HASH, + Err(8) + ); + + // Verify trading plugins are updated + Implementations memory impls = deployer.implementations(); + require( + address(TestIBroker(address(proxy.broker)).dutchTradeImplementation()) == + address(impls.trading.dutchTrade) && + address(TestIBroker(address(proxy.broker)).batchTradeImplementation()) == + address(impls.trading.gnosisTrade), + Err(9) + ); + } + + // Basket checks + { + // New storage slot should start unset: the trading delay applies to the current basket + require(!proxy.basketHandler.tradingDelayBypassed(), Err(10)); + + proxy.assetRegistry.refresh(); + require(proxy.basketHandler.status() == CollateralStatus.SOUND, Err(11)); + } + + // Rotate RTokenAsset + require( + proxy.assetRegistry.registerNewRTokenAsset( + proxy.assetRegistry.toAsset(IERC20(address(rToken))).maxTradeVolume() + ), + Err(12) + ); + + // Renounce adminship and validate final state + { + main.renounceRole(MAIN_OWNER_ROLE, address(this)); + + require( + main.hasRole(MAIN_OWNER_ROLE, msg.sender) && + !main.hasRole(MAIN_OWNER_ROLE, address(this)) && + !main.hasRole(MAIN_OWNER_ROLE, address(main)), + Err(13) + ); + } + } +} diff --git a/tasks/index.ts b/tasks/index.ts index 6f1853561..2f755643e 100644 --- a/tasks/index.ts +++ b/tasks/index.ts @@ -31,3 +31,4 @@ import './validation/mint-tokens' import './validation/proposal-validator' import './validation/spells/3.4.0' import './validation/spells/4.2.0' +import './validation/spells/4.3.0' diff --git a/tasks/validation/proposals/4_3_0.ts b/tasks/validation/proposals/4_3_0.ts new file mode 100644 index 000000000..ea83e3668 --- /dev/null +++ b/tasks/validation/proposals/4_3_0.ts @@ -0,0 +1,74 @@ +import { HardhatRuntimeEnvironment } from 'hardhat/types' +import { buildProposal } from '../utils/governance' +import { Proposal } from '#/utils/subgraph' +import { MAIN_OWNER_ROLE, EXECUTOR_ROLE, PROPOSER_ROLE } from './4_2_0' + +export const proposal_4_3_0 = async ( + hre: HardhatRuntimeEnvironment, + rTokenAddress: string, + governorAddress: string, + timelockAddress: string, + spellAddress: string +): Promise => { + // Confirm governor is Anastasius + const anastasius = await hre.ethers.getContractAt('Governance', governorAddress) + const name = await anastasius.name() + console.log('name', name) + + if (name !== 'Governor Anastasius') { + throw new Error('Governor Anastasius only') + } + + // Validate timelock is controlled by governance + if (!timelockAddress) throw new Error('missing timelockAddress') + const timelock = await hre.ethers.getContractAt('TimelockController', timelockAddress) + if (!(await timelock.hasRole(EXECUTOR_ROLE, governorAddress))) + throw new Error('missing EXECUTOR_ROLE') + if (!(await timelock.hasRole(PROPOSER_ROLE, governorAddress))) + throw new Error('missing PROPOSER_ROLE') + + const rToken = await hre.ethers.getContractAt('RTokenP1', rTokenAddress) + const main = await hre.ethers.getContractAt('MainP1', await rToken.main()) + if (!(await main.hasRole(MAIN_OWNER_ROLE, timelockAddress))) { + throw new Error('timelock does not own Main') + } + const spell = await hre.ethers.getContractAt('Upgrade4_3_0', spellAddress) + + const assetRegistry = await hre.ethers.getContractAt( + 'AssetRegistryP1', + await main.assetRegistry() + ) + const assetPluginRegistry = await hre.ethers.getContractAt( + 'AssetPluginRegistry', + await main.assetPluginRegistry() + ) + const basketHandler = await hre.ethers.getContractAt( + 'BasketHandlerP1', + await main.basketHandler() + ) + const [primeERC20s] = await basketHandler.getPrimeBasket() + + // Unregister deprecated assets, which would fail the spell's asset validation + const txs = [] + const [erc20s, assets] = await assetRegistry.getRegistry() + for (let i = 0; i < assets.length; i++) { + if (!(await assetPluginRegistry.isDeprecated(assets[i]))) continue + + if (primeERC20s.includes(erc20s[i]) || (await basketHandler.quantity(erc20s[i])).gt(0)) { + throw new Error(`deprecated asset ${assets[i]} is in the basket`) + } + + console.log(`Unregistering deprecated asset ${assets[i]}`) + txs.push(await assetRegistry.populateTransaction.unregister(assets[i])) + } + + // Build proposal + txs.push( + await main.populateTransaction.grantRole(MAIN_OWNER_ROLE, spell.address), + await spell.populateTransaction.castSpell(rTokenAddress) + ) + + const description = '4.3.0 Upgrade - Core Contracts' + + return buildProposal(txs, description) +} diff --git a/tasks/validation/spells/4.3.0.ts b/tasks/validation/spells/4.3.0.ts new file mode 100644 index 000000000..2f2b2d85b --- /dev/null +++ b/tasks/validation/spells/4.3.0.ts @@ -0,0 +1,218 @@ +import fs from 'fs' +import { task } from 'hardhat/config' +import { HardhatRuntimeEnvironment } from 'hardhat/types' +import { BigNumber } from 'ethers' +import { useEnv } from '#/utils/env' +import { advanceTime, getLatestBlockTimestamp } from '#/utils/time' +import { whileImpersonating } from '#/utils/impersonation' +import { BASE_DEPLOYMENTS, MAINNET_DEPLOYMENTS, RTokenDeployment } from '../utils/constants' +import { resetFork } from '#/utils/chain' +import { MAIN_OWNER_ROLE } from '../proposals/4_2_0' +import { proposal_4_3_0 } from '../proposals/4_3_0' +import { Upgrade4_3_0 } from '#/typechain' + +const VERSION_4_3_0_HASH = '0xdef94dbdd8411ae515cefcb56b153df454453010a1f4c881b3daa7ed18db793a' +const DEFAULT_ADMIN_ROLE = '0x0000000000000000000000000000000000000000000000000000000000000000' + +// TODO remove after 4.3.0 is deployed, registered, and its assets are whitelisted +// Deploys + registers 4.3.0, whitelists the RToken's current assets for 4.3.0, and +// settles any open trades, which would otherwise block the spell +const setup_4_3_0 = async (hre: HardhatRuntimeEnvironment, deployment: RTokenDeployment) => { + const rToken = await hre.ethers.getContractAt('RTokenP1', deployment.rToken) + const main = await hre.ethers.getContractAt('MainP1', await rToken.main()) + const versionRegistry = await hre.ethers.getContractAt( + 'VersionRegistry', + await main.versionRegistry() + ) + const assetPluginRegistry = await hre.ethers.getContractAt( + 'AssetPluginRegistry', + await main.assetPluginRegistry() + ) + const roleRegistry = await hre.ethers.getContractAt( + 'RoleRegistry', + await versionRegistry.roleRegistry() + ) + const registryOwner = await roleRegistry.getRoleMember(DEFAULT_ADMIN_ROLE, 0) + + // Deploy + register 4.3.0 + if ((await versionRegistry.deployments(VERSION_4_3_0_HASH)) == hre.ethers.constants.AddressZero) { + const priorDeployer = await hre.ethers.getContractAt( + 'DeployerP1', + await versionRegistry.deployments( + hre.ethers.utils.keccak256(hre.ethers.utils.toUtf8Bytes(await rToken.version())) + ) + ) + const broker = await hre.ethers.getContractAt('BrokerP1', await main.broker()) + const priorGnosisTrade = await hre.ethers.getContractAt( + 'GnosisTrade', + await broker.batchTradeImplementation() + ) + + const tradingLib = await ( + await hre.ethers.getContractFactory('RecollateralizationLibP1') + ).deploy() + const basketLib = await (await hre.ethers.getContractFactory('BasketLibP1')).deploy() + const deployImpl = async (name: string, libraries = {}, args: unknown[] = []) => + (await (await hre.ethers.getContractFactory(name, { libraries })).deploy(...args)).address + + const revenueTrader = await deployImpl('RevenueTraderP1') + const implementations = { + main: await deployImpl('MainP1'), + components: { + assetRegistry: await deployImpl('AssetRegistryP1'), + basketHandler: await deployImpl('BasketHandlerP1', { BasketLibP1: basketLib.address }), + distributor: await deployImpl('DistributorP1'), + broker: await deployImpl('BrokerP1'), + backingManager: await deployImpl('BackingManagerP1', { + RecollateralizationLibP1: tradingLib.address, + }), + furnace: await deployImpl('FurnaceP1'), + rToken: await deployImpl('RTokenP1'), + rsrTrader: revenueTrader, + rTokenTrader: revenueTrader, + stRSR: await deployImpl('StRSRP1Votes'), + }, + trading: { + gnosisTrade: await deployImpl('GnosisTrade', {}, [await priorGnosisTrade.gnosis()]), + dutchTrade: await deployImpl('DutchTrade'), + }, + } + + const deployer = await ( + await hre.ethers.getContractFactory('DeployerP1') + ).deploy(await priorDeployer.rsr(), await priorDeployer.rsrAsset(), implementations) + await deployer.deployed() + + await whileImpersonating(hre, registryOwner, async (signer) => { + await versionRegistry.connect(signer).registerVersion(deployer.address) + }) + console.log(`Registered 4.3.0 deployer: ${deployer.address}`) + } + + // Whitelist the RToken's current assets for 4.3.0 + const assetRegistry = await hre.ethers.getContractAt( + 'AssetRegistryP1', + await main.assetRegistry() + ) + const [erc20s, assets] = await assetRegistry.getRegistry() + const toWhitelist: string[] = [] + for (let i = 0; i < assets.length; i++) { + if (erc20s[i] == rToken.address) continue + if (await assetPluginRegistry.isDeprecated(assets[i])) continue // unregistered by proposal + if (!(await assetPluginRegistry.isValidAsset(VERSION_4_3_0_HASH, assets[i]))) { + toWhitelist.push(assets[i]) + } + } + if (toWhitelist.length > 0) { + await whileImpersonating(hre, registryOwner, async (signer) => { + await assetPluginRegistry.connect(signer).updateAssetsByVersion( + VERSION_4_3_0_HASH, + toWhitelist, + toWhitelist.map(() => true) + ) + }) + console.log(`Whitelisted ${toWhitelist.length} assets for 4.3.0`) + } + + // Settle open trades, which would finish before the proposal executes + for (const traderAddr of [ + await main.backingManager(), + await main.rTokenTrader(), + await main.rsrTrader(), + ]) { + const trader = await hre.ethers.getContractAt('ITrading', traderAddr) + if ((await trader.tradesOpen()) == 0) continue + + for (const erc20 of erc20s) { + const tradeAddr = await trader.trades(erc20) + if (tradeAddr == hre.ethers.constants.AddressZero) continue + + const trade = await hre.ethers.getContractAt('ITrade', tradeAddr) + const toAdvance = (await trade.endTime()) - (await getLatestBlockTimestamp(hre)) + 1 + if (toAdvance > 0) await advanceTime(hre, toAdvance) + await trader.settleTrade(erc20) + console.log(`Settled open trade ${tradeAddr}`) + } + } +} + +// Use this once to serialize a proposal +task('4.3.0', 'Upgrade to 4.3.0').setAction(async (_, hre) => { + const network = useEnv('FORK_NETWORK').toLowerCase() + const block = useEnv('FORK_BLOCK') + + const deployments = network === 'base' ? BASE_DEPLOYMENTS : MAINNET_DEPLOYMENTS + for (const deployment of deployments) { + // reset fork + await resetFork(hre, Number(block)) + + const rToken = await hre.ethers.getContractAt('RTokenP1', deployment.rToken) + if ((await rToken.version()) != '4.2.0') { + console.log(`\nSkipping ${await rToken.symbol()}: not on 4.2.0`) + continue + } + + console.log( + '\n', + `/***** 4.3.0 Upgrade - RToken: ${await rToken.symbol()} - Address: ${rToken.address} ****/` + ) + + await setup_4_3_0(hre, deployment) + + // TODO remove and replace with canonical spell address after deployment + let spell: Upgrade4_3_0 + { + const UpgradeFactory = await hre.ethers.getContractFactory('Upgrade4_3_0') + spell = await UpgradeFactory.deploy(network !== 'base') + await spell.deployed() + } + + const anastasius = await hre.ethers.getContractAt('Governance', deployment.governor) + const result = await proposal_4_3_0( + hre, + deployment.rToken, + anastasius.address, + deployment.timelock, + spell.address + ) + result.rtoken = deployment.rToken + result.governor = anastasius.address + result.timelock = deployment.timelock + + const descHash = hre.ethers.utils.keccak256(hre.ethers.utils.toUtf8Bytes(result.description)) + result.proposalId = BigNumber.from( + await anastasius.hashProposal(result.targets, result.values, result.calldatas, descHash) + ).toString() + + fs.writeFileSync( + `./tasks/validation/proposals/proposal-${result.proposalId}.json`, + JSON.stringify(result, null, 4) + ) + + await hre.run('proposal-validator', { + proposalid: result.proposalId, + }) + + const main = await hre.ethers.getContractAt('IMain', await rToken.main()) + if ( + (await main.hasRole(MAIN_OWNER_ROLE, spell.address)) || + !(await main.hasRole(MAIN_OWNER_ROLE, deployment.timelock)) + ) { + throw new Error('RToken rekt') + } + if ((await rToken.version()) != '4.3.0') throw new Error('Failed to upgrade to 4.3.0') + + // All registered collateral should be SOUND + const assetRegistry = await hre.ethers.getContractAt( + 'AssetRegistryP1', + await main.assetRegistry() + ) + const [, assets] = await assetRegistry.getRegistry() + for (const asset of assets) { + const coll = await hre.ethers.getContractAt('ICollateral', asset) + if ((await coll.isCollateral()) && (await coll.status()) != 0) { + throw new Error(`coll ${coll.address} is not SOUND: ${await coll.status()}`) + } + } + } +}) diff --git a/tasks/validation/utils/constants.ts b/tasks/validation/utils/constants.ts index f3cc79405..944d98eab 100644 --- a/tasks/validation/utils/constants.ts +++ b/tasks/validation/utils/constants.ts @@ -60,13 +60,13 @@ export interface RTokenDeployment { export const MAINNET_DEPLOYMENTS: RTokenDeployment[] = [ { rToken: '0xA0d69E286B938e21CBf7E51D71F6A4c8918f482F', // eUSD - governor: '0xf4A9288D5dEb0EaE987e5926795094BF6f4662F8', - timelock: '0x7BEa807798313fE8F557780dBD6b829c1E3aD560', + governor: '0x96dC1C14D3D5e2dDAa52368aDfe6E6b20b976832', + timelock: '0xd979Cf15F7275a3DF838513aB911587d23b6D29e', }, { rToken: '0xE72B141DF173b999AE7c1aDcbF60Cc9833Ce56a8', // ETH+ - governor: '0x868Fe81C276d730A1995Dc84b642E795dFb8F753', - timelock: '0x5d8A7DC9405F08F14541BA918c1Bf7eb2dACE556', + governor: '0xA8a608B9b558235E7f87d7024CC05E6f47d62022', + timelock: '0xD7985A7C617fEbc4A833b5F70CFa79b40C313ad2', oracle: { address: '0xf87d2F4d42856f0B6Eae140Aaf78bF0F777e9936', threshold: 0.5, @@ -79,8 +79,8 @@ export const MAINNET_DEPLOYMENTS: RTokenDeployment[] = [ },*/ { rToken: '0x0d86883FAf4FfD7aEb116390af37746F45b6f378', // USD3 - governor: '0x441808e20E625e0094b01B40F84af89436229279', - timelock: '0x12e4F043c6464984A45173E0444105058b6C3c7B', + governor: '0xd895a5D391fc09F12e8C8D57CfDe5c59BFBE2FA7', + timelock: '0x848b923b5d99d5963608Ff55AcDFee51C443Cca6', }, // { // rToken: '0x005f893ecd7bf9667195642f7649da8163e23658', // dgnETH @@ -97,8 +97,8 @@ export const BASE_DEPLOYMENTS: RTokenDeployment[] = [ }, { rToken: '0xCb327b99fF831bF8223cCEd12B1338FF3aA322Ff', // bsdETH - governor: '0x21fBa52dA03e1F964fa521532f8B8951fC212055', - timelock: '0xe664d294824C2A8C952A10c4034e1105d2907F46', + governor: '0xD56f09e158c9c3e1dE8D598e4E1Bc7E4fF29dfC8', + timelock: '0x06c3d55d72c9ae4f167e512C1bE28d6f9d9e6bB9', oracle: { address: '0xD41310aCF5fA54CDd1970155ac32D708B376Dff6', threshold: 1.25, // Higher threshold to account for melting and time elapsed diff --git a/tasks/validation/whales/whales_1.json b/tasks/validation/whales/whales_1.json index a80da5611..9696e75cd 100644 --- a/tasks/validation/whales/whales_1.json +++ b/tasks/validation/whales/whales_1.json @@ -62,10 +62,10 @@ "0x7ca00559b978cfde81297849be6151d3ccb408a9": "0x7578F31CC44fDF2f123A6f84c42f702f9C990091", "0x6c3ea9036406852006290770bedfcaba0e23a0e8": "0xE25a329d385f77df5D4eD56265babe2b99A5436e", "0x0c0d01abf3e6adfca0989ebba9d6e85dd58eab1e": "0x7E4B4DC22111B84594d9b7707A8DCFFd793D477A", - "0xe72b141df173b999ae7c1adcbf60cc9833ce56a8": "0x778aC5d0EE062502fADaa2d300a51dE0869f7995", + "0xe72b141df173b999ae7c1adcbf60cc9833ce56a8": "0x2c683fAd51da2cd17793219CC86439C1875c353e", "0xacdf0dba4b9839b96221a8487e9ca660a48212be": "0xB912549A2b525cC35F8Ba14813112C81cf79F624", "0xfc0b1eef20e4c68b3dcf36c4537cfa7ce46ca70b": "0xF2B25362a03f6EACCa8De8d5350A9f37944c1e59", - "0x0d86883faf4ffd7aeb116390af37746f45b6f378": "0xC6625129C9df3314a4dd604845488f4bA62F9dB8", + "0x0d86883faf4ffd7aeb116390af37746f45b6f378": "0xE99810Cd5AdCD7b13455aE1BE678B382d61f2d1E", "0x78da5799cf427fee11e9996982f4150ece7a99a7": "0x3154Cf16ccdb4C6d922629664174b904d80F2C35", "0x73968b9a57c6e53d41345fd57a6e6ae27d6cdb2f": "0x0C30476f66034E11782938DF8e4384970B6c9e8a", "0x48c3399719b582dd63eb5aadf12a40b4c3f52fa2": "0xF0d99D5d1D5E06CdAd4766503Cb82213B5E1d1bE", @@ -149,10 +149,10 @@ "0x7ca00559b978cfde81297849be6151d3ccb408a9": "2024-09-23T20:24:15.495Z", "0x6c3ea9036406852006290770bedfcaba0e23a0e8": "2024-09-23T20:24:15.726Z", "0x0c0d01abf3e6adfca0989ebba9d6e85dd58eab1e": "2024-09-23T20:24:16.864Z", - "0xe72b141df173b999ae7c1adcbf60cc9833ce56a8": "2024-09-23T20:24:18.214Z", + "0xe72b141df173b999ae7c1adcbf60cc9833ce56a8": "2026-11-06T00:00:00.000Z", "0xacdf0dba4b9839b96221a8487e9ca660a48212be": "2024-09-23T20:24:18.333Z", "0xfc0b1eef20e4c68b3dcf36c4537cfa7ce46ca70b": "2024-09-23T20:24:18.486Z", - "0x0d86883faf4ffd7aeb116390af37746f45b6f378": "2024-09-23T20:24:18.609Z", + "0x0d86883faf4ffd7aeb116390af37746f45b6f378": "2026-11-06T00:00:00.000Z", "0x78da5799cf427fee11e9996982f4150ece7a99a7": "2024-09-23T20:24:18.759Z", "0x73968b9a57c6e53d41345fd57a6e6ae27d6cdb2f": "2024-09-23T20:24:10.034Z", "0x48c3399719b582dd63eb5aadf12a40b4c3f52fa2": "2024-09-23T20:24:15.172Z", diff --git a/tasks/validation/whales/whales_8453.json b/tasks/validation/whales/whales_8453.json index f8189ed1e..67d22660c 100644 --- a/tasks/validation/whales/whales_8453.json +++ b/tasks/validation/whales/whales_8453.json @@ -3,7 +3,7 @@ "0x50c5725949a6f0c72e6c4a641f24049a917db0cb": "0x73b06d8d18de422e269645eace15400de7462417", "0xd9aaec86b65d86f6a7b5b1b0c42ffa531710b6ca": "0x0b25c51637c43decd6cc1c1e3da4518d54ddb528", "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913": "0x7c41fdced2ea646ed85665d1a9b28e6632b61c41", - "0xab36452dbac151be02b16ca17d8919826072f64a": "0xD552F527217f4Fcf381e5c2a472951ffb0fA3BE1", + "0xab36452dbac151be02b16ca17d8919826072f64a": "0x3D4409cd481F270F52e420C89fd2944315c6d72b", "0x9e1028f5f1d5ede59748ffcee5532509976840e0": "0x123964802e6ababbe1bc9547d72ef1b69b00a6b1", "0x4200000000000000000000000000000000000006": "0xcdac0d6c6c59727a65f871236188350531885c43", "0x2ae3f1ec7f1f5012cfeab0185bfc7aa3cf0dec22": "0x3bf93770f2d4a794c3d9ebefbaebae2a8f09a5e5", @@ -34,7 +34,7 @@ "0x50c5725949a6f0c72e6c4a641f24049a917db0cb": "2024-05-02T02:08:54.913Z", "0xd9aaec86b65d86f6a7b5b1b0c42ffa531710b6ca": "2024-05-02T02:09:09.449Z", "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913": "2024-05-02T02:09:20.185Z", - "0xab36452dbac151be02b16ca17d8919826072f64a": "2024-05-08T02:09:20.356Z", + "0xab36452dbac151be02b16ca17d8919826072f64a": "2026-11-06T00:00:00.000Z", "0x9e1028f5f1d5ede59748ffcee5532509976840e0": "2024-05-02T02:09:20.574Z", "0x4200000000000000000000000000000000000006": "2024-05-02T02:09:23.915Z", "0x2ae3f1ec7f1f5012cfeab0185bfc7aa3cf0dec22": "2024-05-02T02:09:24.479Z", From 177e663b9f7d966f9ab5113b87dcdc20bea369f6 Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Fri, 6 Nov 2026 18:40:23 +0000 Subject: [PATCH 2/5] Assert the 4.3.0 upgrade leaves the basket unchanged The spell intentionally does not call refreshBasket(): with OWNER it would re-run basket selection and bypass the trading delay. Guard that in the fork task by checking the basket nonce, timestamp, and bypass flag. Co-Authored-By: Claude Opus 5.5 --- tasks/validation/spells/4.3.0.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tasks/validation/spells/4.3.0.ts b/tasks/validation/spells/4.3.0.ts index 2f2b2d85b..2bf8c6eb3 100644 --- a/tasks/validation/spells/4.3.0.ts +++ b/tasks/validation/spells/4.3.0.ts @@ -189,11 +189,27 @@ task('4.3.0', 'Upgrade to 4.3.0').setAction(async (_, hre) => { JSON.stringify(result, null, 4) ) + // The upgrade should not change the basket + const main = await hre.ethers.getContractAt('IMain', await rToken.main()) + const basketHandler = await hre.ethers.getContractAt( + 'BasketHandlerP1', + await main.basketHandler() + ) + const nonceBefore = await basketHandler.nonce() + const timestampBefore = await basketHandler.timestamp() + await hre.run('proposal-validator', { proposalid: result.proposalId, }) - const main = await hre.ethers.getContractAt('IMain', await rToken.main()) + if ( + (await basketHandler.nonce()) != nonceBefore || + (await basketHandler.timestamp()) != timestampBefore + ) { + throw new Error('basket changed during upgrade') + } + if (await basketHandler.tradingDelayBypassed()) throw new Error('trading delay bypassed') + if ( (await main.hasRole(MAIN_OWNER_ROLE, spell.address)) || !(await main.hasRole(MAIN_OWNER_ROLE, deployment.timelock)) From afb829d53cce6f32b4acd43f9bb75d312eaa4709 Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Fri, 6 Nov 2026 18:42:26 +0000 Subject: [PATCH 3/5] Keep the existing RTokenAsset in the 4.3.0 spell RTokenAsset code is unchanged in 4.3.0 apart from the version string, so re-deploying it only changes its address. Co-Authored-By: Claude Opus 5.5 --- contracts/spells/4_3_0.sol | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/contracts/spells/4_3_0.sol b/contracts/spells/4_3_0.sol index 86aa7019a..cfb92144d 100644 --- a/contracts/spells/4_3_0.sol +++ b/contracts/spells/4_3_0.sol @@ -183,14 +183,6 @@ contract Upgrade4_3_0 is Versioned { require(proxy.basketHandler.status() == CollateralStatus.SOUND, Err(11)); } - // Rotate RTokenAsset - require( - proxy.assetRegistry.registerNewRTokenAsset( - proxy.assetRegistry.toAsset(IERC20(address(rToken))).maxTradeVolume() - ), - Err(12) - ); - // Renounce adminship and validate final state { main.renounceRole(MAIN_OWNER_ROLE, address(this)); @@ -199,7 +191,7 @@ contract Upgrade4_3_0 is Versioned { main.hasRole(MAIN_OWNER_ROLE, msg.sender) && !main.hasRole(MAIN_OWNER_ROLE, address(this)) && !main.hasRole(MAIN_OWNER_ROLE, address(main)), - Err(13) + Err(12) ); } } From 1dbdc9f9b44e7ee06f3b67539bc184cca8bb879a Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Thu, 12 Nov 2026 18:39:03 +0000 Subject: [PATCH 4/5] Rotate the RTokenAsset in the 4.3.0 spell The RTokenAsset compiles in RecollateralizationLib and Fixed.sol, so the 4.2.0 instances still carry the pre-#1283 safeMulDiv. Rotate it as the 4.2.0 spell does, keeping maxTradeVolume. Collateral plugins are kept. The fork task checks the rotation and that the old RTokenAsset, and the 3.4.0 RTokenAsset the Morpho ETH+ markets read directly, still price within 1e-9 of the new one. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- contracts/spells/4_3_0.sol | 12 ++++++++- tasks/validation/spells/4.3.0.ts | 45 +++++++++++++++++++++++++++++--- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db5065420..a59519d0d 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. +- 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. # 4.2.0 diff --git a/contracts/spells/4_3_0.sol b/contracts/spells/4_3_0.sol index cfb92144d..d5e6a5df4 100644 --- a/contracts/spells/4_3_0.sol +++ b/contracts/spells/4_3_0.sol @@ -26,6 +26,8 @@ bytes32 constant MAIN_OWNER_ROLE = bytes32("OWNER"); * deprecated assets must be unregistered first * - this contract must have MAIN_OWNER_ROLE of Main * + * The spell rotates the RTokenAsset, keeping its maxTradeVolume. No other assets are changed. + * * MAIN_OWNER_ROLE is automatically renounced after casting. Governance is unchanged. * * The spell() function should be called by the timelock owning Main. @@ -183,6 +185,14 @@ contract Upgrade4_3_0 is Versioned { require(proxy.basketHandler.status() == CollateralStatus.SOUND, Err(11)); } + // Rotate RTokenAsset + require( + proxy.assetRegistry.registerNewRTokenAsset( + proxy.assetRegistry.toAsset(IERC20(address(rToken))).maxTradeVolume() + ), + Err(12) + ); + // Renounce adminship and validate final state { main.renounceRole(MAIN_OWNER_ROLE, address(this)); @@ -191,7 +201,7 @@ contract Upgrade4_3_0 is Versioned { main.hasRole(MAIN_OWNER_ROLE, msg.sender) && !main.hasRole(MAIN_OWNER_ROLE, address(this)) && !main.hasRole(MAIN_OWNER_ROLE, address(main)), - Err(12) + Err(13) ); } } diff --git a/tasks/validation/spells/4.3.0.ts b/tasks/validation/spells/4.3.0.ts index 2bf8c6eb3..28bb3f36d 100644 --- a/tasks/validation/spells/4.3.0.ts +++ b/tasks/validation/spells/4.3.0.ts @@ -14,6 +14,14 @@ import { Upgrade4_3_0 } from '#/typechain' const VERSION_4_3_0_HASH = '0xdef94dbdd8411ae515cefcb56b153df454453010a1f4c881b3daa7ed18db793a' const DEFAULT_ADMIN_ROLE = '0x0000000000000000000000000000000000000000000000000000000000000000' +// 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[] } = { + // ETH+: Morpho WETH and USDC markets, through EthPlusPriceAdapter + // 0xf87d2F4d42856f0B6Eae140Aaf78bF0F777e9936 + '0xE72B141DF173b999AE7c1aDcbF60Cc9833Ce56a8': ['0x3f11C47E7ed54b24D7EFC222FD406d8E1F49Fb69'], +} + // TODO remove after 4.3.0 is deployed, registered, and its assets are whitelisted // Deploys + registers 4.3.0, whitelists the RToken's current assets for 4.3.0, and // settles any open trades, which would otherwise block the spell @@ -195,8 +203,16 @@ task('4.3.0', 'Upgrade to 4.3.0').setAction(async (_, hre) => { 'BasketHandlerP1', await main.basketHandler() ) + const assetRegistry = await hre.ethers.getContractAt( + 'AssetRegistryP1', + await main.assetRegistry() + ) const nonceBefore = await basketHandler.nonce() const timestampBefore = await basketHandler.timestamp() + const oldRTokenAsset = await hre.ethers.getContractAt( + 'RTokenAsset', + await assetRegistry.toAsset(rToken.address) + ) await hre.run('proposal-validator', { proposalid: result.proposalId, @@ -218,11 +234,32 @@ task('4.3.0', 'Upgrade to 4.3.0').setAction(async (_, hre) => { } if ((await rToken.version()) != '4.3.0') throw new Error('Failed to upgrade to 4.3.0') - // All registered collateral should be SOUND - const assetRegistry = await hre.ethers.getContractAt( - 'AssetRegistryP1', - await main.assetRegistry() + // The RTokenAsset should be rotated, keeping its maxTradeVolume + const newRTokenAsset = await hre.ethers.getContractAt( + 'RTokenAsset', + await assetRegistry.toAsset(rToken.address) ) + if ( + newRTokenAsset.address == oldRTokenAsset.address || + (await newRTokenAsset.version()) != '4.3.0' || + !(await newRTokenAsset.maxTradeVolume()).eq(await oldRTokenAsset.maxTradeVolume()) + ) { + throw new Error('RTokenAsset not rotated') + } + + // The old and pinned RTokenAssets should price the same as the new one + const [newLow, newHigh] = await newRTokenAsset.tryPrice() + for (const addr of [oldRTokenAsset.address, ...(PINNED_RTOKEN_ASSETS[rToken.address] ?? [])]) { + const [low, high] = await (await hre.ethers.getContractAt('RTokenAsset', addr)).tryPrice() + if ( + low.sub(newLow).abs().mul(1e9).gt(newLow) || + high.sub(newHigh).abs().mul(1e9).gt(newHigh) + ) { + throw new Error(`RTokenAsset ${addr} prices differently: ${low}-${high}`) + } + } + + // All registered collateral should be SOUND const [, assets] = await assetRegistry.getRegistry() for (const asset of assets) { const coll = await hre.ethers.getContractAt('ICollateral', asset) From 913b3d061d48826ee5829d93c08bb1744aca25a2 Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Thu, 12 Nov 2026 18:39:03 +0000 Subject: [PATCH 5/5] Cap the validator's redeem amount at the whale's balance No bsdETH holder has 100 tokens any more, so funding the redeem check failed. Co-Authored-By: Claude Opus 5.5 --- tasks/validation/proposal-validator.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tasks/validation/proposal-validator.ts b/tasks/validation/proposal-validator.ts index 3cfe9f1c4..73f9bc6a9 100644 --- a/tasks/validation/proposal-validator.ts +++ b/tasks/validation/proposal-validator.ts @@ -288,9 +288,11 @@ task('run-validations', 'Runs all validations') /* redeem */ - // Give `tester` RTokens from a whale - const redeemAmt = fp('100') - await whileImpersonating(hre, whales[params.rtoken.toLowerCase()], async (whaleSigner) => { + // Give `tester` RTokens from a whale: 100, or the whale's balance if smaller + const whale = whales[params.rtoken.toLowerCase()] + const whaleBal = await rToken.balanceOf(whale) + const redeemAmt = whaleBal.lt(fp('100')) ? whaleBal : fp('100') + await whileImpersonating(hre, whale, async (whaleSigner) => { await rToken.connect(whaleSigner).transfer(tester.address, redeemAmt) }) if (!(await rToken.balanceOf(tester.address)).gte(redeemAmt)) throw new Error('missing RToken')