@goplausible/openclaw-algorand-plugin 1.2.0 → 1.4.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 +1 -1
- package/package.json +1 -1
- package/skills/algorand-interaction/SKILL.md +9 -5
- package/skills/algorand-interaction/references/algorand-mcp.md +50 -7
- package/skills/algorand-interaction/references/examples-algorand-mcp.md +58 -5
- package/skills/haystack-router-development/SKILL.md +14 -2
- package/skills/haystack-router-interaction/SKILL.md +30 -1
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,7 +2,7 @@
|
|
|
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.
|
|
5
|
+
"version": "1.4.0",
|
|
6
6
|
"skills": [
|
|
7
7
|
"skills/algorand-development",
|
|
8
8
|
"skills/algorand-typescript",
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ description: Interact with Algorand blockchain via the Algorand MCP server — w
|
|
|
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
|
|
|
@@ -162,6 +162,8 @@ For atomic (all-or-nothing) multi-transaction groups:
|
|
|
162
162
|
|
|
163
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
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
|
+
|
|
165
167
|
**ARC-26 URI** (1): `generate_algorand_uri`
|
|
166
168
|
|
|
167
169
|
**Knowledge Base** (1): `get_knowledge_doc`
|
|
@@ -174,13 +176,15 @@ API responses are paginated. All API tools accept optional `itemsPerPage` (defau
|
|
|
174
176
|
|
|
175
177
|
When `x402_fetch` returns HTTP 402 with `PaymentRequirements`, use the atomic group transaction pattern to build the payment:
|
|
176
178
|
|
|
177
|
-
1. Build fee payer transaction
|
|
178
|
-
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**
|
|
179
181
|
3. Group both transactions with `assign_group_id`
|
|
180
|
-
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
|
|
181
183
|
5. Encode the unsigned fee payer transaction (index 0) with `encode_unsigned_transaction`
|
|
182
184
|
6. Construct PAYMENT-SIGNATURE JSON payload — **must include `accepted` field** (the exact `accepts[]` entry chosen) — and retry with `x402_fetch`
|
|
183
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
|
+
|
|
184
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.
|
|
185
189
|
|
|
186
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.
|
|
@@ -206,7 +210,7 @@ When using NFD (`.algo` names), always use the `depositAccount` field from the N
|
|
|
206
210
|
- **Mainnet = real value** — always confirm with user before mainnet transactions
|
|
207
211
|
- Never log, display, or store mnemonics or secret keys — use `wallet_*` tools for signing
|
|
208
212
|
- Verify recipient addresses with `validate_address` — transactions are irreversible
|
|
209
|
-
- 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
|
|
210
214
|
- Respect wallet spending limits — if rejected, inform user rather than bypassing
|
|
211
215
|
|
|
212
216
|
## Links
|
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
8. [NFDomains API Tools](#nfdomains-api-tools)
|
|
16
16
|
9. [Tinyman DEX API Tools](#tinyman-dex-api-tools)
|
|
17
17
|
10. [Haystack Router Tools](#haystack-router-tools)
|
|
18
|
-
11. [
|
|
19
|
-
12. [
|
|
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)
|
|
20
21
|
|
|
21
22
|
---
|
|
22
23
|
|
|
@@ -199,17 +200,16 @@ Build unsigned transaction objects. Must be signed before submission.
|
|
|
199
200
|
"from": "sender_address",
|
|
200
201
|
"to": "receiver_address",
|
|
201
202
|
"amount": 1000000,
|
|
202
|
-
"note": "optional note",
|
|
203
203
|
"fee": 1000,
|
|
204
204
|
"flatFee": false,
|
|
205
|
+
"note": "optional note",
|
|
205
206
|
"closeRemainderTo": "optional",
|
|
206
207
|
"rekeyTo": "optional",
|
|
207
208
|
"network": "testnet"
|
|
208
209
|
}
|
|
209
210
|
```
|
|
210
211
|
> Amount in microAlgos: 1 ALGO = 1,000,000
|
|
211
|
-
> `fee` (optional): transaction fee in microAlgos
|
|
212
|
-
> `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.
|
|
213
213
|
|
|
214
214
|
### make_keyreg_txn
|
|
215
215
|
- **Purpose**: Create a key registration transaction for consensus participation
|
|
@@ -295,8 +295,7 @@ Build unsigned transaction objects. Must be signed before submission.
|
|
|
295
295
|
"network": "testnet"
|
|
296
296
|
}
|
|
297
297
|
```
|
|
298
|
-
> `fee` (optional): transaction fee in microAlgos
|
|
299
|
-
> `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.
|
|
300
299
|
|
|
301
300
|
### make_app_create_txn
|
|
302
301
|
- **Purpose**: Deploy a smart contract
|
|
@@ -711,6 +710,7 @@ DEX-aggregated swaps across Tinyman V2, Pact, and Folks with smart order routing
|
|
|
711
710
|
"network": "mainnet"
|
|
712
711
|
}
|
|
713
712
|
```
|
|
713
|
+
- **`type`**: `"fixed-input"` = `amount` is the input (spend exactly this much); `"fixed-output"` = `amount` is the output (receive exactly this much). See **Swap Type Rules** below.
|
|
714
714
|
- **Returns**: `expectedOutput`, `inputAmount`, `usdIn`, `usdOut`, `userPriceImpact`, `route`, `flattenedRoute`, `requiredAppOptIns`, `protocolFees`
|
|
715
715
|
|
|
716
716
|
### api_haystack_execute_swap
|
|
@@ -729,8 +729,23 @@ DEX-aggregated swaps across Tinyman V2, Pact, and Folks with smart order routing
|
|
|
729
729
|
"network": "mainnet"
|
|
730
730
|
}
|
|
731
731
|
```
|
|
732
|
+
- **`type`**: `"fixed-input"` = `amount` is the input (spend exactly this much); `"fixed-output"` = `amount` is the output (receive exactly this much). See **Swap Type Rules** below.
|
|
732
733
|
- **Returns**: `status`, `confirmedRound`, `txIds`, `signer`, `nickname`, quote details, `summary` (inputAmount, outputAmount, totalFees, transactionCount)
|
|
733
734
|
|
|
735
|
+
### Swap Type Rules
|
|
736
|
+
|
|
737
|
+
> **CRITICAL**: The `type` parameter determines which side of the swap is exact. Getting this wrong means the user spends more or receives less than intended.
|
|
738
|
+
|
|
739
|
+
| User intent | type | amount is | fromASAID | toASAID |
|
|
740
|
+
|-------------|------|-----------|-----------|---------|
|
|
741
|
+
| "Buy 10 ALGO with USDC" | `fixed-output` | 10000000 (output) | USDC | ALGO |
|
|
742
|
+
| "Buy USDC for 10 ALGO" | `fixed-input` | 10000000 (input) | ALGO | USDC |
|
|
743
|
+
| "Swap 5 USDC to ALGO" | `fixed-input` | 5000000 (input) | USDC | ALGO |
|
|
744
|
+
| "I want exactly 100 USDC" | `fixed-output` | 100000000 (output) | ALGO | USDC |
|
|
745
|
+
|
|
746
|
+
- **"Buy X of Y"** → `fixed-output`, amount = X in base units of Y, toASAID = Y
|
|
747
|
+
- **"Swap/sell/use X of Y"** → `fixed-input`, amount = X in base units of Y, fromASAID = Y
|
|
748
|
+
|
|
734
749
|
### api_haystack_needs_optin
|
|
735
750
|
- **Purpose**: Check if an address needs to opt into an asset before swapping
|
|
736
751
|
- **Parameters**: `{ "address": "ALGO_ADDRESS", "assetId": 31566704, "network": "mainnet" }`
|
|
@@ -738,6 +753,34 @@ DEX-aggregated swaps across Tinyman V2, Pact, and Folks with smart order routing
|
|
|
738
753
|
|
|
739
754
|
---
|
|
740
755
|
|
|
756
|
+
## Pera Asset Verification Tools
|
|
757
|
+
|
|
758
|
+
Mainnet asset verification via Pera Wallet API. Use to check if assets are legitimate before transacting.
|
|
759
|
+
|
|
760
|
+
### api_pera_asset_verification_status
|
|
761
|
+
- **Purpose**: Get the verification tier of a mainnet asset (verified, trusted, suspicious, unverified)
|
|
762
|
+
- **Parameters**: `{ "assetId": 31566704 }`
|
|
763
|
+
- **Returns**: `{ asset_id, verification_tier, explorer_url }`
|
|
764
|
+
- **Note**: Mainnet only. Returns `"unverified"` for unknown assets.
|
|
765
|
+
|
|
766
|
+
### api_pera_verified_asset_details
|
|
767
|
+
- **Purpose**: Get detailed asset info including name, unit name, decimals, total supply, USD value, logo, verification tier, and collectible status
|
|
768
|
+
- **Parameters**: `{ "assetId": 31566704 }`
|
|
769
|
+
- **Returns**: Full asset object with `name`, `unit_name`, `fraction_decimals`, `total`, `usd_value`, `logo`, `verification_tier`, `is_collectible`, `creator_address`, etc.
|
|
770
|
+
|
|
771
|
+
### api_pera_verified_asset_search
|
|
772
|
+
- **Purpose**: Search mainnet assets by name, unit name, or keyword with optional verification filter
|
|
773
|
+
- **Parameters**:
|
|
774
|
+
```json
|
|
775
|
+
{
|
|
776
|
+
"query": "USDC",
|
|
777
|
+
"verifiedOnly": true
|
|
778
|
+
}
|
|
779
|
+
```
|
|
780
|
+
- **Returns**: Array of `{ asset_id, name, unit_name, decimals, verification_tier, usd_value, logo, creator_address, is_deleted }`
|
|
781
|
+
|
|
782
|
+
---
|
|
783
|
+
|
|
741
784
|
## ARC-26 URI Tools
|
|
742
785
|
|
|
743
786
|
### generate_algorand_uri
|
|
@@ -402,6 +402,16 @@ api_tinyman_get_pool {
|
|
|
402
402
|
|
|
403
403
|
Best-price swap across multiple DEXes (Tinyman V2, Pact, Folks). For detailed reference, see the **haystack-router-interaction** skill.
|
|
404
404
|
|
|
405
|
+
### CRITICAL: fixed-input vs fixed-output
|
|
406
|
+
|
|
407
|
+
| User says | type | amount is | fromASAID | toASAID |
|
|
408
|
+
|-----------|------|-----------|-----------|---------|
|
|
409
|
+
| "Swap 10 ALGO for USDC" | `fixed-input` | 10000000 (input — spend exactly 10 ALGO) | 0 (ALGO) | 31566704 (USDC) |
|
|
410
|
+
| "Buy 10 ALGO with USDC" | `fixed-output` | 10000000 (output — receive exactly 10 ALGO) | 31566704 (USDC) | 0 (ALGO) |
|
|
411
|
+
|
|
412
|
+
- **"Buy X of Y"** → `fixed-output`, amount = X in base units of Y, toASAID = Y
|
|
413
|
+
- **"Swap/sell/use X of Y"** → `fixed-input`, amount = X in base units of Y, fromASAID = Y
|
|
414
|
+
|
|
405
415
|
### Step 1: Check wallet
|
|
406
416
|
```
|
|
407
417
|
wallet_get_info { "network": "mainnet" }
|
|
@@ -421,24 +431,41 @@ wallet_optin_asset { "assetId": 31566704, "network": "mainnet" }
|
|
|
421
431
|
```
|
|
422
432
|
|
|
423
433
|
### Step 3: Get a quote (show user before executing)
|
|
434
|
+
|
|
435
|
+
**Example A — "Swap 10 ALGO for USDC" (fixed-input):**
|
|
424
436
|
```
|
|
425
437
|
api_haystack_get_swap_quote {
|
|
426
438
|
"fromASAID": 0,
|
|
427
439
|
"toASAID": 31566704,
|
|
428
|
-
"amount":
|
|
440
|
+
"amount": 10000000,
|
|
429
441
|
"type": "fixed-input",
|
|
430
442
|
"address": "[wallet_address]",
|
|
431
443
|
"network": "mainnet"
|
|
432
444
|
}
|
|
433
445
|
```
|
|
434
|
-
|
|
446
|
+
|
|
447
|
+
**Example B — "Buy 10 ALGO with USDC" (fixed-output):**
|
|
448
|
+
```
|
|
449
|
+
api_haystack_get_swap_quote {
|
|
450
|
+
"fromASAID": 31566704,
|
|
451
|
+
"toASAID": 0,
|
|
452
|
+
"amount": 10000000,
|
|
453
|
+
"type": "fixed-output",
|
|
454
|
+
"address": "[wallet_address]",
|
|
455
|
+
"network": "mainnet"
|
|
456
|
+
}
|
|
457
|
+
```
|
|
458
|
+
> Present to user: expected output (or estimated input), USD values, route, price impact.
|
|
435
459
|
|
|
436
460
|
### Step 4: Execute swap (after user confirms)
|
|
461
|
+
|
|
462
|
+
Use the **same `type`, `fromASAID`, `toASAID`, and `amount`** as the quote:
|
|
437
463
|
```
|
|
438
464
|
api_haystack_execute_swap {
|
|
439
465
|
"fromASAID": 0,
|
|
440
466
|
"toASAID": 31566704,
|
|
441
|
-
"amount":
|
|
467
|
+
"amount": 10000000,
|
|
468
|
+
"type": "fixed-input",
|
|
442
469
|
"slippage": 1,
|
|
443
470
|
"network": "mainnet"
|
|
444
471
|
}
|
|
@@ -447,6 +474,31 @@ api_haystack_execute_swap {
|
|
|
447
474
|
|
|
448
475
|
---
|
|
449
476
|
|
|
477
|
+
## Verify an Asset (Pera)
|
|
478
|
+
|
|
479
|
+
Check if an asset is legitimate before transacting — mainnet only.
|
|
480
|
+
|
|
481
|
+
### Check verification status
|
|
482
|
+
```
|
|
483
|
+
api_pera_asset_verification_status { "assetId": 31566704 }
|
|
484
|
+
```
|
|
485
|
+
> Returns: `{ asset_id: 31566704, verification_tier: "verified", explorer_url: "..." }`
|
|
486
|
+
> Tiers: `verified` (highest), `trusted`, `suspicious`, `unverified`
|
|
487
|
+
|
|
488
|
+
### Get detailed asset info with USD value
|
|
489
|
+
```
|
|
490
|
+
api_pera_verified_asset_details { "assetId": 31566704 }
|
|
491
|
+
```
|
|
492
|
+
> Returns: name, unit name, decimals, total supply, USD value, logo, verification tier
|
|
493
|
+
|
|
494
|
+
### Search for verified assets
|
|
495
|
+
```
|
|
496
|
+
api_pera_verified_asset_search { "query": "USDC", "verifiedOnly": true }
|
|
497
|
+
```
|
|
498
|
+
> Returns array of matching assets filtered to verified/trusted only
|
|
499
|
+
|
|
500
|
+
---
|
|
501
|
+
|
|
450
502
|
## Using the Knowledge Base
|
|
451
503
|
|
|
452
504
|
### Get a specific document
|
|
@@ -602,7 +654,8 @@ wallet_get_info { "network": "<network>" }
|
|
|
602
654
|
|
|
603
655
|
### Step 2: Build fee payer transaction
|
|
604
656
|
|
|
605
|
-
The facilitator sponsors fees for the entire group.
|
|
657
|
+
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.
|
|
658
|
+
|
|
606
659
|
```
|
|
607
660
|
make_payment_txn {
|
|
608
661
|
"from": "<feePayer>",
|
|
@@ -616,7 +669,7 @@ make_payment_txn {
|
|
|
616
669
|
|
|
617
670
|
### Step 3: Build payment transaction
|
|
618
671
|
|
|
619
|
-
The payment transaction fee is 0 since the facilitator covers it.
|
|
672
|
+
The payment transaction fee is 0 since the facilitator covers it.
|
|
620
673
|
|
|
621
674
|
**For native ALGO (asset = "0"):**
|
|
622
675
|
```
|
|
@@ -56,11 +56,23 @@ The SDK is the **only** supported integration path. Do not call the API directly
|
|
|
56
56
|
|
|
57
57
|
- **Amounts** are always in base units (microAlgos for ALGO, smallest unit for ASAs)
|
|
58
58
|
- **ASA IDs**: 0 = ALGO, 31566704 = USDC, etc.
|
|
59
|
-
- **
|
|
60
|
-
- **
|
|
59
|
+
- **Slippage**: Percentage tolerance on output (e.g., 1 = 1%). Applied to the final output, not individual hops.
|
|
60
|
+
- **Quote types**: `fixed-input` (default) — specify input amount; `fixed-output` — specify desired output.
|
|
61
61
|
- **Routing**: Supports multi-hop and parallel (combo) swaps for optimal pricing
|
|
62
62
|
- **Middleware**: Plugin system for custom pre/post-swap transactions (e.g., auto opt-out)
|
|
63
63
|
|
|
64
|
+
### fixed-input vs fixed-output
|
|
65
|
+
|
|
66
|
+
| Type | `amount` specifies | Other side | Example |
|
|
67
|
+
|------|-------------------|------------|---------|
|
|
68
|
+
| `fixed-input` (default) | Input (what you send) | Estimated output | "Swap 10 ALGO for USDC" — spend exactly 10 ALGO |
|
|
69
|
+
| `fixed-output` | Output (what you get) | Estimated input | "Buy 10 ALGO with USDC" — receive exactly 10 ALGO |
|
|
70
|
+
|
|
71
|
+
- **"Buy X of Y"** → `fixed-output`, amount = X in base units of Y, toASAID = Y
|
|
72
|
+
- **"Swap/sell/use X of Y"** → `fixed-input`, amount = X in base units of Y, fromASAID = Y
|
|
73
|
+
- **"I want exactly X of Y"** → `fixed-output`, amount = X in base units of Y, toASAID = Y
|
|
74
|
+
- The `amount` field always refers to the **fixed side** — never the estimated side
|
|
75
|
+
|
|
64
76
|
## Reference Files
|
|
65
77
|
|
|
66
78
|
Read the appropriate file based on the task:
|
|
@@ -122,10 +122,39 @@ Step 4: User confirms → Execute
|
|
|
122
122
|
|
|
123
123
|
- **Amounts** are always in base units (microAlgos for ALGO, smallest unit for ASAs)
|
|
124
124
|
- **ASA IDs**: 0 = ALGO, 31566704 = USDC, etc.
|
|
125
|
+
- **Slippage**: Percentage tolerance on output (e.g., 1 = 1%). Applied to the final output, not individual hops.
|
|
125
126
|
- **Quote types**: `fixed-input` (default) — specify input amount; `fixed-output` — specify desired output
|
|
126
|
-
- **Slippage**: Percentage tolerance on output (e.g., 1 = 1%). Applied to the final output, not individual hops
|
|
127
127
|
- **Routing**: Supports multi-hop and parallel (combo) swaps for optimal pricing
|
|
128
128
|
|
|
129
|
+
## CRITICAL: fixed-input vs fixed-output — Choosing the Correct Swap Type
|
|
130
|
+
|
|
131
|
+
The `type` parameter determines which side of the swap is exact. Getting this wrong means the user spends more or receives less than intended. **Parse the user's intent carefully.**
|
|
132
|
+
|
|
133
|
+
| Type | Meaning | `amount` specifies | The other side is | Use when |
|
|
134
|
+
|------|---------|-------------------|-------------------|----------|
|
|
135
|
+
| `fixed-input` | Spend exactly this much | **Input** amount (what you send) | Estimated (output varies) | "Swap 10 ALGO for USDC", "Sell 10 ALGO", "Use 10 ALGO to buy USDC" |
|
|
136
|
+
| `fixed-output` | Receive exactly this much | **Output** amount (what you get) | Estimated (input varies) | "Buy 10 ALGO with USDC", "I want exactly 5 USDC", "Get me 10 ALGO" |
|
|
137
|
+
|
|
138
|
+
### Mapping User Intent — Examples
|
|
139
|
+
|
|
140
|
+
| User says | Type | fromASAID | toASAID | amount | Why |
|
|
141
|
+
|-----------|------|-----------|---------|--------|-----|
|
|
142
|
+
| "Buy 10 ALGO with USDC" | `fixed-output` | 31566704 (USDC) | 0 (ALGO) | 10000000 | User wants **exactly 10 ALGO** out |
|
|
143
|
+
| "Buy USDC for 10 ALGO" | `fixed-input` | 0 (ALGO) | 31566704 (USDC) | 10000000 | User wants to **spend exactly 10 ALGO** |
|
|
144
|
+
| "Swap 5 USDC to ALGO" | `fixed-input` | 31566704 (USDC) | 0 (ALGO) | 5000000 | User wants to **spend exactly 5 USDC** |
|
|
145
|
+
| "I want exactly 100 USDC" | `fixed-output` | 0 (ALGO) | 31566704 (USDC) | 100000000 | User wants **exactly 100 USDC** out |
|
|
146
|
+
| "Sell 10 ALGO" | `fixed-input` | 0 (ALGO) | 31566704 (USDC) | 10000000 | User wants to **spend exactly 10 ALGO** |
|
|
147
|
+
| "Get me 10 ALGO" | `fixed-output` | 31566704 (USDC) | 0 (ALGO) | 10000000 | User wants **exactly 10 ALGO** out |
|
|
148
|
+
|
|
149
|
+
### Rules
|
|
150
|
+
|
|
151
|
+
1. **"Buy X of Y"** → `fixed-output`, amount = X (in base units of Y), toASAID = Y
|
|
152
|
+
2. **"Swap/sell/use X of Y for Z"** → `fixed-input`, amount = X (in base units of Y), fromASAID = Y
|
|
153
|
+
3. **"I want exactly X of Y"** → `fixed-output`, amount = X (in base units of Y), toASAID = Y
|
|
154
|
+
4. **When ambiguous, ask the user**: "Do you want to spend exactly X or receive exactly X?"
|
|
155
|
+
5. **The `amount` field always refers to the fixed side** — input amount for `fixed-input`, output amount for `fixed-output`
|
|
156
|
+
6. **Always show the quote** before executing so the user can verify the estimated other side
|
|
157
|
+
|
|
129
158
|
## Reference Files
|
|
130
159
|
|
|
131
160
|
Read the appropriate file based on the task:
|