Skip to content

Commit

Permalink
feat: Publish event on loan removed
Browse files Browse the repository at this point in the history
  • Loading branch information
kovipu committed Feb 18, 2025
1 parent 2cb8e89 commit 8fb39ef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
1 change: 0 additions & 1 deletion contracts/loan_manager/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ impl LoanManager {
&liquidation_threshold,
);

// Return the contract ID of the deployed contract
Ok(deployed_address)
}

Expand Down
18 changes: 13 additions & 5 deletions contracts/loan_manager/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn write_admin(e: &Env, admin: &Address) {
.persistent()
.set(&LoanManagerDataKey::Admin, &admin);
e.events()
.publish((symbol_short!("admin"), symbol_short!("added")), admin);
.publish((LoanManagerDataKey::Admin, symbol_short!("added")), admin);
}

pub fn admin_exists(e: &Env) -> bool {
Expand Down Expand Up @@ -80,7 +80,14 @@ pub fn write_loan(e: &Env, user: Address, loan: Loan) {
.extend_ttl(&key, POSITIONS_LIFETIME_THRESHOLD, POSITIONS_BUMP_AMOUNT);

e.events().publish(
("Loan", if is_existing { "updated" } else { "created" }),
(
symbol_short!("Loan"),
if is_existing {
symbol_short!("updated")
} else {
symbol_short!("created")
},
),
key,
);
}
Expand All @@ -98,7 +105,8 @@ pub fn read_loan(e: &Env, user: Address) -> Option<Loan> {
}

pub fn delete_loan(e: &Env, user: Address) {
e.storage()
.persistent()
.remove(&LoanManagerDataKey::Loan(user));
let key = LoanManagerDataKey::Loan(user);
e.storage().persistent().remove(&key);
e.events()
.publish((symbol_short!("Loan"), symbol_short!("deleted")), key);
}

0 comments on commit 8fb39ef

Please sign in to comment.