Skip to content

Commit

Permalink
extend script for force withdraw
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 f571bd8 commit b9dd4bf
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions ts/client/scripts/force-withdraw-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,36 +38,53 @@ async function forceWithdrawTokens(): Promise<void> {

const group = await client.getGroup(new PublicKey(GROUP_PK));
const forceWithdrawBank = group.getFirstBankByTokenIndex(TOKEN_INDEX);
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 = (
await client.getAllMangoAccounts(group)
).filter((a) => a.getTokenBalanceUi(forceWithdrawBank) > 0);

for (const mangoAccount of mangoAccountsWithDeposits) {
// const sig = await client.serum3LiqForceCancelOrders(group, mangoAccount);

const sig = await client.tokenForceWithdraw(
group,
mangoAccount,
TOKEN_INDEX,
);
console.log(
`Withdrawing ${mangoAccount.getTokenBalanceUi(forceWithdrawBank)} for ${
`${mangoAccount.getTokenBalanceUi(forceWithdrawBank)} for ${
mangoAccount.publicKey
}`,
);

client.tokenForceWithdraw(group, mangoAccount, TOKEN_INDEX).then((sig) => {
console.log(
` tokenForceWithdraw for ${mangoAccount.publicKey}, owner ${
mangoAccount.owner
}, sig https://explorer.solana.com/tx/${sig.signature}?cluster=${
CLUSTER == 'devnet' ? 'devnet' : ''
}`,
);
});
client
.serum3LiqForceCancelOrders(
group,
mangoAccount,
serum3Market.serumMarketExternal,
)
.then((sig) => {
console.log(
` serum3LiqForceCancelOrders for ${mangoAccount.publicKey}, owner ${
mangoAccount.owner
}, sig https://explorer.solana.com/tx/${sig.signature}?cluster=${
CLUSTER == 'devnet' ? 'devnet' : ''
}`,
);

client
.tokenForceWithdraw(group, mangoAccount, TOKEN_INDEX)
.then((sig) => {
console.log(
` tokenForceWithdraw for ${mangoAccount.publicKey}, owner ${
mangoAccount.owner
}, sig https://explorer.solana.com/tx/${sig.signature}?cluster=${
CLUSTER == 'devnet' ? 'devnet' : ''
}`,
);
});
});
}

await group.reloadAll(client);
console.log(forceWithdrawBank.uiDeposits());
}

forceWithdrawTokens();

0 comments on commit b9dd4bf

Please sign in to comment.