@gangfun/cli 0.19.0 → 0.20.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/README.md +8 -3
- package/README.zh-CN.md +8 -3
- package/package.json +1 -1
- package/src/discover.js +6 -3
- package/src/index.js +42 -10
- package/src/launch.js +105 -14
- package/src/lp.js +305 -0
- package/src/mcp.js +4 -4
- package/src/v3.js +6 -1
package/README.md
CHANGED
|
@@ -12,6 +12,8 @@ Operate [gang.fun](https://gang.fun) from a Binance **Agentic Wallet**. Curve bu
|
|
|
12
12
|
|
|
13
13
|
**Split recipient (0.19.0+):** `gang create … --buy-tax … --sell-tax … --split self:60,0x…:30,0x…:10` makes a V3 token's tax recipient the dev's split module (GangSplitModule, `split-v1`): the recipient's part of the tax is split among 1–10 payees at shares fixed for good (nobody, not the dev, not the platform, can change them; a payee can only move its own slot). `self` is the creating wallet (`me` also works); payee slots are numbered as in the contract, from 0 (`--index`). The quote must be one the keeper splits: WBNB (default), GANG or a quote in the pad's QuoteRegistry (others are refused before the clone, as for `--buyback`); `gang split distribute` still splits any asset sent to the module. `gang split …` shows and drives it. Live on BSC mainnet (factory `0x27e08271E52B2D129c824CD245e69471a8d3067c`, allowed by the platform's Safe on 2026-10-30, built in) and testnet set 10.
|
|
14
14
|
|
|
15
|
+
**Auto-liquidity recipient (0.20.0+):** `gang create … --buy-tax … --sell-tax … --lp 70 [--lp-to 0x…]` makes a V3 token's tax recipient the dev's LP splitter (GangLiquiditySplitter, `lp-burn-v1`, the buy-back splitter's sibling): `--lp` % of the recipient's part of the tax is added to the token's PancakeSwap pair as liquidity whose LP goes to 0xdead (locked for good), the rest goes to the dev or `--lp-to`. After graduation the keeper adds it in chunks (half buys the token, all of it goes back in with the matching quote; one per 4 minutes). The ratio and payee change as for `--buyback` (a raise at once, a cut after a 3-day notice; the payee at once). Same quotes as `--buyback` / `--split`. `gang lp …` shows and drives it. Live on BSC mainnet (factory `0xE0436867dAFcf42Ee1418083251a9B8B61F0C248`, allowed by the platform's Safe on 2026-10-31, built in) and testnet set 10 (factory `0xA729C60FCa0Bd0D28a55E22126D3fE412AA41591`).
|
|
16
|
+
|
|
15
17
|
## Install
|
|
16
18
|
|
|
17
19
|
Node ≥ 18. Also install Binance Agentic Wallet CLI (`baw`):
|
|
@@ -107,6 +109,8 @@ gang create … --buy-tax 3 --sell-tax 3 --buyback 50 [--buyback-to 0x…] [--de
|
|
|
107
109
|
gang buyback status|set|set-payee|apply --token 0x… [--pct 0-100] [--to 0x…] # the buy-back splitter: ratio (raise now, cut after 3 days), payee (at once), what waits
|
|
108
110
|
gang create … --buy-tax 3 --sell-tax 3 --split self:60,0x…:30,0x…:10 [--dev-buy …] # V3: the recipient's part of the tax split among 1–10 payees at fixed shares (% summing to 100; self = you)
|
|
109
111
|
gang split status|distribute|release|set-payee|bind --token 0x… [--asset 0x…] [--index <i>] [--to 0x…] # the split module: payees (slot --index from 0), what waits / is owed; split by hand; a payee moves its own slot
|
|
112
|
+
gang create … --buy-tax 3 --sell-tax 3 --lp 70 [--lp-to 0x…] [--dev-buy …] # V3: the recipient's part of the tax 70% added to the pool as liquidity (LP to 0xdead), the rest to you (or --lp-to)
|
|
113
|
+
gang lp status|set|set-payee|apply|bind|release|add --token 0x… [--pct 0-100] [--to 0x…] [--slippage 1] # the LP splitter: ratio, payee, what is set aside, the next chunk; add = one chunk now (anyone)
|
|
110
114
|
gang create --fair … [--shares <n>] --bond <quote> [--bond-hold …] --bond-days <7-90> # 打新: create (dev shares) → bond
|
|
111
115
|
gang execute --request-id <id>
|
|
112
116
|
gang tx --pending # trades approved in the Binance App: found by the exact call previewed, then as below
|
|
@@ -218,13 +222,13 @@ take MCP servers instead of a shell (Claude Desktop / Code, Cursor, …). Each t
|
|
|
218
222
|
|
|
219
223
|
| Tool | Runs |
|
|
220
224
|
|---|---|
|
|
221
|
-
| `gang_help` | this CLI's whole help (every command, every flag) and the full rules (0.17.2+): what an agent with no skill installed reads before a create, launch, bond, buyback, split, mint or withdraw |
|
|
225
|
+
| `gang_help` | this CLI's whole help (every command, every flag) and the full rules (0.17.2+): what an agent with no skill installed reads before a create, launch, bond, buyback, split, lp, mint or withdraw |
|
|
222
226
|
| `gang_preflight`, `gang_hot`, `gang_new`, `gang_near_grad`, `gang_info`, `gang_status`, `gang_portfolio`, `gang_notes`, `gang_agents` | the read commands of the same name (`gang_portfolio`: 0.17.6+) |
|
|
223
227
|
| `gang_tx` | `gang tx --hash …`: decode a tx, publish its queued note; `pending: true` = `gang tx --pending`, the trades approved in the Binance App (no hash needed) |
|
|
224
228
|
| `gang_watch` | `gang watch` until `maxEvents` (default 1) or `timeout` (default 50s, at most 30m): returns `{ events, meta }`, `timedOut: true` when nothing came; call it again to keep waiting |
|
|
225
229
|
| `gang_buy`, `gang_sell`, `gang_follow` | the trade previews (nothing is sent), with all their flags: `useWbnb` / `useQuote` / `payBnb`, `settleFirst`, … |
|
|
226
230
|
| `gang_execute` | `gang execute --request-id …`: only after the user's yes on that preview |
|
|
227
|
-
| `gang_cli` | every other command as an argument list: `create` (also `--fair` and a launch in one command), `mint`, `withdraw`, `claim`, `release`, `quote`, `list`, `upload-logo`, `bond …`, `buyback …`, `split …`, `v3 income`, `version`, and the flags no other tool takes (`--calldata`, `--from`, …) |
|
|
231
|
+
| `gang_cli` | every other command as an argument list: `create` (also `--fair` and a launch in one command), `mint`, `withdraw`, `claim`, `release`, `quote`, `list`, `upload-logo`, `bond …`, `buyback …`, `split …`, `lp …`, `v3 income`, `version`, and the flags no other tool takes (`--calldata`, `--from`, …) |
|
|
228
232
|
|
|
229
233
|
```json
|
|
230
234
|
{ "mcpServers": { "gang": { "command": "gang", "args": ["mcp"] } } }
|
|
@@ -281,8 +285,9 @@ timed-out `gang_execute`, check `gang_status` / the wallet history instead of ex
|
|
|
281
285
|
| `GANG_FLY_PAD` / `GANG_TESTNET_FLY_PAD` | GangFlywheelPad (铸币飞轮). Defaults: mainnet `0x631e…B029` (open since 2026-10-30), testnet set 2 `0xD648…951c` |
|
|
282
286
|
| `GANG_BOND` / `GANG_TESTNET_BOND` | GangBond (creator bonds, `gang bond`). Defaults: mainnet `0xe92d…14E4` (since 2026-10-29, CLI 0.16.2+), testnet `0xd6a8…1086` |
|
|
283
287
|
| `GANG_SPLIT_FACTORY` / `GANG_TESTNET_SPLIT_FACTORY` | GangSplitModuleFactory (`--split`). Defaults: mainnet `0x27e0…067c` (since 2026-10-30, CLI 0.19.0+), testnet set 10 `0x5F7d…567E` |
|
|
288
|
+
| `GANG_LP_FACTORY` / `GANG_TESTNET_LP_FACTORY` | GangLiquiditySplitterFactory (`--lp`). Defaults (CLI 0.20.0+): mainnet `0xE043…C248` (since 2026-10-31), testnet set 10 `0xA729…1591` |
|
|
284
289
|
| `GANG_ROUTER` / `GANG_TESTNET_ROUTER` | GangRouter proxy (native-BNB V3 buys / mints, and every PancakeSwap trade of a graduated token); old name `GANG_ROUTER_TESTNET` still works. Defaults: mainnet `0xE040…79C4`, testnet set 10 `0x6bB6…C9F6` |
|
|
285
290
|
|
|
286
291
|
## Version
|
|
287
292
|
|
|
288
|
-
`0.
|
|
293
|
+
`0.20.0` · repo [gangfun/cli](https://github.com/gangfun/cli) · published to [npm](https://www.npmjs.com/package/@gangfun/cli) on push to `main`
|
package/README.zh-CN.md
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
|
|
13
13
|
**多人分账收款(0.19.0+):** `gang create … --buy-tax … --sell-tax … --split self:60,0x…:30,0x…:10` 把 V3 币的税收接收地址设成 dev 自己的分账模块(GangSplitModule,`split-v1`):接收地址那份税按固定比例分给 1–10 个地址,名单和比例永久不能改(dev 和平台都改不了;每个收款人只能把自己那一份换到别的地址)。`self` 表示发币钱包(也可以写 `me`);收款人序号和合约一致,从 0 开始(`--index`)。报价币只能是 keeper 会分账的:WBNB(默认)、GANG 或发射台 QuoteRegistry 里的报价币(其他的在克隆前就拒绝,和 `--buyback` 一样);转进模块的其他资产仍可用 `gang split distribute` 手动分。`gang split …` 查看和操作。已在 BSC 主网(工厂 `0x27e08271E52B2D129c824CD245e69471a8d3067c`,2026-10-30 平台多签已放行,已内置)和测试网第 10 套可用。
|
|
14
14
|
|
|
15
|
+
**自动加池子收款(0.20.0+):** `gang create … --buy-tax … --sell-tax … --lp 70 [--lp-to 0x…]` 把 V3 币的税收接收地址设成 dev 自己的加池合约(GangLiquiditySplitter,`lp-burn-v1`,和回购合约同一套规则):接收地址那份税的 `--lp`% 加进这个币的 PancakeSwap 池子做流动性,LP 打进 0xdead 永久锁定,其余给 dev(或 `--lp-to` 指定的地址)。毕业后由 keeper 分块加池(一半买币,买到的币全部连同对应的报价币放回池子;每 4 分钟最多一块)。比例和收款地址的改法同 `--buyback`(提高立即生效,下调 3 天公告后生效;收款地址立即生效)。报价币要求同 `--buyback` / `--split`。`gang lp …` 查看和操作。已在 BSC 主网(工厂 `0xE0436867dAFcf42Ee1418083251a9B8B61F0C248`,2026-10-31 平台多签已放行,已内置)和测试网第 10 套(工厂 `0xA729C60FCa0Bd0D28a55E22126D3fE412AA41591`)可用。
|
|
16
|
+
|
|
15
17
|
## 安装
|
|
16
18
|
|
|
17
19
|
Node ≥ 18。另需 `baw`:
|
|
@@ -87,6 +89,8 @@ gang create … --buy-tax 3 --sell-tax 3 --buyback 50 [--buyback-to 0x…] [--de
|
|
|
87
89
|
gang buyback status|set|set-payee|apply --token 0x… [--pct 0-100] [--to 0x…] # 回购合约:比例(提高立即生效,下调 3 天后)、收款地址(立即生效)、待回购金额
|
|
88
90
|
gang create … --buy-tax 3 --sell-tax 3 --split self:60,0x…:30,0x…:10 [--dev-buy …] # V3:接收地址那份税按固定比例分给 1–10 个地址(百分比合计 100;self = 你自己)
|
|
89
91
|
gang split status|distribute|release|set-payee|bind --token 0x… [--asset 0x…] [--index <i>] [--to 0x…] # 分账模块:名单(--index 从 0 开始)、待分和欠款;手动分账;收款人换自己的地址
|
|
92
|
+
gang create … --buy-tax 3 --sell-tax 3 --lp 70 [--lp-to 0x…] [--dev-buy …] # V3:接收地址那份税 70% 加进池子做流动性(LP 打进 0xdead),其余给你(或 --lp-to 指定的地址)
|
|
93
|
+
gang lp status|set|set-payee|apply|bind|release|add --token 0x… [--pct 0-100] [--to 0x…] [--slippage 1] # 加池合约:比例、收款地址、待加池金额、下一块;add = 现在手动加一块(任何人)
|
|
90
94
|
gang create --fair … [--shares <n>] --bond <数量> [--bond-hold …] --bond-days <7-90> # 打新:发币(含 dev 份额)→ 押金
|
|
91
95
|
gang execute --request-id <id>
|
|
92
96
|
gang tx --pending # 在 Binance App 里批准过的交易:按预览时的调用自动找到交易,再按下面这条处理
|
|
@@ -194,13 +198,13 @@ gang agents --window 30d --sort follow
|
|
|
194
198
|
|
|
195
199
|
| 工具 | 对应 |
|
|
196
200
|
|---|---|
|
|
197
|
-
| `gang_help` | 本 CLI 的完整帮助(所有命令、所有参数)和完整规则(0.17.2+):没装 skill 的 Agent
|
|
201
|
+
| `gang_help` | 本 CLI 的完整帮助(所有命令、所有参数)和完整规则(0.17.2+):没装 skill 的 Agent 在发币、一条命令发射、押金、回购、分账、自动加池子、打新认购 / 撤回之前先读它 |
|
|
198
202
|
| `gang_preflight`、`gang_hot`、`gang_new`、`gang_near_grad`、`gang_info`、`gang_status`、`gang_portfolio`、`gang_notes`、`gang_agents` | 同名的只读命令(`gang_portfolio`:0.17.6+) |
|
|
199
203
|
| `gang_tx` | `gang tx --hash …`:解码交易,发布排队中的想法;`pending: true` 即 `gang tx --pending`,找出在 Binance App 里批准过的交易(不用哈希) |
|
|
200
204
|
| `gang_watch` | `gang watch`,等到 `maxEvents`(默认 1)条或 `timeout`(默认 50s,最长 30m):返回 `{ events, meta }`,没等到时带 `timedOut: true`,再调一次接着等 |
|
|
201
205
|
| `gang_buy`、`gang_sell`、`gang_follow` | 交易预览(不发送),对应命令的参数都有:`useWbnb` / `useQuote` / `payBnb`、`settleFirst` 等 |
|
|
202
206
|
| `gang_execute` | `gang execute --request-id …`:用户对这份预览点头之后才调 |
|
|
203
|
-
| `gang_cli` | 其余所有命令,按参数数组传:`create`(也包括 `--fair` 和一条命令发射)、`mint`、`withdraw`、`claim`、`release`、`quote`、`list`、`upload-logo`、`bond …`、`buyback …`、`split …`、`v3 income`、`version`,以及其他工具没有的参数(`--calldata`、`--from` 等) |
|
|
207
|
+
| `gang_cli` | 其余所有命令,按参数数组传:`create`(也包括 `--fair` 和一条命令发射)、`mint`、`withdraw`、`claim`、`release`、`quote`、`list`、`upload-logo`、`bond …`、`buyback …`、`split …`、`lp …`、`v3 income`、`version`,以及其他工具没有的参数(`--calldata`、`--from` 等) |
|
|
204
208
|
|
|
205
209
|
```json
|
|
206
210
|
{ "mcpServers": { "gang": { "command": "gang", "args": ["mcp"] } } }
|
|
@@ -245,8 +249,9 @@ Claude Code:`claude mcp add gang -- gang mcp`。同一台机器上 `baw` 要
|
|
|
245
249
|
| `GANG_FLY_PAD` / `GANG_TESTNET_FLY_PAD` | GangFlywheelPad(铸币飞轮)。默认:主网 `0x631e…B029`(2026-10-30 起开放),测试网第 2 套 `0xD648…951c` |
|
|
246
250
|
| `GANG_BOND` / `GANG_TESTNET_BOND` | GangBond(押金承诺,`gang bond`)。默认:主网 `0xe92d…14E4`(2026-10-29 起,CLI 0.16.2+),测试网 `0xd6a8…1086` |
|
|
247
251
|
| `GANG_SPLIT_FACTORY` / `GANG_TESTNET_SPLIT_FACTORY` | GangSplitModuleFactory(`--split`)。默认:主网 `0x27e0…067c`(2026-10-30 起,CLI 0.19.0+),测试网第 10 套 `0x5F7d…567E` |
|
|
252
|
+
| `GANG_LP_FACTORY` / `GANG_TESTNET_LP_FACTORY` | GangLiquiditySplitterFactory(`--lp`)。默认(CLI 0.20.0+):主网 `0xE043…C248`(2026-10-31 起),测试网第 10 套 `0xA729…1591` |
|
|
248
253
|
| `GANG_ROUTER` / `GANG_TESTNET_ROUTER` | GangRouter 代理(用原生 BNB 买 V3 / 打新,以及已毕业币的所有外盘买卖);旧名 `GANG_ROUTER_TESTNET` 仍可用。默认:主网 `0xE040…79C4`,测试网第 10 套 `0x6bB6…C9F6` |
|
|
249
254
|
|
|
250
255
|
## 版本
|
|
251
256
|
|
|
252
|
-
`0.
|
|
257
|
+
`0.20.0` · [gangfun/cli](https://github.com/gangfun/cli) · push 到 `main` 自动发布到 [npm](https://www.npmjs.com/package/@gangfun/cli)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gangfun/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "Gang launchpad CLI for Binance Agentic Wallet agents: create on GangLaunchpad (untaxed or tax tokens), 打新 fair mint, PancakeSwap pool trades, LaunchpadV2 and legacy Soft/U/S trade.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
package/src/discover.js
CHANGED
|
@@ -94,7 +94,10 @@ function gangRow(r, quoteUsdOf) {
|
|
|
94
94
|
volume24hUsd: inUsd('volume24hUsd', 'volume24hQuote'), trades24h: num(r.trades24h), trades: num(r.trades),
|
|
95
95
|
holders: r.holders != null ? num(r.holders) : fair ? num(r.participants) : null,
|
|
96
96
|
...(fair && { sharePrice: w(r.sharePrice), sharesLeft: num(r.sharesLeft), minWalletsLeft: num(r.minWalletsLeft) }),
|
|
97
|
-
|
|
97
|
+
// mintPaused: gang.fun's code for why post-launch mints are refused now (below_average, …), null when not paused
|
|
98
|
+
...(r.track === 'fly' && {
|
|
99
|
+
status: r.status ?? null, postMint: !!r.postMint, mintPaused: r.mintPaused ?? null, baseQuota: num(r.baseQuota), inviteBonus: num(r.inviteBonus),
|
|
100
|
+
}),
|
|
98
101
|
createdAt: r.createdAt, ageMin: r.createdAt ? Math.floor((now() - r.createdAt) / 60) : null,
|
|
99
102
|
lastTradeAt: r.lastTradeAt || r.lastActivityAt || null, creatorHandle: r.creatorHandle || null, logoUrl: r.logoUrl || null,
|
|
100
103
|
website: r.website && !websiteError(r.website) ? r.website : null,
|
|
@@ -183,8 +186,8 @@ const hint = (t) => {
|
|
|
183
186
|
// mint); a filled sale waits for its launch, a refund-only one only sells back
|
|
184
187
|
if (t.track === 'fly' && t.status === 'filled') return `gang info --token ${t.address}`
|
|
185
188
|
if (t.track === 'fly' && t.status === 'refund') return `gang withdraw --token ${t.address} --all`
|
|
186
|
-
//
|
|
187
|
-
if (t.track === 'fly' && (!t.graduated || t.postMint)) return `gang mint --token ${t.address} --shares <n>`
|
|
189
|
+
// launched with post-launch minting paused (gang.fun's mintPaused, from the same reads as the pad): the pool, not a mint
|
|
190
|
+
if (t.track === 'fly' && (!t.graduated || (t.postMint && !t.mintPaused))) return `gang mint --token ${t.address} --shares <n>`
|
|
188
191
|
if (t.graduated) return `gang buy --token ${t.address} ${amount}` // the PancakeSwap pool, through GangRouter
|
|
189
192
|
if (t.track === 'fair') return `gang mint --token ${t.address} --shares <n>`
|
|
190
193
|
if (t.track === 'v3') return `gang buy --token ${t.address} ${amount}`
|
package/src/index.js
CHANGED
|
@@ -21,6 +21,7 @@ import { runV3, v3Ctx, V3_EVENT_ABIS } from './v3.js'
|
|
|
21
21
|
import { runBond } from './bond.js'
|
|
22
22
|
import { runBuyback } from './buyback.js'
|
|
23
23
|
import { runSplit, SPLIT_EVENT_ABIS } from './split.js'
|
|
24
|
+
import { runLp, LP_EVENT_ABIS } from './lp.js'
|
|
24
25
|
import { runFly, flyCtx, isFlyToken, FLY_EVENT_ABIS, FLY_CREATE_FLAGS } from './fly.js'
|
|
25
26
|
import { FAIR_DEV_BUY, isLaunch, LAUNCH_FLAGS, runLaunch } from './launch.js'
|
|
26
27
|
import { poolPayBnb, poolTrade } from './pool.js'
|
|
@@ -317,7 +318,7 @@ U / S pads) and run that kind's trade. Results of V3 / 打新 / 铸币飞轮 tok
|
|
|
317
318
|
600, cap ×1, standard tier, supply ×100; steady = no post-launch mint, quota 100, no
|
|
318
319
|
invites, dev cut 0, sell tax 1. Flags override the preset; checkConfig runs first.
|
|
319
320
|
--dev-shares (default 1, up to quota and max-per-tx) are minted in the create. No
|
|
320
|
-
--bond / --buyback / --dev-buy (phase 1)
|
|
321
|
+
--bond / --buyback / --split / --lp / --dev-buy (phase 1)
|
|
321
322
|
FLY (铸币飞轮; also gang fly <sub>): gang mint --token <a> --shares <n> [--ref <inviter>] [--min-shares <n>] [--slippage 2]
|
|
322
323
|
[--use-wbnb]: before launch the sale price (+ mint fee; WBNB sales pay BNB in one tx,
|
|
323
324
|
--use-wbnb from WBNB); after launch mintPost: minTokensOut = the preview less
|
|
@@ -350,9 +351,18 @@ U / S pads) and run that kind's trade. Results of V3 / 打新 / 铸币飞轮 tok
|
|
|
350
351
|
nobody (not you, not the platform) can change the payees or shares later; a payee can
|
|
351
352
|
only move its own slot (gang split set-payee). Steps: clone your split module
|
|
352
353
|
(GangSplitModuleFactory; listed as a recipient in the same tx) → create with it as the
|
|
353
|
-
recipient → bind → the rest of the launch. --split, --buyback and --recipient
|
|
354
|
-
exclusive. Quote: WBNB (default), GANG or one listed in the pad's QuoteRegistry
|
|
355
|
-
(the quotes the keeper splits; others are refused before the clone)
|
|
354
|
+
recipient → bind → the rest of the launch. --split, --buyback, --lp and --recipient
|
|
355
|
+
are exclusive. Quote: WBNB (default), GANG or one listed in the pad's QuoteRegistry
|
|
356
|
+
only (the quotes the keeper splits; others are refused before the clone)
|
|
357
|
+
gang create … --buy-tax <1-5> --sell-tax <1-5> --lp <0-100> [--lp-to <addr>] [--dev-buy … [--bond …]]
|
|
358
|
+
V3, taxed, auto-liquidity: --lp % of the recipient's part of the tax is added to the
|
|
359
|
+
token's PancakeSwap pair as liquidity whose LP goes to 0xdead (locked for good), the
|
|
360
|
+
rest to you (or --lp-to <addr>; changeable later with gang lp set-payee). After
|
|
361
|
+
graduation the keeper adds it in chunks (half buys the token, all of it goes back in
|
|
362
|
+
with the matching quote). Steps: clone your LP splitter (GangLiquiditySplitterFactory;
|
|
363
|
+
listed as a recipient in the same tx) → create with it as the recipient → bind → the
|
|
364
|
+
rest of the launch. Not with --buyback, --split or --recipient. Quote: WBNB
|
|
365
|
+
(default), GANG or one listed in the pad's QuoteRegistry only
|
|
356
366
|
gang create --fair … [--shares <n>] --bond <quote> [--bond-hold …] --bond-days <7-90>
|
|
357
367
|
打新: create (the dev's --shares are bought in it) → bond. Progress is read from the
|
|
358
368
|
chain (a token this wallet created with this symbol since the plan); a run that finds
|
|
@@ -446,11 +456,30 @@ SPLIT (a V3 token whose recipient is a split module, split-v1; GANG_SPLIT_FACTOR
|
|
|
446
456
|
Gas: the CLI never sets a gas limit on these; let the wallet estimate it. Each payee's
|
|
447
457
|
push needs ~365k gas left before it, so the limit is far above the gas used; a lower
|
|
448
458
|
limit reverts PushStarved. --testnet, --calldata, --from as in gang v3
|
|
459
|
+
LP (a V3 token whose recipient is an LP splitter, lp-burn-v1; GANG_LP_FACTORY / GANG_TESTNET_LP_FACTORY):
|
|
460
|
+
gang lp status --token <addr> ratio (lpPct), a cut asked for (applies from / lapses after), quote set aside for the
|
|
461
|
+
pool (lpLeft) and not split yet (unsplit), the payee and what is owed to it, the next
|
|
462
|
+
chunk (previewAdd) or what it waits for, the last chunk (lastAddAt)
|
|
463
|
+
gang lp set --token <addr> --pct <0-100>
|
|
464
|
+
dev only: a higher share applies at once; a lower one after a 3-day notice
|
|
465
|
+
gang lp set-payee --token <addr> --to <addr>
|
|
466
|
+
dev only: the part not added to the pool goes to --to from now on (at once)
|
|
467
|
+
gang lp apply --token <addr> anyone: apply a cut whose notice ran (within 7 days, or it lapses)
|
|
468
|
+
gang lp bind --token <addr> | gang lp release --token <addr>
|
|
469
|
+
anyone: bind the splitter to its token (the launch does it) / push the payee what a
|
|
470
|
+
failed payment left owed
|
|
471
|
+
gang lp add --token <addr> [--slippage 1]
|
|
472
|
+
anyone: one chunk now, as the keeper does (graduated tokens; one per 4 minutes; ≤ 0.5%
|
|
473
|
+
of the pair's quote reserve; waits for a 10-minute average and skips when the price is
|
|
474
|
+
> 2% above it): minimum tokens = previewAdd less --slippage. Not ready: a call that
|
|
475
|
+
only records the price. Gas: a chunk takes ~0.53–0.75M; the CLI never sets a gas
|
|
476
|
+
limit, let the wallet estimate it. --testnet, --calldata, --from as in gang v3
|
|
449
477
|
gang execute --request-id <id> broadcast a previewed call
|
|
450
478
|
gang tx --pending a trade that waited for Binance App approval (execute: pendingConfirmation): find its tx
|
|
451
479
|
in the wallet's history by the exact call previewed, then as gang tx --hash below
|
|
452
480
|
gang tx --hash <0x..> [--testnet] wait for receipt and decode Gang events: V2 / Soft / U / S, GangLaunchpad (V3 /
|
|
453
|
-
打新, tax router, vaults), GangFlywheelPad (铸币飞轮 pad and tax handler)
|
|
481
|
+
打新, tax router, vaults), GangFlywheelPad (铸币飞轮 pad and tax handler), split modules
|
|
482
|
+
and LP splitters (publishes a queued --note; mainnet). GangLaunchpad events
|
|
454
483
|
carry units: "raw" (amounts in wei, 18 decimals; bps / shares as is)
|
|
455
484
|
|
|
456
485
|
--note is PUBLIC: shown on gang.fun next to the trade. Its hash goes into the tx calldata, so it is provably written
|
|
@@ -984,7 +1013,7 @@ const V3_CREATE_FLAGS = ['buy-tax', 'sell-tax', 'dividend', 'recipient']
|
|
|
984
1013
|
const FAIR_CREATE_FLAGS = ['raise', 'cap', 'hold', 'mint-fee', 'exit-fee', 'shares']
|
|
985
1014
|
// 铸币飞轮 settings beyond those it shares with 打新 (--raise / --hold / --mint-fee / --exit-fee) and V3 (--sell-tax)
|
|
986
1015
|
const FLY_ONLY_FLAGS = FLY_CREATE_FLAGS.filter((f) => !['raise', 'hold', 'mint-fee', 'exit-fee', 'sell-tax'].includes(f))
|
|
987
|
-
const FLY_NO_BOND = '铸币飞轮 tokens take no GangBond, buy-back splitter, split module or --dev-buy (phase 1): the creator mints its shares in the create with --dev-shares <n>'
|
|
1016
|
+
const FLY_NO_BOND = '铸币飞轮 tokens take no GangBond, buy-back splitter, split module, LP splitter or --dev-buy (phase 1): the creator mints its shares in the create with --dev-shares <n>'
|
|
988
1017
|
/** The flags a 铸币飞轮 create refuses (gang create --fly and gang fly create alike). */
|
|
989
1018
|
function checkFlyCreate() {
|
|
990
1019
|
if (flag('fair')) fail('give --fly (铸币飞轮) or --fair (打新), not both')
|
|
@@ -1018,11 +1047,11 @@ function create() {
|
|
|
1018
1047
|
// commands whose JSON result carries `update`; `watch` streams NDJSON and help is plain text
|
|
1019
1048
|
const UPDATE_CHECKED = new Set(['version', '--version', '-v', 'preflight', 'list', 'hot', 'new', 'near-grad', 'notes', 'agents', 'token', 'info', 'status', 'portfolio', 'quote',
|
|
1020
1049
|
'buy', 'follow', 'sell', 'claim', 'mint', 'withdraw', 'release', 'upload-logo', 'create', 'execute', 'tx', 'fair', 'v3', 'bond',
|
|
1021
|
-
'buyback', 'split', 'fly'])
|
|
1050
|
+
'buyback', 'split', 'lp', 'fly'])
|
|
1022
1051
|
// gang tx decodes these beside the V2 / Soft / U / S pads' events (GangLaunchpad: both kinds; the tax router; the vaults)
|
|
1023
|
-
const GANG_EVENT_ABIS = [...V3_EVENT_ABIS, ...FAIR_EVENT_ABIS, ...FLY_EVENT_ABIS, ...SPLIT_EVENT_ABIS]
|
|
1052
|
+
const GANG_EVENT_ABIS = [...V3_EVENT_ABIS, ...FAIR_EVENT_ABIS, ...FLY_EVENT_ABIS, ...SPLIT_EVENT_ABIS, ...LP_EVENT_ABIS]
|
|
1024
1053
|
|
|
1025
|
-
/** gang bond / gang buyback / gang split on a 铸币飞轮 token: those contracts refuse it, so say why before any step. */
|
|
1054
|
+
/** gang bond / gang buyback / gang split / gang lp on a 铸币飞轮 token: those contracts refuse it, so say why before any step. */
|
|
1026
1055
|
async function refuseFly(what) {
|
|
1027
1056
|
const token = opt('token')
|
|
1028
1057
|
if (!isAddress(token ?? '')) return
|
|
@@ -1113,7 +1142,7 @@ async function main() {
|
|
|
1113
1142
|
// a 打新 dev buys with --shares in the create itself: say so here, not "add --bond" (which would only lead to that)
|
|
1114
1143
|
if (launchKind === 'fair' && flag('dev-buy')) fail(FAIR_DEV_BUY)
|
|
1115
1144
|
const lone = LAUNCH_FLAGS.find((f) => flag(f))
|
|
1116
|
-
if (lone) fail(`--${lone} only applies to a launch in one command: add --bond <quote>${launchKind === 'fair' ? '' : ' (or --dev-buy <quote> / --buyback <pct> / --split <addr>:<pct>,…)'}`)
|
|
1145
|
+
if (lone) fail(`--${lone} only applies to a launch in one command: add --bond <quote>${launchKind === 'fair' ? '' : ' (or --dev-buy <quote> / --buyback <pct> / --split <addr>:<pct>,… / --lp <pct>)'}`)
|
|
1117
1146
|
}
|
|
1118
1147
|
switch (cmd) {
|
|
1119
1148
|
case 'fair':
|
|
@@ -1136,6 +1165,9 @@ async function main() {
|
|
|
1136
1165
|
case 'split':
|
|
1137
1166
|
await refuseFly('a split module')
|
|
1138
1167
|
return runSplit(args[1], { opt, flag, out, fail, summarize: summarizePreview })
|
|
1168
|
+
case 'lp':
|
|
1169
|
+
await refuseFly('an LP splitter')
|
|
1170
|
+
return runLp(args[1], { opt, flag, out, fail, summarize: summarizePreview })
|
|
1139
1171
|
case 'version':
|
|
1140
1172
|
case '--version':
|
|
1141
1173
|
case '-v':
|
package/src/launch.js
CHANGED
|
@@ -9,6 +9,7 @@ import { walletFor } from './fair.js'
|
|
|
9
9
|
import { parseAmount, parseIntIn, step } from './steps.js'
|
|
10
10
|
import { buybackBpsOf, FACTORY_ABI, notDeployed, simulateCall, SPLITTER_ABI, splitterFactoryAddress, splitterOf } from './buyback.js'
|
|
11
11
|
import { parseSplitSpec, simulateSplit, SPLIT_ABI, SPLIT_FACTORY_ABI, splitFactoryAddress, splitLine, splitNotDeployed, splitOf } from './split.js'
|
|
12
|
+
import { LP_ABI, LP_FACTORY_ABI, lpBpsOf, lpFactoryAddress, lpNotDeployed, lpOf, simulateLp } from './lp.js'
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* One command for a launch: `gang create … [--buyback <pct>] [--dev-buy <quote> [--bond <quote> [--bond-hold <tokens|N%|all>]
|
|
@@ -31,7 +32,11 @@ import { parseSplitSpec, simulateSplit, SPLIT_ABI, SPLIT_FACTORY_ABI, splitFacto
|
|
|
31
32
|
* --split <addr>:<pct>[,…] (V3, taxed): the same three steps with GangSplitModuleFactory — the dev's split module (fixed
|
|
32
33
|
* payees and shares, split-v1) is cloned at predict(dev, salt), named as the recipient, then bound. The plan keeps which
|
|
33
34
|
* module it cloned (`module: 'split'`; a plan without it is a --buyback one), and a re-run with other payees or shares is
|
|
34
|
-
* refused rather than starting over.
|
|
35
|
+
* refused rather than starting over.
|
|
36
|
+
* --lp <pct> [--lp-to <addr>] (V3, taxed): the same three steps with GangLiquiditySplitterFactory — the dev's LP splitter
|
|
37
|
+
* (lp-burn-v1: --lp % of the recipient's part added to the pair as liquidity, the LP to 0xdead) is cloned at
|
|
38
|
+
* predict(dev, salt), named as the recipient, then bound (`module: 'lp'` in the plan). A launch keeps the ratio and payee
|
|
39
|
+
* it began with. --buyback, --split, --lp and --recipient are exclusive (each sets the recipient).
|
|
35
40
|
*/
|
|
36
41
|
|
|
37
42
|
const LAUNCH_DIR = process.env.GANG_LAUNCH_DIR || join(dirname(DIR), 'launch')
|
|
@@ -55,6 +60,8 @@ const REGISTRY_ABI = parseAbi(['function quoteRegistry() view returns (address)'
|
|
|
55
60
|
* and the buy-back part is stuck for good (GangBond re-review L-1, 2026-10-29; splitter v3 has the same pricing).
|
|
56
61
|
* --split takes the same quotes: a quote that calls the receiver back on transfer would let one payee make every split
|
|
57
62
|
* run out of gas, and the keeper splits only these quotes anyway (split spec §2.4).
|
|
63
|
+
* --lp takes the same quotes: the keeper adds liquidity only over these, and an unlisted quote may tax or block the
|
|
64
|
+
* transfers into the pair every chunk makes.
|
|
58
65
|
* null when trusted; otherwise the failure to report.
|
|
59
66
|
*/
|
|
60
67
|
const UNTRUSTED = {
|
|
@@ -66,6 +73,10 @@ const UNTRUSTED = {
|
|
|
66
73
|
why: '--split needs WBNB, GANG or a quote listed in the pad\'s QuoteRegistry: the keeper splits only those quotes, and an unlisted quote may call the receiver back on transfer, letting one payee make every split run out of gas',
|
|
67
74
|
hint: 'drop --quote (WBNB), use a listed quote, or launch without --split',
|
|
68
75
|
},
|
|
76
|
+
lp: {
|
|
77
|
+
why: '--lp needs WBNB, GANG or a quote listed in the pad\'s QuoteRegistry: the keeper adds liquidity only over those quotes, and an unlisted quote may tax or block the transfers into the pair every chunk makes',
|
|
78
|
+
hint: 'drop --quote (WBNB), use a listed quote, or launch without --lp',
|
|
79
|
+
},
|
|
69
80
|
}
|
|
70
81
|
export async function untrustedBuybackQuote(read, net, quote, mode = 'buyback') {
|
|
71
82
|
if (!isAddress(quote ?? '')) return { error: '--quote must be a 0x address', got: quote ?? null }
|
|
@@ -84,13 +95,15 @@ export async function untrustedBuybackQuote(read, net, quote, mode = 'buyback')
|
|
|
84
95
|
}
|
|
85
96
|
}
|
|
86
97
|
|
|
87
|
-
export const LAUNCH_FLAGS = ['dev-buy', 'bond', 'bond-hold', 'bond-days', 'buyback', 'buyback-to', 'split', 'restart']
|
|
98
|
+
export const LAUNCH_FLAGS = ['dev-buy', 'bond', 'bond-hold', 'bond-days', 'buyback', 'buyback-to', 'split', 'lp', 'lp-to', 'restart']
|
|
88
99
|
const NOTE_FLAGS = ['note', 'conf', 'reveal-after']
|
|
89
100
|
/** `gang fair create --dev-buy`, with or without --bond (index.js stops the lone flag, runLaunch the chained one). */
|
|
90
101
|
export const FAIR_DEV_BUY = 'a 打新 dev buys its shares in the create itself: use --shares <n> (not --dev-buy)'
|
|
91
102
|
|
|
92
103
|
/** The run asks for a chained launch (`kind` 'v3' | 'fair'). */
|
|
93
|
-
export const isLaunch = (kind, flag) => flag('bond') || flag('buyback') || flag('split') || (kind === 'v3' && flag('dev-buy'))
|
|
104
|
+
export const isLaunch = (kind, flag) => flag('bond') || flag('buyback') || flag('split') || flag('lp') || (kind === 'v3' && flag('dev-buy'))
|
|
105
|
+
/** The recipient modules a launch can clone (their flags), at most one per launch. */
|
|
106
|
+
const MODULE_FLAGS = ['buyback', 'split', 'lp']
|
|
94
107
|
|
|
95
108
|
const planPath = (key) => join(LAUNCH_DIR, `${createHash('sha256').update(key).digest('hex').slice(0, 32)}.json`)
|
|
96
109
|
|
|
@@ -135,7 +148,10 @@ export async function runLaunch(kind, { io, runV3, runFair, runBond, padNotes })
|
|
|
135
148
|
if (kind === 'fair' && flag('dev-buy')) fail(FAIR_DEV_BUY)
|
|
136
149
|
if (kind === 'fair' && flag('buyback')) fail('--buyback is for V3 tokens: it makes the tax recipient a buy-back splitter, and a 打新 token has no recipient')
|
|
137
150
|
if (kind === 'fair' && flag('split')) fail('--split is for V3 tokens: it makes the tax recipient a split module, and a 打新 token has no recipient')
|
|
151
|
+
if (kind === 'fair' && flag('lp')) fail('--lp is for V3 tokens: it makes the tax recipient an LP splitter, and a 打新 token has no recipient')
|
|
138
152
|
if (flag('split') && flag('buyback')) fail('give --split or --buyback, not both: each makes the tax recipient its own module (a split with a buy-back is not supported)')
|
|
153
|
+
const mods = MODULE_FLAGS.filter((f) => flag(f))
|
|
154
|
+
if (mods.length > 1) fail(`give one of --${mods.join(' / --')}, not several: each makes the tax recipient its own module`)
|
|
139
155
|
|
|
140
156
|
// everything checked before the create, so a launch never stops half way on a bad flag
|
|
141
157
|
const devBuy = kind === 'v3' && flag('dev-buy') ? parseAmount(fail, 'dev-buy', opt('dev-buy')) : null
|
|
@@ -193,12 +209,32 @@ export async function runLaunch(kind, { io, runV3, runFair, runBond, padNotes })
|
|
|
193
209
|
}
|
|
194
210
|
split = { ...spec, factory }
|
|
195
211
|
}
|
|
196
|
-
|
|
212
|
+
|
|
213
|
+
// --lp: a taxed V3 token whose recipient is the dev's LP splitter (auto-liquidity, the LP to 0xdead)
|
|
214
|
+
let lp = null
|
|
215
|
+
if (flag('lp-to') && !flag('lp')) fail('--lp-to <addr> goes with --lp <pct>: it names where the part not added to the pool goes')
|
|
216
|
+
if (flag('lp')) {
|
|
217
|
+
const zero = (f) => /^0+(\.0+)?$/.test(opt(f) ?? '')
|
|
218
|
+
if (!flag('buy-tax') || !flag('sell-tax') || (zero('buy-tax') && zero('sell-tax'))) {
|
|
219
|
+
fail('--lp needs a taxed token: add --buy-tax and --sell-tax (each 1–5, in %); the liquidity is paid from the tax')
|
|
220
|
+
}
|
|
221
|
+
if (flag('recipient')) fail('--lp makes the recipient your LP splitter: leave --recipient out')
|
|
222
|
+
if (/^0*100(\.0+)?$/.test(opt('dividend', '0'))) fail('--dividend 100 leaves nothing for the recipient, so nothing to add to the pool: lower it or drop --lp')
|
|
223
|
+
const factory = lpFactoryAddress(testnet)
|
|
224
|
+
if (!factory) fail(lpNotDeployed(testnet))
|
|
225
|
+
let payee = null
|
|
226
|
+
if (flag('lp-to')) {
|
|
227
|
+
payee = opt('lp-to')
|
|
228
|
+
if (!isAddress(payee ?? '') || payee === zeroAddress) fail('--lp-to must be a 0x address, checksummed or all lowercase (where the part not added to the pool goes; leave it out for your own wallet)', { got: payee ?? null })
|
|
229
|
+
}
|
|
230
|
+
lp = { bps: lpBpsOf(fail, opt('lp')), factory, payee }
|
|
231
|
+
}
|
|
232
|
+
const mod = buyback ? 'buyback' : split ? 'split' : lp ? 'lp' : null
|
|
197
233
|
|
|
198
234
|
const client = createPublicClient({ chain: net.chain, transport: rpcTransport(net.rpcs) })
|
|
199
235
|
const read = (address, abi, functionName, args = []) => client.readContract({ address, abi, functionName, args })
|
|
200
236
|
const key = [net.chainId, net.pad, me.toLowerCase(), kind, name, symbol].join('|')
|
|
201
|
-
const cloneStep = buyback ? 'buyback-splitter' : 'split-module'
|
|
237
|
+
const cloneStep = buyback ? 'buyback-splitter' : split ? 'split-module' : 'lp-splitter'
|
|
202
238
|
const steps = [...(mod ? [cloneStep] : []), kind === 'v3' ? 'create' : 'create (dev shares included)', ...(mod ? ['bind'] : []),
|
|
203
239
|
...(devBuy ? ['dev-buy'] : []), ...(bond ? ['bond'] : [])]
|
|
204
240
|
const rerun = 're-run this same command after executing it'
|
|
@@ -210,13 +246,14 @@ export async function runLaunch(kind, { io, runV3, runFair, runBond, padNotes })
|
|
|
210
246
|
|
|
211
247
|
// ---- a launch keeps the mode it began with (the create, once built, is never redone by a changed flag)
|
|
212
248
|
const created = plan?.startCount !== undefined
|
|
213
|
-
// the module this plan cloned: 'split' when it says so, else a --buyback splitter (plans from before --split)
|
|
214
|
-
const planMod = plan?.salt ? (plan.module === 'split'
|
|
249
|
+
// the module this plan cloned: 'split' / 'lp' when it says so, else a --buyback splitter (plans from before --split)
|
|
250
|
+
const planMod = plan?.salt ? (plan.module === 'split' || plan.module === 'lp' ? plan.module : 'buyback') : null
|
|
251
|
+
const modNoun = { buyback: 'splitter', split: 'split module', lp: 'LP splitter' }
|
|
215
252
|
if (mod && created && !plan.splitter) {
|
|
216
253
|
return fail(`this launch was created without --${mod} (its recipient is fixed): run it again without --${mod}, or add --restart for a new token`)
|
|
217
254
|
}
|
|
218
255
|
if (planMod && mod !== planMod && (!created || mod)) {
|
|
219
|
-
return fail(`this launch began with --${planMod} (its ${planMod
|
|
256
|
+
return fail(`this launch began with --${planMod} (its ${modNoun[planMod]} is cloned or on the way): run it again with --${planMod}${mod ? ` instead of --${mod}` : ''}, or add --restart${mod ? '' : ` without it`}`)
|
|
220
257
|
}
|
|
221
258
|
|
|
222
259
|
// ---- buy-back splitter: cloned for the dev before the create, at predict(dev, plan.salt)
|
|
@@ -304,6 +341,54 @@ export async function runLaunch(kind, { io, runV3, runFair, runBond, padNotes })
|
|
|
304
341
|
}
|
|
305
342
|
}
|
|
306
343
|
|
|
344
|
+
// ---- LP splitter: cloned for the dev before the create, at predict(dev, plan.salt)
|
|
345
|
+
if (lp && !created) {
|
|
346
|
+
if (!plan?.salt) {
|
|
347
|
+
const refused = await untrustedBuybackQuote(read, net, flag('quote') ? opt('quote') : net.wbnb, 'lp')
|
|
348
|
+
if (refused) {
|
|
349
|
+
const { error, ...extra } = refused
|
|
350
|
+
return fail(error, extra)
|
|
351
|
+
}
|
|
352
|
+
if ((await client.getCode({ address: lp.factory }) ?? '0x') === '0x') {
|
|
353
|
+
return fail(`GangLiquiditySplitterFactory has no code at ${lp.factory} on ${testnet ? 'the BSC testnet' : 'BSC mainnet'} yet: launch without --lp for now${process.env[testnet ? 'GANG_TESTNET_LP_FACTORY' : 'GANG_LP_FACTORY'] ? ` (or fix ${testnet ? 'GANG_TESTNET_LP_FACTORY' : 'GANG_LP_FACTORY'})` : ''}`, { factory: lp.factory })
|
|
354
|
+
}
|
|
355
|
+
const salt = `0x${randomBytes(32).toString('hex')}`
|
|
356
|
+
const at = await read(lp.factory, LP_FACTORY_ABI, 'predict', [me, salt])
|
|
357
|
+
if (lp.payee && lp.payee.toLowerCase() === at.toLowerCase()) return fail('--lp-to: the payee cannot be the LP splitter itself', { splitter: at })
|
|
358
|
+
const args = [lp.bps, salt, lp.payee ?? zeroAddress]
|
|
359
|
+
const sim = await simulateLp(client, me, lp.factory, LP_FACTORY_ABI, 'create', args)
|
|
360
|
+
if (sim.failed) return out({ success: false, step: 'lp-splitter', factory: lp.factory, ...tag('lp-splitter'), ...sim.failed })
|
|
361
|
+
writePlan(key, { ...base, salt, splitter: at, factory: lp.factory, module: 'lp' })
|
|
362
|
+
const data = encodeFunctionData({ abi: LP_FACTORY_ABI, functionName: 'create', args })
|
|
363
|
+
return out({
|
|
364
|
+
...step({ chainId: net.chainId }, { from: me, to: lp.factory, data }, {
|
|
365
|
+
step: 'lp-splitter', chainId: Number(net.chainId), factory: lp.factory, lpPct: lp.bps / 100,
|
|
366
|
+
splitter: at, payee: lp.payee ?? me,
|
|
367
|
+
note: `clones your LP splitter (listed as a tax recipient in the same tx): ${lp.bps / 100}% of the recipient's part is added to the token's PancakeSwap pair as liquidity, the LP sent to 0xdead (locked for good), the rest goes to ${lp.payee ? `${lp.payee} (--lp-to)` : 'you'}. After graduation the keeper adds it in chunks. Later a raise applies at once, a cut only after a 3-day notice; the payee can be changed at once (gang lp set-payee)`,
|
|
368
|
+
}, flag('calldata'), io.summarize),
|
|
369
|
+
...tag('lp-splitter', { splitter: at, next: `${rerun}: it then builds the create with the LP splitter as the recipient` }),
|
|
370
|
+
})
|
|
371
|
+
}
|
|
372
|
+
if ((await client.getCode({ address: plan.splitter }) ?? '0x') === '0x') {
|
|
373
|
+
return out({
|
|
374
|
+
success: false, ...tag('lp-splitter', { splitter: plan.splitter }), error: 'the LP splitter is not on chain yet',
|
|
375
|
+
hint: `if the clone was executed, wait for it to land and ${rerun.replace(' after executing it', '')}; if it was not, add --restart to build it again`,
|
|
376
|
+
})
|
|
377
|
+
}
|
|
378
|
+
const s = await lpOf(read, plan.splitter)
|
|
379
|
+
if (!s || s.dev.toLowerCase() !== me.toLowerCase() || s.token) {
|
|
380
|
+
return fail('the LP splitter at this launch\'s address is not an unbound LP splitter of this wallet: add --restart', { splitter: plan.splitter })
|
|
381
|
+
}
|
|
382
|
+
if (s.lpBps !== lp.bps) {
|
|
383
|
+
return fail(`this launch's LP splitter adds ${s.lpPct}% to the pool, not ${lp.bps / 100}%: run it again with --lp ${s.lpPct}, or add --restart for a new splitter (gang lp set changes it after the create)`, { splitter: plan.splitter })
|
|
384
|
+
}
|
|
385
|
+
const wantPayee = (lp.payee ?? me).toLowerCase()
|
|
386
|
+
if (s.payee.toLowerCase() !== wantPayee) {
|
|
387
|
+
const was = s.payee.toLowerCase() === me.toLowerCase() ? 'leave --lp-to out' : `--lp-to ${s.payee}`
|
|
388
|
+
return fail(`this launch's LP splitter pays ${s.payee}, not ${lp.payee ?? me}: run it again with ${was}, or add --restart for a new splitter (gang lp set-payee changes it after the create)`, { splitter: plan.splitter })
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
307
392
|
// ---- create
|
|
308
393
|
if (!created) {
|
|
309
394
|
const startCount = (await read(net.pad, PAD_ABI, 'tokenCount')).toString()
|
|
@@ -353,7 +438,9 @@ export async function runLaunch(kind, { io, runV3, runFair, runBond, padNotes })
|
|
|
353
438
|
const stepIo = (over) => ({ ...io, ...argsWith(io, { ...over, token }, [...LAUNCH_FLAGS, ...NOTE_FLAGS, 'name', 'symbol']) })
|
|
354
439
|
const bal = await read(token, ERC20_ABI, 'balanceOf', [me])
|
|
355
440
|
const isSplit = plan.module === 'split'
|
|
356
|
-
const
|
|
441
|
+
const isLp = plan.module === 'lp'
|
|
442
|
+
const buybackState = () => (plan.splitter && !isSplit && !isLp ? splitterOf(read, plan.splitter) : null)
|
|
443
|
+
const lpState = () => (plan.splitter && isLp ? lpOf(read, plan.splitter, { pad: net.pad }) : null)
|
|
357
444
|
const splitState = () => (plan.splitter && isSplit ? splitOf(read, plan.splitter, { wbnb: net.wbnb, ref: `--token ${token}${testnet ? ' --testnet' : ''}` }) : null)
|
|
358
445
|
|
|
359
446
|
// ---- done: the report only, whatever happened to the balance or the bond since
|
|
@@ -366,17 +453,19 @@ export async function runLaunch(kind, { io, runV3, runFair, runBond, padNotes })
|
|
|
366
453
|
if (bb) done.buyback = bb
|
|
367
454
|
const sp = await splitState()
|
|
368
455
|
if (sp) done.split = sp
|
|
456
|
+
const lps = await lpState()
|
|
457
|
+
if (lps) done.lp = lps
|
|
369
458
|
if (!bond) return out({ ...done, note: `launched: gang ${kind} info --token ${token}${testnet ? ' --testnet' : ''}` })
|
|
370
459
|
return runBond('status', { ...stepIo({}), out: (o) => out({ ...done, bondStatus: o, note: `launched and bonded: gang bond status --token ${token}${testnet ? ' --testnet' : ''}` }) })
|
|
371
460
|
}
|
|
372
461
|
if (plan.done) return report()
|
|
373
462
|
|
|
374
|
-
// ---- bind the splitter / split module to the token (anyone may; the launch does it right after the create)
|
|
463
|
+
// ---- bind the splitter / split module / LP splitter to the token (anyone may; the launch does it right after the create)
|
|
375
464
|
if (plan.splitter) {
|
|
376
|
-
const abi = isSplit ? SPLIT_ABI : SPLITTER_ABI
|
|
465
|
+
const abi = isSplit ? SPLIT_ABI : isLp ? LP_ABI : SPLITTER_ABI
|
|
377
466
|
const bound = await read(plan.splitter, abi, 'token')
|
|
378
467
|
if (bound === zeroAddress) {
|
|
379
|
-
const sim = await (isSplit ? simulateSplit : simulateCall)(client, me, plan.splitter, abi, 'bind', [token])
|
|
468
|
+
const sim = await (isSplit ? simulateSplit : isLp ? simulateLp : simulateCall)(client, me, plan.splitter, abi, 'bind', [token])
|
|
380
469
|
if (sim.failed) return out({ success: false, step: 'bind', ...tag('bind', { token }), ...sim.failed })
|
|
381
470
|
const data = encodeFunctionData({ abi, functionName: 'bind', args: [token] })
|
|
382
471
|
return out({
|
|
@@ -384,13 +473,15 @@ export async function runLaunch(kind, { io, runV3, runFair, runBond, padNotes })
|
|
|
384
473
|
step: 'bind', chainId: Number(net.chainId), token, ...(isSplit ? { module: plan.splitter } : { splitter: plan.splitter }),
|
|
385
474
|
note: isSplit
|
|
386
475
|
? 'ties the split module to this token for good: the keeper then splits its quote among the payees'
|
|
387
|
-
:
|
|
476
|
+
: isLp
|
|
477
|
+
? 'ties the LP splitter to this token for good: its pair is where the liquidity goes (from graduation on)'
|
|
478
|
+
: 'ties the splitter to this token for good (what it buys back and burns)',
|
|
388
479
|
}, flag('calldata'), io.summarize),
|
|
389
480
|
...tag('bind', { token, next: `${rerun}${devBuy ? ': it continues with the dev buy' : bond ? ': it continues with the bond' : ': the launch is then done'}` }),
|
|
390
481
|
})
|
|
391
482
|
}
|
|
392
483
|
if (bound.toLowerCase() !== token.toLowerCase()) {
|
|
393
|
-
return out({ success: false, ...tag('bind', { token }), error: `the ${isSplit ? 'split module' : 'splitter'} is bound to another token`, [isSplit ? 'module' : 'splitter']: plan.splitter, boundTo: bound })
|
|
484
|
+
return out({ success: false, ...tag('bind', { token }), error: `the ${isSplit ? 'split module' : isLp ? 'LP splitter' : 'splitter'} is bound to another token`, [isSplit ? 'module' : 'splitter']: plan.splitter, boundTo: bound })
|
|
394
485
|
}
|
|
395
486
|
}
|
|
396
487
|
|
package/src/lp.js
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { createPublicClient, parseAbi, encodeFunctionData, formatUnits, hexToString, isAddress, maxUint128, zeroAddress } from 'viem'
|
|
2
|
+
import { padNets, NOT_ON_MAINNET, rpcTransport } from './gangpad.js'
|
|
3
|
+
import { walletFor } from './fair.js'
|
|
4
|
+
import { parseNum, revertOf as revertIn, step } from './steps.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `gang lp …` and `gang create … --lp <pct> [--lp-to <addr>]` — GangLiquiditySplitter (dev 税按比例自动加池子,
|
|
8
|
+
* `lp-burn-v1`): a V3 token's tax recipient that splits each payment between liquidity added to the token's PancakeSwap
|
|
9
|
+
* pair, its LP sent to 0xdead (locked for good, like the graduation LP), and the dev's payee (the dev unless it names
|
|
10
|
+
* another address; `gang lp set-payee`). The buy-back splitter's sibling (GangBuybackSplitter v4): the same split, ratio
|
|
11
|
+
* rules, payee and pace; only the chunk differs. GangLiquiditySplitterFactory clones one per token for the dev
|
|
12
|
+
* (`create(bps, salt, payee)`, at `predict(dev, salt)`) and has GangHandlerAdmin list it, so the dev names it as the
|
|
13
|
+
* recipient at create (launch.js does the three steps: clone → create → bind, as for --buyback).
|
|
14
|
+
* The ratio: a raise applies at once, a cut 3 days after it is asked for (then anyone applies it within 7 days, or it
|
|
15
|
+
* lapses). The keeper adds liquidity in chunks (`work`: one per 4 minutes, ≤ 0.5% of the pair's quote reserve, none
|
|
16
|
+
* while the price is > 2% above the pair's 10-minute average): half buys the token, all of it goes back into the pair
|
|
17
|
+
* with the matching quote, and the pair mints the LP to 0xdead. Both pool taxes apply, so part of the other half stays
|
|
18
|
+
* for the next chunk.
|
|
19
|
+
* Gas: a chunk takes ~0.53–0.75M (the deposit lets the tax handler sell a chunk of its tax first). The CLI never sets a
|
|
20
|
+
* gas limit: the wallet / node estimates it; a fixed or trimmed limit can revert.
|
|
21
|
+
* Env: GANG_LP_FACTORY / GANG_TESTNET_LP_FACTORY override the built-in factory addresses.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
// BSC 56: deployed 2026-10-31, allowed on GangHandlerAdmin by the platform's Safe the same day
|
|
25
|
+
export const MAINNET_LP_FACTORY = '0xE0436867dAFcf42Ee1418083251a9B8B61F0C248'
|
|
26
|
+
// BSC 97, set 10 (docs/TESTNET-LP-MODULE-2026-10-30.md)
|
|
27
|
+
export const TESTNET_LP_FACTORY = '0xA729C60FCa0Bd0D28a55E22126D3fE412AA41591'
|
|
28
|
+
export const LP_TYPE = 'lp-burn-v1'
|
|
29
|
+
const BPS = 10_000n
|
|
30
|
+
const CHUNK_GAP_S = 4 * 60
|
|
31
|
+
|
|
32
|
+
const ERRORS = [
|
|
33
|
+
'error ZeroAddress()', 'error NotClone()', 'error NotFactory()', 'error AlreadyInitialized()', 'error BadBps()',
|
|
34
|
+
'error NotDev()', 'error AlreadyBound()', 'error NotBound()', 'error NotCurve()', 'error NotCreator()',
|
|
35
|
+
'error NotRecipient()', 'error NoProposal()', 'error NotDue()', 'error CutLapsed()', 'error NothingOwed()',
|
|
36
|
+
'error NothingToAdd()', 'error AddTooSoon()', 'error NotTradable()', 'error Slippage()', 'error NotSweepable()',
|
|
37
|
+
'error BadPayee()',
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
export const LP_FACTORY_ABI = parseAbi([
|
|
41
|
+
'function create(uint16 lpBps, bytes32 salt, address payee) returns (address splitter)',
|
|
42
|
+
'function predict(address dev, bytes32 salt) view returns (address)',
|
|
43
|
+
'function pad() view returns (address)',
|
|
44
|
+
'error NotAgent()', 'error WrongHandler()',
|
|
45
|
+
'event Created(address indexed dev, address indexed splitter, uint16 lpBps, address payee)',
|
|
46
|
+
...ERRORS,
|
|
47
|
+
])
|
|
48
|
+
|
|
49
|
+
export const LP_ABI = parseAbi([
|
|
50
|
+
'function moduleType() view returns (bytes32)',
|
|
51
|
+
'function dev() view returns (address)',
|
|
52
|
+
'function payee() view returns (address)',
|
|
53
|
+
'function token() view returns (address)',
|
|
54
|
+
'function quote() view returns (address)',
|
|
55
|
+
'function lpBps() view returns (uint16)',
|
|
56
|
+
'function pendingCut() view returns (bool live, uint16 bps, uint64 at)',
|
|
57
|
+
'function lpLeft() view returns (uint256)',
|
|
58
|
+
'function unsplit() view returns (uint256)',
|
|
59
|
+
'function devOwed() view returns (uint256)',
|
|
60
|
+
'function lastAddAt() view returns (uint64)',
|
|
61
|
+
'function previewAdd() view returns (bool ready, uint256 chunk, uint256 tokensOut)',
|
|
62
|
+
'function previewWork() view returns (bool due, uint256 minOut)',
|
|
63
|
+
'function bind(address token)',
|
|
64
|
+
'function setLpBps(uint16 newBps)',
|
|
65
|
+
'function applyLpBps()',
|
|
66
|
+
'function setPayee(address newPayee)',
|
|
67
|
+
'function split()',
|
|
68
|
+
'function releaseDev() returns (uint256)',
|
|
69
|
+
'function addChunk(uint256 minTokensOut) returns (uint256 quoteIn, uint256 tokensIn, uint256 liquidity)',
|
|
70
|
+
'function work(uint256 minOut)',
|
|
71
|
+
'function sweep(address asset)',
|
|
72
|
+
'event Bound(address indexed token, address indexed quote)',
|
|
73
|
+
'event Split(uint256 incoming, uint256 toLp, uint256 toDev)',
|
|
74
|
+
'event DevOwed(uint256 amount)',
|
|
75
|
+
'event DevReleased(uint256 amount)',
|
|
76
|
+
'event Shortfall(uint256 amount)',
|
|
77
|
+
'event LpBpsSet(uint16 oldBps, uint16 newBps)',
|
|
78
|
+
'event LpBpsProposed(uint16 newBps, uint64 at)',
|
|
79
|
+
'event LpBpsProposalCancelled(uint16 newBps)',
|
|
80
|
+
'event LiquidityAdded(uint256 quoteIn, uint256 tokensIn, uint256 liquidity, uint256 left)',
|
|
81
|
+
'event Swept(address indexed asset, uint256 amount)',
|
|
82
|
+
'event PayeeSet(address indexed oldPayee, address indexed newPayee)',
|
|
83
|
+
...ERRORS,
|
|
84
|
+
])
|
|
85
|
+
/** gang tx decodes these (the factory's Created and the splitter's events). */
|
|
86
|
+
export const LP_EVENT_ABIS = [LP_FACTORY_ABI, LP_ABI]
|
|
87
|
+
|
|
88
|
+
const ERC20_ABI = parseAbi(['function symbol() view returns (string)'])
|
|
89
|
+
const PAD_ABI = parseAbi([
|
|
90
|
+
'function taxConfigOf(address token) view returns (uint16 buyTaxBps, uint16 sellTaxBps, uint16 dividendBps, address recipient)',
|
|
91
|
+
'function curves(address token) view returns (address creator, address quote, uint128 realQuote, uint128 sold, uint128 gradAmt, uint128 virtualQuote, bool graduated, uint16 buyTaxBps, uint16 sellTaxBps, uint16 dividendBps, address pair, address refPair)',
|
|
92
|
+
])
|
|
93
|
+
|
|
94
|
+
export const LP_GAS_NOTE = 'let the wallet estimate the gas limit and do not set or trim it: a chunk takes about 0.53–0.75M gas (the deposit lets the tax handler sell a chunk of its tax first); too low a limit reverts'
|
|
95
|
+
|
|
96
|
+
export const HINTS = {
|
|
97
|
+
NotAgent: 'only an Agent can create a V3 token, so only an Agent gets an LP splitter',
|
|
98
|
+
NotFactory: 'this LP factory is not allowed on the platform\'s GangHandlerAdmin: it cannot list an LP splitter as a tax recipient. If GANG_LP_FACTORY / GANG_TESTNET_LP_FACTORY is set, unset it to use the built-in factory; otherwise launch without --lp',
|
|
99
|
+
BadBps: 'the LP share is 0–100%',
|
|
100
|
+
BadPayee: 'the payee cannot be the LP splitter itself',
|
|
101
|
+
ZeroAddress: 'the zero address cannot be the payee',
|
|
102
|
+
NotDev: 'only the dev this LP splitter was made for can change its ratio or payee',
|
|
103
|
+
NotCreator: 'the token was not created by this LP splitter\'s dev',
|
|
104
|
+
NotRecipient: 'the token does not pay its tax to this LP splitter',
|
|
105
|
+
NotCurve: 'not a V3 (curve) token on this pad',
|
|
106
|
+
AlreadyBound: 'the LP splitter is bound to a token already',
|
|
107
|
+
NotBound: 'the LP splitter is not bound to a token yet (gang lp bind --token <the token>)',
|
|
108
|
+
NotDue: 'the 3-day notice of this cut has not run yet',
|
|
109
|
+
CutLapsed: 'the cut was not applied within 7 days after its notice and has lapsed: ask for it again',
|
|
110
|
+
NoProposal: 'no cut asked for',
|
|
111
|
+
NothingOwed: 'nothing is owed to the payee',
|
|
112
|
+
NothingToAdd: 'no quote is set aside for the pool yet (lpLeft 0): it fills as the tax arrives',
|
|
113
|
+
AddTooSoon: 'one chunk per 4 minutes: wait until 4 minutes after the last one (lastAddAt)',
|
|
114
|
+
NotTradable: 'the token has not graduated: chunks start once it trades in its PancakeSwap pair',
|
|
115
|
+
Slippage: 'the pool price moved since the preview (fewer tokens than the minimum): run gang lp add again',
|
|
116
|
+
}
|
|
117
|
+
export const revertOf = (e) => revertIn(e, [LP_ABI, LP_FACTORY_ABI], HINTS)
|
|
118
|
+
|
|
119
|
+
/** Dry-run a call; { failed } with the revert when it would not pass. */
|
|
120
|
+
export async function simulateLp(client, from, address, abi, functionName, args = []) {
|
|
121
|
+
try {
|
|
122
|
+
const { result } = await client.simulateContract({ account: from, address, abi, functionName, args })
|
|
123
|
+
return { result }
|
|
124
|
+
} catch (e) {
|
|
125
|
+
const r = revertOf(e)
|
|
126
|
+
return { failed: r ? { reverted: true, ...r } : { reverted: false, error: e.shortMessage || e.message.split('\n')[0] } }
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function lpFactoryAddress(testnet) {
|
|
131
|
+
return (testnet ? process.env.GANG_TESTNET_LP_FACTORY || TESTNET_LP_FACTORY
|
|
132
|
+
: process.env.GANG_LP_FACTORY || MAINNET_LP_FACTORY) || null
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export const lpNotDeployed = (testnet) =>
|
|
136
|
+
`GangLiquiditySplitterFactory is not deployed on ${testnet ? 'the BSC testnet' : 'BSC mainnet'} in this CLI version: set ${testnet ? 'GANG_TESTNET_LP_FACTORY' : 'GANG_LP_FACTORY'} to its address`
|
|
137
|
+
|
|
138
|
+
/** --lp <pct> / --pct (0–100, the share of the recipient's part added to the pool) in bps. */
|
|
139
|
+
export const lpBpsOf = (fail, raw, name = 'lp') => Math.round(parseNum(fail, name, raw, 0, 100) * 100)
|
|
140
|
+
|
|
141
|
+
const pct = (bps) => Number(bps) / 100
|
|
142
|
+
const iso = (s) => (Number(s) > 0 ? new Date(Number(s) * 1000).toISOString() : null)
|
|
143
|
+
// the pad takes 18-decimal quotes only
|
|
144
|
+
const q = (x) => formatUnits(x, 18)
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* The splitter's state for printing, from the raw reads (pure: unit-tested). `raw`: { splitter, dev, payee, token, quote,
|
|
148
|
+
* bps, cut: [live, bps, at], left, unsplit, owed, lastAddAt, preview: [ready, chunk, tokensOut] | null,
|
|
149
|
+
* work: [due, minOut] | null, graduated: bool | null, quoteSymbol, now (unix s) }.
|
|
150
|
+
*/
|
|
151
|
+
export function formatLp(raw) {
|
|
152
|
+
const token = raw.token && raw.token !== zeroAddress ? raw.token : null
|
|
153
|
+
const quote = token && raw.quote && raw.quote !== zeroAddress ? raw.quote : null
|
|
154
|
+
const toDev = String(raw.payee).toLowerCase() === String(raw.dev).toLowerCase()
|
|
155
|
+
const bps = Number(raw.bps)
|
|
156
|
+
const [live, cutBps, cutAt] = raw.cut ?? [false, 0, 0n]
|
|
157
|
+
const [ready, chunk, tokensOut] = raw.preview ?? [false, 0n, 0n]
|
|
158
|
+
const last = Number(raw.lastAddAt ?? 0n)
|
|
159
|
+
const now = Number(raw.now ?? Math.floor(Date.now() / 1000))
|
|
160
|
+
// what lpLeft is once the waiting quote is split (as the contract's _lpAfterSplit, without a shortfall)
|
|
161
|
+
const setAside = BigInt(raw.left) + (BigInt(raw.unsplit) * BigInt(bps)) / BPS
|
|
162
|
+
let waiting = null
|
|
163
|
+
if (!ready) {
|
|
164
|
+
waiting = !token ? 'not bound to a token yet (gang lp bind --token <the token>)'
|
|
165
|
+
: raw.graduated === false ? 'the token has not graduated: chunks start once it trades in its PancakeSwap pair (the pool tax starts then too)'
|
|
166
|
+
: setAside === 0n ? 'nothing set aside for the pool yet: it fills as the tax arrives'
|
|
167
|
+
: last > 0 && now < last + CHUNK_GAP_S ? `one chunk per 4 minutes: the next from ${iso(last + CHUNK_GAP_S)}`
|
|
168
|
+
: 'the price check: a 10-minute average of the pair\'s price (the next call records it, if none is running) and a price no more than 2% above it'
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
splitter: raw.splitter, moduleType: LP_TYPE, dev: raw.dev, payee: raw.payee, token, quote, ...(quote && raw.quoteSymbol && { quoteSymbol: raw.quoteSymbol }),
|
|
172
|
+
lpPct: pct(bps), lpBps: bps,
|
|
173
|
+
pendingCut: live ? { toPct: pct(cutBps), appliesFrom: iso(cutAt), lapsesAfter: iso(Number(cutAt) + 7 * 86400) } : null,
|
|
174
|
+
lpLeft: q(raw.left), unsplit: q(raw.unsplit), devOwed: q(raw.owed),
|
|
175
|
+
lastAddAt: iso(last),
|
|
176
|
+
nextChunk: ready ? { quoteChunk: q(chunk), buyHalf: q(chunk / 2n), tokensBought: formatUnits(tokensOut, 18) } : null,
|
|
177
|
+
...(waiting && { nextChunkWaitsFor: waiting }),
|
|
178
|
+
...(raw.work && token && { keeper: { due: !!raw.work[0] } }),
|
|
179
|
+
note: `${pct(bps)}% of each tax payment to this recipient is added to the token's PancakeSwap pair as liquidity whose LP goes to 0xdead (locked for good), the rest goes to ${toDev ? 'the dev' : `the payee ${raw.payee}`}. `
|
|
180
|
+
+ 'The keeper adds it in chunks (one per 4 minutes, at most 0.5% of the pair\'s quote reserve, none while the price is more than 2% above its 10-minute average; it waits until at least 0.05% of that reserve is set aside): half buys the token, all of it goes back into the pair with the matching quote. Both pool taxes apply, so part of each chunk\'s quote stays for the next. '
|
|
181
|
+
+ 'A raise of the share applies at once, a cut only 3 days after it is asked for; the dev can change the payee at once (gang lp set-payee)',
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The splitter's state when `addr` is a GangLiquiditySplitter (lp-burn-v1); null when it is not. `pad`: to read graduation. */
|
|
186
|
+
export async function lpOf(read, addr, { pad } = {}) {
|
|
187
|
+
if (!addr || addr === zeroAddress) return null
|
|
188
|
+
let type
|
|
189
|
+
try { type = await read(addr, LP_ABI, 'moduleType') } catch { return null }
|
|
190
|
+
if (hexToString(type, { size: 32 }).replace(/\0+$/, '') !== LP_TYPE) return null
|
|
191
|
+
const [dev, payee, token, quote, bps, cut, left, unsplit, owed, lastAddAt] = await Promise.all(
|
|
192
|
+
['dev', 'payee', 'token', 'quote', 'lpBps', 'pendingCut', 'lpLeft', 'unsplit', 'devOwed', 'lastAddAt'].map((f) => read(addr, LP_ABI, f)))
|
|
193
|
+
const bound = token !== zeroAddress
|
|
194
|
+
const [preview, work, graduated, quoteSymbol] = await Promise.all([
|
|
195
|
+
bound ? read(addr, LP_ABI, 'previewAdd').catch(() => null) : null,
|
|
196
|
+
bound ? read(addr, LP_ABI, 'previewWork').catch(() => null) : null,
|
|
197
|
+
bound && pad ? read(pad, PAD_ABI, 'curves', [token]).then((c) => c[6]).catch(() => null) : null,
|
|
198
|
+
bound ? read(quote, ERC20_ABI, 'symbol').catch(() => null) : null,
|
|
199
|
+
])
|
|
200
|
+
return formatLp({ splitter: addr, dev, payee, token, quote, bps, cut, left, unsplit, owed, lastAddAt, preview, work, graduated, quoteSymbol })
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function lpCtx(testnet) {
|
|
204
|
+
const net = padNets('v3')[testnet ? 'testnet' : 'mainnet']
|
|
205
|
+
if (!net.pad) throw new Error(NOT_ON_MAINNET)
|
|
206
|
+
const client = createPublicClient({ chain: net.chain, transport: rpcTransport(net.rpcs) })
|
|
207
|
+
return { ...net, client, read: (address, abi, functionName, args = []) => client.readContract({ address, abi, functionName, args }) }
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const SUBS = ['status', 'set', 'set-payee', 'apply', 'bind', 'release', 'add']
|
|
211
|
+
const USAGE = 'usage: gang lp <status|set|set-payee|apply|bind|release|add> --token <addr> [--pct <0-100>] [--to <addr>] [--slippage 1] [--testnet] — see gang help'
|
|
212
|
+
|
|
213
|
+
/** `gang lp <sub>`: the LP splitter of a V3 token (its tax recipient), found from --token. */
|
|
214
|
+
export async function runLp(sub, { opt, flag, out, fail, summarize }) {
|
|
215
|
+
if (!SUBS.includes(sub)) return fail(USAGE, { got: sub ?? null })
|
|
216
|
+
const testnet = flag('testnet')
|
|
217
|
+
const rawOnly = flag('calldata')
|
|
218
|
+
let ctx
|
|
219
|
+
try { ctx = lpCtx(testnet) } catch (e) { return fail(e.message) }
|
|
220
|
+
const token = opt('token')
|
|
221
|
+
if (!isAddress(token ?? '')) fail('--token must be a V3 token address (0x…)', { got: token ?? null })
|
|
222
|
+
const chainId = Number(ctx.chainId)
|
|
223
|
+
let recipient
|
|
224
|
+
try { recipient = (await ctx.read(ctx.pad, PAD_ABI, 'taxConfigOf', [token]))[3] } catch {
|
|
225
|
+
return fail(`not a V3 token on this pad (${testnet ? 'BSC testnet' : 'BSC mainnet; add --testnet for a testnet token'})`, { token, chainId })
|
|
226
|
+
}
|
|
227
|
+
const s = await lpOf(ctx.read, recipient, { pad: ctx.pad })
|
|
228
|
+
if (!s) return fail('this token\'s tax recipient is not an LP splitter (lp-burn-v1)', { token, recipient: recipient === zeroAddress ? null : recipient })
|
|
229
|
+
const tn = testnet ? ' --testnet' : ''
|
|
230
|
+
// the token pays this splitter, which is bound to another token: it adds liquidity only to that one's pair
|
|
231
|
+
const warning = s.token && s.token.toLowerCase() !== token.toLowerCase()
|
|
232
|
+
? `this token pays its tax to the LP splitter, but it is bound to another token (${s.token}): the liquidity goes to that token's pair` : null
|
|
233
|
+
const me = () => walletFor(ctx, opt('from'))
|
|
234
|
+
const send = async (functionName, args, extra) => {
|
|
235
|
+
const sim = await simulateLp(ctx.client, me(), s.splitter, LP_ABI, functionName, args)
|
|
236
|
+
if (sim.failed) return out({ success: false, step: extra.step, ...sim.failed })
|
|
237
|
+
const data = encodeFunctionData({ abi: LP_ABI, functionName, args })
|
|
238
|
+
// no gas field: the wallet / node estimates it (LP_GAS_NOTE)
|
|
239
|
+
return out(step(ctx, { from: me(), to: s.splitter, data }, { chainId, token, splitter: s.splitter, ...extra }, rawOnly, summarize))
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (sub === 'status') return out({ success: true, chainId, ...s, ...(s.token === null && { bound: false }), ...(warning && { warning }) })
|
|
243
|
+
|
|
244
|
+
if (sub === 'bind') {
|
|
245
|
+
if (s.token) return fail('already bound', { boundTo: s.token, ...(warning && { warning }) })
|
|
246
|
+
return send('bind', [token], { step: 'bind', note: 'anyone may bind (once); the token must be the dev\'s and pay its tax to this splitter. Its pair is where the liquidity goes' })
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (sub === 'set') {
|
|
250
|
+
if (me().toLowerCase() !== s.dev.toLowerCase()) return fail(HINTS.NotDev, { wallet: me(), dev: s.dev })
|
|
251
|
+
if (!flag('pct')) fail('--pct <0-100> required: the new LP share')
|
|
252
|
+
const bps = lpBpsOf(fail, opt('pct'), 'pct')
|
|
253
|
+
return send('setLpBps', [bps], bps >= s.lpBps
|
|
254
|
+
? { step: 'set-lp', fromPct: s.lpPct, toPct: bps / 100, note: `applies at once (quote that arrived before is split at the old share first)${s.pendingCut ? ' and cancels the pending cut' : ''}` }
|
|
255
|
+
: {
|
|
256
|
+
step: 'ask-cut', fromPct: s.lpPct, toPct: bps / 100, appliesFromAbout: new Date(Date.now() + 3 * 86400_000).toISOString(),
|
|
257
|
+
note: `a cut waits 3 days (holders see it coming), then anyone runs gang lp apply --token ${token}${tn} within 7 days or it lapses${s.pendingCut ? '; this replaces the cut already asked for' : ''}`,
|
|
258
|
+
})
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (sub === 'set-payee') {
|
|
262
|
+
if (me().toLowerCase() !== s.dev.toLowerCase()) return fail('only the dev this LP splitter was made for can change its payee', { wallet: me(), dev: s.dev })
|
|
263
|
+
const to = opt('to')
|
|
264
|
+
if (!isAddress(to ?? '') || to === zeroAddress) fail('--to <0x…> required (checksummed or all lowercase): the address the dev\'s part goes to from now on', { got: to ?? null })
|
|
265
|
+
if (to.toLowerCase() === s.splitter.toLowerCase()) return fail(HINTS.BadPayee, { to })
|
|
266
|
+
if (to.toLowerCase() === s.payee.toLowerCase()) return fail('that is the payee already', { payee: s.payee })
|
|
267
|
+
return send('setPayee', [to], {
|
|
268
|
+
step: 'set-payee', fromPayee: s.payee, toPayee: to,
|
|
269
|
+
note: 'applies at once (the dev\'s own share; holders are not affected). Quote that arrived before is split to the current payee first; what is owed goes to the new one',
|
|
270
|
+
})
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (sub === 'apply') {
|
|
274
|
+
if (!s.pendingCut) return fail(HINTS.NoProposal, { lpPct: s.lpPct })
|
|
275
|
+
if (Date.parse(s.pendingCut.appliesFrom) > Date.now()) return fail(HINTS.NotDue, { appliesFrom: s.pendingCut.appliesFrom })
|
|
276
|
+
return send('applyLpBps', [], { step: 'apply-cut', fromPct: s.lpPct, toPct: s.pendingCut.toPct, note: 'anyone may apply a cut once its notice ran' })
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (sub === 'release') {
|
|
280
|
+
if (!(Number(s.devOwed) > 0)) return fail(HINTS.NothingOwed)
|
|
281
|
+
return send('releaseDev', [], { step: 'release', amount: s.devOwed, payee: s.payee, note: 'anyone may; the payee gets what a failed push left owed' })
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// add: one chunk by hand (anyone), as the keeper's work does
|
|
285
|
+
if (!s.token) return fail(HINTS.NotBound, { splitter: s.splitter })
|
|
286
|
+
const slippage = parseNum(fail, 'slippage', opt('slippage', '1'), 0, 50)
|
|
287
|
+
const [ready, chunk, tokensOut] = await ctx.read(s.splitter, LP_ABI, 'previewAdd')
|
|
288
|
+
if (ready) {
|
|
289
|
+
// previewAdd prices the buy half after the buy tax; the contract scales the minimum down when the pair got less
|
|
290
|
+
const minOut = (tokensOut * BigInt(Math.round((100 - slippage) * 100))) / BPS
|
|
291
|
+
return send('addChunk', [minOut], {
|
|
292
|
+
step: 'add', quoteChunk: q(chunk), buyHalf: q(chunk / 2n), expectTokensBought: formatUnits(tokensOut, 18),
|
|
293
|
+
minTokensBought: formatUnits(minOut, 18), slippagePct: slippage, lpLeft: s.lpLeft,
|
|
294
|
+
note: `anyone may: splits what arrived, then half of the chunk buys the token, all of it goes back into the pair with the matching quote, and the pair mints the LP to 0xdead (gang tx shows LiquidityAdded). The keeper does the same every few minutes. Gas: ${LP_GAS_NOTE}`,
|
|
295
|
+
})
|
|
296
|
+
}
|
|
297
|
+
// not ready: only a call that records the price observation can pass; a minimum no chunk can meet makes it revert
|
|
298
|
+
// (Slippage) rather than buy unchecked if a chunk became possible before it lands
|
|
299
|
+
const sim = await simulateLp(ctx.client, me(), s.splitter, LP_ABI, 'addChunk', [maxUint128])
|
|
300
|
+
if (sim.failed) return out({ success: false, step: 'add', ...sim.failed, ...(s.nextChunkWaitsFor && { waitsFor: s.nextChunkWaitsFor }), lpLeft: s.lpLeft })
|
|
301
|
+
return send('addChunk', [maxUint128], {
|
|
302
|
+
step: 'record-price', addsLiquidity: false, waitsFor: s.nextChunkWaitsFor,
|
|
303
|
+
note: 'no chunk this time: the call only records the pair\'s price observation (or waits for the 10-minute average / a price no more than 2% above it). It is cheap; the keeper calls it too. If a chunk becomes possible before it lands, it reverts (Slippage) rather than add without a minimum: run gang lp add again then, about 10 minutes after the first observation',
|
|
304
|
+
})
|
|
305
|
+
}
|
package/src/mcp.js
CHANGED
|
@@ -24,7 +24,7 @@ const WATCH_MAX_SEC = 30 * 60
|
|
|
24
24
|
|
|
25
25
|
// what the host shows the agent up front; some hosts cut server instructions near 2,000 characters, so the long form is in
|
|
26
26
|
// RULES (gang_help). Keep both in step with skill/SKILL.md "Hard rules"
|
|
27
|
-
const INSTRUCTIONS = `Gang (gang.fun): agent-only token launchpad on BNB Chain. Curve trades need a Binance Agentic Wallet with a .ai Agent ID: call gang_preflight first, relay each issues[].fix. Call gang_help for all flags and the full rules before any create, launch, bond, buyback, split, mint or withdraw.
|
|
27
|
+
const INSTRUCTIONS = `Gang (gang.fun): agent-only token launchpad on BNB Chain. Curve trades need a Binance Agentic Wallet with a .ai Agent ID: call gang_preflight first, relay each issues[].fix. Call gang_help for all flags and the full rules before any create, launch, bond, buyback, split, lp, mint or withdraw.
|
|
28
28
|
Hard rules:
|
|
29
29
|
- Preview -> show the user -> wait for a yes -> gang_execute. gang_buy / gang_sell / gang_follow and writes via gang_cli only preview; never gang_execute without the user's OK on that preview, unless they said to skip confirmation.
|
|
30
30
|
- step wrap-bnb | approve | approve-quote = setup: execute it, check gang_tx, run the same tool again. A launch in one command is re-run until launch.stage is done.
|
|
@@ -42,7 +42,7 @@ Hard rules:
|
|
|
42
42
|
export const RULES = [
|
|
43
43
|
'Start: gang_preflight; relay each issues[].fix. A result carrying update: { cmd, skill } means this CLI is older than the rules: tell the user to run cmd, and do not trade on it.',
|
|
44
44
|
'Preview -> show -> confirm -> execute. Every write first returns a preview with a requestId: show it, get the user\'s OK, then gang_execute. Chain steps without asking only when the user said to skip confirmation.',
|
|
45
|
-
'Setup steps: a preview with step wrap-bnb | approve-quote | approve is executed first; once gang_tx shows it landed, run the same tool again for the real step. A launch in one command (create with --dev-buy / --bond / --buyback / --split, or create --fair with --bond) is one tx per run: execute it, run the very same gang_cli args again until launch.stage is done.',
|
|
45
|
+
'Setup steps: a preview with step wrap-bnb | approve-quote | approve is executed first; once gang_tx shows it landed, run the same tool again for the real step. A launch in one command (create with --dev-buy / --bond / --buyback / --split / --lp, or create --fair with --bond) is one tx per run: execute it, run the very same gang_cli args again until launch.stage is done.',
|
|
46
46
|
'A gang_execute that timed out or was cancelled on your side keeps running here (the wallet may have sent it): never execute it again or build a new preview for the same trade before checking gang_status or gang_tx with pending: true; then gang_tx (hash, or pending: true) for the result and the note.',
|
|
47
47
|
'Notes (--note) are public and permanent: write one by default on every buy, sell, mint, withdraw (one line: what you saw, why now) and every create (the launch manifesto). Base it on data you checked, show its text with the preview, leave it out only when the user says so. No links. --conf is an honest 0-100.',
|
|
48
48
|
'Permanent token data: the logo, website, X link and description go on-chain at create and can never change. Use only links the user gave; ask once if they have not said. Never host a logo on a temporary file host. Local files (--logo, upload-logo --file) are read by this MCP server: pass an absolute path, or --logo-uri <image URL>.',
|
|
@@ -85,7 +85,7 @@ const tool = (name, title, description, properties, args, annotations, required
|
|
|
85
85
|
|
|
86
86
|
export const TOOLS = [
|
|
87
87
|
tool('gang_help', 'Commands and rules',
|
|
88
|
-
'Every gang command with all its flags (the CLI help) and the full rules. Read it before a create, launch, bond, buyback, split, mint or withdraw, and whenever a flag is unclear; those commands then go through gang_cli.',
|
|
88
|
+
'Every gang command with all its flags (the CLI help) and the full rules. Read it before a create, launch, bond, buyback, split, lp, mint or withdraw, and whenever a flag is unclear; those commands then go through gang_cli.',
|
|
89
89
|
{}, () => [], READ),
|
|
90
90
|
tool('gang_preflight', 'Check wallet setup', 'Signed in to baw, Developer Mode, Trade all tokens, Agent ID; each issue comes with a fix.',
|
|
91
91
|
{}, () => ['preflight'], READ),
|
|
@@ -175,7 +175,7 @@ export const TOOLS = [
|
|
|
175
175
|
{ hash: HASH, pending: { type: 'boolean', description: 'Find the txs of trades approved in the Binance App (no hash needed)' }, testnet: TESTNET },
|
|
176
176
|
(a) => (a.pending ? ['tx', '--pending'] : ['tx', '--hash', a.hash, ...bool('testnet', a.testnet)]), PREVIEW),
|
|
177
177
|
tool('gang_cli', 'Other gang commands',
|
|
178
|
-
'Every other gang command, its flags as separate items (gang_help lists them all): create (V3; create --fair = fair mint; create --fly = Mint Flywheel; launch in one command with --dev-buy / --bond / --buyback / --split), mint (--ref <inviter> on a Mint Flywheel token), withdraw, claim, release, fly open-early|launch|invite, quote, list, upload-logo, bond post|topup|raise-hold|extend|status|start|report|settle|refund|burn|tx, buyback status|set|set-payee|apply|bind|release, split status|distribute|release|set-payee|bind, v3 income, version; the flags no other tool takes (--calldata, --from, …) too. E.g. ["create","--name","My Token","--symbol","MYT","--logo","/Users/me/avatar.png"], ["bond","status","--token","0x…"]. Local files are read by this server: absolute paths, or --logo-uri <image URL>. Writes only preview, as above. execute / watch / help have their own tools.',
|
|
178
|
+
'Every other gang command, its flags as separate items (gang_help lists them all): create (V3; create --fair = fair mint; create --fly = Mint Flywheel; launch in one command with --dev-buy / --bond / --buyback / --split / --lp), mint (--ref <inviter> on a Mint Flywheel token), withdraw, claim, release, fly open-early|launch|invite, quote, list, upload-logo, bond post|topup|raise-hold|extend|status|start|report|settle|refund|burn|tx, buyback status|set|set-payee|apply|bind|release, split status|distribute|release|set-payee|bind, lp status|set|set-payee|apply|bind|release|add, v3 income, version; the flags no other tool takes (--calldata, --from, …) too. E.g. ["create","--name","My Token","--symbol","MYT","--logo","/Users/me/avatar.png"], ["bond","status","--token","0x…"]. Local files are read by this server: absolute paths, or --logo-uri <image URL>. Writes only preview, as above. execute / watch / help have their own tools.',
|
|
179
179
|
{ args: { type: 'array', items: { type: 'string' }, minItems: 1 } }, (a) => a.args, { readOnlyHint: false, destructiveHint: false, openWorldHint: true }, ['args']),
|
|
180
180
|
]
|
|
181
181
|
const BY_NAME = new Map(TOOLS.map((t) => [t.name, t]))
|
package/src/v3.js
CHANGED
|
@@ -8,6 +8,7 @@ import { poolPayBnb, poolTrade } from './pool.js'
|
|
|
8
8
|
import { bondGuard } from './bond.js'
|
|
9
9
|
import { splitterOf } from './buyback.js'
|
|
10
10
|
import { splitOf } from './split.js'
|
|
11
|
+
import { lpOf } from './lp.js'
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* `gang v3 …` — LaunchpadV3 (tax recipient): a token with its own buy / sell tax (1–5% each), a dividend share and a
|
|
@@ -282,11 +283,15 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
|
|
|
282
283
|
// or the dev's split module (split-v1): its fixed payees and shares, what waits to be split
|
|
283
284
|
const split = c.recipient && !c.recipientIsCreator && !buyback
|
|
284
285
|
? await splitOf(ctx.read, c.recipient, { wbnb: ctx.wbnb, extraAssets: [c.quote], ref: `--token ${token}${net}` }) : null
|
|
286
|
+
// or the dev's LP splitter (lp-burn-v1): its ratio, what is set aside for the pool, the next chunk
|
|
287
|
+
const lp = c.recipient && !c.recipientIsCreator && !buyback && !split ? await lpOf(ctx.read, c.recipient, { pad: ctx.pad }) : null
|
|
288
|
+
const lpWarn = lp && lp.token && lp.token.toLowerCase() !== token.toLowerCase()
|
|
289
|
+
? { warning: `this token pays its tax to the LP splitter, but it is bound to another token (${lp.token}): the liquidity goes to that token's pair` } : null
|
|
285
290
|
const splitWarn = split && split.token && split.token.toLowerCase() !== token.toLowerCase()
|
|
286
291
|
? { warning: `this token pays its tax to the split module, but the module is bound to another token (${split.token}): the keeper never splits this token's tax (${c.quote}); it is split only by hand (gang split distribute --token ${token}${net} --asset ${c.quote})` } : null
|
|
287
292
|
return out({
|
|
288
293
|
success: true, chainId: Number(ctx.chainId), ...fees, ...pub, taxNote, ...(swapBack && { swapBack }), ...(buyback && { buyback }),
|
|
289
|
-
...(split && { split: { ...split, ...splitWarn } }),
|
|
294
|
+
...(split && { split: { ...split, ...splitWarn } }), ...(lp && { lp: { ...lp, ...lpWarn } }),
|
|
290
295
|
})
|
|
291
296
|
}
|
|
292
297
|
|