trusset.lending.loans covers the life of a loan. The borrower pledges security tokens, draws the settlement token (stablecoin), adds or withdraws collateral, draws more, repays and closes. Every write follows the signing model: no options prepares the plan, { signer } signs and confirms, { txHash } confirms a transaction you broadcast yourself.
Repayment and release never need a price. A repayment sent without a signedPrice reads no price, so neither a stale price nor a paused market blocks it. Closing a debt-free loan moves no money and reads no price, and a debt-free withdrawal is never refused for a stale price. A stale price blocks new borrowing, additional draws and withdrawals from a loan that still carries debt.
How the collateral is held depends on the market’s mode. FREEZE, the reference model, freezes the tokens in the borrower’s own wallet, so they never move during a healthy loan. CUSTODY moves them into the market’s adapter for the loan term. It exists for tokens without the ERC-3643 agent functions, is a different construction from a pledge in place, and sits outside the reference configuration.
Open a loan
The borrower signs every step. On aCUSTODY market the plan is an approval on the collateral token, then openLoan. A FREEZE market needs no approval, so the plan is openLoan alone. With { signer } the SDK fills borrowerAddress from the signer and refuses a different one.
collateralAmount is in the collateral token’s units and borrowAmount in the settlement token’s, both as decimal strings. When the API sends no gas limit, as for openLoan today, the SDK sets one at 1.5 times the signer’s own estimate. A market that charges an opening fee pays out the borrow amount less the fee, and the loan owes the full amount.
To recover from the warning above, confirm with the hash the error carries:
Show the terms before the borrower signs
The terms of a loan appear only on the prepared plan.offering carries the due date, the grace period and any stamped fixed rate, transactionFee the opening fee, and warnings the preflight findings that do not block the loan. Quote the borrowing limit first with markets.maxBorrow.
borrowerAddress is required: every collateral, identity and cap check runs against it. Calling open again with { signer: borrower } builds the plan afresh. To sign the prepared plan in your own infrastructure instead, broadcast steps in order and confirm with the hash of the step at confirmStepIndex.
Every warning carries enforcement: 'OFF_CHAIN'. The contract does not know about them, so acting on one is the lender of record’s decision.
Attribute the loan to a client
clientReference names the client the loan is for: a customer’s referenceKey, externalId or customer ID on your instance. The API refuses an ineligible client with CLIENT_NOT_ELIGIBLE before anything is signed. With { signer } the SDK sends the reference on both legs, so the confirm records the attribution.
Pay the proceeds to another wallet
payToAddress sends the borrowed amount to a wallet other than the borrower. The borrower stays the borrower of record: it owes the debt and receives every collateral return and any liquidation surplus.
PAY_TO_UNSUPPORTED. A payee that is one of the market’s own contracts answers PAY_TO_NOT_ALLOWED.
Add collateral
Adding collateral raises the health factor without repaying debt, which is the fastest way to move a loan away from liquidation. Only the borrower can sign. ACUSTODY market adds an approval step first, and a paused market does not block it.
USER_SUPPLY_CAP_EXCEEDED or SUPPLY_CAP_EXCEEDED. While a Dutch auction is open against the loan, the contract reverts the top-up, and the API does not check for one first.
Borrow more
Draws more of the settlement token against the same collateral. Only the borrower can sign, and the draw moves the loan closer to its liquidation threshold. Read the resulting health factor fromgetByLoanId afterwards.
FIXED_RATE_LOAN: open a new loan at current terms instead. The opening fee applies to every draw. A loan opened with a payee pays every draw to that payee.
On a stale price the draw reverts unless it carries a fresh signedPrice. The price signer produces one with oracle.signPrice, and open and withdrawCollateral take it the same way.
Withdraw collateral
WOULD_BREACH_HEALTH_FACTOR. That bound is stricter than the contract’s, which measures at the liquidation threshold. FREEZE markets unfreeze the released tokens in place, and CUSTODY markets transfer them back to the borrower.
Repay a loan
Any wallet can repay any loan. A third party can rescue a loan approaching liquidation, and an omnibus wallet can pay for its client. The collateral always returns to the borrower, never to the payer. With{ signer } the SDK fills payer from the signer, so the allowance and the plan are checked from the wallet that pays.
all: true:
close call follows it. loanClosed is true when the loan is closed, false while it is open, and null when it could not be read. When a full repayment still left debt open, remainder.offerRepayRemainder is true: repay again with all: true, which is sized afresh.
Choose a mode
In
sequential and permit mode the clearing step after a full repayment is optional. It resets the payer’s whole allowance for the market to zero, including allowance it keeps there for other loans. If it fails or is rejected, the repayment still confirms, and transactions reports the step with its error.
The repay step carries a gas limit from the API, which the SDK forwards unchanged. It is the gas the simulated repayment used plus 50 percent, with a floor.
Repay with a permit
The permit path exists only where the settlement token implements EIP-2612, whichpermitSupported on a prepared plan reports. The payer must be a wallet without contract code, and it sends the transaction itself, because the market redeems the permit for its sender.
permit.value is the amount the permit covers, forecast breaks a full repayment into debt, forecast interest and fee, and description states it in words.
deadlineSeconds sets how long the permit stays valid, from 300 to 1800 seconds, and defaults to 1800. A permit that lapsed while the payer reviewed it is refused with INVALID_PERMIT: quote again and sign the new one. A multisig or smart account repays with sequential or batch instead and answers PERMIT_REQUIRES_EOA here.
Repay in one wallet bundle
batch is for a payer’s wallet that supports atomic batching with wallet_sendCalls. Prepare the plan with the payer named, send every step that is not in optionalStepIndexes as one bundle, then confirm with the hash of the bundle’s transaction. The bundle ends with an approval to zero, so nothing stays approved.
all or amount the plan was built with:
TX_WRONG_TARGET. On every mode, walletPrompts.label and walletPrompts.why say what the wallet will ask for and why. Show both before the first signature.
Close a debt-free loan
Closing releases the collateral of a loan whose debt is zero. Only the borrower can sign, and closing moves no settlement money and charges no fee. A loan repaid withall: true is already closed and answers LOAN_ALREADY_CLOSED.
DEBT_OUTSTANDING, and the message states the exact remainder. Repay it with all: true, which closes the loan itself.
Reclaim escrowed collateral and surplus
Two balances can wait for a borrower. Escrowed collateral is held by aCUSTODY market’s adapter in the collateral token, after a blocked return. A realization surplus is held by the market itself in the settlement token, after a liquidation paid out more than the debt plus its penalty and the payout was refused. Both are per holder and cover every loan of that address on the market.
{ signer } the SDK names the signer as holderAddress, and the API refuses a claim the token still blocks with COLLATERAL_TRANSFER_RESTRICTED instead of handing back a transaction that reverts. A FREEZE market never escrows collateral and answers NOT_CUSTODY_MODE.
claimable: true says a surplus exists, not that the claim will succeed. Unlike the collateral claim, the API does not check whether the settlement token would now accept the transfer.
Read loans and positions
A position is Trusset’s record of a loan. A loan is the market contract’s own state, keyed by its on-chainloanId.
compliance.restricted: null means the collateral token did not answer enough probes to establish its state. Treat it as unknown, never as unrestricted.
Download a loan statement
statement returns a PDF of one loan with its terms, every recorded movement and an audit trail checked against the chain. It comes back as bytes with the file name the API set.
