Skip to content

Commit

Permalink
feat: contracts v2 and updated configs (Swaylend#198)
Browse files Browse the repository at this point in the history
Signed-off-by: Urban Vidovič <urbanfoundit@gmail.com>
Co-authored-by: Vid Kersic <38610409+Vid201@users.noreply.github.com>
Co-authored-by: Vid Kersic <vid.kersic@yahoo.com>
Co-authored-by: Martin Domajnko <35891136+martines3000@users.noreply.github.com>
  • Loading branch information
4 people committed Oct 22, 2024
1 parent 69f5dd9 commit 63d565a
Show file tree
Hide file tree
Showing 17 changed files with 547 additions and 38 deletions.
2 changes: 1 addition & 1 deletion contracts/market/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name = "market"
# address will be the addres of the proxy contract
[proxy]
enabled = true
address = "0x44daa228d84335bf2e17b1af1cf7f9de73266977affe6c3445f08bd07a2b0d5d"
address = "0x657ab45a6eb98a4893a99fd104347179151e8b3828fd8f2a108cc09770d1ebae"

[dependencies]
market_abi = { path = "../../abis/market_abi" }
Expand Down
6 changes: 3 additions & 3 deletions contracts/market/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ use sway_libs::ownership::*;
use sway_libs::signed_integers::i256::I256;

// version of the smart contract
const VERSION: u8 = 1_u8;
const VERSION: u8 = 2_u8;

// pyth oracle configuration params
const ORACLE_MAX_STALENESS: u64 = 30; // 30 seconds
const ORACLE_MAX_STALENESS: u64 = 60; // 60 seconds
const ORACLE_MAX_AHEADNESS: u64 = 60; // 60 seconds
const ORACLE_MAX_CONF_WIDTH: u256 = 100; // 100 / 10000 = 1.0 %

Expand Down Expand Up @@ -1524,7 +1524,7 @@ pub fn present_value_supply(base_supply_index: u256, principal: u256) -> u256 {
/// let present_value = present_value_borrow(base_borrow_index, principal);
/// ```
pub fn present_value_borrow(base_borrow_index: u256, principal: u256) -> u256 {
principal * base_borrow_index / BASE_INDEX_SCALE_15
(principal * base_borrow_index + BASE_INDEX_SCALE_15 - 1) / BASE_INDEX_SCALE_15
}

/// Calculates the principal value based on the given base supply index and present value.
Expand Down
4 changes: 2 additions & 2 deletions contracts/market/tests/local_tests/main_test_uni.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ async fn main_test() {
.await
.unwrap();

assert!(res == u128::from(parse_units(1, usdc.decimals)));
assert!(res == u128::from(parse_units(1, usdc.decimals)) - 1);

// Withdrawing more than available should fail (2 USDC)
let res = market
Expand Down Expand Up @@ -296,7 +296,7 @@ async fn main_test() {
// ==================== Step #6 ====================
// 👛 Wallet: Admin 🗿
// 🤙 Drop of collateral price
// 💰 Amount: -10%
// 💰 Amount: -30%

print_case_title(6, "Admin", "Drop of collateral price", "-10%");
let res = oracle.price(uni.price_feed_id).await.unwrap().value;
Expand Down
Loading

0 comments on commit 63d565a

Please sign in to comment.