Skip to content

Commit

Permalink
merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquinsoza committed Dec 9, 2024
2 parents fa460a6 + d2686f9 commit 4029147
Show file tree
Hide file tree
Showing 19 changed files with 388 additions and 24 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,23 @@ yarn build

# Publish to npm
npm publish --access public
```

## 📄 Whitepaper

To generate a pdf version of the whitepaper, you need to install mdbook:
```sh
cargo install mdbook
# Install mdbook-pdf
cargo install mdbook-pdf

# Install mdbook-katex
cargo install mdbook-katex
```

Then, run the following command:
```sh
cd apps/docs/10-whitepaper
mdbook build

```
14 changes: 10 additions & 4 deletions apps/contracts/src/tests/dev.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import { airdropAccount } from "../utils/contract.js";
import { withdrawFromVault } from "./vault.js";
import { Keypair } from "@stellar/stellar-sdk";
import { Keypair, xdr } from "@stellar/stellar-sdk";

const user = Keypair.fromSecret("SA77N6PLHDFRYDNYE3YJQBPTRNODMVYP5WWF2SG42DXB52GW2FWOG2B3")
const contract = "CCNWF3D7FJCZKYCAD6FAO3JNPRHG6SVXHO5YTFDZRXSPOJXL6TIBWP3Y"
Expand All @@ -10,6 +11,11 @@ const withdrawResult =
// await withdrawFromVault(contract, BigInt(10000), user)

console.log('🚀 ~ withdrawResult:', withdrawResult);
// const badUser = Keypair.random()
// await airdropAccount(badUser);
// await withdrawFromVault(contract, BigInt(1000), badUser)
const envelopeXdr: xdr.TransactionEnvelope = withdrawResult.result.envelopeXdr.toXDR("base64")
console.log('🚀 ~ env:', envelopeXdr)
const decodedEnvelope = xdr.ScVal.fromXDR(Buffer.from(envelopeXdr.toXDR("base64"), "base64"), "raw")
console.log('🟢',decodedEnvelope)
/* const equisderre = xdr.ScVal.fromXDR(env, "base64")
console.log(equisderre) */
/* const envelope = xdr.TransactionEnvelope.fromXDR(withdrawResult.result.envelopeXdr, "base64")
console.log('🚀 ~ envelope:', envelope) */
4 changes: 2 additions & 2 deletions apps/contracts/src/tests/vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export async function investVault(
val: entry.asset.toScVal(), // Convert asset address to ScVal
}),
new xdr.ScMapEntry({
key: xdr.ScVal.scvSymbol("strategy_investments"),
key: xdr.ScVal.scvSymbol("strategy_allocations"),
val: xdr.ScVal.scvVec(
entry.strategy_investments.map((investment) =>
xdr.ScVal.scvMap([
Expand All @@ -235,7 +235,7 @@ export async function investVault(
val: nativeToScVal(BigInt(investment.amount), { type: "i128" }), // Ensure i128 conversion
}),
new xdr.ScMapEntry({
key: xdr.ScVal.scvSymbol("strategy"),
key: xdr.ScVal.scvSymbol("strategy_address"),
val: investment.strategy.toScVal(), // Convert strategy address
}),
])
Expand Down
2 changes: 1 addition & 1 deletion apps/contracts/vault/src/test/vault/withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn negative_amount() {

// check that withdraw without balance after initialized returns error InsufficientBalance
#[test]
fn total_supply_0() {
fn zero_total_supply() {
let test = DeFindexVaultTest::setup();
test.env.mock_all_auths();
let strategy_params_token0 = create_strategy_params_token0(&test);
Expand Down
3 changes: 2 additions & 1 deletion apps/docs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# we want to be able to compile the book locally and not push that to the repo
_book/
_book/
book/
5 changes: 4 additions & 1 deletion apps/docs/01-introduction/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Introduction
DeFindex is a protocol where users can define how investment are distributed among multiple DeFi protocols and strategies.
DeFindex is a protocol where users can define how investment are distributed among multiple DeFi protocols and strategies.

You can find the whitepaper [here](../10-whitepaper/README.md).
and a PDF version [here](https://drive.proton.me/urls/ZGFGQ7JAKC#IzQdqXo8r331).
2 changes: 0 additions & 2 deletions apps/docs/10-whitepaper/02-state-of-the-art/README.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
# Design Decisions
We have decided to do:

## Multi Assets Index.
We think is important to offer diversified Indexes to our users, not only in the platforms or strategies they will be interacting, but also in the assets they will be exposed to.
## Multi Assets Vaults.
We think is important to offer diversified Vaults to our users, not only in the platforms or strategies they will be interacting, but also in the assets they will be exposed to.

## AMM Liquidity Pool Support
When supporting a AMM Liquity Pool, the underlying asset will be considered as the **AMM LP token**, for example, for a Soroswap USDC-XLM liquidity pool, the underlying asset will be the Soroswap-USDC-XLM-LP token and not the USDC or XLM tokens.

## User should provide the exact underlying assets
Even if we would provide the best user experience, every Index will only accept the corresponding assets it will be using for its strategies. We can help the user to get these assets before investing in the Index(See Zapper contract). However it is a decision that the Vault will only accept the desired assets in the correct ratio.
Even if we would provide the best user experience, every Vault only accepts the corresponding assets it will be using for its strategies. We can help the user to get these assets before investing in the Vault(See Zapper contract). However it is a decision that the Vault will only accept the desired assets in the correct ratio.

To understand better why we decide this please check the [Why we can`t swap on deposit](../10-apendix/01-why-we-cant-swap-on-deposit-or-withdraw.md) section.

