Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factory with aggregator method #305

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion apps/contracts/factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use soroban_sdk::{
};
use error::FactoryError;
pub use vault::create_contract;
use storage::{ add_new_defindex, extend_instance_ttl, get_admin, get_vault_wasm_hash, get_defindex_receiver, get_deployed_defindexes, get_fee_rate, has_admin, put_admin, put_vault_wasm_hash, put_defindex_receiver, put_defindex_fee };
use storage::{ add_new_defindex, extend_instance_ttl, get_admin, get_aggregator, get_defindex_receiver, get_deployed_defindexes, get_fee_rate, get_vault_wasm_hash, has_admin, put_admin, put_aggregator, put_defindex_fee, put_defindex_receiver, put_vault_wasm_hash };

fn check_initialized(e: &Env) -> Result<(), FactoryError> {
if !has_admin(e) {
Expand All @@ -37,6 +37,7 @@ pub trait FactoryTrait {
admin: Address,
defindex_receiver: Address,
defindex_fee: u32,
soroswap_aggregator: Address,
vault_wasm_hash: BytesN<32>
);

Expand Down Expand Up @@ -166,6 +167,8 @@ pub trait FactoryTrait {
/// # Returns
/// * `Result<u32, FactoryError>` - Returns the fee rate in basis points or an error if not found.
fn defindex_fee(e: Env) -> Result<u32, FactoryError>;

fn aggregator(e: Env) -> Result<Address, FactoryError>;
}

#[contract]
Expand All @@ -179,12 +182,14 @@ impl FactoryTrait for DeFindexFactory {
admin: Address,
defindex_receiver: Address,
defindex_fee: u32,
soroswap_aggregator: Address,
vault_wasm_hash: BytesN<32>
) {
put_admin(&e, &admin);
put_defindex_receiver(&e, &defindex_receiver);
put_vault_wasm_hash(&e, vault_wasm_hash);
put_defindex_fee(&e, &defindex_fee);
put_aggregator(&e, &soroswap_aggregator);

extend_instance_ttl(&e);
}
Expand Down Expand Up @@ -458,6 +463,12 @@ impl FactoryTrait for DeFindexFactory {
extend_instance_ttl(&e);
Ok(get_fee_rate(&e))
}

fn aggregator(e: Env) -> Result<Address, FactoryError> {
check_initialized(&e)?;
extend_instance_ttl(&e);
Ok(get_aggregator(&e))
}
}

mod test;
10 changes: 10 additions & 0 deletions apps/contracts/factory/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub enum DataKey {
DeFindexReceiver,
DeFindexesMap,
FeeRate,
Aggregator
}

const DAY_IN_LEDGERS: u32 = 17280;
Expand Down Expand Up @@ -105,4 +106,13 @@ pub fn put_defindex_fee(e: &Env, value: &u32) {

pub fn get_fee_rate(e: &Env) -> u32 {
e.storage().instance().get(&DataKey::FeeRate).unwrap()
}

// Soroswap Aggregator
pub fn put_aggregator(e: &Env, address: &Address) {
e.storage().instance().set(&DataKey::Aggregator, address);
}

pub fn get_aggregator(e: &Env) -> Address {
e.storage().instance().get(&DataKey::Aggregator).unwrap()
}
Loading