|
| 1 | +/* eslint-disable no-unused-vars */ |
| 2 | +import { Connection, PublicKey } from "@solana/web3.js"; |
| 3 | +import { |
| 4 | + SOLEND_PRODUCTION_PROGRAM_ID, |
| 5 | + RESERVE_SIZE, |
| 6 | + parseReserve, |
| 7 | +} from "../../dist"; |
| 8 | +import { getAssociatedTokenAddress, getAccount } from "@solana/spl-token"; |
| 9 | + |
| 10 | +const MSOL_MINT_PUBKEY = "mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"; |
| 11 | +// clone and replace with your rpc else this will probably error |
| 12 | +const SOLANA_RPC_ENDPOINT = "https://api.mainnet-beta.solana.com"; |
| 13 | + |
| 14 | +const connection = new Connection(SOLANA_RPC_ENDPOINT); |
| 15 | + |
| 16 | +const main = async () => { |
| 17 | + const resp = await connection.getProgramAccounts( |
| 18 | + new PublicKey(SOLEND_PRODUCTION_PROGRAM_ID), |
| 19 | + { |
| 20 | + commitment: connection.commitment, |
| 21 | + filters: [ |
| 22 | + { |
| 23 | + dataSize: RESERVE_SIZE, |
| 24 | + }, |
| 25 | + ], |
| 26 | + encoding: "base64", |
| 27 | + } |
| 28 | + ); |
| 29 | + |
| 30 | + const reserves = resp.map((account) => |
| 31 | + parseReserve(account.pubkey, account.account, "base64") |
| 32 | + ); |
| 33 | + |
| 34 | + const msolReserves = reserves.filter( |
| 35 | + (reserve) => |
| 36 | + reserve?.info.liquidity.mintPubkey.toBase58() === MSOL_MINT_PUBKEY |
| 37 | + ); |
| 38 | + |
| 39 | + const msolTokenAccounts = await Promise.all( |
| 40 | + msolReserves.map( |
| 41 | + async (reserve) => |
| 42 | + await getAccount(connection, reserve?.info.liquidity.supplyPubkey!) |
| 43 | + ) |
| 44 | + ); |
| 45 | + |
| 46 | + const msolBalances = msolTokenAccounts.map( |
| 47 | + (tokenAccounts) => tokenAccounts.amount |
| 48 | + ); |
| 49 | + |
| 50 | + console.log(msolBalances.reduce((a, b) => a + b).toString()); |
| 51 | +}; |
| 52 | + |
| 53 | +main(); |
0 commit comments