## IDLE funds.
- Security: Enables emergency withdrawal
- Performance: Separate high CPU instructions limits tx.
- Transaction Cost: Enable small investment that wont be affected by costly txs.
IDLE funds are funds that are not being used for any strategy. But they are protected by being held inside the DeFindex Smart Contracts.
- Security: Enables emergency withdrawal. This means that if a DeFi protocol gets too risky, the users won't lose their funds because they can be withdrawn from the DeFi protocol to the DeFindex Smart Contracts.
- Performance: Enable multi transaction movements.
- Transaction Cost: Enable small transactions that wont be affected by costly txs.

## Emergency Withdrawal
- Secutiry. We have roles.
- It allows the Emergency Manager to rescue funds in case of an emergency. These are held in the DeFindex Smart Contracts. Thus, the users won't lose their funds and they will be able to withdraw them anytime.

## Roles
- Manager
- Emergency
- Manager: Can change the Emergency Manager and the Fee Receiver. Rebalance between strategies to optimize the performance and minimize the risk.
- Emergency Manager: Can rescue funds in case of an emergency.
- Fee Receiver: Receives the fees that the protocol pays to incentivize good management.
4 changes: 3 additions & 1 deletion apps/docs/10-whitepaper/03-the-defindex-approach/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# The DeFindex Approach
# The DeFindex Approach

In this section we will describe the approach we took to build DeFindex. Why we chose the design decisions we made and how we tried to improve the current state of the art, leveraging the Stellar ecosystem.
5 changes: 5 additions & 0 deletions apps/docs/10-whitepaper/04-state-of-the-art/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# State of the Art
From all types of DeFi protocols that achieve similar goals currently available on different ecosystem, we have selected 2 to define the basic concepts for DeFidex. These are **Yearn.Finance** and **SetProtocol**.

- [Yearn.Finance](01-yearn-finance.md)
- [SetProtocol](02-set-protocol.md)
3 changes: 3 additions & 0 deletions apps/docs/10-whitepaper/05-appendix/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Appendix

