Skip to content

Commit

Permalink
Merge pull request #375 from Phoenix-Protocol-Group/stake-rewards/sta…
Browse files Browse the repository at this point in the history
…ke-calls-stake-rewards-v2

Stake rewards/stake calls stake rewards v2
  • Loading branch information
ueco-jb authored Aug 6, 2024
2 parents d43b7fd + 22b218e commit ddb7cf2
Show file tree
Hide file tree
Showing 30 changed files with 912 additions and 1,290 deletions.
5 changes: 5 additions & 0 deletions contracts/factory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub trait FactoryTrait {
lp_wasm_hash: BytesN<32>,
stable_wasm_hash: BytesN<32>,
stake_wasm_hash: BytesN<32>,
stake_rewards_wasm_hash: BytesN<32>,
token_wasm_hash: BytesN<32>,
whitelisted_accounts: Vec<Address>,
lp_token_decimals: u32,
Expand Down Expand Up @@ -87,6 +88,7 @@ impl FactoryTrait for Factory {
lp_wasm_hash: BytesN<32>,
stable_wasm_hash: BytesN<32>,
stake_wasm_hash: BytesN<32>,
stake_rewards_wasm_hash: BytesN<32>,
token_wasm_hash: BytesN<32>,
whitelisted_accounts: Vec<Address>,
lp_token_decimals: u32,
Expand Down Expand Up @@ -117,6 +119,7 @@ impl FactoryTrait for Factory {
lp_wasm_hash,
stable_wasm_hash,
stake_wasm_hash,
stake_rewards_wasm_hash,
token_wasm_hash,
whitelisted_accounts,
lp_token_decimals,
Expand Down Expand Up @@ -161,6 +164,7 @@ impl FactoryTrait for Factory {
let config = get_config(&env);
let stake_wasm_hash = config.stake_wasm_hash;
let token_wasm_hash = config.token_wasm_hash;
let stake_rewards_wasm_hash = config.stake_rewards_wasm_hash;

let pool_hash = match pool_type {
PoolType::Xyk => config.lp_wasm_hash,
Expand Down Expand Up @@ -188,6 +192,7 @@ impl FactoryTrait for Factory {
let mut init_fn_args: Vec<Val> = (
stake_wasm_hash,
token_wasm_hash,
stake_rewards_wasm_hash,
lp_init_info.clone(),
factory_addr,
config.lp_token_decimals,
Expand Down
1 change: 1 addition & 0 deletions contracts/factory/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct Config {
pub stable_wasm_hash: BytesN<32>,
pub stake_wasm_hash: BytesN<32>,
pub token_wasm_hash: BytesN<32>,
pub stake_rewards_wasm_hash: BytesN<32>,
pub whitelisted_accounts: Vec<Address>,
pub lp_token_decimals: u32,
}
Expand Down
4 changes: 4 additions & 0 deletions contracts/factory/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use setup::install_stake_rewards_wasm;
use soroban_sdk::{testutils::Address as _, vec, Address, Env};

use self::setup::{
Expand All @@ -23,6 +24,7 @@ fn test_deploy_factory_twice_should_fail() {
let lp_wasm_hash = install_lp_contract(&env);
let stable_wasm_hash = install_stable_lp(&env);
let stake_wasm_hash = install_stake_wasm(&env);
let stake_rewards_wasm_hash = install_stake_rewards_wasm(&env);
let token_wasm_hash = install_token_wasm(&env);

let factory = deploy_factory_contract(&env, admin.clone());
Expand All @@ -33,6 +35,7 @@ fn test_deploy_factory_twice_should_fail() {
&lp_wasm_hash,
&stable_wasm_hash,
&stake_wasm_hash,
&stake_rewards_wasm_hash,
&token_wasm_hash,
&vec![&env, auth_user.clone()],
&10u32,
Expand All @@ -43,6 +46,7 @@ fn test_deploy_factory_twice_should_fail() {
&lp_wasm_hash,
&stable_wasm_hash,
&stake_wasm_hash,
&stake_rewards_wasm_hash,
&token_wasm_hash,
&vec![&env, auth_user.clone()],
&10u32,
Expand Down
4 changes: 3 additions & 1 deletion contracts/factory/src/tests/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::setup::{
deploy_factory_contract, install_lp_contract, install_multihop_wasm, install_stable_lp,
install_stake_wasm, install_token_wasm, lp_contract,
install_stake_rewards_wasm, install_stake_wasm, install_token_wasm, lp_contract,
};
use crate::{
contract::{Factory, FactoryClient},
Expand Down Expand Up @@ -240,6 +240,7 @@ fn factory_fails_to_init_lp_when_no_whitelisted_accounts() {
let lp_wasm_hash = install_lp_contract(&env);
let stable_wasm_hash = install_stable_lp(&env);
let stake_wasm_hash = install_stake_wasm(&env);
let stake_rewards_wasm_hash = install_stake_rewards_wasm(&env);
let token_wasm_hash = install_token_wasm(&env);

factory.initialize(
Expand All @@ -248,6 +249,7 @@ fn factory_fails_to_init_lp_when_no_whitelisted_accounts() {
&lp_wasm_hash,
&stable_wasm_hash,
&stake_wasm_hash,
&stake_rewards_wasm_hash,
&token_wasm_hash,
&whitelisted_accounts,
&10u32,
Expand Down
9 changes: 9 additions & 0 deletions contracts/factory/src/tests/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ pub fn install_stake_wasm(env: &Env) -> BytesN<32> {
env.deployer().upload_contract_wasm(WASM)
}

pub fn install_stake_rewards_wasm(env: &Env) -> BytesN<32> {
soroban_sdk::contractimport!(
file = "../../target/wasm32-unknown-unknown/release/phoenix_stake_rewards.wasm"
);
env.deployer().upload_contract_wasm(WASM)
}

pub fn deploy_factory_contract<'a>(
env: &Env,
admin: impl Into<Option<Address>>,
Expand All @@ -67,6 +74,7 @@ pub fn deploy_factory_contract<'a>(
let lp_wasm_hash = install_lp_contract(env);
let stable_wasm_hash = install_stable_lp(env);
let stake_wasm_hash = install_stake_wasm(env);
let stake_rewards_wasm_hash = install_stake_rewards_wasm(env);
let token_wasm_hash = install_token_wasm(env);

factory.initialize(
Expand All @@ -75,6 +83,7 @@ pub fn deploy_factory_contract<'a>(
&lp_wasm_hash,
&stable_wasm_hash,
&stake_wasm_hash,
&stake_rewards_wasm_hash,
&token_wasm_hash,
&whitelisted_accounts,
&10u32,
Expand Down
9 changes: 9 additions & 0 deletions contracts/multihop/src/tests/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ pub fn install_stake_wasm(env: &Env) -> BytesN<32> {
env.deployer().upload_contract_wasm(WASM)
}

pub fn install_stake_rewards_wasm(env: &Env) -> BytesN<32> {
soroban_sdk::contractimport!(
file = "../../target/wasm32-unknown-unknown/release/phoenix_stake_rewards.wasm"
);
env.deployer().upload_contract_wasm(WASM)
}

#[allow(clippy::too_many_arguments)]
pub fn install_multihop_wasm(env: &Env) -> BytesN<32> {
soroban_sdk::contractimport!(
Expand Down Expand Up @@ -94,6 +101,7 @@ pub fn deploy_and_initialize_factory(env: &Env, admin: Address) -> factory_contr
let lp_wasm_hash = install_lp_contract(env);
let stable_wasm_hash = install_stable_lp_contract(env);
let stake_wasm_hash = install_stake_wasm(env);
let stake_rewards_wasm_hash = install_stake_rewards_wasm(env);
let token_wasm_hash = install_token_wasm(env);

factory_client.initialize(
Expand All @@ -102,6 +110,7 @@ pub fn deploy_and_initialize_factory(env: &Env, admin: Address) -> factory_contr
&lp_wasm_hash,
&stable_wasm_hash,
&stake_wasm_hash,
&stake_rewards_wasm_hash,
&token_wasm_hash,
&whitelisted_accounts,
&10u32,
Expand Down
3 changes: 3 additions & 0 deletions contracts/pool/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub trait LiquidityPoolTrait {
env: Env,
stake_wasm_hash: BytesN<32>,
token_wasm_hash: BytesN<32>,
stake_rewards_wasm_hash: BytesN<32>,
lp_init_info: LiquidityPoolInitInfo,
factory_addr: Address,
share_token_decimals: u32,
Expand Down Expand Up @@ -152,6 +153,7 @@ impl LiquidityPoolTrait for LiquidityPool {
env: Env,
stake_wasm_hash: BytesN<32>,
token_wasm_hash: BytesN<32>,
stake_rewards_wasm_hash: BytesN<32>,
lp_init_info: LiquidityPoolInitInfo,
factory_addr: Address,
share_token_decimals: u32,
Expand Down Expand Up @@ -232,6 +234,7 @@ impl LiquidityPoolTrait for LiquidityPool {
stake_contract::Client::new(&env, &stake_contract_address).initialize(
&admin,
&share_token_address,
&stake_rewards_wasm_hash,
&min_bond,
&min_reward,
&manager,
Expand Down
8 changes: 6 additions & 2 deletions contracts/pool/src/tests/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use phoenix::utils::{LiquidityPoolInitInfo, StakeInitInfo, TokenInitInfo};
use soroban_sdk::{testutils::Address as _, Address, Env, String};

use super::setup::{
deploy_liquidity_pool_contract, deploy_token_contract, install_new_lp_wasm, install_stake_wasm,
install_token_wasm,
deploy_liquidity_pool_contract, deploy_token_contract, install_new_lp_wasm,
install_stake_rewards_wasm, install_stake_wasm, install_token_wasm,
};
use crate::{
contract::{LiquidityPool, LiquidityPoolClient},
Expand Down Expand Up @@ -42,6 +42,7 @@ fn test_initialize_with_bigger_first_token_should_fail() {
};
let stake_wasm_hash = install_stake_wasm(&env);
let token_wasm_hash = install_token_wasm(&env);
let stake_reward_wasm_hash = install_stake_rewards_wasm(&env);

let lp_init_info = LiquidityPoolInitInfo {
admin,
Expand All @@ -58,6 +59,7 @@ fn test_initialize_with_bigger_first_token_should_fail() {
pool.initialize(
&stake_wasm_hash,
&token_wasm_hash,
&stake_reward_wasm_hash,
&lp_init_info,
&Address::generate(&env),
&10u32,
Expand Down Expand Up @@ -475,6 +477,7 @@ fn test_initialize_with_maximum_allowed_swap_fee_bps_over_the_cap_should_fail()
};
let stake_wasm_hash = install_stake_wasm(&env);
let token_wasm_hash = install_token_wasm(&env);
let stake_reward_wasm_hash = install_stake_rewards_wasm(&env);

let lp_init_info = LiquidityPoolInitInfo {
admin,
Expand All @@ -491,6 +494,7 @@ fn test_initialize_with_maximum_allowed_swap_fee_bps_over_the_cap_should_fail()
pool.initialize(
&stake_wasm_hash,
&token_wasm_hash,
&stake_reward_wasm_hash,
&lp_init_info,
&Address::generate(&env),
&10u32,
Expand Down
9 changes: 9 additions & 0 deletions contracts/pool/src/tests/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ pub fn install_stake_wasm(env: &Env) -> BytesN<32> {
env.deployer().upload_contract_wasm(WASM)
}

pub fn install_stake_rewards_wasm(env: &Env) -> BytesN<32> {
soroban_sdk::contractimport!(
file = "../../target/wasm32-unknown-unknown/release/phoenix_stake_rewards.wasm"
);
env.deployer().upload_contract_wasm(WASM)
}

#[allow(clippy::too_many_arguments)]
pub fn install_new_lp_wasm(env: &Env) -> BytesN<32> {
soroban_sdk::contractimport!(
Expand Down Expand Up @@ -64,6 +71,7 @@ pub fn deploy_liquidity_pool_contract<'a>(
};
let stake_wasm_hash = install_stake_wasm(env);
let token_wasm_hash = install_token_wasm(env);
let stake_reward_wasm_hash = install_stake_rewards_wasm(env);

let lp_init_info = LiquidityPoolInitInfo {
admin,
Expand All @@ -80,6 +88,7 @@ pub fn deploy_liquidity_pool_contract<'a>(
pool.initialize(
&stake_wasm_hash,
&token_wasm_hash,
&stake_reward_wasm_hash,
&lp_init_info,
&stake_owner,
&10u32,
Expand Down
7 changes: 6 additions & 1 deletion contracts/pool/src/tests/stake_deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ extern crate std;
use phoenix::utils::{LiquidityPoolInitInfo, StakeInitInfo, TokenInitInfo};
use soroban_sdk::{testutils::Address as _, Address, Env, String};

use super::setup::{deploy_liquidity_pool_contract, deploy_token_contract};
use super::setup::{
deploy_liquidity_pool_contract, deploy_token_contract, install_stake_rewards_wasm,
};
use crate::{
stake_contract,
storage::{Config, PairType},
Expand Down Expand Up @@ -101,6 +103,7 @@ fn second_pool_deployment_should_fail() {

let token_wasm_hash = install_token_wasm(&env);
let stake_wasm_hash = install_stake_wasm(&env);
let stake_reward_wasm_hash = install_stake_rewards_wasm(&env);
let fee_recipient = user;
let max_allowed_slippage = 5_000i64; // 50% if not specified
let max_allowed_spread = 500i64; // 5% if not specified
Expand Down Expand Up @@ -131,6 +134,7 @@ fn second_pool_deployment_should_fail() {
pool.initialize(
&stake_wasm_hash,
&token_wasm_hash,
&stake_reward_wasm_hash,
&lp_init_info,
&Address::generate(&env),
&10u32,
Expand All @@ -143,6 +147,7 @@ fn second_pool_deployment_should_fail() {
pool.initialize(
&stake_wasm_hash,
&token_wasm_hash,
&stake_reward_wasm_hash,
&lp_init_info,
&Address::generate(&env),
&10u32,
Expand Down
3 changes: 3 additions & 0 deletions contracts/pool_stable/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub trait StableLiquidityPoolTrait {
env: Env,
stake_wasm_hash: BytesN<32>,
token_wasm_hash: BytesN<32>,
stake_rewards_wasm_hash: BytesN<32>,
lp_init_info: LiquidityPoolInitInfo,
factory_addr: Address,
share_token_decimal: u32,
Expand Down Expand Up @@ -145,6 +146,7 @@ impl StableLiquidityPoolTrait for StableLiquidityPool {
env: Env,
stake_wasm_hash: BytesN<32>,
token_wasm_hash: BytesN<32>,
stake_rewards_wasm_hash: BytesN<32>,
lp_init_info: LiquidityPoolInitInfo,
factory_addr: Address,
_share_token_decimal: u32,
Expand Down Expand Up @@ -226,6 +228,7 @@ impl StableLiquidityPoolTrait for StableLiquidityPool {
stake_contract::Client::new(&env, &stake_contract_address).initialize(
&admin,
&share_token_address,
&stake_rewards_wasm_hash,
&min_bond,
&min_reward,
&manager,
Expand Down
9 changes: 9 additions & 0 deletions contracts/pool_stable/src/tests/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ pub fn install_stake_wasm(env: &Env) -> BytesN<32> {
env.deployer().upload_contract_wasm(WASM)
}

pub fn install_stake_rewards_wasm(env: &Env) -> BytesN<32> {
soroban_sdk::contractimport!(
file = "../../target/wasm32-unknown-unknown/release/phoenix_stake_rewards.wasm"
);
env.deployer().upload_contract_wasm(WASM)
}

#[allow(clippy::too_many_arguments)]
pub fn deploy_stable_liquidity_pool_contract<'a>(
env: &Env,
Expand Down Expand Up @@ -59,6 +66,7 @@ pub fn deploy_stable_liquidity_pool_contract<'a>(

let token_wasm_hash = install_token_wasm(env);
let stake_wasm_hash = install_stake_wasm(env);
let stake_rewards_wasm_hash = install_stake_rewards_wasm(env);

let lp_init_info = LiquidityPoolInitInfo {
admin,
Expand All @@ -75,6 +83,7 @@ pub fn deploy_stable_liquidity_pool_contract<'a>(
pool.initialize(
&stake_wasm_hash,
&token_wasm_hash,
&stake_rewards_wasm_hash,
&lp_init_info,
&factory,
&10, // LP share decimals, unused
Expand Down
9 changes: 8 additions & 1 deletion contracts/pool_stable/src/tests/stake_deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ extern crate std;
use phoenix::utils::{LiquidityPoolInitInfo, StakeInitInfo, TokenInitInfo};
use soroban_sdk::{testutils::Address as _, Address, Env, String};

use super::setup::{deploy_stable_liquidity_pool_contract, deploy_token_contract};
use super::setup::{
deploy_stable_liquidity_pool_contract, deploy_token_contract, install_stake_rewards_wasm,
};
use crate::contract::{StableLiquidityPool, StableLiquidityPoolClient};
use crate::tests::setup::{install_stake_wasm, install_token_wasm};
use crate::{
Expand Down Expand Up @@ -100,6 +102,7 @@ fn second_pool_stable_deployment_should_fail() {

let token_wasm_hash = install_token_wasm(&env);
let stake_wasm_hash = install_stake_wasm(&env);
let stake_reward_wasm_hash = install_stake_rewards_wasm(&env);
let fee_recipient = user;
let max_allowed_slippage = 5_000i64; // 50% if not specified
let max_allowed_spread = 500i64; // 5% if not specified
Expand Down Expand Up @@ -133,6 +136,7 @@ fn second_pool_stable_deployment_should_fail() {
pool.initialize(
&stake_wasm_hash,
&token_wasm_hash,
&stake_reward_wasm_hash,
&lp_init_info,
&factory,
&10, // LP share decimals, unused
Expand All @@ -144,6 +148,7 @@ fn second_pool_stable_deployment_should_fail() {
pool.initialize(
&stake_wasm_hash,
&token_wasm_hash,
&stake_reward_wasm_hash,
&lp_init_info,
&factory,
&10, // LP share decimals, unused
Expand Down Expand Up @@ -179,6 +184,7 @@ fn pool_stable_initialization_should_fail_with_token_a_bigger_than_token_b() {

let token_wasm_hash = install_token_wasm(&env);
let stake_wasm_hash = install_stake_wasm(&env);
let stake_reward_wasm_hash = install_stake_rewards_wasm(&env);
let fee_recipient = user;
let max_allowed_slippage = 5_000i64; // 50% if not specified
let max_allowed_spread = 500i64; // 5% if not specified
Expand Down Expand Up @@ -212,6 +218,7 @@ fn pool_stable_initialization_should_fail_with_token_a_bigger_than_token_b() {
pool.initialize(
&stake_wasm_hash,
&token_wasm_hash,
&stake_reward_wasm_hash,
&lp_init_info,
&factory,
&10, // LP share decimals, unused
Expand Down
Loading

0 comments on commit ddb7cf2

Please sign in to comment.