Skip to content

Instantly share code, notes, and snippets.

View jefflau's full-sized avatar
🏪
Working from Taipei

Jeff Lau jefflau

🏪
Working from Taipei
View GitHub Profile
@jefflau
jefflau / .deps...npm...hardhat...console.sol
Created January 21, 2022 09:48
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=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity >= 0.4.22 <0.9.0;
library console {
address constant CONSOLE_ADDRESS = address(0x000000000000000000636F6e736F6c652e6c6f67);
function _sendLogPayload(bytes memory payload) private view {
uint256 payloadLength = payload.length;
address consoleAddress = CONSOLE_ADDRESS;
assembly {
@jefflau
jefflau / .deps...npm...hardhat...console.sol
Created January 20, 2022 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.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity >= 0.4.22 <0.9.0;
library console {
address constant CONSOLE_ADDRESS = address(0x000000000000000000636F6e736F6c652e6c6f67);
function _sendLogPayload(bytes memory payload) private view {
uint256 payloadLength = payload.length;
address consoleAddress = CONSOLE_ADDRESS;
assembly {
@jefflau
jefflau / multisig.sol
Last active October 11, 2020 16:54
MultiSig 1st attempt
pragma solidity >=0.6.0 <0.7.0;
import "@nomiclabs/buidler/console.sol";
// SPDX-License-Identifier: MIT
contract MultiSig {
address[] public owners;
mapping(address => bool) isOwner;
uint256 public confirmations;
Transaction[] public transactions;
@jefflau
jefflau / loss.js
Created September 16, 2020 05:07
Calculate pool value loss
function calcPoolValueLoss(x){
return Math.pow(x, 0.02)*((1)^0.98)
}
@jefflau
jefflau / ensApi.md
Last active September 20, 2020 23:44
ENS Javascript API design

API design for ENS

The ENS library is to be used in dapps and possibly other tools that need to connect to the set of ENS contracts on the Ethereum blockchain. It should give them all the tools they need to resolve and set records for their ENS names, as well as abstracting implementation details including, but not limited to:

  • namehashes (could be provided as an advanced option)
  • resolvers (unless it's absolutely required for custom resolvers)
  • using the graph for getting textRecord or non-eth address keys
  • decoders/encoders of addresses

Instantiation

export function sendHelper(tx) {
return new Promise((resolve, reject) => {
tx()
.on('transactionHash', txHash => {
const txState = 'Pending'
addTransaction({ txHash, txState })
resolve(txHash)
})
.on('receipt', receipt => {
const txHash = receipt.transactionHash
@jefflau
jefflau / cloudinary.js
Created February 28, 2019 05:19
Cloudinary unsigned upload
const cloudName = 'xxxxxx'
const cloudinaryUrl = `https://api.cloudinary.com/v1_1/${cloudName}/upload`
const unsignedUploadPreset = 'xxxxxx'
export function upload(file) {
const body = new FormData()
body.append('file', file)
body.append('upload_preset', unsignedUploadPreset)
return (
@jefflau
jefflau / useMedia.js
Created February 27, 2019 09:55
useMedia hook
const useMedia = (query, defaultState) => {
const [state, setState] = useState(defaultState)
useEffect(
() => {
let mounted = true
const mql = window.matchMedia(query)
const onChange = () => {
if (!mounted) return
setState(!!mql.matches)
export function useEditable(
initialState = {
editing: false,
newValue: '',
pending: false,
confirmed: false,
txHash: undefined
}
) {
const types = {
@jefflau
jefflau / mediaQuery.js
Last active October 14, 2018 01:31
mediaQuery.js
import { css } from 'styled-components'
const sizes = {
giant: 1170,
desktop: 992,
tablet: 768,
phone: 376
}
// iterate through the sizes and create a media template