Skip to content

Commit

Permalink
Merge pull request #395 from securesecrets/itsHaseebSaeed-LiquidityBook
Browse files Browse the repository at this point in the history
Final audits and optimizations
  • Loading branch information
itsHaseebSaeed authored Mar 19, 2024
2 parents 495b261 + 8eddf07 commit 9d91e6e
Show file tree
Hide file tree
Showing 87 changed files with 8,861 additions and 5,244 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use std::str::FromStr;

use ethnum::U256;
use shade_protocol::{
c_std::{to_binary, Addr, ContractInfo, Uint128, Uint256},
lb_libraries::{
math::uint256_to_u256::ConvertU256,
types::{ContractInstantiationInfo, LBPair, LBPairInformation, StaticFeeParameters},
lb_libraries::types::{
ContractInstantiationInfo,
LBPair,
LBPairInformation,
StaticFeeParameters,
},
liquidity_book::lb_pair::{LiquidityParameters, RemoveLiquidity, RewardsDistribution},
liquidity_book::lb_pair::{LiquidityParameters, RemoveLiquidity},
snip20::Snip20ReceiveMsg,
swap::core::{TokenAmount, TokenType},
utils::asset::RawContract,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ fn main() -> io::Result<()> {
query_auth: RawContract::example(),

recover_staking_funds_receiver: Addr::funds_recipient(),
max_bins_per_swap: Some(500),
};

writeln!(file, "## Instantiate Message\n")?;
Expand Down
74 changes: 3 additions & 71 deletions contracts/liquidity_book/lb_factory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub fn instantiate(
staking_contract_implementation: ContractInstantiationInfo::default(),
recover_staking_funds_receiver: msg.recover_staking_funds_receiver,
query_auth: msg.query_auth.into_valid(deps.api)?,
max_bins_per_swap: msg.max_bins_per_swap,
};

STATE.save(deps.storage, &config)?;
Expand Down Expand Up @@ -433,6 +434,7 @@ fn try_create_lb_pair(
epoch_staking_duration: staking_preset.epoch_staking_duration,
expiry_staking_duration: staking_preset.expiry_staking_duration,
recover_staking_funds_receiver: config.recover_staking_funds_receiver,
max_bins_per_swap: None,
})?,
code_hash: config.lb_pair_implementation.code_hash.clone(),
funds: vec![],
Expand All @@ -452,76 +454,6 @@ fn try_create_lb_pair(
Ok(Response::new().add_submessages(messages))
}

// /// Sets whether the pair is ignored or not for routing, it will make the pair unusable by the router.
// ///
// /// # Arguments
// ///
// /// * `token_x` - The address of the first token of the pair.
// /// * `token_y` - The address of the second token of the pair.
// /// * `bin_step` - The bin step in basis point of the pair.
// /// * `ignored` - Whether to ignore (true) or not (false) the pair for routing.
// fn try_set_lb_pair_ignored(
// deps: DepsMut,
// env: Env,
// info: MessageInfo,
// token_a: TokenType,
// token_b: TokenType,
// bin_step: u16,
// ignored: bool,
// ) -> Result<Response> {
// let config = CONFIG.load(deps.storage)?;
// only_owner(&info.sender, &config.owner)?;

// let (token_a, token_b) = _sort_tokens(token_a, token_b);

// let mut pair_information = LB_PAIRS_INFO
// .load(
// deps.storage,
// (
// token_a.unique_key().clone(),
// token_b.unique_key().clone(),
// bin_step,
// ),
// )
// .unwrap();

// if pair_information
// .lb_pair
// .contract
// .address
// .as_str()
// .is_empty()
// {
// return Err(Error::LBPairDoesNotExist {
// token_x: token_a.unique_key().clone(),
// token_y: token_b.unique_key().clone(),
// bin_step,
// });
// }

// if pair_information.ignored_for_routing == ignored {
// return Err(Error::LBPairIgnoredIsAlreadyInTheSameState);
// }

// pair_information.ignored_for_routing = ignored;

// LB_PAIRS_INFO.save(
// deps.storage,
// (
// token_a.unique_key().clone(),
// token_b.unique_key().clone(),
// bin_step,
// ),
// &pair_information,
// )?;

// // emit LBPairIgnoredStateChanged(pairInformation.LBPair, ignored);

// // TODO: be more specific about which pair changed
// Ok(Response::default()
// .add_attribute_plaintext("LBPair ignored state changed", format!("{}", ignored)))
// }

/// Sets the preset parameters of a bin step
///
/// # Arguments
Expand Down Expand Up @@ -554,7 +486,7 @@ fn try_set_pair_preset(
epoch_staking_duration: u64,
expiry_staking_duration: Option<u64>,
) -> Result<Response> {
let mut state = STATE.load(deps.storage)?;
let state = STATE.load(deps.storage)?;
validate_admin(
&deps.querier,
AdminPermissions::LiquidityBookAdmin,
Expand Down
6 changes: 2 additions & 4 deletions contracts/liquidity_book/lb_factory/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ use std::collections::HashSet;
use shade_protocol::{
c_std::{Addr, ContractInfo, Storage},
cosmwasm_schema::cw_serde,
lb_libraries::{
pair_parameter_helper::PairParameters,
types::{ContractInstantiationInfo, TreeUint24},
},
lb_libraries::{pair_parameter_helper::PairParameters, types::ContractInstantiationInfo},
liquidity_book::lb_pair::RewardsDistributionAlgorithm,
secret_storage_plus::{AppendStore, Item, Map},
storage::{singleton, singleton_read, ReadonlySingleton, Singleton},
Expand Down Expand Up @@ -65,6 +62,7 @@ pub struct State {
pub admin_auth: Contract,
pub query_auth: Contract,
pub recover_staking_funds_receiver: Addr,
pub max_bins_per_swap: Option<u32>,
}

#[cw_serde]
Expand Down
Loading

0 comments on commit 9d91e6e

Please sign in to comment.