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

expose test-only setup fn #19

Merged
merged 17 commits into from
Feb 3, 2025
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
24 changes: 23 additions & 1 deletion contracts/suilend/sources/lending_market.move
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,18 @@ module suilend::lending_market {
fulfill_liquidity_request(lending_market, reserve_array_index, liquidity_request, ctx)
}

// Compound interest for reserve of type T
public fun compound_interest<P>(
lending_market: &mut LendingMarket<P>,
reserve_array_index: u64,
clock: &Clock,
) {
assert!(lending_market.version == CURRENT_VERSION, EIncorrectVersion);
let reserve = vector::borrow_mut(&mut lending_market.reserves, reserve_array_index);

reserve.compound_interest(clock);
}

/// Borrow tokens of type T. A fee is charged.
public fun borrow_request<P, T>(
lending_market: &mut LendingMarket<P>,
Expand Down Expand Up @@ -790,6 +802,11 @@ module suilend::lending_market {
}

// === Public-View Functions ===

public fun reserves<P>(lending_market: &LendingMarket<P>): &vector<Reserve<P>> {
&lending_market.reserves
}

fun max_borrow_amount<P>(
mut rate_limiter: RateLimiter,
obligation: &Obligation<P>,
Expand Down Expand Up @@ -870,7 +887,7 @@ module suilend::lending_market {
}

// slow function. use sparingly.
fun reserve_array_index<P, T>(lending_market: &LendingMarket<P>): u64 {
public fun reserve_array_index<P, T>(lending_market: &LendingMarket<P>): u64 {
let mut i = 0;
while (i < vector::length(&lending_market.reserves)) {
let reserve = vector::borrow(&lending_market.reserves, i);
Expand Down Expand Up @@ -1267,6 +1284,11 @@ module suilend::lending_market {
object::delete(id);
}

#[test_only]
public fun reserves_mut_for_testing<P>(lending_market: &mut LendingMarket<P>): &mut vector<Reserve<P>> {
&mut lending_market.reserves
}

#[test_only]
public fun add_reserve_for_testing<P, T>(
_: &LendingMarketOwnerCap<P>,
Expand Down
21 changes: 21 additions & 0 deletions contracts/suilend/sources/reserve.move
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,12 @@ module suilend::reserve {
reserve.price_identifier = price_identifier;
}

// === View Functions ===

public fun interest_last_update_timestamp_s<P>(reserve: &Reserve<P>): u64 {
reserve.interest_last_update_timestamp_s
}

// === Private Functions ===
fun log_reserve_data<P>(reserve: &Reserve<P>) {
let available_amount_decimal = decimal::from(reserve.available_amount);
Expand Down Expand Up @@ -971,6 +977,21 @@ module suilend::reserve {
price_identifier::from_byte_vec(v)
}

#[test_only]
public fun burn_ctokens_for_testing<P, T>(
reserve: &mut Reserve<P>,
ctokens: Balance<CToken<P, T>>
) {
reserve.ctoken_supply = reserve.ctoken_supply - balance::value(&ctokens);

let balances: &mut Balances<P, T> = dynamic_field::borrow_mut(
&mut reserve.id,
BalanceKey {}
);

balance::decrease_supply(&mut balances.ctoken_supply, ctokens);
}

#[test]
fun test_accessors() {
use sui::test_scenario::{Self};
Expand Down
29 changes: 28 additions & 1 deletion contracts/suilend/tests/lending_market_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ module suilend::lending_market_tests {
}

#[test_only]
fun setup(mut reserve_args: Bag, scenario: &mut Scenario): State {
public fun setup(mut reserve_args: Bag, scenario: &mut Scenario): State {
use suilend::test_usdc::{TEST_USDC};
use suilend::test_sui::{TEST_SUI};
use suilend::reserve_config::{Self};
Expand Down Expand Up @@ -266,6 +266,33 @@ module suilend::lending_market_tests {
}
}

#[test_only]
public fun new_args(initial_deposit: u64, config: ReserveConfig): ReserveArgs {
ReserveArgs {
config,
initial_deposit,
}
}

#[test_only]
public fun destruct_state(state: State): (
Clock,
LendingMarketOwnerCap<LENDING_MARKET>,
LendingMarket<LENDING_MARKET>,
PriceState,
Bag
) {
let State {
clock,
owner_cap,
lending_market,
prices,
type_to_index,
} = state;

(clock, owner_cap, lending_market, prices, type_to_index)
}


#[test]
public fun test_deposit() {
Expand Down
Loading