Skip to content

Commit

Permalink
fix: Make everything compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Unique-Divine committed May 28, 2024
1 parent 8f1488b commit 09e76ab
Show file tree
Hide file tree
Showing 26 changed files with 239 additions and 126 deletions.
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ bash-rs = { path = "packages/bash-rs" }
nibiru-ownable = { path = "packages/nibiru-ownable" }
ownable-derive = { path = "packages/nibiru-ownable/derive" }
cw-address-like = { path = "packages/cw-address-like" }
easy-addr = { path = "packages/easy-addr" }

# deps: CosmWasm
cosmwasm-std = { version = "2.0.2", features = ["stargate", "staking"] }
Expand Down
14 changes: 4 additions & 10 deletions contracts/broker-bank/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,8 @@ pub fn withdraw_all(
to_address: to_addr.to_string(),
amount: balances.clone(),
};
let event = event_withdraw(
serde_json::to_string(&balances)?.as_str(),
&to_addr,
);
let event =
event_withdraw(serde_json::to_string(&balances)?.as_str(), &to_addr);
LOGS.push_front(
deps.storage,
&Log {
Expand Down Expand Up @@ -285,10 +283,7 @@ pub fn query_accepted_denoms(deps: Deps) -> StdResult<BTreeSet<String>> {
/// query_bank_balances(contract_addr.to_string(), deps.as_ref());
/// assert!(balances.is_ok())
/// ```
pub fn query_bank_balances(
addr: String,
deps: Deps,
) -> StdResult<Vec<Coin>> {
pub fn query_bank_balances(addr: String, deps: Deps) -> StdResult<Vec<Coin>> {
let query_result: Option<AllBalanceResponse> =
deps.querier
.query(&QueryRequest::Bank(BankQuery::AllBalances {
Expand Down Expand Up @@ -633,7 +628,6 @@ pub mod tests {
let not_has: bool = !perms.is_owner(new_member);
assert!(not_has);


// Add an operator to the permission set
let execute_msg = ExecuteMsg::EditOpers(oper_perms::Action::AddOper {
address: new_member.to_string(),
Expand Down Expand Up @@ -797,4 +791,4 @@ pub mod tests {

Ok(())
}
}
}
2 changes: 1 addition & 1 deletion contracts/broker-bank/src/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ pub struct InstantiateMsg {
pub owner: String,
pub to_addrs: BTreeSet<String>,
pub opers: BTreeSet<String>,
}
}
2 changes: 1 addition & 1 deletion contracts/broker-bank/src/oper_perms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ impl Permissions {
false => Err(ContractError::NoOperatorPerms { addr }),
}
}
}
}
2 changes: 1 addition & 1 deletion contracts/broker-bank/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ pub struct Log {
pub block_height: u64,
pub sender_addr: String,
pub event: Event,
}
}
2 changes: 1 addition & 1 deletion contracts/broker-staking/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ pub struct UnstakeMsg {
pub struct StakeMsg {
pub share: Uint128,
pub validator: String,
}
}
2 changes: 1 addition & 1 deletion contracts/broker-staking/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,4 +751,4 @@ fn exec_unstake() -> TestResult {
assert_eq!(want_resp_msgs, got_resp_msgs);
}
Ok(())
}
}
3 changes: 2 additions & 1 deletion contracts/core-cw3-flex-msig/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ thiserror = { workspace = true }
[dev-dependencies]
cw4-group = { workspace = true }
cw-multi-test = { workspace = true }
cw20-base = { workspace = true }
cw20-base = { workspace = true }
easy-addr = { workspace = true }
27 changes: 14 additions & 13 deletions contracts/core-cw3-flex-msig/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ mod tests {
coin, coins, Addr, BankMsg, Coin, Decimal, Timestamp, Uint128,
};

use super::*;
use cw2::{query_contract_info, ContractVersion};
use cw20::{Cw20Coin, UncheckedDenom};
use cw3::{DepositError, UncheckedDepositInfo};
Expand All @@ -523,16 +524,16 @@ mod tests {
Executor, SudoMsg,
};
use cw_utils::{Duration, Threshold};
use easy_addr::addr;

use super::*;

const OWNER: &str = "admin0001";
const VOTER1: &str = "voter0001";
const VOTER2: &str = "voter0002";
const VOTER3: &str = "voter0003";
const VOTER4: &str = "voter0004";
const VOTER5: &str = "voter0005";
const SOMEBODY: &str = "somebody";
const OWNER: &str = addr!("admin0001");
const VOTER1: &str = addr!("voter0001");
const VOTER2: &str = addr!("voter0002");
const VOTER3: &str = addr!("voter0003");
const VOTER4: &str = addr!("voter0004");
const VOTER5: &str = addr!("voter0005");
const SOMEBODY: &str = addr!("somebody");
const NEWBIE: &str = addr!("newbie");

fn member<T: Into<String>>(addr: T, weight: u64) -> Member {
Member {
Expand Down Expand Up @@ -1926,7 +1927,7 @@ mod tests {
// updates VOTER2 power to 21 -> with snapshot, vote doesn't pass proposal
// adds NEWBIE with 2 power -> with snapshot, invalid vote
// removes VOTER3 -> with snapshot, can vote on proposal
let newbie: &str = "newbie";
let newbie: &str = NEWBIE;
let update_msg = cw4_group::msg::ExecuteMsg::UpdateMembers {
remove: vec![VOTER3.into()],
add: vec![member(VOTER2, 21), member(newbie, 2)],
Expand Down Expand Up @@ -2226,7 +2227,7 @@ mod tests {
app.update_block(|block| block.height += 2);

// admin changes the group (3 -> 0, 2 -> 9, 0 -> 29) - total = 56, require 29 to pass
let newbie: &str = "newbie";
let newbie: &str = NEWBIE;
let update_msg = cw4_group::msg::ExecuteMsg::UpdateMembers {
remove: vec![VOTER3.into()],
add: vec![member(VOTER2, 9), member(newbie, 29)],
Expand Down Expand Up @@ -2331,7 +2332,7 @@ mod tests {
app.update_block(|block| block.height += 2);

// admin changes the group (3 -> 0, 2 -> 9, 0 -> 28) - total = 55, require 28 to pass
let newbie: &str = "newbie";
let newbie: &str = NEWBIE;
let update_msg = cw4_group::msg::ExecuteMsg::UpdateMembers {
remove: vec![VOTER3.into()],
add: vec![member(VOTER2, 9), member(newbie, 29)],
Expand Down Expand Up @@ -2899,4 +2900,4 @@ mod tests {
let balance = app.wrap().query_balance(OWNER, "TOKEN").unwrap();
assert_eq!(balance.amount, Uint128::new(10));
}
}
}
3 changes: 2 additions & 1 deletion contracts/core-shifter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ nibiru-ownable = { workspace = true }
cw2 = { workspace = true }

[dev-dependencies]
anyhow = { workspace = true }
anyhow = { workspace = true }
easy-addr = { workspace = true }
4 changes: 3 additions & 1 deletion contracts/core-shifter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ pub mod tests {
use cosmwasm_std::{coins, testing};
use std::collections::BTreeSet;

use easy_addr::addr;

// ---------------------------------------------------------------------------
// Tests
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -248,7 +250,7 @@ pub mod tests {
#[test]
fn test_exec_edit_opers_add() -> TestResult {
let (mut deps, _env, _info) = t::setup_contract()?;
let new_member = "new_member";
let new_member = addr!("new_member");
let perms = Permissions::load(&deps.storage)?;
let not_has: bool = !perms.is_owner(new_member);
assert!(not_has);
Expand Down
2 changes: 1 addition & 1 deletion contracts/core-shifter/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ pub enum ContractError {

#[error("{0}")]
MathError(#[from] errors::MathError),
}
}
2 changes: 1 addition & 1 deletion contracts/core-shifter/src/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ pub enum QueryMsg {
/// Perms: Query the contract owner and set of operators.
#[returns(operator_perms::PermsResponse)]
Perms {},
}
}
4 changes: 3 additions & 1 deletion contracts/incentives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ thiserror = { workspace = true }
lockup = { workspace = true }

[dev-dependencies]
cw-multi-test = { workspace = true }
cw-multi-test = { workspace = true }
easy-addr = { workspace = true }
anyhow = { workspace = true }
25 changes: 18 additions & 7 deletions contracts/incentives/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,13 @@ fn execute_withdraw_rewards(
Decimal::from_ratio(qualified_locked_amount, epoch.total_locked);
println!("ownership ratio: {:?}", user_ownership_ratio.to_string());
for coin in epoch.to_distribute {
let coin_amount = Decimal::new(coin.amount);
let coin_amount =(coin_amount * user_ownership_ratio).to_uint_floor();
let coin_amount: Uint128 = coin
.amount
.checked_multiply_ratio(
qualified_locked_amount,
epoch.total_locked,
)
.unwrap();
add_coins(
&mut to_distribute,
Coin {
Expand All @@ -267,6 +272,14 @@ fn execute_withdraw_rewards(
.unwrap();

println!("distributing: {:?}", &to_distribute);
let to_distribute: Vec<Coin> = to_distribute
.into_iter()
.filter(|coin| !coin.amount.is_zero())
.collect();

if to_distribute.is_empty() {
return Ok(Response::new());

Check warning on line 281 in contracts/incentives/src/contract.rs

View check run for this annotation

Codecov / codecov/patch

contracts/incentives/src/contract.rs#L281

Added line #L281 was not covered by tests
}
Ok(Response::new().add_message(BankMsg::Send {
to_address: info.sender.to_string(),
amount: to_distribute,
Expand Down Expand Up @@ -328,10 +341,8 @@ fn execute_process_epoch(
)?;

// identify how much is the total locked
let total_locked = locks
.iter()
.map(|lock| lock.coin.amount)
.sum::<Uint128>();
let total_locked =
locks.iter().map(|lock| lock.coin.amount).sum::<Uint128>();

// then we identify how many coins we need to pay
// based on the program funding
Expand Down Expand Up @@ -403,4 +414,4 @@ mod tests {
let result = 2 + 2;
assert_eq!(result, 4);
}
}
}
Loading

0 comments on commit 09e76ab

Please sign in to comment.