Skip to content

Commit

Permalink
feat: remove contract-libs and add install.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
TuDo1403 committed Jun 16, 2024
1 parent b3dff81 commit 52167eb
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 13 deletions.
3 changes: 1 addition & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ localhost = "http://localhost:8545"
[dependencies]
forge-std = { version = "1.8.2" }
solady = { version = "0.0.206" }
"@openzeppelin-contracts" = { version = "4.9.3" }
contract-libs = { version = "0.1.1", url = "https://github.com/axieinfinity/contract-libs/archive/refs/tags/release-v0.1.1.zip" }
"@openzeppelin-contracts" = { version = "4.9.3" }
16 changes: 16 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Install foundryup
curl -L https://foundry.paradigm.xyz | bash
# Install foundry
$HOME/.foundry/bin/foundryup -v nightly-de33b6af53005037b463318d2628b5cfcaf39916 # Stable version
# Install rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Update rustup
$HOME/.cargo/bin/rustup update stable
# Install soldeer
$HOME/.cargo/bin/cargo install soldeer
# Update dependencies with soldeer
$HOME/.cargo/bin/soldeer update
# Run forge build
$HOME/.foundry/bin/forge build
# Install jq
brew install jq
2 changes: 1 addition & 1 deletion script/OnchainExecutor.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { console } from "../dependencies/forge-std-1.8.2/src/console.sol";
import { ScriptExtended } from "./extensions/ScriptExtended.s.sol";
import { BaseGeneralConfig } from "./BaseGeneralConfig.sol";
import { sendRawTransaction } from "./utils/Helpers.sol";
import { LibErrorHandler } from "../dependencies/contract-libs-0.1.1/src/LibErrorHandler.sol";
import { LibErrorHandler } from "./libraries/LibErrorHandler.sol";

contract OnchainExecutor is ScriptExtended {
using LibErrorHandler for bool;
Expand Down
2 changes: 1 addition & 1 deletion script/extensions/ScriptExtended.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { StdAssertions } from "../../dependencies/forge-std-1.8.2/src/StdAsserti
import { IVme } from "../interfaces/IVme.sol";
import { IRuntimeConfig } from "../interfaces/configs/IRuntimeConfig.sol";
import { IScriptExtended } from "../interfaces/IScriptExtended.sol";
import { LibErrorHandler } from "../../dependencies/contract-libs-0.1.1/src/LibErrorHandler.sol";
import { LibErrorHandler } from "../libraries/LibErrorHandler.sol";
import { LibSharedAddress } from "../libraries/LibSharedAddress.sol";
import { TContract } from "../types/TContract.sol";
import { TNetwork } from "../types/TNetwork.sol";
Expand Down
40 changes: 40 additions & 0 deletions script/libraries/LibErrorHandler.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

library LibErrorHandler {
/// @dev Reserves error definition to upload to signature database.
error ExternalCallFailed(bytes4 msgSig, bytes4 callSig);

/// @notice handle low level call revert if call failed,
/// If external call return empty bytes, reverts with custom error.
/// @param status Status of external call
/// @param callSig function signature of the calldata
/// @param returnOrRevertData bytes result from external call
function handleRevert(bool status, bytes4 callSig, bytes memory returnOrRevertData) internal pure {
// Get the function signature of current context
bytes4 msgSig = msg.sig;
assembly ("memory-safe") {
if iszero(status) {
// Load the length of bytes array
let revertLength := mload(returnOrRevertData)
// Check if length != 0 => revert following reason from external call
if iszero(iszero(revertLength)) {
// Start of revert data bytes. The 0x20 offset is always the same.
revert(add(returnOrRevertData, 0x20), revertLength)
}

// Load free memory pointer
let ptr := mload(0x40)
// Store 4 bytes the function selector of ExternalCallFailed(msg.sig, callSig)
// Equivalent to revert ExternalCallFailed(bytes4,bytes4)
mstore(ptr, 0x49bf4104)
// Store 4 bytes of msgSig parameter in the next slot
mstore(add(ptr, 0x20), msgSig)
// Store 4 bytes of callSig parameter in the next slot
mstore(add(ptr, 0x40), callSig)
// Revert 68 bytes of error starting from 0x1c
revert(add(ptr, 0x1c), 0x44)
}
}
}
}
2 changes: 1 addition & 1 deletion script/utils/Helpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { stdJson } from "../../dependencies/forge-std-1.8.2/src/StdJson.sol";
import { console } from "../../dependencies/forge-std-1.8.2/src/console.sol";
import { StdStyle } from "../../dependencies/forge-std-1.8.2/src/StdStyle.sol";
import { LibSharedAddress } from "../libraries/LibSharedAddress.sol";
import { LibErrorHandler } from "../../dependencies/contract-libs-0.1.1/src/LibErrorHandler.sol";
import { LibErrorHandler } from "../libraries/LibErrorHandler.sol";
import { LibString } from "../../dependencies/solady-0.0.206/src/utils/LibString.sol";
import { JSONParserLib } from "../../dependencies/solady-0.0.206/src/utils/JSONParserLib.sol";
import { TContract } from "../types/TContract.sol";
Expand Down
6 changes: 0 additions & 6 deletions soldeer.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ version = "4.9.3"
source = "https://soldeer-revisions.s3.amazonaws.com/@openzeppelin-contracts/4_9_3_22-01-2024_13:13:53_contracts.zip"
checksum = "95886307069cf73310b41396c49df51801a73f31f18f62e7d05adfc2031e7725"

[[dependencies]]
name = "contract-libs"
version = "0.1.1"
source = "https://github.com/axieinfinity/contract-libs/archive/refs/tags/release-v0.1.1.zip"
checksum = "4eab7ea5ba459b1564dd52da6413d4da2acd32e523c3fb3eac2b8309a89bf582"

[[dependencies]]
name = "forge-std"
version = "1.8.2"
Expand Down
4 changes: 2 additions & 2 deletions src/mocks/WNT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity ^0.8.17;

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

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

receive() external payable virtual {
Expand Down

0 comments on commit 52167eb

Please sign in to comment.