Skip to content

Commit 3949f32

Browse files
authored
Merge pull request #220 from kryputh/feat/issue-151-refactor-function-parameters
feat: Add market liquidity filter with minimum pool size threshold
2 parents f63f38d + 9d37168 commit 3949f32

4 files changed

Lines changed: 293 additions & 72 deletions

File tree

contracts/teachlink/src/errors.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub enum EscrowError {
6767
RefundTimeMustBeInFuture = 203,
6868
RefundTimeMustBeAfterReleaseTime = 204,
6969
DuplicateSigner = 205,
70+
DuplicateSigners = 205, // Alias for consistency
7071
SignerNotAuthorized = 206,
7172
SignerAlreadyApproved = 207,
7273
CallerNotAuthorized = 208,
@@ -83,6 +84,10 @@ pub enum EscrowError {
8384
EscrowNotPending = 219,
8485
EscrowNotFound = 220,
8586
ArbitratorNotAuthorized = 221,
87+
InvalidBeneficiary = 222,
88+
InvalidToken = 223,
89+
InvalidArbitrator = 224,
90+
DepositorCannotBeBeneficiary = 225,
8691
}
8792

8893
/// Rewards module errors

contracts/teachlink/src/escrow.rs

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,32 @@ use soroban_sdk::{symbol_short, vec, Address, Bytes, Env, IntoVal, Map, Vec};
1414
pub struct EscrowManager;
1515

1616
impl EscrowManager {
17+
/// Creates an escrow with validated parameters
18+
///
19+
/// # Arguments
20+
/// * `params` - EscrowParameters containing all escrow creation details
21+
///
22+
/// # Returns
23+
/// * `u64` - The ID of the created escrow
24+
///
25+
/// # Errors
26+
/// Returns `EscrowError` if validation fails
1727
pub fn create_escrow(
1828
env: &Env,
19-
depositor: Address,
20-
beneficiary: Address,
21-
token: Address,
22-
amount: i128,
23-
signers: Vec<EscrowSigner>,
24-
threshold: u32,
25-
release_time: Option<u64>,
26-
refund_time: Option<u64>,
27-
arbitrator: Address,
29+
params: EscrowParameters,
2830
) -> Result<u64, EscrowError> {
29-
depositor.require_auth();
31+
params.depositor.require_auth();
3032

31-
EscrowValidator::validate_create_escrow(
32-
env,
33-
&depositor,
34-
&beneficiary,
35-
&token,
36-
amount,
37-
&signers,
38-
threshold,
39-
release_time,
40-
refund_time,
41-
&arbitrator,
42-
)?;
33+
EscrowValidator::validate_escrow_parameters(env, &params)?;
4334

4435
env.invoke_contract::<()>(
45-
&token,
36+
&params.token,
4637
&symbol_short!("transfer"),
4738
vec![
4839
env,
49-
depositor.clone().into_val(env),
40+
params.depositor.clone().into_val(env),
5041
env.current_contract_address().into_val(env),
51-
amount.into_val(env),
42+
params.amount.into_val(env),
5243
],
5344
);
5445

@@ -58,9 +49,9 @@ impl EscrowManager {
5849
.instance()
5950
.has(&crate::storage::INSURANCE_POOL)
6051
{
61-
let premium = InsuranceManager::calculate_premium(env, amount);
52+
let premium = InsuranceManager::calculate_premium(env, params.amount);
6253
if premium > 0 {
63-
InsuranceManager::pay_premium_internal(env, depositor.clone(), premium)?;
54+
InsuranceManager::pay_premium_internal(env, params.depositor.clone(), premium)?;
6455
}
6556
}
6657

@@ -71,16 +62,16 @@ impl EscrowManager {
7162
let now = env.ledger().timestamp();
7263
let escrow = Escrow {
7364
id: escrow_count,
74-
depositor,
75-
beneficiary,
76-
token: token.clone(),
77-
amount,
78-
signers,
79-
threshold,
65+
depositor: params.depositor.clone(),
66+
beneficiary: params.beneficiary.clone(),
67+
token: params.token.clone(),
68+
amount: params.amount,
69+
signers: params.signers.clone(),
70+
threshold: params.threshold,
8071
approval_count: 0,
81-
release_time,
82-
refund_time,
83-
arbitrator,
72+
release_time: params.release_time,
73+
refund_time: params.refund_time,
74+
arbitrator: params.arbitrator.clone(),
8475
status: EscrowStatus::Pending,
8576
created_at: now,
8677
dispute_reason: None,
@@ -90,7 +81,7 @@ impl EscrowManager {
9081
escrows.set(escrow_count, escrow.clone());
9182
env.storage().instance().set(&ESCROWS, &escrows);
9283

93-
EscrowAnalyticsManager::update_creation(env, amount);
84+
EscrowAnalyticsManager::update_creation(env, params.amount);
9485

9586
EscrowCreatedEvent { escrow }.publish(env);
9687

0 commit comments

Comments
 (0)