Skip to content

Instantly share code, notes, and snippets.

View Alexintosh's full-sized avatar
🧑‍🍳
Baking

Alessio Delmonti Alexintosh

🧑‍🍳
Baking
View GitHub Profile
@lrettig
lrettig / iceage.py
Created January 18, 2019 15:03
Simulation script for ice age block times
# Date, blocknum, difficulty as of 2019-01-18
# Script by vbuterin, slightly modified by lrettig
import random
import datetime
import sys
def calc_bomb(i):
period = i // 100000
if (period > 0):
# Subtract 2, this is the original formula
@allenday
allenday / gini-balance-erc20.sql
Created January 31, 2019 10:14
Calculate Gini coefficient for ERC-20 balances.
with
double_entry_book as (
-- debits
select to_address as address, CAST(value AS NUMERIC) as value, block_timestamp
from `bigquery-public-data.crypto_ethereum.token_transfers`
where from_address is not null and to_address is not null
and token_address = LOWER('0x408e41876cccdc0f92210600ef50372656052a38') --OMG
union all
-- credits
select from_address as address, -CAST(value AS NUMERIC) as value, block_timestamp
def isWrapPair(equivalentSets, tokenA, tokenB):
for equivalentSet in equivalentSets:
if ((tokenA in equivalentSet) and (tokenB in equivalentSet)):
return True
return False
equivalentSets = [
["WETH", "aETH", "cETH", "iETH", "iETH", "PETH"], # ETH group
["DAI", "aDAI", "cDAI", "dDAI", "iDAI", "yDAI", "rDAI", "CHAI"], # DAI group
["USDC", "aUSDC", "cUSDC", "dUSDC", "iUSDC", "yUSDC"] # USDC group
@gorgos
gorgos / ExampleSlidingWindowOracleDaiWethKovan.sol
Created January 9, 2021 20:16
ExampleSlidingWindowOracle with DAI + WETH for Kovan.
pragma solidity 0.6.6;
pragma experimental ABIEncoderV2;
import "https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/interfaces/IUniswapV2Pair.sol";
import "https://github.com/Uniswap/uniswap-lib/blob/master/contracts/libraries/FixedPoint.sol";
import "https://github.com/Uniswap/uniswap-lib/blob/master/contracts/libraries/FullMath.sol";
import "https://github.com/Uniswap/uniswap-lib/blob/master/contracts/libraries/Babylonian.sol";
import "https://github.com/Uniswap/uniswap-lib/blob/master/contracts/libraries/BitMath.sol";
library SafeMath {
@miohtama
miohtama / bigquery.sql
Created January 28, 2021 11:47
How to get the total cost of approve() function calls on Ethereum blockchain
-- Web3.utils.keccak256("approve(address,uint256)").slice(0, 10);
-- '0x095ea7b3'
WITH txdata as (
SELECT tx.hash as txid, cast(tx.receipt_gas_used as numeric) * cast(tx.gas_price as numeric) as cost FROM
bigquery-public-data.crypto_ethereum.transactions as tx
where
tx.input
LIKE "0x095ea7b3%")
SELECT (SUM(cost) / POWER(10, 18)) as eth_cost from txdata;
@alexisgauba
alexisgauba / VestingCallOptions.md
Created June 25, 2021 18:53
Vesting Call Options

Vesting Call Options

The following instructions go step-by-step through how to create vesting call options, similar to equity options that startups typically use to incentivize employees.

H/t @Fubuloubu, who approached us about creating these for the Yearn team to potentially use! This allows Yearn or similar projects (on-chain DAOs) to grant vesting options to any contributor.

We'll use YFI call options as an example.

Deploy the call options

@z0r0z
z0r0z / SquishiGame.sol
Created October 9, 2021 21:38
SushiToken Battle Royale on Polygon
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.9;
/// @notice Minimal ERC-20 token interface.
interface IERC20Minimal {
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
// Unlike the string type, ShortString is a value type that can be made immutable.
// It supports strings of at most 32 bytes and assumes they don't contain null bytes.
type ShortString is bytes32;
error StringTooLong(string s);
@ruphy
ruphy / GPT3.js
Last active November 2, 2023 23:41
GPT3() function for Google Sheets
// SPDX-License-Identifier: MIT
//
// This code will add a GPT3() function in your Google Sheets
// This code is originally inspired from https://twitter.com/fabianstelzer/status/1572926883179778050
// To use it, insert your API key below, open Google Sheets -> Extensions -> Apps Script -> Copy & Paste this -> Save
//
// Usage: =GPT3(prompt, max_tokens (default=15), model (default=davinci))
// Example usage: =GPT3("Once upon a time,", 1000, "davinci")
var API_KEY = "your-API-key";
export const chaosTestStrings = (): void => {
const textNodes = getAllTextNodes(document.body);
for (const node of textNodes) {
const textNodeLength = node.textContent ? node.textContent.length : 0;
if (node.textContent === null) {
return;
}
if (node.parentElement instanceof Element) {
if (node.parentElement.dataset.originalText === undefined) {