Skip to content

Commit cf6be21

Browse files
authored
Merge pull request #51 from axieinfinity/release/v0.2.0
chore: merge all features from 'release/v0.2.0'
2 parents e17e269 + 51c6d91 commit cf6be21

18 files changed

+437
-148
lines changed

.broadcast.env.example

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Fork block number to debug
2+
BLOCK=0x0
3+
# Caller
4+
FROM=0x0000000000000000000000000000000000000000
5+
# Callee
6+
TO=0x0000000000000000000000000000000000000000
7+
# Sent Value
8+
VALUE=0
9+
# Gas Amount
10+
GAS=0
11+
# Call Data
12+
CALLDATA=0x0

.debug.env.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ FROM=0x0000000000000000000000000000000000000000
55
# Callee
66
TO=0x0000000000000000000000000000000000000000
77
# Sent Value
8-
VALUE=0x27cdb0997a65b2de99
8+
VALUE=0
9+
# Gas Amount
10+
GAS=0
911
# Call Data
1012
CALLDATA=0x0

broadcast.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Source (or "dot") the .env file to load environment variables
2+
if [ -f .env ]; then
3+
source .broadcast.env
4+
else
5+
echo "Error: .broadcast.env file not found."
6+
fi
7+
8+
verify_arg=""
9+
extra_argument=""
10+
11+
for arg in "$@"; do
12+
case $arg in
13+
--trezor)
14+
extra_argument+=trezor@
15+
;;
16+
*) ;;
17+
esac
18+
done
19+
20+
# Remove the @ character from the end of extra_argument
21+
extra_argument="${extra_argument%%@}"
22+
23+
echo Broadcast Tx...
24+
echo From: ${FROM}
25+
echo To: ${TO}
26+
echo Value: ${VALUE}
27+
echo GasAmount: ${GAS}
28+
echo Calldata:
29+
cast pretty-calldata ${CALLDATA}
30+
calldata=$(cast calldata 'broadcast(address,address,uint256,uint256,bytes)' ${FROM} ${TO} ${GAS} ${VALUE} ${CALLDATA})
31+
forge script ${verify_arg} ${@} -g 200 OnchainExecutor --sig 'run(bytes,string)' ${calldata} "${extra_argument}"

debug.sh

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,12 @@ fi
77

88
verify_arg=""
99
extra_argument=""
10-
op_command="op run --env-file="./.env" --"
1110

1211
for arg in "$@"; do
1312
case $arg in
1413
--trezor)
15-
op_command=""
1614
extra_argument+=trezor@
1715
;;
18-
--broadcast)
19-
op_command="op run --env-file="./.env" --"
20-
;;
21-
--log)
22-
set -- "${@/#--log/}"
23-
extra_argument+=log@
24-
;;
2516
*) ;;
2617
esac
2718
done
@@ -33,7 +24,8 @@ echo Debug Tx...
3324
echo From: ${FROM}
3425
echo To: ${TO}
3526
echo Value: ${VALUE}
27+
echo GasAmount: ${GAS}
3628
echo Calldata:
3729
cast pretty-calldata ${CALLDATA}
38-
calldata=$(cast calldata 'trace(uint256,address,address,uint256,bytes)' ${BLOCK} ${FROM} ${TO} ${VALUE} ${CALLDATA})
39-
${op_command} forge script ${verify_arg} --legacy ${@} OnchainDebugger --sig 'run(bytes,string)' ${calldata} "${extra_argument}"
30+
calldata=$(cast calldata 'trace(uint256,address,address,uint256,uint256,bytes)' ${BLOCK} ${FROM} ${TO} ${GAS} ${VALUE} ${CALLDATA})
31+
forge script ${verify_arg} --legacy ${@} OnchainExecutor --sig 'run(bytes,string)' ${calldata} "${extra_argument}"

run.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
verify_arg=""
22
extra_argument=""
3-
op_command="op run --env-file="./.env" --"
43

54
for arg in "$@"; do
65
case $arg in
76
--trezor)
8-
op_command=""
97
extra_argument+=trezor@
108
;;
11-
--broadcast)
12-
op_command="op run --env-file="./.env" --"
13-
# verify_arg="--verify --verifier sourcify --verifier-url https://sourcify.roninchain.com/server/"
14-
;;
159
--log)
1610
set -- "${@/#--log/}"
1711
extra_argument+=log@
@@ -24,4 +18,4 @@ done
2418
extra_argument="${extra_argument%%@}"
2519

2620
calldata=$(cast calldata 'run()')
27-
${op_command} forge script ${verify_arg} --legacy ${@} --sig 'run(bytes,string)' ${calldata} "${extra_argument}"
21+
forge script ${verify_arg} ${@} -g 200 --sig 'run(bytes,string)' ${calldata} "${extra_argument}"

script/BaseGeneralConfig.sol

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.19;
33

