Skip to content

Instantly share code, notes, and snippets.

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"
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 {
@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",
@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 / 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 / stat.json
Created October 4, 2022 08:04
Gas estimation stats
{
"ConvexBooster": {
"methods": [
"depositAll",
"deposit2",
"withdraw2",
"withdrawAll"
],
"stat": {
"CONVEX_BOOSTER": [
package main
import (
"context"
"encoding/json"
"fmt"
"net/http"
"os"
"github.com/Khan/genqlient/graphql"
%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 (
"github.com/Gearbox-protocol/sdk-go/artifacts/poolService"
"github.com/Gearbox-protocol/sdk-go/core"
"github.com/Gearbox-protocol/sdk-go/core/schemas"
"github.com/Gearbox-protocol/sdk-go/ethclient"
"github.com/Gearbox-protocol/sdk-go/log"
@harsh-98
harsh-98 / index.js
Created January 11, 2022 08:19
Trezor script to generate the private keys from seed.
const hdkey = require('hdkey')
const bip39 = require('bip39')
const ethUtil = require('ethereumjs-util')
const BigNumber = require('bignumber.js');
require('dotenv').config()
function hdwallet(){
let mnemonic , seed;
if (! process.env.MNEMONIC) {
mnemonic = bip39.generateMnemonic(); //generates string
} else {