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

Auto-Detect Template in justfile #30

Draft
wants to merge 8 commits into
base: feat/transfer-owner-template
Choose a base branch
from
Draft
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
8 changes: 4 additions & 4 deletions src/improvements/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ This toml configuration file allows task developers to set gas limits for the ta
#### Template 00 to set gas configs:

```bash
forge script src/improvements/template/GasConfigTemplate.sol --sig "run(string)" test/tasks/mock/example/task-00/config.toml --rpc-url mainnet -vvv
forge script src/improvements/template/GasConfigTemplate.sol --sig "run(string)" test/tasks/mock/example/eth/task-00/config.toml --rpc-url mainnet -vvv
```

#### Template 01 to set dispute game upgrade:

```bash
forge script src/improvements/template/DisputeGameUpgradeTemplate.sol --sig "run(string)" test/tasks/mock/example/task-01/config.toml --rpc-url mainnet -vvv
forge script src/improvements/template/DisputeGameUpgradeTemplate.sol --sig "run(string)" test/tasks/mock/example/eth/task-01/config.toml --rpc-url mainnet -vvv
```

#### Template 02 to set respected game type:

```bash
forge script src/improvements/template/SetGameTypeTemplate.sol --sig "run(string)" test/tasks/mock/example/task-02/config.toml --rpc-url mainnet -vvvvv
forge script src/improvements/template/SetGameTypeTemplate.sol --sig "run(string)" test/tasks/mock/example/eth/task-02/config.toml --rpc-url mainnet -vvvvv
```

#### Template 03 to set gas config:

