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

feat: contracts v2 and updated configs #198

Merged
merged 15 commits into from
Oct 22, 2024
Merged
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
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