@goplausible/openclaw-algorand-plugin 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/x402-fetch.ts +3 -10
- package/openclaw.plugin.json +4 -2
- package/package.json +1 -1
- package/skills/algorand-interaction/SKILL.md +12 -6
- package/skills/algorand-interaction/references/algorand-mcp.md +81 -7
- package/skills/algorand-interaction/references/examples-algorand-mcp.md +77 -2
- package/skills/haystack-router-development/SKILL.md +85 -0
- package/skills/haystack-router-development/references/api-reference.md +381 -0
- package/skills/haystack-router-development/references/configuration.md +184 -0
- package/skills/haystack-router-development/references/fees-and-referrals.md +91 -0
- package/skills/haystack-router-development/references/getting-started.md +93 -0
- package/skills/haystack-router-development/references/migration.md +53 -0
- package/skills/haystack-router-development/references/node-automation.md +113 -0
- package/skills/haystack-router-development/references/quotes.md +155 -0
- package/skills/haystack-router-development/references/react-integration.md +260 -0
- package/skills/haystack-router-development/references/swaps.md +161 -0
- package/skills/haystack-router-interaction/SKILL.md +146 -0
- package/skills/haystack-router-interaction/references/configuration.md +53 -0
- package/skills/haystack-router-interaction/references/getting-started.md +48 -0
- package/skills/haystack-router-interaction/references/node-automation.md +51 -0
- package/skills/haystack-router-interaction/references/quotes.md +80 -0
- package/skills/haystack-router-interaction/references/swaps.md +84 -0
package/lib/x402-fetch.ts
CHANGED
|
@@ -36,17 +36,10 @@ const PAYMENT_INSTRUCTIONS = `To pay for this resource, follow these steps using
|
|
|
36
36
|
"algorand:wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=" → "mainnet"
|
|
37
37
|
|
|
38
38
|
2. Build fee payer transaction (facilitator sponsors fees for the group):
|
|
39
|
-
make_payment_txn {
|
|
40
|
-
|
|
41
|
-
to: "<feePayer>",
|
|
42
|
-
amount: 0,
|
|
43
|
-
fee: 2000,
|
|
44
|
-
flatFee: true,
|
|
45
|
-
network: "<network>"
|
|
46
|
-
}
|
|
47
|
-
— fee: 2000 covers both transactions in the group (1000 each). flatFee: true prevents SDK override.
|
|
39
|
+
make_payment_txn { from: "<feePayer from accepts[].extra.feePayer>", to: "<feePayer>", amount: 0, fee: N×1000 (N=group size, e.g. 2000 for 2 txns), flatFee: true, network: "<network>" }
|
|
40
|
+
— NEVER set fee=0 on the fee payer — this causes "txgroup had 0 in fees" errors.
|
|
48
41
|
|
|
49
|
-
3. Build payment transaction
|
|
42
|
+
3. Build payment transaction:
|
|
50
43
|
— For native ALGO (asset "0"):
|
|
51
44
|
make_payment_txn { from: "<your_address>", to: "<payTo>", amount: <maxAmountRequired>, fee: 0, flatFee: true, network: "<network>" }
|
|
52
45
|
— For ASA (asset is ASA ID):
|
package/openclaw.plugin.json
CHANGED
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
"id": "openclaw-algorand-plugin",
|
|
3
3
|
"name": "Algorand Integration",
|
|
4
4
|
"description": "Algorand blockchain integration with MCP and skills — by GoPlausible",
|
|
5
|
-
"version": "1.0
|
|
5
|
+
"version": "1.3.0",
|
|
6
6
|
"skills": [
|
|
7
7
|
"skills/algorand-development",
|
|
8
8
|
"skills/algorand-typescript",
|
|
9
9
|
"skills/algorand-python",
|
|
10
10
|
"skills/algorand-interaction",
|
|
11
11
|
"skills/algorand-x402-typescript",
|
|
12
|
-
"skills/algorand-x402-python"
|
|
12
|
+
"skills/algorand-x402-python",
|
|
13
|
+
"skills/haystack-router-development",
|
|
14
|
+
"skills/haystack-router-interaction"
|
|
13
15
|
],
|
|
14
16
|
"configSchema": {
|
|
15
17
|
"type": "object",
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: algorand-interaction
|
|
3
|
-
description: Interact with Algorand blockchain via the Algorand MCP server — wallet operations, ALGO/ASA transactions, smart contracts, account info, NFD lookups, atomic groups, Tinyman swaps, TEAL compilation, knowledge base. Use when user asks about Algorand wallet, balances, sending ALGO or tokens, asset opt-in, transactions, NFD names, DEX swaps, smart contracts, or account details.
|
|
3
|
+
description: Interact with Algorand blockchain via the Algorand MCP server — wallet operations, ALGO/ASA transactions, smart contracts, account info, NFD lookups, atomic groups, Tinyman swaps, Haystack Router DEX-aggregated swaps, TEAL compilation, knowledge base. Use when user asks about Algorand wallet, balances, sending ALGO or tokens, asset opt-in, transactions, NFD names, DEX swaps, smart contracts, or account details.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Algorand MCP Interaction
|
|
7
7
|
|
|
8
|
-
Interact with Algorand blockchain through the Algorand MCP server (
|
|
8
|
+
Interact with Algorand blockchain through the Algorand MCP server (104+ tools across 13 categories).
|
|
9
9
|
|
|
10
10
|
## Key Characteristics
|
|
11
11
|
|
|
@@ -160,6 +160,10 @@ For atomic (all-or-nothing) multi-transaction groups:
|
|
|
160
160
|
|
|
161
161
|
**Tinyman DEX** (9): `api_tinyman_get_pool`, `api_tinyman_get_pool_analytics`, `api_tinyman_get_pool_creation_quote`, `api_tinyman_get_liquidity_quote`, `api_tinyman_get_remove_liquidity_quote`, `api_tinyman_get_swap_quote`, `api_tinyman_get_asset_optin_quote`, `api_tinyman_get_validator_optin_quote`, `api_tinyman_get_validator_optout_quote`
|
|
162
162
|
|
|
163
|
+
**Haystack Router** (3): `api_haystack_get_swap_quote`, `api_haystack_execute_swap`, `api_haystack_needs_optin` — DEX-aggregated swaps across Tinyman V2, Pact, Folks with optimal routing. See the **haystack-router-interaction** skill for detailed workflows and reference docs.
|
|
164
|
+
|
|
165
|
+
**Pera Asset Verification** (3): `api_pera_asset_verification_status`, `api_pera_verified_asset_details`, `api_pera_verified_asset_search` — mainnet asset verification (verified/trusted/suspicious/unverified), detailed asset info with USD value, and search by name/keyword
|
|
166
|
+
|
|
163
167
|
**ARC-26 URI** (1): `generate_algorand_uri`
|
|
164
168
|
|
|
165
169
|
**Knowledge Base** (1): `get_knowledge_doc`
|
|
@@ -172,13 +176,15 @@ API responses are paginated. All API tools accept optional `itemsPerPage` (defau
|
|
|
172
176
|
|
|
173
177
|
When `x402_fetch` returns HTTP 402 with `PaymentRequirements`, use the atomic group transaction pattern to build the payment:
|
|
174
178
|
|
|
175
|
-
1. Build fee payer transaction
|
|
176
|
-
2. Build payment transaction
|
|
179
|
+
1. Build fee payer transaction: `make_payment_txn` with from=feePayer, to=feePayer, amount=0, **fee=N×1000** (N=group size, e.g. 2000 for 2 txns), **flatFee=true**
|
|
180
|
+
2. Build payment transaction: `make_payment_txn` or `make_asset_transfer_txn` to `payTo`, **fee=0**, **flatFee=true**
|
|
177
181
|
3. Group both transactions with `assign_group_id`
|
|
178
|
-
4. Sign only the payment transaction (index 1) with
|
|
182
|
+
4. Sign only the payment transaction (index 1) with `wallet_sign_transaction` — leave fee payer unsigned
|
|
179
183
|
5. Encode the unsigned fee payer transaction (index 0) with `encode_unsigned_transaction`
|
|
180
184
|
6. Construct PAYMENT-SIGNATURE JSON payload — **must include `accepted` field** (the exact `accepts[]` entry chosen) — and retry with `x402_fetch`
|
|
181
185
|
|
|
186
|
+
> **IMPORTANT: Fee Abstraction** — Pass `fee` and `flatFee` directly as input parameters to `make_*_txn` tools. Fee payer: `fee=N×1000`, `flatFee=true`. Payment: `fee=0`, `flatFee=true`. NEVER set fee=0 on the fee payer — this causes "txgroup had 0 in fees" errors.
|
|
187
|
+
|
|
182
188
|
**Critical**: The `accepted` field is REQUIRED. It must be an exact copy of the `accepts[]` entry you chose to pay with (including all fields: scheme, network, price, payTo, asset, maxAmountRequired, extra, etc.). Without it, the server cannot match your payment and will reject with 402.
|
|
183
189
|
|
|
184
190
|
**Critical — Base64 blob handling**: When constructing the `paymentHeader` JSON string for `x402_fetch`, NEVER manually re-type or partially copy base64 blob strings. Use the EXACT `bytes` value from `encode_unsigned_transaction` and the EXACT `blob` value from `wallet_sign_transaction` — copy each complete value verbatim into the `paymentGroup` array. Even a single character corruption (e.g., `5` → `4`) causes "signature does not match sender" errors and the payment will be rejected.
|
|
@@ -204,7 +210,7 @@ When using NFD (`.algo` names), always use the `depositAccount` field from the N
|
|
|
204
210
|
- **Mainnet = real value** — always confirm with user before mainnet transactions
|
|
205
211
|
- Never log, display, or store mnemonics or secret keys — use `wallet_*` tools for signing
|
|
206
212
|
- Verify recipient addresses with `validate_address` — transactions are irreversible
|
|
207
|
-
- Verify asset IDs on-chain — scam tokens use similar names
|
|
213
|
+
- Verify asset IDs on-chain and check verification tier with `api_pera_asset_verification_status` — scam tokens use similar names
|
|
208
214
|
- Respect wallet spending limits — if rejected, inform user rather than bypassing
|
|
209
215
|
|
|
210
216
|
## Links
|
|
@@ -14,8 +14,10 @@
|
|
|
14
14
|
7. [Indexer API Tools](#indexer-api-tools)
|
|
15
15
|
8. [NFDomains API Tools](#nfdomains-api-tools)
|
|
16
16
|
9. [Tinyman DEX API Tools](#tinyman-dex-api-tools)
|
|
17
|
-
10. [
|
|
18
|
-
11. [
|
|
17
|
+
10. [Haystack Router Tools](#haystack-router-tools)
|
|
18
|
+
11. [Pera Asset Verification Tools](#pera-asset-verification-tools)
|
|
19
|
+
12. [ARC-26 URI Tools](#arc-26-uri-tools)
|
|
20
|
+
13. [Knowledge Base Tools](#knowledge-base-tools)
|
|
19
21
|
|
|
20
22
|
---
|
|
21
23
|
|
|
@@ -198,17 +200,16 @@ Build unsigned transaction objects. Must be signed before submission.
|
|
|
198
200
|
"from": "sender_address",
|
|
199
201
|
"to": "receiver_address",
|
|
200
202
|
"amount": 1000000,
|
|
201
|
-
"note": "optional note",
|
|
202
203
|
"fee": 1000,
|
|
203
204
|
"flatFee": false,
|
|
205
|
+
"note": "optional note",
|
|
204
206
|
"closeRemainderTo": "optional",
|
|
205
207
|
"rekeyTo": "optional",
|
|
206
208
|
"network": "testnet"
|
|
207
209
|
}
|
|
208
210
|
```
|
|
209
211
|
> Amount in microAlgos: 1 ALGO = 1,000,000
|
|
210
|
-
> `fee` (optional): transaction fee in microAlgos
|
|
211
|
-
> `flatFee` (optional): if `true`, use `fee` exactly as specified; if `false` (default), SDK may adjust fee based on transaction size.
|
|
212
|
+
> `fee` (optional): transaction fee in microAlgos (default: suggested fee). `flatFee` (optional): if true, use exact fee value instead of suggested fee.
|
|
212
213
|
|
|
213
214
|
### make_keyreg_txn
|
|
214
215
|
- **Purpose**: Create a key registration transaction for consensus participation
|
|
@@ -294,8 +295,7 @@ Build unsigned transaction objects. Must be signed before submission.
|
|
|
294
295
|
"network": "testnet"
|
|
295
296
|
}
|
|
296
297
|
```
|
|
297
|
-
> `fee` (optional): transaction fee in microAlgos
|
|
298
|
-
> `flatFee` (optional): if `true`, use `fee` exactly as specified; if `false` (default), SDK may adjust fee based on transaction size.
|
|
298
|
+
> `fee` (optional): transaction fee in microAlgos (default: suggested fee). `flatFee` (optional): if true, use exact fee value instead of suggested fee.
|
|
299
299
|
|
|
300
300
|
### make_app_create_txn
|
|
301
301
|
- **Purpose**: Deploy a smart contract
|
|
@@ -691,6 +691,80 @@ Decentralized exchange operations on Tinyman AMM.
|
|
|
691
691
|
|
|
692
692
|
---
|
|
693
693
|
|
|
694
|
+
## Haystack Router Tools
|
|
695
|
+
|
|
696
|
+
DEX-aggregated swaps across Tinyman V2, Pact, and Folks with smart order routing. For detailed workflows and the full SDK guide, see the **haystack-router-interaction** and **haystack-router-development** skills.
|
|
697
|
+
|
|
698
|
+
### api_haystack_get_swap_quote
|
|
699
|
+
- **Purpose**: Get an optimized swap quote across multiple DEXes without executing
|
|
700
|
+
- **Parameters**:
|
|
701
|
+
```json
|
|
702
|
+
{
|
|
703
|
+
"fromASAID": 0,
|
|
704
|
+
"toASAID": 31566704,
|
|
705
|
+
"amount": 1000000,
|
|
706
|
+
"type": "fixed-input",
|
|
707
|
+
"address": "optional — enables opt-in detection",
|
|
708
|
+
"maxGroupSize": 16,
|
|
709
|
+
"maxDepth": 4,
|
|
710
|
+
"network": "mainnet"
|
|
711
|
+
}
|
|
712
|
+
```
|
|
713
|
+
- **Returns**: `expectedOutput`, `inputAmount`, `usdIn`, `usdOut`, `userPriceImpact`, `route`, `flattenedRoute`, `requiredAppOptIns`, `protocolFees`
|
|
714
|
+
|
|
715
|
+
### api_haystack_execute_swap
|
|
716
|
+
- **Purpose**: All-in-one swap: quote → sign (via wallet) → submit → confirm. Enforces wallet spending limits.
|
|
717
|
+
- **Parameters**:
|
|
718
|
+
```json
|
|
719
|
+
{
|
|
720
|
+
"fromASAID": 0,
|
|
721
|
+
"toASAID": 31566704,
|
|
722
|
+
"amount": 1000000,
|
|
723
|
+
"slippage": 1,
|
|
724
|
+
"type": "fixed-input",
|
|
725
|
+
"note": "optional text note",
|
|
726
|
+
"maxGroupSize": 16,
|
|
727
|
+
"maxDepth": 4,
|
|
728
|
+
"network": "mainnet"
|
|
729
|
+
}
|
|
730
|
+
```
|
|
731
|
+
- **Returns**: `status`, `confirmedRound`, `txIds`, `signer`, `nickname`, quote details, `summary` (inputAmount, outputAmount, totalFees, transactionCount)
|
|
732
|
+
|
|
733
|
+
### api_haystack_needs_optin
|
|
734
|
+
- **Purpose**: Check if an address needs to opt into an asset before swapping
|
|
735
|
+
- **Parameters**: `{ "address": "ALGO_ADDRESS", "assetId": 31566704, "network": "mainnet" }`
|
|
736
|
+
- **Returns**: `{ address, assetId, needsOptIn: true/false, network }`
|
|
737
|
+
|
|
738
|
+
---
|
|
739
|
+
|
|
740
|
+
## Pera Asset Verification Tools
|
|
741
|
+
|
|
742
|
+
Mainnet asset verification via Pera Wallet API. Use to check if assets are legitimate before transacting.
|
|
743
|
+
|
|
744
|
+
### api_pera_asset_verification_status
|
|
745
|
+
- **Purpose**: Get the verification tier of a mainnet asset (verified, trusted, suspicious, unverified)
|
|
746
|
+
- **Parameters**: `{ "assetId": 31566704 }`
|
|
747
|
+
- **Returns**: `{ asset_id, verification_tier, explorer_url }`
|
|
748
|
+
- **Note**: Mainnet only. Returns `"unverified"` for unknown assets.
|
|
749
|
+
|
|
750
|
+
### api_pera_verified_asset_details
|
|
751
|
+
- **Purpose**: Get detailed asset info including name, unit name, decimals, total supply, USD value, logo, verification tier, and collectible status
|
|
752
|
+
- **Parameters**: `{ "assetId": 31566704 }`
|
|
753
|
+
- **Returns**: Full asset object with `name`, `unit_name`, `fraction_decimals`, `total`, `usd_value`, `logo`, `verification_tier`, `is_collectible`, `creator_address`, etc.
|
|
754
|
+
|
|
755
|
+
### api_pera_verified_asset_search
|
|
756
|
+
- **Purpose**: Search mainnet assets by name, unit name, or keyword with optional verification filter
|
|
757
|
+
- **Parameters**:
|
|
758
|
+
```json
|
|
759
|
+
{
|
|
760
|
+
"query": "USDC",
|
|
761
|
+
"verifiedOnly": true
|
|
762
|
+
}
|
|
763
|
+
```
|
|
764
|
+
- **Returns**: Array of `{ asset_id, name, unit_name, decimals, verification_tier, usd_value, logo, creator_address, is_deleted }`
|
|
765
|
+
|
|
766
|
+
---
|
|
767
|
+
|
|
694
768
|
## ARC-26 URI Tools
|
|
695
769
|
|
|
696
770
|
### generate_algorand_uri
|
|
@@ -398,6 +398,80 @@ api_tinyman_get_pool {
|
|
|
398
398
|
|
|
399
399
|
---
|
|
400
400
|
|
|
401
|
+
## Haystack Router Swap (DEX-Aggregated)
|
|
402
|
+
|
|
403
|
+
Best-price swap across multiple DEXes (Tinyman V2, Pact, Folks). For detailed reference, see the **haystack-router-interaction** skill.
|
|
404
|
+
|
|
405
|
+
### Step 1: Check wallet
|
|
406
|
+
```
|
|
407
|
+
wallet_get_info { "network": "mainnet" }
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
### Step 2: Check opt-in (if swapping to an ASA)
|
|
411
|
+
```
|
|
412
|
+
api_haystack_needs_optin {
|
|
413
|
+
"address": "[wallet_address]",
|
|
414
|
+
"assetId": 31566704,
|
|
415
|
+
"network": "mainnet"
|
|
416
|
+
}
|
|
417
|
+
```
|
|
418
|
+
If `needsOptIn: true`:
|
|
419
|
+
```
|
|
420
|
+
wallet_optin_asset { "assetId": 31566704, "network": "mainnet" }
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
### Step 3: Get a quote (show user before executing)
|
|
424
|
+
```
|
|
425
|
+
api_haystack_get_swap_quote {
|
|
426
|
+
"fromASAID": 0,
|
|
427
|
+
"toASAID": 31566704,
|
|
428
|
+
"amount": 1000000,
|
|
429
|
+
"type": "fixed-input",
|
|
430
|
+
"address": "[wallet_address]",
|
|
431
|
+
"network": "mainnet"
|
|
432
|
+
}
|
|
433
|
+
```
|
|
434
|
+
> Present to user: expected output, USD values, route, price impact.
|
|
435
|
+
|
|
436
|
+
### Step 4: Execute swap (after user confirms)
|
|
437
|
+
```
|
|
438
|
+
api_haystack_execute_swap {
|
|
439
|
+
"fromASAID": 0,
|
|
440
|
+
"toASAID": 31566704,
|
|
441
|
+
"amount": 1000000,
|
|
442
|
+
"slippage": 1,
|
|
443
|
+
"network": "mainnet"
|
|
444
|
+
}
|
|
445
|
+
```
|
|
446
|
+
> Signs via wallet, submits, and confirms atomically. Returns confirmed round and tx IDs.
|
|
447
|
+
|
|
448
|
+
---
|
|
449
|
+
|
|
450
|
+
## Verify an Asset (Pera)
|
|
451
|
+
|
|
452
|
+
Check if an asset is legitimate before transacting — mainnet only.
|
|
453
|
+
|
|
454
|
+
### Check verification status
|
|
455
|
+
```
|
|
456
|
+
api_pera_asset_verification_status { "assetId": 31566704 }
|
|
457
|
+
```
|
|
458
|
+
> Returns: `{ asset_id: 31566704, verification_tier: "verified", explorer_url: "..." }`
|
|
459
|
+
> Tiers: `verified` (highest), `trusted`, `suspicious`, `unverified`
|
|
460
|
+
|
|
461
|
+
### Get detailed asset info with USD value
|
|
462
|
+
```
|
|
463
|
+
api_pera_verified_asset_details { "assetId": 31566704 }
|
|
464
|
+
```
|
|
465
|
+
> Returns: name, unit name, decimals, total supply, USD value, logo, verification tier
|
|
466
|
+
|
|
467
|
+
### Search for verified assets
|
|
468
|
+
```
|
|
469
|
+
api_pera_verified_asset_search { "query": "USDC", "verifiedOnly": true }
|
|
470
|
+
```
|
|
471
|
+
> Returns array of matching assets filtered to verified/trusted only
|
|
472
|
+
|
|
473
|
+
---
|
|
474
|
+
|
|
401
475
|
## Using the Knowledge Base
|
|
402
476
|
|
|
403
477
|
### Get a specific document
|
|
@@ -553,7 +627,8 @@ wallet_get_info { "network": "<network>" }
|
|
|
553
627
|
|
|
554
628
|
### Step 2: Build fee payer transaction
|
|
555
629
|
|
|
556
|
-
The facilitator sponsors fees for the entire group.
|
|
630
|
+
The facilitator sponsors fees for the entire group. The fee payer's `fee` must equal **N × 1000 µAlgo** (N = total transactions in group). For a 2-txn group: fee = 2 × 1000 = **2000**. NEVER set fee=0 on the fee payer.
|
|
631
|
+
|
|
557
632
|
```
|
|
558
633
|
make_payment_txn {
|
|
559
634
|
"from": "<feePayer>",
|
|
@@ -567,7 +642,7 @@ make_payment_txn {
|
|
|
567
642
|
|
|
568
643
|
### Step 3: Build payment transaction
|
|
569
644
|
|
|
570
|
-
The payment transaction fee is 0 since the facilitator covers it.
|
|
645
|
+
The payment transaction fee is 0 since the facilitator covers it.
|
|
571
646
|
|
|
572
647
|
**For native ALGO (asset = "0"):**
|
|
573
648
|
```
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: haystack-router-development
|
|
3
|
+
description: Comprehensive guide for building applications with Haystack Router SDK (@txnlab/haystack-router) — a DEX aggregator and smart order routing protocol on Algorand. Use when developing swap UIs with React and use-wallet, writing Node.js automation scripts, integrating RouterClient for quotes and swaps, or working with the SDK API surface, middleware, fees, and referral program. Strong triggers include haystack router, @txnlab/haystack-router, RouterClient, DEX aggregator, swap UI, swap React, newQuote, newSwap, deflex migration, haystack SDK, swap routing, best price swap.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Haystack Router (Development)
|
|
7
|
+
|
|
8
|
+
This is the parent skill for building applications that integrate the `@txnlab/haystack-router` SDK — React swap UIs, Node.js automation scripts, custom signing flows, middleware, and direct RouterClient usage. No Algorand MCP tools are involved.
|
|
9
|
+
|
|
10
|
+
> **Want to execute swaps** through the Algorand MCP server instead of building an app? Use the **haystack-router-interaction** skill — it provides Algorand MCP tools for quoting, swapping, and opt-in checking with wallet-based signing.
|
|
11
|
+
> **Need Algorand blockchain interaction guidance?** See the **algorand-interaction** skill for wallet setup, transaction workflows, and MCP tool reference.
|
|
12
|
+
|
|
13
|
+
Haystack Router is a DEX aggregator and smart order routing protocol on Algorand. It finds optimal swap routes across multiple DEXes (Tinyman V2, Pact, Folks) and LST protocols (tALGO, xALGO), then executes them atomically through on-chain smart contracts.
|
|
14
|
+
|
|
15
|
+
## Package
|
|
16
|
+
|
|
17
|
+
`@txnlab/haystack-router` — TypeScript SDK for DEX-aggregated swaps. Requires `algosdk` (v3+) as a peer dependency.
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @txnlab/haystack-router algosdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**API key required.** A free tier key is available for immediate use — see [configuration.md](references/configuration.md) for details.
|
|
24
|
+
|
|
25
|
+
## SDK Core Flow
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { RouterClient } from '@txnlab/haystack-router'
|
|
29
|
+
|
|
30
|
+
// 1. Initialize
|
|
31
|
+
const router = new RouterClient({
|
|
32
|
+
apiKey: '1b72df7e-1131-4449-8ce1-29b79dd3f51e', // Free tier (60 requests/min)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
// 2. Get a quote
|
|
36
|
+
const quote = await router.newQuote({
|
|
37
|
+
fromASAID: 0, // ALGO
|
|
38
|
+
toASAID: 31566704, // USDC
|
|
39
|
+
amount: 1_000_000, // 1 ALGO (base units)
|
|
40
|
+
address: activeAddress,
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
// 3. Execute the swap (use-wallet signer for browser, custom signer for Node.js)
|
|
44
|
+
const swap = await router.newSwap({
|
|
45
|
+
quote,
|
|
46
|
+
address: activeAddress,
|
|
47
|
+
signer: transactionSigner,
|
|
48
|
+
slippage: 1, // 1%
|
|
49
|
+
})
|
|
50
|
+
const result = await swap.execute()
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The SDK is the **only** supported integration path. Do not call the API directly.
|
|
54
|
+
|
|
55
|
+
## Key Concepts
|
|
56
|
+
|
|
57
|
+
- **Amounts** are always in base units (microAlgos for ALGO, smallest unit for ASAs)
|
|
58
|
+
- **ASA IDs**: 0 = ALGO, 31566704 = USDC, etc.
|
|
59
|
+
- **Quote types**: `fixed-input` (default) — specify input amount; `fixed-output` — specify desired output
|
|
60
|
+
- **Slippage**: Percentage tolerance on output (e.g., 1 = 1%). Applied to the final output, not individual hops
|
|
61
|
+
- **Routing**: Supports multi-hop and parallel (combo) swaps for optimal pricing
|
|
62
|
+
- **Middleware**: Plugin system for custom pre/post-swap transactions (e.g., auto opt-out)
|
|
63
|
+
|
|
64
|
+
## Reference Files
|
|
65
|
+
|
|
66
|
+
Read the appropriate file based on the task:
|
|
67
|
+
|
|
68
|
+
| Task | Reference |
|
|
69
|
+
| --------------------------------------- | ------------------------------------------------------- |
|
|
70
|
+
| Install SDK, initialize RouterClient | [getting-started.md](references/getting-started.md) |
|
|
71
|
+
| Get swap quotes, display pricing | [quotes.md](references/quotes.md) |
|
|
72
|
+
| Execute swaps with SDK signing | [swaps.md](references/swaps.md) |
|
|
73
|
+
| Build React swap UI with use-wallet | [react-integration.md](references/react-integration.md) |
|
|
74
|
+
| Automate swaps via Node.js scripts | [node-automation.md](references/node-automation.md) |
|
|
75
|
+
| RouterClient config, middleware, debug | [configuration.md](references/configuration.md) |
|
|
76
|
+
| Fee structure, referral program | [fees-and-referrals.md](references/fees-and-referrals.md) |
|
|
77
|
+
| Full API surface and types | [api-reference.md](references/api-reference.md) |
|
|
78
|
+
| Migrate from @txnlab/deflex | [migration.md](references/migration.md) |
|
|
79
|
+
|
|
80
|
+
## How to Use This Skill
|
|
81
|
+
|
|
82
|
+
1. **Start here** to understand which reference you need
|
|
83
|
+
2. **Read the topic `.md`** file for step-by-step guidance
|
|
84
|
+
3. **For MCP-based swaps** (no SDK), see the `haystack-router-interaction` skill
|
|
85
|
+
4. **For general Algorand development**, see `algorand-development`, `algorand-typescript`, or `algorand-python` skills
|