Skip to content

Instantly share code, notes, and snippets.

View hihiben's full-sized avatar

PangTing Huang hihiben

View GitHub Profile
@hihiben
hihiben / HTLC.sol
Last active December 17, 2019 07:24
Basic implementation of HTLC
pragma solidity ^0.5.0;
contract HTLC {
address payable public sender;
address payable public receiver;
bytes32 public hashlock;
uint256 public timelock;
bytes32 public preimage;
constructor(address payable _receiver, bytes32 _hashlock, uint256 _timelock) public payable {
@hihiben
hihiben / bank.sol
Created April 19, 2021 03:31
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.3+commit.8d00100c.js&optimize=true&runs=200&gist=
pragma solidity ^0.8.0;
import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/master/contracts/token/ERC20/ERC20.sol";
contract TST is ERC20 {
constructor() ERC20("Test token", "TST") {
_mint(msg.sender, 10000 * (10**uint256(decimals())));
}
}
@hihiben
hihiben / Setup.sol
Created April 20, 2021 03:08
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.3+commit.8d00100c.js&optimize=true&runs=200&gist=
pragma solidity ^0.8.0;
import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/master/contracts/token/ERC20/ERC20.sol";
import "./Weth9.sol";
interface Protocol {
function mint(uint256 amount) external;
function burn(uint256 amount) external;
function underlying() external view returns (IERC20);
function balanceUnderlying() external view returns (uint256);
@hihiben
hihiben / contracts...test.sol
Created September 7, 2021 03:41
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.7+commit.e28d00a7.js&optimize=true&runs=200&gist=
/// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.7;
interface IERC20 {
function balanceOf(address account) external view returns(uint256);
}
interface IProxy {
function batchExec(address[] calldata tos, bytes32[] calldata configs, bytes[] memory datas) external payable;
@hihiben
hihiben / BeaconProxy.sol
Created June 7, 2022 11:24
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.14+commit.80d49f37.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.14;
import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/master/contracts/proxy/beacon/BeaconProxy.sol";
import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/master/contracts/proxy/beacon/UpgradeableBeacon.sol";
import {ImplementationV1, ImplementationV2} from "./Implementation.sol";
contract Setup {
address immutable public proxy1;
address immutable public proxy2;
@hihiben
hihiben / LibFacet1.sol
Created August 2, 2022 02: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.6.12+commit.27d51765.js&optimize=false&runs=200&gist=
library LibFacet1 {
bytes32 constant storagePosition = keccak256("diamond.storage.LibFacet1");
struct DiamondStorage {
uint256 n;
}
function diamondStorage() internal pure returns (DiamondStorage storage ds) {
bytes32 position = storagePosition;
assembly {
@hihiben
hihiben / bytesDecode.sol
Created August 16, 2022 02:40
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.16+commit.07a7930e.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract Try {
function createBytes(uint256 n) public pure returns (bytes memory data) {
uint256[] memory ret = new uint256[](n);
for (uint256 i = 0; i < n; i++) {
ret[i] = i;
}
@hihiben
hihiben / create2.sol
Created August 19, 2022 10:04
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.16+commit.07a7930e.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
contract ContractFactory {
function deploy(uint256 n_, bytes calldata code_) external payable returns (address) {
Proxy p;
try new Proxy{salt: bytes32(n_)}() returns (Proxy _p) {
p = _p;
} catch {
revert("Deploy proxy failed");