Skip to content

Commit

Permalink
Merge pull request #10 from oraichain/fix/init_config
Browse files Browse the repository at this point in the history
fix instantiate logic
  • Loading branch information
trung2891 authored Oct 23, 2024
2 parents d65b165 + b82f084 commit dc94a86
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
8 changes: 3 additions & 5 deletions contracts/zapper/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
use crate::state::CONFIG;
use crate::{entrypoints::*, Config};

use cosmwasm_std::{
to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult,
};
use cosmwasm_std::{to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};
use cw2::set_contract_version;

// version info for migration info
Expand All @@ -24,12 +22,12 @@ pub const ADD_LIQUIDITY_REPLY_ID: u64 = 3;
pub fn instantiate(
deps: DepsMut,
_env: Env,
info: MessageInfo,
_info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, ContractError> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
let config = Config {
admin: info.sender,
admin: msg.admin,
dex_v3: msg.dex_v3,
mixed_router: msg.mixed_router,
};
Expand Down
6 changes: 2 additions & 4 deletions contracts/zapper/src/entrypoints/execute.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use cosmwasm_std::{
to_json_binary, Addr, CosmosMsg, Decimal, DepsMut, Env, MessageInfo, Response, SubMsg, Uint128,
WasmMsg,
to_json_binary, Addr, CosmosMsg, Decimal, DepsMut, Env, MessageInfo, Response, Uint128, WasmMsg,
};

use oraiswap_v3_common::{
Expand All @@ -12,14 +11,13 @@ use oraiswap_v3_common::{
};

use crate::{
contract::{ZAP_IN_LIQUIDITY_REPLY_ID, ZAP_OUT_LIQUIDITY_REPLY_ID},
entrypoints::common::get_pool_v3_asset_info,
msg::{ExecuteMsg, Route},
state::{CONFIG, PENDING_POSITION, PROTOCOL_FEE, RECEIVER, SNAP_BALANCES, ZAP_OUT_ROUTES},
Config, PairBalance, PendingPosition,
};

use super::{build_swap_msg, internal, validate_fund};
use super::{build_swap_msg, validate_fund};

pub fn update_config(
deps: DepsMut,
Expand Down
24 changes: 18 additions & 6 deletions contracts/zapper/src/entrypoints/internal.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::vec;

use cosmwasm_std::{
to_json_binary, Coin, CosmosMsg, Decimal, DepsMut, Env, MessageInfo, Order, Response, StdResult, SubMsg, WasmMsg
to_json_binary, Coin, CosmosMsg, Decimal, DepsMut, Env, MessageInfo, Order, Response,
StdResult, WasmMsg,
};

use oraiswap_v3_common::{
Expand All @@ -17,7 +18,6 @@ use oraiswap_v3_common::{
};

use crate::{
contract::ADD_LIQUIDITY_REPLY_ID,
msg::ExecuteMsg,
state::{
CONFIG, PENDING_POSITION, PROTOCOL_FEE, RECEIVER, SNAP_BALANCE, SNAP_BALANCES,
Expand All @@ -28,7 +28,11 @@ use crate::{

use super::build_swap_msg;

pub fn zap_in_liquidity(deps: DepsMut, env: Env, info: MessageInfo) -> Result<Response, ContractError> {
pub fn zap_in_liquidity(
deps: DepsMut,
env: Env,
info: MessageInfo,
) -> Result<Response, ContractError> {
if info.sender != env.contract.address {
return Err(ContractError::Unauthorized {});
}
Expand Down Expand Up @@ -146,7 +150,11 @@ pub fn zap_in_liquidity(deps: DepsMut, env: Env, info: MessageInfo) -> Result<Re
Ok(Response::new().add_messages(msgs))
}

pub fn refund_after_zap_in(deps: DepsMut, env: Env, info: MessageInfo) -> Result<Response, ContractError> {
pub fn refund_after_zap_in(
deps: DepsMut,
env: Env,
info: MessageInfo,
) -> Result<Response, ContractError> {
if info.sender != env.contract.address {
return Err(ContractError::Unauthorized {});
}
Expand Down Expand Up @@ -201,11 +209,15 @@ pub fn refund_after_zap_in(deps: DepsMut, env: Env, info: MessageInfo) -> Result
Ok(Response::new().add_messages(msgs))
}

pub fn zap_out_liquidity(deps: DepsMut, env: Env, info: MessageInfo) -> Result<Response, ContractError> {
pub fn zap_out_liquidity(
deps: DepsMut,
env: Env,
info: MessageInfo,
) -> Result<Response, ContractError> {
if info.sender != env.contract.address {
return Err(ContractError::Unauthorized {});
}

let mut msgs: Vec<CosmosMsg> = vec![];
let receiver = RECEIVER.load(deps.storage)?;
let zap_out_routes = ZAP_OUT_ROUTES.load(deps.storage)?;
Expand Down
10 changes: 2 additions & 8 deletions contracts/zapper/src/tests/withdraw.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
use cosmwasm_std::{coins, Uint128};
use decimal::*;
use oraiswap::mixed_router::SwapOperation;
use oraiswap_v3_common::asset::{Asset, AssetInfo};
use oraiswap_v3_common::math::percentage::Percentage;

use oraiswap_v3_common::storage::{FeeTier, PoolKey};

use crate::msg::Route;
use crate::tests::common::init_basic_v3_pool;
use crate::tests::helper::MockApp;
use crate::tests::helper::{macros::*, FEE_DENOM};

Expand All @@ -33,7 +26,8 @@ fn test_withdraw() {
},
amount: Uint128::new(1),
}];
let err = app.withdraw(bob, zapper.as_str(), assets.clone(), Some(bob))
let err = app
.withdraw(bob, zapper.as_str(), assets.clone(), Some(bob))
.unwrap_err();
assert!(err.root_cause().to_string().contains("Unauthorized"));

Expand Down
6 changes: 6 additions & 0 deletions contracts/zapper/src/tests/zapout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ fn zap_out_position_not_exist() {
let err = app
.zap_out_liquidity(&bob, zapper.as_str(), 1, vec![])
.unwrap_err();
println!("error {:?}", err.root_cause().to_string());

#[cfg(not(feature="test-tube"))]
assert!(err.root_cause().to_string().contains("not found"));

#[cfg(feature="test-tube")]
assert!(err.root_cause().to_string().contains("Querier contract error"));
}

#[test]
Expand Down

0 comments on commit dc94a86

Please sign in to comment.