-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/paltalabs/defindex into fix…
…/refactorUX
- Loading branch information
Showing
9 changed files
with
107 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
[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 <[email protected]>"] | ||
license = { workspace = true } | ||
edition = { workspace = true } | ||
publish = false | ||
publish = true | ||
repository = { workspace = true } | ||
homepage = { workspace = true } | ||
keywords = ["soroban", "defindex", "strategy", "core", "stellar"] | ||
categories = ["cryptography::cryptocurrencies", "no-std", "development-tools"] | ||
|
||
[dependencies] | ||
soroban-sdk = { workspace = true } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<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(()) | ||
} | ||
} | ||
``` | ||
|
||
3. Emit Events | ||
|
||
Use the event module to log actions: | ||
```rust | ||
event::emit_deposit(&e, String::from("MyCustomStrategy"), amount, from.clone()); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters