Skip to content

Instantly share code, notes, and snippets.

View a2468834's full-sized avatar
🤗
Search for opportunities

Chuan-Chun Wang a2468834

🤗
Search for opportunities
View GitHub Profile
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0; // 限定 compiler version 在某一個區間較好
contract donation {
// Data
struct donorinfo {
address[] donors;
mapping(address=> uint) ledger;
}
@a2468834
a2468834 / SqrtByMagicNumber.cxx
Created March 6, 2022 14:41
Calaulate sqrt(x) using magic number method
#include <iostream>
#include <cmath>
#define SQRT_MAGIC32 0x5F375A86
#define SQRT_MAGIC64 0x5FE6EB50C7B537A9
using namespace std;
float Sqrt32(float x) {
uint32_t i; // The integer interpretation of x
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0 <0.9.0;
contract PreSaleMint {
address public immutable _owner;
mapping(address => uint256) public addressMintedBalance; // # of NFTs minted by every address
address[] public whitelistedAddresses; // Dynamic array version of the whitelist
mapping(address => bool) public whitelistedAddressesMap; // Mapping version of the whitelist
modifier onlyOwner() {
@a2468834
a2468834 / query.js
Last active March 21, 2022 08:24
Query WETH9 contract using Hardhat mainnet forking between a range of blocks
// Please read mainnet forking tutorial at the LunDAO
// Constants
const EXIT_SUCCESS = 0;
const EXIT_FAILURE = 1;
const weth9_address = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
const contract_ABI = require("./contract-abi.json");
const start_block = 14379900; // The starting block number you want
const end_block = 14379910; // The ending block number you want
@a2468834
a2468834 / interact.js
Created March 14, 2022 17:26
Interact with WETH9 contract using Hardhat network + mainnet forking
// Interact with WETH9 contract using Hardhat network + mainnet forking
// #0 = No. 0 of Hardhat Network default accounts
// #1 = A randomly picked address
// Constants
const EXIT_SUCCESS = 0;
const EXIT_FAILURE = 1;
const weth9_address = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
const somebody = "0x2feb1512183545f48f6b9c5b4ebfcaf49cfca6f3";
const contract_ABI = require("./contract-abi.json"); // WETH9's ABI
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0 <0.9.0;
contract D1 {
function A() public pure { // 21437, MAX
uint256 x;
x+=1;
}
function B() public pure { // 21333, min
uint256 x;
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.1 <0.9.0;
/**
* @dev
* The original contract:
* https://etherscan.io/address/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2#code
*/
interface IWeth9 {
function allowance(address, address) external returns (uint256);
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.1;
// The compiler does not reserve a storage slot for these variables.
uint256 constant dim1 = 36;
uint256 constant dim2 = 36;
uint256 constant dim = dim1 * dim2;
// Use the original "struct Cell"
// Constants
const EXIT_SUCCESS = 0;
const EXIT_FAILURE = 1;
// Method1: Query getCanvasSlice() 36 times, sequential
async function method1(contract) {
for(let i = 0; i < 36; i++) {
var args = [(i).toString(), (i+1).toString()];
await contract.getCanvasSlice(...args);
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.1;
contract SortedSequence {
uint256[100] public _array;
mapping(uint256 => bool) public _mapping;
function setValue(uint256[100] calldata init_seq) public {
for(uint8 i = 0; i < 100; i++) {
_array[i] = init_seq[i];