2023-05-16 00:52:21 -07:00
|
|
|
import { AnchorProvider, Wallet } from '@coral-xyz/anchor';
|
2023-05-13 02:55:08 -07:00
|
|
|
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
|
|
|
import { MangoClient } from '../src/client';
|
|
|
|
import { MANGO_V4_ID } from '../src/constants';
|
2023-05-16 00:52:21 -07:00
|
|
|
import { getRiskStats } from '../src/risk';
|
2023-05-13 02:55:08 -07:00
|
|
|
|
|
|
|
const { MB_CLUSTER_URL } = process.env;
|
|
|
|
|
|
|
|
const GROUP_PK = '78b8f4cGCwmZ9ysPFMWLaLTkkaYnUjwMJYStWe5RTSSX';
|
|
|
|
|
|
|
|
async function buildClient(): Promise<MangoClient> {
|
|
|
|
const clientKeypair = new Keypair();
|
|
|
|
|
|
|
|
const options = AnchorProvider.defaultOptions();
|
|
|
|
const connection = new Connection(MB_CLUSTER_URL!, options);
|
|
|
|
|
|
|
|
const clientWallet = new Wallet(clientKeypair);
|
|
|
|
const clientProvider = new AnchorProvider(connection, clientWallet, options);
|
|
|
|
|
|
|
|
return await MangoClient.connect(
|
|
|
|
clientProvider,
|
|
|
|
'mainnet-beta',
|
|
|
|
MANGO_V4_ID['mainnet-beta'],
|
|
|
|
{
|
|
|
|
idsSource: 'get-program-accounts',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main(): Promise<void> {
|
|
|
|
const client = await buildClient();
|
|
|
|
const group = await client.getGroup(new PublicKey(GROUP_PK));
|
2023-05-16 01:05:10 -07:00
|
|
|
try {
|
|
|
|
console.log(JSON.stringify(await getRiskStats(client, group), null, 2));
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
}
|
2023-05-13 02:55:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
main();
|