Skip to content

Commit

Permalink
cargo clippy --fix and minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
itsHaseebSaeed committed Oct 18, 2023
1 parent 225d8cd commit a54d935
Show file tree
Hide file tree
Showing 19 changed files with 215 additions and 524 deletions.
10 changes: 8 additions & 2 deletions contracts/liquidity_book/lb_pair/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ use math::tree_math::TreeUint24; //?
use oracle_helper::Oracle; //?
use types::Bytes32; //?

use shade_protocol::lb_libraries::viewing_keys::ViewingKey;
use shade_protocol::lb_libraries::{math, oracle_helper, pair_parameter_helper, tokens, types};
use shade_protocol::lb_libraries::{
math,
oracle_helper,
pair_parameter_helper,
tokens,
types,
viewing_keys::ViewingKey,
};
use tokens::TokenType; //?

pub const CONFIG: Item<State, Bincode2> = Item::new("config");
Expand Down
16 changes: 10 additions & 6 deletions contracts/liquidity_book/lb_pair/src/unittest/handle_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ use cosmwasm_std::{Uint128, Uint256};
use shade_multi_test::interfaces::{lb_pair, lb_token, snip20};
use shade_protocol::contract_interfaces::liquidity_book::lb_token::QueryAnswer;

use crate::test_helper::{init_addrs, remove_liquidity_parameters_helper};
use crate::unittest::test_helper::{
assert_approx_eq_rel, init_lb_pair, liquidity_parameters_helper,
lp_tokens_tempate_for_100_sscrts, mint_increase_allowance_helper,
assert_approx_eq_rel,
init_addrs,
init_lb_pair,
liquidity_parameters_helper,
lp_tokens_tempate_for_100_sscrts,
mint_increase_allowance_helper,
remove_liquidity_parameters_helper,
};

