Build action plans
Translate a standard borrower action into bounded calls and verified receipts.
On this page
Action context
build receives the read context plus borrower, action and the registered market. Termbook also supplies minimum_receive or maximum_spend when the action needs price protection. A builder must reject unsupported directions, sizing and order types.
| Input | Purpose |
|---|---|
| action.params | Standard user inputs; no arbitrary calldata. |
| market | The registered assets, address and decimal scales. |
| minimum_receive | Minimum output for spend-sized actions. |
| maximum_spend | Maximum input for receive-sized actions. |
| position_state | Bound position identity, market and direction where needed. |
Returned plan
{
calls: [{
target: approved_router,
data: encoded_trade,
value: 0n,
spend_asset: usdc,
spend_amount: 100_000n,
}],
spending: [{ asset: usdc, maximum: 100_000n }],
receiving: [{
asset: native_mon,
minimum: protected_minimum,
controlled_by: context.account,
}],
completion: { kind: "atomic" },
}Calls execute from the Credit Account. spending is the exact aggregate budget per input asset; receiving records the output asset, minimum receipt and controlling account. A plan supports at most eight calls. Calls and budgets must match the registered definition.
Native assets & funding
For native MON, set call.value to the actual MON amount, use the zero address in spending, and set spend_amount to zero. Native value and ERC-20 allowance spending are counted separately. Do not declare the same native amount in both fields.
fundingPath in a capability definition declares how much settlement-asset credit the action needs. spendPath or valuePath declares what the account spends. A sell can spend MON already owned by the account without drawing more USDC.
Asynchronous actions
completion: {
kind: "pending",
deadline: expires_at,
tracking: {
target: market_address,
event: "OrderSettled(bytes32,uint256,uint256)",
},
}The tracking event above illustrates the format; use the app’s actual ABI event. Pending actions must declare and reconcile committed funds, fills, refunds, remaining amounts and liabilities. A successful transaction receipt alone is not a filled order.
Validate the plan
import { check_plan } from "@termbook/sdk";
const plan = await exchange.actions.place_order.build(context);
return check_plan(exchange.definition, context.action, plan, context);The SDK reconstructs the admitted execution and compares target, calldata, native value and spending. Shared onchain policies verify the allowed call and result during execution. The post-action risk check remains mandatory.