latticexyz / mud

MUD is a framework for building autonomous worlds
https://mud.dev
MIT License
740 stars 187 forks source link

rethink PostDeploy and deploy hooks via scripts #1755

Open holic opened 1 year ago

holic commented 1 year ago

mostly so we have a place to set up boilerplate like setting the store address

contract PostDeploy is Script {
  function run(address worldAddress) external {
    StoreSwitch.setStoreAddress(worldAddress);

but also could mean in the future we add support for multiple PostDeploy scripts by looking at the scripts inheritance chain and, if it inherits from our base PostDeploy, it's executed, regardless of the name (no special PostDeploy naming needed anymore)

yonadaaa commented 1 year ago

Following how MudTest extends Foundry's Test, you could have MudScript extending Script.

holic commented 1 year ago

Following how MudTest extends Foundry's Test, you could have MudScript extending Script.

Definitely! And we could move away from a generic run(address) to something like afterDeployWorld(address), leaving us room to add other "hooks" like afterUpgradeWorld(address)

holic commented 7 months ago

with this structure, we'd be able to split big PostDeploy scripts into multiple files, which could help with issues we're seeing in Sky Strife where kicking off 300+ txs in a single script causes failures due to overlapping nonces

if we went this route, another thing that would be great is to be able to specify a list of "dependencies" for managing deploy order

contract UploadMaps is MudScript {
  afterDeployWorld(address worldAddress) {
    ....
  }
}
contract CreateDebugMatch is MudScript {
  bytes4[] public constant dependsOn = [UploadMaps.afterDeployWorld.selector];

  afterDeployWorld(address worldAddress) {
    ....
  }
}