Mc/keeper (#714)
* v0.19.28 * ts: tokenWithdrawAllDepositForMint Signed-off-by: microwavedcola1 <microwavedcola@gmail.com> * Fix Signed-off-by: microwavedcola1 <microwavedcola@gmail.com> * Fix Signed-off-by: microwavedcola1 <microwavedcola@gmail.com> * rust: dont include tokens with errors in crank Signed-off-by: microwavedcola1 <microwavedcola@gmail.com> * Fixes from review Signed-off-by: microwavedcola1 <microwavedcola@gmail.com> * review fixes * Fixes from review Signed-off-by: microwavedcola1 <microwavedcola@gmail.com> --------- Signed-off-by: microwavedcola1 <microwavedcola@gmail.com> Co-authored-by: Christian Kamm <mail@ckamm.de>
This commit is contained in:
parent
b2c187dd92
commit
885427e777
|
@ -217,7 +217,22 @@ pub async fn loop_update_index_and_rate(
|
|||
is_writable: true,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
ix.accounts.append(&mut banks);
|
||||
|
||||
let sim_result = match client.simulate(vec![ix.clone()]).await {
|
||||
Ok(response) => response.value,
|
||||
Err(e) => {
|
||||
error!(token.name, "simulation request error: {e:?}");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(e) = sim_result.err {
|
||||
error!(token.name, "simulation error: {e:?} {:?}", sim_result.logs);
|
||||
continue;
|
||||
}
|
||||
|
||||
instructions.push(ix);
|
||||
}
|
||||
let pre = Instant::now();
|
||||
|
|
|
@ -26,6 +26,7 @@ use mango_v4::state::{
|
|||
use solana_address_lookup_table_program::state::AddressLookupTable;
|
||||
use solana_client::nonblocking::rpc_client::RpcClient as RpcClientAsync;
|
||||
use solana_client::rpc_config::RpcSendTransactionConfig;
|
||||
use solana_client::rpc_response::RpcSimulateTransactionResult;
|
||||
use solana_sdk::address_lookup_table_account::AddressLookupTableAccount;
|
||||
use solana_sdk::commitment_config::CommitmentLevel;
|
||||
use solana_sdk::hash::Hash;
|
||||
|
@ -1757,6 +1758,21 @@ impl MangoClient {
|
|||
.send_and_confirm(&self.client)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn simulate(
|
||||
&self,
|
||||
instructions: Vec<Instruction>,
|
||||
) -> anyhow::Result<SimulateTransactionResponse> {
|
||||
TransactionBuilder {
|
||||
instructions,
|
||||
address_lookup_tables: vec![],
|
||||
payer: self.client.fee_payer.pubkey(),
|
||||
signers: vec![self.client.fee_payer.clone()],
|
||||
config: self.client.transaction_builder_config,
|
||||
}
|
||||
.simulate(&self.client)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
@ -1784,6 +1800,9 @@ pub struct TransactionBuilder {
|
|||
pub config: TransactionBuilderConfig,
|
||||
}
|
||||
|
||||
pub type SimulateTransactionResponse =
|
||||
solana_client::rpc_response::Response<RpcSimulateTransactionResult>;
|
||||
|
||||
impl TransactionBuilder {
|
||||
pub async fn transaction(
|
||||
&self,
|
||||
|
@ -1834,6 +1853,12 @@ impl TransactionBuilder {
|
|||
.map_err(prettify_solana_client_error)
|
||||
}
|
||||
|
||||
pub async fn simulate(&self, client: &Client) -> anyhow::Result<SimulateTransactionResponse> {
|
||||
let rpc = client.rpc_async();
|
||||
let tx = self.transaction(&rpc).await?;
|
||||
Ok(rpc.simulate_transaction(&tx).await?)
|
||||
}
|
||||
|
||||
pub async fn send_and_confirm(&self, client: &Client) -> anyhow::Result<Signature> {
|
||||
let rpc = client.rpc_async();
|
||||
let tx = self.transaction(&rpc).await?;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@blockworks-foundation/mango-v4",
|
||||
"version": "0.19.27",
|
||||
"version": "0.19.28",
|
||||
"description": "Typescript Client for mango-v4 program.",
|
||||
"repository": "https://github.com/blockworks-foundation/mango-v4",
|
||||
"author": {
|
||||
|
|
|
@ -1409,6 +1409,35 @@ export class MangoClient {
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Withdraw the entire deposit balance for a token, effectively freeing the token position
|
||||
*
|
||||
* @param group
|
||||
* @param mangoAccount
|
||||
* @param mintPk
|
||||
* @returns
|
||||
*/
|
||||
public async tokenWithdrawAllDepositForMint(
|
||||
group: Group,
|
||||
mangoAccount: MangoAccount,
|
||||
mintPk: PublicKey,
|
||||
): Promise<MangoSignatureStatus> {
|
||||
const bank = group.getFirstBankByMint(mintPk);
|
||||
const b = mangoAccount.getTokenBalance(bank).toNumber();
|
||||
if (b < 0) {
|
||||
throw new Error(`Only call this method for deposits and not borrows!`);
|
||||
}
|
||||
const ixes = await this.tokenWithdrawNativeIx(
|
||||
group,
|
||||
mangoAccount,
|
||||
mintPk,
|
||||
U64_MAX_BN,
|
||||
false,
|
||||
);
|
||||
|
||||
return await this.sendAndConfirmTransactionForGroup(group, ixes);
|
||||
}
|
||||
|
||||
public async tokenWithdraw(
|
||||
group: Group,
|
||||
mangoAccount: MangoAccount,
|
||||
|
|
Loading…
Reference in New Issue