4-
import { Vm } from "../lib/forge-std/src/Vm.sol";
4+
import { Vm, VmSafe } from "../lib/forge-std/src/Vm.sol";
55
import { StdStyle } from "../lib/forge-std/src/StdStyle.sol";
66
import { console2 as console } from "../lib/forge-std/src/console2.sol";
7-
import { LibString } from "../lib/solady/src/utils/LibString.sol";
87
import { WalletConfig } from "./configs/WalletConfig.sol";
98
import { RuntimeConfig } from "./configs/RuntimeConfig.sol";
109
import { MigrationConfig } from "./configs/MigrationConfig.sol";
@@ -17,11 +16,8 @@ import { LibSharedAddress } from "./libraries/LibSharedAddress.sol";
1716

1817
contract BaseGeneralConfig is RuntimeConfig, WalletConfig, ContractConfig, NetworkConfig, MigrationConfig {
1918
using StdStyle for string;
20-
using LibString for string;
2119
using EnumerableSet for EnumerableSet.AddressSet;
2220

23-
Vm internal constant vm = Vm(LibSharedAddress.VM);
24-
2521
fallback() external {
2622
if (msg.sig == ISharedParameter.sharedArguments.selector) {
2723
bytes memory returnData = getRawSharedArguments();
@@ -91,19 +87,12 @@ contract BaseGeneralConfig is RuntimeConfig, WalletConfig, ContractConfig, Netwo
9187
}
9288

9389
function _setUpDefaultSender() private {
94-
// by default we will read private key from .env
95-
_envPk = vm.envUint(getPrivateKeyEnvLabel(getCurrentNetwork()));
96-
_envSender = vm.rememberKey(_envPk);
97-
98-
label(block.chainid, _envSender, "ENVSender");
99-
console.log("GeneralConfig:", vm.getLabel(_envSender));
100-
10190
_setUpSender();
10291
}
10392

10493
function getSender() public view virtual override returns (address payable sender) {
10594
sender = _option.trezor ? payable(_trezorSender) : payable(_envSender);
106-
require(sender != address(0), "GeneralConfig: Sender is address(0x0)");
95+
require(sender != address(0x0), "GeneralConfig: Sender is address(0x0)");
10796
}
10897

10998
function setAddress(TNetwork network, TContract contractType, address contractAddr) public virtual {
@@ -127,10 +116,14 @@ contract BaseGeneralConfig is RuntimeConfig, WalletConfig, ContractConfig, Netwo
127116

128117
function _handleRuntimeConfig() internal virtual override {
129118
if (_option.trezor) {
130-
string memory str = vm.envString(deployerEnvLabel());
131-
_trezorSender = vm.parseAddress(str.replace(trezorPrefix(), ""));
119+
_loadTrezorAccount();
132120
label(block.chainid, _trezorSender, "TrezorSender");
133-
console.log("GeneralConfig:", vm.getLabel(_trezorSender));
121+
console.log("GeneralConfig:", vm.getLabel(_trezorSender), "Enabled!");
122+
} else {
123+
string memory envLabel = getPrivateKeyEnvLabel(getCurrentNetwork());
124+
_loadENVAccount(envLabel);
125+
label(block.chainid, _envSender, "ENVSender");
126+
console.log("GeneralConfig:", vm.getLabel(_envSender), "Enabled!");
134127
}
135128
}
136129
}

script/BaseMigration.s.sol

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import {
99
import { LibString } from "../lib/solady/src/utils/LibString.sol";
1010
import { console, LibSharedAddress, StdStyle, IScriptExtended, ScriptExtended } from "./extensions/ScriptExtended.s.sol";
1111
import { IArtifactFactory, ArtifactFactory } from "./ArtifactFactory.sol";
12-
import { OnchainDebugger } from "./OnchainDebugger.s.sol"; // cheat to load artifact to parent `out` directory
12+
import { OnchainExecutor } from "./OnchainExecutor.s.sol"; // cheat to load artifact to parent `out` directory
1313
import { IMigrationScript } from "./interfaces/IMigrationScript.sol";
1414
import { LibProxy } from "./libraries/LibProxy.sol";
1515
import { DefaultContract } from "./utils/DefaultContract.sol";
1616
import { TContract } from "./types/Types.sol";
1717

1818
abstract contract BaseMigration is ScriptExtended {
19-
using StdStyle for string;
19+
using StdStyle for *;
2020
using LibString for bytes32;
2121
using LibProxy for address payable;
2222

@@ -232,6 +232,7 @@ abstract contract BaseMigration is ScriptExtended {
232232
function _upgradeRaw(address proxyAdmin, address payable proxy, address logic, bytes memory args) internal virtual {
233233
ITransparentUpgradeableProxy iProxy = ITransparentUpgradeableProxy(proxy);
234234
ProxyAdmin wProxyAdmin = ProxyAdmin(proxyAdmin);
235+
235236
// if proxyAdmin is External Owned Wallet
236237
if (proxyAdmin.code.length == 0) {
237238
vm.broadcast(proxyAdmin);
@@ -240,31 +241,91 @@ abstract contract BaseMigration is ScriptExtended {
240241
} else {
241242
try wProxyAdmin.owner() returns (address owner) {
242243
if (args.length == 0) {
243-
// try `upgrade` function
244+
// try `upgrade(address,address)` function
244245
vm.prank(owner);
245246
(bool success,) = proxyAdmin.call(abi.encodeCall(ProxyAdmin.upgrade, (iProxy, logic)));
246247
if (success) {
247-
vm.broadcast(owner);
248-
wProxyAdmin.upgrade(iProxy, logic);
248+
if (owner.code.length != 0) {
249+
_cheatUpgrade(owner, wProxyAdmin, iProxy, logic);
250+
} else {
251+
vm.broadcast(owner);
252+
wProxyAdmin.upgrade(iProxy, logic);
253+
}
249254
} else {
250255
console.log(
251-
StdStyle.yellow(
252-
"`ProxyAdmin:upgrade` failed!. Retrying with `ProxyAdmin:upgradeAndCall` with emty args..."
253-
)
256+
"`ProxyAdmin:upgrade` failed!. Retrying with `ProxyAdmin:upgradeAndCall` with emty args...".yellow()
254257
);
258+
if (owner.code.length != 0) {
259+
_cheatUpgradeAndCall(owner, wProxyAdmin, iProxy, logic, args);
260+
} else {
261+
vm.broadcast(owner);
262+
wProxyAdmin.upgradeAndCall(iProxy, logic, args);
263+
}
264+
}
265+
} else {
266+
if (owner.code.length != 0) {
267+
_cheatUpgradeAndCall(owner, wProxyAdmin, iProxy, logic, args);
268+
} else {
255269
vm.broadcast(owner);
256270
wProxyAdmin.upgradeAndCall(iProxy, logic, args);
257271
}
258-
} else {
259-
vm.broadcast(owner);
260-
wProxyAdmin.upgradeAndCall(iProxy, logic, args);
261272
}
262273
} catch {
263274
revert("BaseMigration: Unknown ProxyAdmin contract!");
264275
}
265276
}
266277
}
267278

279+
function _cheatUpgrade(address owner, ProxyAdmin wProxyAdmin, ITransparentUpgradeableProxy iProxy, address logic)
280+
internal
281+
virtual
282+
{
283+
bytes memory callData = abi.encodeCall(ProxyAdmin.upgrade, (iProxy, logic));
284+
console.log(
285+
"------------------------------------------------------------------------------- Multi-Sig Proposal -------------------------------------------------------------------------------"
286+
);
287+
console.log("To:".cyan(), vm.getLabel(address(wProxyAdmin)));
288+
console.log(
289+
"Method:\n".cyan(),
290+
string.concat(" - upgrade(address,address)\n - ", vm.getLabel(address(iProxy)), "\n - ", vm.getLabel(logic))
291+
);
292+
console.log("Raw Calldata Data:\n".cyan(), string.concat(" - ", vm.toString(callData)));
293+
console.log(
294+
"----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
295+
);
296+
297+
// cheat prank to update `implementation slot` for next call
298+
vm.prank(owner);
299+
wProxyAdmin.upgrade(iProxy, logic);
300+
}
301+
302+
function _cheatUpgradeAndCall(
303+
address owner,
304+
ProxyAdmin wProxyAdmin,
305+
ITransparentUpgradeableProxy iProxy,
306+
address logic,
307+
bytes memory args
308+
) internal virtual {
309+
bytes memory callData = abi.encodeCall(ProxyAdmin.upgradeAndCall, (iProxy, logic, args));
310+
console.log(
311+
"------------------------------------------------------------------------------- Multi-Sig Proposal -------------------------------------------------------------------------------"
312+
);
313+
console.log("To:".cyan(), vm.getLabel(address(wProxyAdmin)));
314+
console.log(
315+
"Method:\n".cyan(),
316+
" - upgradeAndCall(address,address,bytes)\n",
317+
string.concat(" - ", vm.getLabel(address(iProxy)), "\n - ", vm.getLabel(logic), "\n - ", vm.toString(args))
318+
);
319+
console.log("Raw Call Data:\n".cyan(), " - ", vm.toString(callData));
320+
console.log(
321+
"----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
322+
);
323+
324+
// cheat prank to update `implementation slot` for next call
325+
vm.prank(owner);
326+
wProxyAdmin.upgradeAndCall(iProxy, logic, args);
327+
}
328+
268329
function _setDependencyDeployScript(TContract contractType, IScriptExtended deployScript) internal virtual {
269330
_deployScript[contractType] = IMigrationScript(address(deployScript));
270331
}

script/OnchainDebugger.s.sol

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)