Reference

Authority matrix

Who may call what on the rules contract, and the test that holds each limit. The contract vouches for who called, and the enclave decides whether the caller is entitled.

Who may call what

CallWhoWhat it does, and its test
fix_ratethe agentFixes the period's base rate and its end date
contract test_only_the_agent_fixes_the_rate
request_interestthe agentTypes the total it expects. The enclave refuses unless it equals what the register says
contract test_the_borrower_cannot_request_interest
settlethe agentSettles a payment: every lender is credited in one step
contract test_a_lender_cannot_settle_a_payment
settle_tradethe agentSettles a trade, cash against loan
authority test_only_the_right_party_can_run_each_command
set_dqthe borrowerSets the list of buyers who may not buy into the loan, sealed
contract test_the_agent_cannot_set_the_dq_list
ft_transfer_call, to pay a requestthe borrowerPays an open interest request in the deal's test USDC
contract test_only_the_borrower_pays_a_request
ft_transfer_call, as cashany accountHolds the caller's own cash in the books, as a buyer does before it buys in
contract test_a_transfer_from_another_token_is_rejected
register_view_keyany accountRegisters the key the caller's envelopes are sealed to
contract test_a_view_key_is_published_once_the_enclave_accepts_it
offer_tradethe sellerOffers part of its position: the buyer, size, price and trade date, sealed
authority test_only_the_right_party_can_run_each_command
accept_tradethe buyerAccepts an offer that names it as the buyer
authority test_only_the_right_party_can_run_each_command
withdrawany partyTakes its own cash out of the deal as test USDC
authority test_a_party_can_only_move_its_own_cash
init_deal, unlockthe ownerLoads the closed deal once; releases a lock left by a callback that never ran
contract test_only_the_owner_sets_the_deal_up

The agent’s and the borrower’s calls are checked by the contract itself. For the calls any account can send, the contract only vouches for who called, and the enclave decides whether the caller is entitled. When the agent is a DAO, each of the agent’s calls is a proposal that two of three operators must approve; see The agent, two of three.

What nobody can do

LimitTest
The agent cannot request more than the register saysprincipal test_agent_cannot_request_more_than_the_register_says
A settlement cannot pay more than was requestedprincipal test_settlement_cannot_pay_more_than_requested
Nothing settles without an open requestprincipal test_no_settlement_without_an_open_request
Lenders cannot be credited more than the borrower paid incontract test_lenders_cannot_be_credited_more_than_the_borrower_paid_in
A payout cannot exceed the test USDC the contract holdscontract test_a_payout_cannot_exceed_the_usdc_held
A payout goes only to the party that askedcontract test_a_payout_goes_only_to_the_party_that_asked
Only a withdrawal pays outcontract test_only_a_withdrawal_pays_out
A withdrawal is capped by the party's cashprincipal test_withdrawal_is_capped_by_the_party_s_cash
Every lender is paid, or none isinterest test_every_lender_is_paid_or_none_is
The borrower cannot favour a lenderinterest test_borrower_cannot_favour_a_lender
One action runs at a timecontract test_one_action_at_a_time
Nothing runs once the deal is frozencontract test_nothing_runs_once_frozen
The deal is set up onceauthority test_the_deal_is_set_up_once_and_the_root_tracks_every_change
A sealed offer copied from the chain is no use to anyone elseprotocol test_a_sealed_offer_copied_from_the_chain_is_no_use_to_anyone_else
A late run cannot undo an answer the contract receivedprotocol test_a_late_run_cannot_undo_an_answer_the_contract_received

The contract’s owner

The owner loads the deal once, and can release the lock if a callback is lost. It cannot read the books, move money, act as the agent or set the fingerprint: only the enclave’s answer to the contract’s own request does that.

The tests

enclave   interest     5   one-step payment to the cent, pro rata, no favourites, all or none
          trading      5   cash against loan, interest split on the trade date, DQ screening, trade privacy
          principal    4   the Revlon guard: no request, settlement or withdrawal above what is due
          authority    3   only the right party runs each command
          protocol    11   one envelope per party, one-fact proofs, late answers, no guess confirmed, no box reused
contract              26   roles, one action at a time, credited ≤ paid in, payouts ≤ held, freeze
───────────────────────────────────────────────────────────────────────────────────────────────────
54 tests passing

The enclave’s tests are in near/enclave/tests and the contract’s in near/contract/src/tests.rs. The deal’s rules are ported from the Canton build’s Daml tests with the same names and numbers. Run them with cargo test in each folder; see Check it yourself.