Skip to content

Commit

Permalink
clean warnings vault and factory
Browse files Browse the repository at this point in the history
  • Loading branch information
esteblock committed Nov 11, 2024
1 parent da6efd3 commit 7eefd81
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion apps/contracts/factory/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mod defindex_vault_contract {

// Create Test Token
pub(crate) fn create_token_contract<'a>(e: &Env, admin: &Address) -> SorobanTokenClient<'a> {
SorobanTokenClient::new(e, &e.register_stellar_asset_contract(admin.clone()))
SorobanTokenClient::new(e, &e.register_stellar_asset_contract_v2(admin.clone()).address())
}

pub(crate) fn get_token_admin_client<'a>(
Expand Down
2 changes: 1 addition & 1 deletion apps/contracts/factory/src/test/all_flow.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use soroban_sdk::{vec, BytesN, Map, String, Vec};
use soroban_sdk::{vec, BytesN, String};

use crate::test::{create_asset_params, defindex_vault_contract::{self, Investment}, DeFindexFactoryTest};

Expand Down
2 changes: 1 addition & 1 deletion apps/contracts/factory/src/test/initialize.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use soroban_sdk::{vec, Address, BytesN, String, Vec};
use soroban_sdk::{BytesN, String};

use crate::error::FactoryError;
use crate::test::{create_asset_params, DeFindexFactoryTest};
Expand Down
2 changes: 1 addition & 1 deletion apps/contracts/vault/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use models::{
OptionalSwapDetailsExactOut,
};
use storage::{
get_assets, set_asset, set_defindex_protocol_fee_receiver, set_factory, set_last_fee_assesment,
get_assets, set_asset, set_defindex_protocol_fee_receiver, set_factory,
set_total_assets, set_vault_fee, extend_instance_ttl
};
use strategies::{
Expand Down
4 changes: 2 additions & 2 deletions apps/contracts/vault/src/test/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn deposit_amounts_desired_more_length() {
let test = DeFindexVaultTest::setup();
test.env.mock_all_auths();
let strategy_params_token0 = create_strategy_params_token0(&test);
let strategy_params_token1 = create_strategy_params_token1(&test);
// let strategy_params_token1 = create_strategy_params_token1(&test);

// initialize with 2 assets
let assets: Vec<AssetAllocation> = sorobanvec![
Expand Down Expand Up @@ -669,7 +669,7 @@ fn deposit_several_assets_min_greater_than_optimal() {
assert_eq!(deposit_result, Err(Ok(ContractError::InsufficientAmount)));

// now we manage to deposit
let deposit_result=test.defindex_contract.deposit(
test.defindex_contract.deposit(
&sorobanvec![&test.env, amount0, amount1],
&sorobanvec![&test.env, amount0, amount1],
&users[0],
Expand Down
2 changes: 1 addition & 1 deletion apps/contracts/vault/src/test/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn test_initialize_with_unsupported_strategy() {
#[test]
fn test_initialize_with_empty_asset_allocation() {
let test = DeFindexVaultTest::setup();
let strategy_params_token0 = create_strategy_params_token0(&test);
// let strategy_params_token0 = create_strategy_params_token0(&test);

let assets: Vec<AssetAllocation> = sorobanvec![&test.env];

Expand Down
2 changes: 1 addition & 1 deletion apps/contracts/vault/src/token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ mod storage_types;
mod total_supply;

pub use contract::VaultToken;
pub use contract::VaultTokenClient;
// pub use contract::VaultTokenClient;
pub use contract::{internal_burn, internal_mint};
pub use metadata::write_metadata;
68 changes: 34 additions & 34 deletions apps/contracts/vault/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,40 +83,40 @@ pub fn calculate_asset_amounts_for_dftokens(
asset_amounts
}

pub fn calculate_dftokens_from_asset_amounts(
env: &Env,
asset_amounts: Map<Address, i128>, // The input asset amounts
total_managed_funds: Map<Address, i128>, // The total managed funds for each asset
) -> Result<i128, ContractError> {
let total_supply = VaultToken::total_supply(env.clone()); // Total dfToken supply

// Initialize the minimum dfTokens corresponding to each asset
let mut min_df_tokens: Option<i128> = None;

// Iterate over each asset in the input map
for (asset_address, input_amount) in asset_amounts.iter() {
// Get the total managed amount for this asset
let managed_amount = total_managed_funds.get(asset_address.clone()).unwrap_or(0);

// Ensure the managed amount is not zero to prevent division by zero
if managed_amount == 0 {
return Err(ContractError::InsufficientManagedFunds);
}

// Calculate the dfTokens corresponding to this asset's amount
let df_tokens_for_asset = (input_amount * total_supply) / managed_amount;

// If this is the first asset or if the calculated df_tokens_for_asset is smaller, update the minimum df_tokens
if let Some(current_min_df_tokens) = min_df_tokens {
min_df_tokens = Some(current_min_df_tokens.min(df_tokens_for_asset));
} else {
min_df_tokens = Some(df_tokens_for_asset);
}
}

// Return the minimum dfTokens across all assets
min_df_tokens.ok_or(ContractError::NoAssetsProvided)
}
// pub fn calculate_dftokens_from_asset_amounts(
// env: &Env,
// asset_amounts: Map<Address, i128>, // The input asset amounts
// total_managed_funds: Map<Address, i128>, // The total managed funds for each asset
// ) -> Result<i128, ContractError> {
// let total_supply = VaultToken::total_supply(env.clone()); // Total dfToken supply

// // Initialize the minimum dfTokens corresponding to each asset
// let mut min_df_tokens: Option<i128> = None;

// // Iterate over each asset in the input map
// for (asset_address, input_amount) in asset_amounts.iter() {
// // Get the total managed amount for this asset
// let managed_amount = total_managed_funds.get(asset_address.clone()).unwrap_or(0);

// // Ensure the managed amount is not zero to prevent division by zero
// if managed_amount == 0 {
// return Err(ContractError::InsufficientManagedFunds);
// }

// // Calculate the dfTokens corresponding to this asset's amount
// let df_tokens_for_asset = (input_amount * total_supply) / managed_amount;

// // If this is the first asset or if the calculated df_tokens_for_asset is smaller, update the minimum df_tokens
// if let Some(current_min_df_tokens) = min_df_tokens {
// min_df_tokens = Some(current_min_df_tokens.min(df_tokens_for_asset));
// } else {
// min_df_tokens = Some(df_tokens_for_asset);
// }
// }

// // Return the minimum dfTokens across all assets
// min_df_tokens.ok_or(ContractError::NoAssetsProvided)
// }

pub fn calculate_optimal_amounts_and_shares_with_enforced_asset(
e: &Env,
Expand Down

0 comments on commit 7eefd81

Please sign in to comment.