loan_room
essey_sui::loan_room — sealed rooms. See Sealed rooms.
public fun open<C, L>(m: &Market<C, L>, collateral: Coin<C>, amount: u64, max_rate_bps: u64, term_ms: u64, offer_ct_len: u64, close_ms: u64, settle_by_ms: u64, clock: &Clock, ctx: &mut TxContext)Needs: nothing; the signer becomes the room's borrower. EBadRoom unless amount and collateral are above zero, 0 < max_rate_bps ≤ 100,000, term_ms > 0, now < close_ms < settle_by_ms, bidding at most 6 h and the settle window at most 6 h; EBadCiphertext unless 0 < offer_ct_len ≤ 1,024.
public fun place_offer<C, L>(room: &mut LoanRoom<C, L>, ciphertext: vector<u8>, commitment: vector<u8>, clock: &Clock, ctx: &TxContext)Needs: nothing; any address may bid. Open and before close (EClosed); ciphertext exactly the room's length (EBadCiphertext); a 32-byte commitment (EBadCommitment).
public fun commitment_of(rate_bps: u64, salt: vector<u8>, treasury_id: ID, cap_id: ID, lender: address): vector<u8>
public fun consent_of(room_id: ID, rate_bps: u64, salt: vector<u8>): vector<u8>commitment_of = blake2b256(bcs(rate) ‖ salt ‖ bcs(treasury) ‖ bcs(cap) ‖ bcs(lender)). consent_of = blake2b256(bcs(room) ‖ bcs(rate) ‖ salt), the digest a lender's agent passes to treasury::consent_sealed.
public fun settle<C, L>(room: &mut LoanRoom<C, L>, t: &mut Treasury<L>, m: &Market<C, L>, r: &Reading, index: u64, rate_bps: u64, salt: vector<u8>, cap_id: ID, acc: &Access, clock: &Clock, ctx: &mut TxContext): (LoanDeed, Coin<L>)Needs: to be the room's borrower (ENotBorrower), and the lending Access object, which must admit the borrower for the room's amount (access::assert_open_now, inside loan::open_from_offer). Open (ENotOpen), after close (ENotClosed), before the settle deadline (ESettleWindowClosed), the room's market (EWrongMarket), an existing bid (ENoSuchOffer), a rate within the ceiling (EOverMaxRate), a 32-byte salt (EBadCommitment), an opening that matches the commitment (ECommitmentMismatch), and the lender's consent (treasury::ENoConsent). Then fills through the lender's live mandate with the room's amount and term, as a sealed-room taker.
public fun decline<C, L>(room: &mut LoanRoom<C, L>, ctx: &mut TxContext): Coin<C>
public fun refund<C, L>(room: &mut LoanRoom<C, L>, clock: &Clock, ctx: &mut TxContext)decline: the borrower, any time while open; returns the collateral. refund: anyone, after the settle deadline (ESettleWindowOpen before); sends the collateral to the borrower.
entry fun seal_approve<C, L>(id: vector<u8>, room: &LoanRoom<C, L>, clock: &Clock, ctx: &TxContext)Not called in transactions: Seal key servers dry-run it to decide whether to release a room's keys. It passes only for the identity [package][room_id ‖ "offers"], after close, for the borrower (ENoAccess).
Views#
borrower, market_id, collateral_value, amount, max_rate_bps, term_ms, offer_ct_len, close_ms, settle_by_ms, offer_count, offer_at(index) → (lender, ciphertext, commitment), rate_bps, loan_id, is_open, is_settled, is_declined, is_refunded, and the limits max_room_ms, max_settle_window_ms, max_ct_len, max_rate_limit_bps.
States: 0 OPEN, 1 SETTLED, 2 DECLINED, 3 REFUNDED.
Events#
RoomOpened, RoomSettled { room_id, loan_id, treasury_id, index, rate_bps }, RoomDeclined, RoomRefunded.
Abort codes#
1 ENotBorrower, 2 ENotOpen, 3 EBadRoom, 4 EClosed, 5 EBadCiphertext, 6 EBadCommitment, 7 ENotClosed, 8 ESettleWindowClosed, 9 ENoSuchOffer, 10 EOverMaxRate, 11 ECommitmentMismatch, 12 EWrongMarket, 13 ESettleWindowOpen, 14 ENoAccess.