Skip to content

Commit 0e3e393

Browse files
committed
msol tvl calculator
1 parent c67cd04 commit 0e3e393

3 files changed

Lines changed: 57 additions & 4 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 { 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();

solend-sdk/src/state/reserve.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,7 @@ export const ReserveLayout: typeof BufferLayout.Structure = BufferLayout.struct(
141141
BufferLayout.struct(
142142
[
143143
BufferLayout.struct(
144-
[
145-
Layout.uint64("maxOutflow"),
146-
Layout.uint64("windowDuration"),
147-
],
144+
[Layout.uint64("maxOutflow"), Layout.uint64("windowDuration")],
148145
"config"
149146
),
150147
Layout.uint128("previousQuantity"),

solend-sdk/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
"esModuleInterop": true,
1313
"typeRoots": ["./types", "./node_modules/@types"]
1414
},
15+
"ts-node": {
16+
"files": true
17+
},
1518
"include": ["src/**/*"],
1619
"exclude": ["src/experimental/*"]
1720
}

0 commit comments

Comments
 (0)