fix package.json targets

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2022-04-07 17:16:46 +02:00
parent 921dd8e0a6
commit ed312e71d5
4 changed files with 48 additions and 3 deletions

View File

@ -8,7 +8,8 @@
"scripts": {
"build": "tsc",
"clean": "rm -rf dist",
"example": "ts-node ts/example.ts",
"example0": "ts-node ts/example0.ts",
"example1": "ts-node ts/example1.ts",
"format": "prettier --check .",
"lint": "eslint . --ext ts --ext tsx --ext js --quiet",
"type-check": "tsc --pretty --noEmit"

View File

@ -3,6 +3,7 @@ import {
Transaction,
TransactionInstruction,
} from '@solana/web3.js';
import { assert } from 'console';
import { MangoClient } from '../../client';
export class Group {
@ -39,8 +40,8 @@ export async function createGroupIx(
export async function getGroupForAdmin(
client: MangoClient,
adminPk: PublicKey,
): Promise<Group[]> {
return (
): Promise<Group> {
const groups = (
await client.program.account.group.all([
{
memcmp: {
@ -50,4 +51,8 @@ export async function getGroupForAdmin(
},
])
).map((tuple) => Group.from(tuple.publicKey, tuple.account));
assert(groups.length == 1);
return groups[0];
}

View File

@ -1,5 +1,6 @@
import { Program, Provider } from '@project-serum/anchor';
import { PublicKey } from '@solana/web3.js';
import { getGroupForAdmin, Group } from './accounts/types/group';
import { IDL, MangoV4 } from './mango_v4';
export const MANGO_V4_ID = new PublicKey(
@ -47,4 +48,10 @@ export class MangoClient {
devnet,
);
}
public getGroup(adminPk: PublicKey): Promise<Group> {
return getGroupForAdmin(this, adminPk);
}
}

32
ts/example1.ts Normal file
View File

@ -0,0 +1,32 @@
import { Provider, Wallet } from '@project-serum/anchor';
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
import fs from 'fs';
import { MangoClient } from './client';
//
// An example based on high level api i.e. the client
//
async function main() {
const options = Provider.defaultOptions();
const connection = new Connection(
'https://mango.devnet.rpcpool.com',
options,
);
const user = Keypair.fromSecretKey(
Buffer.from(
JSON.parse(fs.readFileSync(process.env.USER_KEYPAIR!, 'utf-8')),
),
);
const userWallet = new Wallet(user);
const userProvider = new Provider(connection, userWallet, options);
const client = await MangoClient.connect(userProvider, true);
console.log(`User ${userWallet.publicKey.toBase58()}`);
const group = await client.getGroup(
new PublicKey('6ACH752p6FsdLzuociVkmDwc3wJW8pcCoxZKfXJKfKcD'),
);
console.log(group);
}
main();