Voltar para Documentação

Docs Técnicas

Credit Products

TREA includes several credit contracts that share the same core idea: the contract stores the product lifecycle, while ledger posting helpers describe the economic event.

O conteúdo abaixo vem das fontes técnicas do repositório e é prerenderizado no site para leitura direta por pessoas, crawlers e agentes.

TREA includes several credit contracts that share the same core idea: the contract stores the product lifecycle, while ledger posting helpers describe the economic event.

Simple Loan

SimpleLoan is the minimal bilateral lifecycle: originate, repay, and declare default. It is documented in the contract library as a compact example of composition with Roles.

Use it when the product is intentionally direct: one lender, one borrower, and a simple outstanding amount.

See Simple Loan.

TermLoan

std.credit.TermLoan models a fixed-term loan with partial amortization and interest accrual.

Important entrypoints:

python
@tx
def originate(lender, borrower, amount, rate_ppm, term_end)

@tx
def amortize(amount)

@tx
def accrue_interest(amount)

originate posts loan origination lines and credits principal_due: Balance[PRINCIPAL]. amortize debits that balance and posts repayment lines. accrue_interest posts accrual lines and increases the tracked principal due.

The borrower-facing wallet view is balanceOf(borrower), which returns the current outstanding amount.

RevolvingCredit

std.credit.RevolvingCredit models a reusable credit line.

python
@tx
def open(lender, borrower, credit_limit)

@tx
def draw(amount)

@tx
def repay(amount)

@view
def available_credit() -> u128

Draws must stay within credit_limit. Repayments reduce outstanding: Balance[CREDIT]. The invariant outstanding_within_limit captures the main safety property.

Use it for working-capital lines or card-like credit facilities where the borrower repeatedly draws and repays without originating a new contract each time.

ReceivableContract

std.credit.ReceivableContract tracks accounts receivable: recognize, settle, or write off.

python
@tx
def recognize(originator, debtor, amount)

@tx
def settle(amount)

@tx
def write_off(amount)

Receivables use explicit posting lines under the generic operation kind, so the ledger can distinguish recognition, cash settlement, and bad-debt write-off without inventing an off-chain convention.

Receipts

The credit stdlib emits ProductReceipt events for loan and credit lifecycle steps. These are designed for wallets, explorers, and pre-deploy simulations: users should see "loan originated", "draw executed", or "repayment posted", not just an opaque contract call hash.