Skip to content

Commit

Permalink
feat: approve-upgrade script to make approving upgrades easy against …
Browse files Browse the repository at this point in the history
…baseFork
  • Loading branch information
hiddentao committed Oct 16, 2024
1 parent d082bfb commit b0213a2
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 44 deletions.
13 changes: 13 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CHAIN_ID=31337
RPC_URL=http://localhost:8545
NAYM_SYS_ADMIN_ADDRESS=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
NAYM_TOKEN_DEPLOYER_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
ETH_SEPOLIA_RPC_URL=http://localhost:8545
ETH_MAINNET_RPC_URL=http://localhost:8545
BASE_SEPOLIA_RPC_URL=http://localhost:8545
BASESCAN_API_KEY=0x0000000000000000000000000000000000000000
BLOCKSCOUT_API_KEY=0x0000000000000000000000000000000000000000
BASE_MAINNET_RPC_URL=http://localhost:8545
AURORA_MAINNET_RPC_URL=http://localhost:8545
AURORA_TESTNET_RPC_URL=http://localhost:8545
NAYM_TOKEN_SALT=0x0000000000000000000000000000000000000000000000000000000000000000
46 changes: 14 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ Install pre-requisites:
* [Foundry](https://book.getfoundry.sh/)
* [Yarn](https://yarnpkg.com/)

Then copy `.env.example` to `.env`:

```shell
$ cp .env.example .env
```

Then run:

```shell
Expand All @@ -46,40 +52,16 @@ To run a local devnet:
$ yarn devnet
```

## Deployment

* _The `owner` and `minter` are both initially set to be the deployment wallet's address._
* _[CREATE2](https://book.getfoundry.sh/tutorials/create2-tutorial) is used for deployment, so the address will always be the same as long as the deployment wallet and bytecode are the same, irrespective of chain, nonce, etc._

### Local (anvil)

To deploy locally, first run a local devnet:

```shell
$ yarn devnet
```

Then run:

```shell
$ yarn deploy-local
```

### Public (tesnets, mainnets)

Set the following environment variables:
## Test an upgrade against Base fork

```shell
$ export PRIVATE_KEY="0x..."
$ export RPC_URL="http://..."
$ export CHAIN_ID="..."
```

Then run:
1. In a separate terminal, clone the [contracts-v3](https://github.com/nayms/contracts-v3) repo and run `make base-fork`. This should start a local node forked from Base mainnet.
2. Back in this repo...
3. Run `yarn deploy baseFork --upgrade-start`
* To run an [upgrade initialization]() use: `yarn deploy baseFork --upgrade-start --upgrade-init-contract <contract name> --upgrade-init-method <method name>`
* Note down the upgrade ID for use in the following command...
4. Run `yarn approve-upgrade --id <upgrade ID> --contract 0x314d7f9e2f55B430ef656FBB98A7635D43a2261E#balances`
5. Run `yarn deploy baseFork --upgrade-finish`

```shell
$ yarn deploy-public
```

## License

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"devnet": "anvil",
"commitlint": "commitlint --edit",
"deploy": "./script/gemforge/deploy.js",
"approve-upgrade": "./script/gemforge/approveUpgrade.js",
"query": "gemforge query"
},
"commitlint": {
Expand Down
56 changes: 56 additions & 0 deletions script/gemforge/approveUpgrade.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env node

const chalk = require("chalk");
const yargs = require("yargs");
const { $ } = require("./utils");

(async () => {
const { argv } = yargs
.option('id', {
alias: 'u',
description: 'Upgrade ID to approve',
type: 'string',
demandOption: true
})
.option('contract', {
alias: 'c',
description: 'Contract address',
type: 'string',
demandOption: true
})
.option('from', {
alias: 'f',
description: 'From address',
type: 'string',
default: '0x28b85ca97cbf8127b47def4570bf6d9fb1983e38'
})
.option('newOwner', {
alias: 'n',
description: 'Transfer ownership for approval to this new owner address',
type: 'string',
default: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
});

const rpcUrl = 'http://127.0.0.1:8545';

console.log(chalk.blue('Approving upgrade...'));

// Impersonate account and create upgrade
await $(`cast rpc anvil_impersonateAccount ${argv.from}`);
await $(`cast send ${argv.contract} "createUpgrade(bytes32)" '${argv.id}' --rpc-url ${rpcUrl} --unlocked --from ${argv.from}`);

console.log(chalk.green('Upgrade approved successfully!'));

if (argv.newOwner) {
console.log(chalk.blue('Transferring ownership...'));

// Impersonate account and transfer ownership
await $(`cast rpc anvil_impersonateAccount ${argv.from}`);
await $(`cast send ${argv.contract} "transferOwnership(address)" '${argv.newOwner}' --rpc-url ${rpcUrl} --unlocked --from ${argv.from}`);

console.log(chalk.green('Ownership transferred successfully!'));
}

console.log(chalk.green('Done!'));
})();

14 changes: 3 additions & 11 deletions script/gemforge/deploy.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env node

const chalk = require("chalk");
const path = require("path");
const fs = require("fs");
const path = require("node:path");
const fs = require("node:fs");
const rootFolder = path.join(__dirname, "..", "..");
const config = require(path.join(rootFolder, "gemforge.config.cjs"));
const yargs = require("yargs");

const execa = require("execa");
const { $ } = require("./utils");

const { getProxyAddress, calculateUpgradeId, assertUpgradeIdIsEnabled, enableUpgradeViaGovernance } = require("./utils");

Expand Down Expand Up @@ -37,13 +36,6 @@ const assertThatUpgradeIsEnabled = async (targetId, cutFile) => {
};

(async () => {
const $ = async (cmd, opts = {}) => {
if (typeof cmd !== "string") {
throw new Error("Command must be a string");
}
return await execa.command(cmd, { ...opts, shell: true, stdio: "inherit", cwd: rootFolder });
};

const { argv } = yargs;

const targetArg = argv._[0];
Expand Down
10 changes: 9 additions & 1 deletion script/gemforge/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require("path");
const path = require("node:path");
const execa = require("execa");
const rootFolder = path.join(__dirname, "..", "..", "..");

const { createPublicClient, createWalletClient, http, encodeAbiParameters, keccak256, publicActions } = require("viem");
Expand Down Expand Up @@ -145,3 +146,10 @@ exports.assertUpgradeIdIsEnabled = async (targetId, upgradeId) => {
throw new Error(`Upgrade not found!`);
}
};

exports.$ = async (cmd, opts = {}) => {
if (typeof cmd !== "string") {
throw new Error("Command must be a string");
}
return await execa.command(cmd, { ...opts, shell: true, stdio: "inherit", cwd: rootFolder });
};

0 comments on commit b0213a2

Please sign in to comment.