Skip to content

Commit

Permalink
Merge pull request #4 from axieinfinity/feature/migration-script
Browse files Browse the repository at this point in the history
feat: refactor migration scripts
  • Loading branch information
TuDo1403 authored Dec 11, 2023
2 parents 7c7891b + 7c7da0e commit cc92d20
Show file tree
Hide file tree
Showing 58 changed files with 1,980 additions and 499 deletions.
10 changes: 10 additions & 0 deletions .debug.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Fork block number to debug
BLOCK=0x0
# Caller
FROM=0x0000000000000000000000000000000000000000
# Callee
TO=0x0000000000000000000000000000000000000000
# Sent Value
VALUE=0x27cdb0997a65b2de99
# Call Data
CALLDATA=0x0
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
url = https://github.com/foundry-rs/forge-std
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/openzeppelin/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/solady"]
path = lib/solady
url = https://github.com/Vectorized/solady
[submodule "lib/contract-libs"]
path = lib/contract-libs
url = https://github.com/axieinfinity/contract-libs
39 changes: 39 additions & 0 deletions debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Source (or "dot") the .env file to load environment variables
if [ -f .env ]; then
source .debug.env
else
echo "Error: .debug.env file not found."
fi

verify_arg=""
extra_argument=""
op_command=""

for arg in "$@"; do
case $arg in
--trezor)
op_command=""
extra_argument+=trezor@
;;
--broadcast)
op_command="op run --env-file="./.env" --"
;;
--log)
set -- "${@/#--log/}"
extra_argument+=log@
;;
*) ;;
esac
done

# Remove the @ character from the end of extra_argument
extra_argument="${extra_argument%%@}"

echo Debug Tx...
echo From: ${FROM}
echo To: ${TO}
echo Value: ${VALUE}
echo Calldata:
cast pretty-calldata ${CALLDATA}
calldata=$(cast calldata 'trace(uint256,address,address,uint256,bytes)' ${BLOCK} ${FROM} ${TO} ${VALUE} ${CALLDATA})
${op_command} forge script ${verify_arg} --legacy ${@} script/OnchainDebugger.s.sol --sig 'run(bytes,string)' ${calldata} "${extra_argument}"
1 change: 1 addition & 0 deletions deployments/ronin-mainnet/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2020
1 change: 1 addition & 0 deletions deployments/ronin-testnet/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2021
12 changes: 10 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
src = "src"
out = "out"
libs = ["lib"]

ffi = true
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

solc = '0.8.21'
solc = '0.8.23'
extra_output = ["devdoc", "userdoc", "storagelayout"]
evm_version = 'istanbul'
use_literal_content = true
Expand All @@ -14,3 +14,11 @@ fs_permissions = [{ access = "read-write", path = "./" }]
[fmt]
line_length = 120
tab_width = 2
bracket_spacing = true

[rpc_endpoints]
ethereum = "https://eth.llamarpc.com"
goerli = "https://ethereum-goerli.publicnode.com"
ronin-mainnet = "https://api-partner.roninchain.com/rpc"
ronin-testnet = "https://saigon-archive.roninchain.com/rpc"
localhost = "http://localhost:8545"
1 change: 1 addition & 0 deletions lib/contract-libs
Submodule contract-libs added at 238860
4 changes: 1 addition & 3 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
@openzeppelin/=lib/openzeppelin-contracts/
foundry-deployment-kit/=script/
27 changes: 27 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
verify_arg=""
extra_argument=""
op_command="op run --env-file="./.env" --"

for arg in "$@"; do
case $arg in
--trezor)
op_command=""
extra_argument+=trezor@
;;
--broadcast)
op_command="op run --env-file="./.env" --"
# verify_arg="--verify --verifier sourcify --verifier-url https://sourcify.roninchain.com/server/"
;;
--log)
set -- "${@/#--log/}"
extra_argument+=log@
;;
*) ;;
esac
done

# Remove the @ character from the end of extra_argument
extra_argument="${extra_argument%%@}"

