Manage a Credit
Read state, execute reviewed actions, repay and close through the resource API.
On this page
Read the facility
const credit = termbook.credit(credit_id);
const summary = await credit.summary();
const health = await credit.account.health();
const positions = await credit.app.positions();
const pending = await credit.app.pending();
const unsubscribe = credit.subscribe((events) => {
render_activity(events);
});
// Call unsubscribe when the view is removed.summary reports facility state, debt, limit, revision and account. health reports the current debt and risk state. Account balances reads the House settlement token; use the integration’s account reader for the complete app portfolio.
Review & execute
const review = await credit.app.review(action);
if (!review.canExecute) throw new Error(review.healthState);
const result = await credit.app.execute(action, review);
if (result.status !== "settled") {
show_action_outcome(result);
}The review includes required input, spending, free assets, required draw, projected debt and projected health. Execution still checks the current authorized state; a prior review is not a guarantee of acceptance.
Repay
const payment = await credit.repay({
amount: "max",
from: "credit_account",
});
console.log(payment.status, payment.applied, payment.remaining);from can be credit_account, wallet or aurora_intents. Remote payments also need an admitted source route and bounded source/refund configuration. applied is the actual amount allocated; remaining is outstanding debt. Do not treat partial or pending as fully repaid.
Close the facility
await credit.close({ mode: "unwind" });Closure coordinates the approved app exit, repayment, surplus handling, account release and source-collateral return. No preceding sell or repay call is required. Retain mode is available only when the integration and accepted terms allow it, with debt funded through an approved source.
Collateral & withdrawals
await credit.collateral.add({ amount: collateral_amount });
await credit.collateral.withdraw({ amount: withdrawal_amount });
await credit.account.withdraw({
asset: settlement_asset,
amount: profit_amount,
});Collateral top-ups change source collateral; they are distinct from app margin. Source withdrawals require safe reservation and proof confirmation. Account withdrawals are restricted to authorized cash and the borrower recipient, with debt, pending exposure and health checks.