Skip to content

Commit e526f8d

Browse files
v14.2.0 (#44)
1 parent 71d705e commit e526f8d

File tree

5 files changed

+1543
-1
lines changed

5 files changed

+1543
-1
lines changed

.coverage

40 KB
Binary file not shown.

README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Solana Agent Kit provides a growing library of plugins that enhance your Solana
3838
* MCP - Interface with MCP web servers
3939
* Image Generation - Generate images with OpenAI, Grok, or Gemini with uploading to S3 compatible storage
4040
* Nemo Agent - Generate Python projects with Nemo Agent with uploading to S3 compatible storage
41+
* Token Math - Reliable token amount calculations for swaps, limit orders, and transfers (LLMs are bad at math!)
4142

4243
## 📦 Installation
4344

@@ -835,6 +836,92 @@ config = {
835836
}
836837
```
837838

839+
### Token Math
840+
841+
This plugin provides reliable token amount calculations for swaps, limit orders, and transfers. **LLMs are notoriously bad at math** - they drop zeros, mess up decimal conversions, and hallucinate calculations. This tool does the math reliably so your agent doesn't lose the user money.
842+
843+
No config is needed - it's pure math with no external dependencies.
844+
845+
```python
846+
config = {
847+
"agents": [
848+
{
849+
"name": "trading_agent",
850+
"instructions": """
851+
ALWAYS use the token_math tool BEFORE calling privy_ultra, privy_transfer, or privy_trigger!
852+
853+
For swaps (privy_ultra):
854+
1. Get token price and decimals from Birdeye
855+
2. Call token_math action="swap" with usd_amount, token_price_usd, decimals
856+
3. Use the returned smallest_units as the amount for privy_ultra
857+
858+
For transfers (privy_transfer):
859+
1. Get token price from Birdeye
860+
2. Call token_math action="transfer" with usd_amount, token_price_usd
861+
3. Use the returned amount for privy_transfer
862+
863+
For limit orders (privy_trigger):
864+
1. Get prices and decimals for BOTH tokens from Birdeye
865+
2. Call token_math action="limit_order" with all params
866+
3. Use the returned making_amount and taking_amount for privy_trigger
867+
868+
NEVER calculate amounts yourself - use token_math!
869+
""",
870+
"specialization": "Solana trading",
871+
"tools": ["token_math", "birdeye", "privy_ultra", "privy_transfer", "privy_trigger"],
872+
}
873+
]
874+
}
875+
```
876+
877+
**Actions:**
878+
879+
- `swap` - Calculate smallest units for a swap given USD amount
880+
- Params: `usd_amount`, `token_price_usd`, `decimals`
881+
- Returns: `smallest_units` (use this for privy_ultra amount)
882+
883+
- `transfer` - Calculate human-readable token amount for transfers
884+
- Params: `usd_amount`, `token_price_usd`
885+
- Returns: `amount` (human-readable, use this for privy_transfer amount)
886+
887+
- `limit_order` - Calculate making_amount and taking_amount for limit orders
888+
- Params: `usd_amount`, `input_price_usd`, `input_decimals`, `output_price_usd`, `output_decimals`, `price_change_percentage`
889+
- Returns: `making_amount`, `taking_amount` (use these for privy_trigger)
890+
- `price_change_percentage`: Use "-0.5" for 0.5% lower (buy the dip), "10" for 10% higher (sell high)
891+
892+
- `to_smallest_units` - Convert human amount to smallest units
893+
- Params: `human_amount`, `decimals`
894+
- Returns: `smallest_units`
895+
896+
- `to_human` - Convert smallest units to human readable
897+
- Params: `smallest_units`, `decimals`
898+
- Returns: `human_amount`
899+
900+
- `usd_to_tokens` - Calculate token amount from USD value
901+
- Params: `usd_amount`, `token_price_usd`
902+
- Returns: `token_amount` (human readable)
903+
904+
**Example - Limit Order:**
905+
```
906+
User: "limit buy BONK when price drops 0.5% with $10 of SOL"
907+
908+
1. Birdeye: SOL price=$140, decimals=9, BONK price=$0.00001, decimals=5
909+
910+
2. token_math action="limit_order":
911+
- usd_amount="10"
912+
- input_price_usd="140" (SOL)
913+
- input_decimals=9
914+
- output_price_usd="0.00001" (BONK)
915+
- output_decimals=5
916+
- price_change_percentage="-0.5"
917+
918+
Returns:
919+
- making_amount="71428571" (SOL in lamports)
920+
- taking_amount="100502512562" (BONK in smallest units)
921+
922+
3. privy_trigger with those exact amounts
923+
```
924+
838925
## 🧩 Plugin Development
839926
Want to add your own plugins to Solana Agent Kit? Follow these guidelines:
840927

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "sakit"
3-
version = "14.1.12"
3+
version = "14.2.0"
44
description = "Solana Agent Kit"
55
authors = ["Bevan Hunt <bevan@bevanhunt.com>"]
66
license = "MIT"
@@ -58,6 +58,7 @@ search_internet = "sakit.search_internet:get_plugin"
5858
solana_dflow_swap = "sakit.solana_dflow_swap:get_plugin"
5959
solana_transfer = "sakit.solana_transfer:get_plugin"
6060
solana_ultra = "sakit.solana_ultra:get_plugin"
61+
token_math = "sakit.token_math:get_plugin"
6162
vybe = "sakit.vybe:get_plugin"
6263

6364
[tool.poetry.group.dev.dependencies]

0 commit comments

Comments
 (0)