force close mango account script
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
48b5b81a09
commit
ebeb2328b9
|
@ -17,7 +17,7 @@ const PAYER_KEYPAIR =
|
|||
const USER_KEYPAIR =
|
||||
process.env.USER_KEYPAIR_OVERRIDE || process.env.MB_PAYER_KEYPAIR;
|
||||
const GROUP_NUM = Number(process.env.GROUP_NUM || 0);
|
||||
const MANGO_ACCOUNT = process.env.MANGO_ACCOUNT_PK;
|
||||
const MANGO_ACCOUNT_PK = process.env.MANGO_ACCOUNT_PK;
|
||||
const CLUSTER: Cluster =
|
||||
(process.env.CLUSTER_OVERRIDE as Cluster) || 'mainnet-beta';
|
||||
|
||||
|
@ -257,8 +257,8 @@ async function main(): Promise<void> {
|
|||
|
||||
for (const mangoAccount of mangoAccounts) {
|
||||
if (
|
||||
!MANGO_ACCOUNT ||
|
||||
mangoAccount.publicKey.equals(new PublicKey(MANGO_ACCOUNT))
|
||||
!MANGO_ACCOUNT_PK ||
|
||||
mangoAccount.publicKey.equals(new PublicKey(MANGO_ACCOUNT_PK))
|
||||
) {
|
||||
console.log();
|
||||
console.log(`MangoAccount ${mangoAccount.publicKey}`);
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
import { AnchorProvider, Wallet } from '@project-serum/anchor';
|
||||
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
||||
import fs from 'fs';
|
||||
import { Group } from '../accounts/group';
|
||||
import { MangoClient } from '../client';
|
||||
import { MANGO_V4_ID } from '../constants';
|
||||
|
||||
const GROUP_NUM = Number(process.env.GROUP_NUM || 0);
|
||||
const MANGO_ACCOUNT_PK = process.env.MANGO_ACCOUNT_PK;
|
||||
const { MB_CLUSTER_URL, MB_PAYER_KEYPAIR, MB_USER_KEYPAIR, MB_USER4_KEYPAIR } =
|
||||
process.env;
|
||||
|
||||
async function buildUserClient(
|
||||
userKeypair: string,
|
||||
): Promise<[MangoClient, Group, Keypair]> {
|
||||
const options = AnchorProvider.defaultOptions();
|
||||
const connection = new Connection(MB_CLUSTER_URL!, options);
|
||||
|
||||
const user = Keypair.fromSecretKey(
|
||||
Buffer.from(JSON.parse(fs.readFileSync(userKeypair, 'utf-8'))),
|
||||
);
|
||||
const userWallet = new Wallet(user);
|
||||
const userProvider = new AnchorProvider(connection, userWallet, options);
|
||||
|
||||
const client = await MangoClient.connect(
|
||||
userProvider,
|
||||
'mainnet-beta',
|
||||
MANGO_V4_ID['mainnet-beta'],
|
||||
);
|
||||
|
||||
const admin = Keypair.fromSecretKey(
|
||||
Buffer.from(JSON.parse(fs.readFileSync(MB_PAYER_KEYPAIR!, 'utf-8'))),
|
||||
);
|
||||
console.log(`Admin ${admin.publicKey.toBase58()}`);
|
||||
const group = await client.getGroupForCreator(admin.publicKey, GROUP_NUM);
|
||||
return [client, group, user];
|
||||
}
|
||||
|
||||
async function forceCloseUserAccount() {
|
||||
const result = await buildUserClient(MB_PAYER_KEYPAIR!);
|
||||
const client = result[0];
|
||||
const group = result[1];
|
||||
const mangoAccount = await client.getMangoAccount(
|
||||
new PublicKey(MANGO_ACCOUNT_PK!),
|
||||
);
|
||||
await client.closeMangoAccount(group, mangoAccount, true);
|
||||
process.exit();
|
||||
}
|
||||
|
||||
async function main() {
|
||||
await forceCloseUserAccount();
|
||||
}
|
||||
|
||||
main();
|
Loading…
Reference in New Issue