Voltar para Documentação

Docs Técnicas

Accounting Effects

TREA separates business state from ledger accounting.

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 separates business state from ledger accounting.

Storage records business facts. Posting plans record economic meaning.

A successful local execution does not guarantee ledger commit.

The runtime checks effect shape and produces an execution result. The ledger then validates posting routes, lifecycle state, accepted version, and active policy constraints before commit.

`send(...)`

send(...) expresses generic value transfer.

python
send(amount, from, to)

It lowers to a canonical generic post:

python
post(lines_generator(ctx.asset, generic,
    line_generator(from, available, dec, amount),
    line_generator(from, EQ3_4, dec, amount),
    line_generator(to, available, inc, amount),
    line_generator(to, EQ3_4, inc, amount)))

Use it when the contract means "send value" and does not want to claim a more specific reason such as loan origination, fee recognition, accrual, or reclassification. For those cases, use post(...).

`post(...)`

post(...) expresses journal-shaped accounting intent.

python
post(lines_generator(ctx.asset, loan_origination,
    line_generator(self.lender, available, dec, amount),
    line_generator(self.borrower, available, inc, amount),
    line_generator(self.lender, receivable_long, inc, amount),
    line_generator(self.borrower, payable_long, inc, amount)))

The second argument to lines_generator is an operation kind identifier — an unquoted symbolic name chosen from the catalog below. The third argument onwards are line_generator(owner, bucket, op, amount) calls, where bucket and op are also unquoted identifiers.

All arguments to lines_generator and line_generator must appear on a single line (the TREA parser does not support multi-line call arguments).

Operation Kind Catalog

The full list of supported operation kinds. Pass as an unquoted identifier to lines_generator.

| Kind | Description | Typical Debit | Typical Credit | Intrinsic | | ---- | ----------- | ------------- | -------------- | --------- | | generic | General-purpose value transfer with no specific economic classification. | available | available | send | | loan_origination | Loan disbursement: lender available decreases, borrower available increases, receivable and payable obligations opened. | available (lender) | A1_2_1 / L2_2_1 | loan.origination_lines | | loan_accrual | Interest accrual: lender receivable and borrower payable increase by the accrued interest amount. No cash movement. | A1_2_1 (lender) | L2_2_1 (borrower) | loan.accrual_lines | | loan_repayment | Principal repayment: borrower available decreases, lender available increases, receivable and payable obligations closed. | available (borrower) | A1_2_1 / L2_2_1 | loan.repayment_lines | | reversal | Full reversal of a prior posting: mirror-image lines sourced to the original transaction id. | same as original (reversed) | same as original (reversed) | reverse / reversal | | counterpost | Partial correction via offsetting lines on the same accounts without cancelling the original transaction. | varies | varies | counterpost | | reclassification | Move balance between buckets on the same account — e.g. from receivable_long to available — without cash movement. | source bucket | target bucket | reclassify | | fee_charge | Direct fee debit from payer available to payee available. | available (payer) | available (payee) | fees.charge_lines | | fee_accrual | Fee obligation accrual: payable recognition before cash settlement. | receivable_short | payable_short | fees.accrual_lines | | fee_settlement | Settle an accrued fee: cash payment clears the payable/receivable. | available | receivable_short / payable_short | fees.settlement_lines | | yield_accrual | Yield entitlement accrual: investor receivable increases, issuer payable increases. | receivable_long | payable_long | yield.accrual_lines | | yield_realization | Yield cash settlement: cash paid from issuer to investor, entitlement cleared. | available (issuer) | receivable_long / payable_long | yield.realization_lines | | installment_schedule | Installment obligation creation: scheduled payment obligation recognized. | receivable_short | payable_short | installments.schedule_lines | | installment_payment | Installment payment: cash received, scheduled obligation cleared. | available | receivable_short / payable_short | installments.payment_lines | | fx_conversion | FX conversion: source asset available decreases, target asset available increases, with optional spread separated. | available (source asset) | available (target asset) | fx.conversion_lines | | insurance_premium | Premium payment from insured to insurer. | available (insured) | available (insurer) | insurance.premium_lines | | insurance_reserve | Insurer locks available into a reserve to back potential claims. | available (insurer) | payable reserve | insurance.reserve_lines | | insurance_payout | Claim payout: insurer releases reserve to beneficiary. | payable reserve | available (beneficiary) | insurance.payout_lines | | loss_provision | Loss provision: reduce receivable and counterparty payable by impaired amount. | A1_2_1 dec | L2_2_1 dec | provisioning_loss.provision_lines | | loss_write_off | Write-off: permanent loss recognition, receivable zeroed. | A1_2_1 dec | L2_2_1 dec | provisioning_loss.writeoff_lines | | loss_recovery | Recovery: restore previously written-off receivable and payable. | A1_2_1 inc | L2_2_1 inc | provisioning_loss.recovery_lines | | nfa_transfer | Non-fungible asset title transfer between two parties. | available (from) | available (to) | nfa.transfer_lines | | nfa_encumber | NFA encumbrance: lock NFA available into a payable reserve. | available | payable reserve | nfa.encumber_lines | | nfa_release | NFA release: restore from payable reserve back to available. | payable reserve | available | nfa.release_lines |

