Skip to content

Commit

Permalink
Merge pull request #150 from axieinfinity/implement-feature/rework/fi…
Browse files Browse the repository at this point in the history
…x-logic-warp-on-local

feat(rework): implement `fix-logic-warp-on-local`
  • Loading branch information
TuDo1403 authored Jun 16, 2024
2 parents 1521acf + 261b62d commit 2c141ee
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 8 deletions.
8 changes: 5 additions & 3 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,15 @@ if [[ ! $extra_argument == *"sender"* ]] && [[ ! $extra_argument == *"trezor"* ]
# Check if the .env file exists
if [ -f .env ]; then
source .env
# If network_name is empty, set it to localhost
network_name=${network_name:-localhost}
# Convert network name to uppercase
account_label=$(echo $network_name | tr '[:lower:]' '[:upper:]')
# Replace "-" with "_"
account_label=$(echo $account_label | tr '-' '_')
# Add "_PK" prefix
account_label="${account_label}_PK"

# Check if the private key is stored in the .env file
if [[ $(eval "echo \$$account_label") == *"op://"* ]]; then
echo "\033[32mFound 'op://' in ${account_label}\033[0m"
Expand Down Expand Up @@ -204,8 +206,6 @@ if [ $? -eq 0 ]; then
yarn hardhat sourcify --endpoint https://sourcify.roninchain.com/server --network ${network_name} --contract-name $deployed
done <./logs/deployed-contracts

# Remove the deployed-contracts file
rm ./logs/deployed-contracts
# Restore the .env content
echo $env_data >.env
fi
Expand All @@ -214,4 +214,6 @@ fi

end_time=$(date +%s)

# Remove the deployed-contracts file
rm -rf ./logs/deployed-contracts
echo "Execution time: $((end_time - start_time))s"
3 changes: 2 additions & 1 deletion script/extensions/ScriptExtended.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ abstract contract ScriptExtended is BaseScriptExtended, Script, StdAssertions, I
if (runtimeConfig.network != network()) {
switchTo(runtimeConfig.network, runtimeConfig.forkBlockNumber);
} else {
if (vm.getBlockTimestamp() == 0) vm.warp(vm.unixTime() / 1_000);
uint256 currUnixTimestamp = vm.unixTime() / 1_000;
if (vm.getBlockTimestamp() < currUnixTimestamp) vm.warp(currUnixTimestamp);
if (runtimeConfig.forkBlockNumber != 0) vme.rollUpTo(runtimeConfig.forkBlockNumber);

vme.logSenderInfo();
Expand Down
9 changes: 5 additions & 4 deletions script/libraries/LibArtifact.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ library LibArtifact {
return;
}

console.log(string.concat("By: ", vm.getLabel(info.deployer), ", nonce: ", vm.toString(info.nonce), "\n"));
if (!vm.exists("logs")) vm.createDir("logs", true);
vm.writeLine("logs/deployed-contracts", info.artifactName);

string memory dirPath = vme.getDeploymentDirectory(vme.getCurrentNetwork());

_tryCreateDir(dirPath);
Expand Down Expand Up @@ -81,7 +85,7 @@ library LibArtifact {
json = json.serialize("deployedBytecode", parsedArtifact.at('"deployedBytecode"').at('"object"').value());
}

function _logDeployment(ArtifactInfo memory info) internal {
function _logDeployment(ArtifactInfo memory info) internal view {
console.log(
string.concat(
vm.getLabel(info.addr),
Expand All @@ -91,9 +95,6 @@ library LibArtifact {
info.addr.toHexString().cyan()
).green()
);
console.log(string.concat("By: ", vm.getLabel(info.deployer), ", nonce: ", vm.toString(info.nonce), "\n"));
if (!vm.exists("logs")) vm.createDir("logs", true);
vm.writeLine("logs/deployed-contracts", info.artifactName);
}

function _tryCreateDir(string memory dirPath) private {
Expand Down
1 change: 1 addition & 0 deletions script/libraries/LibDeploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ library LibDeploy {
deployed = _deployRaw(callValue, bytecode, by);

require(deployed != address(0x0), "LibDeploy: deployFromBytecode(bytes,bytes,uint256,address): Deployment failed.");
require(deployed.code.length > 0, "LibDeploy: deployFromBytecode(bytes,bytes,uint256,address): Empty code.");

vme.label(vme.getCurrentNetwork(), deployed, artifactName);

Expand Down
58 changes: 58 additions & 0 deletions script/sample/contracts/SampleProxyDeployV2.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.2 <0.9.0;
pragma experimental ABIEncoderV2;

import { SampleProxy } from "src/mocks/SampleProxy.sol";
import { Contract } from "../utils/Contract.sol";
import { TContract } from "../../types/TContract.sol";
import { ISharedArgument, SampleMigration } from "../SampleMigration.s.sol";
import { DeployInfo, LibDeploy } from "../../libraries/LibDeploy.sol";
import { LibString } from "../../../dependencies/solady-0.0.206/src/utils/LibString.sol";

contract SampleProxyV2Deploy is SampleMigration {
using LibString for bytes32;

function _defaultArguments() internal virtual override returns (bytes memory args) {
ISharedArgument.SharedParameter memory param = ISharedArgument(address(vme)).sharedArguments();
args = abi.encodeCall(SampleProxy.initialize, (param.proxyMessage));
}

function run() public virtual returns (SampleProxy instance) {
instance = SampleProxy(_deployProxy(Contract.SampleProxy.key()));
assertEq(instance.getMessage(), ISharedArgument(address(vme)).sharedArguments().proxyMessage);
}

function _deployProxy(
TContract contractType,
string memory artifactName,
address proxyAdmin,
uint256 callValue,
address by,
bytes memory callData,
bytes memory logicConstructorArgs
)
internal
virtual
override
logFn(string.concat("_deployProxy ", TContract.unwrap(contractType).unpackOne()))
returns (address payable deployed)
{
string memory contractName = vme.getContractName(contractType);

deployed = LibDeploy.deployTransparentProxyV2({
implInfo: DeployInfo({
callValue: 0,
by: by,
contractName: contractName,
absolutePath: vme.getContractAbsolutePath(contractType),
artifactName: bytes(artifactName).length == 0 ? contractName : artifactName,
constructorArgs: logicConstructorArgs
}),
callValue: callValue,
proxyAdmin: proxyAdmin,
callData: callData
});

vme.setAddress(network(), contractType, deployed);
}
}

0 comments on commit 2c141ee

Please sign in to comment.