Skip to content

Commit

Permalink
fixes the failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gangov committed Jan 9, 2025
1 parent a30633c commit abd405a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 35 deletions.
35 changes: 18 additions & 17 deletions contracts/factory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
save_lp_vec_with_tuple_as_key, save_stable_wasm_hash, set_initialized, Asset, Config,
LiquidityPoolInfo, LpPortfolio, PairTupleKey, StakePortfolio, UserPortfolio, ADMIN,
},
utils::{deploy_and_initialize_multihop_contract, deploy_lp_contract},
utils::deploy_and_initialize_multihop_contract,
ConvertVec,
};
use phoenix::{
Expand All @@ -18,8 +18,8 @@ use phoenix::{
utils::{LiquidityPoolInitInfo, PoolType, StakeInitInfo, TokenInitInfo},
};
use soroban_sdk::{
contract, contractimpl, contractmeta, log, panic_with_error, vec, Address, BytesN, Env,
IntoVal, String, Symbol, Val, Vec,
contract, contractimpl, contractmeta, log, panic_with_error, vec, xdr::ToXdr, Address, Bytes,
BytesN, Env, IntoVal, String, Symbol, Val, Vec,
};

// Metadata that is added on to the WASM custom section
Expand Down Expand Up @@ -112,18 +112,6 @@ impl FactoryTrait for Factory {
let stake_wasm_hash = config.stake_wasm_hash;
let token_wasm_hash = config.token_wasm_hash;

let pool_hash = match pool_type {
PoolType::Xyk => config.lp_wasm_hash,
PoolType::Stable => get_stable_wasm_hash(&env),
};

let lp_contract_address = deploy_lp_contract(
&env,
pool_hash,
&lp_init_info.token_init_info.token_a,
&lp_init_info.token_init_info.token_b,
);

validate_bps!(
lp_init_info.swap_fee_bps,
lp_init_info.max_allowed_slippage_bps,
Expand All @@ -134,7 +122,6 @@ impl FactoryTrait for Factory {
);

let factory_addr = env.current_contract_address();
let init_fn: Symbol = Symbol::new(&env, "initialize");
let mut init_fn_args: Vec<Val> = (
stake_wasm_hash,
token_wasm_hash,
Expand All @@ -155,7 +142,21 @@ impl FactoryTrait for Factory {

init_fn_args.push_back(max_allowed_fee_bps.into_val(&env));

env.invoke_contract::<Val>(&lp_contract_address, &init_fn, init_fn_args);
let mut salt = Bytes::new(&env);
salt.append(&lp_init_info.token_init_info.token_a.clone().to_xdr(&env));
salt.append(&lp_init_info.token_init_info.token_b.clone().to_xdr(&env));
let salt = env.crypto().sha256(&salt);

let lp_contract_address = match pool_type {
PoolType::Xyk => env
.deployer()
.with_current_contract(salt)
.deploy_v2(config.lp_wasm_hash, init_fn_args.clone()),
PoolType::Stable => env
.deployer()
.with_current_contract(salt)
.deploy_v2(get_stable_wasm_hash(&env), init_fn_args),
};

let mut lp_vec = get_lp_vec(&env);

Expand Down
14 changes: 14 additions & 0 deletions contracts/factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ pub mod stake_contract {
);
}

//#[allow(clippy::too_many_arguments)]
//pub mod xyk_pool {
// soroban_sdk::contractimport!(
// file = "../../target/wasm32-unknown-unknown/release/phoenix_pool.wasm"
// );
//}
//
//#[allow(clippy::too_many_arguments)]
//pub mod stable_pool {
// soroban_sdk::contractimport!(
// file = "../../target/wasm32-unknown-unknown/release/phoenix_pool_stable.wasm"
// );
//}
//
pub trait ConvertVec<T, U> {
fn convert_vec(&self) -> soroban_sdk::Vec<U>;
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/factory/src/tests/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,9 @@ fn factory_create_xyk_pool_with_amp_parameter_should_still_succeed() {
&String::from_str(&env, "Pool Stable"),
&String::from_str(&env, "EUROC/USDC"),
&PoolType::Xyk,
&Some(10),
&Some(10u64),
&100i64,
&1_000,
&1_000i64,
);

let lp_contract_addr = factory.query_pools().get(0).unwrap();
Expand Down
16 changes: 0 additions & 16 deletions contracts/factory/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
use soroban_sdk::{xdr::ToXdr, Address, Bytes, BytesN, Env};

pub fn deploy_lp_contract(
env: &Env,
wasm_hash: BytesN<32>,
token_a: &Address,
token_b: &Address,
) -> Address {
let mut salt = Bytes::new(env);
salt.append(&token_a.to_xdr(env));
salt.append(&token_b.to_xdr(env));
let salt = env.crypto().sha256(&salt);

env.deployer()
.with_current_contract(salt)
.deploy_v2(wasm_hash, ())
}

pub fn deploy_and_initialize_multihop_contract(
env: Env,
admin: Address,
Expand Down

0 comments on commit abd405a

Please sign in to comment.