Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ratik committed Dec 18, 2024
1 parent ab5a541 commit 489d715
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 27 deletions.
4 changes: 2 additions & 2 deletions contracts/icq-adapter-kv/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ fn sudo_delegations_and_balance_kv_query_result(
let data: BalancesAndDelegations =
ResultReconstruct::reconstruct(&kv_results, &config.options.sdk_version, None)?;

let new_state = match DELEGATIONS_AND_BALANCES.may_load(deps.storage, &remote_height)? {
let new_state = match DELEGATIONS_AND_BALANCES.may_load(deps.storage, remote_height)? {
Some(mut state) => {
if !state.collected_chunks.contains(&chunk_id) {
state
Expand Down Expand Up @@ -260,6 +260,6 @@ fn sudo_delegations_and_balance_kv_query_result(
}
}

DELEGATIONS_AND_BALANCES.save(deps.storage, &remote_height, &new_state)?;
DELEGATIONS_AND_BALANCES.save(deps.storage, remote_height, &new_state)?;
Ok(Response::default())
}
39 changes: 37 additions & 2 deletions contracts/icq-adapter-kv/src/store.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use cosmos_sdk_proto::cosmos::base::v1beta1::Coin as CosmosCoin;
use cosmos_sdk_proto::cosmos::staking::v1beta1::{
Delegation, Params, Validator as CosmosValidator,
};
use cosmwasm_schema::{cw_serde, serde::Serialize};
use cosmwasm_std::{Addr, Decimal256, Timestamp, Uint128};
use cosmwasm_std::{from_json, Addr, Decimal256, StdError, Timestamp, Uint128, Uint256};
use cw_storage_plus::{Item, Map};
use drop_helpers::version::version_to_u32;
use neutron_sdk::bindings::types::StorageValue;
Expand All @@ -14,13 +15,16 @@ use prost::Message;
use std::ops::Div;
use std::str::FromStr;

pub const DECIMAL_PLACES: u32 = 18;
const DECIMAL_FRACTIONAL: u128 = 10u128.pow(DECIMAL_PLACES);

pub const DELEGATIONS_AND_BALANCES_QUERY_ID_CHUNK: Map<u64, u64> =
Map::new("delegations_and_balances_query_id_chunk");

pub const LAST_COMPLETE_DELEGATIONS_AND_BALANCES_KEY: Item<u64> =
Item::new("last_complete_delegations_and_balances_key");

pub const DELEGATIONS_AND_BALANCES: Map<u64, BalancesAndDelegationsState<Z>> =
pub const DELEGATIONS_AND_BALANCES: Map<u64, BalancesAndDelegationsState<BalancesAndDelegations>> =
Map::new("delegations_and_balances");

#[cw_serde]
Expand Down Expand Up @@ -167,3 +171,34 @@ impl ResultReconstruct for BalancesAndDelegations {
})
}
}

