Skip to content

Instantly share code, notes, and snippets.

@BlockmanCodes
BlockmanCodes / 08_decodeExactInputPath.js
Last active March 20, 2024 06:44
Uniswap V3: decode exactInput paths
const hashes = [
'0x04fffe0fb9d0ac806b0f3c329a83d8dd5ddcd598ee82779043d83802d6ee784a',
'0x8df99a1c9bbbf7cda5a9f1bc11d3b3cd0c6d99f31039396a29779fea252960f6',
'0x3f94bc2af1300a01827e59a745b05af8517ae4fc5e25ee1add9789d19c9bfd00',
'0x68cf26f581d6c0add08c9fcf9b1d4d31cff660d8bfb6b7d9e3636a7aa1e0a91f',
'0xed797fb4d05950dca9279c55f2436211a3eb585f1f20877e7384017500951fe4',
'0x7596c887baea532f2a2370af06d1990dac8be04f68e8f906dd82025d2ce42ad7',
'0x8892ffda5398dbf54d0fb6bc4d2bbdbc31de250f633cf1becc568a92fbe63c51',
'0x9219aa3bc64b325f84f9e3c101e602c83f65f61272a982c8f2fd1c55874ecc6d',
'0x81995eb1d1a62c3dbdb817663e39b40d235861e4ee6513962299d8a15905dded',
@BlockmanCodes
BlockmanCodes / .env
Created August 31, 2023 22:30
Uniswap V3 / EthersJS: decode mempool swap router swaps
WEBSOCKET_URL=wss://mainnet.infura.io/ws/v3/abc
@BlockmanCodes
BlockmanCodes / 04_getLogsAndDecode.js
Created August 21, 2023 23:13
EthersJS: query, filter, and decode event logs
require('dotenv').config()
const ethers = require("ethers")
// ie: -> Flash(address,address,uint256,uint256,uint256,uint256)
const getEventSignature = (eventName, abi) => {
const eventAbi = abi.find((entry) => entry.name === eventName);
const types = eventAbi.inputs.map((input) => input.type);
return `${eventName}(${types.join(',')})`;
}
@BlockmanCodes
BlockmanCodes / 01_impersonateSigner.js
Created August 11, 2023 01:31
Hardhat: impersonate signer when forking
const SwapRouterArtifact = require('@uniswap/v3-periphery/artifacts/contracts/SwapRouter.sol/SwapRouter.json')
const erc20Abi = [
{
"inputs": [
{"internalType": "address", "name": "spender", "type": "address"},
{"internalType": "uint256", "name": "amount", "type": "uint256"}
],
"name": "approve",
"outputs": [{"internalType": "bool", "name": "", "type": "bool"}],
@BlockmanCodes
BlockmanCodes / 01_simpleSwap.js
Created July 23, 2023 20:04
Uniswap: Universal Router: ETH to USDC
const { SwapRouter } = require('@uniswap/universal-router-sdk')
const { TradeType, Ether, Token, CurrencyAmount, Percent } = require('@uniswap/sdk-core')
const { Trade: V2Trade } = require('@uniswap/v2-sdk')
const { Pool, nearestUsableTick, TickMath, TICK_SPACINGS, FeeAmount, Trade: V3Trade, Route: RouteV3 } = require('@uniswap/v3-sdk')
const { MixedRouteTrade, Trade: RouterTrade } = require('@uniswap/router-sdk')
const IUniswapV3Pool = require('@uniswap/v3-core/artifacts/contracts/UniswapV3Pool.sol/UniswapV3Pool.json')
const JSBI = require('jsbi')
const erc20Abi = require('../abis/erc20.json')
@BlockmanCodes
BlockmanCodes / listen.js
Created July 13, 2023 01:44
Uniswap V3: listen all pools
const ethers = require('ethers')
const poolAbi = [
{
"anonymous": false,
"inputs": [
{"indexed": true, "internalType": "address", "name": "sender", "type": "address"},
{"indexed": true, "internalType": "address", "name": "recipient", "type": "address"},
{"indexed": false, "internalType": "int256", "name": "amount0", "type": "int256"},
{"indexed": false, "internalType": "int256", "name": "amount1", "type": "int256"},
@BlockmanCodes
BlockmanCodes / abis__erc20.json
Last active August 23, 2023 21:53
Pancake Swap: exactInputSingle
[
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
@BlockmanCodes
BlockmanCodes / getPrice.js
Created June 16, 2023 12:25
Uni V3: getPriceFromTick
const JSBI = require('jsbi')
const { TickMath, FullMath } = require('@uniswap/v3-sdk')
const baseToken = '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599' // WETH
const quoteToken = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' // WBTC
async function main(
baseToken,
quoteToken,
inputAmount,
@BlockmanCodes
BlockmanCodes / 01_classicSwap.js
Last active April 9, 2024 18:04
Kyber (classic): swap eth to usdt
const ethers = require('ethers');
const dmmRouterAbi = require("../abis/dmmRouter.json")
const erc20Abi = require("../abis/erc20.json")
const wethAbi = require("../abis/weth.json")
WETH_ADDRESS= '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'
USDT_ADDRESS= '0xdAC17F958D2ee523a2206206994597C13D831ec7'
@BlockmanCodes
BlockmanCodes / 00_findPools.js
Created June 7, 2023 12:32
Kyber: get dmm pool addresses
const ethers = require('ethers');
const dmmFactoryAbi = require("../abis/dmmFactory.json")
WETH_ADDRESS= '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'
USDT_ADDRESS= '0xdAC17F958D2ee523a2206206994597C13D831ec7'
DMM_FACTORY_ADDRESS='0x833e4083B7ae46CeA85695c4f7ed25CDAd8886dE'
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545/')