From 853d0c020292fd47362a702920a0093d51ce4eff Mon Sep 17 00:00:00 2001 From: coderipper Date: Mon, 18 Nov 2024 10:18:56 -0300 Subject: [PATCH 1/6] added get_fees to the vault it retruns (u32, u32) --- apps/contracts/vault/src/fee.rs | 2 +- apps/contracts/vault/src/interface.rs | 2 ++ apps/contracts/vault/src/lib.rs | 12 +++++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/contracts/vault/src/fee.rs b/apps/contracts/vault/src/fee.rs index 8a4dd847..5d5445c0 100644 --- a/apps/contracts/vault/src/fee.rs +++ b/apps/contracts/vault/src/fee.rs @@ -14,7 +14,7 @@ use crate::{ /// Fetches the current fee rate from the factory contract. /// The fee rate is expressed in basis points (BPS). -fn fetch_defindex_fee(e: &Env) -> u32 { +pub fn fetch_defindex_fee(e: &Env) -> u32 { let factory_address = get_factory(e); // Interacts with the factory contract to get the fee rate. e.invoke_contract( diff --git a/apps/contracts/vault/src/interface.rs b/apps/contracts/vault/src/interface.rs index 7dd40f1f..1beeef94 100644 --- a/apps/contracts/vault/src/interface.rs +++ b/apps/contracts/vault/src/interface.rs @@ -198,6 +198,8 @@ pub trait VaultTrait { // TODO: DELETE THIS, USED FOR TESTING /// Temporary method for testing purposes. fn get_asset_amounts_for_dftokens(e: Env, df_token: i128) -> Map; + + fn get_fees(e: Env) -> (u32, u32); } pub trait AdminInterfaceTrait { diff --git a/apps/contracts/vault/src/lib.rs b/apps/contracts/vault/src/lib.rs index ece2aec1..6dc5701c 100755 --- a/apps/contracts/vault/src/lib.rs +++ b/apps/contracts/vault/src/lib.rs @@ -24,7 +24,7 @@ mod utils; use access::{AccessControl, AccessControlTrait, RolesDataKey}; use aggregator::{internal_swap_exact_tokens_for_tokens, internal_swap_tokens_for_exact_tokens}; -use fee::collect_fees; +use fee::{collect_fees, fetch_defindex_fee}; use funds::{fetch_current_idle_funds, fetch_current_invested_funds, fetch_total_managed_funds}; //, fetch_idle_funds_for_asset}; use interface::{AdminInterfaceTrait, VaultManagementTrait, VaultTrait}; use investment::{check_and_execute_investments}; @@ -33,8 +33,7 @@ use models::{ OptionalSwapDetailsExactOut, }; use storage::{ - get_assets, set_asset, set_defindex_protocol_fee_receiver, set_factory, - set_total_assets, set_vault_fee, extend_instance_ttl + extend_instance_ttl, get_assets, get_vault_fee, set_asset, set_defindex_protocol_fee_receiver, set_factory, set_total_assets, set_vault_fee }; use strategies::{ get_asset_allocation_from_address, get_strategy_asset, get_strategy_client, @@ -568,6 +567,13 @@ impl VaultTrait for DeFindexVault { extend_instance_ttl(&e); calculate_asset_amounts_for_dftokens(&e, df_tokens) } + + fn get_fees(e: Env) -> (u32, u32) { + extend_instance_ttl(&e); + let defindex_protocol_fee = fetch_defindex_fee(&e); + let vault_fee = get_vault_fee(&e); + (defindex_protocol_fee, vault_fee) + } } #[contractimpl] From 96e45faf4a7ffb89c891cb8dba55b40ae1b180e4 Mon Sep 17 00:00:00 2001 From: coderipper Date: Mon, 18 Nov 2024 10:24:06 -0300 Subject: [PATCH 2/6] published addresses, new factory deployed --- public/testnet.contracts.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/testnet.contracts.json b/public/testnet.contracts.json index c00c6f35..a184b171 100644 --- a/public/testnet.contracts.json +++ b/public/testnet.contracts.json @@ -1,11 +1,11 @@ { "ids": { "hodl_strategy": "CAEYFO6TY5MMPHSX6CMUKSDHPFVLJKV4TFPHE4ZXAEER2NEIB5GSVBVG", - "defindex_factory": "CBHW3ETUDAZ4FKKEEASONLALSZAYR6IMBA2THXKRPGRAVRG7UQLZFEKP" + "defindex_factory": "CARG5QZELODA44D3NB4LIEIJSEMWLJSKA6CNOT4FFGPRYUKC7JLDDZ6L" }, "hashes": { "hodl_strategy": "fcdb4a3c11525a1f32611951741bca5bc4196f58fd1633af37d5b35d30fdf5b0", - "defindex_vault": "861b1b2734e65edb70cc632889d00ce0f07946110e3f957a76714ce9674c73ce", + "defindex_vault": "468b456399610600ae2718188e16052aabb7488493f7260d16b21c8f7dbf1001", "defindex_factory": "d6522e73d98e7826782e0b8df6c15410d1b1be95cca985b3e6f1c88a27a11a92" } } \ No newline at end of file From 8f66b084642e4a7a2f5951a4df423ac5b9c9f9e3 Mon Sep 17 00:00:00 2001 From: coderipper Date: Mon, 18 Nov 2024 15:30:04 -0300 Subject: [PATCH 3/6] fixed version and added core toml --- apps/contracts/Cargo.lock | 16 ++--- apps/contracts/Cargo.toml | 3 +- apps/contracts/strategies/core/Cargo.toml | 3 + apps/contracts/strategies/core/README.md | 77 +++++++++++++++++++++++ 4 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 apps/contracts/strategies/core/README.md diff --git a/apps/contracts/Cargo.lock b/apps/contracts/Cargo.lock index 64415e34..234d602b 100644 --- a/apps/contracts/Cargo.lock +++ b/apps/contracts/Cargo.lock @@ -94,7 +94,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "blend_strategy" -version = "1.0.0" +version = "0.1.0" dependencies = [ "defindex-strategy-core", "soroban-sdk", @@ -281,21 +281,21 @@ dependencies = [ [[package]] name = "defindex-factory" -version = "1.0.0" +version = "0.1.0" dependencies = [ "soroban-sdk", ] [[package]] name = "defindex-strategy-core" -version = "1.0.0" +version = "0.1.0" dependencies = [ "soroban-sdk", ] [[package]] name = "defindex-vault" -version = "1.0.0" +version = "0.1.0" dependencies = [ "defindex-strategy-core", "soroban-sdk", @@ -449,7 +449,7 @@ checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" [[package]] name = "fixed_apr_strategy" -version = "1.0.0" +version = "0.1.0" dependencies = [ "defindex-strategy-core", "soroban-sdk", @@ -540,7 +540,7 @@ dependencies = [ [[package]] name = "hodl_strategy" -version = "1.0.0" +version = "0.1.0" dependencies = [ "defindex-strategy-core", "soroban-sdk", @@ -1200,7 +1200,7 @@ dependencies = [ [[package]] name = "soroswap_strategy" -version = "1.0.0" +version = "0.1.0" dependencies = [ "defindex-strategy-core", "soroban-sdk", @@ -1519,7 +1519,7 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "xycloans_adapter" -version = "1.0.0" +version = "0.1.0" dependencies = [ "defindex-strategy-core", "soroban-sdk", diff --git a/apps/contracts/Cargo.toml b/apps/contracts/Cargo.toml index 9dee20c8..79b3c9e0 100644 --- a/apps/contracts/Cargo.toml +++ b/apps/contracts/Cargo.toml @@ -6,10 +6,11 @@ exclude = [ resolver = "2" [workspace.package] -version = "1.0.0" +version = "0.1.0" edition = "2021" license = "GPL-3.0" repository = "https://github.com/paltalabs/defindex" +homepage = "https://defindex.io" [workspace.dependencies] soroban-sdk = "21.7.6" diff --git a/apps/contracts/strategies/core/Cargo.toml b/apps/contracts/strategies/core/Cargo.toml index 7949f80b..97cc36d3 100644 --- a/apps/contracts/strategies/core/Cargo.toml +++ b/apps/contracts/strategies/core/Cargo.toml @@ -6,6 +6,9 @@ license = { workspace = true } edition = { workspace = true } publish = false repository = { workspace = true } +homepage = { workspace = true } +keywords = ["soroban", "defindex", "strategy", "core", "stellar"] +categories = ["cryptography::cryptocurrencies", "no-std", "development-tools"] [dependencies] soroban-sdk = { workspace = true } diff --git a/apps/contracts/strategies/core/README.md b/apps/contracts/strategies/core/README.md new file mode 100644 index 00000000..0f59f1b9 --- /dev/null +++ b/apps/contracts/strategies/core/README.md @@ -0,0 +1,77 @@ +# DeFindex Strategy Core + +The defindex-strategy-core package is a foundational library designed to facilitate the development of strategies for DeFindex. It provides reusable abstractions and utilities that streamline the creation, management, and integration of strategies into the DeFindex ecosystem. + +### Features + +- **Reusable Events**: Predefined events to log actions such as deposits, withdrawals, and harvests. +- **Custom Errors**: A unified error handling system to ensure consistent and informative feedback across strategies. +- **Core Abstractions**: Base traits and utilities to define and implement strategies with minimal boilerplate. + +### Structure + +This package includes the following modules: +1. **Error**: Provides custom error types to handle various edge cases and ensure smooth execution. +2. **Event**: Includes predefined events for logging and monitoring strategy activity. +3. **Core Traits**: Defines the DeFindexStrategyTrait, which serves as the contract for developing new strategies. + +### Installation + +Add the defindex-strategy-core package to your Cargo.toml dependencies: + +```toml +[dependencies] +defindex-strategy-core = "0.1.0" +``` + +### Usage + +Here is a simple example of how to use this package to build a custom strategy: + +1. Import the Core Library +```rust +use defindex_strategy_core::{DeFindexStrategyTrait, StrategyError, event}; +``` + +2. Implement the Strategy Trait + +Define your custom strategy by implementing the DeFindexStrategyTrait: +```rust +#[contract] +struct MyCustomStrategy; + +#[contractimpl] +impl DeFindexStrategyTrait for MyCustomStrategy { + fn initialize(e: Env, asset: Address, init_args: Vec) -> Result<(), StrategyError> { + // Initialization logic + Ok(()) + } + + fn deposit(e: Env, amount: i128, from: Address) -> Result<(), StrategyError> { + // Deposit logic + Ok(()) + } + + fn withdraw(e: Env, amount: i128, from: Address) -> Result { + // Withdrawal logic + Ok(amount) + } + + fn balance(e: Env, from: Address) -> Result { + // Balance check logic + Ok(0) + } + + fn harvest(e: Env, from: Address) -> Result<(), StrategyError> { + // Harvest logic + Ok(()) + } +} +``` + +3. Emit Events + +Use the event module to log actions: +```rust +event::emit_deposit(&e, String::from("MyCustomStrategy"), amount, from.clone()); +``` \ No newline at end of file From 742aa4f45fe84a3b26303e24532a5ddbd083150a Mon Sep 17 00:00:00 2001 From: coderipper Date: Mon, 18 Nov 2024 15:30:58 -0300 Subject: [PATCH 4/6] publish tru --- apps/contracts/strategies/core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/contracts/strategies/core/Cargo.toml b/apps/contracts/strategies/core/Cargo.toml index 97cc36d3..c597e1b6 100644 --- a/apps/contracts/strategies/core/Cargo.toml +++ b/apps/contracts/strategies/core/Cargo.toml @@ -4,7 +4,7 @@ version = { workspace = true } authors = ["coderipper "] license = { workspace = true } edition = { workspace = true } -publish = false +publish = true repository = { workspace = true } homepage = { workspace = true } keywords = ["soroban", "defindex", "strategy", "core", "stellar"] From 4c589625993b1290fb1ad4d3eeb6bd6a10abcde5 Mon Sep 17 00:00:00 2001 From: coderipper Date: Mon, 18 Nov 2024 15:34:01 -0300 Subject: [PATCH 5/6] added description --- apps/contracts/strategies/core/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/contracts/strategies/core/Cargo.toml b/apps/contracts/strategies/core/Cargo.toml index c597e1b6..a32161a9 100644 --- a/apps/contracts/strategies/core/Cargo.toml +++ b/apps/contracts/strategies/core/Cargo.toml @@ -1,5 +1,6 @@ [package] name = "defindex-strategy-core" +description = "A foundational library for developing and integrating strategies into the DeFindex ecosystem, providing reusable abstractions, events, and custom error handling." version = { workspace = true } authors = ["coderipper "] license = { workspace = true } From fe508d894db6f87ef0de6c3d14dd2a9b9c2109bf Mon Sep 17 00:00:00 2001 From: coderipper Date: Mon, 18 Nov 2024 15:38:32 -0300 Subject: [PATCH 6/6] updated scf rtacker --- scf-tracker.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scf-tracker.md b/scf-tracker.md index f10d6fc0..0366cf32 100644 --- a/scf-tracker.md +++ b/scf-tracker.md @@ -34,7 +34,7 @@ - **Result:** - ✅ Code available on [GitHub](https://github.com/paltalabs/defindex/tree/main/apps/contracts/strategies) - - 🛠️ Adapter Struct published at crates.io + - ✅ Adapter Struct published at crates.io - 🛠️ SEP proposal ---