The Intent gossip and Matchmaker

To run an intent gossip node with an RPC server:

anoma node gossip --rpc ""

To run an intent gossip node with the intent gossip system, a token exchange matchmaker and RPC through which new intents are requested:

anoma node gossip --rpc "" --matchmaker-path wasm/mm_token_exch.wasm --tx-code-path wasm/tx_from_intent.wasm --ledger-address "" --source matchmaker --signing-key matchmaker

Mind that matchmaker should be valid key in your wallet.

This pre-built matchmaker implementation is the fungible token exchange mm_token_exch, that is being used together with the pre-built tx_from_intent transaction WASM to submit transaction from matched intents to the ledger.

✋ Example intents

  1. Lets create some accounts:

    anoma wallet key gen --alias alberto --unsafe-dont-encrypt
    anoma client init-account --alias alberto-account --public-key alberto --source alberto
    anoma wallet  key gen --alias christel --unsafe-dont-encrypt
    anoma client init-account --alias christel-account --public-key christel --source christel
    anoma wallet key gen --alias bertha --unsafe-dont-encrypt
    anoma client init-account --alias bertha-account --public-key bertha --source bertha
    anoma wallet key gen --alias my-matchmaker --unsafe-dont-encrypt
    anoma client init-account --alias my-matchmaker-account --public-key my-matchmaker --source my-matchmaker
  2. We then need some tokens:

    anoma client transfer --source faucet --target alberto-account --signer alberto-account --token BTC --amount 1000
    anoma client transfer --source faucet --target bertha-account --signer bertha-account --token ETH --amount 1000
    anoma client transfer --source faucet --target christel-account --signer christel-account --token XAN --amount 1000
  3. Lets export some variables:

    export ALBERTO=$(anoma wallet address find --alias alberto-account | cut -c 28- | tr -d '\n')
    export CHRISTEL=$(anoma wallet address find --alias christel-account | cut -c 28- | tr -d '\n')
    export BERTHA=$(anoma wallet address find --alias bertha-account | cut -c 28- | tr -d '\n')
    export XAN=$(anoma wallet address find --alias XAN | cut -c 28- | tr -d '\n')
    export BTC=$(anoma wallet address find --alias BTC | cut -c 28- | tr -d '\n')
    export ETH=$(anoma wallet address find --alias ETH | cut -c 28- | tr -d '\n')
  4. Create files with the intents description:

    echo '[{"addr":"'$ALBERTO'","key":"'$ALBERTO'","max_sell":"70","min_buy":"100","rate_min":"2","token_buy":"'$XAN'","token_sell":"'$BTC'","vp_path": "wasm_for_tests/vp_always_true.wasm"}]' >
    echo '[{"addr":"'$BERTHA'","key":"'$BERTHA'","max_sell":"300","min_buy":"50","rate_min":"0.7","token_buy":"'$BTC'","token_sell":"'$ETH'"}]' >
    echo '[{"addr":"'$CHRISTEL'","key":"'$CHRISTEL'","max_sell":"200","min_buy":"20","rate_min":"0.5","token_buy":"'$ETH'","token_sell":"'$XAN'"}]' >
  5. Start the ledger and the matchmaker. Instruct the matchmaker to subscribe to a topic "asset_v1":

    anoma node ledger run
    anoma node gossip --rpc "" --matchmaker-path wasm/mm_token_exch.wasm --tx-code-path wasm/tx_from_intent.wasm --ledger-address "" --source mm-1 --signing-key mm-1
    anoma client subscribe-topic --node "" --topic "asset_v1"
  6. Submit the intents (the target gossip node must be running an RPC server):

    anoma client intent --data-path --topic "asset_v1" --signing-key alberto --node ""
    anoma client intent --data-path --topic "asset_v1" --signing-key bertha --node ""
    anoma client intent --data-path --topic "asset_v1" --signing-key christel --node ""

    The matchmaker should find a match from these intents and submit a transaction to the ledger that performs the n-party transfers of tokens.

  7. You can check the balances with:

    anoma client balance --owner alberto-account
    anoma client balance --owner bertha-account
    anoma client balance --owner christel-account

🤝 Custom matchmaker

A custom matchmaker code can be built from wasm/mm_template.

A matchmaker code must contain the following function, which will be called when a new intent is received:

fn main() {
use anoma_vm_env::matchmaker_prelude::*;

fn add_intent(last_state: Vec<u8>, intent_id: Vec<u8>, intent_data: Vec<u8>) -> bool {
  // Returns a result of processing the intent

The matchmaker can keep some state between its runs. The state can be updated from within the matchmaker code with update_state function and received from the last_state argument.

To find out about the interface available in a matchmaker and the library code used in the mm_token_exch implementation, please check out Rust docs for matchmaker_prelude.