Skip to content

Instantly share code, notes, and snippets.

View genaroibc's full-sized avatar

Genaro Bonavita genaroibc

View GitHub Profile
enum DataType {
NUMBER,
STRING,
BOOLEAN,
}
type BaseDataMap = {
[DataType.NUMBER]: {
type: DataType.NUMBER;
value: number;
import { create } from "zustand";
import { persist } from "zustand/middleware";
interface V0HistoryStore {
oldProperty: string;
}
-interface Store {
+type StoreState = Pick<Store, "newProperty">;
+
async function getDominantColor(imageUrl: string) {
const img = document.createElement("img");
img.src = imageUrl;
img.crossOrigin = "Anonymous";
await new Promise((resolve, reject) => {
img.onload = resolve;
img.onerror = reject;
});
@genaroibc
genaroibc / getHexColorWithOpacity.js
Created April 16, 2024 12:32
JS function to get hexadecimal color with opacity based on the given color and opacity percentage
/**
* Returns a hexadecimal color with opacity based on the given color and opacity percentage.
*
* @example getHexColorFromOpacityPercentage('#FF0000', 0.5) // '#FF000080'
*
* @param {string} color - The base color in hexadecimal format.
* @param {number} opacity - The opacity percentage (0-1).
* @returns {string} The hexadecimal color with opacity.
*/
function getHexColorFromOpacityPercentage(color, opacity) {
import { ethers } from "ethers";
import { Squid } from "@0xsquid/sdk";
import { ChainType, SquidCallType } from "@0xsquid/squid-types";
const NATIVE_TOKEN_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
const ETHEREUM_RPC_URL =
"https://rpc.tenderly.co/fork/2554f46d-5131-40a8-bbbc-047fcbf83b2f";
const WETH_TOKEN_ADDRESS = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
const SOMMELIER_CONTRACT = "0xfd6db5011b171B05E1Ea3b92f9EAcaEEb055e971";
const TURBO_STETH_TOKEN_ADDRESS = "0xfd6db5011b171b05e1ea3b92f9eacaeeb055e971";
import { ethers } from "ethers";
const ETHEREUM_RPC_URL =
"https://rpc.tenderly.co/fork/65a7226b-278e-4306-b0bf-bb049916ac0e";
const WETH_TOKEN_ADDRESS = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
const SOMMELIER_CONTRACT = "0xfd6db5011b171B05E1Ea3b92f9EAcaEEb055e971";
const TURBO_STETH_TOKEN_ADDRESS = "0xfd6db5011b171b05e1ea3b92f9eacaeeb055e971";
const SOMMELIER_CONTRACT_ABI = [
"function deposit(uint256 assets, address receiver)",
"function balanceOf(address account) view returns (uint256)",
async function getDataURL(url) {
return new Promise(resolve => fetch(String(url))
.then(response => response.blob())
.then(blob => {
const reader = new FileReader()
reader.onload = () => resolve(reader.result)
reader.readAsDataURL(blob)
}))
}`
@genaroibc
genaroibc / UNISWAP-V2.md
Last active July 6, 2023 16:45
Notes about Uniswap V2 contract

Liquidity pools

A shared pot of funds deposited by agents.

Agents who deposit funds to the pool are liquidity providers. They receive pool fees as reward.

CPMM Model

Constant Product Market Maker Model is an Automated Market Maker (AMM), a mathematic formula to determine the price in a pool.

Transaction

A transaction is an action initiated by an EOA (externally-owned account) which modifies the state of the blockchain.

Message

A message is the data created when two contracts interact. It contains:

  • from: the address of the sender
  • to: the address of the recipient
import { Squid, SquidCallType } from "@0xsquid/sdk";
import dotenv from "dotenv";
import { ethers } from "ethers";
import erc20abi from "./abis/erc20.json";
import wrcAbi from "./abis/wrcTokenAbi.json";
dotenv.config();
const erc20Interface = new ethers.utils.Interface(erc20abi);
const wrcInterface = new ethers.utils.Interface(wrcAbi);