Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(config, world/upgrade): add proxy support #2707

Merged
merged 7 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions docs/pages/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,7 @@ The global configuration keys are all optional.

- **`worldsFile`** a `string`: JSON file for the chain to `World` deploy address mapping.
The default is `./worlds.json`.

- <a id="upgradeableWorldImplementation" />
**`upgradeableWorldImplementation`** a `bool`: Whether the `World` is to be deployed behind a proxy to [enable upgrades](/world/upgrade).
qbzzt marked this conversation as resolved.
Show resolved Hide resolved
qbzzt marked this conversation as resolved.
Show resolved Hide resolved
The default is `false`.
1 change: 1 addition & 0 deletions docs/pages/world/_meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default {
balance: "Balance",
"account-delegation": "Account Delegation",
"batch-calls": "Batch Calls",
"upgrade": "Upgrading",
modules: "Modules",
reference: "Reference",
};
95 changes: 95 additions & 0 deletions docs/pages/world/upgrade.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { CollapseCode } from "../../components/CollapseCode";
import { Callout } from "nextra/components";

# Upgrading worlds

The [tables](./tables) and [`System`s](./systems) can be upgraded without changing the underlying `World` code.
qbzzt marked this conversation as resolved.
Show resolved Hide resolved
However, if the `World` was deployed [behind a proxy](/config#upgradeableWorldImplementation) it is also possible to upgrade the `World` itself.
This will be useful in the future as we further develop MUD, adding features and fixing bugs.
qbzzt marked this conversation as resolved.
Show resolved Hide resolved

## Are upgrades possible?

As per [ERC-1967](https://eips.ethereum.org/EIPS/eip-1967#logic-contract-address), the storage slot `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc` stores the address of the actual `World` contract in a proxy.
qbzzt marked this conversation as resolved.
Show resolved Hide resolved
So to identify if a `World` is deployed behind a proxy run these commands:

```sh copy
WORLD_ADDRESS=0xbe6b85dc88f969e45d8d8ae128c5a9c9744d6464
cast implementation $WORLD_ADDRESS
```

If the answer is anything other than zero, the `World` is behind a proxy and can be upgraded.

## The actual upgrade
qbzzt marked this conversation as resolved.
Show resolved Hide resolved

To upgrade the `World` use these steps in a `package/contracts` directory:

1. Edit `.env` to add `WORLD_ADDRESS` with the address displayed by MUD Dev Tools.
For example, you might want to use this file:

<CollapseCode>

```sh filename=".env" showLineNumbers copy {12}
# This .env file is for demonstration purposes only.
#
# This should usually be excluded via .gitignore and the env vars attached to
# your deployment environment, but we're including this here for ease of local
# development. Please do not commit changes to this file!
#
# Enable debug logs for MUD CLI
DEBUG=mud:*
#
# Anvil default private key:
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
WORLD_ADDRESS=0xbe6b85dc88f969e45d8d8ae128c5a9c9744d6464
```

</CollapseCode>

1. Create this script in `scripts/UpgradeWorld.s.sol`.

<CollapseCode>

```solidity filename="UpgradeWorld.s.sol" copy showLineNumbers {18,23}
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;

import { Script } from "forge-std/Script.sol";
import { console } from "forge-std/console.sol";

import { World } from "@latticexyz/world/src/World.sol";
import { WorldProxy } from "@latticexyz/world/src/WorldProxy.sol";

contract SetImplementation is Script {
function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);

address proxyAddress = vm.envAddress("WORLD_ADDRESS");

// Deploy new world implementation
World newWorld = new World();
qbzzt marked this conversation as resolved.
Show resolved Hide resolved

console.log("proxy:", proxyAddress);
console.log("new World:", address(newWorld));

WorldProxy(payable(proxyAddress)).setImplementation(address(newWorld));

vm.stopBroadcast();
}
}
```

</CollapseCode>

1. Run the script.

```sh copy
forge script script/UpgradeWorld.s.sol --rpc-url http://localhost:8545 --broadcast
```

1. See the new address.

```sh copy
source .env
cast implementation $WORLD_ADDRESS
```
Loading