From b9dd4bffa3346dd5b2fec28950b868b1dafd7708 Mon Sep 17 00:00:00 2001 From: microwavedcola1 Date: Mon, 19 Aug 2024 13:47:28 +0200 Subject: [PATCH] extend script for force withdraw Signed-off-by: microwavedcola1 --- ts/client/scripts/force-withdraw-token.ts | 51 +++++++++++++++-------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/ts/client/scripts/force-withdraw-token.ts b/ts/client/scripts/force-withdraw-token.ts index acc129d4e..bd15d30a5 100644 --- a/ts/client/scripts/force-withdraw-token.ts +++ b/ts/client/scripts/force-withdraw-token.ts @@ -38,6 +38,9 @@ async function forceWithdrawTokens(): Promise { 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 = ( @@ -45,29 +48,43 @@ async function forceWithdrawTokens(): Promise { ).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();