Skip to content

Commit

Permalink
small improvements to withdra script
Browse files Browse the repository at this point in the history
Signed-off-by: microwavedcola1 <[email protected]>
  • Loading branch information
microwavedcola1 committed Aug 19, 2024
1 parent b9dd4bf commit f1e9420
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ts/client/scripts/force-withdraw-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,20 @@ async function forceWithdrawTokens(): Promise<void> {

const group = await client.getGroup(new PublicKey(GROUP_PK));
const forceWithdrawBank = group.getFirstBankByTokenIndex(TOKEN_INDEX);
console.log(`${forceWithdrawBank.name} bank`);
const serum3Market = Array.from(
group.serum3MarketsMapByMarketIndex.values(),
).filter((m) => m.baseTokenIndex == TOKEN_INDEX)[0];

// Get all mango accounts with deposits for given token
const mangoAccountsWithDeposits = (
const mangoAccountsWithInUseCount = (
await client.getAllMangoAccounts(group)
).filter((a) => a.getTokenBalanceUi(forceWithdrawBank) > 0);
).filter((a) => a.getTokenInUseCount(forceWithdrawBank) > 0);

for (const mangoAccount of mangoAccountsWithDeposits) {
console.log(
`Found ${mangoAccountsWithInUseCount.length} mango accounts with in use count > 0`,
);

for (const mangoAccount of mangoAccountsWithInUseCount) {
console.log(
`${mangoAccount.getTokenBalanceUi(forceWithdrawBank)} for ${
mangoAccount.publicKey
Expand Down
5 changes: 5 additions & 0 deletions ts/client/src/accounts/mangoAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ export class MangoAccount {
return tp ? tp.balanceUi(bank) : 0;
}

public getTokenInUseCount(bank: Bank): number {
const tp = this.getToken(bank.tokenIndex);
return tp?.inUseCount ?? 0;
}

/**
*
* @param bank
Expand Down

0 comments on commit f1e9420

Please sign in to comment.