| Crates.io | defindex-strategy-core |
| lib.rs | defindex-strategy-core |
| version | 0.2.0 |
| created_at | 2024-11-18 18:34:35.887994+00 |
| updated_at | 2024-12-18 15:17:57.477868+00 |
| description | A foundational library for developing and integrating strategies into the DeFindex ecosystem, providing reusable abstractions, events, and custom error handling. |
| homepage | https://defindex.io |
| repository | https://github.com/paltalabs/defindex |
| max_upload_size | |
| id | 1452543 |
| size | 12,905 |
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.
This package includes the following modules:
Add the defindex-strategy-core package to your Cargo.toml dependencies:
[dependencies]
defindex-strategy-core = "0.2.0"
Here is a simple example of how to use this package to build a custom strategy:
use defindex_strategy_core::{DeFindexStrategyTrait, StrategyError, event};
Define your custom strategy by implementing the DeFindexStrategyTrait:
#[contract]
struct MyCustomStrategy;
#[contractimpl]
impl DeFindexStrategyTrait for MyCustomStrategy {
fn __constructor(e: Env, asset: Address, init_args: Vec<Val>) {
// Initialization logic
}
fn deposit(e: Env, amount: i128, from: Address) -> Result<i128, StrategyError> {
// Deposit logic
Ok(0) // it must return the vault balance, same response as balance()
}
fn withdraw(e: Env, amount: i128, from: Address, to: Address) -> Result<i128, StrategyError> {
// Withdrawal logic
Ok(amount) // it must return the vault balance, same response as balance()
}
fn balance(e: Env, from: Address) -> Result<i128, StrategyError> {
// Balance check logic
Ok(0)
}
fn harvest(e: Env, from: Address) -> Result<(), StrategyError> {
// Harvest logic
Ok(())
}
}
Use the event module to log actions:
event::emit_deposit(&e, String::from("MyCustomStrategy"), amount, from.clone());