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",
|
||||||
"fixed-macro",
|
"fixed-macro",
|
||||||
"futures 0.3.21",
|
"futures 0.3.21",
|
||||||
|
"itertools 0.10.3",
|
||||||
"log 0.4.17",
|
"log 0.4.17",
|
||||||
"mango-v4",
|
"mango-v4",
|
||||||
"pyth-sdk-solana",
|
"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 = { version = "=1.11.0", features = ["serde", "borsh"] }
|
||||||
fixed-macro = "^1.1.1"
|
fixed-macro = "^1.1.1"
|
||||||
futures = "0.3.21"
|
futures = "0.3.21"
|
||||||
|
itertools = "0.10.3"
|
||||||
log = "0.4.0"
|
log = "0.4.0"
|
||||||
mango-v4 = { path = "../programs/mango-v4", features = ["no-entrypoint", "client"] }
|
mango-v4 = { path = "../programs/mango-v4", features = ["no-entrypoint", "client"] }
|
||||||
pyth-sdk-solana = "0.1.0"
|
pyth-sdk-solana = "0.1.0"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::{sync::Arc, time::Duration};
|
use std::{sync::Arc, time::Duration};
|
||||||
|
|
||||||
use crate::MangoClient;
|
use crate::MangoClient;
|
||||||
|
use itertools::Itertools;
|
||||||
|
|
||||||
use anchor_lang::{__private::bytemuck::cast_ref, solana_program};
|
use anchor_lang::{__private::bytemuck::cast_ref, solana_program};
|
||||||
use client::prettify_client_error;
|
use client::prettify_client_error;
|
||||||
|
@ -22,7 +23,16 @@ pub async fn runner(
|
||||||
.context
|
.context
|
||||||
.tokens
|
.tokens
|
||||||
.keys()
|
.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<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let handles2 = mango_client
|
let handles2 = mango_client
|
||||||
|
@ -49,23 +59,31 @@ pub async fn runner(
|
||||||
Ok(())
|
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));
|
let mut interval = time::interval(Duration::from_secs(5));
|
||||||
loop {
|
loop {
|
||||||
interval.tick().await;
|
interval.tick().await;
|
||||||
|
|
||||||
let client = mango_client.clone();
|
let client = mango_client.clone();
|
||||||
|
|
||||||
|
let token_indices_clone = token_indices.clone();
|
||||||
|
|
||||||
let res = tokio::task::spawn_blocking(move || -> anyhow::Result<()> {
|
let res = tokio::task::spawn_blocking(move || -> anyhow::Result<()> {
|
||||||
let token = client.context.token(token_index);
|
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 banks_for_a_token = token.mint_info.banks();
|
||||||
let token_name = &token.name;
|
|
||||||
let oracle = token.mint_info.oracle;
|
let oracle = token.mint_info.oracle;
|
||||||
|
|
||||||
let sig_result = client
|
|
||||||
.program()
|
|
||||||
.request()
|
|
||||||
.instruction({
|
|
||||||
let mut ix = Instruction {
|
let mut ix = Instruction {
|
||||||
program_id: mango_v4::id(),
|
program_id: mango_v4::id(),
|
||||||
accounts: anchor_lang::ToAccountMetas::to_account_metas(
|
accounts: anchor_lang::ToAccountMetas::to_account_metas(
|
||||||
|
@ -90,17 +108,16 @@ pub async fn loop_update_index_and_rate(mango_client: Arc<MangoClient>, token_in
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
ix.accounts.append(&mut banks);
|
ix.accounts.append(&mut banks);
|
||||||
ix
|
req = req.instruction(ix);
|
||||||
})
|
}
|
||||||
.send()
|
let sig_result = req.send().map_err(prettify_client_error);
|
||||||
.map_err(prettify_client_error);
|
|
||||||
|
|
||||||
if let Err(e) = sig_result {
|
if let Err(e) = sig_result {
|
||||||
log::error!("{:?}", e)
|
log::error!("{:?}", e)
|
||||||
} else {
|
} else {
|
||||||
log::info!(
|
log::info!(
|
||||||
"update_index_and_rate {} {:?}",
|
"update_index_and_rate {} {:?}",
|
||||||
token_name,
|
token_names,
|
||||||
sig_result.unwrap()
|
sig_result.unwrap()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ fn main() -> Result<(), anyhow::Error> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mango_client = Arc::new(MangoClient::new_for_existing_account(
|
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,
|
cli.mango_account,
|
||||||
owner,
|
owner,
|
||||||
)?);
|
)?);
|
||||||
|
|
|
@ -96,7 +96,7 @@ async fn main() -> anyhow::Result<()> {
|
||||||
let rpc_url = cli.rpc_url;
|
let rpc_url = cli.rpc_url;
|
||||||
let ws_url = rpc_url.replace("https", "wss");
|
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 cluster = Cluster::Custom(rpc_url.clone(), ws_url.clone());
|
||||||
let commitment = CommitmentConfig::processed();
|
let commitment = CommitmentConfig::processed();
|
||||||
let client = Client::new(cluster.clone(), commitment, &liqor_owner, Some(rpc_timeout));
|
let client = Client::new(cluster.clone(), commitment, &liqor_owner, Some(rpc_timeout));
|
||||||
|
|
|
@ -200,7 +200,12 @@ async function main() {
|
||||||
console.log(
|
console.log(
|
||||||
`Editing group, setting existing admin as fastListingAdmin to be able to add MNGO truslessly...`,
|
`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...`);
|
console.log(`Registering MNGO...`);
|
||||||
const mngoDevnetMint = new PublicKey(DEVNET_MINTS.get('MNGO')!);
|
const mngoDevnetMint = new PublicKey(DEVNET_MINTS.get('MNGO')!);
|
||||||
const mngoDevnetOracle = new PublicKey(DEVNET_ORACLES.get('MNGO')!);
|
const mngoDevnetOracle = new PublicKey(DEVNET_ORACLES.get('MNGO')!);
|
||||||
|
@ -296,6 +301,7 @@ async function main() {
|
||||||
'USDC',
|
'USDC',
|
||||||
btcDevnetOracle,
|
btcDevnetOracle,
|
||||||
0.1,
|
0.1,
|
||||||
|
undefined,
|
||||||
0.01,
|
0.01,
|
||||||
0.3,
|
0.3,
|
||||||
0.08,
|
0.08,
|
||||||
|
@ -323,6 +329,7 @@ async function main() {
|
||||||
'USDC',
|
'USDC',
|
||||||
usdcDevnetOracle.publicKey,
|
usdcDevnetOracle.publicKey,
|
||||||
0.1,
|
0.1,
|
||||||
|
undefined,
|
||||||
0.01,
|
0.01,
|
||||||
0.4,
|
0.4,
|
||||||
0.07,
|
0.07,
|
||||||
|
|
Loading…
Reference in New Issue