Created
September 3, 2024 07:48
-
-
Save m-waqas88/5dded4aae40b4716be4dcd8f671bac74 to your computer and use it in GitHub Desktop.
Custom smart contract auditing script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.9; | |
import {Script} from "forge-std/Script.sol"; | |
// import "contracts/access/MidasAccessControl.sol"; | |
// import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; | |
struct Ctx { | |
uint256 counter; | |
mapping(uint256 => string) variables; | |
mapping(string => bytes32) variableType; | |
mapping(uint256 => bytes) states; | |
} | |
contract BaseScript is Script { | |
Ctx internal ctx; | |
// Variables, events, errors sb yaha hongy | |
// From local anvil node | |
address WAQAS = 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720; | |
uint256 WAQAS_KEY = 0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6; | |
address HARIS = 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266; | |
uint256 HARIS_KEY = 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80; | |
// From mainnet | |
address USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; | |
address USDC_WHALE = 0x3f8a8DF5ffC35f9aC7CeA4b18656663Cd1E0eb9d; | |
address USDC_DATA_FEED = 0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6; | |
// Deployed Smart Contracts | |
// MidasAccessControl accessControl; | |
function _watch(string memory _label, bytes calldata _value) internal { | |
bytes32 myType = keccak256("BYTES"); | |
ctx.variables[ctx.counter] = _label; | |
ctx.variableType[_label] = myType; | |
ctx.states[ctx.counter] = abi.encode(_value); | |
ctx.counter++; | |
} | |
function _watch(string memory _label, bytes32 _value) internal { | |
bytes32 myType = keccak256("BYTES32"); | |
ctx.variables[ctx.counter] = _label; | |
ctx.variableType[_label] = myType; | |
ctx.states[ctx.counter] = abi.encode(_value); | |
ctx.counter++; | |
} | |
function _watch(string memory _label, address _value) internal { | |
bytes32 myType = keccak256("ADDRESS"); | |
ctx.variables[ctx.counter] = _label; | |
ctx.variableType[_label] = myType; | |
ctx.states[ctx.counter] = abi.encode(_value); | |
ctx.counter++; | |
} | |
function _watch(string memory _label, uint256 _value) internal { | |
bytes32 myType = keccak256("UINT256"); | |
ctx.variables[ctx.counter] = _label; | |
ctx.variableType[_label] = myType; | |
ctx.states[ctx.counter] = abi.encode(_value); | |
ctx.counter++; | |
} | |
function _logWatch() internal { | |
console.log(" "); | |
console.log("==== WATCH LIST ===="); | |
for(uint256 i; i < ctx.counter; i++) { | |
string memory myVariableName = ctx.variables[i]; | |
bytes32 myVariableType = ctx.variableType[myVariableName]; | |
bytes memory myState = ctx.states[i]; | |
if(keccak256("BYTES") == myVariableType) { | |
console.log(string(abi.encodePacked(myVariableName,":"))); | |
console.logBytes(myState); | |
}else if(keccak256("ADDRESS") == myVariableType){ | |
console.log(string(abi.encodePacked(myVariableName,": ")), abi.decode(myState, (address))); | |
}else if(keccak256("UINT256") == myVariableType){ | |
console.log(string(abi.encodePacked(myVariableName,": ")), abi.decode(myState, (uint256))); | |
}else if(keccak256("BYTES32") == myVariableType){ | |
console.log(string(abi.encodePacked(myVariableName,":"))); | |
console.logBytes32(abi.decode(myState, (bytes32))); | |
} else { | |
console.log("Unknown state :-O"); | |
} | |
} | |
console.log("==== WATCH LIST ===="); | |
} | |
} | |
abstract contract Deployments is BaseScript { | |
function _mainDeploymentsScript() internal { | |
vm.startBroadcast(HARIS_KEY); | |
// __deployAccessControl(); | |
vm.stopBroadcast(); | |
} | |
// function __deployAccessControl() internal { | |
// bytes memory data = abi.encodeWithSignature("initialize()"); | |
// ERC1967Proxy accessControlProxy = new ERC1967Proxy(address(new MidasAccessControl()), data); | |
// accessControl = MidasAccessControl(address(accessControlProxy)); | |
// _watch("accessControl", address(accessControl)); | |
// } | |
} | |
abstract contract Interactions is BaseScript { | |
function _mainInteractionsScript() internal { | |
// __addPaymentToken(); | |
} | |
// function __addPaymentToken() private { | |
// vm.startBroadcast(HARIS_KEY); | |
// mtBillDepositVault.addPaymentToken(USDC, address(usdcDataFeed), 200, true); | |
// vm.stopBroadcast(); | |
// } | |
} | |
contract MainScript is BaseScript, Deployments, Interactions { | |
function run() external { | |
_mainDeploymentsScript(); | |
_mainInteractionsScript(); | |
// _watch("Waqas mtBill balance", mtBill.balanceOf(WAQAS) / 1e18); | |
_logWatch(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment