Auto-Swap
OKB -> USDG funding after policy gate
Auto-swap lets an agent pay USDG-settled x402 services when wallet balance is in OKB.
The swap is strictly a funding step: ZenithPay never swaps before SpendPolicy.sol approves the payment.
Auto-swap (funding mechanism)
Auto-swap exists to help agents pay services that require USDG when the agent has insufficient USDG but enough OKB.
Key rule: policy first, never swap first
ZenithPay always checks SpendPolicy.sol for the settlement-token-denominated maxAmount before any swap happens.
If policy fails, the payment is rejected immediately (status: "blocked"). If the payment is above the human review threshold, it is paused for approval (status: "pending"). No swap occurs in either case.
When swap happens
Swap is only attempted if USDG is insufficient to cover the requested payment amount.
Correct execution order (pay service)
- SpendPolicy check (settlement token amount)
- USDG balance check
- If needed:
swap_quote->swap_approve->swap_swapfor the exact required USDG - x402
/verify->/settle
Why exact amount matters
ZenithPay approves only what it needs for the payment, so slippage cannot accidentally push spending above the policy-gated cap.