keeper token rate update - group multiple ixs into one (#151)
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
4f72985f2d
commit
24c359ef92
|
@ -2919,6 +2919,7 @@ dependencies = [
|
|||
"fixed",
|
||||
"fixed-macro",
|
||||
"futures 0.3.21",
|
||||
"itertools 0.10.3",
|
||||
"log 0.4.17",
|
||||
"mango-v4",
|
||||
"pyth-sdk-solana",
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
RPC_URL=https://mango.devnet.rpcpool.com
|
||||
PAYER_KEYPAIR=~/.config/solana/mango-devnet.json
|
||||
GROUP_FROM_ADMIN_KEYPAIR=~/.config/solana/admin.json
|
||||
MANGO_ACCOUNT_NAME=Account
|
|
@ -1,4 +0,0 @@
|
|||
RPC_URL=https://mango.rpcpool.com/
|
||||
PAYER_KEYPAIR=~/.config/solana/mango-mainnet.json
|
||||
GROUP=grouppubkey
|
||||
MANGO_ACCOUNT_NAME=Account
|
|
@ -17,6 +17,7 @@ env_logger = "0.8.4"
|
|||
fixed = { version = "=1.11.0", features = ["serde", "borsh"] }
|
||||
fixed-macro = "^1.1.1"
|
||||
futures = "0.3.21"
|
||||
itertools = "0.10.3"
|
||||
log = "0.4.0"
|
||||
mango-v4 = { path = "../programs/mango-v4", features = ["no-entrypoint", "client"] }
|
||||
pyth-sdk-solana = "0.1.0"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use std::{sync::Arc, time::Duration};
|
||||
|
||||
use crate::MangoClient;
|
||||
use itertools::Itertools;
|
||||
|
||||
use anchor_lang::{__private::bytemuck::cast_ref, solana_program};
|
||||
use client::prettify_client_error;
|
||||
|
@ -22,7 +23,16 @@ pub async fn runner(
|
|||
.context
|
||||
.tokens
|
||||
.keys()
|
||||
.map(|&token_index| loop_update_index_and_rate(mango_client.clone(), token_index))
|
||||
// TokenUpdateIndexAndRate is known to take max 71k cu
|
||||
// from cargo test-bpf local tests
|
||||
.chunks(15)
|
||||
.into_iter()
|
||||
.map(|chunk| {
|
||||
loop_update_index_and_rate(
|
||||
mango_client.clone(),
|
||||
chunk.copied().collect::<Vec<TokenIndex>>(),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let handles2 = mango_client
|
||||
|
@ -49,58 +59,65 @@ pub async fn runner(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn loop_update_index_and_rate(mango_client: Arc<MangoClient>, token_index: TokenIndex) {
|
||||
pub async fn loop_update_index_and_rate(
|
||||
mango_client: Arc<MangoClient>,
|
||||
token_indices: Vec<TokenIndex>,
|
||||
) {
|
||||
let mut interval = time::interval(Duration::from_secs(5));
|
||||
loop {
|
||||
interval.tick().await;
|
||||
|
||||
let client = mango_client.clone();
|
||||
|
||||
let res = tokio::task::spawn_blocking(move || -> anyhow::Result<()> {
|
||||
let token = client.context.token(token_index);
|
||||
let banks_for_a_token = token.mint_info.banks();
|
||||
let token_name = &token.name;
|
||||
let oracle = token.mint_info.oracle;
|
||||
let token_indices_clone = token_indices.clone();
|
||||
|
||||
let sig_result = client
|
||||
.program()
|
||||
.request()
|
||||
.instruction({
|
||||
let mut ix = Instruction {
|
||||
program_id: mango_v4::id(),
|
||||
accounts: anchor_lang::ToAccountMetas::to_account_metas(
|
||||
&mango_v4::accounts::TokenUpdateIndexAndRate {
|
||||
group: token.mint_info.group,
|
||||
mint_info: token.mint_info_address,
|
||||
oracle,
|
||||
instructions: solana_program::sysvar::instructions::id(),
|
||||
},
|
||||
None,
|
||||
),
|
||||
data: anchor_lang::InstructionData::data(
|
||||
&mango_v4::instruction::TokenUpdateIndexAndRate {},
|
||||
),
|
||||
};
|
||||
let mut banks = banks_for_a_token
|
||||
.iter()
|
||||
.map(|bank_pubkey| AccountMeta {
|
||||
pubkey: *bank_pubkey,
|
||||
is_signer: false,
|
||||
is_writable: true,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
ix.accounts.append(&mut banks);
|
||||
ix
|
||||
})
|
||||
.send()
|
||||
.map_err(prettify_client_error);
|
||||
let res = tokio::task::spawn_blocking(move || -> anyhow::Result<()> {
|
||||
let token_names = token_indices_clone
|
||||
.iter()
|
||||
.map(|token_index| client.context.token(*token_index).name.to_owned())
|
||||
.join(", ");
|
||||
|
||||
let program = client.program();
|
||||
let mut req = program.request();
|
||||
for token_index in token_indices_clone.iter() {
|
||||
let token = client.context.token(*token_index);
|
||||
let banks_for_a_token = token.mint_info.banks();
|
||||
let oracle = token.mint_info.oracle;
|
||||
|
||||
let mut ix = Instruction {
|
||||
program_id: mango_v4::id(),
|
||||
accounts: anchor_lang::ToAccountMetas::to_account_metas(
|
||||
&mango_v4::accounts::TokenUpdateIndexAndRate {
|
||||
group: token.mint_info.group,
|
||||
mint_info: token.mint_info_address,
|
||||
oracle,
|
||||
instructions: solana_program::sysvar::instructions::id(),
|
||||
},
|
||||
None,
|
||||
),
|
||||
data: anchor_lang::InstructionData::data(
|
||||
&mango_v4::instruction::TokenUpdateIndexAndRate {},
|
||||
),
|
||||
};
|
||||
let mut banks = banks_for_a_token
|
||||
.iter()
|
||||
.map(|bank_pubkey| AccountMeta {
|
||||
pubkey: *bank_pubkey,
|
||||
is_signer: false,
|
||||
is_writable: true,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
ix.accounts.append(&mut banks);
|
||||
req = req.instruction(ix);
|
||||
}
|
||||
let sig_result = req.send().map_err(prettify_client_error);
|
||||
|
||||
if let Err(e) = sig_result {
|
||||
log::error!("{:?}", e)
|
||||
} else {
|
||||
log::info!(
|
||||
"update_index_and_rate {} {:?}",
|
||||
token_name,
|
||||
token_names,
|
||||
sig_result.unwrap()
|
||||
)
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
};
|
||||
|
||||
let mango_client = Arc::new(MangoClient::new_for_existing_account(
|
||||
Client::new(cluster, commitment, &owner, Some(Duration::from_secs(1))),
|
||||
Client::new(cluster, commitment, &owner, Some(Duration::from_secs(10))),
|
||||
cli.mango_account,
|
||||
owner,
|
||||
)?);
|
||||
|
|
|
@ -96,7 +96,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
let rpc_url = cli.rpc_url;
|
||||
let ws_url = rpc_url.replace("https", "wss");
|
||||
|
||||
let rpc_timeout = Duration::from_secs(1);
|
||||
let rpc_timeout = Duration::from_secs(10);
|
||||
let cluster = Cluster::Custom(rpc_url.clone(), ws_url.clone());
|
||||
let commitment = CommitmentConfig::processed();
|
||||
let client = Client::new(cluster.clone(), commitment, &liqor_owner, Some(rpc_timeout));
|
||||
|
|
|
@ -200,7 +200,12 @@ async function main() {
|
|||
console.log(
|
||||
`Editing group, setting existing admin as fastListingAdmin to be able to add MNGO truslessly...`,
|
||||
);
|
||||
await client.groupEdit(group, group.admin, group.admin);
|
||||
let sig = await client.groupEdit(
|
||||
group,
|
||||
group.admin,
|
||||
new PublicKey('Efhak3qj3MiyzgJr3cUUqXXz5wr3oYHt9sPzuqJf9eBN'),
|
||||
);
|
||||
console.log(`sig https://explorer.solana.com/tx/${sig}?cluster=devnet`);
|
||||
console.log(`Registering MNGO...`);
|
||||
const mngoDevnetMint = new PublicKey(DEVNET_MINTS.get('MNGO')!);
|
||||
const mngoDevnetOracle = new PublicKey(DEVNET_ORACLES.get('MNGO')!);
|
||||
|
@ -296,6 +301,7 @@ async function main() {
|
|||
'USDC',
|
||||
btcDevnetOracle,
|
||||
0.1,
|
||||
undefined,
|
||||
0.01,
|
||||
0.3,
|
||||
0.08,
|
||||
|
@ -323,6 +329,7 @@ async function main() {
|
|||
'USDC',
|
||||
usdcDevnetOracle.publicKey,
|
||||
0.1,
|
||||
undefined,
|
||||
0.01,
|
||||
0.4,
|
||||
0.07,
|
||||
|
|
Loading…
Reference in New Issue