Contract post-conditions

Source: SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.xbtc-sbtc-swap-v2arrow-up-right

Description

The as-contract? function resolves the expression caller to the principal of the current contract. Most importantly it allows a contract to protect its own assets during the execution of the expression with a set of specified allowances.

Use Cases

  • A contract invoking a body expression that potentially may have unwanted and unexpected asset transfers.

  • Protecting a contract invoking another external contract's function.

Key Concepts

  • Contract caller context - Switches the current context's tx-sender and contract-caller values to the contract's principal and executes the body expressions within that context, then checks the asset outflows from the contract against the granted allowances, in declaration order.

  • Clarity post-conditions - Accepts a set of allowances, defined using with-stx, with-ft, with-nft, and with-stacking, which selectively grant outflow allowances from the contract's assets.

Last updated

Was this helpful?