Skip to content

Commit

Permalink
feat: add equitx contract stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
chadoh committed Jul 23, 2024
1 parent 5abcc86 commit 8f43b52
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions contracts/data-feed/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Reflector Network contract clone

This is a minimum viable clone of the Reflector contract, to iron out how we are going to use Loam SDK and to allow for rapid local development.
23 changes: 23 additions & 0 deletions contracts/equitx-landscape/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "equitx-landscape"
description = "Keeps track of all EquitX contracts and allows deploying new ones"
version = "0.0.0"
authors = ["Aha Labs <[email protected]>"]
license = "Apache-2.0"
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib"]
doctest = false

[dependencies]
loam-sdk = { workspace = true, features = ["loam-soroban-sdk"] }
loam-subcontract-core = { workspace = true }


[dev_dependencies]
loam-sdk = { workspace = true, features = ["soroban-sdk-testutils"] }

[package.metadata.loam]
contract = true
7 changes: 7 additions & 0 deletions contracts/equitx-landscape/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# EquitX Landscape Contract

This contract will have:

- a map of asset names ("xUSD") to contract addresses ("C123…")
- a method to deploy new xAsset contract (so it will need to store the wasm of the xAsset contract, or a reference to it by name on the Loam Registry), which is only callable by admin.
- a method to list all CDPs for a given account, so it can iterate the "map of asset names" keys and make cross-contract calls to see if the given account has an entry in its CDPs map.
3 changes: 3 additions & 0 deletions contracts/equitx-landscape/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#![no_std]
use loam_sdk::{derive_contract, soroban_sdk::Vec};
use loam_subcontract_core::{admin::Admin, Core};
23 changes: 23 additions & 0 deletions contracts/xasset/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "xasset"
description = "Fungible Token that wraps another asset, creates a stability pool for it, and allows creating Collateralized Debt Positions (CDPs) against it."
version = "0.0.0"
authors = ["Aha Labs <[email protected]>"]
license = "Apache-2.0"
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib"]
doctest = false

[dependencies]
loam-sdk = { workspace = true, features = ["loam-soroban-sdk"] }
loam-subcontract-core = { workspace = true }


[dev_dependencies]
loam-sdk = { workspace = true, features = ["soroban-sdk-testutils"] }

[package.metadata.loam]
contract = true
47 changes: 47 additions & 0 deletions contracts/xasset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# xAsset Contract

This is mostly just a Fungible Token ([example implementation](https://github.com/loambuild/loam-sdk/tree/main/examples/soroban/ft)), but will also contain most of the other logic described in the Indigo white paper. This includes Stability Pool functionality, and the iAsset/xAsset functionality. We need to come up with a better name for this one. Maybe "BorrowableAsset" or "CollateralizedAsset" or "CDPAsset". These will each be implemented as Loam subcontracts, which will 1. make them easy to split out to separate contracts later if needed and 2. make them easy to publish and share, which means they need understandable names that don't make them sound app-specific. This "asset that wraps another, which people can borrow using CDPs, where these CDPs get liquidated if the collateralization ratio falls below some minimum" is a fairly common pattern across the blockchain space at this point, and it would be nice to give it a recognizable name.

Let's call this subcontract CollateralizedAsset for now. Here's the data managed by this subcontract:

```rs
struct CollateralizedAsset {
/// Oracle ID & which asset from Oracle this tracks. Might be worth storing these as separate fields?
pegged_to: String;
/// basis points; default 110%; updateable by admin
minimum_collateralization_ratio: u16;
/// each Address can only have one CDP per Asset. Given that you can adjust your CDPs freely, that seems fine?
cdps: Map<Address, CDP>;
}
```

Where CDP needs to have:

```rs
struct CDP {
xlm_deposited: u128,
usd_lent: u128,
status: CDPStatus,
}

/// Descriptions of these on page 5 of Indigo white paper
enum CDPStatus {
Open,
Insolvent, // not sure if `Insolvent` needs to be hard-coded or if it can be calculated on-demand while data's small and as part of our eventual indexing layer once data's big
Frozen,
Closed,
}
```


Ok, onto the StabilityPool subcontract.

```
/// all attributes listed here are described in the Indigo white paper
struct StabilityPool {
product_constant: u32; // maybe u64? not sure it will ever get that big
compounded_constant: u32; // or u64! or float??
}
```

I think that might be it, for xAsset contracts. It's at least a good starting point and already gives us lots of functionality to implement and play with.
3 changes: 3 additions & 0 deletions contracts/xasset/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#![no_std]
use loam_sdk::{derive_contract, soroban_sdk::Vec};
use loam_subcontract_core::{admin::Admin, Core};

0 comments on commit 8f43b52

Please sign in to comment.