Skip to content

Commit

Permalink
integration-test-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
crypto-vincent committed Oct 21, 2023
1 parent 9e9bd71 commit 911446f
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 254 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,25 @@ pub struct RebalanceCreateWithdrawRequestFromCredixLpDepository<'info> {
)]
pub controller: AccountLoader<'info, Controller>,

/// #6
/// #3
pub collateral_mint: Box<Account<'info, Mint>>,

/// #3
/// #4
#[account(
mut,
has_one = collateral_mint @UxdError::InvalidCollateralMint,
)]
pub identity_depository: AccountLoader<'info, IdentityDepository>,

/// #4
/// #5
#[account(
mut,
has_one = controller @UxdError::InvalidController,
has_one = collateral_mint @UxdError::InvalidCollateralMint,
)]
pub mercurial_vault_depository: AccountLoader<'info, MercurialVaultDepository>,

/// #5
/// #6
#[account(
mut,
has_one = controller @UxdError::InvalidController,
Expand Down Expand Up @@ -118,17 +118,17 @@ pub struct RebalanceCreateWithdrawRequestFromCredixLpDepository<'info> {
)]
pub credix_withdraw_epoch: Account<'info, credix_client::WithdrawEpoch>,

/// #6
/// #14
#[account(
mut,
has_one = controller @UxdError::InvalidController,
has_one = collateral_mint @UxdError::InvalidCollateralMint,
)]
pub alloyx_vault_depository: AccountLoader<'info, AlloyxVaultDepository>,

/// #14
pub system_program: Program<'info, System>,
/// #15
pub system_program: Program<'info, System>,
/// #16
pub credix_program: Program<'info, credix_client::program::Credix>,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,30 @@ pub struct RebalanceRedeemWithdrawRequestFromCredixLpDepository<'info> {
)]
pub controller: AccountLoader<'info, Controller>,

/// #7
/// #3
pub collateral_mint: Box<Account<'info, Mint>>,

/// #3
/// #4
#[account(
mut,
has_one = collateral_mint @UxdError::InvalidCollateralMint,
constraint = identity_depository.load()?.collateral_vault == identity_depository_collateral.key() @UxdError::InvalidDepositoryCollateral,
)]
pub identity_depository: AccountLoader<'info, IdentityDepository>,

/// #4
/// #5
#[account(mut)]
pub identity_depository_collateral: Box<Account<'info, TokenAccount>>,

/// #5
/// #6
#[account(
mut,
has_one = controller @UxdError::InvalidController,
has_one = collateral_mint @UxdError::InvalidCollateralMint,
)]
pub mercurial_vault_depository: AccountLoader<'info, MercurialVaultDepository>,

/// #6
/// #7
#[account(
mut,
has_one = controller @UxdError::InvalidController,
Expand Down Expand Up @@ -167,30 +167,30 @@ pub struct RebalanceRedeemWithdrawRequestFromCredixLpDepository<'info> {
)]
pub credix_withdraw_epoch: Account<'info, credix_client::WithdrawEpoch>,

/// #6
/// #20
#[account(
mut,
has_one = controller @UxdError::InvalidController,
has_one = collateral_mint @UxdError::InvalidCollateralMint,
)]
pub alloyx_vault_depository: AccountLoader<'info, AlloyxVaultDepository>,

/// #20
/// #21
#[account(
mut,
token::mint = collateral_mint,
)]
pub profits_beneficiary_collateral: Box<Account<'info, TokenAccount>>,

/// #21
pub system_program: Program<'info, System>,
/// #22
pub token_program: Program<'info, Token>,
pub system_program: Program<'info, System>,
/// #23
pub associated_token_program: Program<'info, AssociatedToken>,
pub token_program: Program<'info, Token>,
/// #24
pub credix_program: Program<'info, credix_client::program::Credix>,
pub associated_token_program: Program<'info, AssociatedToken>,
/// #25
pub credix_program: Program<'info, credix_client::program::Credix>,
/// #26
pub rent: Sysvar<'info, Rent>,
}

