Skip to content

Commit 1521acf

Browse files
authored
Merge pull request #149 from axieinfinity/implement-feature/rework/remove-contract-libs-and-add-install
feat(rework): implement `remove-contract-libs-and-add-install`
2 parents b3dff81 + 52167eb commit 1521acf

File tree

8 files changed

+62
-13
lines changed

8 files changed

+62
-13
lines changed

foundry.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,4 @@ localhost = "http://localhost:8545"
2727
[dependencies]
2828
forge-std = { version = "1.8.2" }
2929
solady = { version = "0.0.206" }
30-
"@openzeppelin-contracts" = { version = "4.9.3" }
31-
contract-libs = { version = "0.1.1", url = "https://github.com/axieinfinity/contract-libs/archive/refs/tags/release-v0.1.1.zip" }
30+
"@openzeppelin-contracts" = { version = "4.9.3" }

install.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Install foundryup
2+
curl -L https://foundry.paradigm.xyz | bash
3+
# Install foundry
4+
$HOME/.foundry/bin/foundryup -v nightly-de33b6af53005037b463318d2628b5cfcaf39916 # Stable version
5+
# Install rustup
6+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
7+
# Update rustup
8+
$HOME/.cargo/bin/rustup update stable
9+
# Install soldeer
10+
$HOME/.cargo/bin/cargo install soldeer
11+
# Update dependencies with soldeer
12+
$HOME/.cargo/bin/soldeer update
13+
# Run forge build
14+
$HOME/.foundry/bin/forge build
15+
# Install jq
16+
brew install jq

script/OnchainExecutor.s.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { console } from "../dependencies/forge-std-1.8.2/src/console.sol";
77
import { ScriptExtended } from "./extensions/ScriptExtended.s.sol";
88
import { BaseGeneralConfig } from "./BaseGeneralConfig.sol";
99
import { sendRawTransaction } from "./utils/Helpers.sol";
10-
import { LibErrorHandler } from "../dependencies/contract-libs-0.1.1/src/LibErrorHandler.sol";
10+
import { LibErrorHandler } from "./libraries/LibErrorHandler.sol";
1111

1212
contract OnchainExecutor is ScriptExtended {
1313
using LibErrorHandler for bool;

script/extensions/ScriptExtended.s.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { StdAssertions } from "../../dependencies/forge-std-1.8.2/src/StdAsserti
99
import { IVme } from "../interfaces/IVme.sol";
1010
import { IRuntimeConfig } from "../interfaces/configs/IRuntimeConfig.sol";
1111
import { IScriptExtended } from "../interfaces/IScriptExtended.sol";
12-
import { LibErrorHandler } from "../../dependencies/contract-libs-0.1.1/src/LibErrorHandler.sol";
12+
import { LibErrorHandler } from "../libraries/LibErrorHandler.sol";
1313
import { LibSharedAddress } from "../libraries/LibSharedAddress.sol";
1414
import { TContract } from "../types/TContract.sol";
1515
import { TNetwork } from "../types/TNetwork.sol";

script/libraries/LibErrorHandler.sol

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.19;
3+
4+
library LibErrorHandler {
5+
/// @dev Reserves error definition to upload to signature database.
6+
error ExternalCallFailed(bytes4 msgSig, bytes4 callSig);
7+
8+
/// @notice handle low level call revert if call failed,
9+
/// If external call return empty bytes, reverts with custom error.
10+
/// @param status Status of external call
11+
/// @param callSig function signature of the calldata
12+
/// @param returnOrRevertData bytes result from external call
13+
function handleRevert(bool status, bytes4 callSig, bytes memory returnOrRevertData) internal pure {
14+
// Get the function signature of current context
15+
bytes4 msgSig = msg.sig;
16+
assembly ("memory-safe") {
17+
if iszero(status) {
18+
// Load the length of bytes array
19+
let revertLength := mload(returnOrRevertData)
20+
// Check if length != 0 => revert following reason from external call
21+
if iszero(iszero(revertLength)) {
22+
// Start of revert data bytes. The 0x20 offset is always the same.
23+
revert(add(returnOrRevertData, 0x20), revertLength)
24+
}
25+
26+
// Load free memory pointer
27+
let ptr := mload(0x40)
28+
// Store 4 bytes the function selector of ExternalCallFailed(msg.sig, callSig)
29+
// Equivalent to revert ExternalCallFailed(bytes4,bytes4)
30+
mstore(ptr, 0x49bf4104)
31+
// Store 4 bytes of msgSig parameter in the next slot
32+
mstore(add(ptr, 0x20), msgSig)
33+
// Store 4 bytes of callSig parameter in the next slot
34+
mstore(add(ptr, 0x40), callSig)
35+
// Revert 68 bytes of error starting from 0x1c
36+
revert(add(ptr, 0x1c), 0x44)
37+
}
38+
}
39+
}
40+
}

script/utils/Helpers.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { stdJson } from "../../dependencies/forge-std-1.8.2/src/StdJson.sol";
77
import { console } from "../../dependencies/forge-std-1.8.2/src/console.sol";
88
import { StdStyle } from "../../dependencies/forge-std-1.8.2/src/StdStyle.sol";
99
import { LibSharedAddress } from "../libraries/LibSharedAddress.sol";
10-
import { LibErrorHandler } from "../../dependencies/contract-libs-0.1.1/src/LibErrorHandler.sol";
10+
import { LibErrorHandler } from "../libraries/LibErrorHandler.sol";
1111
import { LibString } from "../../dependencies/solady-0.0.206/src/utils/LibString.sol";
1212
import { JSONParserLib } from "../../dependencies/solady-0.0.206/src/utils/JSONParserLib.sol";
1313
import { TContract } from "../types/TContract.sol";

soldeer.lock

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ version = "4.9.3"
55
source = "https://soldeer-revisions.s3.amazonaws.com/@openzeppelin-contracts/4_9_3_22-01-2024_13:13:53_contracts.zip"
66
checksum = "95886307069cf73310b41396c49df51801a73f31f18f62e7d05adfc2031e7725"
77

8-
[[dependencies]]
9-
name = "contract-libs"
10-
version = "0.1.1"
11-
source = "https://github.com/axieinfinity/contract-libs/archive/refs/tags/release-v0.1.1.zip"
12-
checksum = "4eab7ea5ba459b1564dd52da6413d4da2acd32e523c3fb3eac2b8309a89bf582"
13-
148
[[dependencies]]
159
name = "forge-std"
1610
version = "1.8.2"

src/mocks/WNT.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pragma solidity ^0.8.17;
33

44
import { ERC20 } from "../../dependencies/@openzeppelin-contracts-4.9.3//token/ERC20/ERC20.sol";
55
import { IWNT } from "./interfaces/IWNT.sol";
6-
import { LibNativeTransfer } from "../../dependencies/contract-libs-0.1.1/src/transfers/LibNativeTransfer.sol";
76

87
/// @notice Minimalist and modern Wrapped Ether implementation.
98
/// @author Solmate
@@ -23,7 +22,8 @@ contract WNT is IWNT, ERC20 {
2322
address sender = _msgSender();
2423
_burn(sender, amount);
2524
emit Withdrawal(sender, amount);
26-
LibNativeTransfer.transfer(sender, amount, 2300);
25+
(bool success,) = sender.call{ value: amount }("");
26+
require(success, "WNT: Native transfer failed");
2727
}
2828

2929
receive() external payable virtual {

0 commit comments

Comments
 (0)