Skip to content

Commit 61c13d3

Browse files
committed
added scripts for managing the 712 macro forwarder and related ACL
1 parent 7a5ee29 commit 61c13d3

File tree

4 files changed

+175
-0
lines changed

4 files changed

+175
-0
lines changed

packages/ethereum-contracts/ops-scripts/deploy-deterministically.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const SuperfluidLoader = artifacts.require("SuperfluidLoader");
77
const CFAv1Forwarder = artifacts.require("CFAv1Forwarder");
88
const GDAv1Forwarder = artifacts.require("GDAv1Forwarder");
99
const MacroForwarder = artifacts.require("MacroForwarder");
10+
const Only712MacroForwarder = artifacts.require("Only712MacroForwarder");
1011

1112
/**
1213
* @dev Deploy specified contract at a deterministic address (defined by sender, nonce)
@@ -89,6 +90,12 @@ module.exports = eval(`(${S.toString()})()`)(async function (
8990
console.log(
9091
`setting up MacroForwarder for chainId ${chainId}, host ${hostAddr}`
9192
);
93+
} else if (contractName === "Only712MacroForwarder") {
94+
ContractArtifact = Only712MacroForwarder;
95+
deployArgs = [hostAddr];
96+
console.log(
97+
`setting up Only712MacroForwarder for chainId ${chainId}, host ${hostAddr}`
98+
);
9299
} else {
93100
throw new Error("Contract unknown / not supported");
94101
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.23;
3+
4+
import { Script } from "forge-std/Script.sol";
5+
import { console } from "forge-std/console.sol";
6+
import { IAccessControl } from "@openzeppelin-v5/contracts/access/IAccessControl.sol";
7+
import { ISuperfluid } from "../contracts/interfaces/superfluid/ISuperfluid.sol";
8+
9+
/**
10+
* @title GrantMacroProviderRole
11+
* @dev Grants the macro provider role in SimpleACL for a given provider string (e.g. "macros.superfluid.eth").
12+
* The role is keccak256(provider). Caller must have DEFAULT_ADMIN_ROLE on SimpleACL.
13+
*
14+
* Usage (with wrapper):
15+
* tasks/grant-macro-provider-role.sh <network> <grantee-address> [provider]
16+
*
17+
* Or directly:
18+
* forge script scripts/GrantMacroProviderRole.s.sol --sig "run(address,address,string)" \\
19+
* <host> <grantee> [provider] --rpc-url <url> --broadcast
20+
*/
21+
contract GrantMacroProviderRole is Script {
22+
string public constant DEFAULT_PROVIDER = "macros.superfluid.eth";
23+
24+
function run(address host, address grantee, string memory provider) external {
25+
if (bytes(provider).length == 0) {
26+
provider = DEFAULT_PROVIDER;
27+
}
28+
29+
IAccessControl simpleACL = ISuperfluid(host).getSimpleACL();
30+
bytes32 role = keccak256(bytes(provider));
31+
32+
console.log("Host: ", host);
33+
console.log("SimpleACL: ", address(simpleACL));
34+
console.log("Grantee: ", grantee);
35+
console.log("Provider: ", provider);
36+
console.log("Role (hex):");
37+
console.logBytes32(role);
38+
39+
if (simpleACL.hasRole(role, grantee)) {
40+
console.log("Grantee already has the role; no-op.");
41+
return;
42+
}
43+
44+
vm.startBroadcast();
45+
simpleACL.grantRole(role, grantee);
46+
vm.stopBroadcast();
47+
48+
console.log("Granted macro provider role to", grantee);
49+
}
50+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
set -eu
3+
set -o pipefail
4+
5+
# Usage:
6+
# tasks/deploy-712-macro-forwarder.sh <network>
7+
#
8+
# The invoking account needs to be (co-)owner of the resolver and governance
9+
#
10+
# important ENV vars:
11+
# RELEASE_VERSION, ONLY712MACROFWD_DEPLOYER_PK
12+
# ONLY712MACROFWD_EXPECTED_ADDRESS: set after generating deployer with vanity-eth
13+
# (e.g. npx vanityeth -i 712f --contract), or set SKIP_ADDRESS_CHECK=1 to skip.
14+
#
15+
# You can use the npm package vanity-eth to get a deployer account for a given contract address:
16+
# Example use: npx vanityeth -i 712f --contract
17+
#
18+
# For optimism the gas estimation doesn't work, requires setting EST_TX_COST
19+
# (the value auto-detected for arbitrum should work).
20+
#
21+
# On some networks you may need to use override ENV vars for the deployment to succeed
22+
23+
# shellcheck source=/dev/null
24+
source .env
25+
26+
set -x
27+
28+
network=$1
29+
expectedContractAddr="0x712F228ba2638FF22B383d97B0d0D210a06F6547"
30+
deployerPk=$ONLY712MACROFWD_DEPLOYER_PK
31+
32+
tmpfile="/tmp/$(basename "$0").addr"
33+
34+
# deploy
35+
DETERMINISTIC_DEPLOYER_PK=$deployerPk npx truffle exec --network "$network" ops-scripts/deploy-deterministically.js : Only712MacroForwarder | tee "$tmpfile"
36+
contractAddr=$(tail -n 1 "$tmpfile")
37+
rm "$tmpfile"
38+
39+
echo "deployed to $contractAddr"
40+
if [[ -n "$expectedContractAddr" && $contractAddr != "$expectedContractAddr" ]]; then
41+
echo "contract address not as expected!"
42+
if [ -z "$SKIP_ADDRESS_CHECK" ]; then
43+
exit
44+
fi
45+
fi
46+
47+
# verify (give it a few seconds to pick up the code)
48+
sleep 5
49+
# allow to fail
50+
set +e
51+
npx truffle run --network "$network" verify Only712MacroForwarder@"$contractAddr"
52+
set -e
53+
54+
# set resolver
55+
ALLOW_UPDATE=1 npx truffle exec --network "$network" ops-scripts/resolver-set-key-value.js : Only712MacroForwarder "$contractAddr"
56+
57+
# create gov action
58+
npx truffle exec --network "$network" ops-scripts/gov-set-trusted-forwarder.js : 0x0000000000000000000000000000000000000000 "$contractAddr" 1
59+
60+
# TODO: on mainnets, the resolver entry should be set only after the gov action was signed & executed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
set -eu
3+
set -o pipefail
4+
5+
# Usage:
6+
# tasks/grant-macro-provider-role.sh <network> <grantee-address> [provider]
7+
#
8+
# Grants the macro provider role in SimpleACL. The role is keccak256(provider);
9+
# default provider is "macros.superfluid.eth".
10+
#
11+
# Network: canonical name from metadata (e.g. optimism-sepolia, eth-sepolia).
12+
# Grantee: address to grant the role (must be valid for the forwarder / macro runner).
13+
#
14+
# The caller must have DEFAULT_ADMIN_ROLE on SimpleACL (e.g. governance).
15+
# Use your usual signer: private key (PRIVATE_KEY / --private-key), foundry wallet
16+
# (--account), or other forge-supported options.
17+
#
18+
# Requires: jq, forge. Run from packages/ethereum-contracts (or repo root; script will cd).
19+
20+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
21+
PKG_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
22+
METADATA_JSON="$PKG_ROOT/../metadata/networks.json"
23+
24+
network="${1:?Usage: $0 <network> <grantee-address> [provider]}"
25+
grantee="${2:?Usage: $0 <network> <grantee-address> [provider]}"
26+
provider="${3:-macros.superfluid.eth}"
27+
account="${FOUNDRY_ACCOUNT:-gh-agent}"
28+
29+
if [[ ! -f "$METADATA_JSON" ]]; then
30+
echo "Metadata not found: $METADATA_JSON" >&2
31+
exit 1
32+
fi
33+
34+
host=$(jq -r '.[] | select(.name == "'"$network"'") | .contractsV1.host' "$METADATA_JSON")
35+
rpc=$(jq -r '.[] | select(.name == "'"$network"'") | .publicRPCs[0]' "$METADATA_JSON")
36+
37+
if [[ -z "$host" || "$host" == "null" ]]; then
38+
echo "Unknown network: $network (no host in metadata)" >&2
39+
exit 1
40+
fi
41+
if [[ -z "$rpc" || "$rpc" == "null" ]]; then
42+
echo "No public RPC for network: $network" >&2
43+
exit 1
44+
fi
45+
46+
echo "Network: $network"
47+
echo "Host: $host"
48+
echo "Grantee: $grantee"
49+
echo "Provider: $provider"
50+
echo "RPC: $rpc"
51+
echo ""
52+
53+
cd "$PKG_ROOT"
54+
forge script scripts/GrantMacroProviderRole.s.sol \
55+
--sig "run(address,address,string)" "$host" "$grantee" "$provider" \
56+
--rpc-url "$rpc" \
57+
--account "$account" \
58+
--broadcast

0 commit comments

Comments
 (0)