Skip to content

Commit 5204e21

Browse files
authored
Merge pull request #140 from skylavis-sky/fix/pancakeswap-v2-skill-dry-run-url
fix(pancakeswap-v2): v0.2.3 — human-readable amounts, --dry-run docs, erc20_decimals consolidation
2 parents bf1a6ee + 8edd2fd commit 5204e21

12 files changed

Lines changed: 198 additions & 80 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "pancakeswap-v2",
33
"description": "Swap tokens and manage liquidity on PancakeSwap V2 (xyk AMM) on BSC, Base, and Arbitrum. Triggers: swap pancakeswap v2, add/remove liquidity pancake, pcs v2 quote, check pancake pair.",
4-
"version": "0.2.2",
4+
"version": "0.2.3",
55
"author": { "name": "skylavis-sky", "github": "skylavis-sky" },
66
"license": "MIT"
77
}

skills/pancakeswap-v2/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
target/
1+
/target/

skills/pancakeswap-v2/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

skills/pancakeswap-v2/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pancakeswap-v2"
3-
version = "0.2.2"
3+
version = "0.2.3"
44
edition = "2021"
55

66
[[bin]]

skills/pancakeswap-v2/SKILL.md

Lines changed: 99 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
name: pancakeswap-v2
33
description: "Swap tokens and manage liquidity on PancakeSwap V2 (xyk AMM) on BSC, Base, and Arbitrum. Triggers: swap pancakeswap v2, add/remove liquidity pancake, pcs v2 quote, check pancake pair."
4-
version: "0.2.2"
4+
version: "0.2.3"
55
author: "skylavis-sky"
66
tags:
77
- dex
@@ -36,7 +36,9 @@ npx skills add okx/plugin-store --skill plugin-store --yes --global
3636
### Install pancakeswap-v2 binary (auto-injected)
3737

3838
```bash
39-
if ! command -v pancakeswap-v2 >/dev/null 2>&1; then
39+
REQUIRED_VERSION="0.2.3"
40+
INSTALLED_VERSION=$(pancakeswap-v2 --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
41+
if [ "$INSTALLED_VERSION" != "$REQUIRED_VERSION" ]; then
4042
OS=$(uname -s | tr A-Z a-z)
4143
ARCH=$(uname -m)
4244
EXT=""
@@ -50,9 +52,26 @@ if ! command -v pancakeswap-v2 >/dev/null 2>&1; then
5052
mingw*_x86_64|msys*_x86_64|cygwin*_x86_64) TARGET="x86_64-pc-windows-msvc"; EXT=".exe" ;;
5153
mingw*_i686|msys*_i686|cygwin*_i686) TARGET="i686-pc-windows-msvc"; EXT=".exe" ;;
5254
mingw*_aarch64|msys*_aarch64|cygwin*_aarch64) TARGET="aarch64-pc-windows-msvc"; EXT=".exe" ;;
55+
*) echo "Unsupported platform: ${OS}_${ARCH}"; exit 1 ;;
5356
esac
57+
BASE_URL="https://github.com/okx/plugin-store/releases/download/plugins/pancakeswap-v2@${REQUIRED_VERSION}"
5458
mkdir -p ~/.local/bin
55-
curl -fsSL "https://github.com/okx/plugin-store/releases/download/plugins/pancakeswap-v2@0.2.1/pancakeswap-v2-${TARGET}${EXT}" -o ~/.local/bin/pancakeswap-v2${EXT}
59+
curl -fsSL "${BASE_URL}/checksums.txt" -o /tmp/pancakeswap-v2-checksums.txt
60+
curl -fsSL "${BASE_URL}/pancakeswap-v2-${TARGET}${EXT}" -o ~/.local/bin/pancakeswap-v2${EXT}
61+
EXPECTED=$(grep "pancakeswap-v2-${TARGET}${EXT}" /tmp/pancakeswap-v2-checksums.txt | awk '{print $1}')
62+
if command -v sha256sum >/dev/null 2>&1; then
63+
ACTUAL=$(sha256sum ~/.local/bin/pancakeswap-v2${EXT} | awk '{print $1}')
64+
elif command -v shasum >/dev/null 2>&1; then
65+
ACTUAL=$(shasum -a 256 ~/.local/bin/pancakeswap-v2${EXT} | awk '{print $1}')
66+
else
67+
echo "Warning: cannot verify checksum (no sha256sum or shasum found)" && ACTUAL="$EXPECTED"
68+
fi
69+
if [ "$ACTUAL" != "$EXPECTED" ]; then
70+
echo "Checksum mismatch for pancakeswap-v2-${TARGET}${EXT} — aborting install"
71+
rm -f ~/.local/bin/pancakeswap-v2${EXT} /tmp/pancakeswap-v2-checksums.txt
72+
exit 1
73+
fi
74+
rm -f /tmp/pancakeswap-v2-checksums.txt
5675
chmod +x ~/.local/bin/pancakeswap-v2${EXT}
5776
fi
5877
```
@@ -71,7 +90,7 @@ if [ ! -f "$REPORT_FLAG" ]; then
7190
unset _K
7291
curl -s -X POST "https://plugin-store-dun.vercel.app/install" \
7392
-H "Content-Type: application/json" \
74-
-d '{"name":"pancakeswap-v2","version":"0.2.1"}' >/dev/null 2>&1 || true
93+
-d '{"name":"pancakeswap-v2","version":"0.2.3"}' >/dev/null 2>&1 || true
7594
curl -s -X POST "https://www.okx.com/priapi/v1/wallet/plugins/download/report" \
7695
-H "Content-Type: application/json" \
7796
-d '{"pluginName":"pancakeswap-v2","divId":"'"$DIV_ID"'"}' >/dev/null 2>&1 || true
@@ -86,6 +105,19 @@ fi
86105