/***********************************************
Expand All @@ -28,7 +32,7 @@ fn test_init() -> Result<(), anyhow::Error> {

let lb_token_info = lb_pair::lb_token_query(&app, &lb_pair_contract_info.clone().into())?;

let contract_info_lb_token = lb_token::contract_info_query(&app, &lb_token_info)?;
let contract_info_lb_token = lb_token::query_contract_info(&app, &lb_token_info)?;

match contract_info_lb_token {
QueryAnswer::TokenContractInfo { curators, .. } => {
Expand Down Expand Up @@ -112,7 +116,7 @@ fn test_add_liquidity() -> Result<(), anyhow::Error> {

let mut i = 0;
for id in log_shares_array {
let liquidity = lb_token::id_balance_query(&app, &lb_token_info, id.0.to_string())?;
let liquidity = lb_token::query_id_balance(&app, &lb_token_info, id.0.to_string())?;

match liquidity {
shade_protocol::liquidity_book::lb_token::QueryAnswer::IdTotalBalance { amount } => {
Expand Down Expand Up @@ -240,7 +244,7 @@ fn test_remove_liquidity() -> Result<(), anyhow::Error> {

let mut i = 0;
for (id, amt) in remove_liq_log {
let liquidity = lb_token::id_balance_query(&app, &lb_token_info, id.to_string())?;
let liquidity = lb_token::query_id_balance(&app, &lb_token_info, id.to_string())?;

match liquidity {
shade_protocol::liquidity_book::lb_token::QueryAnswer::IdTotalBalance { amount } => {
Expand Down
21 changes: 19 additions & 2 deletions contracts/liquidity_book/lb_pair/src/unittest/test_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ use core::result::Result::Ok;
use std::{any::Any, str::FromStr};

use cosmwasm_std::{
Addr, BlockInfo, ContractInfo, StdError, StdResult, Timestamp, Uint128, Uint256,
Addr,
BlockInfo,
ContractInfo,
StdError,
StdResult,
Timestamp,
Uint128,
Uint256,
};
use serde::de::Error;
use shade_multi_test::{
interfaces::{
lb_pair, snip20,
lb_pair,
snip20,
utils::{DeployedContracts, SupportedContracts},
},
multi::lb_token::LbToken,
Expand All @@ -33,27 +41,35 @@ impl Addrs {
pub fn admin(&self) -> Addr {
self.addrs[0].clone()
}

pub fn user1(&self) -> Addr {
self.addrs[1].clone()
}

pub fn user2(&self) -> Addr {
self.addrs[2].clone()
}

pub fn user3(&self) -> Addr {
self.addrs[3].clone()
}

pub fn all(&self) -> Vec<Addr> {
self.addrs.clone()
}

pub fn a_hash(&self) -> String {
self.hashes[0].clone()
}

pub fn b_hash(&self) -> String {
self.hashes[1].clone()
}

pub fn c_hash(&self) -> String {
self.hashes[2].clone()
}

pub fn _d_hash(&self) -> String {
self.hashes[3].clone()
}
Expand Down Expand Up @@ -160,6 +176,7 @@ pub fn init_lb_pair() -> Result<(App, Contract, DeployedContracts), anyhow::Erro
"viewing_key".to_string(),
String::new(),
String::new(),
addrs.admin(),
)?;

Ok((app, lb_pair, deployed_contracts))
Expand Down
76 changes: 40 additions & 36 deletions contracts/liquidity_book/lb_token/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,38 @@ use secret_toolkit::{
viewing_key::{ViewingKey, ViewingKeyStore},
};

use crate::state::{
balances_r, blockinfo_r, contr_conf_r, get_receiver_hash,
permissions::{list_owner_permission_keys, may_load_any_permission},
tkn_info_r, tkn_tot_supply_r,
txhistory::{get_txs, may_get_current_owner},
PREFIX_REVOKED_PERMITS,
};
use crate::{
receiver::Snip1155ReceiveMsg,
state::{
balances_w, blockinfo_w, contr_conf_w,
permissions::{new_permission, update_permission},
set_receiver_hash, tkn_info_w, tkn_tot_supply_w,
txhistory::{append_new_owner, store_burn, store_mint, store_transfer},
RESPONSE_BLOCK_SIZE,
balances_r, balances_w, blockinfo_r, blockinfo_w, contr_conf_r, contr_conf_w,
get_receiver_hash,
permissions::{
list_owner_permission_keys, may_load_any_permission, new_permission, update_permission,
},
set_receiver_hash, tkn_info_r, tkn_info_w, tkn_tot_supply_r, tkn_tot_supply_w,
txhistory::{
append_new_owner, get_txs, may_get_current_owner, store_burn, store_mint,
store_transfer,
},
PREFIX_REVOKED_PERMITS, RESPONSE_BLOCK_SIZE,
},
};

use secret_toolkit::permit::{validate, Permit, TokenPermissions};
use shade_protocol::lb_libraries::lb_token::{
expiration::Expiration,
metadata::Metadata,
permissions::{Permission, PermissionKey},
state_structs::{
ContractConfig, CurateTokenId, OwnerBalance, StoredTokenInfo, TknConfig, TokenAmount,
TokenInfoMsg,
use shade_protocol::{
lb_libraries::lb_token::{
expiration::Expiration,
metadata::Metadata,
permissions::{Permission, PermissionKey},
state_structs::{
ContractConfig, CurateTokenId, OwnerBalance, StoredTokenInfo, TknConfig, TokenAmount,
TokenInfoMsg,
},
},
liquidity_book::lb_token::{
ExecuteAnswer, ExecuteMsg, InstantiateMsg, ResponseStatus::Success, SendAction,
TransferAction,
},
};
use shade_protocol::liquidity_book::lb_token::{
ExecuteAnswer, ExecuteMsg, InstantiateMsg, ResponseStatus::Success, SendAction, TransferAction,
};
/////////////////////////////////////////////////////////////////////////////////
// Init
Expand Down Expand Up @@ -410,8 +412,8 @@ fn try_burn_tokens(

if token_info_op.is_none() {
return Err(StdError::generic_err(
"token_id does not exist. Cannot burn non-existent `token_ids`. Use `curate_token_ids` to create tokens on new `token_ids`"
));
"token_id does not exist. Cannot burn non-existent `token_ids`. Use `curate_token_ids` to create tokens on new `token_ids`",
));
}

let token_info = token_info_op.clone().unwrap();
Expand Down Expand Up @@ -475,7 +477,7 @@ fn try_change_metadata(
return Err(StdError::generic_err(format!(
"token_id {} does not exist",
token_id
)))
)));
}
Some(i) => i.token_config.flatten(),
};
Expand All @@ -499,7 +501,7 @@ fn try_change_metadata(
return Err(StdError::generic_err(format!(
"unable to change the metadata for token_id {}",
token_id
)))
)));
}
true => {
let mut tkn_info = tkn_info_op.unwrap();
Expand Down Expand Up @@ -1080,9 +1082,9 @@ fn exec_curate_token_id(
if initial_token.token_info.token_config.flatten().is_nft {
if initial_token.balances.len() > 1 {
return Err(StdError::generic_err(format!(
"token_id {} is an NFT; there can only be one NFT. Balances should only have one address",
initial_token.token_info.token_id
)));
"token_id {} is an NFT; there can only be one NFT. Balances should only have one address",
initial_token.token_info.token_id
)));
} else if initial_token.balances[0].amount != Uint256::from(1_u64) {
return Err(StdError::generic_err(format!(
"token_id {} is an NFT; there can only be one NFT. Balances.amount must == 1",
Expand Down Expand Up @@ -1229,14 +1231,14 @@ fn impl_transfer(
return Err(StdError::generic_err(format!(
"Allowance has expired: {}",
perm.trfer_allowance_exp
)))
)));
}
// not enough allowance to transfer amount
Some(perm) if perm.trfer_allowance_perm < amount => {
return Err(StdError::generic_err(format!(
"Insufficient transfer allowance: {}",
perm.trfer_allowance_perm
)))
)));
}
// success, so need to reduce allowance
Some(mut perm) if perm.trfer_allowance_perm >= amount => {
Expand All @@ -1263,7 +1265,7 @@ fn impl_transfer(
true => {
return Err(StdError::generic_err(
"These tokens do not exist or you have no permission to transfer",
))
));
}
false => (),
}
Expand Down Expand Up @@ -1383,7 +1385,7 @@ fn exec_change_balance(
Err(_e) => {
return Err(StdError::generic_err(
"total supply exceeds max allowed of 2^128",
))
));
}
};
tkn_tot_supply_w(storage).save(token_info.token_id.as_bytes(), &new_amount)?;
Expand Down Expand Up @@ -1499,7 +1501,9 @@ fn permit_queries(deps: Deps, permit: Permit, query: QueryWithPermit) -> Result<
if account != owner.as_str() && account != allowed_address.as_str() {
return Err(StdError::generic_err(format!(
"Cannot query permission. Requires permit for either owner {:?} or viewer||spender {:?}, got permit for {:?}",
owner.as_str(), allowed_address.as_str(), account.as_str()
owner.as_str(),
allowed_address.as_str(),
account.as_str()
)));
}

Expand Down Expand Up @@ -1662,7 +1666,7 @@ fn query_token_id_private_info(deps: Deps, viewer: &Addr, token_id: String) -> S
None => {
return Err(StdError::generic_err(
"you do have have permission to view private token info",
))
));
}
Some(perm) => {
let block: BlockInfo =
Expand Down Expand Up @@ -1715,7 +1719,7 @@ fn query_balance(deps: Deps, owner: &Addr, viewer: &Addr, token_id: String) -> S
None => {
return Err(StdError::generic_err(
"you do have have permission to view balance",
))
));
}
Some(perm) => {
let block: BlockInfo =
Expand Down
Loading

0 comments on commit a54d935

Please sign in to comment.