Skip to content

Commit

Permalink
feat: update market configuration (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vid201 authored Aug 9, 2024
1 parent 4b0a40c commit 1b2a261
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 224 deletions.
11 changes: 9 additions & 2 deletions abis/market_abi/src/abi.sw
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::bytes::Bytes;
abi Market {
// # 0. Activate contract (un-pause)
#[storage(write, read)]
fn activate_contract();
fn activate_contract(market_configuration: MarketConfiguration);

// # 1. Debug functionality (for testing purposes)
// This functionality is exclusively utilized in local tests to evaluate interest accrual.
Expand Down Expand Up @@ -96,7 +96,8 @@ abi Market {
fn pause(config: PauseConfiguration);

// # 9. Getters
fn get_configuration() -> MarketConfiguration;
#[storage(read)]
fn get_market_configuration() -> MarketConfiguration;

#[storage(read)]
fn get_market_basics() -> MarketBasics;
Expand All @@ -110,8 +111,10 @@ abi Market {
fn balance_of(asset: b256) -> u64;

// Formulas to help calculate supply and borrow rates
#[storage(read)]
fn get_supply_rate(utilization: u256) -> u256;

#[storage(read)]
fn get_borrow_rate(utilization: u256) -> u256;

// ## 10. Pyth calls
Expand All @@ -126,4 +129,8 @@ abi Market {

#[payable, storage(read)]
fn update_price_feeds(update_fee: u64, update_data: Vec<Bytes>);

// ## 11. Changing market configuration
#[storage(write, read)]
fn update_market_configuration(configuration: MarketConfiguration);
}
60 changes: 43 additions & 17 deletions abis/market_abi/src/structs.sw
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
library;

use i256::I256;
use std::constants::ZERO_B256;

pub const BASE_ACCRUAL_SCALE: u256 = 1_000_000; // 1e6
pub const BASE_INDEX_SCALE_15: u256 = 1_000_000_000_000_000; // 1e15
Expand All @@ -23,23 +24,48 @@ pub struct MarketConfiguration {
pub base_token: b256,
pub base_token_decimals: u32,
pub base_token_price_feed_id: b256,
pub supply_kink: u256,
pub borrow_kink: u256,
pub supply_per_second_interest_rate_slope_low: u256,
pub supply_per_second_interest_rate_slope_high: u256,
pub supply_per_second_interest_rate_base: u256,
pub borrow_per_second_interest_rate_slope_low: u256,
pub borrow_per_second_interest_rate_slope_high: u256,
pub borrow_per_second_interest_rate_base: u256,
pub store_front_price_factor: u256,
pub base_tracking_index_scale: u256,
pub base_tracking_supply_speed: u256,
pub base_tracking_borrow_speed: u256,
pub base_min_for_rewards: u256,
pub base_borrow_min: u256,
pub target_reserves: u256,
pub debug_step: u64,
pub fuel_eth_base_asset_id: b256,
pub supply_kink: u256, // decimals: 18
pub borrow_kink: u256, // decimals: 18
pub supply_per_second_interest_rate_slope_low: u256, // decimals: 18
pub supply_per_second_interest_rate_slope_high: u256, // decimals: 18
pub supply_per_second_interest_rate_base: u256, // decimals: 18
pub borrow_per_second_interest_rate_slope_low: u256, // decimals: 18
pub borrow_per_second_interest_rate_slope_high: u256, // decimals: 18
pub borrow_per_second_interest_rate_base: u256, // decimals: 18
pub store_front_price_factor: u256, // decimals: 18
pub base_tracking_index_scale: u256, // decimals: 18
pub base_tracking_supply_speed: u256, // decimals: 18
pub base_tracking_borrow_speed: u256, // decimals: 18
pub base_min_for_rewards: u256, // decimals: base_token_decimals
pub base_borrow_min: u256, // decimals: base_token_decimals
pub target_reserves: u256, // decimals: base_token_decimals
}

impl MarketConfiguration {
pub fn default() -> Self {
MarketConfiguration {
governor: Address::from(ZERO_B256),
pause_guardian: Address::from(ZERO_B256),
base_token: ZERO_B256,
base_token_decimals: 0,
base_token_price_feed_id: ZERO_B256,
supply_kink: 0,
borrow_kink: 0,
supply_per_second_interest_rate_slope_low: 0,
supply_per_second_interest_rate_slope_high: 0,
supply_per_second_interest_rate_base: 0,
borrow_per_second_interest_rate_slope_low: 0,
borrow_per_second_interest_rate_slope_high: 0,
borrow_per_second_interest_rate_base: 0,
store_front_price_factor: 0,
base_tracking_index_scale: 0,
base_tracking_supply_speed: 0,
base_tracking_borrow_speed: 0,
base_min_for_rewards: 0,
base_borrow_min: 0,
target_reserves: 0,
}
}
}

pub struct PauseConfiguration {
Expand Down
7 changes: 6 additions & 1 deletion contracts/market/src/events.sw
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ pub struct ReservesWithdrawnEvent {
// Pause configuration event
pub struct PauseConfigurationEvent {
pub pause_config: PauseConfiguration,
}
}

// Market configuration event
pub struct MarketConfigurationEvent {
pub market_config: MarketConfiguration,
}
Loading

0 comments on commit 1b2a261

Please sign in to comment.