87106
Before executing any write operation, verify the environment is ready:
88107

108+
> **Version check**: Run `pancakeswap-v2 --version` and confirm it prints `pancakeswap-v2 0.2.3`. If the installed version is older, force-reinstall:
109+
> ```bash
110+
> OS=$(uname -s | tr A-Z a-z); ARCH=$(uname -m)
111+
> case "${OS}_${ARCH}" in
112+
> darwin_arm64) TARGET="aarch64-apple-darwin" ;;
113+
> darwin_x86_64) TARGET="x86_64-apple-darwin" ;;
114+
> linux_x86_64) TARGET="x86_64-unknown-linux-gnu" ;;
115+
> linux_aarch64) TARGET="aarch64-unknown-linux-gnu" ;;
116+
> esac
117+
> curl -fsSL "https://github.com/okx/plugin-store/releases/download/plugins/pancakeswap-v2@0.2.3/pancakeswap-v2-${TARGET}" \
118+
> -o ~/.local/bin/pancakeswap-v2 && chmod +x ~/.local/bin/pancakeswap-v2
119+
> ```
120+
89121
```bash
90122
# Check onchainos version (requires >= 0.1.0)
91123
onchainos --version
@@ -116,11 +148,32 @@ Do NOT use for: PancakeSwap V3 swaps (use pancakeswap skill), concentrated liqui
116148
- Supports BSC (chain 56, default), Base (chain 8453), and Arbitrum One (chain 42161)
117149
- V2 uses constant-product xyk formula; LP tokens are standard ERC-20 (not NFTs); fixed 0.25% swap fee
118150
151+
## Global Flags
152+
153+
These flags apply to the **entire binary** and must be placed **before** the subcommand:
154+
155+
| Flag | Default | Description |
156+
|------|---------|-------------|
157+
| `--chain <id>` | `56` | Chain ID: 56 (BSC), 8453 (Base), 42161 (Arbitrum) |
158+
| `--dry-run` | false | Simulate without broadcasting — no onchainos call made |
159+
| `--slippage-bps <n>` | `50` | Slippage tolerance in basis points (50 = 0.5%) |
160+
| `--deadline-secs <n>` | `300` | Transaction deadline in seconds from now |
161+
| `--from <address>` | wallet | Override sender address |
162+
| `--rpc-url <url>` | (chain default) | Override RPC endpoint |
163+
164+
**Correct usage pattern:**
165+
```
166+
pancakeswap-v2 --dry-run --chain 56 swap --token-in USDT --token-out CAKE --amount-in 100
167+
pancakeswap-v2 --dry-run --chain 56 add-liquidity --token-a USDT --token-b BNB --amount-a 100 --amount-b 0.05
168+
```
169+
170+
> ⚠️ `--dry-run` does **not** appear in subcommand `--help` output because it is a global flag. Always pass it before the subcommand name.
171+
119172
## Execution Flow for Write Operations
120173
121-
1. Run with `--dry-run` first to preview calldata and estimated amounts
174+
1. Run with `pancakeswap-v2 --dry-run --chain <id> <command> ...` to preview calldata and estimated amounts
122175
2. **Ask user to confirm** the transaction details before proceeding
123-
3. Execute only after explicit user approval
176+
3. Execute only after explicit user approval (re-run without `--dry-run`)
124177
4. Report transaction hash and block explorer link
125178
126179
---
@@ -145,15 +198,15 @@ Do NOT use for: PancakeSwap V3 swaps (use pancakeswap skill), concentrated liqui
145198
146199
**Usage:**
147200
```
148-
pancakeswap-v2 --chain 56 quote --token-in USDT --token-out CAKE --amount-in 100000000000000000000
201+
pancakeswap-v2 --chain 56 quote --token-in USDT --token-out CAKE --amount-in 100
149202
```
150203
151204
**Parameters:**
152205
| Name | Flag | Description |
153206
|------|------|-------------|
154207
| tokenIn | `--token-in` | Input token: symbol (USDT, CAKE, WBNB) or hex address |
155208
| tokenOut | `--token-out` | Output token: symbol or hex address |
156-
| amountIn | `--amount-in` | Input amount in minimal units (e.g. 100e18 = 100 tokens for 18-decimal token) |
209+
| amountIn | `--amount-in` | Input amount as a human-readable decimal (e.g. 100, 1.5, 0.001) |
157210
| chain | `--chain` | Chain ID: 56 (BSC, default), 8453 (Base), or 42161 (Arbitrum) |
158211
159212
**Example output:**
@@ -185,21 +238,24 @@ Read-only operation — no confirmation required.
185238
186239
**Usage:**
187240
```
188-
pancakeswap-v2 --chain 56 swap --token-in USDT --token-out CAKE --amount-in 100000000000000000000
241+
# Live swap
242+
pancakeswap-v2 --chain 56 swap --token-in USDT --token-out CAKE --amount-in 100
243+
# Dry-run preview (--dry-run is a global flag, goes before the subcommand)
244+
pancakeswap-v2 --dry-run --chain 56 swap --token-in USDT --token-out CAKE --amount-in 100
189245
```
190246
191247
**Parameters:**
192248
| Name | Flag | Description |
193249
|------|------|-------------|
194250
| tokenIn | `--token-in` | Input token: symbol or address. Use BNB/ETH for native |
195251
| tokenOut | `--token-out` | Output token: symbol or address |
196-
| amountIn | `--amount-in` | Input amount in minimal units |
197-
| slippageBps | `--slippage-bps` | Slippage in basis points (default 50 = 0.5%) |
198-
| deadlineSecs | `--deadline-secs` | Seconds until deadline (default 300) |
199-
| dryRun | `--dry-run` | Preview calldata only, no broadcast |
252+
| amountIn | `--amount-in` | Input amount as a human-readable decimal (e.g. 100, 1.5, 0.001) |
253+
| slippageBps | `--slippage-bps` | Slippage in basis points (default 50 = 0.5%) — global flag |
254+
| deadlineSecs | `--deadline-secs` | Seconds until deadline (default 300) — global flag |
255+
| dryRun | `--dry-run` | Preview calldata only, no broadcast **global flag, place before subcommand** |
200256
201257
**Execution flow:**
202-
1. Run `--dry-run` to preview the swap calldata and expected output
258+
1. Run `pancakeswap-v2 --dry-run --chain 56 swap ...` to preview the swap calldata and expected output
203259
2. **Ask user to confirm** the swap details (tokenIn, tokenOut, amountIn, amountOutMin, slippage)
204260
3. If tokenIn is an ERC-20 and allowance is insufficient, first submit an exact-amount approve tx via `onchainos wallet contract-call`; **ask user to confirm** the approval
205261
4. Submit swap via `onchainos wallet contract-call`
@@ -230,25 +286,28 @@ pancakeswap-v2 --chain 56 swap --token-in USDT --token-out CAKE --amount-in 1000
230286
**Usage:**
231287
```
232288
# Token + Token
233-
pancakeswap-v2 --chain 56 add-liquidity --token-a CAKE --token-b USDT --amount-a 10000000000000000000 --amount-b 50000000000000000000
289+
pancakeswap-v2 --chain 56 add-liquidity --token-a CAKE --token-b USDT --amount-a 10 --amount-b 50
234290
235291
# Token + native BNB
236-
pancakeswap-v2 --chain 56 add-liquidity --token-a CAKE --token-b BNB --amount-a 10000000000000000000 --amount-b 50000000000000000
292+
pancakeswap-v2 --chain 56 add-liquidity --token-a CAKE --token-b BNB --amount-a 10 --amount-b 0.05
293+
294+
# Dry-run preview (--dry-run is a global flag, goes before the subcommand)
295+
pancakeswap-v2 --dry-run --chain 56 add-liquidity --token-a USDT --token-b BNB --amount-a 100 --amount-b 0.05
237296
```
238297
239298
**Parameters:**
240299
| Name | Flag | Description |
241300
|------|------|-------------|
242301
| tokenA | `--token-a` | First token: symbol or address. Use BNB/ETH for native |
243302
| tokenB | `--token-b` | Second token. Use BNB/ETH for native |
244-
| amountA | `--amount-a` | Desired amount of tokenA in minimal units |
245-
| amountB | `--amount-b` | Desired amount of tokenB (or native BNB/ETH) in minimal units |
246-
| slippageBps | `--slippage-bps` | Slippage tolerance (default 50 = 0.5%) |
247-
| dryRun | `--dry-run` | Preview calldata only |
303+
| amountA | `--amount-a` | Desired amount of tokenA as a human-readable decimal (e.g. 10, 0.5) |
304+
| amountB | `--amount-b` | Desired amount of tokenB (or native BNB/ETH) as a human-readable decimal |
305+
| slippageBps | `--slippage-bps` | Slippage tolerance (default 50 = 0.5%) — global flag |
306+
| dryRun | `--dry-run` | Preview calldata only **global flag, place before subcommand** |
248307
249308
**Execution flow:**
250309
1. Check current pair reserves and ratio
251-
2. Run `--dry-run` to preview the transaction
310+
2. Run `pancakeswap-v2 --dry-run --chain 56 add-liquidity ...` to preview the transaction
252311
3. **Ask user to confirm** the amounts and LP token receipt before proceeding
253312
4. Approve Router02 to spend the exact tokenA/tokenB amounts via `onchainos wallet contract-call` (if needed); **ask user to confirm** each approval
254313
5. Submit `addLiquidity` or `addLiquidityETH` via `onchainos wallet contract-call`
@@ -266,22 +325,22 @@ pancakeswap-v2 --chain 56 add-liquidity --token-a CAKE --token-b BNB --amount-a
266325
pancakeswap-v2 --chain 56 remove-liquidity --token-a CAKE --token-b USDT
267326
268327
# Remove specific amount
269-
pancakeswap-v2 --chain 56 remove-liquidity --token-a CAKE --token-b USDT --liquidity 1000000000000000000
328+
pancakeswap-v2 --chain 56 remove-liquidity --token-a CAKE --token-b USDT --liquidity 1.0
270329
```
271330
272331
**Parameters:**
273332
| Name | Flag | Description |
274333
|------|------|-------------|
275334
| tokenA | `--token-a` | First token |
276335
| tokenB | `--token-b` | Second token. Use BNB/ETH to receive native |
277-
| liquidity | `--liquidity` | LP tokens to burn (minimal units). Omit to remove all |
278-
| slippageBps | `--slippage-bps` | Slippage tolerance (default 50 = 0.5%) |
279-
| dryRun | `--dry-run` | Preview only |
336+
| liquidity | `--liquidity` | LP tokens to burn as a human-readable decimal (e.g. 1.0). Omit to remove all |
337+
| slippageBps | `--slippage-bps` | Slippage tolerance (default 50 = 0.5%) — global flag |
338+
| dryRun | `--dry-run` | Preview only **global flag, place before subcommand** |
280339
281340
**Execution flow:**
282341
1. Fetch LP balance and compute expected token withdrawals
283342
2. Display summary: LP amount, expected tokenA and tokenB out
284-
3. Run `--dry-run` to preview calldata
343+
3. Run `pancakeswap-v2 --dry-run --chain 56 remove-liquidity ...` to preview calldata
285344
4. **Ask user to confirm** the removal details before proceeding
286345
5. Approve LP tokens to Router02 via `onchainos wallet contract-call`; **ask user to confirm**
287346
6. Submit `removeLiquidity` or `removeLiquidityETH` via `onchainos wallet contract-call`
@@ -360,6 +419,20 @@ For Arbitrum One (42161): WETH `0x82aF49447D8a07e3bd95BD0d56f35241523fBab1`, USD
360419
361420
## Changelog
362421
422+
### v0.2.3 (2026-04-11)
423+
424+
- **fix**: `--amount-in`, `--amount-a`, `--amount-b`, and `--liquidity` now accept human-readable decimal input (e.g. `1.5`, `100`, `0.001`). Previously clap rejected decimal values at parse time with "invalid digit found in string" because those args were typed `u128`. Changed to `String` and added `parse_human_amount()` which resolves each token's ERC-20 `decimals()` on-chain and converts to raw units.
425+
- **feat**: `pancakeswap-v2 --version` now works (added `version` to `#[command(...)]` attribute)
426+
- **fix**: `.gitignore` uses `/target/` (anchored) instead of `target/`
427+
- **fix**: consolidate duplicate `erc20_decimals` / `get_erc20_decimals` into single function in `rpc.rs`
428+
- **docs**: Added Global Flags section explaining that `--dry-run`, `--chain`, `--slippage-bps`, `--deadline-secs`, `--from`, `--rpc-url` are root-level flags and must be placed **before** the subcommand
429+
- **docs**: Updated Usage examples for `swap`, `add-liquidity`, and `remove-liquidity` to show correct `--dry-run` placement
430+
431+
### v0.2.2 (2026-04-11)
432+
433+
- **fix**: `remove-liquidity` overflow protection upgraded from pure f64 to `safe_mul_div` — tries `checked_mul` first (exact integer arithmetic for small pools), falls back to f64 only when `reserve × lp_balance` would overflow u128 (e.g. BSC BNB/USDT ~$17M TVL). Behavior is identical for all affected pools; change improves precision for pools below the overflow threshold.
434+
- **fix**: Exact-amount ERC-20 approvals (not unlimited) — approves the exact swap/LP amount rather than `uint256.max`
435+
363436
### v0.2.1 (2026-04-11)
364437
365438
- **fix**: Arbitrum RPC URL updated from `arb1.arbitrum.io/rpc` to `arbitrum-one-rpc.publicnode.com` for consistency with BSC/Base (both use publicnode endpoints)

skills/pancakeswap-v2/plugin.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
schema_version: 1
22
name: pancakeswap-v2
3-
version: "0.2.2"
3+
version: "0.2.3"
44
description: "Swap tokens and manage liquidity on PancakeSwap V2 (xyk AMM) on BSC, Base, and Arbitrum. Triggers: swap pancakeswap v2, add/remove liquidity pancake, pcs v2 quote, check pancake pair."
55
author:
66
name: skylavis-sky

0 commit comments

Comments
 (0)