From 3baafa2c61cbdaef89637f72cd685ac980c0171d Mon Sep 17 00:00:00 2001 From: esteblock Date: Mon, 11 Nov 2024 11:23:57 -0300 Subject: [PATCH] test invest correct idle funds --- apps/contracts/vault/src/investment.rs | 11 +++---- apps/contracts/vault/src/lib.rs | 3 +- apps/contracts/vault/src/strategies.rs | 43 ++++++++----------------- apps/contracts/vault/src/test/invest.rs | 2 +- 4 files changed, 21 insertions(+), 38 deletions(-) diff --git a/apps/contracts/vault/src/investment.rs b/apps/contracts/vault/src/investment.rs index f793bbc5..69fae1a3 100644 --- a/apps/contracts/vault/src/investment.rs +++ b/apps/contracts/vault/src/investment.rs @@ -1,10 +1,8 @@ -use soroban_sdk::{Address, Env, Map, Vec, panic_with_error}; +use soroban_sdk::{Env, Vec, panic_with_error}; use crate::{ models::{AssetStrategySet, AssetInvestmentAllocation}, strategies::invest_in_strategy, - - &asset, utils::{check_nonnegative_amount}, ContractError, }; @@ -31,9 +29,7 @@ use crate::{ /// - For each strategy within an asset: /// - **Non-Negative Amount Check**: Validates that the investment amount is non-negative. /// - **Strategy Active Check**: Ensures that the strategy is not paused before proceeding with the investment. -/// - **Execute Investment**: Calls the `invest_in_strategy` fu -&asset, -ction if all checks pass. +/// - **Execute Investment**: Calls the `invest_in_strategy` fuction if all checks pass. /// /// # Errors /// * Returns `ContractError::WrongAssetAddress` if an asset's address does not match the expected address. @@ -90,7 +86,8 @@ pub fn check_and_execute_investments( // Execute the investment if checks pass - invest_in_strategy(&e, + invest_in_strategy( + &e, &asset.address, &strategy.address, &strategy_investment.amount)?; diff --git a/apps/contracts/vault/src/lib.rs b/apps/contracts/vault/src/lib.rs index b74f05aa..024523de 100755 --- a/apps/contracts/vault/src/lib.rs +++ b/apps/contracts/vault/src/lib.rs @@ -740,7 +740,8 @@ impl VaultManagementTrait for DeFindexVault { }, ActionType::Invest => match (&instruction.strategy, &instruction.amount) { (Some(strategy_address), Some(amount)) => { - invest_in_strategy(&e, strategy_address, amount)?; + invest_in_strategy( + &e, strategy_address, strategy_address, amount)?; // TODO THIS WILL FAIUL FOR NOW } _ => return Err(ContractError::MissingInstructionData), }, diff --git a/apps/contracts/vault/src/strategies.rs b/apps/contracts/vault/src/strategies.rs index 97e648c2..0ea8385e 100644 --- a/apps/contracts/vault/src/strategies.rs +++ b/apps/contracts/vault/src/strategies.rs @@ -1,5 +1,5 @@ use defindex_strategy_core::DeFindexStrategyClient; -use soroban_sdk::{Address, Env, vec, IntoVal, Vec, Val, Symbol}; +use soroban_sdk::{Address, Env, vec, IntoVal, Symbol}; use soroban_sdk::auth::{ContractContext, InvokerContractAuthEntry, SubContractInvocation}; @@ -137,37 +137,18 @@ pub fn withdraw_from_strategy( } pub fn invest_in_strategy( - e: &Env,\ + e: &Env, asset_address: &Address, strategy_address: &Address, amount: &i128, ) -> Result<(), ContractError> { - // e.authorize_as_current_contract(vec![ - // &e, - // InvokerContractAuthEntry::Contract(SubContractInvocation { - // context: ContractContext { - // contract: token_a.clone(), - // fn_name: Symbol::new(&e, "transfer"), - // args: transfer_args_a.clone(), - // }, - // sub_invocations: vec![&e], - // }), - // InvokerContractAuthEntry::Contract(SubContractInvocation { - // context: ContractContext { - // contract: token_b.clone(), - // fn_name: Symbol::new(&e, "transfer"), - // args: transfer_args_b.clone(), - // }, - // sub_invocations: vec![&e], - // }), - // ]); - - // Now we will handle funds on behalf of the contract, not the caller (manager or user) - let mut transfer_args: Vec = vec![&e]; - transfer_args.push_back(e.current_contract_address().into_val(&e)); //from - transfer_args.push_back(strategy_address.into_val(&e)); //to - transfer_args.push_back(amount.into_val(&e)); //amount + + // // Now we will handle funds on behalf of the contract, not the caller (manager or user) + // let mut transfer_args: Vec = vec![&e]; + // transfer_args.push_back(e.current_contract_address().into_val(&e)); //from + // transfer_args.push_back(strategy_address.into_val(&e)); //to + // transfer_args.push_back(amount.into_val(&e)); //amount e.authorize_as_current_contract(vec![ @@ -176,11 +157,15 @@ pub fn invest_in_strategy( context: ContractContext { contract: asset_address.clone(), fn_name: Symbol::new(&e, "transfer"), - args: transfer_args.clone(), + args: ( + e.current_contract_address(), + strategy_address, + amount.clone()).into_val(e), + }, sub_invocations: vec![&e], }), - ]); + ]); let strategy_client = get_strategy_client(&e, strategy_address.clone()); diff --git a/apps/contracts/vault/src/test/invest.rs b/apps/contracts/vault/src/test/invest.rs index c496fc96..d7e53bcb 100644 --- a/apps/contracts/vault/src/test/invest.rs +++ b/apps/contracts/vault/src/test/invest.rs @@ -120,7 +120,7 @@ fn test_invest_wrong_strategy_length() { let test = DeFindexVaultTest::setup(); 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); let assets: Vec = sorobanvec![ &test.env,