This file contains 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.20; | |
interface IERC20 { | |
event Transfer(address indexed from, address indexed to, uint256 value); | |
event Approval(address indexed owner, address indexed spender, uint256 value); | |
function totalSupply() external view returns (uint256); | |
function balanceOf(address account) external view returns (uint256); | |
function transfer(address to, uint256 value) external returns (bool); |
This file contains 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
import BN from "bn.js"; | |
import * as types from "./types"; | |
test("decimalStringFromBN", () => { | |
expect(types.decimalStringFromBN(new BN(0))).toEqual("0"); | |
expect(types.decimalStringFromBN(new BN(0), 1)).toEqual("0"); | |
expect(types.decimalStringFromBN(new BN(1000000))).toEqual("1000000"); | |
expect(types.decimalStringFromBN(new BN(1000000), 1)).toEqual("100000"); | |
expect(types.decimalStringFromBN(new BN(1000001), 1)).toEqual("100000.1"); | |
expect(types.decimalStringFromBN(new BN(1000100), 1)).toEqual("100010"); |
This file contains 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
$ ganache-cli --fork <NODE_RPC_URL> --chainId 1 --secure --unlock <ADMIN_ADDRESS> |
This file contains 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
// Storage slot 9 contains "balances" (mapping(address => uint256)) | |
// Derive slot position for the key k | |
const k = holderAddr.slice(2).toLowerCase().padStart(64, "0"); | |
const p = "9".padStart(64, "0"); | |
const valueSlotPos = web3.utils.keccak256("0x" + k + p); | |
const data = await web3.eth.getStorageAt(contract.address, valueSlotPos); | |
expect(new BN(data.slice(2), 16).eq(expectedBalance)).to.be.true; |
This file contains 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
// Storage slot 4 contains "name" (string) | |
const data = await web3.eth.getStorageAt(contract.address, 4); | |
const len2 = parseInt(data.slice(-2), 16); // Last 1 byte = length * 2 | |
// Read the text (skip "0x") | |
const text = Buffer.from(data.slice(2, 2 + len2), "hex").toString("utf8"); | |
expect(text).to.equal(name); |
This file contains 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
// Storage slot 1 contains "pauser" (bool) and "paused" (address) | |
const data = await web3.eth.getStorageAt(contract.address, 1); | |
const pauserData = data.slice(-40); // Take the last 20 bytes | |
const pausedData = data.slice(-42, -40); // Take 1 byte before that | |
expect(pauserData).to.equal(pauserAddress.slice(2).toLowerCase()); | |
expect(!!parseInt(pausedData, 16)).to.equal(paused); // Convert to boolean |
This file contains 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
// Storage slot 0 contains "owner" (address) | |
const data = await web3.eth.getStorageAt(contract.address, 0); | |
// Take the last 20 bytes, left-pad with zeros if needed | |
const ownerData = data.slice(-40).padStart(40, "0"); | |
expect(ownerData).to.equal( | |
ownerAddress.slice(2).toLowerCase() // Remove "0x" | |
); |
This file contains 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
contract Foo { | |
bytes32 private constant NUM_SLOT = keccak256("Foo.num"); | |
function num() public view returns (uint256 val) { | |
bytes32 slot = NUM_SLOT; | |
assembly { | |
val := sload(slot) | |
} | |
} | |
This file contains 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 | |
// Copyright (c) 2020 petejkim | |
pragma solidity 0.6.12; | |
import { Ownable } from "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.2.0/contracts/access/Ownable.sol"; | |
import { IERC20 } from "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.2.0/contracts/token/ERC20/IERC20.sol"; | |
import { SafeERC20 } from "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.2.0/contracts/token/ERC20/SafeERC20.sol"; | |
contract USDCFaucet is Ownable { |
This file contains 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
test("decimalStringFromBN", () => { | |
expect(types.decimalStringFromBN(new BN(0))).toEqual("0"); | |
expect(types.decimalStringFromBN(new BN(0), 1)).toEqual("0"); | |
expect(types.decimalStringFromBN(new BN(1000000))).toEqual("1000000"); | |
expect(types.decimalStringFromBN(new BN(1000000), 1)).toEqual("100000"); | |
expect(types.decimalStringFromBN(new BN(1000001), 1)).toEqual("100000.1"); | |
expect(types.decimalStringFromBN(new BN(1000100), 1)).toEqual("100010"); | |
expect(types.decimalStringFromBN(new BN(1000000), 2)).toEqual("10000"); | |
expect(types.decimalStringFromBN(new BN(1000001), 2)).toEqual("10000.01"); | |
expect(types.decimalStringFromBN(new BN(1000100), 2)).toEqual("10001"); |
NewerOlder