Skip to content

Instantly share code, notes, and snippets.

View TuDo1403's full-sized avatar
👻
Working from home

tu-do.ron TuDo1403

👻
Working from home
  • Ho Chi Minh City - VietNam
  • 08:34 (UTC +07:00)
  • X @TuDo1403
View GitHub Profile
@TuDo1403
TuDo1403 / LibCurrency.sol
Created March 7, 2024 03:58
LibCurrency
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IERC20Metadata} from "@openzeppelin/contracts/interfaces/IERC20Metadata.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {LibNativeTransfer} from "./LibNativeTransfer.sol";
type Currency is address;
using {eq as ==} for Currency global;
@TuDo1403
TuDo1403 / contracts...NameChecker.sol
Created September 23, 2023 05:55
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.17+commit.8df45f5f.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import {AccessControlEnumerable} from "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import {ShortString, ShortStrings} from "@openzeppelin/contracts/utils/ShortStrings.sol";
import {BitMaps} from "@openzeppelin/contracts/utils/structs/BitMaps.sol";
import {LibSubString} from "./LibSubString.sol";
contract NameCheckerMap is Initializable, AccessControlEnumerable {
@TuDo1403
TuDo1403 / contracts...LibSubString.sol
Created September 23, 2023 05:55
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.17+commit.8df45f5f.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
library LibSubString {
struct WordRange {
uint8 min;
uint8 max;
}
@TuDo1403
TuDo1403 / contracts...ExhaustGas.sol
Created September 7, 2023 09:47
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.17+commit.8df45f5f.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
contract ExhaustGas {
uint256 val;
function exhaustivelyConsumeAllGas() external pure {
assembly {
revert(0, 1000000)
}
@TuDo1403
TuDo1403 / draft-ERC1155Enumerable.sol
Created August 18, 2023 07:14
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.21+commit.d9974bed.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;
import {ERC1155Supply} from "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
interface IERC1155Enumerable {
function getTokenCount() external view returns (uint256);
function getTokenOfOwnerCount(address account) external view returns (uint256);
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.20;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
@TuDo1403
TuDo1403 / Concatenation.sol
Created July 19, 2023 05:09
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.20+commit.a1b79de6.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Concatenation {
function randomizeAddress(uint256 seed, uint256 amount) external pure returns (address[] memory addrs) {
addrs = new address[](amount);
for (uint256 i; i < amount; ) {
addrs[i] = address(ripemd160(abi.encode(seed, i)));
unchecked {
++i;
@TuDo1403
TuDo1403 / helpers.ts
Created May 23, 2023 08:24 — forked from hmmdeif/helpers.ts
Hardhat calculate bytes4 interface
// Import contract factory generated from `hardhat compile` with typechain
import { IERC165__factory, IERC2981__factory } from '@custom-types/contracts'
import { ethers } from 'hardhat'
import { utils } from 'ethers'
const getInterfaceID = (contractInterface: utils.Interface) => {
let interfaceID = ethers.constants.Zero;
const functions: string[] = Object.keys(contractInterface.functions);
for (let i = 0; i < functions.length; i++) {
@TuDo1403
TuDo1403 / contracts...router...AffiliateRouterV2.sol
Created May 11, 2023 10:18
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.17+commit.d19bba13.js&optimize=false&runs=200&gist=
pragma solidity ^0.5.17;
import {IKatanaRouter} from "./IKatanaRouter.sol";
import {SafeMath} from "../libraries/SafeMath.sol";
import {ErrorHandler} from "../libraries/ErrorHandler.sol";
import {TransferHelper} from "../libraries/TransferHelper.sol";
contract AffiliateRouterV2 {
using SafeMath for uint256;
@TuDo1403
TuDo1403 / contracts...PieceCombiner.sol
Created December 5, 2022 07:54
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.17+commit.8df45f5f.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
contract PieceCombiner {
uint256 public constant NUM_RARITIES = 4;
uint256 public constant NUM_ATTRIBUTES = 4;
mapping(address => uint8[NUM_RARITIES]) public attributeBitMap;
mapping(address => mapping(uint8 => uint256[][])) public collectibles;
mapping(address => uint8[NUM_RARITIES][NUM_ATTRIBUTES]) public collectibleCounter;