Skip to content

Commit

Permalink
Merge pull request #139 from axieinfinity/implement-feature/rework/ba…
Browse files Browse the repository at this point in the history
…se-migration

feat(rework): implement `base-migration`
  • Loading branch information
TuDo1403 committed Jun 10, 2024
2 parents 787ff64 + 0522298 commit c3f9f1c
Show file tree
Hide file tree
Showing 43 changed files with 1,408 additions and 713 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ docs/
node_modules/
yarn-error.log
.yarn
.yarnrc.yml
.yarnrc.yml
deployments/**/exported_address
9 changes: 2 additions & 7 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@ import {
HardhatUserConfig,
NetworkUserConfig,
} from "hardhat/types";
import * as dotenv from 'dotenv';

dotenv.config();

const { TESTNET_URL, MAINNET_URL } = process.env;

const testnet: NetworkUserConfig = {
chainId: 2021,
url: TESTNET_URL || "https://saigon-testnet.roninchain.com/rpc",
url: "https://saigon-testnet.roninchain.com/rpc",
};

const mainnet: NetworkUserConfig = {
chainId: 2020,
url: MAINNET_URL || "https://api.roninchain.com/rpc",
url: "https://api.roninchain.com/rpc",
};

const config: HardhatUserConfig = {
Expand Down
114 changes: 106 additions & 8 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# Function to display script usage
usage() {
forge script --help

echo ""
echo "\033[33mFoundry Script Usage:\033[0m"
echo "Usage: $0 [forge_options] --no-postcheck --sender {sender_address} --force-generate-artifact"
echo "Options:"
echo " --no-postcheck: Disable post-check"
echo " --sender: Specify the default sender address"
echo " --force-generate-artifact: Force generate artifact"

exit 1
}

# Check if command-line arguments are provided
if [ "$#" -eq 0 ]; then
usage
fi

verify_arg=""
extra_argument=""

Expand All @@ -6,6 +26,64 @@ op_command=""
network_name=""
is_broadcast=false
should_verify=false
force_generate_artifact=false
# Define the deployments folder by concatenating it with the child folder
root="deployments/"

export_address() {
index=0

start_time=$(date +%s)

for folder in "$root"/*; do
# If exported_address.toml exists, delete it
if [ -f "$folder"/exported_address ]; then
rm "$folder"/exported_address
fi

# Create a new exported_address file
touch "$folder"/exported_address

for file in "$folder"/*.json; do

# Check if the file exists and is a regular file
if [ -f "$file" ] && [ "$(basename "$file")" != ".chainId" ] && [ "$(basename "$file")" != "exported_address" ]; then
((index++))
(
# Extract address from the JSON file
contractAddress=$(jq -r '.address' "$file")
# Extract contractName from file name without the extension
contractName=$(basename "$file" .json)

# Check if contractName and address are not empty
if [ -n "$contractName" ]; then
# Write to file the contractName and address
echo "$contractName.json@$contractAddress" >>"$folder"/exported_address
else
echo "Error: Missing contractName or address in $file"
fi
) &
fi

# Check if index is a multiple of 10, then wait
if [ $((index % 10)) -eq 0 ]; then
wait
fi
done
done

wait

end_time=$(date +%s)
echo "Export address in deployment folder: $((end_time - start_time)) seconds"
}

export_address

echo "\033[33mTrying to compile contracts ...\033[0m"
forge build # Ensure the contracts are compiled before running the script

index=0

for arg in "$@"; do
case $arg in
Expand All @@ -22,11 +100,15 @@ for arg in "$@"; do
;;
-f | --fork-url)
network_name=${@:index+2:1}
extra_argument+="network.${network_name}@"
# skip if network_name is localhost
if [[ $network_name != "localhost" ]]; then
extra_argument+="network.${network_name}@"

set -- "${@/#-f/}"
set -- "${@/#--fork-url/}"
set -- "${@/#$network_name/}"
fi

set -- "${@/#-f/}"
set -- "${@/#--fork-url/}"
set -- "${@/#$network_name/}"
;;
--fork-block-number)
fork_block_number=${@:index+2:1}
Expand All @@ -38,14 +120,31 @@ for arg in "$@"; do
--broadcast)
is_broadcast=true
;;
--sender)
sender=${@:index+2:1}
extra_argument+="sender.${sender}@"
;;
--force-generate-artifact)
force_generate_artifact=true

set -- "${@/#--force-generate-artifact/}"
;;
--help)
usage
exist 1
;;
*) ;;
esac
index=$((index + 1))
done

should_verify=$([[ $should_verify == true && $is_broadcast == true ]] && echo true || echo false)

if [[ $should_verify == true ]]; then
if [[ $force_generate_artifact == true ]]; then
extra_argument+=generate-artifact@
fi

if [[ $should_verify == true ]] && [[ $force_generate_artifact == false ]]; then
extra_argument+=generate-artifact@
fi

Expand All @@ -67,17 +166,16 @@ if [[ ! $extra_argument == *"sender"* ]] && [[ ! $extra_argument == *"trezor"* ]
fi
fi

calldata=$(cast calldata 'run()')
start_time=$(date +%s)

${op_command} forge script ${verify_arg} ${@} -g 200 --sig 'run(bytes,string)' ${calldata} "${extra_argument}"
${op_command} forge script ${verify_arg} ${@} -g 200 --sig 'run(bytes,string)' $(cast calldata 'run()') "${extra_argument}"

# Check if the command was successful
if [ $? -eq 0 ]; then
if [[ $should_verify == true ]]; then
if [[ $network_name == "ronin-mainnet" ]] || [[ $network_name == "ronin-testnet" ]]; then
echo "Verifying contract..."
${op_command} yarn hardhat sourcify --endpoint https://sourcify.roninchain.com/server --network ${network_name}
yarn hardhat sourcify --endpoint https://sourcify.roninchain.com/server --network ${network_name}
fi
fi
fi
Expand Down
97 changes: 0 additions & 97 deletions script/ArtifactFactory.sol

This file was deleted.

43 changes: 16 additions & 27 deletions script/BaseGeneralConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,9 @@ contract BaseGeneralConfig is
function _setUpSender() internal virtual { }

function _setUpDefaultNetworks() private {
setNetworkInfo(
DefaultNetwork.Local.chainId(),
DefaultNetwork.Local.key(),
DefaultNetwork.Local.chainAlias(),
DefaultNetwork.Local.deploymentDir(),
DefaultNetwork.Local.envLabel(),
DefaultNetwork.Local.explorer()
);
setNetworkInfo(
DefaultNetwork.RoninTestnet.chainId(),
DefaultNetwork.RoninTestnet.key(),
DefaultNetwork.RoninTestnet.chainAlias(),
DefaultNetwork.RoninTestnet.deploymentDir(),
DefaultNetwork.RoninTestnet.envLabel(),
DefaultNetwork.RoninTestnet.explorer()
);
setNetworkInfo(
DefaultNetwork.RoninMainnet.chainId(),
DefaultNetwork.RoninMainnet.key(),
DefaultNetwork.RoninMainnet.chainAlias(),
DefaultNetwork.RoninMainnet.deploymentDir(),
DefaultNetwork.RoninMainnet.envLabel(),
DefaultNetwork.RoninMainnet.explorer()
);
setNetworkInfo(DefaultNetwork.Local.data());
setNetworkInfo(DefaultNetwork.RoninTestnet.data());
setNetworkInfo(DefaultNetwork.RoninMainnet.data());

_setUpNetworks();
}
Expand Down Expand Up @@ -142,10 +121,20 @@ contract BaseGeneralConfig is
if (_option.trezor) {
_loadTrezorAccount();
label(block.chainid, _trezorSender, "TrezorSender");
} else if (_option.sender != address(0x0)) {
_envSender = _option.sender;
_trezorSender = _option.sender;

label(block.chainid, _option.sender, "OverrideSender");
} else {
string memory envLabel = getPrivateKeyEnvLabel(getCurrentNetwork());
_loadENVAccount(envLabel);
label(block.chainid, _envSender, "ENVSender");
if (getCurrentNetwork() == DefaultNetwork.Local.key()) {
_envSender = DEFAULT_SENDER;
label(block.chainid, _envSender, "DefaultLocalSender");
} else {
string memory envLabel = getPrivateKeyEnvLabel(getCurrentNetwork());
_loadENVAccount(envLabel);
label(block.chainid, _envSender, "ENVSender");
}
}
}
}
Loading

0 comments on commit c3f9f1c

Please sign in to comment.