calldata=$(cast calldata 'run()')
${op_command} forge script ${verify_arg} --legacy ${@} --sig 'run(bytes,string)' ${calldata} "${extra_argument}"
88 changes: 88 additions & 0 deletions script/ArtifactFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { Vm } from "../lib/forge-std/src/Vm.sol";
import { stdJson } from "../lib/forge-std/src/StdJson.sol";
import { StdStyle } from "../lib/forge-std/src/StdStyle.sol";
import { console2 as console } from "../lib/forge-std/src/console2.sol";
import { LibString } from "../lib/solady/src/utils/LibString.sol";
import { JSONParserLib } from "../lib/solady/src/utils/JSONParserLib.sol";
import { IArtifactFactory } from "./interfaces/IArtifactFactory.sol";
import { IGeneralConfig } from "./interfaces/IGeneralConfig.sol";
import { LibSharedAddress } from "./libraries/LibSharedAddress.sol";

contract ArtifactFactory is IArtifactFactory {
using stdJson for *;
using StdStyle for *;
using LibString for *;
using JSONParserLib for *;

Vm internal constant vm = Vm(LibSharedAddress.VM);
IGeneralConfig public constant CONFIG = IGeneralConfig(LibSharedAddress.CONFIG);

function generateArtifact(
address deployer,
address contractAddr,
string memory contractAbsolutePath,
string calldata fileName,
bytes calldata args,
uint256 nonce
) external {
console.log(
string.concat(
fileName,
" will be deployed at: ",
CONFIG.getExplorer(CONFIG.getCurrentNetwork()),
"address/",
contractAddr.toHexString()
).green(),
string.concat("(nonce: ", nonce.toString(), ")")
);
if (!CONFIG.getRuntimeConfig().log) {
console.log("Skipping artifact generation for:", vm.getLabel(contractAddr), "\n");
return;
}
string memory dirPath = CONFIG.getDeploymentDirectory(CONFIG.getCurrentNetwork());
string memory filePath = string.concat(dirPath, fileName, ".json");

string memory json;
uint256 numDeployments = 1;

if (vm.exists(filePath)) {
string memory existedJson = vm.readFile(filePath);
if (vm.keyExists(existedJson, ".numDeployments")) {
numDeployments = vm.parseJsonUint(vm.readFile(filePath), ".numDeployments");
numDeployments += 1;
}
}

json.serialize("args", args);
json.serialize("nonce", nonce);
json.serialize("isFoundry", true);
json.serialize("deployer", deployer);
json.serialize("chainId", block.chainid);
json.serialize("address", contractAddr);
json.serialize("blockNumber", block.number);
json.serialize("timestamp", block.timestamp);
json.serialize("contractAbsolutePath", contractAbsolutePath);
json.serialize("numDeployments", numDeployments);

string[] memory s = contractAbsolutePath.split(":");
string memory artifactPath = s.length == 2
? string.concat("./out/", s[0], "/", s[1], ".json")
: string.concat("./out/", contractAbsolutePath, "/", contractAbsolutePath.replace(".sol", ".json"));
string memory artifact = vm.readFile(artifactPath);
JSONParserLib.Item memory item = artifact.parse();

json.serialize("abi", item.at('"abi"').value());
json.serialize("ast", item.at('"ast"').value());
json.serialize("devdoc", item.at('"devdoc"').value());
json.serialize("userdoc", item.at('"userdoc"').value());
json.serialize("metadata", item.at('"rawMetadata"').value());
json.serialize("storageLayout", item.at('"storageLayout"').value());
json.serialize("bytecode", item.at('"bytecode"').at('"object"').value());
json = json.serialize("deployedBytecode", item.at('"deployedBytecode"').at('"object"').value());

json.write(filePath);
}
}
144 changes: 0 additions & 144 deletions script/BaseDeploy.s.sol

This file was deleted.

Loading

0 comments on commit cc92d20

Please sign in to comment.