Skip to content

Instantly share code, notes, and snippets.

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
@dvgui
dvgui / TokenLock.sol
Created June 1, 2023 12:08
Token lock contract for erc20 with defined lock deadline and duration
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.6;
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract TokenLock is OwnableUpgradeable, IERC20 {
ERC20 public token;
uint256 public depositDeadline;
@dvgui
dvgui / contracts...TokenImplementation.sol
Created April 4, 2023 17:59
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.19+commit.7dd6d404.js&optimize=false&runs=200&gist=
// contracts/TokenImplementation.sol
// SPDX-License-Identifier: Apache 2
pragma solidity ^0.8.0;
import "./TokenState.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
@dvgui
dvgui / gist:13dcce8a6618414c75bbb5914fe5e3b0
Created March 15, 2023 11:17
Util function for ERC20 permit generation in TS (adapted from uniswap's)
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { BigNumberish, constants, Signature, Contract } from 'ethers';
import { splitSignature } from 'ethers/lib/utils';
import { TestToken } from '../typechain-types';
export async function getPermitSignature(
wallet: SignerWithAddress,
token: TestToken | Contract,
spender: string,
value: BigNumberish = constants.MaxUint256,
const { ethers, upgrades, network } = require("hardhat");
module.exports.toWei = (n) => ethers.BigNumber.from(10).pow(18).mul(n);
module.exports.toEther = (n) => ethers.utils.formatEther(n);
module.exports.toBN = (n) => ethers.BigNumber.from(n);
module.exports.numberLastBlock = async () =>
(await ethers.provider.getBlock("latest")).number;
module.exports.timeStampLastBlock = async () =>
(await ethers.provider.getBlock("latest")).timestamp;