diff --git a/src/contract.rs b/src/contract.rs index 551ac6c..459b756 100644 --- a/src/contract.rs +++ b/src/contract.rs @@ -7,7 +7,7 @@ use cw2::set_contract_version; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; -use crate::state::{State, STATE}; +use crate::state::{State, FEE_RATE, STATE}; use astroport::asset::AssetInfo; use astroport::pair::{self}; use cosmwasm_std::{Addr, Order, StdError, WasmMsg}; @@ -21,13 +21,14 @@ pub fn instantiate( deps: DepsMut, _env: Env, info: MessageInfo, - _msg: InstantiateMsg, + msg: InstantiateMsg, ) -> Result { let state = State { owner: info.sender.clone(), }; set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; STATE.save(deps.storage, &state)?; + FEE_RATE.save(deps.storage, &msg.fee_rate)?; Ok(Response::new() .add_attribute("method", "instantiate") @@ -77,19 +78,7 @@ fn handle_swap_reply(_deps: DepsMut, _env: Env, msg: Reply) -> StdResult CwTemplateContract { let my_contract_id = app.store_code(my_contract()); - let msg = InstantiateMsg {}; + let msg = InstantiateMsg { fee_rate: 5 }; let my_contract_addr = app .instantiate_contract( my_contract_id, @@ -291,7 +291,7 @@ mod tests { let mut app = mock_app(); let cw_template_id = app.store_code(contract_template()); let pair_id = app.store_code(pair_contract()); - let msg = InstantiateMsg {}; + let msg = InstantiateMsg { fee_rate: 5 }; let cw_template_contract_addr = app .instantiate_contract( cw_template_id, @@ -454,7 +454,7 @@ mod tests { }, ) .unwrap(); - assert_eq!(res.unwrap(), Uint128::new(999998006002)); + assert_eq!(res.unwrap(), Uint128::new(999998006501)); // let another user do swap @@ -498,7 +498,7 @@ mod tests { }, ) .unwrap(); - assert_eq!(res.unwrap(), Uint128::new(999997009006)); + assert_eq!(res.unwrap(), Uint128::new(999997010004)); // Check current balance of user assert_eq!( diff --git a/src/msg.rs b/src/msg.rs index 3e8289b..0865f6c 100644 --- a/src/msg.rs +++ b/src/msg.rs @@ -2,7 +2,9 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::Addr; #[cw_serde] -pub struct InstantiateMsg {} +pub struct InstantiateMsg { + pub fee_rate: u64, +} #[cw_serde] pub enum ExecuteMsg { diff --git a/src/state.rs b/src/state.rs index 8a8c22b..b805310 100644 --- a/src/state.rs +++ b/src/state.rs @@ -45,3 +45,5 @@ pub const POOL_CONTRACT_ADDR: Item = Item::new("pool_contract_addr"); pub const REGISTRY_CONTRACT_ADDR: Item = Item::new("registry_contract_addr"); pub const FACTORY_CONTRACT_ADDR: Item = Item::new("factory_contract_addr"); pub const PAIR_CONTRACT_ADDR: Item = Item::new("pair_contract_addr"); + +pub const FEE_RATE: Item = Item::new("fee_rate");