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. It also takes a `newTradingDelay` and sets it on the BackingManager, so each community can choose `tradingDelay` for its new meaning.
- 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. The spell requires the RToken to be SOUND and fully collateralized, RSR to be registered, and the Broker to use the DAO's TrustedFillerRegistry.

## Rounding Changes

Expand Down
12 changes: 11 additions & 1 deletion contracts/spells/4_3_0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ bytes32 constant MAIN_OWNER_ROLE = bytes32("OWNER");
* - 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
* - RSR must be registered, and the RToken must be SOUND and fully collateralized
* - this contract must have MAIN_OWNER_ROLE of Main
*
* The spell rotates the RTokenAsset, keeping its maxTradeVolume. No other assets are changed.
Expand Down Expand Up @@ -117,7 +118,9 @@ contract Upgrade4_3_0 is Versioned {
require(
main.versionRegistry() == registries.versionRegistry &&
main.assetPluginRegistry() == registries.assetPluginRegistry &&
main.daoFeeRegistry() == registries.daoFeeRegistry,
main.daoFeeRegistry() == registries.daoFeeRegistry &&
TestIBroker(address(main.broker())).trustedFillerRegistry() ==
registries.trustedFillerRegistry,
Err(4)
);

Expand All @@ -137,6 +140,9 @@ contract Upgrade4_3_0 is Versioned {
stRSR: main.stRSR()
});

// RSR should still be registered: 4.2.0 allows unregistering it, 4.3.0 does not
require(proxy.assetRegistry.isRegistered(main.rsr()), Err(15));

// tradingDelay should only increase
require(
newTradingDelay >= TestIBackingManager(address(proxy.backingManager)).tradingDelay(),
Expand Down Expand Up @@ -195,6 +201,10 @@ contract Upgrade4_3_0 is Versioned {

proxy.assetRegistry.refresh();
require(proxy.basketHandler.status() == CollateralStatus.SOUND, Err(11));

// Assets unregistered before casting may have been needed to restore the backing.
// Unregistering cannot change this result without also disabling the basket.
require(proxy.basketHandler.fullyCollateralized(), Err(16));
}

// Set tradingDelay for its 4.3.0 meaning
Expand Down
14 changes: 14 additions & 0 deletions tasks/validation/proposals/4_3_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,27 @@ export const proposal_4_3_0 = async (
await main.basketHandler()
)
const [primeERC20s] = await basketHandler.getPrimeBasket()
const rsr = await main.rsr()

// Unregistered assets may be needed to restore the backing. The spell checks this too.
if (!(await basketHandler.fullyCollateralized())) {
throw new Error('RToken is not fully collateralized')
}

// 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++) {
// The RToken's own asset cannot be unregistered; the spell rotates it
if (erc20s[i].toLowerCase() == rTokenAddress.toLowerCase()) continue

if (!(await assetPluginRegistry.isDeprecated(assets[i]))) continue

// 4.2.0 allows unregistering RSR; the spell requires it to stay registered
if (erc20s[i] == rsr) {
throw new Error(`deprecated RSR asset ${assets[i]} must be swapped, not unregistered`)
}

if (primeERC20s.includes(erc20s[i]) || (await basketHandler.quantity(erc20s[i])).gt(0)) {
throw new Error(`deprecated asset ${assets[i]} is in the basket`)
}
Expand Down
72 changes: 72 additions & 0 deletions tasks/validation/spells/4.3.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ 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'
import { Proposal } from '#/utils/subgraph'
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'

const VERSION_4_3_0_HASH = '0xdef94dbdd8411ae515cefcb56b153df454453010a1f4c881b3daa7ed18db793a'
const DEFAULT_ADMIN_ROLE = '0x0000000000000000000000000000000000000000000000000000000000000000'
Expand Down Expand Up @@ -147,6 +149,74 @@ const setup_4_3_0 = async (hre: HardhatRuntimeEnvironment, deployment: RTokenDep
}
}

// The spell should refuse an RToken that lost RSR, or that is not fully collateralized
const checkSpellGuards = async (
hre: HardhatRuntimeEnvironment,
deployment: RTokenDeployment,
spell: Upgrade4_3_0,
proposal: Proposal
) => {
const rToken = await hre.ethers.getContractAt('RTokenP1', deployment.rToken)
const main = await hre.ethers.getContractAt('MainP1', await rToken.main())
const assetRegistry = await hre.ethers.getContractAt(
'AssetRegistryP1',
await main.assetRegistry()
)
const basketHandler = await hre.ethers.getContractAt(
'BasketHandlerP1',
await main.basketHandler()
)

// Runs the proposal up to castSpell, breaks the RToken, then expects castSpell to revert
const expectErr = async (
index: number,
breakRToken: (timelock: SignerWithAddress) => unknown
) => {
const snapshot = await hre.network.provider.send('evm_snapshot')

await whileImpersonating(hre, deployment.timelock, async (timelock) => {
for (let i = 0; i < proposal.targets.length - 1; i++) {
await timelock.sendTransaction({ to: proposal.targets[i], data: proposal.calldatas[i] })
}
await breakRToken(timelock)

const expected = spell.interface.encodeErrorResult('Err', [index])
const actual = await hre.network.provider
.send('eth_call', [
{
from: timelock.address,
to: spell.address,
data: proposal.calldatas[proposal.calldatas.length - 1],
},
])
.then(
() => 'no revert',
(e) => e.data
)
if (actual != expected) throw new Error(`expected Err(${index}), got ${actual}`)
})

await hre.network.provider.send('evm_revert', [snapshot])
console.log(`Spell reverts with Err(${index}) as expected`)
}

// 4.2.0 allows unregistering RSR
await expectErr(15, async (timelock) => {
await assetRegistry.connect(timelock).unregister(await assetRegistry.toAsset(await main.rsr()))
})

// Move a token of the current basket out of the BackingManager
await expectErr(16, async (timelock) => {
const backingManager = await main.backingManager()
const [erc20s] = await basketHandler.getHistoricalBasket(await basketHandler.nonce())
const erc20 = await hre.ethers.getContractAt('ERC20Mock', erc20s[0])
await whileImpersonating(hre, backingManager, async (signer) => {
await erc20.connect(signer).transfer(timelock.address, await erc20.balanceOf(backingManager))
})
if (await basketHandler.fullyCollateralized()) throw new Error('still fully collateralized')
})
}

// 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()
Expand Down Expand Up @@ -191,6 +261,8 @@ task('4.3.0', 'Upgrade to 4.3.0').setAction(async (_, hre) => {
result.governor = anastasius.address
result.timelock = deployment.timelock

await checkSpellGuards(hre, deployment, spell, result)

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)
Expand Down
Loading