#strategy #soroban #stellar #action #core #defindex

no-std defindex-strategy-core

A foundational library for developing and integrating strategies into the DeFindex ecosystem, providing reusable abstractions, events, and custom error handling

1 unstable release

new 0.1.0 Nov 18, 2024

#633 in Magic Beans

Download history 129/week @ 2024-11-15

129 downloads per month

GPL-3.0 license

13KB
110 lines

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:

[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
use defindex_strategy_core::{DeFindexStrategyTrait, StrategyError, event};
  1. Implement the Strategy Trait

Define your custom strategy by implementing the DeFindexStrategyTrait:

#[contract]
struct MyCustomStrategy;

#[contractimpl]
impl DeFindexStrategyTrait for MyCustomStrategy {
    fn initialize(e: Env, asset: Address, init_args: Vec<Val>) -> 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<i128, StrategyError> {
        // Withdrawal logic
        Ok(amount)
    }

    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(())
    }
}
  1. Emit Events

Use the event module to log actions:

event::emit_deposit(&e, String::from("MyCustomStrategy"), amount, from.clone());

Dependencies

~11–15MB
~313K SLoC