Skip to content

Commit

Permalink
msol tvl calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
nope-finance committed Mar 29, 2023
1 parent c67cd04 commit 0e3e393
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
53 changes: 53 additions & 0 deletions solend-sdk/src/experimental/msol_tvl.ts
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();
5 changes: 1 addition & 4 deletions solend-sdk/src/state/reserve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,7 @@ export const ReserveLayout: typeof BufferLayout.Structure = BufferLayout.struct(
BufferLayout.struct(
[
BufferLayout.struct(
[
Layout.uint64("maxOutflow"),
Layout.uint64("windowDuration"),
],
[Layout.uint64("maxOutflow"), Layout.uint64("windowDuration")],
"config"
),
Layout.uint128("previousQuantity"),
Expand Down
3 changes: 3 additions & 0 deletions solend-sdk/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"esModuleInterop": true,
"typeRoots": ["./types", "./node_modules/@types"]
},
"ts-node": {
"files": true
},
"include": ["src/**/*"],
"exclude": ["src/experimental/*"]
}

0 comments on commit 0e3e393

Please sign in to comment.