- [Why we can't swap on deposit or withdraw](01-why-we-cant-swap-on-deposit-or-withdraw.md)
4 changes: 3 additions & 1 deletion apps/docs/10-whitepaper/10-appendix/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Apendix
# Apendix

[Why we can't swap on deposit or withdraw](01-why-we-cant-swap-on-deposit-or-withdraw.md)
46 changes: 44 additions & 2 deletions apps/docs/10-whitepaper/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,48 @@
# DeFindex Whitepaper

This protocol by Palta Labs.
Francisco Catrileo | Joaquin Soza | Esteban Iglesias

## Abstract
DeFindex is a set of Smart Contracts to Interact better with different Descentralized Finance protocols on the Stellar / Soroban Blockchain
### Introduction
- [Introduction](./01-introduction/README.md)
- [Core Concepts](./01-introduction/02-core-concepts.md)


### The DeFindex Approach
- [Overview](./03-the-defindex-approach/README.md)
- [Design Decisions](./03-the-defindex-approach/01-design-decisions.md)

### Contracts
- [Vault Contract](./03-the-defindex-approach/02-contracts/01-vault-contract.md)
- [Strategy Contract](./03-the-defindex-approach/02-contracts/02-strategy-contract.md)
- [Zapper Contract](./03-the-defindex-approach/02-contracts/02-zapper-contract.md)

### State of the Art
- [State of the Art](./04-state-of-the-art/README.md)

### Appendix
- [Appendix](./05-appendix/README.md)

### Abstract

DeFindex is a suite of smart contracts designed to facilitate interaction with various Decentralized Finance (DeFi) protocols on the Stellar/Soroban Blockchain. It enables users to create custom strategies, allowing investments to be distributed across multiple DeFi protocols in a streamlined manner. The protocol serves two primary audiences:

1. **Wallet Users (including Web2 users):** DeFindex provides a simplified interface that wallet developers can integrate into their platforms, enabling users to access DeFi investment services effortlessly.
2. **Expert Users:** For experienced investors, DeFindex offers an efficient way to diversify investments without the complexity of building and managing their own strategies.

Inspired by projects such as Yearn, Set Protocol, Compound, and YieldYak, DeFindex adapts their core principles to the Stellar ecosystem.

The protocol comprises three main components:

1. **Factory:** A smart contract responsible for creating new Vaults.
2. **Vaults:** The primary contracts through which users interact, enabling deposits, withdrawals, and position adjustments.
3. **Strategies:** Contracts that allocate Vault assets across various DeFi protocols.

To ensure robust functionality and security, DeFindex implements a role-based management system:

- **Manager:** Oversees strategies and the assets within Vaults.
- **Emergency Manager:** Handles emergency withdrawals.
- **Fee Receiver:** Collects and manages strategy-related fees.

By combining simplicity for newcomers with advanced features for seasoned users, DeFindex aims to make DeFi more accessible and efficient on the Stellar Blockchain.

22 changes: 22 additions & 0 deletions apps/docs/10-whitepaper/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Summary

[DeFindex Whitepaper](./README.md)

# Introduction
- [Introduction](./01-introduction/README.md)
- [Core Concepts](./01-introduction/02-core-concepts.md)

# The DeFindex Approach
- [Overview](./03-the-defindex-approach/README.md)
- [Design Decisions](./03-the-defindex-approach/01-design-decisions.md)

# Contracts
- [Vault Contract](./03-the-defindex-approach/02-contracts/01-vault-contract.md)
- [Strategy Contract](./03-the-defindex-approach/02-contracts/02-strategy-contract.md)
- [Zapper Contract](./03-the-defindex-approach/02-contracts/02-zapper-contract.md)

# State of the Art
- [State of the Art](./04-state-of-the-art/README.md)

# Appendix
- [Appendix](./05-appendix/README.md)
20 changes: 20 additions & 0 deletions apps/docs/10-whitepaper/book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[book]
authors = ["Francisco Catrileo", "Joaquin Soza", "Esteban Iglesias"]
language = "en"
multilingual = false
src = "."
title = "DeFindex Whitepaper"

[output.html]
default-theme = "light"
preferred-dark-theme = "navy"
git-repository-url = "https://github.com/yourusername/yourrepo"
mathjax-support = true

[preprocessor.katex]
after = ["links"]

[output.pdf]
optional = true
pdf.links = false
no-links = true
Loading

0 comments on commit 4029147

Please sign in to comment.