-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c67cd04
commit 0e3e393
Showing
3 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* eslint-disable no-unused-vars */ | ||
import { Connection, PublicKey } from "@solana/web3.js"; | ||
import { | ||
SOLEND_PRODUCTION_PROGRAM_ID, | ||
RESERVE_SIZE, | ||
parseReserve, | ||
} from "../../dist"; | ||
import { getAccount } from "@solana/spl-token"; | ||
|
||
const MSOL_MINT_PUBKEY = "mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"; | ||
// clone and replace with your rpc else this will probably error | ||
const SOLANA_RPC_ENDPOINT = "https://api.mainnet-beta.solana.com"; | ||
|
||
const connection = new Connection(SOLANA_RPC_ENDPOINT); | ||
|
||
const main = async () => { | ||
const resp = await connection.getProgramAccounts( | ||
new PublicKey(SOLEND_PRODUCTION_PROGRAM_ID), | ||
{ | ||
commitment: connection.commitment, | ||
filters: [ | ||
{ | ||
dataSize: RESERVE_SIZE, | ||
}, | ||
], | ||
encoding: "base64", | ||
} | ||
); | ||
|
||
const reserves = resp.map((account) => | ||
parseReserve(account.pubkey, account.account, "base64") | ||
); | ||
|
||
const msolReserves = reserves.filter( | ||
(reserve) => | ||
reserve?.info.liquidity.mintPubkey.toBase58() === MSOL_MINT_PUBKEY | ||
); | ||
|
||
const msolTokenAccounts = await Promise.all( | ||
msolReserves.map( | ||
async (reserve) => | ||
await getAccount(connection, reserve?.info.liquidity.supplyPubkey!) | ||
) | ||
); | ||
|
||
const msolBalances = msolTokenAccounts.map( | ||
(tokenAccounts) => tokenAccounts.amount | ||
); | ||
|
||
console.log(msolBalances.reduce((a, b) => a + b).toString()); | ||
}; | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters