Voltar para Documentação

Docs Técnicas

Intrinsics

Intrinsics are built-in functions known to the verifier and runtime.

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

Intrinsics are built-in functions known to the verifier and runtime.

Guards

python
require(condition, "error_label")
assert(condition, "error_label")
fail("error_label")
fail("error_label", "message")

Use require(...) for preconditions.

Events

python
emit LoanRequested(lender, ctx.caller, principal, rate_ppm)

Events are emitted only if execution succeeds.

Movement

python
send(amount, from, to)

Use send(...) for generic value transfer. It lowers to canonical available plus EQ3_4 residual lines. Use post(...) when the accounting reason matters.

Posting

python
post(lines_generator(asset, operation_kind, line1, ...))
line_generator(owner, bucket, op, amount)
lines_generator(asset, operation_kind, line1, ...)

Corrections

python
reverse(source_tx_id, asset, operation_kind?, line1, ...)
reversal(source_tx_id, asset, operation_kind?, line1, ...)
counterpost(source_tx_id, asset, operation_kind?, line1, ...)
reclassify(source_tx_id, asset, line1, line2)

Product Helpers

Product helpers return validated posting plans and are preferred over raw post(lines_generator(...)) for product flows.

loan

python
loan.accrue_interest(principal, rate_ppm, from_ts, to_ts) -> u128
loan.origination_lines(asset, lender, borrower, amount)
loan.accrual_lines(asset, lender, borrower, amount)
loan.repayment_lines(asset, lender, borrower, amount)

fees

python
fees.charge_lines(asset, payer, recipient, amount)
fees.accrual_lines(asset, payer, recipient, amount)
fees.settlement_lines(asset, payer, recipient, amount)

yield

python
yield.accrue_interest(principal, rate_ppm, from_ts, to_ts) -> u128
yield.accrual_lines(asset, issuer, holder, amount)
yield.realization_lines(asset, issuer, holder, amount)

installments

python
installments.schedule_lines(asset, servicer, obligor, amount)
installments.payment_lines(asset, servicer, obligor, amount)

fx

python
fx.conversion_lines(asset, from_party, to_party, amount)

Call twice for a full FX round-trip, once per currency leg.

insurance

python
insurance.premium_lines(asset, insured, insurer, amount)
insurance.reserve_lines(asset, insurer, amount)
insurance.payout_lines(asset, insurer, beneficiary, amount)

provisioning_loss

python
provisioning_loss.provision_lines(asset, institution, counterparty, amount)
provisioning_loss.writeoff_lines(asset, institution, counterparty, amount)
provisioning_loss.recovery_lines(asset, institution, counterparty, amount)

nfa

python
nfa.transfer_lines(asset, from_holder, to_holder, amount)
nfa.encumber_lines(asset, holder, amount)
nfa.release_lines(asset, holder, amount)

Collection Stdlib

Collection functions are pure. They never mutate in place. Always assign the return value back to storage.

vec

python
vec_push(vec, item)       # new Vec with item appended
vec_pop(vec)              # new Vec with last item removed
vec_len(vec) -> u64
vec_get(vec, idx)         # element at index; fails if out of bounds
vec_contains(vec, item) -> bool
python
self.checkpoints = vec_push(self.checkpoints, block_ts)

map

python
map_get(map, key)         # value for key, or type default if absent
map_set(map, key, value)  # new Map with key set
map_remove(map, key)      # new Map with key removed
map_contains(map, key) -> bool
map_len(map) -> u64
python
self.balances = map_set(self.balances, owner, new_amount)

The compiler rejects bare vec_push/vec_pop/map_set/map_remove as statements where the result is not assigned — a fatal error.

Financial Balance Helpers

Balance[T] storage fields are updated through tracked helpers:

python
credit(position, amount)
debit(position, amount)
amount_of(position) -> u128

credit and debit are statements. amount_of is read-only and can be used in views or guards. Raw u128 arithmetic is not recognized as money.

Context Vault

python
ctx.vault() -> Address

Returns the deterministic implicit vault address for the current contract instance. Use it when a contract needs to receive, hold, or release value without introducing a user-controlled burn address or a zero-address sentinel.

KYC Helpers

python
ctx.kyc_verified(account) -> bool
ctx.kyc_level(account) -> KycLevel
ctx.kyc_compat(account, schema) -> bool
ctx.kyc_verifier(account) -> Address
ctx.kyc_expires_at(account) -> u64

These read the deterministic ledger snapshot. They do not fetch private KYC evidence from the validator.

Spending Helpers

python
spending.verify_intent(card_pubkey, card_curve, vault_id, merchant,
                       token_id, amount, nonce, expires_at,
                       signed_intent) -> bool

Verifies the PaymentIntentV1 card signature used by SpendingVault, AuthorizedSpendingVault, and CreditCardVault.

Factory Helpers

python
derive_child_id(template_id, requester, salt) -> Address

Derives a deterministic child contract id (contract:<hex16>) for ProductTemplate flows.