Expand Down
5 changes: 4 additions & 1 deletion programs/uxd/src/instructions/edit_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ impl<'info> EditController<'info> {
depositories_routing_weight_bps.identity_depository_weight_bps,
depositories_routing_weight_bps.mercurial_vault_depository_weight_bps,
)?,
depositories_routing_weight_bps.credix_lp_depository_weight_bps,
checked_add(
depositories_routing_weight_bps.credix_lp_depository_weight_bps,
depositories_routing_weight_bps.alloyx_vault_depository_weight_bps,
)?,
)?;
require!(
u64::from(total_weight_bps) == BPS_POWER,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub mod process_deploy_program;
pub mod process_set_router_depositories;
pub mod process_set_controller_router_depositories;
pub mod process_setup_router_depositories_fields;

pub use process_deploy_program::*;
pub use process_set_router_depositories::*;
pub use process_set_controller_router_depositories::*;
pub use process_setup_router_depositories_fields::*;
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ pub async fn process_deploy_program(
.await?;

// Make sure the controller has the proper router depositories set
program_uxd::procedures::process_set_router_depositories(
program_uxd::procedures::process_set_controller_router_depositories(
program_context,
payer,
authority,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::integration_tests::api::program_credix;
use crate::integration_tests::api::program_mercurial;
use crate::integration_tests::api::program_uxd;

pub async fn process_set_router_depositories(
pub async fn process_set_controller_router_depositories(
program_context: &mut Box<dyn program_context::ProgramContext>,
payer: &Keypair,
authority: &Keypair,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::Keypair;

use uxd::instructions::EditCredixLpDepositoryFields;
use uxd::instructions::EditIdentityDepositoryFields;
use uxd::instructions::EditMercurialVaultDepositoryFields;
use uxd::instructions::EditAlloyxVaultDepositoryFields;

use crate::integration_tests::api::program_context;
use crate::integration_tests::api::program_uxd;

pub async fn process_setup_router_depositories_fields(
program_context: &mut Box<dyn program_context::ProgramContext>,
payer: &Keypair,
authority: &Keypair,
collateral_mint: &Pubkey,
supply_cap: u64,
minting_fee_in_bps: Option<u8>,
redeeming_fee_in_bps: Option<u8>,
minting_disabled: Option<bool>,
profits_beneficiary_collateral: Option<Pubkey>,
) -> Result<(), program_context::ProgramError> {
// Set the identity_depository cap and make sure minting is not disabled
program_uxd::instructions::process_edit_identity_depository(
program_context,
payer,
authority,
&EditIdentityDepositoryFields {
redeemable_amount_under_management_cap: Some(supply_cap.into()),
minting_disabled,
},
)
.await?;

// Set the mercurial_vault_depository cap and make sure minting is not disabled
program_uxd::instructions::process_edit_mercurial_vault_depository(
program_context,
payer,
authority,
collateral_mint,
&EditMercurialVaultDepositoryFields {
redeemable_amount_under_management_cap: Some(supply_cap.into()),
minting_fee_in_bps,
redeeming_fee_in_bps,
minting_disabled,
profits_beneficiary_collateral,
},
)
.await?;

// Set the credix_lp_depository cap and make sure minting is not disabled
program_uxd::instructions::process_edit_credix_lp_depository(
program_context,
payer,
authority,
collateral_mint,
&EditCredixLpDepositoryFields {
redeemable_amount_under_management_cap: Some(supply_cap.into()),
minting_fee_in_bps,
redeeming_fee_in_bps,
minting_disabled,
profits_beneficiary_collateral,
},
)
.await?;

// Set the alloyx_vault_depository cap and make sure minting is not disabled
program_uxd::instructions::process_edit_alloyx_vault_depository(
program_context,
payer,
authority,
collateral_mint,
&EditAlloyxVaultDepositoryFields {
redeemable_amount_under_management_cap: Some(supply_cap),
minting_fee_in_bps,
redeeming_fee_in_bps,
minting_disabled,
profits_beneficiary_collateral,
},
)
.await?;

// Done
Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ async fn test_controller_edit() -> Result<(), program_context::ProgramError> {
depositories_routing_weight_bps: Some(EditDepositoriesRoutingWeightBps {
identity_depository_weight_bps: 25 * 100, // 25%
mercurial_vault_depository_weight_bps: 35 * 100, // 35%
credix_lp_depository_weight_bps: 40 * 100, // 40%
alloyx_vault_depository_weight_bps: 0, // 0%
credix_lp_depository_weight_bps: 30 * 100, // 30%
alloyx_vault_depository_weight_bps: 10 * 100, // 10%
}),
router_depositories: None,
outflow_limit_per_epoch_amount: None,
Expand Down Expand Up @@ -179,8 +179,8 @@ async fn test_controller_edit() -> Result<(), program_context::ProgramError> {
depositories_routing_weight_bps: Some(EditDepositoriesRoutingWeightBps {
identity_depository_weight_bps: 20 * 100, // 20%
mercurial_vault_depository_weight_bps: 30 * 100, // 30%
credix_lp_depository_weight_bps: 50 * 100, // 50%
alloyx_vault_depository_weight_bps: 0, // 0%
credix_lp_depository_weight_bps: 40 * 100, // 40%
alloyx_vault_depository_weight_bps: 10 * 100, // 10%
}),
router_depositories: Some(EditRouterDepositories {
identity_depository: Pubkey::default(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use solana_sdk::signer::Signer;
use spl_token::state::Account;

use uxd::instructions::EditControllerFields;
use uxd::instructions::EditCredixLpDepositoryFields;
use uxd::instructions::EditDepositoriesRoutingWeightBps;
use uxd::instructions::EditIdentityDepositoryFields;
use uxd::instructions::EditMercurialVaultDepositoryFields;

use crate::integration_tests::api::program_context;
use crate::integration_tests::api::program_credix;
Expand Down Expand Up @@ -125,10 +122,10 @@ async fn test_credix_lp_depository_rebalance_illiquid() -> Result<(), program_co
&EditControllerFields {
redeemable_global_supply_cap: Some(amount_we_use_as_supply_cap.into()),
depositories_routing_weight_bps: Some(EditDepositoriesRoutingWeightBps {
identity_depository_weight_bps: 50 * 100,
mercurial_vault_depository_weight_bps: 25 * 100,
credix_lp_depository_weight_bps: 25 * 100,
alloyx_vault_depository_weight_bps: 0,
identity_depository_weight_bps: 40 * 100, // 40%
mercurial_vault_depository_weight_bps: 25 * 100, // 25%
credix_lp_depository_weight_bps: 25 * 100, // 25%
alloyx_vault_depository_weight_bps: 10 * 100, // 10%
}),
router_depositories: None,
outflow_limit_per_epoch_amount: None,
Expand All @@ -139,55 +136,25 @@ async fn test_credix_lp_depository_rebalance_illiquid() -> Result<(), program_co
.await?;

// Now we set the router depositories to the correct PDAs
program_uxd::procedures::process_set_router_depositories(
program_uxd::procedures::process_set_controller_router_depositories(
&mut program_context,
&payer,
&authority,
&collateral_mint.pubkey(),
)
.await?;

// Set the identity_depository cap and make sure minting is not disabled
program_uxd::instructions::process_edit_identity_depository(
&mut program_context,
&payer,
&authority,
&EditIdentityDepositoryFields {
redeemable_amount_under_management_cap: Some(amount_we_use_as_supply_cap.into()),
minting_disabled: Some(false),
},
)
.await?;

// Set the mercurial_vault_depository cap and make sure minting is not disabled
program_uxd::instructions::process_edit_mercurial_vault_depository(
&mut program_context,
&payer,
&authority,
&collateral_mint.pubkey(),
&EditMercurialVaultDepositoryFields {
redeemable_amount_under_management_cap: Some(amount_we_use_as_supply_cap.into()),
minting_fee_in_bps: Some(100),
redeeming_fee_in_bps: Some(100),
minting_disabled: Some(false),
profits_beneficiary_collateral: Some(profits_beneficiary_collateral),
},
)
.await?;

// Set the credix_lp_depository cap and make sure minting is not disabled
program_uxd::instructions::process_edit_credix_lp_depository(
// Setup the fees, caps and profits beneficiary for router depositories
program_uxd::procedures::process_setup_router_depositories_fields(
&mut program_context,
&payer,
&authority,
&collateral_mint.pubkey(),
&EditCredixLpDepositoryFields {
redeemable_amount_under_management_cap: Some(amount_we_use_as_supply_cap.into()),
minting_fee_in_bps: Some(100),
redeeming_fee_in_bps: Some(100),
minting_disabled: Some(false),
profits_beneficiary_collateral: Some(profits_beneficiary_collateral),
},
amount_we_use_as_supply_cap,
Some(100),
Some(100),
Some(false),
Some(profits_beneficiary_collateral),
)
.await?;

Expand Down
Loading

0 comments on commit 911446f

Please sign in to comment.