Skip to main content

Contract overview

Setllend's on-chain logic is a single Rust smart contract deployed at setllend.near on NEAR mainnet. It holds the order books, escrow, loans, and notes for every maturity, matches nothing on its own, and moves funds only inside the user's Intents balance on intents.near. This section is the full reference for developers and auditors: every entry point, message, view, event, and error string, copied from the deployed code.

The deployed code is commit 49fcc47 of the repository, built reproducibly. The contract's contract_source_metadata view names that commit and the build image, so anyone can rebuild it and compare the code hash. See Verify the contract.

What the contract does​

  • Keeps one order book per maturity. A lend order is a bid that escrows USDC. A borrow order is an ask that escrows collateral (or borrows against collateral already in a loan) and issues new notes. A sell_note order is an ask that locks existing notes for sale. See Order book.
  • Checks and settles fills. Anyone may call match_orders with pairs of orders and sizes. The contract validates each fill, sets the rate (the maker's limit rate), mints notes and debt or moves notes, and pays the USDC out. See Matching.
  • Holds loans. One loan per (borrower, maturity), holding one or more collateral tokens and a debt face. It supports adding collateral, repaying, withdrawing collateral, and liquidation with pro rata seizure.
  • Accounts for notes as shares of a per-maturity pool, so bad debt is shared fairly by all note holders of that maturity. See Math.
  • Reads prices from aggregate-oracle.near when an action needs them (borrow fills, liquidation, collateral withdrawal with debt) and validates them itself.
  • Pays out to the user's Intents balance with mt_transfer on intents.near. A payout that fails is credited to an internal free balance the user can withdraw later.

What it does not do​

  • It never verifies signatures. Users sign intents. intents.near verifies the signature, executes the intent, and then calls Setllend. Setllend trusts exactly one caller for user actions: it checks predecessor_account_id == intents.near in mt_on_transfer and on_auth, and rejects any other caller with Caller must be the intents contract.
  • It holds no tokens outside NEAR Intents. Escrow sits in setllend.near's own Intents balance. Deposits from other chains and exits to them happen outside the contract (1Click or the bridges).
  • It does not match orders by itself. A matcher (Setllend runs one, anyone may run another) proposes fills. The contract only accepts or skips them.
  • It does not swap. A liquidator repays USDC and receives collateral. There is no DEX call inside the contract.
  • It has no pause and no user limits. No minimum or maximum order size, no deposit caps, no order-count limits, no rate range.
  • Views make no cross-contract calls, so the contract does not return a health factor. Clients compute it off-chain with the same formula and fresh oracle prices.

Entry points​

Entry pointCalled byPurposePage
mt_on_transfer(sender_id, previous_owner_ids, token_ids, amounts, msg)intents.near only, after a transfer intent with msgActions that bring tokens in: lend, borrow, add_collateral, repay, liquidateTransfer messages
on_auth(signer_id, msg)intents.near only, after an auth_call intentActions without incoming tokens: borrow against a loan, cancel, sell_note, withdraw_collateral, redeem, withdrawAuth call actions
match_orders(fills)AnyoneSettle a batch of fillsMatching
add_maturity, add_collateral_token, update_collateral_token, freeze_collateral_token, unfreeze_collateral_tokenThe owner onlyMaturities and collateral tokensOwner methods
get_* viewsAnyone, freeRead stateViews
on_payout, on_match_prices, on_liquidate_prices, on_withdraw_collateral_pricesThe contract itself only (#[private])Callbacks of payouts and oracle callsGas
new(config)The contract account only (#[private]), once at deployInitializationOwner methods

The owner is setllend.near itself (owner_id in get_config). The contract emits a log line for every state change, described in Events.

How a call reaches the contract​

A user never calls setllend.near directly. They sign an intent with their wallet (ERC-191 for EVM wallets, NEP-413 for NEAR wallets, see Signing intents). Someone submits it to intents.near with execute_intents: Setllend's relayer does this and pays the gas, but anyone holding the signed payload can. intents.near checks the signature and nonce, runs the intent, and calls Setllend.

Two properties matter for integrators:

  • A transfer is atomic with the action. If mt_on_transfer panics, Setllend's state is reverted and intents.near refunds the full amount to the sender's Intents balance. A partial refund (for example the overpayment of a repay) comes back through the return value.
  • An auth_call is detached. The intent batch succeeds even if on_auth fails. To know whether the action happened, read the outcome of the on_auth receipt, and for actions that pay out, look for a payout_failed event too. See Auth call actions.

Units and encoding​

FieldRust typeJSONNotes
Amountsu128decimal string, e.g. "1000000000"Smallest unit of the token. USDC has 6 decimals, ETH 18, NEAR 24. "1000000000" is 1,000 USDC
Gasu64decimal string of gas units"100000000000000" is 100 Tgas
Ratesu32number, e.g. 700APR in basis points (bps). 700 = 7.00%. Any value is accepted
Ratiosu32numbermax_ltv, liq_threshold, liq_bonus in bps, per collateral token. 7000 = 70%
Timestampsu64decimal stringNanoseconds since the Unix epoch, like env::block_timestamp(). expires_at and created_at use it
maturityu64decimal stringA timestamp from the maturity list, e.g. "1795766400000000000" = 2026-11-27 08:00 UTC
order_idu64decimal stringSequential from "0", never reused
Note sharesu128decimal stringInternal unit of note ownership in one maturity. Values are shown next to shares in views
Oracle durationsu32numberoracle_max_age in seconds. grace is a u64 decimal string in nanoseconds ("3600000000000" = 1 hour)
Token IDsStringstringNEAR Intents asset ID, e.g. nep141:arb.omft.near. See Asset IDs
AccountsAccountIdstringAn EVM wallet is the implicit account of its address in lowercase, e.g. 0x2222222222222222222222222222222222222222. A NEAR wallet is its NEAR account, e.g. alice.near. The contract treats both alike
warning

NEAR account IDs are lowercase. A checksummed (mixed-case) EVM address is not a valid account ID: in a msg field such as borrower it fails to parse and the whole action is rejected with Invalid msg. Lowercase the address first.

Numbers that can exceed 2^53 (u64, u128) are always strings; small integers (u32, u8) are plain JSON numbers. A u64 or u128 field written as a JSON number fails to parse.

Assets on mainnet​

RoleAsset IDDecimals
Debt token (USDC, native on NEAR)nep141:17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a16
Collateral: ETH from Arbitrumnep141:arb.omft.near18
Collateral: ETH from Basenep141:base.omft.near18
Collateral: NEAR (wrapped)nep141:wrap.near24

get_config and get_collateral_tokens return the live list. Examples on these pages use the debt token's full asset ID or shorten it only where noted.

The msg format​

Both mt_on_transfer and on_auth take a msg string. It is a JSON object serialized into a string, tagged by action:

{"action": "<snake_case action name>", "data": { ...fields of that action... }}

In Rust this is #[serde(tag = "action", content = "data", rename_all = "snake_case")], the same tagging as the official escrow-swap contract. Because msg is itself a string inside the intent JSON, its quotes are escaped there:

{
"intent": "transfer",
"receiver_id": "setllend.near",
"tokens": {"nep141:17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1": "1000000000"},
"msg": "{\"action\":\"lend\",\"data\":{\"maturity\":\"1795766400000000000\",\"min_rate_bps\":700,\"expires_at\":null}}"
}

Optional fields (expires_at, borrower, the value of redeem, the amount of withdraw) may be null or left out. Unknown actions, missing required fields, and wrong types all fail with Invalid msg.

Entry pointActions
mt_on_transferlend, borrow, add_collateral, repay, liquidate
on_authborrow, cancel, sell_note, withdraw_collateral, redeem, withdraw

borrow exists on both: as a transfer it escrows new collateral, as an auth call it borrows against collateral the loan already holds.

Storage and fees​

Users never attach NEAR to Setllend. The contract pays the storage of orders, loans, notes, and free balances from its own NEAR balance, and frees it when an entry closes. Setllend charges no fee of its own. See Gas and storage.