Skip to content
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
9 changes: 9 additions & 0 deletions .github/workflows/contracts-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
components: rustfmt, clippy

- name: Cache cargo
uses: actions/cache@v4
Expand All @@ -33,6 +34,9 @@ jobs:
restore-keys: |
${{ runner.os }}-cargo-

- name: Check formatting
run: cargo fmt --all --check

# creditline-contract embeds the four dependency WASMs via
# soroban_sdk::contractimport!, so those WASMs must exist before
# creditline compiles. Build them individually first.
Expand All @@ -49,6 +53,11 @@ jobs:
cargo build --locked --target wasm32-unknown-unknown --release \
-p vouching-contract

# Lint after the dependency WASMs exist so creditline-contract's
# contractimport! clients resolve during the native clippy compile.
- name: Clippy (lint gate)
run: cargo clippy --workspace --all-targets --locked -- -D warnings

- name: Build all contracts
run: |
cargo build --locked --target wasm32-unknown-unknown --release
Expand Down
21 changes: 3 additions & 18 deletions contracts/creditline-contract/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub fn emit_loan_funded(
);
}


/// Emit a loan created event
pub fn emit_loan_created(
env: &Env,
Expand Down Expand Up @@ -180,19 +179,10 @@ pub fn emit_loan_in_grace_period(
}

/// Emitted when a late fee is collected as part of `repay_installment`.
pub fn emit_late_fee_paid(
env: &Env,
loan_id: u64,
installment_index: u32,
fee_amount: i128,
) {
pub fn emit_late_fee_paid(env: &Env, loan_id: u64, installment_index: u32, fee_amount: i128) {
env.events().publish(
(LATE_FEE_PAID, loan_id),
(
installment_index,
fee_amount,
env.ledger().timestamp(),
),
(installment_index, fee_amount, env.ledger().timestamp()),
);
}

Expand All @@ -217,12 +207,7 @@ pub fn emit_upgrade_proposed(
}

/// Emit an event when a cross-contract reputation score update fails.
pub fn emit_score_update_failed(
env: &Env,
borrower: &Address,
is_increase: bool,
amount: u32,
) {
pub fn emit_score_update_failed(env: &Env, borrower: &Address, is_increase: bool, amount: u32) {
env.events().publish(
(Symbol::new(env, "ScoreUpdateFailed"), borrower.clone()),
(is_increase, amount, env.ledger().timestamp()),
Expand Down
22 changes: 11 additions & 11 deletions contracts/creditline-contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,14 @@ impl CreditLineContract {
storage::write_loan(&env, &loan);

let pool_contribution = safe_math::sub_i128(total_amount, guarantee_amount)?;
Self::fund_loan_from_pool(&env, &user, &vendor, guarantee_amount, pool_contribution, true);
Self::fund_loan_from_pool(
&env,
&user,
&vendor,
guarantee_amount,
pool_contribution,
true,
);

events::emit_loan_created(
&env,
Expand Down Expand Up @@ -658,10 +665,7 @@ impl CreditLineContract {
&Symbol::new(&env, "decrease_score"),
(updater, loan.borrower.clone(), penalty).into_val(&env),
);
let call_succeeded = match res {
Ok(Ok(())) => true,
_ => false,
};
let call_succeeded = matches!(res, Ok(Ok(())));
if !call_succeeded {
events::emit_score_update_failed(&env, &loan.borrower, false, penalty);
panic_with_error!(&env, CreditLineError::ReputationCallFailed);
Expand Down Expand Up @@ -1175,10 +1179,7 @@ impl CreditLineContract {
&Symbol::new(env, "increase_score"),
(updater, borrower, score_increase).into_val(env),
);
let call_succeeded = match res {
Ok(Ok(())) => true,
_ => false,
};
let call_succeeded = matches!(res, Ok(Ok(())));
if !call_succeeded {
events::emit_score_update_failed(env, borrower, true, score_increase);
panic_with_error!(env, CreditLineError::ReputationCallFailed);
Expand Down Expand Up @@ -1240,8 +1241,7 @@ impl CreditLineContract {

loan.late_fees_outstanding =
safe_math::sub_i128(loan.late_fees_outstanding, late_fee_paid)?;
loan.interest_outstanding =
safe_math::sub_i128(loan.interest_outstanding, interest_paid)?;
loan.interest_outstanding = safe_math::sub_i128(loan.interest_outstanding, interest_paid)?;
loan.service_fee_outstanding =
safe_math::sub_i128(loan.service_fee_outstanding, service_fee_paid)?;
loan.principal_outstanding =
Expand Down
1 change: 1 addition & 0 deletions contracts/creditline-contract/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub fn get_user_loan_count(env: &Env, borrower: &Address) -> Result<u64, CreditL
/// Pagination contract for consumers:
/// - `start`: zero-indexed global loan offset for the borrower.
/// - `limit`: maximum number of loan IDs to retrieve in one call.
///
/// Indexes are stored in pages of size `PAGE_SIZE` (32 loan IDs per page key).
pub fn get_user_loan_ids_paginated(
env: &Env,
Expand Down
Loading
Loading