Skip to content

Instantly share code, notes, and snippets.

%lang starknet
from starkware.cairo.common.math import (signed_div_rem, sqrt)
from starkware.cairo.common.cairo_builtins import HashBuiltin
const FP = 10 ** 12
const RANGE_CHECK_BOUND = 2 ** 64
const FRICTION = 40 * FP
@event
func increase_balance_called(
package main
import (
"context"
"encoding/json"
"fmt"
"net/http"
"os"
"github.com/Khan/genqlient/graphql"
@harsh-98
harsh-98 / stat.json
Created October 4, 2022 08:04
Gas estimation stats
{
"ConvexBooster": {
"methods": [
"depositAll",
"deposit2",
"withdraw2",
"withdrawAll"
],
"stat": {
"CONVEX_BOOSTER": [
@harsh-98
harsh-98 / doc.md
Last active January 24, 2023 16:40
Calculating trade volume on gearbox v2

All the operations done on v2:

 depositAll(uint256,bool)
 CloseCreditAccount(address,address)
 swapExactTokensForTokens(uint256,uint256,address[],address,uint256)
 withdrawAndUnwrap(uint256,bool)
 unwrap(uint256)
 exactInputSingle((address,address,uint24,address,uint256,uint256,uint256,uint160))
 DecreaseBorrowedAmount(address,uint256)
@harsh-98
harsh-98 / a.sql
Last active January 26, 2023 14:00
init collateral+ total borrowedamount
borrow_amt | borrow_usd | init_col | col_usd | underlying_token
--------------------+--------------------+-------------------+--------------------+--------------------------------------------
16992380.838408105 | 16995650.68225284 | 2978216.706608446 | 2978789.8048492973 | 0x6B175474E89094C44Da98b954EedeAC495271d0F
14837.437708756617 | 23430508.59916383 | 3018.486498765127 | 4766636.615703305 | 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
26601062.457343996 | 26601062.457343996 | 4889989.477375998 | 4889989.477375998 | 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
with t1 as (select underlying_token, account, init_col*price col_usd, init_col, borrow_amt , borrow_amt *price borrow_usd, (borrow_amt+ init_col)*price total_usd from
@harsh-98
harsh-98 / connect.md
Last active May 30, 2023 19:54
websocket for trading app

wss://gearbox-ws.fly.dev/ws

Send ->

{"type":"subscribe:Updates", "data":{ "borrower":"0x1B3dfF537b7d46A0d30B1D20b101c483586747AA"}}

Receive updates in form of:

{
  "address": "0xD3BeD41dc971225a759fFd6122Af3b40Da1e882C",
type LastTs mutex[[]int64]
REQUEST_PER_PEER = 10
func (l LastTs) check() error {
l.lock()
l.unlock()
fiveMinAgo:=time.Now().Sub(5*Second).Unix()
streamBeforeFiveMin = sort.Search(len(l), func(i int) bool { return l[i] >= fiveMinAgo })
if len(l) - streamBeforeFiveMin > REQUEST_PER_PEER {
package main

import (
	"math/big"

	"github.com/Gearbox-protocol/go-liquidator/config"
	"github.com/Gearbox-protocol/go-liquidator/ethclient"
	"github.com/Gearbox-protocol/sdk-go/core"
	"github.com/Gearbox-protocol/sdk-go/log"
We can make this file beautiful and searchable if this error is corrected: It looks like row 8 should actually have 13 columns, instead of 5 in line 7.
Date,BlockNum,ezETH,wstETH,cbETH,rETH,USDe,WBTC,WETH,LINK,GMX,PENDLE,ARB
2024-07-05,228769400,1175499.127076,49989.925614,0.000000,726484.146254,1029876.729700,0.000000,435103.218160,0.000000,0.000000,0.000000,802.734900
2024-07-06,229120406,1563987.015121,1216352.567862,0.000000,877833.550869,2289303.841861,0.000000,898435.498263,0.000000,0.000000,0.000000,698.332800
2024-07-07,229496377,1624891.622776,1558981.443974,0.000000,899392.588944,2531527.141096,0.000000,978703.277833,0.000000,0.000000,0.000000,776.767455
2024-07-08,229851421,1572879.392524,1505022.105604,0.000000,868378.723682,3274020.153516,0.000000,919127.974732,0.000000,0.000000,0.000000,741.922500
2024-07-09,230206028,1610612.642829,1628190.338895,0.000000,889573.095693,3764213.197070,0.000000,1036009.598897,0.000000,0.000000,0.000000,750.662633
2024-07-10,230581596,1430847.254555,2280765.615407,0.000000,867170.040994,4081398.262274,0.000000,947849.727687,0.000000,0.000000,0.000000,793.927200
2024-07-11,230961536,1437998.253231,2543981.800197,0
We can make this file beautiful and searchable if this error is corrected: It looks like row 9 should actually have 5 columns, instead of 2 in line 8.
User,Token,avgValue=sigma/HowLongAgoFirstDeposit,HowLongAgoFirstDeposit, sigma[deposit*(1julyts-depoitts)-withdraw*(1julyts-withdrawts)]
0xE9548dE676021a1085A28Be7c4E9c8Da623F52f8,0x82aF49447D8a07e3bd95BD0d56f35241523fBab1,0.412122,3188760,1314157.787497
0xD4fE31E0005cF3Be991868d43Cb8bb61a6207A50,0x82aF49447D8a07e3bd95BD0d56f35241523fBab1,0.159495,2961791,472389.684185
0x36C9fdBF2EaFdb64F0082bE0E824Dc4605603E71,0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8,615.228666,2113587,1300339309.466808
0xBd9fcE89358c6897692a99C3717c370AB9d0cc35,0x82aF49447D8a07e3bd95BD0d56f35241523fBab1,0.099508,7177122,714181.898781
0x58Fc8a5d2bc89Dc1a353537271a217a6f64c92A4,0x82aF49447D8a07e3bd95BD0d56f35241523fBab1,858.587264,7022336,6029288253.128704
0xC929fD701A001518dAefaf870A40e8bDc4E3766d,0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8,66.213349,516442,34195354.572226
0x6B1c3D31e59790d40ecb09a5e11431d0C8a1d1E6,0x82aF49447D8a07e3bd95BD0d56f35241523fBab1,0.354947,8844967,3139494.766645
0x61f59CE34a5502493074257b2598457Bf6B2F242,0x82aF494