Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot: Resolve pagination of the carrot contracts #81

Merged
merged 4 commits into from
Apr 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 40 additions & 11 deletions bot/src/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,29 +302,58 @@ fn autocompound_instance(
}

mod utils {
use cosmos_sdk_proto::{
cosmos::base::query::v1beta1::{PageRequest, PageResponse},
cosmwasm::wasm::v1::QueryContractsByCodeResponse,
};
use cw_asset::AssetBase;

use super::*;
const MIN_REWARD: (&str, Uint128) = ("uosmo", Uint128::new(100_000));

pub fn next_page_request(page_response: PageResponse) -> PageRequest {
PageRequest {
key: page_response.next_key,
offset: 0,
limit: 0,
count_total: false,
reverse: false,
}
}

/// Get the contract instances of a given code_id
pub async fn fetch_instances(
channel: Channel,
code_id: u64,
version: &str,
) -> anyhow::Result<Vec<String>> {
let mut cw_querier = QueryClient::new(channel);
let contract_addrs = cw_querier
.contracts_by_code(QueryContractsByCodeRequest {
code_id,
// TODO: pagination
pagination: None,
})
.await?
.into_inner()
.contracts;
log!(Level::Info, "Savings addrs({version}): {contract_addrs:?}");
anyhow::Ok(contract_addrs)

let mut contract_addrs = vec![];
let mut pagination = None;

loop {
let QueryContractsByCodeResponse {
mut contracts,
pagination: next_pagination,
} = cw_querier
.contracts_by_code(QueryContractsByCodeRequest {
code_id,
pagination,
})
.await?
.into_inner();

contract_addrs.append(&mut contracts);
match next_pagination {
Some(page_response) => pagination = Some(next_page_request(page_response)),
// Done with pagination can return out all of the contracts
None => {
log!(Level::Info, "Savings addrs({version}): {contract_addrs:?}");
break anyhow::Ok(contract_addrs);
}
}
}
}

/// Finds the account owner and checks if the contract has authz permissions on it.
Expand Down
Loading