diff --git a/foundry.toml b/foundry.toml index d79689c..01a66e8 100644 --- a/foundry.toml +++ b/foundry.toml @@ -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" } \ No newline at end of file +"@openzeppelin-contracts" = { version = "4.9.3" } \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..5436dc4 --- /dev/null +++ b/install.sh @@ -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 \ No newline at end of file diff --git a/script/OnchainExecutor.s.sol b/script/OnchainExecutor.s.sol index a61d92d..8a22c01 100644 --- a/script/OnchainExecutor.s.sol +++ b/script/OnchainExecutor.s.sol @@ -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; diff --git a/script/extensions/ScriptExtended.s.sol b/script/extensions/ScriptExtended.s.sol index 7f406c9..bd127de 100644 --- a/script/extensions/ScriptExtended.s.sol +++ b/script/extensions/ScriptExtended.s.sol @@ -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"; diff --git a/script/libraries/LibErrorHandler.sol b/script/libraries/LibErrorHandler.sol new file mode 100644 index 0000000..5464852 --- /dev/null +++ b/script/libraries/LibErrorHandler.sol @@ -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) + } + } + } +} diff --git a/script/utils/Helpers.sol b/script/utils/Helpers.sol index f1246b6..21214c1 100644 --- a/script/utils/Helpers.sol +++ b/script/utils/Helpers.sol @@ -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"; diff --git a/soldeer.lock b/soldeer.lock index a1bbf05..c9921b1 100644 --- a/soldeer.lock +++ b/soldeer.lock @@ -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" diff --git a/src/mocks/WNT.sol b/src/mocks/WNT.sol index 4c0a215..b880ebc 100644 --- a/src/mocks/WNT.sol +++ b/src/mocks/WNT.sol @@ -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 @@ -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 {