Concepts
Promises and checks
The three kinds of check and how to write each one.
A promise is a list of checks. They are read by End against the snapshot. Each check names a watched entry by its position in the list you gave Begin (0 is always your wallet).
SOL
sol(entry, min): the lamports of that account must have moved by at least min (a signed number: negative means "may lose at most").
| You want | Write |
|---|---|
| "I may spend 0.05 SOL" | sol(0, -50_000_000) |
| "My SOL must not go down" | sol(0, 0) (or nothing, it is the default) |
| "I expect to receive 0.5 SOL" | sol(0, 500_000_000) |
The network fee is paid before the program runs, so it is not part of the promise. Rent for an account you create is: declare it.
Token
token(entry, min): the amount in that token account moved by at least min, in the token's smallest unit.
Delegate
delegate(entry, cap): that token account may end with a delegate that can spend at most cap tokens. Without this check, a new delegate (or a bigger one) is refused. An old delegate that does not change is not a new risk, and clearing a delegate is always fine.
Choosing numbers
- Receive checks: the quote minus a tolerance. 1 % for a liquid pool.
- Spend checks: exactly what you intend to spend.
- Delegate: usually nothing. If an app really needs one, cap it to the amount it needs.
The entry numbers refer to the order of your watched list, at most ten accounts.