impl ResultReconstruct for MultiBalances {
//TODO: fix in sdk and remove this
fn reconstruct(
storage_values: &[StorageValue],
version: &str,
_: Option<&str>,
) -> NeutronResult<MultiBalances> {
let mut coins: Vec<cosmwasm_std::Coin> = Vec::with_capacity(storage_values.len());
for kv in storage_values {
if kv.value.len() > 0 {
let (_, denom) = deconstruct_account_denom_balance_key(kv.key.to_vec())?;
let amount: Uint128 = match version_to_u32(version)? {
ver if ver >= version_to_u32("0.47.0")? => {
// Directly parse Uint128 from the string obtained from kv.value
Uint128::from_str(&String::from_utf8(kv.value.to_vec()).map_err(|_| {
NeutronError::InvalidQueryResultFormat("Invalid utf8".to_string())
})?)
}
// For versions below "0.47.0", use the existing balance.amount
_ => {
let balance: CosmosCoin = CosmosCoin::decode(kv.value.as_slice())?;
Uint128::from_str(balance.amount.as_str())
}
}?;
coins.push(cosmwasm_std::Coin::new(amount.u128(), denom));
}
}
Ok(MultiBalances { coins })
}
}
6 changes: 4 additions & 2 deletions contracts/icq-router/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_std::{
attr, ensure, ensure_eq, from_json, to_json_binary, BankMsg, Binary, Coin, CosmosMsg, Deps,
DepsMut, Env, MessageInfo, Response, WasmMsg,
DepsMut, Empty, Env, MessageInfo, Response, WasmMsg,
};
use drop_helpers::answer::response;
use drop_staking_base::msg::icq_router::{BalancesData, DelegationsData};
Expand Down Expand Up @@ -166,7 +166,9 @@ fn update_validators(
Ok(res.add_message(CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: config.adapter.to_string(),
msg: to_json_binary(
&drop_staking_base::msg::icq_adapter::ExecuteMsg::UpdateValidatorSet { validators },
&drop_staking_base::msg::icq_adapter::ExecuteMsg::<Empty>::UpdateValidatorSet {
validators,
},
)?,
funds: vec![],
})))
Expand Down
2 changes: 1 addition & 1 deletion contracts/mirror/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub fn execute_update_bond(
) -> ContractResult<Response<NeutronMsg>> {
cw_ownable::assert_owner(deps.storage, &info.sender)?;
let mut bond = BONDS.load(deps.storage, id)?;
bond.receiver = receiver.clone();
bond.receiver.clone_from(&receiver);
bond.backup = backup
.clone()
.map(|a| deps.api.addr_validate(&a))
Expand Down
4 changes: 2 additions & 2 deletions contracts/native-bond-provider/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ fn execute_update_config(
}

if let Some(port_id) = new_config.port_id {
state.port_id = port_id.clone();
state.port_id.clone_from(&port_id);
attrs.push(attr("port_id", port_id));
}

if let Some(transfer_channel_id) = new_config.transfer_channel_id {
state.transfer_channel_id = transfer_channel_id.clone();
state.transfer_channel_id.clone_from(&transfer_channel_id);
attrs.push(attr("transfer_channel_id", transfer_channel_id));
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/proposal-votes-poc/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ fn execute_update_config(
}

if let Some(connection_id) = new_config.connection_id {
config.connection_id = connection_id.clone();
config.connection_id.clone_from(&connection_id);
attrs.push(attr("connection_id", connection_id))
}

if let Some(port_id) = new_config.port_id {
config.port_id = port_id.clone();
config.port_id.clone_from(&port_id);
attrs.push(attr("port_id", port_id))
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/provider-proposals-poc/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ fn execute_update_config(
}

if let Some(connection_id) = new_config.connection_id {
config.connection_id = connection_id.clone();
config.connection_id.clone_from(&connection_id);
attrs.push(attr("connection_id", connection_id))
}

if let Some(port_id) = new_config.port_id {
config.port_id = port_id.clone();
config.port_id.clone_from(&port_id);
attrs.push(attr("port_id", port_id))
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/pump/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fn execute_update_config(
attrs.push(cosmwasm_std::attr("dest_port".to_string(), dest_port));
}
if let Some(connection_id) = new_config.connection_id {
config.connection_id = connection_id.clone();
config.connection_id.clone_from(&connection_id);
attrs.push(cosmwasm_std::attr(
"connection_id".to_string(),
connection_id,
Expand All @@ -167,7 +167,7 @@ fn execute_update_config(
));
}
if let Some(local_denom) = new_config.local_denom {
config.local_denom = local_denom.clone();
config.local_denom.clone_from(&local_denom);
attrs.push(cosmwasm_std::attr("local_denom".to_string(), local_denom));
}
CONFIG.save(deps.storage, &config)?;
Expand Down
10 changes: 5 additions & 5 deletions contracts/puppeteer-initia/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,17 @@ fn execute_update_config(
if !remote_denom.starts_with("move/") {
return Err(ContractError::InvalidRemoteDenom);
}
config.remote_denom = remote_denom.clone();
config.remote_denom.clone_from(&remote_denom);
attrs.push(attr("remote_denom", remote_denom))
}

if let Some(connection_id) = new_config.connection_id {
config.connection_id = connection_id.clone();
config.connection_id.clone_from(&connection_id);
attrs.push(attr("connection_id", connection_id))
}

if let Some(port_id) = new_config.port_id {
config.port_id = port_id.clone();
config.port_id.clone_from(&port_id);
attrs.push(attr("port_id", port_id))
}

Expand All @@ -295,12 +295,12 @@ fn execute_update_config(
}

if let Some(transfer_channel_id) = new_config.transfer_channel_id {
config.transfer_channel_id = transfer_channel_id.clone();
config.transfer_channel_id.clone_from(&transfer_channel_id);
attrs.push(attr("transfer_channel_id", transfer_channel_id))
}

if let Some(sdk_version) = new_config.sdk_version {
config.sdk_version = sdk_version.clone();
config.sdk_version.clone_from(&sdk_version);
attrs.push(attr("sdk_version", sdk_version))
}
if let Some(timeout) = new_config.timeout {
Expand Down
10 changes: 5 additions & 5 deletions contracts/puppeteer/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,17 @@ fn execute_update_config(
let mut attrs: Vec<Attribute> = Vec::new();

if let Some(remote_denom) = new_config.remote_denom {
config.remote_denom = remote_denom.clone();
config.remote_denom.clone_from(&remote_denom);
attrs.push(attr("remote_denom", remote_denom))
}

if let Some(connection_id) = new_config.connection_id {
config.connection_id = connection_id.clone();
config.connection_id.clone_from(&connection_id);
attrs.push(attr("connection_id", connection_id))
}

if let Some(port_id) = new_config.port_id {
config.port_id = port_id.clone();
config.port_id.clone_from(&port_id);
attrs.push(attr("port_id", port_id))
}

Expand All @@ -314,12 +314,12 @@ fn execute_update_config(
}

if let Some(transfer_channel_id) = new_config.transfer_channel_id {
config.transfer_channel_id = transfer_channel_id.clone();
config.transfer_channel_id.clone_from(&transfer_channel_id);
attrs.push(attr("transfer_channel_id", transfer_channel_id))
}

if let Some(sdk_version) = new_config.sdk_version {
config.sdk_version = sdk_version.clone();
config.sdk_version.clone_from(&sdk_version);
attrs.push(attr("sdk_version", sdk_version))
}
if let Some(timeout) = new_config.timeout {
Expand Down
4 changes: 2 additions & 2 deletions contracts/validators-stats/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ fn sudo_signing_info(
if let Some(address) = valoper_address {
let mut validator_state = get_validator_state(&deps, address.clone())?;

validator_state.valcons_address = info.address.clone();
validator_state.valcons_address.clone_from(&info.address);
validator_state.tombstone = if info.tombstoned {
true
} else {
Expand Down Expand Up @@ -301,7 +301,7 @@ fn sudo_signing_info(

// TODO: Implement tests
fn calucalate_missed_blocks_percent(
all_missed_blocks: &Vec<MissedBlocks>,
all_missed_blocks: &[MissedBlocks],
missed_blocks: &mut MissedBlocks,
address: String,
missed_blocks_counter: u64,
Expand Down

0 comments on commit 489d715

Please sign in to comment.