2022-04-02 23:57:45 -07:00
|
|
|
import {
|
|
|
|
PublicKey,
|
|
|
|
Transaction,
|
|
|
|
TransactionInstruction,
|
2022-04-07 08:58:20 -07:00
|
|
|
TransactionSignature,
|
2022-04-02 23:57:45 -07:00
|
|
|
} from '@solana/web3.js';
|
|
|
|
import { MangoClient } from '../../client';
|
|
|
|
|
|
|
|
export class Group {
|
|
|
|
static from(publicKey: PublicKey, obj: { admin: PublicKey }): Group {
|
|
|
|
return new Group(publicKey, obj.admin);
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(public publicKey: PublicKey, public admin: PublicKey) {}
|
|
|
|
}
|
|
|
|
|
2022-04-07 12:00:08 -07:00
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
*/
|
2022-04-02 23:57:45 -07:00
|
|
|
export async function createGroup(
|
|
|
|
client: MangoClient,
|
|
|
|
adminPk: PublicKey,
|
2022-04-07 08:58:20 -07:00
|
|
|
): Promise<TransactionSignature> {
|
2022-04-02 23:57:45 -07:00
|
|
|
const tx = new Transaction();
|
2022-04-07 08:03:44 -07:00
|
|
|
const ix = await createGroupIx(client, adminPk);
|
2022-04-02 23:57:45 -07:00
|
|
|
tx.add(ix);
|
2022-04-07 08:58:20 -07:00
|
|
|
return await client.program.provider.send(tx);
|
2022-04-02 23:57:45 -07:00
|
|
|
}
|
|
|
|
|
2022-04-07 12:00:08 -07:00
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
*/
|
2022-04-02 23:57:45 -07:00
|
|
|
export async function createGroupIx(
|
|
|
|
client: MangoClient,
|
|
|
|
adminPk: PublicKey,
|
|
|
|
): Promise<TransactionInstruction> {
|
|
|
|
return await client.program.methods
|
|
|
|
.createGroup()
|
|
|
|
.accounts({
|
|
|
|
admin: adminPk,
|
2022-04-07 08:03:44 -07:00
|
|
|
payer: adminPk,
|
2022-04-02 23:57:45 -07:00
|
|
|
})
|
|
|
|
.instruction();
|
|
|
|
}
|
|
|
|
|
2022-04-07 12:00:08 -07:00
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
*/
|
2022-04-02 23:57:45 -07:00
|
|
|
export async function getGroupForAdmin(
|
|
|
|
client: MangoClient,
|
|
|
|
adminPk: PublicKey,
|
2022-04-07 08:16:46 -07:00
|
|
|
): Promise<Group> {
|
|
|
|
const groups = (
|
2022-04-02 23:57:45 -07:00
|
|
|
await client.program.account.group.all([
|
|
|
|
{
|
|
|
|
memcmp: {
|
|
|
|
bytes: adminPk.toBase58(),
|
|
|
|
offset: 8,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
])
|
|
|
|
).map((tuple) => Group.from(tuple.publicKey, tuple.account));
|
2022-04-07 08:16:46 -07:00
|
|
|
return groups[0];
|
2022-04-02 23:57:45 -07:00
|
|
|
}
|