@gangfun/cli 0.40.0 → 0.42.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/DEVELOPERS.md +1 -0
- package/DEVELOPERS.zh-CN.md +1 -0
- package/README.md +6 -1
- package/README.zh-CN.md +14 -1
- package/package.json +1 -1
- package/src/capabilities.js +9 -0
- package/src/flags.js +5 -2
- package/src/gradreward.js +314 -0
- package/src/help.js +8 -0
- package/src/index.js +80 -4
- package/src/mcp.js +5 -2
- package/src/telemetry.js +15 -1
- package/src/v3.js +70 -7
package/DEVELOPERS.md
CHANGED
|
@@ -116,6 +116,7 @@ capitalization). Existing tokens keep their addresses. A suffix alone does not p
|
|
|
116
116
|
| `NO_AGENT_ID` | This wallet has no Agent ID |
|
|
117
117
|
| `DEV_MODE_OFF`, `TRADE_ALL_TOKENS_OFF` | A wallet setting (from `gang preflight`) |
|
|
118
118
|
| `NETWORK` | An RPC or the API can't be reached: retry a read later |
|
|
119
|
+
| `NO_FUNDS` (0.41.0+) | The wallet can't pay for this trade: `fund` says how to top it up; nothing was sent |
|
|
119
120
|
| `REVERT` | The simulation or the chain refused it |
|
|
120
121
|
| A contract error name (such as `NotAgent`) | That contract error |
|
|
121
122
|
| A lower-case word (such as `not_found`) | A specific refusal: `error` explains it |
|
package/DEVELOPERS.zh-CN.md
CHANGED
|
@@ -114,6 +114,7 @@ Pad 3.0 的 owner 启用 `abcd` 部署器后,CLI 会为曲线、打新、铸
|
|
|
114
114
|
| `NO_AGENT_ID` | 这个钱包没有 Agent ID |
|
|
115
115
|
| `DEV_MODE_OFF`、`TRADE_ALL_TOKENS_OFF` | 钱包设置问题(来自 `gang preflight`) |
|
|
116
116
|
| `NETWORK` | RPC 或 API 连不上,读操作可以稍后重试 |
|
|
117
|
+
| `NO_FUNDS`(0.41.0+) | 钱包余额不够这笔交易:`fund` 写了怎么充值;什么都没发出 |
|
|
117
118
|
| `REVERT` | 模拟执行或链上拒绝了这笔交易 |
|
|
118
119
|
| 合约错误名(如 `NotAgent`) | 对应的合约错误 |
|
|
119
120
|
| 小写单词(如 `not_found`) | 具体的拒绝原因,见 `error` |
|
package/README.md
CHANGED
|
@@ -24,6 +24,8 @@ Operate [gang.fun](https://gang.fun) from a Binance **Agentic Wallet**. Curve bu
|
|
|
24
24
|
|
|
25
25
|
**Opening base (0.40.0+, BSC testnet; on mainnet the pad is upgraded and the base opens with an owner (Safe) call — until then `--base` stops with "closed"):** `gang create … --base <5|10> --base-vest <30|90|180> [--grad 6|9|12|15]` creates a GangLaunchpad 3.0 curve token whose very first trade buys 5% or 10% of the supply for the token's own base vault (GangBaseVault, `base-v1`). The create pays exactly the pad's `previewBaseCost` in BNB as the tx value (5% at 6 / 9 / 12 / 15 BNB: 0.0994 / 0.1490 / 0.1987 / 0.2484 BNB; 10%: 0.2090 / 0.3135 / 0.4180 / 0.5225; the 1% fee included, 70% of it back as your creator fee). The vault never trades: the base is locked until graduation, then the first `gang base release` (anyone may call it) starts the clock and the base is released linearly over `--base-vest` days to the creator's wallet (5%: 30 / 90 / 180 days; 10%: 90 / 180; fixed for good). **If the token never graduates, the base and its cost stay locked for good.** The preview shows the cost, the schedule and the spec's payoff figures (the least you get, at the graduation price, days to recover the cost, the daily release, what other buyers pay more), and that GangBond does not constrain the base (the vault keeps refilling the creator's wallet, so a bond is no promise about it). WBNB quote only, no dividend, not with `--vault` / `--promote` / `--fair` / `--fly` or a launch in one command; on a taxed token the recipient is usually the creator. With abcd on, the create goes through `createWithSalt` with the BNB. The CLI asks the pad (`baseVaultImpl`) and refuses `--base` where it is not live. `gang base status --token 0x…` shows the vault, size, period, start (or not started), total, released, releasable and unreleased (counted by time); `gang base release --token 0x…` starts the release, then sends what has vested to the creator.
|
|
26
26
|
|
|
27
|
+
**Graduation reward (冲毕业奖励, 0.42.0+, BSC testnet; on mainnet once the pad is upgraded and the Safe opens it):** `gang create … --grad-reward <seed> [--gr-min-buy <amount>] [--gr-entries <1-20>] [--gr-last <0-50>] [--gr-refund-days <30-180>]` creates a GangLaunchpad 3.0 curve token with a reward pool you seed in the token's quote (pulled in the create, so the CLI asks you to approve it first; at least 0.1 BNB worth). The pad keeps the last `--gr-entries` curve buys (default 10) that each actually spend `--gr-min-buy` (default 0.01 BNB worth), with the Agent gate on; the buy that graduates the token always counts. At graduation that buy gets `--gr-last` % of the pool on top (default 30), and all entries, it included, split the rest by what each spent. A curve sell takes out that wallet's earlier entries (a later buy counts again). Buyers claim for 180 days after graduation, then anyone sweeps the rest back to you. If the token does not graduate, `--gr-refund-days` (default 90) after the create you may ask for the pool back: the request is public for 7 days (a graduation in that time pays the buyers as usual), then you have 3 days to take it, else it lapses. Buyers pay nothing extra: the pool is your money, split by a fixed public rule, with no draw. Works with `--promote` on an untaxed token or with `--recipient`; not with `--vault` / `--base` / `--fair` / `--fly` or a launch in one command. `gang buy` / `gang sell` previews say under `rewards.gradReward` whether the buy counts and what a sell takes out. `gang grad-reward status --token 0x…` shows the pool, rules, list, refund state and what you can claim; `claim`, `settle`, `sweep`, `retry-carry`, `refund-request`, `refund-cancel` and `refund` do the rest.
|
|
28
|
+
|
|
27
29
|
**Call bond and follow binding (0.37.0+):** an agent can back its own call — a buy note on a GangLaunchpad 3.0 curve token — with a bond: buy with `--note`, then within 10 minutes `gang call-bond post --token 0x… --amount 0.1 --for 48h` (the note defaults to the wallet's latest buy of the token; `--hold` defaults to the whole balance). Until settle the wallet's balance of the token stays ≥ hold; one sell, vault lock or transfer below it — also after the deadline, until `gang call-bond settle` has run (two steps, 1 hour apart) — and anyone can `gang call-bond report` it: 1% to the reporter, half burnt, the rest paid to the note's followers by their loss (`gang call-bond claim` once the root's 2-day dispute window is over). Nothing of a broken bond comes back to the caller. Quotes: WBNB, USDT, USDC, USD1. A caller's `gang v3 sell` below its hold is refused unless `--break-call-bond`. On a token with a promoter share, `gang follow` binds the note's author as the wallet's promoter for good (it builds `buyWithPromoter`; same price and fee; `--no-promoter` for a plain follow). GangCallBond is live on BSC mainnet (`0x6d6e4A36e9a231cCc932151cdbFb087Cf3860c3D`, deployed 2026-11-09, owned by the platform's Safe; built in) and the BSC testnet (`0xBE2B8519278E9D31B6c4040bAd35f727fD5d2A70`).
|
|
28
30
|
|
|
29
31
|
**GangLaunchpad 2.0, the creator fee and the graduation target (0.23.0+):** 2.0 is a new generation of the same pad (the same V3 curves and 打新 sales); of the 1% fee on every V3 curve buy and sell, 70% is kept on the pad for the token's creator, who claims it any time, before or after graduation: `gang creator-fee` lists a creator's 2.0 tokens and what each holds, `gang creator-fee --token <addr> --claim [--to <addr>]` claims it. It is the creator's own, never the tax recipient's or a buy-back / split / LP module's; 1.0 tokens and 打新 sales have none. 2.0 also lets the creator pick the V3 graduation target: `gang create --grad 6|9|12|15` (BNB raised, default 9; market cap at graduation ≈ 5×); `gang info` / `gang status` show each token's `graduationTargetBnb`. New tokens go to the newest generation built in for the network (`gang preflight` → `createPadGen`); a token keeps trading on its own generation's pad, GangRouter, GangBond and module factories, found by asking each pad's `kindOf`. On the BSC testnet 2.0 is live and the create target (pad `0xb14d415f70D7F99f0D93Bd3BF76e0D6b38b53B3E`, GangRouter `0x5a4FA2D91638a305EdF027894753c943f095dDAA`; the first testnet 2.0, `0x6381…39be`, no longer creates, and its tokens keep trading and claiming there). On BSC mainnet 2.0 is live and the create target since 2026-10-31 (pad `0x770331a9accdb53ACb4a45B6c5B7D151fADCe557`, GangRouter `0xa83209d6bfC2B220cD86410cCDDC71FEb354844a`); 1.0 tokens keep trading on 1.0 (pad `0x15CF…4365`).
|
|
@@ -150,6 +152,8 @@ gang create … --buy-tax 3 --sell-tax 3 --floor [--redeem-fee 2] [--tax-cap 20
|
|
|
150
152
|
gang floor status|redeem|distribute|release|set-payee|bind --token 0x… [--amount <tokens>|all] [--to 0x…] [--asset 0x…] [--index <i>] [--break-bond] [--break-call-bond] [--settle-first] # the floor module: treasury, what a token redeems for, fee, cap and payees; redeem burns the tokens (0xdead) for their share of the treasury
|
|
151
153
|
gang create … --base 5|10 --base-vest 30|90|180 [--grad 6|9|12|15] # 3.0 opening base: the create also buys 5% / 10% for a base vault, paid in BNB; locked until graduation (for good if it never graduates), then released linearly to you
|
|
152
154
|
gang base status|release --token 0x… # the base vault: size, period, start, released, releasable, unreleased; release starts the clock, then sends what has vested to the creator
|
|
155
|
+
gang create … --grad-reward <seed> [--gr-min-buy <amt>] [--gr-entries 1-20] [--gr-last 0-50] [--gr-refund-days 30-180] # 3.0 graduation reward: a pool you seed for the last buys before graduation, by what each spent
|
|
156
|
+
gang grad-reward status|claim|settle|sweep|retry-carry|refund-request|refund-cancel|refund --token 0x… # the pool, list and claims; the creator's refund with a 7-day notice
|
|
153
157
|
gang create --fair … [--shares <n>] --bond <quote> [--bond-hold …] --bond-days <7-90> # 打新: create (dev shares) → bond
|
|
154
158
|
gang execute --request-id <id>
|
|
155
159
|
gang tx --pending # trades approved in the Binance App: found by the exact call previewed, then as below
|
|
@@ -369,7 +373,8 @@ timed-out `gang_execute`, check `gang_status` / the wallet history instead of ex
|
|
|
369
373
|
From 0.24.0 the CLI counts how it is used, anonymously, so gang.fun can see where agents get stuck before a first trade.
|
|
370
374
|
Each command adds one event:
|
|
371
375
|
- the command name (and subcommand), the names of the flags given (never their values);
|
|
372
|
-
- whether it succeeded, and if not, a short error code (`NO_AGENT_ID`, `DEV_MODE_OFF`, a Binance risk code, `USAGE`…);
|
|
376
|
+
- whether it succeeded, and if not, a short error code (`NO_AGENT_ID`, `DEV_MODE_OFF`, a Binance risk code, `USAGE`…); from
|
|
377
|
+
0.41.0 a Binance code also carries the wallet's error name, an upper-case constant such as `SERVICE_ERROR`;
|
|
373
378
|
- for `gang preflight`, which checks passed;
|
|
374
379
|
- the agent host's name, when known (0.31.0+): the MCP client's own name (such as `claude-code`), or `GANG_CLIENT`. Only a
|
|
375
380
|
short name made of letters, digits, spaces, `-` and `_` goes out; anything else is sent as `other`.
|
package/README.zh-CN.md
CHANGED
|
@@ -24,6 +24,17 @@
|
|
|
24
24
|
|
|
25
25
|
**开盘底仓(0.40.0+,BSC 测试网;主网 pad 已升级,等多签开放后可用,开放前 `--base` 会提示未开放):** `gang create … --base <5|10> --base-vest <30|90|180> [--grad 6|9|12|15]` 在 GangLaunchpad 3.0 上建一个曲线币,它的第一笔成交就是给这个币专属的底仓金库(GangBaseVault,`base-v1`)买入总量的 5% 或 10%。建币交易按 pad 的 `previewBaseCost` 正好付这么多 BNB(5% 在 6 / 9 / 12 / 15 BNB 档:0.0994 / 0.1490 / 0.1987 / 0.2484 BNB;10%:0.2090 / 0.3135 / 0.4180 / 0.5225;含 1% 手续费,其中 70% 作为创建人手续费返还给你)。金库不交易:毕业前底仓锁住;毕业后第一次有人调 `gang base release`(谁都可以调)开始计时,之后在 `--base-vest` 天里匀速释放到创建人的钱包(5%:30 / 90 / 180 天;10%:90 / 180 天;写死不能改)。**如果代币永远不毕业,底仓和为它付的钱永远锁着,收不回来。** 预览里有花费、释放节奏和规格里的收益表(最少能拿多少、按毕业价算多少、几天收回成本、每天释放量、其他买家多付多少),并说明保证金约束不了底仓(金库一直往创建人钱包里补币,保证金不代表对底仓的任何承诺)。只支持 WBNB 计价,不能带分红,不能和 `--vault` / `--promote` / `--fair` / `--fly` 或一条命令发射一起用;带税时收款人通常就是创建人自己。开启 abcd 时建币经 `createWithSalt` 带上 BNB 发出。CLI 会先问 pad(`baseVaultImpl`),没开放的地方直接拒绝 `--base`。`gang base status --token 0x…` 显示金库、底仓大小、释放期、开始时间(或未开始)、总量、已释放、可释放和未释放(按时间算);`gang base release --token 0x…` 第一次调用开始计时,之后把已经到期的部分转给创建人。
|
|
26
26
|
|
|
27
|
+
**冲毕业奖励(0.42.0+,BSC 测试网;主网等 pad 升级、多签开放后可用):** `gang create … --grad-reward <种子钱> [--gr-min-buy <金额>] [--gr-entries <1-20>] [--gr-last <0-50>] [--gr-refund-days <30-180>]` 在 GangLaunchpad 3.0 上建一个曲线币,同时用这个币的报价币放进一笔奖励池。种子钱在建币时拉走,所以 CLI 会先让你批准;至少值 0.1 BNB。
|
|
28
|
+
|
|
29
|
+
- **谁能分**:pad 记下最后 `--gr-entries` 笔(默认 10)曲线买入,每笔都要实际花掉 `--gr-min-buy`(默认值 0.01 BNB),而且 Agent 门槛开着;把币推过毕业线的那一笔一律计入。
|
|
30
|
+
- **怎么分**:毕业时,这一笔先额外拿奖励池的 `--gr-last`%(默认 30),剩下的由所有格子(包括这一笔)按各自实际花掉的金额分。
|
|
31
|
+
- **卖出**:在曲线上卖出,这个钱包之前的格子全部失效;之后再买会重新计入。
|
|
32
|
+
- **领取**:毕业后 180 天内买家自己领,之后任何人都可以把剩下的部分退给你。
|
|
33
|
+
- **不毕业**:建币满 `--gr-refund-days` 天(默认 90)后,你可以申请撤回。申请公示 7 天,期间毕业照常发放;公示期满后 3 天内可以取回,过期就要重新申请。
|
|
34
|
+
- **组合**:可以和 `--promote` 一起用(不带税,或者带 `--recipient`);不能和 `--vault` / `--base` / `--fair` / `--fly` 或一条命令发射一起用。
|
|
35
|
+
|
|
36
|
+
买家不额外付钱:奖励池是你自己的钱,按公开的固定规则分配,不抽签。`gang buy` / `gang sell` 的预览会在 `rewards.gradReward` 里说明这笔会不会计入、卖出会让哪些格子失效。`gang grad-reward status --token 0x…` 显示奖励池、规则、名单、撤回状态和你能领多少;`claim`、`settle`、`sweep`、`retry-carry`、`refund-request`、`refund-cancel`、`refund` 负责其余操作。
|
|
37
|
+
|
|
27
38
|
**喊单保证金和跟单绑定(0.37.0+):** agent 可以给自己的喊单(GangLaunchpad 3.0 内盘币上的一条买入 note)押保证金:带 `--note` 买入,10 分钟内执行 `gang call-bond post --token 0x… --amount 0.1 --for 48h`(note 默认取这个钱包最近一次买这个币的交易;`--hold` 默认是全部余额)。结算前,这个钱包的持仓不能低于 hold:只要一次卖出、锁进 vault 或转出让余额低于它(过了截止时间、`gang call-bond settle` 还没执行完之前也算;结算分两步,间隔 1 小时),任何人都能 `gang call-bond report`:举报人拿 1%,一半销毁,其余按损失赔给这条 note 的跟单者(root 的 2 天争议期过后用 `gang call-bond claim` 领取)。违约的保证金一分都不会回到喊单者。报价币:WBNB、USDT、USDC、USD1。喊单者用 `gang v3 sell` 卖到低于 hold 会被拒,除非加 `--break-call-bond`。在开了推广分成的币上,`gang follow` 会把 note 作者永久绑成这个钱包的推广人(走 `buyWithPromoter`,价格和手续费不变;加 `--no-promoter` 就是普通跟单)。GangCallBond 已在 BSC 主网上线(`0x6d6e4A36e9a231cCc932151cdbFb087Cf3860c3D`,2026-11-09 部署,owner 是平台多签;已内置),测试网也有(`0xBE2B8519278E9D31B6c4040bAd35f727fD5d2A70`)。
|
|
28
39
|
|
|
29
40
|
**GangLaunchpad 2.0、creator 分成和毕业目标(0.23.0+):** 2.0 是同一个内盘的新一代(V3 曲线和打新都一样)。V3 内盘每笔买卖收的 1% 手续费里,70% 留在内盘上归这个币的 creator,creator 毕业前后随时可以领:`gang creator-fee` 列出这个 creator 所有 2.0 币各自可领多少,`gang creator-fee --token <addr> --claim [--to <addr>]` 领取。这笔钱只归 creator 本人,不给税收接收地址,也不经过回购 / 分账 / 加池模块;1.0 的币和打新没有这项。2.0 还允许 creator 自选 V3 毕业目标:`gang create --grad 6|9|12|15`(内盘募到的 BNB,默认 9;毕业时市值约为目标的 5 倍);`gang info` / `gang status` 显示每个币的 `graduationTargetBnb`。新币发到这条链上内置的最新一代(`gang preflight` 的 `createPadGen`);已有的币始终用它自己那一代的内盘、GangRouter、GangBond 和模块工厂(CLI 逐个问各代内盘的 `kindOf` 找到它)。BSC 测试网上 2.0 已上线并且是发币目标(内盘 `0xb14d415f70D7F99f0D93Bd3BF76e0D6b38b53B3E`,GangRouter `0x5a4FA2D91638a305EdF027894753c943f095dDAA`;测试网第一版 2.0 `0x6381…39be` 不再发新币,上面的币照常交易和领取)。BSC 主网 2026-10-31 起 2.0 已上线并且是发币目标(内盘 `0x770331a9accdb53ACb4a45B6c5B7D151fADCe557`,GangRouter `0xa83209d6bfC2B220cD86410cCDDC71FEb354844a`);1.0 的币照常在 1.0(内盘 `0x15CF…4365`)上交易。
|
|
@@ -129,6 +140,8 @@ gang create … --buy-tax 3 --sell-tax 3 --floor [--redeem-fee 2] [--tax-cap 20
|
|
|
129
140
|
gang floor status|redeem|distribute|release|set-payee|bind --token 0x… [--amount <数量>|all] [--to 0x…] [--asset 0x…] [--index <i>] [--break-bond] [--break-call-bond] [--settle-first] # 底价模块:金库、每枚能赎回多少、手续费、上限和收款人;redeem 把代币打进 0xdead,换回金库里按比例的一份
|
|
130
141
|
gang create … --base 5|10 --base-vest 30|90|180 [--grad 6|9|12|15] # 3.0 开盘底仓:建币时用 BNB 给底仓金库买 5% / 10%;毕业前锁住(不毕业就永远锁着),毕业后匀速释放给你
|
|
131
142
|
gang base status|release --token 0x… # 底仓金库:大小、释放期、开始时间、已释放、可释放、未释放;release 第一次开始计时,之后把到期的部分转给创建人
|
|
143
|
+
gang create … --grad-reward <种子钱> [--gr-min-buy <金额>] [--gr-entries 1-20] [--gr-last 0-50] [--gr-refund-days 30-180] # 3.0 冲毕业奖励:你出钱奖励毕业前最后几笔买入,按花费分
|
|
144
|
+
gang grad-reward status|claim|settle|sweep|retry-carry|refund-request|refund-cancel|refund --token 0x… # 奖励池、名单和领取;创建人撤回要先公示 7 天
|
|
132
145
|
gang create --fair … [--shares <n>] --bond <数量> [--bond-hold …] --bond-days <7-90> # 打新:发币(含 dev 份额)→ 押金
|
|
133
146
|
gang execute --request-id <id>
|
|
134
147
|
gang tx --pending # 在 Binance App 里批准过的交易:按预览时的调用自动找到交易,再按下面这条处理
|
|
@@ -317,7 +330,7 @@ Claude Code:`claude mcp add gang -- gang mcp`。同一台机器上 `baw` 要
|
|
|
317
330
|
|
|
318
331
|
从 0.24.0 起,CLI 会匿名统计使用情况,让 gang.fun 知道 agent 在第一笔交易之前卡在哪一步。每条命令记一条事件:
|
|
319
332
|
- 命令名(和子命令)、用到的参数名(不含参数值);
|
|
320
|
-
- 是否成功;失败时带一个简短的错误码(`NO_AGENT_ID`、`DEV_MODE_OFF`、币安风控码、`USAGE`
|
|
333
|
+
- 是否成功;失败时带一个简短的错误码(`NO_AGENT_ID`、`DEV_MODE_OFF`、币安风控码、`USAGE` 等);从 0.41.0 起,币安的错误码后面还会带上钱包返回的错误名(全大写常量,如 `SERVICE_ERROR`);
|
|
321
334
|
- `gang preflight` 另记各项检查是否通过;
|
|
322
335
|
- Agent 客户端名称(已知时,0.31.0+):MCP 客户端自己的名称(如 `claude-code`),或 `GANG_CLIENT`。只发送由字母、数字、空格、`-` 和 `_`
|
|
323
336
|
组成的短名称,其他内容一律记为 `other`。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gangfun/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.0",
|
|
4
4
|
"mcpName": "io.github.gangfun/gang",
|
|
5
5
|
"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.",
|
|
6
6
|
"type": "module",
|
package/src/capabilities.js
CHANGED
|
@@ -64,6 +64,7 @@ export const COMMANDS = [
|
|
|
64
64
|
c('creator-fee --claim --to', 'preview', 'high', '0.23.0', 'Creator only: claim the creator fee to another address'),
|
|
65
65
|
c('upload-logo', 'publish', 'medium', '0.2.0', 'Publish a local image or a URL on gang.fun, at once: only a file the user named', { needsUserConfirmation: true }),
|
|
66
66
|
c('create', 'preview', 'high', '0.1.0', 'Launch a token. Its name, tax, logo and links never change; a launch in one command also buys, bonds or binds modules'),
|
|
67
|
+
c('create --grad-reward', 'preview', 'high', '0.42.0', 'Create a 3.0 curve token with a reward pool the creator seeds for the last curve buys before graduation (by what each spent; the graduating buy gets a share on top); refundable only after a public notice if it never graduates'),
|
|
67
68
|
c('create --base', 'preview', 'high', '0.40.0', 'Create a 3.0 curve token that buys 5% or 10% of its supply for a base vault in the same tx, paid in BNB: locked until graduation (for good if it never graduates), then released linearly to the creator'),
|
|
68
69
|
c('mint', 'preview', 'medium', '0.12.0', 'Buy shares of a 打新 or Mint Flywheel sale'),
|
|
69
70
|
c('withdraw', 'preview', 'medium', '0.12.0', 'Sell shares back at the mint price, less the exit fee, before the sale fills', { riskIf: { 'break-bond': { risk: 'high', why: '打新 only: gives up the whole bond' } } }),
|
|
@@ -102,6 +103,14 @@ export const COMMANDS = [
|
|
|
102
103
|
]),
|
|
103
104
|
c('base status', 'read', 'none', '0.40.0', "A 3.0 token's opening base: its vault, size, release period, start, released, releasable and unreleased (by time)"),
|
|
104
105
|
c('base release', 'preview', 'low', '0.40.0', "Anyone, after graduation: start the base's linear release (first call), then send what has vested to the creator"),
|
|
106
|
+
c('grad-reward status', 'read', 'none', '0.42.0', "A 3.0 token's graduation reward: the pool, the rules, the list of the last counted buys, the refund state and what a wallet can claim"),
|
|
107
|
+
c('grad-reward claim', 'preview', 'low', '0.42.0', 'After graduation: claim this wallet\'s share of the graduation reward (all its valid entries), once'),
|
|
108
|
+
c('grad-reward settle', 'preview', 'low', '0.42.0', 'Anyone, after graduation: count the valid entries (the first claim does too)'),
|
|
109
|
+
c('grad-reward sweep', 'preview', 'low', '0.42.0', 'Anyone, 180 days after graduation: send the unclaimed rest back to the creator and close the reward'),
|
|
110
|
+
c('grad-reward retry-carry', 'preview', 'low', '0.42.0', 'Anyone: resend a carry owed to the token\'s countdown reward module'),
|
|
111
|
+
c('grad-reward refund-request', 'preview', 'medium', '0.42.0', 'Creator, on the curve, after --gr-refund-days: ask for the pool back; starts a public 7-day notice'),
|
|
112
|
+
c('grad-reward refund-cancel', 'preview', 'low', '0.42.0', 'Creator: cancel a running refund request'),
|
|
113
|
+
c('grad-reward refund', 'preview', 'medium', '0.42.0', 'Creator, within 3 days after the notice, the token still on its curve: take the pool back; the reward ends for good'),
|
|
105
114
|
c('promote buy', 'preview', 'medium', '0.34.0', "Buy naming a promoter: a wallet's first trade of the token binds it for good, on the curve"),
|
|
106
115
|
c('promote status', 'read', 'none', '0.34.0', "A token's promoter terms, a wallet's binding and what it can claim"),
|
|
107
116
|
c('promote earnings', 'read', 'none', '0.34.0', 'A promoter wallet: shares to claim on the curve and in the pool'),
|
package/src/flags.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { FLY_CREATE_FLAGS } from './fly.js'
|
|
7
7
|
import { LAUNCH_FLAGS } from './launch.js'
|
|
8
|
+
import { GRAD_FLAGS } from './gradreward.js'
|
|
8
9
|
|
|
9
10
|
export const LINK_FLAGS = ['website', 'twitter']
|
|
10
11
|
// gang create: V3 by default, a 打新 sale with --fair; a setting of the other kind is refused, not ignored
|
|
@@ -13,12 +14,14 @@ export const FAIR_CREATE_FLAGS = ['raise', 'cap', 'hold', 'mint-fee', 'exit-fee'
|
|
|
13
14
|
|
|
14
15
|
export const CREATE_ACCEPTS = new Set([
|
|
15
16
|
'name', 'symbol', 'logo', 'logo-file', 'file-logo', 'logo-uri', 'keep-logo-uri', ...LINK_FLAGS, 'description',
|
|
16
|
-
'quote', 'ref-pool', 'grad', 'vault', 'base', 'base-vest', 'testnet', 'calldata', 'from', 'note', 'conf', 'reveal-after',
|
|
17
|
+
'quote', 'ref-pool', 'grad', 'vault', 'base', 'base-vest', ...GRAD_FLAGS, 'testnet', 'calldata', 'from', 'note', 'conf', 'reveal-after',
|
|
17
18
|
'fair', 'fly', ...V3_CREATE_FLAGS, ...FAIR_CREATE_FLAGS, ...FLY_CREATE_FLAGS,
|
|
18
19
|
// a launch in one command: its dev buy reads --slippage like gang buy, its bond --use-wbnb like gang bond post
|
|
19
20
|
...LAUNCH_FLAGS, 'slippage', 'use-wbnb',
|
|
20
21
|
// refused further on, each with its own reason
|
|
21
22
|
'follow', 'cover', 'taxed', 'pair', 'pair-or-quote', 'hours',
|
|
23
|
+
// every result is JSON already: agents add --json out of habit, so it is accepted and changes nothing
|
|
24
|
+
'json',
|
|
22
25
|
])
|
|
23
26
|
|
|
24
27
|
// every flag a buy's code reads, whatever the token's kind: a buy refuses the rest, since a misspelled --promoter would fall
|
|
@@ -26,7 +29,7 @@ export const CREATE_ACCEPTS = new Set([
|
|
|
26
29
|
export const BUY_ACCEPTS = new Set([
|
|
27
30
|
'agent', 'all', 'amount', 'bnb', 'board', 'break-bond', 'break-call-bond', 'buy-tax', 'calldata', 'cap', 'conf', 'confirm-out',
|
|
28
31
|
'description', 'dev-buy', 'dev-cut', 'dev-shares', 'dividend', 'events', 'exit-fee', 'fair', 'file', 'file-logo',
|
|
29
|
-
'fly', 'follow', 'from', 'grad', 'guard', 'hash', 'hold', 'hours', 'include-graduated', 'interval',
|
|
32
|
+
'fly', 'follow', 'from', 'grad', 'guard', 'hash', 'hold', 'hours', 'include-graduated', 'interval', 'json',
|
|
30
33
|
'keep-logo-uri', 'kind', 'limit', 'logo', 'logo-file', 'logo-uri', 'max-age', 'max-events', 'min-hit', 'min-pct',
|
|
31
34
|
'min-shares', 'mint-fee', 'name', 'no-post-mint', 'no-promoter', 'note', 'notes', 'pair', 'pair-or-quote', 'path', 'pay-bnb',
|
|
32
35
|
'pending', 'poll', 'post-mint', 'preset', 'promoter', 'quote', 'raise', 'recipient', 'ref', 'ref-pool',
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { createPublicClient, encodeFunctionData, isAddress, parseAbi, parseUnits } from 'viem'
|
|
2
|
+
import { walletFor } from './fair.js'
|
|
3
|
+
import { atTokenPad, KIND_UNREAD, NOT_ON_MAINNET, PAD3_GEN, padNets, rpcTransport } from './gangpad.js'
|
|
4
|
+
import { missingRead } from './base.js'
|
|
5
|
+
import { revertOf as revertIn, step, units } from './steps.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 冲毕业奖励, the graduation reward of a GangLaunchpad 3.0 curve token (docs/SPEC-GRAD-REWARD-2026-11-17.md §13). The
|
|
9
|
+
* creator seeds a reward pool at create, in the token's quote (`gang create … --grad-reward <amount>`). The pad keeps
|
|
10
|
+
* the last N counted curve buys. A buy counts when the Agent gate is on and it actually spends at least minBuy; the buy
|
|
11
|
+
* that graduates the token always counts. A curve sell takes that wallet's earlier entries out. At graduation the
|
|
12
|
+
* newest valid entry gets lastBps of the pool on top; all valid entries, the newest included, split the rest by what
|
|
13
|
+
* each actually spent. Buyers claim for 180 days, then the rest is swept back to the creator. A token that does not
|
|
14
|
+
* graduate: the creator may ask for the pool back after refundAfter, and takes it only after a public 7-day notice,
|
|
15
|
+
* within 3 days (else the request lapses); a graduation during the notice pays as usual.
|
|
16
|
+
*
|
|
17
|
+
* Not a bet: buyers buy the token as on any curve and pay nothing extra; the pool is the creator's own money.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const TAX = '(uint16 buyTaxBps, uint16 sellTaxBps, uint16 dividendBps, address recipient)'
|
|
21
|
+
const CFG = '(uint128 seed, uint96 minBuy, uint8 entries, uint16 lastBps, uint16 carryBps, uint32 refundAfter, uint16 promoteBps, uint32 promoteWindow)'
|
|
22
|
+
const VIEW = '(uint8 state, uint128 pot, uint96 minBuy, uint8 entries, uint16 lastBps, uint16 carryBps, uint32 refundAfter, uint40 createdAt, uint40 refundAt, uint40 gradAt, uint64 seq, address countdown, uint128 claimed, uint128 carryOwed, bool settled, uint16 valid, uint128 validSpent, bool refundPending)'
|
|
23
|
+
export const GRAD_PAD_ABI = parseAbi([
|
|
24
|
+
`function createWithGradReward(string name, string symbol, string logoURI, string metaURI, address quote, address refPool, ${TAX} tax, uint256 gradBnb, ${CFG} cfg) returns (address token)`,
|
|
25
|
+
'function gradRewardDeps() view returns (bool open, address handlerAdmin, address countdownFactory)',
|
|
26
|
+
`function gradReward(address token) view returns (${VIEW})`,
|
|
27
|
+
'function gradEntries(address token) view returns (address[] buyers, uint64[] seqs, uint96[] spent, bool[] valid)',
|
|
28
|
+
'function gradClaimable(address token, address wallet) view returns (uint256)',
|
|
29
|
+
'function agentGateEnabled() view returns (bool)',
|
|
30
|
+
'function claimGradReward(address token) returns (uint256 amount)',
|
|
31
|
+
'function settleGradReward(address token)',
|
|
32
|
+
'function sweepGradReward(address token)',
|
|
33
|
+
'function retryCarry(address token)',
|
|
34
|
+
'function requestGradRefund(address token)',
|
|
35
|
+
'function cancelGradRefund(address token)',
|
|
36
|
+
'function gradRefund(address token) returns (uint256 amount)',
|
|
37
|
+
'error GradNotOpen()', 'error BadGradConfig()', 'error BadCountdown()', 'error NotGradState()', 'error RefundNotDue()',
|
|
38
|
+
'error AlreadyClaimed()', 'error NothingToClaim()', 'error SweepNotDue()', 'error NoCarryOwed()', 'error CarryGasLow()',
|
|
39
|
+
'event GradRewardSet(address indexed token, uint256 seed, uint256 minBuy, uint8 entries, uint16 lastBps, uint16 carryBps, uint32 refundAfter, address countdown)',
|
|
40
|
+
'event GradEntry(address indexed token, address indexed buyer, uint64 seq, uint256 spent, uint256 tokens)',
|
|
41
|
+
'event GradDisqualified(address indexed token, address indexed wallet, uint64 seq)',
|
|
42
|
+
'event GradRewardBooked(address indexed token, uint256 pot, uint256 carry, uint64 seq)',
|
|
43
|
+
'event GradSettled(address indexed token, uint256 valid, uint64 lastSeq, uint256 lastShare, uint256 restPay, uint256 validSpent)',
|
|
44
|
+
'event GradClaimed(address indexed token, address indexed wallet, uint256 amount)',
|
|
45
|
+
'event GradSwept(address indexed token, address indexed to, uint256 amount)',
|
|
46
|
+
'event RefundRequested(address indexed token, uint256 executableAt, uint256 expiresAt)',
|
|
47
|
+
'event RefundCancelled(address indexed token)',
|
|
48
|
+
'event Refunded(address indexed token, address indexed dev, uint256 amount)',
|
|
49
|
+
'event CarrySent(address indexed token, address indexed module, uint256 amount)',
|
|
50
|
+
'event CarryOwed(address indexed token, address indexed module, uint256 amount)',
|
|
51
|
+
'event GradRewardDepsSet(bool open, address handlerAdmin, address countdownFactory)',
|
|
52
|
+
])
|
|
53
|
+
/** What `gang tx` decodes the graduation reward's logs with. */
|
|
54
|
+
export const GRAD_EVENT_ABIS = [GRAD_PAD_ABI]
|
|
55
|
+
|
|
56
|
+
export const HINTS = {
|
|
57
|
+
GradNotOpen: 'the graduation reward is closed on this pad: drop --grad-reward',
|
|
58
|
+
BadGradConfig: '--grad-reward out of bounds: a seed above 0, --gr-min-buy above 0, --gr-entries 1–20, --gr-last 0–50, --gr-refund-days 30–180',
|
|
59
|
+
BadCountdown: 'the tax recipient is a countdown reward module made for another token or quote (or a carry was asked without one)',
|
|
60
|
+
NotGradState: 'the reward is not in the state this needs (on the curve for a refund; graduated for a claim, a settle or a sweep)',
|
|
61
|
+
RefundNotDue: 'a refund needs: --gr-refund-days passed since the create to ask; then a 7-day public notice; then 3 days to take it, after which the request lapses',
|
|
62
|
+
AlreadyClaimed: 'this wallet already claimed its graduation reward for this token',
|
|
63
|
+
NothingToClaim: 'this wallet has no valid entry in the list: it was not among the last buys counted, or it sold on the curve after its buys',
|
|
64
|
+
SweepNotDue: 'the unclaimed rest can be swept 180 days after graduation',
|
|
65
|
+
NoCarryOwed: 'no carry is owed to the countdown module',
|
|
66
|
+
CarryGasLow: 'too little gas for the countdown module\'s receiveCarry: send the tx with more gas',
|
|
67
|
+
}
|
|
68
|
+
export const revertOf = (e) => revertIn(e, [GRAD_PAD_ABI], HINTS)
|
|
69
|
+
|
|
70
|
+
export const STATES = ['none', 'on the curve', 'graduated: claims open', 'refunded to the creator', 'closed']
|
|
71
|
+
export const MAX_ENTRIES = 20
|
|
72
|
+
export const DEFAULTS = { entries: 10, lastPct: 30, refundDays: 90 }
|
|
73
|
+
// in BNB, converted into the quote at the pad's own rate (graduation amount ÷ target)
|
|
74
|
+
export const DEFAULT_MIN_BUY_BNB = '0.01'
|
|
75
|
+
export const MIN_SEED_BNB = '0.1'
|
|
76
|
+
export const NOTICE_DAYS = 7
|
|
77
|
+
export const WINDOW_DAYS = 3
|
|
78
|
+
export const CLAIM_DAYS = 180
|
|
79
|
+
|
|
80
|
+
export const GRAD_FLAGS = ['grad-reward', 'gr-min-buy', 'gr-entries', 'gr-last', 'gr-refund-days']
|
|
81
|
+
export const GRAD_USAGE = '--grad-reward <seed> [--gr-min-buy <amount>] [--gr-entries <1-20>] [--gr-last <0-50>] [--gr-refund-days <30-180>]: the reward pool you put in at create (in the token\'s quote), the least a buy must spend to count, how many of the last buys share it, the % the graduating buy gets on top, and the days before you may ask for the pool back'
|
|
82
|
+
export const GRAD_ALONE = 'a --grad-reward create stands alone in this CLI: no chained dev buy, GangBond or buy-back / split / LP / combined / floor / capped recipient, no --base, no --vault. A dev buy is its own gang buy after the create lands'
|
|
83
|
+
export const NOT_A_BET = 'the reward pool is the creator\'s own money; buyers pay only the usual curve price and 1% fee, nothing extra, and get the tokens they buy. Who gets what follows a fixed public rule (the last buys counted, by what each spent): no randomness, no draw'
|
|
84
|
+
|
|
85
|
+
/** The --grad-reward / --gr-* flags, checked: { seed, minBuy, entries, lastBps, refundDays } (amounts as typed), or { error }. */
|
|
86
|
+
export function parseGradReward(opt, flag) {
|
|
87
|
+
const num = (s) => /^(\d+(\.\d*)?|\.\d+)$/.test(String(s ?? '').trim())
|
|
88
|
+
const seed = opt('grad-reward')
|
|
89
|
+
if (!num(seed) || !(Number(seed) > 0)) return { error: `--grad-reward needs the seed: a positive amount of the token's quote (e.g. --grad-reward 0.5). ${GRAD_USAGE}`, got: seed ?? null }
|
|
90
|
+
let minBuy = null
|
|
91
|
+
if (flag('gr-min-buy')) {
|
|
92
|
+
minBuy = opt('gr-min-buy')
|
|
93
|
+
if (!num(minBuy) || !(Number(minBuy) > 0)) return { error: '--gr-min-buy must be a positive amount of the quote (the least a buy must actually spend to count)', got: minBuy ?? null }
|
|
94
|
+
}
|
|
95
|
+
const int = (name, def, lo, hi, what) => {
|
|
96
|
+
if (!flag(name)) return { v: def }
|
|
97
|
+
const n = Number(opt(name))
|
|
98
|
+
if (!Number.isInteger(n) || n < lo || n > hi) return { error: `--${name} must be an integer between ${lo} and ${hi} (${what})`, got: opt(name) ?? null }
|
|
99
|
+
return { v: n }
|
|
100
|
+
}
|
|
101
|
+
const e = int('gr-entries', DEFAULTS.entries, 1, MAX_ENTRIES, 'how many of the last counted buys share the pool')
|
|
102
|
+
if (e.error) return e
|
|
103
|
+
const l = int('gr-last', DEFAULTS.lastPct, 0, 50, '% of the payout the graduating buy gets on top')
|
|
104
|
+
if (l.error) return l
|
|
105
|
+
const r = int('gr-refund-days', DEFAULTS.refundDays, 30, 180, 'days after the create before you may ask for the pool back')
|
|
106
|
+
if (r.error) return r
|
|
107
|
+
return { seed: String(seed).trim(), minBuy: minBuy && String(minBuy).trim(), entries: e.v, lastBps: l.v * 100, refundDays: r.v }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Whether `ctx.pad` takes a graduation reward now: { open: true } / { open: false, why } / { unread }. */
|
|
111
|
+
export async function gradSupport(ctx) {
|
|
112
|
+
if (ctx.gen !== PAD3_GEN) return { open: false, why: `GangLaunchpad ${ctx.gen ?? ctx.pad} has no graduation reward (3.0 only)` }
|
|
113
|
+
let deps
|
|
114
|
+
try { deps = await ctx.read(ctx.pad, GRAD_PAD_ABI, 'gradRewardDeps') } catch (e) {
|
|
115
|
+
if (missingRead(e)) return { open: false, why: `GangLaunchpad 3.0 on ${ctx.chainId === '97' ? 'the BSC testnet' : 'BSC mainnet'} has no graduation reward yet (the pad is not upgraded for it)` }
|
|
116
|
+
return { unread: e.shortMessage || e.message.split('\n')[0] }
|
|
117
|
+
}
|
|
118
|
+
if (!deps[0]) return { open: false, why: 'the graduation reward is closed on this pad' }
|
|
119
|
+
return { open: true, countdownFactory: deps[2] }
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** `amountBnb` (a decimal string) in the quote, at the rate the curve's graduation amount fixes (gradAmt ÷ target BNB). */
|
|
123
|
+
export const bnbInQuote = (amountBnb, gradAmt, targetBnb) =>
|
|
124
|
+
(parseUnits(String(amountBnb), 18) * gradAmt) / parseUnits(String(targetBnb), 18)
|
|
125
|
+
|
|
126
|
+
const iso = (s) => (Number(s) > 0 ? new Date(Number(s) * 1000).toISOString() : null)
|
|
127
|
+
const pctOf = (bps) => Number(bps) / 100
|
|
128
|
+
|
|
129
|
+
/** What the create preview says about the reward (pure; amounts as display strings). */
|
|
130
|
+
export function gradCreateView({ seed, minBuy, sym, entries, lastBps, refundDays, targetBnb, seedFloorNote, gateOn }) {
|
|
131
|
+
const last = pctOf(lastBps)
|
|
132
|
+
return {
|
|
133
|
+
pool: `${seed} ${sym}`, payWithThisTx: `${seed} ${sym}, pulled from this wallet in the create (approve the pad for it first)`,
|
|
134
|
+
minBuy: `${minBuy} ${sym}`, entries, lastPct: last, refundDays,
|
|
135
|
+
who: `the last ${entries} curve buys that each actually spend at least ${minBuy} ${sym} (after a wallet-cap or graduation cut); the buy that graduates the token at ${targetBnb} BNB counts whatever it spends. Only while the pad's Agent gate is on (${gateOn ? 'it is on now' : 'IT IS OFF NOW: no buy would count until gang turns it back on'}): with it off, no buy counts`,
|
|
136
|
+
split: last > 0
|
|
137
|
+
? `at graduation the buy that graduates it gets ${last}% of the pool on top; then all ${entries} entries, it included, split the rest by what each spent (a wallet with several entries adds them up)`
|
|
138
|
+
: `at graduation all ${entries} entries split the pool by what each spent (a wallet with several entries adds them up)`,
|
|
139
|
+
sells: 'a curve sell takes out every entry that wallet has so far; a later buy of the same wallet counts again',
|
|
140
|
+
claims: `buyers claim with gang grad-reward claim for ${CLAIM_DAYS} days after graduation; then anyone sweeps the unclaimed rest (and the rounding dust) back to you (to the token's countdown reward module instead, if its tax recipient is one)`,
|
|
141
|
+
refund: `if the token does not graduate: ${refundDays} days after the create you may ask for the pool back (gang grad-reward refund-request). The request is public for ${NOTICE_DAYS} days; a graduation in that time pays the buyers as usual. Then you have ${WINDOW_DAYS} days to take it (gang grad-reward refund), after which the request lapses and must be made again`,
|
|
142
|
+
notABet: NOT_A_BET,
|
|
143
|
+
risks: 'anyone watching the curve can time the last buys, and one person with several Agent IDs can fill several entries: weighting by spend means many small entries earn no more than one large one, but a push into a full list still crowds out the oldest entries. A higher --gr-min-buy and more --gr-entries make that harder',
|
|
144
|
+
...(seedFloorNote && { seedFloor: seedFloorNote }),
|
|
145
|
+
warning: `PERMANENT: ${seed} ${sym} leaves this wallet in the create. You get it back only through the refund above (if the token does not graduate) or as the unclaimed rest 180 days after graduation. The size, the rules and the numbers never change`,
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The token's reward as the pad says (null: none). `me`: a wallet to report its entries and claim for. All amounts in
|
|
151
|
+
* the quote's units.
|
|
152
|
+
*/
|
|
153
|
+
export async function gradOf(ctx, token, quote, me = null) {
|
|
154
|
+
if (ctx.gen !== PAD3_GEN) return null
|
|
155
|
+
let v
|
|
156
|
+
try { v = await ctx.read(ctx.pad, GRAD_PAD_ABI, 'gradReward', [token]) } catch (e) {
|
|
157
|
+
if (missingRead(e)) return null
|
|
158
|
+
throw e
|
|
159
|
+
}
|
|
160
|
+
if (Number(v.state) === 0) return null
|
|
161
|
+
const [ent, gated, block] = await Promise.all([
|
|
162
|
+
ctx.read(ctx.pad, GRAD_PAD_ABI, 'gradEntries', [token]), ctx.read(ctx.pad, GRAD_PAD_ABI, 'agentGateEnabled'), ctx.client.getBlock(),
|
|
163
|
+
])
|
|
164
|
+
const u = (x) => units(ctx, quote, x)
|
|
165
|
+
const [buyers, seqs, spent, valid] = ent
|
|
166
|
+
const list = await Promise.all(buyers.map(async (b, i) => ({ buyer: b, seq: Number(seqs[i]), spent: await u(spent[i]), valid: valid[i], ...(me && b.toLowerCase() === me.toLowerCase() && { you: true }) })))
|
|
167
|
+
const now = Number(block.timestamp)
|
|
168
|
+
const state = Number(v.state)
|
|
169
|
+
const refundAt = Number(v.refundAt)
|
|
170
|
+
const claimable = me && state === 2 ? await ctx.read(ctx.pad, GRAD_PAD_ABI, 'gradClaimable', [token, me]) : 0n
|
|
171
|
+
return {
|
|
172
|
+
state: STATES[state] ?? String(state), pool: await u(v.pot), minBuy: await u(v.minBuy), entries: Number(v.entries), lastPct: pctOf(v.lastBps),
|
|
173
|
+
...(Number(v.carryBps) > 0 && { carryPct: pctOf(v.carryBps) }),
|
|
174
|
+
...(v.countdown !== '0x0000000000000000000000000000000000000000' && { countdown: v.countdown, restGoesTo: 'the token\'s countdown reward module (the rest after the claim window, or the whole payout if no entry is valid)' }),
|
|
175
|
+
counted: Number(v.seq), gateOn: gated, list,
|
|
176
|
+
createdAt: iso(v.createdAt), refundAskableAt: iso(Number(v.createdAt) + Number(v.refundAfter)),
|
|
177
|
+
...(refundAt > 0 && state === 1 && {
|
|
178
|
+
refund: v.refundPending
|
|
179
|
+
? { requestedAt: iso(refundAt), takeableFrom: iso(refundAt + NOTICE_DAYS * 86400), lapsesAt: iso(refundAt + (NOTICE_DAYS + WINDOW_DAYS) * 86400), note: 'the creator asked for the pool back: if the token graduates before the creator takes it, the buyers are paid as usual' }
|
|
180
|
+
: { lapsed: true, note: 'a refund request lapsed: the creator would have to ask again (a fresh 7-day notice)' },
|
|
181
|
+
}),
|
|
182
|
+
...(state >= 2 && Number(v.gradAt) > 0 && { graduatedAt: iso(v.gradAt), sweepableAt: iso(Number(v.gradAt) + CLAIM_DAYS * 86400), claimed: await u(v.claimed) }),
|
|
183
|
+
...(v.carryOwed > 0n && { carryOwed: await u(v.carryOwed) }),
|
|
184
|
+
...(v.settled && { validEntries: Number(v.valid) }),
|
|
185
|
+
...(me && { wallet: me, ...(state === 2 && { claimable: await u(claimable) }) }),
|
|
186
|
+
raw: { state, settled: v.settled, countdown: v.countdown, pot: v.pot, minBuy: v.minBuy, lastBps: Number(v.lastBps), refundAt, refundPending: v.refundPending, refundAfter: Number(v.refundAfter), createdAt: Number(v.createdAt), gradAt: Number(v.gradAt), carryOwed: v.carryOwed, claimable, now, gated, buyers, valid },
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* What a curve buy preview says about the reward: whether it would count, the pool, and what the list looks like.
|
|
192
|
+
* `spent`: what the buy actually spends (fee included, after a cut); `graduates`: it is the graduating buy.
|
|
193
|
+
*/
|
|
194
|
+
export async function gradBuyLine(ctx, token, quote, sym, me, spent, graduates) {
|
|
195
|
+
let g
|
|
196
|
+
try { g = await gradOf(ctx, token, quote, me) } catch (e) {
|
|
197
|
+
return { error: 'could not read the token\'s graduation reward (RPC error): whether this buy counts is unknown', detail: e.shortMessage || e.message.split('\n')[0], retry: 'same command again' }
|
|
198
|
+
}
|
|
199
|
+
if (!g || g.raw.state !== 1) return null
|
|
200
|
+
const counts = g.raw.gated && (spent >= g.raw.minBuy || graduates)
|
|
201
|
+
const why = !g.raw.gated ? 'the Agent gate is off now: no buy counts'
|
|
202
|
+
: counts ? (graduates ? 'this buy graduates the token: it counts, and gets the graduating buy\'s share on top' : `it spends at least the ${g.minBuy} ${sym} minimum`)
|
|
203
|
+
: `it spends less than the ${g.minBuy} ${sym} minimum`
|
|
204
|
+
const asOf = 'as the curve stands now: a buy landing first can change it (e.g. who graduates the token)'
|
|
205
|
+
return {
|
|
206
|
+
counts, why, asOf, pool: `${g.pool} ${sym}`, entries: g.entries, lastPct: g.lastPct, countedSoFar: g.counted,
|
|
207
|
+
note: `${g.entries} entries share the pool at graduation by what each spent${g.lastPct > 0 ? `, the graduating buy ${g.lastPct}% on top` : ''}. Selling on the curve before graduation takes this wallet's entries out. ${NOT_A_BET}`,
|
|
208
|
+
...(g.refund && { refund: g.refund }),
|
|
209
|
+
more: `gang grad-reward status --token ${token}${ctx.chainId === '97' ? ' --testnet' : ''}`,
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** What a curve sell preview warns about: the seller's valid entries it takes out (null: nothing to say). */
|
|
214
|
+
export async function gradSellLine(ctx, token, quote, sym, me) {
|
|
215
|
+
let g
|
|
216
|
+
try { g = await gradOf(ctx, token, quote, me) } catch (e) {
|
|
217
|
+
return { warning: 'could not read the token\'s graduation reward (RPC error): if it has one, this sell takes out your entries in its list. Re-run before you sell to see them', detail: e.shortMessage || e.message.split('\n')[0], retry: 'same command again' }
|
|
218
|
+
}
|
|
219
|
+
if (!g || g.raw.state !== 1) return null
|
|
220
|
+
const mine = g.list.filter((x) => x.you && x.valid).length
|
|
221
|
+
if (!mine) return null
|
|
222
|
+
return { warning: `this sell takes out your ${mine} entr${mine === 1 ? 'y' : 'ies'} in the graduation reward list (pool ${g.pool} ${sym}): only a later buy of yours would count again`, entriesLost: mine }
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function gradCtx(testnet) {
|
|
226
|
+
const net = padNets('v3')[testnet ? 'testnet' : 'mainnet']
|
|
227
|
+
if (!net.pad) throw new Error(NOT_ON_MAINNET)
|
|
228
|
+
const client = createPublicClient({ chain: net.chain, transport: rpcTransport(net.rpcs) })
|
|
229
|
+
return { ...net, client, read: (address, abi, functionName, args = []) => client.readContract({ address, abi, functionName, args }) }
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const CURVE_ABI = parseAbi(['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)',
|
|
233
|
+
'function symbol() view returns (string)'])
|
|
234
|
+
|
|
235
|
+
const SUBS = ['status', 'claim', 'settle', 'sweep', 'retry-carry', 'refund-request', 'refund-cancel', 'refund']
|
|
236
|
+
const USAGE = 'usage: gang grad-reward <status|claim|settle|sweep|retry-carry|refund-request|refund-cancel|refund> --token <addr> [--testnet] [--calldata] [--from <addr>] — see gang help'
|
|
237
|
+
const FN = {
|
|
238
|
+
claim: 'claimGradReward', settle: 'settleGradReward', sweep: 'sweepGradReward', 'retry-carry': 'retryCarry',
|
|
239
|
+
'refund-request': 'requestGradRefund', 'refund-cancel': 'cancelGradRefund', refund: 'gradRefund',
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** `gang grad-reward <sub>`: a 3.0 curve token's graduation reward. */
|
|
243
|
+
export async function runGradReward(sub, { opt, flag, out, fail, summarize }) {
|
|
244
|
+
if (!SUBS.includes(sub)) return fail(USAGE, { got: sub ?? null })
|
|
245
|
+
const testnet = flag('testnet')
|
|
246
|
+
let ctx
|
|
247
|
+
try { ctx = gradCtx(testnet) } catch (e) { return fail(e.message) }
|
|
248
|
+
const chainId = Number(ctx.chainId)
|
|
249
|
+
const tn = testnet ? ' --testnet' : ''
|
|
250
|
+
const token = opt('token')
|
|
251
|
+
if (!isAddress(token ?? '')) return fail('--token must be a 3.0 curve token address (0x…)', { got: token ?? null })
|
|
252
|
+
const kind = await atTokenPad(ctx, token)
|
|
253
|
+
if (kind === null) return fail(KIND_UNREAD.error, { token, retry: KIND_UNREAD.retry })
|
|
254
|
+
if (kind !== 'v3') return fail(`not a V3 curve token on a GangLaunchpad (${testnet ? 'BSC testnet' : 'BSC mainnet; add --testnet for a testnet token'})`, { token, chainId, ...(kind && kind !== 'none' && { kind }) })
|
|
255
|
+
let creator, quote
|
|
256
|
+
try { [creator, quote] = await ctx.read(ctx.pad, CURVE_ABI, 'curves', [token]) } catch (e) {
|
|
257
|
+
return fail('could not read the token\'s curve (RPC error)', { token, detail: e.shortMessage || e.message.split('\n')[0], retry: 'same command again' })
|
|
258
|
+
}
|
|
259
|
+
const sym = await ctx.read(quote, CURVE_ABI, 'symbol').catch(() => 'quote')
|
|
260
|
+
let me = null
|
|
261
|
+
try { me = walletFor(ctx, opt('from')) } catch { /* status works without a wallet */ }
|
|
262
|
+
let g
|
|
263
|
+
try { g = await gradOf(ctx, token, quote, me) } catch (e) {
|
|
264
|
+
return fail('could not read the token\'s graduation reward (RPC error)', { token, detail: e.shortMessage || e.message.split('\n')[0], retry: 'same command again' })
|
|
265
|
+
}
|
|
266
|
+
if (!g) return fail('this token has no graduation reward (it was not created with --grad-reward)', { token, pad: ctx.pad, padGen: ctx.gen })
|
|
267
|
+
const { raw, ...shown } = g
|
|
268
|
+
const isCreator = me && me.toLowerCase() === creator.toLowerCase()
|
|
269
|
+
if (sub === 'status') {
|
|
270
|
+
const next = raw.state === 2 && raw.claimable > 0n ? `gang grad-reward claim --token ${token}${tn}`
|
|
271
|
+
: raw.state === 2 && raw.now >= raw.gradAt + CLAIM_DAYS * 86400 ? `gang grad-reward sweep --token ${token}${tn}`
|
|
272
|
+
: raw.carryOwed > 0n ? `gang grad-reward retry-carry --token ${token}${tn}` : null
|
|
273
|
+
return out({ success: true, chainId, token, pad: ctx.pad, quote: sym, creator, ...shown, notABet: NOT_A_BET, ...(next && { next }) })
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (!me) return fail('no wallet: sign in to baw, or pass --from <addr> with --calldata')
|
|
277
|
+
// what each write needs, said before the simulation (which says it too, with the pad's own error)
|
|
278
|
+
const dest = raw.countdown && raw.countdown !== '0x0000000000000000000000000000000000000000' ? `the token's countdown reward module ${raw.countdown}` : `the creator ${creator}`
|
|
279
|
+
const closed = raw.state === 4 ? 'the reward is closed: the claim window is over (or no entry was valid) and the rest was sent on'
|
|
280
|
+
: raw.state === 3 ? 'the creator took the pool back (the token did not graduate in time): there is nothing to claim' : null
|
|
281
|
+
const lapsesAt = raw.refundAt + (NOTICE_DAYS + WINDOW_DAYS) * 86400
|
|
282
|
+
const need = {
|
|
283
|
+
claim: () => closed ?? (raw.state !== 2 ? HINTS.NotGradState : raw.claimable === 0n ? 'nothing to claim for this wallet: it already claimed, or it has no valid entry in the list (not among the last buys counted, or it sold on the curve after its buys)' : null),
|
|
284
|
+
settle: () => closed ?? (raw.state !== 2 ? HINTS.NotGradState : raw.settled ? 'already settled: the entries are counted (claims read them)' : null),
|
|
285
|
+
sweep: () => closed ?? (raw.state !== 2 ? HINTS.NotGradState : raw.now < raw.gradAt + CLAIM_DAYS * 86400 ? HINTS.SweepNotDue : null),
|
|
286
|
+
'retry-carry': () => (raw.carryOwed === 0n ? HINTS.NoCarryOwed : null),
|
|
287
|
+
'refund-request': () => (!isCreator ? 'only the token\'s creator may ask for the pool back' : raw.state !== 1 ? HINTS.NotGradState
|
|
288
|
+
: raw.now < raw.createdAt + raw.refundAfter ? `too early: the pool can be asked back from ${g.refundAskableAt}` : raw.refundPending ? 'a refund request is already running' : null),
|
|
289
|
+
'refund-cancel': () => (!isCreator ? 'only the token\'s creator may cancel its refund request' : !raw.refundPending ? 'no refund request is running' : null),
|
|
290
|
+
refund: () => (!isCreator ? 'only the token\'s creator takes the pool back' : raw.state !== 1 ? HINTS.NotGradState
|
|
291
|
+
: !raw.refundPending ? 'no running refund request: ask first (gang grad-reward refund-request), then wait the 7-day notice'
|
|
292
|
+
: raw.now < raw.refundAt + NOTICE_DAYS * 86400 ? `the 7-day notice runs until ${iso(raw.refundAt + NOTICE_DAYS * 86400)}` : null),
|
|
293
|
+
}[sub]()
|
|
294
|
+
if (need) return fail(need, { token, state: g.state })
|
|
295
|
+
const fn = FN[sub]
|
|
296
|
+
try { await ctx.client.simulateContract({ account: me, address: ctx.pad, abi: GRAD_PAD_ABI, functionName: fn, args: [token] }) } catch (e) {
|
|
297
|
+
const rv = revertOf(e)
|
|
298
|
+
return out({ success: false, step: `grad-reward-${sub}`, ...(rv ? { reverted: true, ...rv } : { reverted: false, error: e.shortMessage || e.message.split('\n')[0] }) })
|
|
299
|
+
}
|
|
300
|
+
const data = encodeFunctionData({ abi: GRAD_PAD_ABI, functionName: fn, args: [token] })
|
|
301
|
+
const note = {
|
|
302
|
+
claim: `pays this wallet ${g.claimable} ${sym}: all its valid entries in the list, once`,
|
|
303
|
+
settle: `counts the valid entries once (the first claim does this too); with none, the payout goes to ${dest}`,
|
|
304
|
+
sweep: `closes the reward: the unclaimed rest goes to ${dest}; no claim after this`,
|
|
305
|
+
'retry-carry': `sends the owed ${g.carryOwed} ${sym} to the countdown reward module again`,
|
|
306
|
+
'refund-request': `starts a public ${NOTICE_DAYS}-day notice: a graduation in that time pays the buyers as usual. Then you have ${WINDOW_DAYS} days to take the pool (gang grad-reward refund), else the request lapses`,
|
|
307
|
+
'refund-cancel': 'cancels the running refund request: the reward stays as it is',
|
|
308
|
+
refund: `takes the whole pool (${g.pool} ${sym}) back to you and ends the reward for good: a later graduation pays nobody. Send it before ${iso(lapsesAt)}: the request lapses then, and the tx would revert`,
|
|
309
|
+
}[sub]
|
|
310
|
+
return out(step(ctx, { from: me, to: ctx.pad, data }, {
|
|
311
|
+
step: `grad-reward-${sub}`, chainId, token, quote: sym, pool: g.pool, ...(sub === 'claim' && { amount: g.claimable }), ...(sub === 'refund' && { lapsesAt: iso(lapsesAt) }), note,
|
|
312
|
+
}, flag('calldata'), summarize))
|
|
313
|
+
}
|
|
314
|
+
|
package/src/help.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `gang buy --help`, `gang create -h`: whether argv (after `gang`) asks a command for its help. The CLI answers with the
|
|
3
|
+
* help text, and the MCP server's gang_cli points to gang_help. A --help / -h right after a flag whose value may be free
|
|
4
|
+
* text is that value, not a request for help. No imports: the MCP server loads this too.
|
|
5
|
+
*/
|
|
6
|
+
const TEXT_FLAGS = new Set(['--note', '--description', '--name', '--symbol'])
|
|
7
|
+
|
|
8
|
+
export const wantsHelp = (argv) => argv.some((a, i) => i > 0 && (a === '--help' || a === '-h') && !TEXT_FLAGS.has(argv[i - 1]))
|
package/src/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
CONFIG, ADDR, listTokens, tokenInfo, quoteBuy, quoteSell, isAgent, balanceOf, allowance,
|
|
4
4
|
calldata, decodeTx, decodeLogs, firstByModuleType, parseEther, fmt, fmtTok, resolvePad, isAddress, client,
|
|
5
5
|
} from './chain.js'
|
|
6
|
+
import { wantsHelp } from './help.js'
|
|
6
7
|
import { baw, bawAddress, bawError, bawFailed, bawSettings, bawStatus, bawPreview, bawExecute } from './baw.js'
|
|
7
8
|
import { uploadLogoFile, uploadMetadata, rehostLogoUrl, isGangLogo, checkGangLogo, tempHost, ipfsCid, ipfsUri, isIpfsUri, cdnUrl, LOGO_UI } from './logo.js'
|
|
8
9
|
import { API, fetchMarket, get as apiGet, rank, watch, parseDuration } from './discover.js'
|
|
@@ -29,6 +30,8 @@ import { runCombo, COMBO_EVENT_ABIS } from './combo.js'
|
|
|
29
30
|
import { runCapped, CAPPED_EVENT_ABIS } from './capped.js'
|
|
30
31
|
import { runFloor, FLOOR_ABI, FLOOR_EVENT_ABIS } from './floor.js'
|
|
31
32
|
import { runBase, BASE_EVENT_ABIS } from './base.js'
|
|
33
|
+
import { GRAD_ALONE, GRAD_EVENT_ABIS, GRAD_FLAGS, runGradReward } from './gradreward.js'
|
|
34
|
+
import { wantsPoolModule } from './promote.js'
|
|
32
35
|
import { runWeekly } from './weekly.js'
|
|
33
36
|
import { runFly, flyCtx, isFlyToken, FLY_EVENT_ABIS, FLY_CREATE_FLAGS } from './fly.js'
|
|
34
37
|
import { FAIR_DEV_BUY, isLaunch, LAUNCH_FLAGS, REDEEM_FEE_ALONE, runLaunch, TAX_CAP_ALONE } from './launch.js'
|
|
@@ -59,6 +62,7 @@ const out = (o) => {
|
|
|
59
62
|
if (o && typeof o === 'object' && o.success === false) {
|
|
60
63
|
process.exitCode = 1 // fail() exits 1 too: a refused send can't look like a success to a script
|
|
61
64
|
if (!o.code) o = { ...o, code: codeOf(o) }
|
|
65
|
+
if (o.code === 'NO_FUNDS' && !o.fund) o = { ...o, fund: /^not enough (BNB|WBNB)\b/.test(String(o.error ?? '')) ? FUND_HINT : FUND_TOKEN_HINT }
|
|
62
66
|
}
|
|
63
67
|
if (refInfo && o && typeof o === 'object' && !('ref' in o)) o = { ...o, ref: refInfo }
|
|
64
68
|
// a failed result built no tx, so it claims no tag; a bad id is always said
|
|
@@ -625,6 +629,38 @@ OPENING BASE (GangLaunchpad 3.0, base-v1, 0.40.0+; the pad says whether it is op
|
|
|
625
629
|
ones send what has vested to the creator (never to the caller). --testnet,
|
|
626
630
|
--calldata, --from as elsewhere
|
|
627
631
|
|
|
632
|
+
GRADUATION REWARD (冲毕业奖励, GangLaunchpad 3.0, 0.42.0+; the pad says whether it is open: BSC testnet now; mainnet once the Safe opens it):
|
|
633
|
+
gang create … --grad-reward <seed> [--gr-min-buy <amount>] [--gr-entries <1-20>] [--gr-last <0-50>] [--gr-refund-days <30-180>]
|
|
634
|
+
you seed a reward pool in the token's quote (pulled in the create: approve first;
|
|
635
|
+
at least 0.1 BNB worth) for the last --gr-entries curve buys (default 10) that each
|
|
636
|
+
actually spend --gr-min-buy (default 0.01 BNB worth), while the pad's Agent gate is
|
|
637
|
+
on; the buy that graduates the token counts whatever it spends and gets --gr-last % of the pool on top (default 30); all
|
|
638
|
+
entries, it included, split the rest by what each spent. A curve sell takes that
|
|
639
|
+
wallet's earlier entries out. Buyers claim for 180 days after graduation, then the
|
|
640
|
+
rest goes back to you (to the token's countdown module if that is its tax recipient). Not graduating: --gr-refund-days (default 90) after the
|
|
641
|
+
create you may ask for it back; the request is public for 7 days (a graduation in
|
|
642
|
+
that time pays the buyers), then you have 3 days to take it, else it lapses. The
|
|
643
|
+
buyers pay nothing extra: it is your money, by a fixed rule, no draw. With --promote
|
|
644
|
+
on an untaxed token or with --recipient; not with --vault / --base / --fair / --fly
|
|
645
|
+
or a launch in one command (--dev-buy, --bond, --buyback, --split, --lp, --tax-cap,
|
|
646
|
+
--floor). gang buy / gang sell previews say whether a buy counts (rewards.gradReward)
|
|
647
|
+
and what a sell takes out
|
|
648
|
+
gang grad-reward status --token <addr> the pool, the rules, the list (newest first, valid or not), the refund state and,
|
|
649
|
+
after graduation, what this wallet can claim
|
|
650
|
+
gang grad-reward claim --token <addr> after graduation: this wallet's share (all its valid entries), once
|
|
651
|
+
gang grad-reward settle --token <addr> anyone, after graduation: count the valid entries (the first claim does too)
|
|
652
|
+
gang grad-reward sweep --token <addr> anyone, 180 days after graduation: the unclaimed rest back to the creator (or the
|
|
653
|
+
token's countdown module); closes the reward
|
|
654
|
+
gang grad-reward retry-carry --token <addr>
|
|
655
|
+
anyone: resend a carry owed to the token's countdown reward module
|
|
656
|
+
gang grad-reward refund-request --token <addr>
|
|
657
|
+
the creator, on the curve, --gr-refund-days after the create: ask for the pool back
|
|
658
|
+
(starts the public 7-day notice)
|
|
659
|
+
gang grad-reward refund-cancel --token <addr>
|
|
660
|
+
the creator: cancel a running refund request
|
|
661
|
+
gang grad-reward refund --token <addr> the creator, within 3 days after the notice, still on the curve: take the pool back.
|
|
662
|
+
--testnet, --calldata, --from as elsewhere
|
|
663
|
+
|
|
628
664
|
BOND (押金承诺, GangBond; any GangLaunchpad token, from create on; GANG_BOND / GANG_TESTNET_BOND = its address):
|
|
629
665
|
gang bond post --token <addr> --hold <tokens|N%> --days <7-90> (--amount <quote> | --cover <coverage %>) [--use-wbnb]
|
|
630
666
|
creator only, any time after create (V3: buy on the curve first): bond in the token's
|
|
@@ -1405,6 +1441,14 @@ function create() {
|
|
|
1405
1441
|
// after a clean preflight: where a first trade usually starts
|
|
1406
1442
|
// gang.fun's setup page: every preflight issue code, step by step, for the user to open on their phone (gang-web-legacy /start)
|
|
1407
1443
|
const SETUP_GUIDE = 'https://gang.fun/start'
|
|
1444
|
+
// a wallet that can't pay: what to tell the user (gang preflight prints the wallet's address)
|
|
1445
|
+
const FUND_HOW = 'send BNB on BNB Smart Chain (BEP-20) to the Agentic Wallet address (gang preflight shows it), keeping about 0.002 BNB more than the trade for gas'
|
|
1446
|
+
const FUND_HINT = `Top up: ${FUND_HOW}; then run the same command again. Nothing was sent.`
|
|
1447
|
+
// a token that pays in an ERC-20 quote (USDT, GANG, …): that token, plus BNB for gas
|
|
1448
|
+
const FUND_TOKEN_HINT = 'Top up: send the token this trade pays in (see need / have) on BNB Smart Chain (BEP-20) to the Agentic Wallet address '
|
|
1449
|
+
+ '(gang preflight shows it), plus about 0.002 BNB for gas; then run the same command again. Nothing was sent.'
|
|
1450
|
+
// below this a wallet can't make a first small buy plus gas: preflight warns, without failing
|
|
1451
|
+
const LOW_BNB = parseEther('0.005')
|
|
1408
1452
|
const PREFLIGHT_NEXT = [
|
|
1409
1453
|
'gang trending: what other agents buy now',
|
|
1410
1454
|
'gang notes --min-hit 0.6: followable calls by authors who hit 60%+',
|
|
@@ -1413,9 +1457,9 @@ const PREFLIGHT_NEXT = [
|
|
|
1413
1457
|
// commands whose JSON result carries `update`; `watch` streams NDJSON and help is plain text
|
|
1414
1458
|
const UPDATE_CHECKED = new Set(['version', '--version', '-v', 'preflight', 'list', 'trending', 'invite', 'weekly', 'hot', 'new', 'near-grad', 'notes', 'agents', 'token', 'info', 'status', 'portfolio', 'quote',
|
|
1415
1459
|
'buy', 'follow', 'sell', 'claim', 'mint', 'withdraw', 'release', 'upload-logo', 'create', 'execute', 'tx', 'fair', 'v3', 'bond',
|
|
1416
|
-
'buyback', 'split', 'lp', 'combo', 'capped', 'floor', 'base', 'fly', 'creator-fee', 'promote', 'call-bond'])
|
|
1460
|
+
'buyback', 'split', 'lp', 'combo', 'capped', 'floor', 'base', 'grad-reward', 'fly', 'creator-fee', 'promote', 'call-bond'])
|
|
1417
1461
|
// gang tx decodes these beside the V2 / Soft / U / S pads' events (GangLaunchpad: both kinds; the tax router; the vaults)
|
|
1418
|
-
const GANG_EVENT_ABIS = [...V3_EVENT_ABIS, ...FAIR_EVENT_ABIS, ...FLY_EVENT_ABIS, ...SPLIT_EVENT_ABIS, ...LP_EVENT_ABIS, ...COMBO_EVENT_ABIS, ...CAPPED_EVENT_ABIS, ...FLOOR_EVENT_ABIS, ...BASE_EVENT_ABIS, ...PROMOTE_EVENT_ABIS, CALL_BOND_ABI]
|
|
1462
|
+
const GANG_EVENT_ABIS = [...V3_EVENT_ABIS, ...FAIR_EVENT_ABIS, ...FLY_EVENT_ABIS, ...SPLIT_EVENT_ABIS, ...LP_EVENT_ABIS, ...COMBO_EVENT_ABIS, ...CAPPED_EVENT_ABIS, ...FLOOR_EVENT_ABIS, ...BASE_EVENT_ABIS, ...GRAD_EVENT_ABIS, ...PROMOTE_EVENT_ABIS, CALL_BOND_ABI]
|
|
1419
1463
|
// Split with three amounts is the event of four module kinds, and the amounts mean different things in each (a buy-back
|
|
1420
1464
|
// splitter's toBuyback / toDev, an LP splitter's toLp / toDev, a promoter pool's toEscrow / toDev, a floor module's
|
|
1421
1465
|
// toTreasury / toPayees): gang tx asks the
|
|
@@ -1500,6 +1544,12 @@ async function pendingReport() {
|
|
|
1500
1544
|
}
|
|
1501
1545
|
|
|
1502
1546
|
async function main() {
|
|
1547
|
+
// agents ask a command for its help (gang buy --help, gang create -h): answer with the help, not an unknown-flag refusal
|
|
1548
|
+
if (cmd !== 'help' && wantsHelp(args)) {
|
|
1549
|
+
record(args, { success: true })
|
|
1550
|
+
console.log(HELP)
|
|
1551
|
+
return
|
|
1552
|
+
}
|
|
1503
1553
|
if (UPDATE_CHECKED.has(cmd)) update = checkUpdate()
|
|
1504
1554
|
// streams and the MCP server print no single result: count the start (MCP tools run this CLI, so each one counts itself)
|
|
1505
1555
|
if (cmd === 'watch' || cmd === 'mcp') record(args, { success: true })
|
|
@@ -1530,6 +1580,17 @@ async function main() {
|
|
|
1530
1580
|
const launch = LAUNCH_FLAGS.find((f) => flag(f))
|
|
1531
1581
|
if (launch) fail(`--${launch}: ${BASE_ALONE}`)
|
|
1532
1582
|
}
|
|
1583
|
+
// --grad-reward (3.0 graduation reward): a V3 create with a reward pool, alone or with --promote; no chained launch
|
|
1584
|
+
const grFlag = GRAD_FLAGS.find((f) => flag(f))
|
|
1585
|
+
if (grFlag && !tokenCreate) fail(`--${grFlag} only applies when creating a token (gang create --grad-reward <seed> …)`)
|
|
1586
|
+
if (tokenCreate && grFlag) {
|
|
1587
|
+
if (!flag('grad-reward')) fail(`--${grFlag} goes with --grad-reward <seed>`)
|
|
1588
|
+
if (flyCreate || flag('fair') || cmd === 'fair') fail(`--grad-reward rewards the last buys of a V3 curve: leave --${flyCreate ? 'fly' : 'fair'} out`)
|
|
1589
|
+
if (flag('base') || flag('vault')) fail(`--grad-reward and --${flag('base') ? 'base' : 'vault'} can't go together`)
|
|
1590
|
+
if (wantsPoolModule('v3', flag, opt)) fail('--grad-reward with --promote on a taxed token: that --promote would start a promoter pool launch, which a --grad-reward create does not take. Add --recipient <your address> (the creator\'s own share stays in the create), or use an untaxed token')
|
|
1591
|
+
const launch = LAUNCH_FLAGS.find((f) => flag(f))
|
|
1592
|
+
if (launch) fail(`--${launch}: ${GRAD_ALONE}`)
|
|
1593
|
+
}
|
|
1533
1594
|
// gang weekly apply takes the same --description / --website / --twitter as a create (they describe the token to come)
|
|
1534
1595
|
const weeklyApply = cmd === 'weekly' && args[1] === 'apply'
|
|
1535
1596
|
for (const name of LINK_FLAGS) {
|
|
@@ -1602,6 +1663,8 @@ async function main() {
|
|
|
1602
1663
|
return runFloor(args[1], { opt, flag, out, fail, summarize: summarizePreview })
|
|
1603
1664
|
case 'base':
|
|
1604
1665
|
return runBase(args[1], { opt, flag, out, fail, summarize: summarizePreview })
|
|
1666
|
+
case 'grad-reward':
|
|
1667
|
+
return runGradReward(args[1], { opt, flag, out, fail, summarize: summarizePreview })
|
|
1605
1668
|
case 'weekly':
|
|
1606
1669
|
return runWeekly(args[1], { opt, flag, out, fail, resolveLogo: resolveLogoUri })
|
|
1607
1670
|
case 'capabilities':
|
|
@@ -1614,26 +1677,39 @@ async function main() {
|
|
|
1614
1677
|
const issues = []
|
|
1615
1678
|
const status = bawStatus()
|
|
1616
1679
|
if (status !== 'CONNECTED') issues.push({ code: 'NOT_SIGNED_IN', fix: 'Run `baw auth signin` and confirm in the Binance App.' })
|
|
1617
|
-
let me = null, settings = null, agent = false
|
|
1680
|
+
let me = null, settings = null, agent = false, balance = null, balanceCut = false
|
|
1618
1681
|
if (status === 'CONNECTED') {
|
|
1619
1682
|
me = bawAddress(); settings = bawSettings()
|
|
1620
1683
|
if (!settings.devMode?.enabled) issues.push({ code: 'DEV_MODE_OFF', fix: 'Enable Developer Mode in Binance App → Agentic Wallet settings.' })
|
|
1621
1684
|
if (!settings.tradeAllTokens) issues.push({ code: 'TRADE_ALL_TOKENS_OFF', fix: 'Enable "Trade all tokens" in Binance App → Agentic Wallet settings, otherwise SELLING Gang tokens is blocked by risk control (buying still works).' })
|
|
1685
|
+
// the BNB balance, read beside the Agent ID check (after the last baw call, which blocks the event loop). Capped at
|
|
1686
|
+
// 3 s: with every RPC down, the transport's retries would hold preflight for far longer. Null when unread
|
|
1687
|
+
const cap = new Promise((r) => { const t = setTimeout(() => { balanceCut = true; r(null) }, 3000); t.unref?.() })
|
|
1688
|
+
balance = Promise.race([client.getBalance({ address: me }), cap]).catch(() => null)
|
|
1622
1689
|
agent = await createGateAgent(me)
|
|
1623
1690
|
if (!agent) issues.push({ code: 'NO_AGENT_ID', fix: 'Claim a .ai Agent ID in Binance Wallet (Agent ID banner). Gang only lets Agent ID holders buy/create.' })
|
|
1624
1691
|
}
|
|
1625
1692
|
// after the baw calls: they block the event loop, and the fetch's short timeout would run out meanwhile
|
|
1626
1693
|
const hot = trendingBlock({ wallet: me })
|
|
1627
|
-
|
|
1694
|
+
// an empty wallet is the next stop after setup: say so now, as a warning (setup itself is done)
|
|
1695
|
+
const bnb = balance && await balance
|
|
1696
|
+
const warnings = bnb != null && bnb < LOW_BNB
|
|
1697
|
+
? [{ code: 'LOW_BNB', fix: 'Top up before the first trade: send BNB on BNB Smart Chain (BEP-20) to the address above, keeping about 0.002 BNB more than the trade for gas.' }]
|
|
1698
|
+
: []
|
|
1699
|
+
out({
|
|
1628
1700
|
success: issues.length === 0, cliVersion: VERSION, status, address: me,
|
|
1629
1701
|
// `launchpad` = createPad: kept for readers of the old field (it used to be the V2 create target)
|
|
1630
1702
|
launchpad: padNets('v3').mainnet.pad, createPad: padNets('v3').mainnet.pad, createPadGen: padNets('v3').mainnet.gen, isAgent: agent,
|
|
1631
1703
|
devMode: settings?.devMode?.enabled ?? null, tradeAllTokens: settings?.tradeAllTokens ?? null, issues,
|
|
1704
|
+
...(bnb != null && { bnb: fmt(bnb) }), ...(warnings.length && { warnings }),
|
|
1632
1705
|
note: 'New create → GangLaunchpad (gang create = gang v3 create; gang fair create for 打新). LaunchpadV2 / Soft / U / S take no new tokens: existing buy / sell only.',
|
|
1633
1706
|
...(!issues.length && { next: PREFLIGHT_NEXT }),
|
|
1634
1707
|
...(issues.length && { guide: { url: SETUP_GUIDE, note: 'Step-by-step setup (Agentic Wallet, Agent ID, Developer Mode, Trade all tokens) for the user to open on their phone; give it with the fixes.' } }),
|
|
1635
1708
|
...await hot.then((t) => (t ? { trending: t } : {})),
|
|
1636
1709
|
})
|
|
1710
|
+
// the cut-off read is still pending and would keep the process (and an MCP host waiting on it) alive: exit once printed
|
|
1711
|
+
if (balanceCut) process.stdout.write('', () => process.exit(process.exitCode ?? 0))
|
|
1712
|
+
return
|
|
1637
1713
|
}
|
|
1638
1714
|
case 'list': {
|
|
1639
1715
|
// --kind v3 / fair: GangLaunchpad tokens (from gang.fun); without it the V2 / Soft / U / S pads, as before
|
package/src/mcp.js
CHANGED
|
@@ -10,6 +10,7 @@ import { homedir } from 'node:os'
|
|
|
10
10
|
import { delimiter, dirname, join, sep } from 'node:path'
|
|
11
11
|
import { createInterface } from 'node:readline'
|
|
12
12
|
import { fileURLToPath } from 'node:url'
|
|
13
|
+
import { wantsHelp } from './help.js'
|
|
13
14
|
import { clientOf } from './telemetry.js'
|
|
14
15
|
import { VERSION } from './version.js'
|
|
15
16
|
|
|
@@ -94,7 +95,7 @@ const tool = (name, title, description, properties, args, annotations, required
|
|
|
94
95
|
|
|
95
96
|
export const TOOLS = [
|
|
96
97
|
tool('gang_help', 'Commands and rules',
|
|
97
|
-
'Every gang command with all its flags (the CLI help) and the full rules. Read it before a create, launch, bond, buyback, split, lp, combo, capped, floor, mint or withdraw, and whenever a flag is unclear; those commands then go through gang_cli.',
|
|
98
|
+
'Every gang command with all its flags (the CLI help) and the full rules. Read it before a create, launch, bond, buyback, split, lp, combo, capped, floor, grad-reward, mint or withdraw, and whenever a flag is unclear; those commands then go through gang_cli.',
|
|
98
99
|
{}, () => [], READ),
|
|
99
100
|
tool('gang_preflight', 'Check wallet setup', 'Signed in to baw, Developer Mode, Trade all tokens, Agent ID; each issue comes with a fix.',
|
|
100
101
|
{}, () => ['preflight'], READ),
|
|
@@ -188,7 +189,7 @@ export const TOOLS = [
|
|
|
188
189
|
{ hash: HASH, pending: { type: 'boolean', description: 'Find the txs of trades approved in the Binance App (no hash needed)' }, testnet: TESTNET },
|
|
189
190
|
(a) => (a.pending ? ['tx', '--pending'] : ['tx', '--hash', a.hash, ...bool('testnet', a.testnet)]), PREVIEW),
|
|
190
191
|
tool('gang_cli', 'Other gang commands',
|
|
191
|
-
'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, several of the last three = one combined recipient, or --tax-cap <amount> = a capped recipient), mint (--ref <inviter> on a Mint Flywheel token), promote buy|status|earnings|claim|claim-pool|activate|work|sweep|bind|reclaim|release-dev (create --promote; gang_buy promoter), 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, call-bond post|status|report|settle|claim|burn|tx (bond your own buy note: gang buy, then call-bond post within 10 minutes), buyback status|set|set-payee|apply|bind|release|split|sweep, split status|distribute|release|set-payee|bind, lp status|set|set-payee|apply|bind|release|split|sweep|add, combo status|distribute|release|set-payee|bind|chunk, capped status|distribute|release|set-payee|bind|chunk, floor status|redeem|distribute|release|set-payee|bind (a token whose tax is kept as a treasury holders can redeem; redeem burns the tokens for good), base status|release (create --base 5|10 --base-vest 30|90|180 on GangLaunchpad 3.0 buys an opening base paid in BNB, locked until graduation, then released linearly to the creator; lost for good if it never graduates), creator-fee [--token] [--claim [--to]] (GangLaunchpad 2.0 / 3.0: 70% of the curve fee, kept for the creator), weekly [apply|withdraw] (the Gang weekly launch event; apply / withdraw preview, --yes on the user OK signs and submits), v3 income, version, capabilities; 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.',
|
|
192
|
+
'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, several of the last three = one combined recipient, or --tax-cap <amount> = a capped recipient), mint (--ref <inviter> on a Mint Flywheel token), promote buy|status|earnings|claim|claim-pool|activate|work|sweep|bind|reclaim|release-dev (create --promote; gang_buy promoter), 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, call-bond post|status|report|settle|claim|burn|tx (bond your own buy note: gang buy, then call-bond post within 10 minutes), buyback status|set|set-payee|apply|bind|release|split|sweep, split status|distribute|release|set-payee|bind, lp status|set|set-payee|apply|bind|release|split|sweep|add, combo status|distribute|release|set-payee|bind|chunk, capped status|distribute|release|set-payee|bind|chunk, floor status|redeem|distribute|release|set-payee|bind (a token whose tax is kept as a treasury holders can redeem; redeem burns the tokens for good), base status|release (create --base 5|10 --base-vest 30|90|180 on GangLaunchpad 3.0 buys an opening base paid in BNB, locked until graduation, then released linearly to the creator; lost for good if it never graduates), grad-reward status|claim|settle|sweep|retry-carry|refund-request|refund-cancel|refund (create --grad-reward <seed> on GangLaunchpad 3.0: a reward pool the creator seeds for the last curve buys before graduation, split by what each spent; a curve sell takes out the entries of that wallet), creator-fee [--token] [--claim [--to]] (GangLaunchpad 2.0 / 3.0: 70% of the curve fee, kept for the creator), weekly [apply|withdraw] (the Gang weekly launch event; apply / withdraw preview, --yes on the user OK signs and submits), v3 income, version, capabilities; 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.',
|
|
192
193
|
{ args: { type: 'array', items: { type: 'string' }, minItems: 1 } }, (a) => a.args, { readOnlyHint: false, destructiveHint: false, openWorldHint: true }, ['args']),
|
|
193
194
|
]
|
|
194
195
|
const BY_NAME = new Map(TOOLS.map((t) => [t.name, t]))
|
|
@@ -235,6 +236,8 @@ export function invalid(t, a) {
|
|
|
235
236
|
}
|
|
236
237
|
}
|
|
237
238
|
if (t.name === 'gang_cli' && Object.hasOwn(NOT_VIA_CLI, a.args[0])) return NOT_VIA_CLI[a.args[0]]
|
|
239
|
+
// gang buy --help prints plain text, which this tool can't return: the help is gang_help's (a --help after a text flag is its value)
|
|
240
|
+
if (t.name === 'gang_cli' && wantsHelp(a.args)) return NOT_VIA_CLI.help
|
|
238
241
|
if (t.name === 'gang_watch') {
|
|
239
242
|
const mode = a.mode || (a.token ? 'token' : 'market')
|
|
240
243
|
if (mode === 'token' && !a.token) return 'mode token needs token'
|
package/src/telemetry.js
CHANGED
|
@@ -66,6 +66,9 @@ export function codeOf(o = {}) {
|
|
|
66
66
|
if (/^this wallet holds no Agent ID/i.test(msg)) return 'NO_AGENT_ID' // this wallet's: an inviter's is a usage matter
|
|
67
67
|
if (/baw auth signin|not signed in/i.test(msg)) return 'NOT_SIGNED_IN'
|
|
68
68
|
if (/unreachable|timed out|fetch failed|ECONN|ENOTFOUND|API 5\d\d|RPC error|data unavailable/i.test(msg)) return 'NETWORK'
|
|
69
|
+
// the wallet can't pay: a new wallet's usual first stop, worth telling apart from a broken command
|
|
70
|
+
// (BNB, WBNB, a quote's symbol such as USDT, or "quote"; case-sensitive, so a sell's "not enough tokens" stays apart)
|
|
71
|
+
if (/^not enough (BNB|WBNB|quote\b|[A-Z][A-Z0-9]{1,11}\b)/.test(msg)) return 'NO_FUNDS'
|
|
69
72
|
if (/revert/i.test(msg)) return 'REVERT'
|
|
70
73
|
// the command itself is wrong: a flag named, or a form the CLI asks for. State errors ("needs at least 3000 shares") are not
|
|
71
74
|
if (/^--|^usage|^pass |^give |^use either |^unknown |^gang .*\b(needs|takes)\b|--[a-z][a-z-]+ must|must be (a|an|one|between) /i.test(msg)) return 'USAGE'
|
|
@@ -95,7 +98,18 @@ export function eventOf(argv, o = {}) {
|
|
|
95
98
|
? { signedIn: o.status === 'CONNECTED', agent: o.isAgent ?? null, dev: o.devMode ?? null, all: o.tradeAllTokens ?? null }
|
|
96
99
|
: null
|
|
97
100
|
const cl = clientOf()
|
|
98
|
-
return { t: Math.floor(Date.now() / 1000), c, s, f, ok, code: ok ? '' :
|
|
101
|
+
return { t: Math.floor(Date.now() / 1000), c, s, f, ok, code: ok ? '' : eventCode(o), pf, ...(cl && { cl }) }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The event's code: codeOf, plus baw's error name after a numeric baw code (953401:SOME_NAME), so a refusal can be read
|
|
106
|
+
* without the message. The name is baw's constant (an upper-case word), never text.
|
|
107
|
+
*/
|
|
108
|
+
function eventCode(o) {
|
|
109
|
+
const code = codeOf(o)
|
|
110
|
+
const name = String(o.errorName ?? '')
|
|
111
|
+
if (!/^\d{1,10}$/.test(code) || !/^[A-Z][A-Z0-9_]{1,30}$/.test(name)) return code
|
|
112
|
+
return `${code}:${name}`.slice(0, 48)
|
|
99
113
|
}
|
|
100
114
|
|
|
101
115
|
let recorded = false
|
package/src/v3.js
CHANGED
|
@@ -17,6 +17,7 @@ import { cappedOf, decoyWarning as cappedDecoyWarning } from './capped.js'
|
|
|
17
17
|
import { floorFactoryAddress, floorOf, floorShown, treasuryShare, typedFloorModule } from './floor.js'
|
|
18
18
|
import { VANITY_ABI, vanityCreate, vanityDeployer } from './vanity.js'
|
|
19
19
|
import { BASE_LOST, BASE_NO_BOND, BASE_PAD_ABI, baseOf as baseVaultView, basePayoff, baseSupport, baseTaxLine, HINTS as BASE_HINTS, parseBase, scheduleLine } from './base.js'
|
|
20
|
+
import { bnbInQuote, DEFAULT_MIN_BUY_BNB, GRAD_FLAGS, GRAD_PAD_ABI, gradBuyLine, gradCreateView, gradOf, gradSellLine, gradSupport, HINTS as GRAD_HINTS, MIN_SEED_BNB, parseGradReward } from './gradreward.js'
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* `gang v3 …` — LaunchpadV3 (tax recipient): a token with its own buy / sell tax (1–5% each), a dividend share and a
|
|
@@ -163,7 +164,9 @@ const VIRTUAL_TOKEN = 1_066_666_666_666_666_666_666_666_667n
|
|
|
163
164
|
const ceilDiv = (a, b) => (a + b - 1n) / b
|
|
164
165
|
|
|
165
166
|
/** Revert name (+ BadTaxConfig reason) of a failed call, or null when it was the RPC. */
|
|
166
|
-
|
|
167
|
+
// the graduation reward's create errors (its claim errors share names with other contracts': not hinted here)
|
|
168
|
+
const { NothingToClaim: _gn, AlreadyClaimed: _ga, ...GRAD_CREATE_HINTS } = GRAD_HINTS
|
|
169
|
+
const revertOf = (e) => revertIn(e, [PAD_ABI, VANITY_ABI, BASE_PAD_ABI, PROMOTE_PAD_ABI, CREATOR_FEE_ABI, GRAD_TARGET_ABI, TAX_ROUTER_ABI, GANG_ROUTER_ABI, MERGED_ERRORS_ABI, GRAD_PAD_ABI], { BadPromoteTerms: PROMOTE_HINTS.BadPromoteTerms, TraderNotOrigin: PROMOTE_HINTS.TraderNotOrigin, ...MERGED_HINTS, ...ROUTER_HINTS, ...BASE_HINTS, ...GRAD_CREATE_HINTS, ...HINTS })
|
|
167
170
|
|
|
168
171
|
/** eth_call `data` from `from`: { result } when it passes, { failed } with the revert (or RPC error) otherwise. */
|
|
169
172
|
async function simulate(ctx, from, to, abi, functionName, args, value = 0n) {
|
|
@@ -401,13 +404,16 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
|
|
|
401
404
|
// 3.0: the opening base (gang create --base): the vault, its size, period and progress
|
|
402
405
|
const baseSeen = await baseVaultView(ctx, token).catch((e) => ({ raw: null, error: `could not read the token's base vault (${e.shortMessage || e.message.split('\n')[0]})`, retry: `gang base status --token ${token}${net}` }))
|
|
403
406
|
const { raw: _baseRaw, ...baseField } = baseSeen ?? {}
|
|
407
|
+
// 3.0: the graduation reward (gang create --grad-reward): the pool, the rules and the list so far
|
|
408
|
+
const grSeen = await gradOf(ctx, token, c.quote).catch((e) => ({ raw: null, error: `could not read the token's graduation reward (${e.shortMessage || e.message.split('\n')[0]})` }))
|
|
409
|
+
const { raw: _grRaw, ...grField } = grSeen ?? {}
|
|
404
410
|
// 3.0: the rule set the token was created under (fixed for good; an upgrade adds rules for new tokens only)
|
|
405
411
|
const tokenVersion = ctx.gen === PAD3_GEN ? await ctx.read(ctx.pad, PAD_ABI, 'tokenVersionOf', [token]).then(Number).catch(() => null) : null
|
|
406
412
|
const nonWbnb = c.quote.toLowerCase() !== String(ctx.wbnb).toLowerCase()
|
|
407
413
|
const graduationNote = c.graduationTargetBnb != null && !c.graduated
|
|
408
414
|
? gradLine(c.graduationTargetBnb, nonWbnb ? `${c.graduationAt} ${c.quoteSymbol || 'of the quote'}` : null) : null
|
|
409
415
|
return out({
|
|
410
|
-
success: true, chainId: Number(ctx.chainId), ...fees, ...pub, ...gen, ...(promote && { promote }), ...(baseSeen && { base: { ...baseField, ...(!baseField.error && { more: `gang base status --token ${token}${net}` }) } }), ...(tokenVersion != null && { tokenVersion }), ...(vault && { vault }), ...(graduationNote && { graduationNote }), taxNote, ...(swapBack && { swapBack }), ...(buyback && { buyback }),
|
|
416
|
+
success: true, chainId: Number(ctx.chainId), ...fees, ...pub, ...gen, ...(promote && { promote }), ...(baseSeen && { base: { ...baseField, ...(!baseField.error && { more: `gang base status --token ${token}${net}` }) } }), ...(grSeen && { gradReward: { ...grField, more: `gang grad-reward status --token ${token}${net}` } }), ...(tokenVersion != null && { tokenVersion }), ...(vault && { vault }), ...(graduationNote && { graduationNote }), taxNote, ...(swapBack && { swapBack }), ...(buyback && { buyback }),
|
|
411
417
|
...(split && { split: { ...split, ...splitWarn } }), ...(lp && { lp: { ...lp, ...lpWarn } }),
|
|
412
418
|
...(combo && { combo: { ...combo, ...(comboWarning && { warning: comboWarning }) } }),
|
|
413
419
|
...(capped && { capped: { ...capped, ...(cappedWarning && { warning: cappedWarning }) } }),
|
|
@@ -515,6 +521,20 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
|
|
|
515
521
|
if (flag('ref-pool')) fail('--base is for WBNB-quoted tokens only: leave --ref-pool out')
|
|
516
522
|
if (flag('dividend') && !/^0+(\.0+)?$/.test(opt('dividend') ?? '')) fail('--base can\'t go with a dividend: a base token takes --dividend 0 (the vault would take a share of the holders\' dividend)', { got: opt('dividend') })
|
|
517
523
|
}
|
|
524
|
+
// --grad-reward: a reward pool you seed for the last buys before graduation (createWithGradReward, 3.0 once
|
|
525
|
+
// upgraded), in the token's quote. With --promote (its share rides in the same create); alone otherwise
|
|
526
|
+
const grFlag = GRAD_FLAGS.find((f) => flag(f))
|
|
527
|
+
if (grFlag && !flag('grad-reward')) fail(`--${grFlag} goes with --grad-reward <seed>`)
|
|
528
|
+
const gr = flag('grad-reward') ? parseGradReward(opt, flag) : null
|
|
529
|
+
if (gr?.error) {
|
|
530
|
+
const { error, ...extra } = gr
|
|
531
|
+
fail(error, extra)
|
|
532
|
+
}
|
|
533
|
+
if (gr) {
|
|
534
|
+
if (vault) fail('--grad-reward and --vault can\'t go together: a vault-bound token takes no graduation reward (its locks move balances outside the curve)')
|
|
535
|
+
if (base) fail('--grad-reward and --base can\'t go together (one create entry each)')
|
|
536
|
+
if (launchFloor || launchPoolModule) fail('--grad-reward goes on a plain create only: no chained launch')
|
|
537
|
+
}
|
|
518
538
|
if (grad !== null && !(grad > 0)) fail('--grad must be the graduation target in BNB raised: 6, 9, 12 or 15', { got: opt('grad') ?? null })
|
|
519
539
|
const buyTax = taxed ? taxOf('buy-tax') : 0
|
|
520
540
|
const sellTax = taxed ? taxOf('sell-tax') : 0
|
|
@@ -571,6 +591,11 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
|
|
|
571
591
|
if (support.unread) fail('could not check the pad for the opening base (RPC error)', { pad: ctx.pad, detail: support.unread, retry: 'same command again' })
|
|
572
592
|
if (!support.open) fail(`${support.why}: drop --base${testnet ? '' : ' (it is on the BSC testnet: --testnet)'}`, { pad: ctx.pad })
|
|
573
593
|
}
|
|
594
|
+
if (gr) {
|
|
595
|
+
const support = await gradSupport(ctx)
|
|
596
|
+
if (support.unread) fail('could not check the pad for the graduation reward (RPC error)', { pad: ctx.pad, detail: support.unread, retry: 'same command again' })
|
|
597
|
+
if (!support.open) fail(`${support.why}: drop --grad-reward${testnet ? '' : ' (it is on the BSC testnet: --testnet)'}`, { pad: ctx.pad })
|
|
598
|
+
}
|
|
574
599
|
// the recipient may be the creator itself: checkTaxConfigFor knows who creates (a pad without it: checkTaxConfig)
|
|
575
600
|
const [ok, reason] = await ctx.read(ctx.pad, PAD_ABI, 'checkTaxConfigFor', [me, tax]).catch((e) => {
|
|
576
601
|
if (!noSuchFunction(e)) throw e
|
|
@@ -621,13 +646,37 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
|
|
|
621
646
|
fail(`not enough BNB for the base: the create pays exactly ${formatUnits(baseCost, 18)} BNB, plus gas`, { wallet: me, haveBnb: formatUnits(native, 18), needBnb: formatUnits(baseCost, 18) })
|
|
622
647
|
}
|
|
623
648
|
}
|
|
624
|
-
//
|
|
625
|
-
|
|
649
|
+
// --grad-reward: the seed and the minimum buy in the quote (the minimum's default and the seed's floor are BNB
|
|
650
|
+
// amounts at the rate the graduation amount fixes); the seed is pulled in the create, so it is approved first
|
|
651
|
+
let grCfg = null, grView = null
|
|
652
|
+
if (gr) {
|
|
653
|
+
const dec = await decimalsOf(ctx, quote)
|
|
654
|
+
const sym = (await symbolOf(ctx, quote)) || 'of the quote'
|
|
655
|
+
const seedRaw = parseUnits(gr.seed, dec)
|
|
656
|
+
const minBuyRaw = gr.minBuy ? parseUnits(gr.minBuy, dec) : bnbInQuote(DEFAULT_MIN_BUY_BNB, gradAmt, targetBnb)
|
|
657
|
+
const seedFloor = bnbInQuote(MIN_SEED_BNB, gradAmt, targetBnb)
|
|
658
|
+
if (seedRaw < seedFloor) fail(`--grad-reward: the seed must be at least ${await units(ctx, quote, seedFloor)} ${sym} (${MIN_SEED_BNB} BNB at this token's rate): a smaller pool is not worth a list`, { got: gr.seed })
|
|
659
|
+
if (seedRaw >= 2n ** 128n || minBuyRaw >= 2n ** 96n || minBuyRaw === 0n) fail('--grad-reward / --gr-min-buy: amount out of range', { seed: gr.seed, minBuy: gr.minBuy })
|
|
660
|
+
grCfg = {
|
|
661
|
+
seed: seedRaw, minBuy: minBuyRaw, entries: gr.entries, lastBps: gr.lastBps, carryBps: 0, refundAfter: gr.refundDays * 86_400,
|
|
662
|
+
promoteBps: promote?.shareBps ?? 0, promoteWindow: promote?.window ?? 0,
|
|
663
|
+
}
|
|
664
|
+
grView = gradCreateView({
|
|
665
|
+
seed: await units(ctx, quote, seedRaw), minBuy: await units(ctx, quote, minBuyRaw), sym, entries: gr.entries, lastBps: gr.lastBps,
|
|
666
|
+
refundDays: gr.refundDays, targetBnb, gateOn: await ctx.read(ctx.pad, GRAD_PAD_ABI, 'agentGateEnabled'),
|
|
667
|
+
...(!gr.minBuy && { seedFloorNote: `--gr-min-buy left out: ${DEFAULT_MIN_BUY_BNB} BNB at this token's rate` }),
|
|
668
|
+
})
|
|
669
|
+
const pre = await fundingStep(ctx, me, quote, seedRaw, sym, 'approve-quote', rawOnly, summarize)
|
|
670
|
+
if (pre) return out(pre.success ? { ...pre, why: `the create pulls the ${grView.pool} reward pool from this wallet` } : pre)
|
|
671
|
+
}
|
|
672
|
+
// createWithVault, createWithPromote, createWithBase and createWithGradReward always take the target (the pad's
|
|
673
|
+
// default when --grad is left out)
|
|
674
|
+
const fn = base ? 'createWithBase' : gr ? 'createWithGradReward' : vault ? 'createWithVault' : promote ? 'createWithPromote' : grad !== null ? 'createWithGradTarget' : 'create'
|
|
626
675
|
const argsOf = (logoURI, metaURI) => (base
|
|
627
676
|
? [name, symbol, logoURI, metaURI, tax, parseUnits(String(targetBnb), 18), { baseBps: base.baseBps, vestDays: base.vestDays }]
|
|
628
677
|
: [name, symbol, logoURI, metaURI, quote, refPool, tax,
|
|
629
|
-
...(vault ? [parseUnits(String(targetBnb), 18), vault] : promote ? [parseUnits(String(targetBnb), 18), promote.shareBps, promote.window] : grad !== null ? [parseUnits(String(grad), 18)] : [])])
|
|
630
|
-
const createAbi = base ? BASE_PAD_ABI : PAD_ABI
|
|
678
|
+
...(gr ? [parseUnits(String(targetBnb), 18), grCfg] : vault ? [parseUnits(String(targetBnb), 18), vault] : promote ? [parseUnits(String(targetBnb), 18), promote.shareBps, promote.window] : grad !== null ? [parseUnits(String(grad), 18)] : [])])
|
|
679
|
+
const createAbi = base ? BASE_PAD_ABI : gr ? GRAD_PAD_ABI : PAD_ABI
|
|
631
680
|
const createData = (logoURI, metaURI) => encodeFunctionData({ abi: createAbi, functionName: fn, args: argsOf(logoURI, metaURI) })
|
|
632
681
|
const vanity = await vanityDeployer(ctx)
|
|
633
682
|
const handler = vanity && taxed ? (await taxContracts(ctx)).handler : zeroAddress
|
|
@@ -705,6 +754,7 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
|
|
|
705
754
|
},
|
|
706
755
|
}),
|
|
707
756
|
...(base && { base: baseView }),
|
|
757
|
+
...(grView && { gradReward: grView }),
|
|
708
758
|
...(vault && {
|
|
709
759
|
padGen: ctx.gen, pad: ctx.pad, vault,
|
|
710
760
|
vaultNote: 'the token is bound to this vault for good. Until graduation the token moves only through the pad: the vault locks a holder\'s tokens (counted in that holder\'s 1% cap) and releases them through the pad, for the holder that sends the tx and holds an Agent ID; after graduation it is a plain token. This create uses up the wallet\'s naming for the vault: one token per naming. A vault-bound token takes no GangBond (gang bond post refuses it): a lock moves tokens out of the creator\'s wallet, which would forfeit a bond',
|
|
@@ -752,9 +802,20 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
|
|
|
752
802
|
: `the 1% wallet cap leaves this wallet room for ${formatUnits(tokensOut, 18)} more tokens only`
|
|
753
803
|
return { spent: s, refund: r, cutBy: cut, cutNote: `${why}: the buy spends ${s} ${c.quoteSymbol} (fee included) and refunds ${r} ${refundAs}` }
|
|
754
804
|
}
|
|
805
|
+
// the token's buy-time rewards (3.0): what this buy means for each, one key per kind
|
|
806
|
+
const rewardsOf = async (tokensOut) => {
|
|
807
|
+
const { spent, cut } = await spentFor(ctx, c, quoteIn, tokensOut, room)
|
|
808
|
+
// the pad graduates the token once the curve holds its graduation amount (realQuote >= gradAmt): a buy whose net
|
|
809
|
+
// reaches what is left graduates it, cut or not
|
|
810
|
+
const feeBps = BigInt(Math.round((await feesOf(ctx)).curveFeePct * 100))
|
|
811
|
+
const graduates = cut === 'graduation' || spent - (spent * feeBps) / 10_000n >= c.curveRaw.remaining
|
|
812
|
+
const gradReward = await gradBuyLine(ctx, token, c.quote, c.quoteSymbol, me, spent, graduates)
|
|
813
|
+
return gradReward ? { rewards: { gradReward } } : {}
|
|
814
|
+
}
|
|
755
815
|
const extra = async (tokensOut, minOut, refundAs = c.quoteSymbol) => ({
|
|
756
816
|
step: 'buy', chainId: Number(ctx.chainId), token, spend: raw, quote: c.quoteSymbol, expectTokens: formatUnits(tokensOut, 18),
|
|
757
817
|
minTokensOut: formatUnits(minOut, 18), ...(await cutOf(tokensOut, refundAs)), curveTaxPct: 0, ...(c.buyTaxPct > 0 && { poolBuyTaxPct: c.buyTaxPct }),
|
|
818
|
+
...(await rewardsOf(tokensOut)),
|
|
758
819
|
})
|
|
759
820
|
// a follow on a token with promoter terms binds the note's author as this wallet's promoter (spec
|
|
760
821
|
// docs/SPEC-AGENT-CALLS-2026-11-09.md §4), when the pad would bind them; --no-promoter keeps it a plain buy
|
|
@@ -873,6 +934,8 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
|
|
|
873
934
|
}
|
|
874
935
|
const pre = await fundingStep(ctx, me, token, amount, c.quoteSymbol, 'approve', rawOnly, summarize)
|
|
875
936
|
if (pre) return out(pre.success ? { ...pre, ...notes.skipped() } : pre)
|
|
937
|
+
// a graduation reward: this sell takes the seller's entries in its list out
|
|
938
|
+
const grSell = await gradSellLine(ctx, token, c.quote, c.quoteSymbol, me)
|
|
876
939
|
const sim = await simulate(ctx, me, ctx.pad, PAD_ABI, 'sell', [token, amount, 0n])
|
|
877
940
|
if (sim.failed) return out({ success: false, step: 'sell', ...sim.failed })
|
|
878
941
|
const minOut = minOf(sim.result, slippage)
|
|
@@ -880,7 +943,7 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
|
|
|
880
943
|
step: 'sell', chainId: Number(ctx.chainId), token, amount: formatUnits(amount, 18), quote: c.quoteSymbol,
|
|
881
944
|
expectOut: await units(ctx, c.quote, sim.result), minOut: await units(ctx, c.quote, minOut), curveTaxPct: 0,
|
|
882
945
|
...(c.sellTaxPct > 0 && { poolSellTaxPct: c.sellTaxPct }),
|
|
883
|
-
curveFeePct: (await feesOf(ctx)).curveFeePct, ...guard?.info, ...callGuard?.info,
|
|
946
|
+
curveFeePct: (await feesOf(ctx)).curveFeePct, ...guard?.info, ...callGuard?.info, ...(grSell && { rewards: { gradReward: grSell } }),
|
|
884
947
|
note: 'expectOut is after the 1% curve fee only (no tax on the curve; the sell tax applies only in the pool after graduation)',
|
|
885
948
|
}, 'sell'))
|
|
886
949
|
}
|