> API: GET /api/contracts/operation-kinds returns this catalog at runtime as JSON, including descriptions and typical bucket routes.

Bucket Aliases

Safe aliases accepted as bucket identifiers in line_generator:

text
available
receivable_short
receivable_long
payable_short
payable_long

Raw bucket codes also accepted:

text
A1_1_1
A1_1_2
A1_2_1
EQ3_4
L2_1_1
L2_2_1

Ledger Validation

The runtime checks shape. The ledger still validates posting routes against chart and AllowedEdge policy.

A contract can compile and execute locally but fail at ledger commit if it tries an unsupported accounting route.

Standard Library Templates

The TREA standard library ships three credit contract templates that demonstrate canonical posting patterns for common financial instruments.

`std.credit.LoanContract`

Term loan with origination, accrual, and repayment via loan.* intrinsics.

python
contract LoanContract:
    # ...
    @tx
    def originate(lender: Address, borrower: Address, amount: u128, rate_ppm: u128):
        # ...
        post(loan.origination_lines(ctx.asset, lender, borrower, amount))

    @tx
    def accrue():
        let interest = loan.accrue_interest(self.principal_due, self.rate_ppm, self.last_accrual_ts, ctx.block_timestamp)
        post(loan.accrual_lines(ctx.asset, self.lender, self.borrower, interest))

    @tx
    def repay(amount: u128):
        post(loan.repayment_lines(ctx.asset, self.lender, self.borrower, amount))

`std.credit.TradeSettlement`

Bilateral trade: propose → settle (cash) or cancel.

python
contract TradeSettlement:
    @tx
    def propose(counterparty: Address, amount: u128): ...
    @tx
    def settle():
        send(self.amount, self.initiator, self.counterparty)
    @tx
    def cancel(): ...

`std.credit.ReceivableContract`

Receivable lifecycle: recognize obligation, settle in cash, or write off.

python
contract ReceivableContract:
    @tx
    def recognize(creditor: Address, debtor: Address, amount: u128):
        post(lines_generator(ctx.asset, generic, line_generator(creditor, A1_2_1, inc, amount), line_generator(debtor, L2_2_1, inc, amount)))

    @tx
    def settle(amount: u128):
        post(lines_generator(ctx.asset, generic, line_generator(self.debtor, available, dec, amount), line_generator(self.creditor, available, inc, amount), line_generator(self.creditor, A1_2_1, dec, amount), line_generator(self.debtor, L2_2_1, dec, amount)))

    @tx
    def write_off(amount: u128):
        post(lines_generator(ctx.asset, generic, line_generator(self.creditor, A1_2_1, dec, amount), line_generator(self.debtor, L2_2_1, dec, amount)))