Skip to content

Commit

Permalink
Factory: PR comments, adds new field in response for a liquidity pool…
Browse files Browse the repository at this point in the history
…, updates tests. Pair: adds new field for the factory response. Updates CHANGELOG.md
  • Loading branch information
gangov committed Sep 14, 2023
1 parent 7207813 commit 24bcaaf
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to
- Decimal: Implement `from_atomics` and `to_string` ([#115])
- Curve: Implement `end` helper ([#115])
- Phoenix: Helper library for commonly used functions, structs, etc... ([#116])
- Factory: Adds functionality that provides more detailed information about a single pool or a vector of pools ([#128])

## Changed

Expand Down Expand Up @@ -48,6 +49,7 @@ and this project adheres to
[#116]: https://github.com/Phoenix-Protocol-Group/phoenix-contracts/pull/116
[#118]: https://github.com/Phoenix-Protocol-Group/phoenix-contracts/pull/118
[#122]: https://github.com/Phoenix-Protocol-Group/phoenix-contracts/pull/122
[#128]: https://github.com/Phoenix-Protocol-Group/phoenix-contracts/pull/128

## [0.5.0] - 2023-08-04

Expand Down
4 changes: 2 additions & 2 deletions contracts/factory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub trait FactoryTrait {
pool_address: Address,
) -> Result<LiquidityPoolInfo, ContractError>;

fn query_all_pool_details(env: Env) -> Result<Vec<LiquidityPoolInfo>, ContractError>;
fn query_all_pools_details(env: Env) -> Result<Vec<LiquidityPoolInfo>, ContractError>;

fn get_admin(env: Env) -> Result<Address, ContractError>;
}
Expand Down Expand Up @@ -109,7 +109,7 @@ impl FactoryTrait for Factory {
Ok(pool_response)
}

fn query_all_pool_details(env: Env) -> Result<Vec<LiquidityPoolInfo>, ContractError> {
fn query_all_pools_details(env: Env) -> Result<Vec<LiquidityPoolInfo>, ContractError> {
let all_lp_vec_addresses = get_lp_vec(&env)?;
let mut result = Vec::new(&env);
for address in all_lp_vec_addresses {
Expand Down
25 changes: 1 addition & 24 deletions contracts/factory/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,6 @@ impl TryFromVal<Env, DataKey> for Val {
}
}

#[contracttype]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(u32)]
pub enum PairType {
Xyk = 0,
}
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Config {
pub token_a: Address,
pub token_b: Address,
pub share_token: Address,
pub stake_contract: Address,
pub pair_type: PairType,
/// The total fees (in bps) charged by a pair of this type.
/// In relation to the returned amount of tokens
pub total_fee_bps: i64,
pub fee_recipient: Address,
/// The maximum amount of slippage (in bps) that is tolerated during providing liquidity
pub max_allowed_slippage_bps: i64,
/// The maximum amount of spread (in bps) that is tolerated during swap
pub max_allowed_spread_bps: i64,
}

#[contracttype]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Asset {
Expand All @@ -65,6 +41,7 @@ pub struct PoolResponse {
#[contracttype]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LiquidityPoolInfo {
pub pool_address: Address,
pub pool_response: PoolResponse,
pub total_fee_bps: i64,
}
Expand Down
32 changes: 29 additions & 3 deletions contracts/factory/src/tests/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,32 @@ use super::setup::{
};
use phoenix::utils::{LiquidityPoolInitInfo, StakeInitInfo, TokenInitInfo};

use crate::storage::Config;
use soroban_sdk::arbitrary::std;
use soroban_sdk::{testutils::Address as _, Address, Env, Symbol, Vec};
use soroban_sdk::{contracttype, testutils::Address as _, Address, Env, Symbol, Vec};

#[contracttype]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(u32)]
pub enum PairType {
Xyk = 0,
}
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Config {
pub token_a: Address,
pub token_b: Address,
pub share_token: Address,
pub stake_contract: Address,
pub pair_type: PairType,
/// The total fees (in bps) charged by a pair of this type.
/// In relation to the returned amount of tokens
pub total_fee_bps: i64,
pub fee_recipient: Address,
/// The maximum amount of slippage (in bps) that is tolerated during providing liquidity
pub max_allowed_slippage_bps: i64,
/// The maximum amount of spread (in bps) that is tolerated during swap
pub max_allowed_spread_bps: i64,
}

#[test]
fn test_deploy_multiple_liquidity_pools() {
Expand Down Expand Up @@ -139,6 +162,7 @@ fn test_deploy_multiple_liquidity_pools() {
share_token_addr,
first_result.pool_response.asset_lp_share.address
);
assert_eq!(lp_contract_addr, first_result.pool_address);

let second_lp_contract_addr = factory.query_pools().get(1).unwrap();
let second_result = factory.query_pool_details(&second_lp_contract_addr);
Expand All @@ -164,6 +188,7 @@ fn test_deploy_multiple_liquidity_pools() {
second_share_token_addr,
second_result.pool_response.asset_lp_share.address
);
assert_eq!(second_lp_contract_addr, second_result.pool_address);

let third_lp_contract_addr = factory.query_pools().get(2).unwrap();
let third_result = factory.query_pool_details(&third_lp_contract_addr);
Expand All @@ -189,8 +214,9 @@ fn test_deploy_multiple_liquidity_pools() {
third_share_token_addr,
third_result.pool_response.asset_lp_share.address
);
assert_eq!(third_lp_contract_addr, third_result.pool_address);

let all_pools = factory.query_all_pool_details();
let all_pools = factory.query_all_pools_details();
assert_eq!(all_pools.len(), 3);
all_pools.iter().for_each(|pool| {
assert!(all_pools.contains(pool));
Expand Down
1 change: 1 addition & 0 deletions contracts/pair/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ impl LiquidityPoolTrait for LiquidityPool {
let total_fee_bps = config.max_allowed_spread_bps;

Ok(LiquidityPoolInfo {
pool_address: env.current_contract_address(),
pool_response,
total_fee_bps,
})
Expand Down
1 change: 1 addition & 0 deletions contracts/pair/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pub struct PoolResponse {
#[contracttype]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LiquidityPoolInfo {
pub pool_address: Address,
pub pool_response: PoolResponse,
pub total_fee_bps: i64,
}
Expand Down

0 comments on commit 24bcaaf

Please sign in to comment.