Write Rego policies for Newton Protocol transaction authorization
A Newton policy is a Rego program that evaluates whether an Intent should be approved. Policies reference data from two sources: configuration parameters (data.params) and runtime data from WASM oracles (data.data).
package sanctions_checkdefault allow := false# Allow the transaction if the oracle reports no sanctions matchallow if { data.data.is_sanctioned == false}# Also allow if the sender is on the explicit allowlistallow if { input.from == data.params.admin}
This policy:
Defaults to deny (allow := false)
Allows transactions where the oracle reports no sanctions match
Always allows transactions from the configured admin address
package spend_limitdefault allow := false# Allow if transfer value is under the configured limitallow if { input.value <= data.params.max_value}# Block transfers to specific addressesdeny if { input.to == data.params.blocked_address}allow if { not deny input.chain_id == 11155111}
The data.data path contains whatever your WASM oracle returned:
Copy
Ask AI
package price_checkdefault allow := false# Only allow trades when the price is below the configured maximumallow if { data.data.price < data.params.max_price data.data.symbol == "BTC"}