```bash
forge script src/improvements/template/GasConfigTemplate.sol --sig "run(string)" test/tasks/mock/example/task-03/config.toml --rpc-url mainnet -vvvvv
forge script src/improvements/template/GasConfigTemplate.sol --sig "run(string)" test/tasks/mock/example/eth/task-03/config.toml --rpc-url mainnet -vvvvv
```
2 changes: 1 addition & 1 deletion src/improvements/doc/CALLDATA_DIFFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ data: `0xb40a817c000000000000000000000000000000000000000000000000000000000393870

command:
```bash
forge script src/improvements/template/GasConfigTemplate.sol --sig "simulateRun(string)" test/tasks/mock/example/task-03/config.toml --rpc-url mainnet -vvv
forge script src/improvements/template/GasConfigTemplate.sol --sig "simulateRun(string)" test/tasks/mock/example/eth/task-03/config.toml --rpc-url mainnet -vvv
```

Calldata diff can be found here https://www.diffchecker.com/HA7YFSWi/, select character comparison to see the difference.
14 changes: 14 additions & 0 deletions src/improvements/get-rpc-url.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# Get the task path from the first argument
TASK_PATH="$1"

# Check if the path contains eth/ or sep/
if [[ "$TASK_PATH" == *"/eth/"* ]]; then
echo "mainnet"
elif [[ "$TASK_PATH" == *"/sep/"* ]]; then
echo "sepolia"
else
echo "Error: Task path must contain either /eth/ or /sep/" >&2
exit 1
fi
176 changes: 108 additions & 68 deletions src/improvements/nested.just
Original file line number Diff line number Diff line change
@@ -1,38 +1,51 @@
set dotenv-load

export rpcUrl := env_var_or_default('ETH_RPC_URL', 'https://ethereum.publicnode.com')
# Common variables used across multiple recipes
# Export variables in uppercase for shell script usage
export TASK_PATH := invocation_directory()
export SCRIPT_PATH := justfile_directory()

# Get RPC URL based on task path
rpc_cmd := SCRIPT_PATH + "/get-rpc-url.sh \"" + TASK_PATH + "\""
export rpcUrl := shell(rpc_cmd)

# Fetch the template name from the config.toml file
cmd := "sed -n 's/^[[:space:]]*templateName[[:space:]]*=[[:space:]]*\\\"\\([^\\\"]*\\)\\\".*/\\1/p' " + TASK_PATH + "/config.toml"
export SCRIPT_NAME := shell(cmd)
export signatures := env_var_or_default('SIGNATURES', '')
export taskPath := invocation_directory()
export scriptPath := justfile_directory()
export scriptName := env_var('SCRIPT_NAME')

# Accounts
export councilSafe := env_var("COUNCIL_SAFE")
export foundationSafe := env_var("FOUNDATION_SAFE")
export chainGovernorSafe := env_var_or_default('CHAIN_GOVERNOR_SAFE', '')
export randomPersonEoa := "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
randomPersonEoa := "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"

simulate whichSafe hdPath='0':
#!/usr/bin/env bash
config=${taskPath}/config.toml
script=${scriptPath}/template/${scriptName}.sol

echo "Using script ${script}"
echo "getting signer address for {{whichSafe}}..."

# Get the appropriate safe address based on whichSafe
if [ "{{whichSafe}}" == "foundation" ]; then
safe="{{foundationSafe}}"
fi
if [ "{{whichSafe}}" == "council" ]; then
safe="{{councilSafe}}"
fi
if [ "{{whichSafe}}" == "chain-governor" ]; then
if [ -z "{{chainGovernorSafe}}" ]; then
echo "Error: CHAIN_GOVERNOR_SAFE is not set for chain-governor." >&2
if [ -z "$FOUNDATION_SAFE" ]; then
echo "Error: FOUNDATION_SAFE is required for foundation simulation" >&2
exit 1
fi
safe="$FOUNDATION_SAFE"
elif [ "{{whichSafe}}" == "council" ]; then
if [ -z "$COUNCIL_SAFE" ]; then
echo "Error: COUNCIL_SAFE is required for council simulation" >&2
exit 1
fi
safe="{{chainGovernorSafe}}"
safe="$COUNCIL_SAFE"
elif [ "{{whichSafe}}" == "chain-governor" ]; then
if [ -z "$CHAIN_GOVERNOR_SAFE" ]; then
echo "Error: CHAIN_GOVERNOR_SAFE is required for chain-governor simulation" >&2
exit 1
fi
safe="$CHAIN_GOVERNOR_SAFE"
else
echo "Error: Invalid safe type {{whichSafe}}" >&2
exit 1
fi

config=${TASK_PATH}/config.toml
script=${SCRIPT_PATH}/template/${SCRIPT_NAME}.sol

echo "Using script ${script}"
echo "getting signer address for {{whichSafe}}..."
signer=$(cast call ${safe} "getOwners()(address[])" -r ${rpcUrl} | grep -oE '0x[a-fA-F0-9]{40}' | head -n1)

echo "safe: $safe"
Expand All @@ -55,25 +68,34 @@ simulate whichSafe hdPath='0':

sign whichSafe hdPath='0':
#!/usr/bin/env bash
config=${taskPath}/config.toml
script=${scriptPath}/template/${scriptName}.sol

echo "Using script ${script}"
# Get the appropriate safe address based on whichSafe
if [ "{{whichSafe}}" == "foundation" ]; then
safe="{{foundationSafe}}"
if [ -z "$FOUNDATION_SAFE" ]; then
echo "Error: FOUNDATION_SAFE is required for foundation signing" >&2
exit 1
fi
safe="$FOUNDATION_SAFE"
echo "Using foundation safe at ${safe}"
fi
if [ "{{whichSafe}}" == "council" ]; then
safe="{{councilSafe}}"
elif [ "{{whichSafe}}" == "council" ]; then
if [ -z "$COUNCIL_SAFE" ]; then
echo "Error: COUNCIL_SAFE is required for council signing" >&2
exit 1
fi
safe="$COUNCIL_SAFE"
echo "Using council safe at ${safe}"
fi
if [ "{{whichSafe}}" == "chain-governor" ]; then
if [ -z "{{chainGovernorSafe}}" ]; then
echo "Error: CHAIN_GOVERNOR_SAFE is not set for chain-governor." >&2
elif [ "{{whichSafe}}" == "chain-governor" ]; then
if [ -z "$CHAIN_GOVERNOR_SAFE" ]; then
echo "Error: CHAIN_GOVERNOR_SAFE is required for chain-governor signing" >&2
exit 1
fi
safe="{{chainGovernorSafe}}"
safe="$CHAIN_GOVERNOR_SAFE"
else
echo "Error: Invalid safe type {{whichSafe}}" >&2
exit 1
fi

config=${TASK_PATH}/config.toml
script=${SCRIPT_PATH}/template/${SCRIPT_NAME}.sol
echo "getting signer address..."
signer=$(cast wallet address --ledger --mnemonic-derivation-path "m/44'/60'/{{hdPath}}'/0/0")
echo "Signing with: ${signer}"
Expand All @@ -90,25 +112,34 @@ sign whichSafe hdPath='0':

approve whichSafe hdPath='0':
#!/usr/bin/env bash
config=${taskPath}/config.toml
script=${scriptPath}/template/${scriptName}.sol

echo "Using script ${script}"
# Get the appropriate safe address based on whichSafe
if [ "{{whichSafe}}" == "foundation" ]; then
safe="{{foundationSafe}}"
if [ -z "$FOUNDATION_SAFE" ]; then
echo "Error: FOUNDATION_SAFE is required for foundation approval" >&2
exit 1
fi
safe="$FOUNDATION_SAFE"
echo "Using foundation safe at ${safe}"
fi
if [ "{{whichSafe}}" == "council" ]; then
safe="{{councilSafe}}"
elif [ "{{whichSafe}}" == "council" ]; then
if [ -z "$COUNCIL_SAFE" ]; then
echo "Error: COUNCIL_SAFE is required for council approval" >&2
exit 1
fi
safe="$COUNCIL_SAFE"
echo "Using council safe at ${safe}"
fi
if [ "{{whichSafe}}" == "chain-governor" ]; then
if [ -z "{{chainGovernorSafe}}" ]; then
echo "Error: CHAIN_GOVERNOR_SAFE is not set for chain-governor." >&2
elif [ "{{whichSafe}}" == "chain-governor" ]; then
if [ -z "$CHAIN_GOVERNOR_SAFE" ]; then
echo "Error: CHAIN_GOVERNOR_SAFE is required for chain-governor approval" >&2
exit 1
fi
safe="{{chainGovernorSafe}}"
safe="$CHAIN_GOVERNOR_SAFE"
else
echo "Error: Invalid safe type {{whichSafe}}" >&2
exit 1
fi

config=${TASK_PATH}/config.toml
script=${SCRIPT_PATH}/template/${SCRIPT_NAME}.sol
sender=$(cast wallet address --ledger --mnemonic-derivation-path "m/44'/60'/{{hdPath}}'/0/0")

forge build
Expand All @@ -124,26 +155,35 @@ approve whichSafe hdPath='0':

simulate-approve whichSafe hdPath='0':
#!/usr/bin/env bash
config=${taskPath}/config.toml
script=${scriptPath}/template/${scriptName}.sol

echo "Using script ${script}"
# Get the appropriate safe address based on whichSafe
if [ "{{whichSafe}}" == "foundation" ]; then
safe="{{foundationSafe}}"
if [ -z "$FOUNDATION_SAFE" ]; then
echo "Error: FOUNDATION_SAFE is required for foundation simulate-approve" >&2
exit 1
fi
safe="$FOUNDATION_SAFE"
echo "Using foundation safe at ${safe}"
fi
if [ "{{whichSafe}}" == "council" ]; then
safe="{{councilSafe}}"
elif [ "{{whichSafe}}" == "council" ]; then
if [ -z "$COUNCIL_SAFE" ]; then
echo "Error: COUNCIL_SAFE is required for council simulate-approve" >&2
exit 1
fi
safe="$COUNCIL_SAFE"
echo "Using council safe at ${safe}"
fi
if [ "{{whichSafe}}" == "chain-governor" ]; then
if [ -z "{{chainGovernorSafe}}" ]; then
echo "Error: CHAIN_GOVERNOR_SAFE is not set for chain-governor." >&2
elif [ "{{whichSafe}}" == "chain-governor" ]; then
if [ -z "$CHAIN_GOVERNOR_SAFE" ]; then
echo "Error: CHAIN_GOVERNOR_SAFE is required for chain-governor simulate-approve" >&2
exit 1
fi
safe="{{chainGovernorSafe}}"
safe="$CHAIN_GOVERNOR_SAFE"
else
echo "Error: Invalid safe type {{whichSafe}}" >&2
exit 1
fi

config=${TASK_PATH}/config.toml
script=${SCRIPT_PATH}/template/${SCRIPT_NAME}.sol

if [ ! -z "$SIMULATE_WITHOUT_LEDGER" ]; then
sender=$(cast call ${safe} "getOwners()(address[])" -r ${rpcUrl} | grep -oE '0x[a-fA-F0-9]{40}' | head -n1)
else
Expand All @@ -161,8 +201,8 @@ simulate-approve whichSafe hdPath='0':

execute hdPath='0':
#!/usr/bin/env bash
config=${taskPath}/config.toml
script=${scriptPath}/template/${scriptName}.sol
config=${TASK_PATH}/config.toml
script=${SCRIPT_PATH}/template/${SCRIPT_NAME}.sol

echo "Using script ${script}"
sender=$(cast wallet address --ledger --mnemonic-derivation-path "m/44'/60'/{{hdPath}}'/0/0")
Expand All @@ -179,8 +219,8 @@ execute hdPath='0':

simulated-run hdPath='0':
#!/usr/bin/env bash
config=${taskPath}/config.toml
script=${scriptPath}/template/${scriptName}.sol
config=${TASK_PATH}/config.toml
script=${SCRIPT_PATH}/template/${SCRIPT_NAME}.sol

echo "Using script ${script}"

Expand Down
45 changes: 23 additions & 22 deletions src/improvements/single.just
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
set dotenv-load

export rpcUrl := env_var('ETH_RPC_URL')
# Common variables used across multiple recipes
# Export variables in uppercase for shell script usage
export TASK_PATH := invocation_directory()
export SCRIPT_PATH := justfile_directory()

# Get RPC URL based on task path
rpc_cmd := SCRIPT_PATH + "/get-rpc-url.sh \"" + TASK_PATH + "\""
export rpcUrl := shell(rpc_cmd)

# Fetch the template name from the config.toml file
cmd := "sed -n 's/^[[:space:]]*templateName[[:space:]]*=[[:space:]]*\\\"\\([^\\\"]*\\)\\\".*/\\1/p' " + TASK_PATH + "/config.toml"
export SCRIPT_NAME := shell(cmd)
export signatures := env_var_or_default('SIGNATURES', '')
export taskPath := invocation_directory()
export scriptPath := justfile_directory()
export ownerSafe := env_var('OWNER_SAFE')
export scriptName := env_var('SCRIPT_NAME')

simulate hdPath='0':
#!/usr/bin/env bash
config=${taskPath}/config.toml
script=${scriptPath}/template/${scriptName}.sol

config=${TASK_PATH}/config.toml
script=${SCRIPT_PATH}/template/${SCRIPT_NAME}.sol

echo "Using script ${script}"
echo "Safe address: ${ownerSafe}"
echo "Getting signer address..."

if [ ! -z "$SIMULATE_WITHOUT_LEDGER" ]; then
signer=$(cast call ${ownerSafe} "getOwners()(address[])" -r ${rpcUrl} | grep -oE '0x[a-fA-F0-9]{40}' | head -n1)
else
signer=$(cast wallet address --ledger --mnemonic-derivation-path "m/44'/60'/{{hdPath}}'/0/0")
fi
echo "Simulating with: ${signer}"
echo ""

forge build
forge script ${script} \
--rpc-url ${rpcUrl} \
--sig "simulateRun(string)" ${config} \
--sender ${signer}

sign hdPath='0':
#!/usr/bin/env bash
config=${taskPath}/config.toml
script=${scriptPath}/template/${scriptName}.sol
config=${TASK_PATH}/config.toml
script=${SCRIPT_PATH}/template/${SCRIPT_NAME}.sol
echo "script name: ${SCRIPT_NAME}"
echo "task path: ${TASK_PATH}"
echo "script path: ${SCRIPT_PATH}"

echo "Using script ${script}"
echo "getting signer address..."
Expand All @@ -50,8 +51,8 @@ sign hdPath='0':

execute hdPath='0':
#!/usr/bin/env bash
config=${taskPath}/config.toml
script=${scriptPath}/template/${scriptName}.sol
config=${TASK_PATH}/config.toml
script=${SCRIPT_PATH}/template/${SCRIPT_NAME}.sol

echo "Using script ${script}"
sender=$(cast wallet address --ledger --mnemonic-derivation-path "m/44'/60'/{{hdPath}}'/0/0")
Expand All @@ -60,4 +61,4 @@ execute hdPath='0':
forge script --fork-url ${rpcUrl} ${script} \
--sig "executeRun(string,bytes)" ${config} ${signatures} \
--ledger --hd-paths "m/44'/60'/{{hdPath}}'/0/0" --broadcast \
--sender ${sender}
--sender ${sender}
2 changes: 1 addition & 1 deletion test/tasks/MultisigTask.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract MultisigTaskUnitTest is Test {
AddressRegistry public addresses;
MultisigTask public task;

string constant MAINNET_CONFIG = "./test/tasks/mock/example/task-03/config.toml";
string constant MAINNET_CONFIG = "./test/tasks/mock/example/eth/task-03/config.toml";

/// @notice variables that store the storage offset of different variables in the MultisigTask contract

Expand Down
2 changes: 1 addition & 1 deletion test/tasks/NestedMultisigTask.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract NestedMultisigTaskTest is Test {
uint256 public constant THRESHOLD_STORAGE_OFFSET = 4;

/// ProxyAdminOwner safe for task-01 is a nested multisig for Op mainnet L2 chain.
string taskConfigFilePath = "test/tasks/mock/example/task-01/config.toml";
string taskConfigFilePath = "test/tasks/mock/example/eth/task-01/config.toml";

function setUp() public {
vm.createSelectFork("mainnet");
Expand Down
Loading