Skip to content

Commit

Permalink
Add stubs for landscape contract
Browse files Browse the repository at this point in the history
  • Loading branch information
pselle committed Jul 23, 2024
1 parent 3607987 commit f2a54d2
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
9 changes: 9 additions & 0 deletions contracts/equitx-landscape/src/cdp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[subcontract]
pub trait CDP {
// 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.

fn create_contract(&self, asset: Asset, contract: Address);

// 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.
fn list_cdps(&self, account: Address);
}
53 changes: 53 additions & 0 deletions contracts/equitx-landscape/src/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use loam_sdk::{
soroban_sdk::{self, contracttype, env, xdr::Liabilities, Address, Bytes, Env, Lazy, Map, Vec},
IntoKey,
};

use crate::cdp::CDP;

pub enum Asset {
/// Can be a Stellar Classic or Soroban asset
Stellar(loam_sdk::soroban_sdk::Address),
/// For any external tokens/assets/symbols
Other(loam_sdk::soroban_sdk::Symbol),
}

#[contracttype]
#[derive(IntoKey)]
pub struct Landscape {
// A map of asset names ("xUSD") to contract addresses ("C123…")
assets: Map<Asset, Address>,
}

impl Landscape {
#[must_use]
pub fn new(assets: Map<Asset, Address>) -> Self {
let mut asset_map = Map::new(env());
for asset in assets.into_iter() {
asset_map.set(asset, Map::new(env()));
}
Landscape { assets: asset_map }
}
}

/// Loam SDK currently requires us to implement `Default`. This will be fixed in
/// https://github.com/loambuild/loam/issues/92
impl Default for Landscape {
fn default() -> Self {
Landscape::new(Map::new(env()))
}
}

impl CDP for Landscape {
// 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.

fn create_contract(&self, asset: Asset, contract: Address) {
todo!()
//self.assets.set(asset, contract);
}

// 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.
fn list_cdps(&self, account: Address) {
todo!()
}
}
4 changes: 4 additions & 0 deletions contracts/equitx-landscape/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#![no_std]
use loam_sdk::{derive_contract, soroban_sdk::Vec};
use loam_subcontract_core::{admin::Admin, Core};

mod contract;

pub use contract::Landscape;

0 comments on commit f2a54d2

Please sign in to comment.