Solver Example
Start Web Socket Connection
Connect to the websocket-based Solver API.
Wait for Subintent Bundles
Anthic will send subintent bundles as soon as they are available.
{
"id": null,
"jsonrpc": "2.0",
"method": "new_subintent_bundle",
"params": [
"4d2103210221012105210607020a94ef0000000000000a96ef0000000000002200002200000a9bcde95acae5855320200022000020200107209b529edcd8f768182dc20d5b5bcb5968b6cf5adaa3b83272628f07428d27748b20220b610209000000002100000280005d62a3f5498520803a31ec9034c613e205f53100f5f7021b5e2d53d737ac850090c051f4cbcbe504000000000000000000000000000000600121018100000000020180005d32f3d22b24f7baa86e92e11f02b08676699846a6344735e9687b3dc5fb6102090000000021018101000000000280005d62a3f5498520803a31ec9034c613e205f53100f5f7021b5e2d53d737ac8500a06d9e32144801000000000000000000000000000000004103800051e40b09665d6aa3c8c9d4bcb4e4af712d5960b638efe78206591d5c7c190c076465706f7369742101810200000061020900000000210183004103800051e40b09665d6aa3c8c9d4bcb4e4af712d5960b638efe78206591d5c7c190c087769746864726177210280005da66318c6318c61f5a61b4c6318c6318cf794aa8d295f14e6318c6318c6850000b2d3595bf00600000000000000000000000000000000000280005da66318c6318c61f5a61b4c6318c6318cf794aa8d295f14e6318c6318c6850000b2d3595bf00600000000000000000000000000000000600121018103000000202101012105210607020a94ef0000000000000a96ef0000000000002200002201010508aa5c67000000000a000000000000000020200022000020200020220a6201220201220001220001220001210280009a4c6318c6318c6cb554820c6318c6318cf7a951d7a9e547c6318c6318c687021de40b09665d6aa3c8c9d4bcb4e4af712d5960b638efe78206591d5c7c19410380005109b94817ce100f25a0a35a42d78c253a40aa0f34b4b14b8a52bce956dd0c087769746864726177210280005d62a3f5498520803a31ec9034c613e205f53100f5f7021b5e2d53d737ac8500302ef026e013e704000000000000000000000000000000000280005d62a3f5498520803a31ec9034c613e205f53100f5f7021b5e2d53d737ac850090c051f4cbcbe5040000000000000000000000000000000a0123802201005d32f3d22b24f7baa86e92e11f02b08676699846a6344735e9687b3dc5fb02018500a044d2b0e0020000000000000000000000000000000000600121018100000000000280005d62a3f5498520803a31ec9034c613e205f53100f5f7021b5e2d53d737ac8500a0e05435f9400100000000000000000000000000000000000280005d62a3f5498520803a31ec9034c613e205f53100f5f7021b5e2d53d737ac8500008d49fd1a0700000000000000000000000000000000006001210281010000008102000000410380005109b94817ce100f25a0a35a42d78c253a40aa0f34b4b14b8a52bce956dd0c0d6465706f7369745f626174636821018300600121002022010102200720d047686b25ca256ddd547b0f3b139d512a864859ec3ac26de9c9273bd4b7c9ac21012007405f507a5c9c84e8d750e19e7cea96b4771b4367c418407d5a0f9b26d8d2f7f58863fd7698029fa5f7088f7cc4359e40cb1e3090da5d4194aa55a7a0734fab080a20200122010102200720a4d2cf90aee486c748f9da81bebdc44f3a39808aee6ac85b326423771d107127210120074063451de7fd791f09a850c9c545a09d397039f570166fb6c1e7dca498d187beb80707f54f2697eb50c259216efff11f95a27f9ca7049e4cf5090c45a69a7ecd08",
"4d2103210221012105210607020a94ef0000000000000a96ef0000000000002200002200000a806e24d0021167a1202000220000202001072088842f428c7c8a5c5bad51ac5cc4d98fbf0bc19651afd9a821ef2351351e538820220b610209000000002100000280005d32f3d22b24f7baa86e92e11f02b08676699846a6344735e9687b3dc5fb8500a044d2b0e0020000000000000000000000000000000000600121018100000000020180005d62a3f5498520803a31ec9034c613e205f53100f5f7021b5e2d53d737ac6102090000000021018101000000000280005d32f3d22b24f7baa86e92e11f02b08676699846a6344735e9687b3dc5fb850030ef7dba020000000000000000000000000000000000004103800051e40b09665d6aa3c8c9d4bcb4e4af712d5960b638efe78206591d5c7c190c076465706f7369742101810200000061020900000000210183004103800051e40b09665d6aa3c8c9d4bcb4e4af712d5960b638efe78206591d5c7c190c087769746864726177210280005da66318c6318c61f5a61b4c6318c6318cf794aa8d295f14e6318c6318c6850000b2d3595bf00600000000000000000000000000000000000280005da66318c6318c61f5a61b4c6318c6318cf794aa8d295f14e6318c6318c6850000b2d3595bf00600000000000000000000000000000000600121018103000000202101012105210607020a94ef0000000000000a96ef0000000000002200002201010503aa5c67000000000a332b872818d5b3b020200022000020200020220d41038000c1646fa75f334d38a794c9f74de7dd57f5fea33adc8b90edf71b597899fa0c1d6372656174655f70726f6f665f6f665f6e6f6e5f66756e6769626c6573210280009a68762738e7a5006c70df616ec8e002322084bad529c7b1b9cc9198c9cd20870103532fb7d5f6369c66e129ba32d1b81dbc24a72b4c24b922dd16649b5ae5522cd8150280009a68762738e7a5006c70df616ec8e002322084bad529c7b1b9cc9198c9cd20870103532fb7d5f6369c66e129ba32d1b81dbc24a72b4c24b922dd16649b5ae5522cd841038000c05b45d24b96f686afd33c69a18b0b2027e4286c881ba778e1b3d05190480c0f6d696e745f746f5f6163636f756e74210380005d32f3d22b24f7baa86e92e11f02b08676699846a6344735e9687b3dc5fb8500d033506be302000000000000000000000000000000000082000000006201220201220001220001220001210280009a4c6318c6318c6cb554820c6318c6318cf7a951d7a9e547c6318c6318c687021de40b09665d6aa3c8c9d4bcb4e4af712d5960b638efe78206591d5c7c1941038000c1646fa75f334d38a794c9f74de7dd57f5fea33adc8b90edf71b597899fa0c087769746864726177210280005d32f3d22b24f7baa86e92e11f02b08676699846a6344735e9687b3dc5fb8500d033506be3020000000000000000000000000000000000000280005d32f3d22b24f7baa86e92e11f02b08676699846a6344735e9687b3dc5fb8500a044d2b0e00200000000000000000000000000000000000a0123802201005d62a3f5498520803a31ec9034c613e205f53100f5f7021b5e2d53d737ac0201850090c051f4cbcbe504000000000000000000000000000000600121018100000000000280005d32f3d22b24f7baa86e92e11f02b08676699846a6344735e9687b3dc5fb85000000000000000000000000000000000000000000000000000280005d32f3d22b24f7baa86e92e11f02b08676699846a6344735e9687b3dc5fb850030ef7dba02000000000000000000000000000000000000600121028101000000810200000041038000c1646fa75f334d38a794c9f74de7dd57f5fea33adc8b90edf71b597899fa0c0d6465706f7369745f626174636821018300600121002022010102200720d047686b25ca256ddd547b0f3b139d512a864859ec3ac26de9c9273bd4b7c9ac2101200740decb5ae36c4907ab99fdee07c9e3162c2d286ace1cac23c8304c5dfa35e15d0ca0e8611e8044caca56e6050b1bff31f280182714e75bcc7a089151d077cd5c0020200122010001210120074101066f866fdca0d2aad13917fa73cd030ca6f85c2b4dd8d45e2f28a03d04f4537d0523d29d40e578829e1def4863fad3b1604a17bea611181aee45b7d8b45dfd2e"
]
}
The two values in the params
array are hex-encoded Manifest-SBOR Signed Partial Transactions.
Parse Manifest into Anthic Limit Orders
Because each limit order subintent is wrapped by an Anthic subintent you must first remove outer subintent before analyzing the limit order manifest.
Once done, parse the manifests of all signed partial transactions following the Anthic Limit Order Subintent Schema.
At this point you will be able to know the <sell_resource>
, <sell_amount>
, <buy_resource>
, and <buy_amount>
of every subintent. This represents what resources each subintent is providing and requires.
Construct Root SubIntent
With this knowledge you can now construct a root subintent which includes these subintents as children and perform the required swaps between these children.
1. USE_CHILD NamedIntent("child0") Intent("...");
2. USE_CHILD NamedIntent("child1") Intent("...");
3. YIELD_TO_CHILD NamedIntent("child0");
4. YIELD_TO_CHILD NamedIntent("child1");
5. TAKE_FROM_WORKTOP <buy_resource_0> <buy_amount_0> Bucket("Buy0");
6. TAKE_FROM_WORKTOP <buy_resource_1> <buy_amount_1> Bucket("Buy1");
7. YIELD_TO_CHILD NamedIntent("child0") Bucket("Buy0");
8. YIELD_TO_CHILD NamedIntent("child1") Bucket("Buy1");
9. CALL_METHOD <solver_account> "deposit_batch" Expression("ENTIRE_WORKTOP");
The fees you will receive will be sent to your worktop in lines 7 and 8.
Submit Transaction
Once finished, sign and submit the transaction. The fees you are rewarded is deposited into your account within the same transaction.