Skip to content

Instantly share code, notes, and snippets.

@toidv
Created October 11, 2023 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toidv/8d288e4cb53df2a11c6fa0c9f9d65390 to your computer and use it in GitHub Desktop.
Save toidv/8d288e4cb53df2a11c6fa0c9f9d65390 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"math"
// "math/big"
)
// A Response struct to map the Entire Response
type Response struct {
Name string `json:"name"`
Pokemon []Pokemon `json:"pokemon_entries"`
}
// A Pokemon Struct to map every pokemon to.
type Pokemon struct {
EntryNo int `json:"entry_number"`
Species PokemonSpecies `json:"pokemon_species"`
}
// A struct to map our Pokemon's Species which includes it's name
type PokemonSpecies struct {
Name string `json:"name"`
}
type HolderResponse struct {
ErrorCode string `json:"error_code"`
Data DataHolders `json:"data"`
}
type DataHolders struct {
TotalCount int `json:"total_count"`
Holders []HolderInfo `json:"holders"`
}
type HolderInfo struct {
Id string `json:"id"`
}
type LPAutoGenerated struct {
Timestamp int `json:"timestamp,omitempty"`
Data []struct {
ChainName string `json:"chainName,omitempty"`
ChainID int `json:"chainId,omitempty"`
ChainLogo string `json:"chainLogo,omitempty"`
Balances []struct {
Project string `json:"project,omitempty"`
ProjectLogo string `json:"projectLogo,omitempty"`
Token struct {
Address string `json:"address,omitempty"`
Symbol string `json:"symbol,omitempty"`
Name string `json:"name,omitempty"`
Decimals int `json:"decimals,omitempty"`
Logo string `json:"logo,omitempty"`
Tag string `json:"tag,omitempty"`
} `json:"token,omitempty"`
TokenType string `json:"tokenType,omitempty"`
TokenID string `json:"tokenId,omitempty"`
Balance string `json:"balance,omitempty"`
UserAddress string `json:"userAddress,omitempty"`
Quotes struct {
Usd struct {
Symbol string `json:"symbol,omitempty"`
Price int `json:"price,omitempty"`
PriceChange24HPercentage int `json:"priceChange24hPercentage,omitempty"`
Value int `json:"value,omitempty"`
Timestamp int `json:"timestamp,omitempty"`
} `json:"usd,omitempty"`
} `json:"quotes,omitempty"`
Web3ProjectAddress string `json:"web3ProjectAddress,omitempty"`
Underlying []struct {
Token struct {
Address string `json:"address,omitempty"`
Symbol string `json:"symbol,omitempty"`
Name string `json:"name,omitempty"`
Decimals int `json:"decimals,omitempty"`
Logo string `json:"logo,omitempty"`
Tag string `json:"tag,omitempty"`
} `json:"token,omitempty"`
TokenType string `json:"tokenType,omitempty"`
Balance string `json:"balance,omitempty"`
UserAddress string `json:"userAddress,omitempty"`
Quotes struct {
Usd struct {
Symbol string `json:"symbol,omitempty"`
Price float64 `json:"price,omitempty"`
PriceChange24HPercentage int `json:"priceChange24hPercentage,omitempty"`
Value float64 `json:"value,omitempty"`
Timestamp int `json:"timestamp,omitempty"`
} `json:"usd,omitempty"`
} `json:"quotes,omitempty"`
AssetType string `json:"assetType,omitempty"`
} `json:"underlying,omitempty"`
HarvestedReward []struct {
Token struct {
Address string `json:"address,omitempty"`
Symbol string `json:"symbol,omitempty"`
Name string `json:"name,omitempty"`
Decimals int `json:"decimals,omitempty"`
Logo string `json:"logo,omitempty"`
Tag string `json:"tag,omitempty"`
} `json:"token,omitempty"`
TokenType string `json:"tokenType,omitempty"`
Balance string `json:"balance,omitempty"`
UserAddress string `json:"userAddress,omitempty"`
Quotes struct {
Usd struct {
Symbol string `json:"symbol,omitempty"`
Price float64 `json:"price,omitempty"`
PriceChange24HPercentage float64 `json:"priceChange24hPercentage,omitempty"`
Value float64 `json:"value,omitempty"`
Timestamp int `json:"timestamp,omitempty"`
} `json:"usd,omitempty"`
} `json:"quotes,omitempty"`
Web3ProjectAddress string `json:"web3ProjectAddress,omitempty"`
AssetType string `json:"assetType,omitempty"`
} `json:"harvestedReward,omitempty"`
LpData struct {
LpPoolData struct {
Token0 struct {
Address string `json:"address,omitempty"`
Symbol string `json:"symbol,omitempty"`
Name string `json:"name,omitempty"`
Decimals int `json:"decimals,omitempty"`
Logo string `json:"logo,omitempty"`
Tag string `json:"tag,omitempty"`
} `json:"token0,omitempty"`
Token1 struct {
Address string `json:"address,omitempty"`
Symbol string `json:"symbol,omitempty"`
Name string `json:"name,omitempty"`
Decimals int `json:"decimals,omitempty"`
Logo string `json:"logo,omitempty"`
Tag string `json:"tag,omitempty"`
} `json:"token1,omitempty"`
Fee float64 `json:"fee,omitempty"`
PoolAddress string `json:"poolAddress,omitempty"`
} `json:"lpPoolData,omitempty"`
LpPositionData struct {
CurrentPrice float64 `json:"currentPrice,omitempty"`
MinPrice float64 `json:"minPrice,omitempty"`
MaxPrice float64 `json:"maxPrice,omitempty"`
TotalToken0Amount string `json:"totalToken0Amount,omitempty"`
TotalToken1Amount string `json:"totalToken1Amount,omitempty"`
CurrentToken0Amount string `json:"currentToken0Amount,omitempty"`
CurrentToken1Amount string `json:"currentToken1Amount,omitempty"`
TotalFeeEarned0 string `json:"totalFeeEarned0,omitempty"`
TotalFeeEarned1 string `json:"totalFeeEarned1,omitempty"`
NfpmAddress string `json:"nfpmAddress,omitempty"`
TokenID string `json:"tokenId,omitempty"`
ClosedBlockTime int `json:"closedBlockTime,omitempty"`
DepositedTime int `json:"depositedTime,omitempty"`
TotalFeeEarned0LastWithdraw string `json:"totalFeeEarned0LastWithdraw,omitempty"`
TotalFeeEarned1LastWithdraw string `json:"totalFeeEarned1LastWithdraw,omitempty"`
StakedTime int `json:"stakedTime,omitempty"`
FarmClosedBlockTime int `json:"farmClosedBlockTime,omitempty"`
TotalToken0Value float64 `json:"totalToken0Value,omitempty"`
TotalToken1Value float64 `json:"totalToken1Value,omitempty"`
CurrentToken0Value float64 `json:"currentToken0Value,omitempty"`
CurrentToken1Value float64 `json:"currentToken1Value,omitempty"`
YesterdayEarning float64 `json:"yesterdayEarning,omitempty"`
YesterdayFeeEarning float64 `json:"yesterdayFeeEarning,omitempty"`
YesterdayRewardEarning float64 `json:"yesterdayRewardEarning,omitempty"`
TotalFeeEarned0Usd float64 `json:"totalFeeEarned0Usd,omitempty"`
TotalFeeEarned1Usd float64 `json:"totalFeeEarned1Usd,omitempty"`
TotalFeeEarned float64 `json:"totalFeeEarned,omitempty"`
TotalFeeEarned0LastWithdrawUsd float64 `json:"totalFeeEarned0LastWithdrawUsd,omitempty"`
TotalFeeEarned1LastWithdrawUsd float64 `json:"totalFeeEarned1LastWithdrawUsd,omitempty"`
TotalFarmingReward float64 `json:"totalFarmingReward,omitempty"`
ImpermanentLoss float64 `json:"impermanentLoss,omitempty"`
Pnl float64 `json:"pnl,omitempty"`
Apr float64 `json:"apr,omitempty"`
Status string `json:"status,omitempty"`
AvgConvertPrice string `json:"avgConvertPrice,omitempty"`
IsCovertFromToken0 bool `json:"isCovertFromToken0,omitempty"`
} `json:"lpPositionData,omitempty"`
LpUniV2Data struct {
CurrentPrice int `json:"currentPrice,omitempty"`
TotalToken0Amount string `json:"totalToken0Amount,omitempty"`
TotalToken1Amount string `json:"totalToken1Amount,omitempty"`
CurrentToken0Amount string `json:"currentToken0Amount,omitempty"`
CurrentToken1Amount string `json:"currentToken1Amount,omitempty"`
TotalFeeEarned0 string `json:"totalFeeEarned0,omitempty"`
TotalFeeEarned1 string `json:"totalFeeEarned1,omitempty"`
LastLiqChangeBlockNum int `json:"lastLiqChangeBlockNum,omitempty"`
LastLiqChangeBlockTime int `json:"lastLiqChangeBlockTime,omitempty"`
TotalToken0Usd int `json:"totalToken0Usd,omitempty"`
TotalToken1Usd int `json:"totalToken1Usd,omitempty"`
CurrentToken0Usd int `json:"currentToken0Usd,omitempty"`
CurrentToken1Usd int `json:"currentToken1Usd,omitempty"`
FeeToken0Usd int `json:"feeToken0Usd,omitempty"`
FeeToken1Usd int `json:"feeToken1Usd,omitempty"`
ImpermanentLoss int `json:"impermanentLoss,omitempty"`
Pnl int `json:"pnl,omitempty"`
Apr int `json:"apr,omitempty"`
} `json:"lpUniV2Data,omitempty"`
} `json:"lpData,omitempty"`
AssetType string `json:"assetType,omitempty"`
} `json:"balances,omitempty"`
} `json:"data,omitempty"`
}
func main() {
getHolders()
}
func getHolders() {
r, err := http.Get("https://api.debank.com/pool/top_holders?start=0&limit=20000&id=0x556b9306565093c855aea9ae92a594704c2cd59e&chain_id=bsc")
if err != nil {
fmt.Print(err.Error())
os.Exit(1)
}
rd, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Fatal(err)
}
var responseObject HolderResponse
json.Unmarshal(rd, &responseObject)
// fmt.Println(responseObject.ErrorCode)
// fmt.Println(len(responseObject.Data.Holders))
for i := 0; i < len(responseObject.Data.Holders); i++ {
var url = fmt.Sprintf("https://api-dev.krystal.team/all/v1/balance/lp?addresses=%s&quoteSymbols=usd,btc&chainIds=1,56,137,43114,25,250,42161,1313161554,8217,10,59144,101&includeClosedPosition=true", responseObject.Data.Holders[i].Id)
parseLP(url)
}
}
func parseLP(url string) {
r, err := http.Get(url)
if err != nil {
fmt.Print(err.Error())
os.Exit(1)
}
rd, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Fatal(err)
}
var responseObject LPAutoGenerated
json.Unmarshal(rd, &responseObject)
for i :=0; i < len(responseObject.Data); i++ {
for j:=0; j < len(responseObject.Data[i].Balances); j++ {
postion := responseObject.Data[i].Balances[j]
if len(postion.Underlying) > 1 {
underlying0 := postion.Underlying[0]
underlying1 := postion.Underlying[1]
lpPositionData := postion.LpData.LpPositionData
totalToken0Value := lpPositionData.TotalToken0Value
totalToken1Value := lpPositionData.TotalToken1Value
currentToken0Value := lpPositionData.CurrentToken0Value
currentToken1Value := lpPositionData.CurrentToken1Value
yesterdayEarning := lpPositionData.YesterdayEarning
yesterdayFeeEarning := lpPositionData.YesterdayFeeEarning
yesterdayRewardEarning := lpPositionData.YesterdayRewardEarning
totalFeeEarned0Usd := lpPositionData.TotalFeeEarned0Usd
totalFeeEarned1Usd := lpPositionData.TotalFeeEarned1Usd
totalFeeEarned := lpPositionData.TotalFeeEarned
totalFeeEarned0LastWithdrawUsd := lpPositionData.TotalFeeEarned0LastWithdrawUsd
totalFeeEarned1LastWithdrawUsd := lpPositionData.TotalFeeEarned1LastWithdrawUsd
pnl := lpPositionData.Pnl
apr := lpPositionData.Apr
// token0 := underlying0.Balance
// token1 := underlying1.Balance
token0Value := underlying0.Quotes.Usd.Value
token1Value := underlying1.Quotes.Usd.Value
// harvestedReward0Value := harvestedReward0.Quotes.Usd.Value
// harvestedReward1Value := harvestedReward1.Quotes.Usd.Value
ONE_HUNDRED_MILION := math.Pow(10, 8)
ONE_HUNDRED_MILION_FLOAT := float64(ONE_HUNDRED_MILION)
// if token0Value < 0 {
// output := fmt.Sprintf("token0Value: %f", token0Value)
// fmt.Println(output)
// }
// if token1Value < 0 {
// output := fmt.Sprintf("token1Value: %f", token1Value)
// fmt.Println(output)
// }
// if token0Value > ONE_HUNDRED_MILION {
// output := fmt.Sprintf("token0Value: %f", token0Value)
// fmt.Println(output)
// }
// if token1Value > ONE_HUNDRED_MILION {
// output := fmt.Sprintf("token1Value: %f", token1Value)
// fmt.Println(output)
// }
// if totalToken0Value < 0 || {
// output := fmt.Sprintf("token1Value: %f", token1Value)
// fmt.Println(output)
// }
if token0Value < 0 || token1Value < 0 || token0Value > ONE_HUNDRED_MILION|| token1Value > ONE_HUNDRED_MILION ||
totalToken0Value < 0 || totalToken1Value < 0 ||
currentToken0Value < 0 ||
currentToken1Value < 0 ||
yesterdayEarning < 0 ||
yesterdayFeeEarning < 0 ||
yesterdayRewardEarning < 0 ||
totalFeeEarned0Usd < 0 ||
totalFeeEarned1Usd < 0 ||
totalFeeEarned < 0 ||
totalFeeEarned0LastWithdrawUsd < 0 ||
totalFeeEarned1LastWithdrawUsd < 0 ||
apr < 0 ||
totalToken0Value > ONE_HUNDRED_MILION_FLOAT ||
totalToken1Value > ONE_HUNDRED_MILION_FLOAT ||
currentToken0Value > ONE_HUNDRED_MILION_FLOAT ||
currentToken1Value > ONE_HUNDRED_MILION_FLOAT ||
yesterdayEarning > ONE_HUNDRED_MILION_FLOAT ||
yesterdayFeeEarning > ONE_HUNDRED_MILION_FLOAT ||
yesterdayRewardEarning > ONE_HUNDRED_MILION_FLOAT ||
totalFeeEarned0Usd > ONE_HUNDRED_MILION_FLOAT ||
totalFeeEarned1Usd > ONE_HUNDRED_MILION_FLOAT ||
totalFeeEarned > ONE_HUNDRED_MILION_FLOAT ||
totalFeeEarned0LastWithdrawUsd > ONE_HUNDRED_MILION_FLOAT ||
totalFeeEarned1LastWithdrawUsd > ONE_HUNDRED_MILION_FLOAT ||
pnl > ONE_HUNDRED_MILION_FLOAT ||
apr > ONE_HUNDRED_MILION_FLOAT {
fmt.Println("===================Issue")
output := fmt.Sprintf("https://wallet-dev.krystal.team/liquidity-lens/%s/%s/%s", postion.UserAddress, postion.Web3ProjectAddress, postion.TokenID)
// output := fmt.Sprintf("User %s having token0Value: %f, token1Value: %f", postion.UserAddress, token0Value, token1Value)
fmt.Println(output)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment