Skip to content

Instantly share code, notes, and snippets.

@Bind
Created April 2, 2022 18:38
Show Gist options
  • Save Bind/a8acd13ec669622d497a68c4ce9f458c to your computer and use it in GitHub Desktop.
Save Bind/a8acd13ec669622d497a68c4ce9f458c to your computer and use it in GitHub Desktop.
// THIS FILE WAS GENERATED
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface CheatCodes {
function store(
address,
bytes32,
bytes32
) external;
function load(address, bytes32) external returns (bytes32);
}
contract ERC20StorageContract {
address internal target;
CheatCodes public constant VM = CheatCodes(address(bytes20(uint160(uint256(keccak256("hevm cheat code"))))));
constructor(address _contractAddress) {
target = _contractAddress;
}
function clear(
uint256 slotData,
uint8 length,
uint8 offset
) public pure returns (uint256) {
if (length == 32) {
return uint256(0);
}
unchecked {
return slotData & (type(uint256).max ^ (((1 << (8 * length)) - 1) << (offset * 8)));
}
}
// Must be zeroed out first
function set(
uint256 slotData,
uint256 value,
uint8 offset
) public pure returns (uint256) {
return slotData | (value << (offset * 8));
}
uint256 public nameStorageSlot = uint256(0);
uint256 public symbolStorageSlot = uint256(1);
uint256 public totalSupplyStorageSlot = uint256(2);
uint256 public balanceOfStorageSlot = uint256(3);
uint256 public allowanceStorageSlot = uint256(4);
uint256 public noncesStorageSlot = uint256(5);
function name(string memory value) public {
VM.store(target, bytes32(nameStorageSlot), bytes32(bytes(value)));
}
function symbol(string memory value) public {
VM.store(target, bytes32(symbolStorageSlot), bytes32(bytes(value)));
}
function totalSupply(uint256 value) public {
VM.store(target, bytes32(totalSupplyStorageSlot), bytes32(uint256(value)));
}
function balanceOf(address key0, uint256 value) public {
uint256 slot = uint256(keccak256(abi.encode(key0, bytes32(balanceOfStorageSlot))));
VM.store(target, bytes32(slot), bytes32(uint256(value)));
}
function allowance(
address key0,
address key1,
uint256 value
) public {
uint256 slot = uint256(
keccak256(abi.encode(key1, bytes32(keccak256(abi.encode(key0, bytes32(allowanceStorageSlot))))))
);
VM.store(target, bytes32(slot), bytes32(uint256(value)));
}
function nonces(address key0, uint256 value) public {
uint256 slot = uint256(keccak256(abi.encode(key0, bytes32(noncesStorageSlot))));
VM.store(target, bytes32(slot), bytes32(uint256(value)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment