description |
---|
This page explains how intents and solving works within the Anoma protocol. |
Intents, which are unbalanced transactions, can be become balanced transactions through composition with matching intents by other counterparties.
Anoma users submit their intents to an intent pool in the form of unbalanced transactions, which are received and processed by solvers that output balanced transactions. These transactions are then ordered and finally sent to the executor node, which verifies and executes the transactions in the determined order, updating the state.
Below, we show examples of a balanced transaction that can directly be executed and two flavors of intents (unbalanced transactions) requiring counterparty discovery.
{% hint style="info" %} Legend
- Symbols, e.g., 🍏 , indicate resource objects of specific kind that can contain arbitrary data and logic.
- Numbers Preceeding numbers, e.g., 4🍏 indicate the quantity of resources.
- Names following a resource, e.g., 4🍏 Alice , indicate who is authorized to consume it.
- Blue coloring indicates ephemeral resources.
- Speech bubbles 💬 indicate ephemeral intent resources expressing constraints over the transaction. {% endhint %}
{% tabs %} {% tab title="Basic Intent" %} Alice and Bob own apple 🍏 and banana 🍌 resources. Both want to swap their fruits and know exactly what they want. Both don't need to know each other.
"I want to give 3🍏 for 2🍌."
Consume | Create |
---|---|
3🍏 Alice | 2🍌 Alice |
"I want to give 2🍌 for 3🍏."
Consume | Create |
---|---|
2🍌 Bob | 3🍏 Bob |
Anyone seeing the two transactions (including Alice and Bob themselves) can compose the unbalanced transactions to obtain a balanced transaction containing two actions.
Consume | Create |
---|---|
3🍏 Alice | 2🍌 Alice |
// Action Separator
2🍌 Bob | 3🍏 Bob |
---|
After execution,
- Alice has swapped her 3🍏 Alice resource for a 2🍌 Alice resource,
- Bob has swapped his 2🍌 Bob for a 3🍏 Bob resource.
This outcome is equivalent to two balanced transactions (see the previous tab) where both, Alice and Bob, transfer resources to one another. {% endtab %}
{% tab title="Advanced Intent & Solution" %} Alice and Bob own apple 🍏 and banana 🍌 resources. Both want to swap some of their fruits within specific constraints. Both don't know each other.
Both, Alice and Bob express their intents over the preferred state transition as ephemeral intent resources 💬 to solver Sally.
"Sally, I want to give exactly 4🍏 for at least 4🍌."
Consume | Create |
---|---|
4🍏 Alice | 1💬 Sally, give = 4🍏 Alice, want ≥ 4🍌 Alice |
"Sally, I want to give at most 7🍌 for exactly 3🍏."
Consume | Create |
---|---|
7🍌 Bob | 1💬 Sally, give ≤ 7🍌 Bob, want = 3🍏 Bob |
Seeing both intents in the intent pool, Sally comes up with a solution for the two intents:
"I'll give 3🍏 to Bob and take 1🍏 for myself as a fee. Furthermore, I'll give 5🍌 to Alice, return 1🍌 to Bob, and take 1🍌 for myself as a fee."
Consume | Create |
---|---|
1💬 Sally, give = 4🍏 Alice, want ≥ 4🍌 Alice | 3🍏 Bob |
1💬 Sally, give ≤ 7🍌 Bob, want = 3🍏 Bob | 1🍏 Sally |
5🍌 Alice | |
1🍌 Bob | |
1🍌 Sally |
Sally composes her solution intent with Alice's and Bob's intents and obtains a balanced transaction containing three actions.
Consume | Create |
---|---|
4🍏 Alice | 1💬 Sally, give = 4🍏 Alice, want ≥ 4🍌 Alice |
{% code fullWidth="true" %}
// Action Separator
{% endcode %}
Consume | Create |
---|---|
7🍌 Bob | 1💬 Sally, give ≤ 7🍌 Bob, want = 3🍏 Bob |
// Action Separator
Consume | Create |
---|---|
1💬 Sally, give = 4🍏 Alice, want ≥ 4🍌 Alice | 3🍏 Bob |
1💬 Sally, give ≤ 7🍌 Bob, want = 3🍏 Bob | 1🍏 Sally |
5🍌 Alice | |
1🍌 Bob | |
1🍌 Sally |
After execution,
- Alice gave her 4🍏 and got 5🍌 , more than the least amount she specified,
- Bob gave 6🍌 and has 1🍌 left, less than the maximal amount he specified, and got the 3🍏 apples he wanted,
- Sally took 1🍏 and 1🍌 for her services. If she is taking too much for herself, users might decide to not let her settle their intents anymore (see the Slow Games ART). {% endtab %} {% endtabs %}