@gangfun/cli 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,7 +6,7 @@ Operate [gang.fun](https://gang.fun) from a Binance **Agentic Wallet**. Curve bu
6
6
 
7
7
  **One command per action (0.12.0+):** `gang buy` / `sell` / `info` / `status` / `claim` / `mint` / `withdraw` / `release` work on every token: the CLI reads the token's kind and runs the V3, 打新 or V2 / Soft code. `gang v3 …` / `gang fair …` stay as aliases.
8
8
 
9
- **铸币飞轮 / Mint Flywheel (0.18.0+):** `gang create --fly` starts a sale on GangFlywheelPad (its own pad, kind 3): shares with a quota per wallet (invites add quota), a pool at the mint price once it fills, and minting that goes on after launch. The unified commands detect these tokens (`kind: "fly"`); `gang fly …` is the alias. Live on BSC mainnet since 2026-10-30 (pad `0x631e66560F4FAE4e486B65349edE48189E48B029`, built in); `--testnet` uses BSC testnet set 2. Rules: `skill/references/fly.md`.
9
+ **铸币飞轮 / Mint Flywheel (0.18.0+):** `gang create --fly` starts a sale on GangFlywheelPad (its own pad, kind 3): shares with a quota per wallet (invites add quota), a pool at the mint price once it fills, and minting that goes on after launch. The unified commands detect these tokens (`kind: "fly"`); `gang fly …` is the alias. Live on BSC mainnet since 2026-10-30 (V1 pad `0x631e66560F4FAE4e486B65349edE48189E48B029`); from 0.21.0 new tokens go to the V2 pad `0x281889ad915c1A95ffc4922235c6314b3Cbd8a5a` (built in; `create --fly` says so while it is not open yet), and every other command follows the token's own pad. `--testnet` uses BSC testnet (V1 set 2, V2 `0x7069…E3d6`). Rules: `skill/references/fly.md`.
10
10
 
11
11
  **V3 tax tokens and 打新 (0.9.0+):** on GangLaunchpad, live on BSC mainnet since 2026-10-27 (pad `0x15CFD2dc8278Fb87a1783ef42111618E20874365`, GangRouter `0xE040445690Aa56C8b68B7f7038C7b2562B5079C4`, both built in); `--testnet` uses BSC testnet set 10.
12
12
 
@@ -83,6 +83,7 @@ gang create --fair --name <n> --symbol <s> [--raise 15] [--cap 0.5] [--hold 60]
83
83
  # steady; every setting can be overridden: --raise 3-50 --quota 5-100 --invite-bonus 0-3 --max-per-tx 1-10 --hold 60-90
84
84
  # --mint-fee 1-3 --exit-fee 1-2 --dev-cut 0-10 --buy-pct 0-50 --sell-tax 1-2 --launch-delay 0-300 --window 300-1800
85
85
  # --cap-mul 1-2 --post-mint|--no-post-mint --tier flat|standard|linear [--step-pct --step-shares --max-mul] --supply-cap 10-500
86
+ # V2 pad only: --guard off|15|20|30 (default off: no pause on price drops) --twap-window 15|30 (default 30); --quota ≤ 10 with post-launch minting
86
87
  gang create --fly --name <n> --symbol <s> [--preset j|steady] [settings…] [--dev-shares 1] [--logo …] [--testnet]
87
88
  gang mint --token <addr> --shares <n> [--ref <inviter>] [--slippage 2] # before launch: the sale price; after: mintPost (pool price or above)
88
89
  gang fly open-early --token <addr> # creator, ≥ 30% sold
@@ -282,7 +283,8 @@ timed-out `gang_execute`, check `gang_status` / the wallet history instead of ex
282
283
  | `GANG_UPDATE_URL` | Where that check asks, default `https://registry.npmjs.org/@gangfun/cli/latest`; set an npm mirror's `…/@gangfun/cli/latest` if npmjs is slow or blocked |
283
284
  | `GANG_PAD` / `GANG_TESTNET_PAD` | Override the merged GangLaunchpad (mainnet / testnet) behind V3 and 打新 (defaults: mainnet `0x15CF…4365`, testnet set 10 `0xFebF…5BB1`). Old names `GANG_V3_PAD` / `GANG_FAIR_PAD`, `GANG_V3_TESTNET_PAD` / `GANG_FAIR_TESTNET_PAD` still work as aliases |
284
285
  | `GANG_TESTNET_RPC_URL` | Testnet RPC, one URL or a comma list (unset: PublicNode, then BNB Chain's testnet nodes); old names `GANG_V3_TESTNET_RPC_URL` / `GANG_FAIR_TESTNET_RPC_URL` still work |
285
- | `GANG_FLY_PAD` / `GANG_TESTNET_FLY_PAD` | GangFlywheelPad (铸币飞轮). Defaults: mainnet `0x631e…B029` (open since 2026-10-30), testnet set 2 `0xD648…951c` |
286
+ | `GANG_FLY_PAD_V2` / `GANG_TESTNET_FLY_PAD_V2` | GangFlywheelPad V2 (铸币飞轮), where new tokens go. Defaults: mainnet `0x2818…8a5a`, testnet `0x7069…E3d6` |
287
+ | `GANG_FLY_PAD` / `GANG_TESTNET_FLY_PAD` | GangFlywheelPad V1 (铸币飞轮). Defaults: mainnet `0x631e…B029` (open since 2026-10-30), testnet set 2 `0xD648…951c` |
286
288
  | `GANG_BOND` / `GANG_TESTNET_BOND` | GangBond (creator bonds, `gang bond`). Defaults: mainnet `0xe92d…14E4` (since 2026-10-29, CLI 0.16.2+), testnet `0xd6a8…1086` |
287
289
  | `GANG_SPLIT_FACTORY` / `GANG_TESTNET_SPLIT_FACTORY` | GangSplitModuleFactory (`--split`). Defaults: mainnet `0x27e0…067c` (since 2026-10-30, CLI 0.19.0+), testnet set 10 `0x5F7d…567E` |
288
290
  | `GANG_LP_FACTORY` / `GANG_TESTNET_LP_FACTORY` | GangLiquiditySplitterFactory (`--lp`). Defaults (CLI 0.20.0+): mainnet `0xE043…C248` (since 2026-10-31), testnet set 10 `0xA729…1591` |
@@ -290,4 +292,4 @@ timed-out `gang_execute`, check `gang_status` / the wallet history instead of ex
290
292
 
291
293
  ## Version
292
294
 
293
- `0.20.0` · repo [gangfun/cli](https://github.com/gangfun/cli) · published to [npm](https://www.npmjs.com/package/@gangfun/cli) on push to `main`
295
+ `0.21.0` · repo [gangfun/cli](https://github.com/gangfun/cli) · published to [npm](https://www.npmjs.com/package/@gangfun/cli) on push to `main`
package/README.zh-CN.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  **一个动作一条命令(0.12.0+):** `gang buy` / `sell` / `info` / `status` / `claim` / `mint` / `withdraw` / `release` 对所有币都能用:CLI 先读出这个币的类型,再执行 V3、打新或 V2 / Soft 的逻辑。`gang v3 …` / `gang fair …` 保留为别名。
8
8
 
9
- **铸币飞轮(0.18.0+):** `gang create --fly` 在 GangFlywheelPad(单独的发射台,kind 3)上开一场铸币飞轮:按份 mint,每个钱包有额度,邀请可以加额度;打满后按 mint 价开池,开池后还能继续 mint。统一命令会自动识别这类币(`kind: "fly"`),`gang fly …` 是别名。2026-10-30 起在 BSC 主网运行(发射台 `0x631e66560F4FAE4e486B65349edE48189E48B029`,已内置);`--testnet` 走 BSC 测试网第 2 套。规则见 `skill/references/fly.md`。
9
+ **铸币飞轮(0.18.0+):** `gang create --fly` 在 GangFlywheelPad(单独的发射台,kind 3)上开一场铸币飞轮:按份 mint,每个钱包有额度,邀请可以加额度;打满后按 mint 价开池,开池后还能继续 mint。统一命令会自动识别这类币(`kind: "fly"`),`gang fly …` 是别名。2026-10-30 起在 BSC 主网运行(V1 发射台 `0x631e66560F4FAE4e486B65349edE48189E48B029`);0.21.0 起新币发在 V2 发射台 `0x281889ad915c1A95ffc4922235c6314b3Cbd8a5a`(已内置;V2 开放前 `create --fly` 会直接说明),其他命令按代币自己的发射台走。`--testnet` 走 BSC 测试网(V1 第 2 套,V2 `0x7069…E3d6`)。规则见 `skill/references/fly.md`。
10
10
 
11
11
  **V3 税收币和打新(0.9.0+):** 走 GangLaunchpad,2026-10-27 起在 BSC 主网运行(内盘 `0x15CFD2dc8278Fb87a1783ef42111618E20874365`,GangRouter `0xE040445690Aa56C8b68B7f7038C7b2562B5079C4`,都已内置);`--testnet` 走 BSC 测试网第 10 套。
12
12
 
@@ -97,6 +97,7 @@ gang tx --pending # 在 Binance App 里批准过的
97
97
  # 铸币飞轮(GangFlywheelPad;主网,--testnet 走测试网第 2 套)。--preset j(默认,J 模板)或 steady,每一项都能单独改:
98
98
  # --raise 3-50 --quota 5-100 --invite-bonus 0-3 --max-per-tx 1-10 --hold 60-90 --mint-fee 1-3 --exit-fee 1-2 --dev-cut 0-10
99
99
  # --buy-pct 0-50 --sell-tax 1-2 --launch-delay 0-300 --window 300-1800 --cap-mul 1-2 --post-mint|--no-post-mint
100
+ # 只限 V2 发射台:--guard off|15|20|30(默认 off:价格下跌时不暂停 mint)--twap-window 15|30(默认 30);开池后 mint 打开时 --quota ≤ 10
100
101
  # --tier flat|standard|linear [--step-pct --step-shares --max-mul] --supply-cap 10-500
101
102
  gang create --fly --name <n> --symbol <s> [--preset j|steady] [设置…] [--dev-shares 1] [--logo …] [--testnet]
102
103
  gang mint --token <addr> --shares <n> [--ref <邀请人>] [--slippage 2] # 开池前按发售价;开池后 mintPost(不低于池子价格)
@@ -246,7 +247,8 @@ Claude Code:`claude mcp add gang -- gang mcp`。同一台机器上 `baw` 要
246
247
  | `GANG_UPDATE_URL` | 新版本检查查询的地址,默认 `https://registry.npmjs.org/@gangfun/cli/latest`;npmjs 慢或打不开时,可以换成 npm 镜像的 `…/@gangfun/cli/latest` |
247
248
  | `GANG_PAD` / `GANG_TESTNET_PAD` | 覆盖合并后的内盘合约 GangLaunchpad(主网 / 测试网),V3 和打新共用(默认:主网 `0x15CF…4365`,测试网第 10 套 `0xFebF…5BB1`)。旧名 `GANG_V3_PAD` / `GANG_FAIR_PAD`、`GANG_V3_TESTNET_PAD` / `GANG_FAIR_TESTNET_PAD` 仍可用(别名) |
248
249
  | `GANG_TESTNET_RPC_URL` | 测试网 RPC,可填一个或逗号分隔的多个(不设时先用 PublicNode,再用 BNB Chain 的测试网节点);旧名 `GANG_V3_TESTNET_RPC_URL` / `GANG_FAIR_TESTNET_RPC_URL` 仍可用 |
249
- | `GANG_FLY_PAD` / `GANG_TESTNET_FLY_PAD` | GangFlywheelPad(铸币飞轮)。默认:主网 `0x631e…B029`(2026-10-30 起开放),测试网第 2 套 `0xD648…951c` |
250
+ | `GANG_FLY_PAD_V2` / `GANG_TESTNET_FLY_PAD_V2` | GangFlywheelPad V2(铸币飞轮),新币发在这里。默认:主网 `0x2818…8a5a`,测试网 `0x7069…E3d6` |
251
+ | `GANG_FLY_PAD` / `GANG_TESTNET_FLY_PAD` | GangFlywheelPad V1(铸币飞轮)。默认:主网 `0x631e…B029`(2026-10-30 起开放),测试网第 2 套 `0xD648…951c` |
250
252
  | `GANG_BOND` / `GANG_TESTNET_BOND` | GangBond(押金承诺,`gang bond`)。默认:主网 `0xe92d…14E4`(2026-10-29 起,CLI 0.16.2+),测试网 `0xd6a8…1086` |
251
253
  | `GANG_SPLIT_FACTORY` / `GANG_TESTNET_SPLIT_FACTORY` | GangSplitModuleFactory(`--split`)。默认:主网 `0x27e0…067c`(2026-10-30 起,CLI 0.19.0+),测试网第 10 套 `0x5F7d…567E` |
252
254
  | `GANG_LP_FACTORY` / `GANG_TESTNET_LP_FACTORY` | GangLiquiditySplitterFactory(`--lp`)。默认(CLI 0.20.0+):主网 `0xE043…C248`(2026-10-31 起),测试网第 10 套 `0xA729…1591` |
@@ -254,4 +256,4 @@ Claude Code:`claude mcp add gang -- gang mcp`。同一台机器上 `baw` 要
254
256
 
255
257
  ## 版本
256
258
 
257
- `0.20.0` · [gangfun/cli](https://github.com/gangfun/cli) · push 到 `main` 自动发布到 [npm](https://www.npmjs.com/package/@gangfun/cli)
259
+ `0.21.0` · [gangfun/cli](https://github.com/gangfun/cli) · push 到 `main` 自动发布到 [npm](https://www.npmjs.com/package/@gangfun/cli)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gangfun/cli",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "description": "Gang launchpad CLI for Binance Agentic Wallet agents: create on GangLaunchpad (untaxed or tax tokens), 打新 fair mint, PancakeSwap pool trades, LaunchpadV2 and legacy Soft/U/S trade.",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/fly.js CHANGED
@@ -14,14 +14,20 @@ import { poolPayBnb, poolTrade } from './pool.js'
14
14
  * tokens are minted. Pool tax: buy 1%, sell 1–2%; holders who minted share part of it (the hold line, `holdBps`).
15
15
  * No GangBond and no buy-back splitter on these tokens (phase 1).
16
16
  * Contracts: gang-launchpad src/flywheel (GangFlywheelPad, FlywheelTaxHandler, GangMintToken; issue #75).
17
- * Env: GANG_FLY_PAD / GANG_TESTNET_FLY_PAD override the pad; the RPCs and the GangRouter (pool trades) are GangLaunchpad's.
17
+ * Two pad versions: V1 (the first pad) and V2 (FlyConfig adds guardBps / twapWindow; post-launch mints check only the
18
+ * TWAP guard and the price above the pool). New tokens go to V2 once it is listed here; every other command uses the
19
+ * token's own pad (token.launchpad()). The tax handler, token and token deployer are the same code on both.
20
+ * Env: GANG_FLY_PAD / GANG_TESTNET_FLY_PAD override V1, GANG_FLY_PAD_V2 / GANG_TESTNET_FLY_PAD_V2 V2; the RPCs and the
21
+ * GangRouter (pool trades) are GangLaunchpad's.
18
22
  */
19
23
  export const FLY_PADS = {
20
- mainnet: { pad: '0x631e66560F4FAE4e486B65349edE48189E48B029', startBlock: 130634782n },
21
- // testnet set 2 (2026-10-30, after the pre-mainnet audit fixes)
22
- testnet: { pad: '0xD6482850aCAC74BA889804931Fc797294777951c', startBlock: 139749672n },
24
+ // V2 deployed 2026-10-31; creates go there (it says so while its migrator is unset: no fallback to V1)
25
+ mainnet: { v1: '0x631e66560F4FAE4e486B65349edE48189E48B029', v2: '0x281889ad915c1A95ffc4922235c6314b3Cbd8a5a', startBlock: 130634782n },
26
+ // V1: testnet set 2 (2026-10-30, after the pre-mainnet audit fixes); V2 from block 139842621 (2026-10-31)
27
+ testnet: { v1: '0xD6482850aCAC74BA889804931Fc797294777951c', v2: '0x706973e4F08dBf1604Cf540d0168428521e0E3d6', startBlock: 139749672n },
23
28
  }
24
29
 
30
+ // V1's FlyConfig; V2 appends guardBps and twapWindow (CFG_V2): a new create / checkConfig selector and Created topic
25
31
  const CFG = '(uint256 raiseBnb, uint16 baseQuota, uint8 inviteBonus, uint8 maxPerTx, uint16 holdBps, uint16 mintFeeBps, uint16 exitFeeBps, uint16 devCutBps, uint16 buyBps, uint16 sellTaxBps, uint32 launchDelay, uint32 window, uint8 windowCapMul, bool postMint, uint8 tierMode, uint16 stepBps, uint32 stepShares, uint16 maxMulX100, uint16 supplyCapMul)'
26
32
  const SALE = '(address creator, address quote, address gate, address pair, uint128 basePrice, uint64 totalShares, uint64 filledAt, uint64 progressAt, uint16 sold, uint16 creatorShares, uint16 markSold, uint16 baseQuota, uint16 holdBps, uint16 mintFeeBps, uint16 exitFeeBps, uint16 devCutBps, uint16 buyBps, uint32 launchDelay, uint32 window, uint8 inviteBonus, uint8 maxPerTx, uint8 windowCapMul, uint8 tierMode, uint16 stepBps, uint32 stepShares, uint16 maxMulX100, bool postMint, bool launched)'
27
33
  export const FLY_PAD_ABI = parseAbi([
@@ -75,6 +81,14 @@ export const FLY_PAD_ABI = parseAbi([
75
81
  'event FeesFlushed(address indexed quote, uint256 amount)',
76
82
  'event ShareWriteFailed(address indexed token, address indexed user, uint256 share)',
77
83
  ])
84
+ const CFG_V2 = CFG.replace(/\)$/, ', uint16 guardBps, uint32 twapWindow)')
85
+ /** What only the V2 pad has (everything else in FLY_PAD_ABI is the same on both). */
86
+ export const FLY_PAD_V2_ABI = parseAbi([
87
+ `function create(string[4] text, address quote, address refPool, ${CFG_V2} cfg, uint256 devShares) returns (address token)`,
88
+ `function checkConfig(${CFG_V2} cfg, uint256 devShares) view returns (bool ok, string reason)`,
89
+ 'function postRulesOf(address token) view returns (uint16 guardBps, uint32 twapWindow)',
90
+ `event Created(address indexed token, address indexed creator, string name, string symbol, string logoURI, address quote, uint256 basePrice, ${CFG_V2} cfg)`,
91
+ ])
78
92
  export const FLY_HANDLER_ABI = parseAbi([
79
93
  'function protectionOf(address token) view returns (uint64 until, address gate, uint256 cap)',
80
94
  'function boughtInWindow(address token, address user) view returns (uint256)',
@@ -100,6 +114,7 @@ export const FLY_HANDLER_ABI = parseAbi([
100
114
  'event ShareWriteFailed(address indexed token, address indexed user, uint256 share)',
101
115
  ])
102
116
  const TOKEN_ABI = parseAbi([
117
+ 'function launchpad() view returns (address)',
103
118
  'function balanceOf(address) view returns (uint256)',
104
119
  'function symbol() view returns (string)',
105
120
  'function totalSupply() view returns (uint256)',
@@ -115,7 +130,7 @@ const DEX_ABI = parseAbi(['function getAmountsOut(uint256 amountIn, address[] pa
115
130
  const GANG_ROUTER_VIEW = parseAbi(['function pancakeRouter() view returns (address)'])
116
131
 
117
132
  /** What `gang tx` decodes a 铸币飞轮 tx's logs with (the pad, the tax handler, the holder-reward vault). */
118
- export const FLY_EVENT_ABIS = [FLY_PAD_ABI, FLY_HANDLER_ABI, VAULT_ABI]
133
+ export const FLY_EVENT_ABIS = [FLY_PAD_ABI, FLY_PAD_V2_ABI, FLY_HANDLER_ABI, VAULT_ABI]
119
134
 
120
135
  // platform constants (FlywheelLogic): the pad's own numbers, fixed in the contract
121
136
  const TOTAL_SHARES = 10_000
@@ -142,7 +157,7 @@ const HINTS = {
142
157
  TooEarly: 'too early: launch waits launchDelay after the fill; open-early needs at least 30% (3,000 shares) sold',
143
158
  OnlyCreator: 'only the creator can open the sale early',
144
159
  Slippage: 'fewer shares / tokens than the minimum: the sale or the price moved; re-run to re-quote',
145
- PriceBelowAverage: 'the pool price is more than 10% below its 30-minute average: post-launch mints pause until it recovers',
160
+ PriceBelowAverage: 'the pool price is too far below its average (V1: 10% under 30 minutes; V2: the sale\'s guard under its TWAP window): post-launch mints pause until it recovers (gang info: postMint)',
146
161
  PriceBelowRecentHigh: 'the pool price is more than 10% below its recent high: post-launch mints pause until it recovers (the high decays 0.5% a minute)',
147
162
  PriceAbovePool: 'the mint price is more than 10% above the pool price right now (the pool just dropped): try again shortly',
148
163
  PaceExceeded: 'this wallet minted too much too fast: recent post-launch mints (decaying over 30 minutes) plus this one may be at most 2% of the pool\'s quote side; mint fewer shares or wait',
@@ -164,32 +179,63 @@ const HINTS = {
164
179
  }
165
180
  const revertOf = (e) => revertIn(e, [FLY_PAD_ABI, FLY_HANDLER_ABI, TOKEN_ABI, ROUTER_ABI, MERGED_ERRORS_ABI], { ...MERGED_HINTS, ...ROUTER_HINTS, ...HINTS })
166
181
 
167
- /** Network settings: GangLaunchpad's chain, RPCs, WBNB and GangRouter (pool trades), with the fly pad. */
182
+ /**
183
+ * Network settings: GangLaunchpad's chain, RPCs, WBNB and GangRouter (pool trades), with the fly pads. ctx.pad /
184
+ * ctx.version start as the create target (V2 when known, else V1); bindPad switches them to a token's own pad.
185
+ */
168
186
  export function flyCtx(testnet) {
169
187
  const net = padNets('v3')[testnet ? 'testnet' : 'mainnet']
170
188
  const fly = FLY_PADS[testnet ? 'testnet' : 'mainnet']
171
- const pad = process.env[testnet ? 'GANG_TESTNET_FLY_PAD' : 'GANG_FLY_PAD'] || fly.pad
189
+ const env = (n) => process.env[testnet ? `GANG_TESTNET_${n}` : `GANG_${n}`]
190
+ const pads = [
191
+ { address: env('FLY_PAD_V2') || fly.v2, version: 2 },
192
+ { address: env('FLY_PAD') || fly.v1, version: 1 },
193
+ ].filter((p) => p.address)
172
194
  const client = createPublicClient({ chain: net.chain, transport: rpcTransport(net.rpcs) })
173
195
  return {
174
- ...net, pad, startBlock: fly.startBlock, client,
196
+ ...net, pads, pad: pads[0].address, version: pads[0].version, startBlock: fly.startBlock, client,
175
197
  read: (address, abi, functionName, args = []) => client.readContract({ address, abi, functionName, args }),
176
198
  }
177
199
  }
178
200
 
179
- /** true when `token` is a 铸币飞轮 token on this pad; null on an RPC error. */
201
+ /**
202
+ * The fly pad `token` belongs to, or null (not a fly token on these pads). A GangMintToken names its pad
203
+ * (launchpad()); other tokens are asked of each pad's kindOf. Throws on an RPC error.
204
+ */
205
+ async function padOf(ctx, token) {
206
+ const named = await ctx.read(token, TOKEN_ABI, 'launchpad').catch(() => null)
207
+ const known = named && ctx.pads.find((p) => same(p.address, named))
208
+ if (known) return known
209
+ for (const p of ctx.pads) {
210
+ if (Number(await ctx.read(p.address, FLY_PAD_ABI, 'kindOf', [token])) === 3) return p
211
+ }
212
+ return null
213
+ }
214
+
215
+ /** true when `token` is a 铸币飞轮 token on one of the pads; null on an RPC error. */
180
216
  export async function isFlyToken(ctx, token) {
181
217
  try {
182
- return Number(await ctx.read(ctx.pad, FLY_PAD_ABI, 'kindOf', [token])) === 3
218
+ return !!(await padOf(ctx, token))
183
219
  } catch {
184
220
  return null
185
221
  }
186
222
  }
187
223
 
224
+ /** Point ctx at `token`'s own pad (V1 or V2); false when it is on neither. */
225
+ async function bindPad(ctx, token) {
226
+ const p = await padOf(ctx, token)
227
+ if (!p) return false
228
+ ctx.pad = p.address
229
+ ctx.version = p.version
230
+ return true
231
+ }
232
+
188
233
  /** The pad takes creates only once its migrator is set (mainnet: when the Safe opens it). */
189
234
  export async function padOpen(ctx) {
190
235
  return (await ctx.read(ctx.pad, FLY_PAD_ABI, 'migrator')) !== zeroAddress
191
236
  }
192
- const CLOSED = 'the 铸币飞轮 (Mint Flywheel) pad on BSC mainnet takes no creates right now (no migrator set): use --testnet to try it there'
237
+ /** The create target has no migrator yet: say which pad, and that existing tokens are not affected. */
238
+ const closed = (ctx, testnet) => `the ${ctx.version === 2 ? 'V2 ' : ''}铸币飞轮 (Mint Flywheel) pad on BSC ${testnet ? 'testnet' : 'mainnet'} is not open yet (no migrator set), so it takes no creates right now; existing 铸币飞轮 tokens keep working${testnet ? '' : '. Use --testnet to try it there'}`
193
239
 
194
240
  const symbolOf = async (ctx, token) => { try { return await ctx.read(token, TOKEN_ABI, 'symbol') } catch { return null } }
195
241
  const pct = (bps) => Number(bps) / 100
@@ -223,7 +269,7 @@ export async function saleOf(ctx, token) {
223
269
  : t >= graceEnds ? (sold >= EARLY_OPEN_SHARES ? 'stalled' : 'refund')
224
270
  : 'filled'
225
271
  return {
226
- token, status, creator: s.creator, quote: s.quote, quoteSymbol, gate: s.gate === zeroAddress ? null : s.gate,
272
+ token, status, padVersion: ctx.version, pad: ctx.pad, creator: s.creator, quote: s.quote, quoteSymbol, gate: s.gate === zeroAddress ? null : s.gate,
227
273
  pair: s.pair === zeroAddress ? null : s.pair, launched: s.launched,
228
274
  sharePriceRaw: s.basePrice, sharePrice: await units(ctx, s.quote, s.basePrice),
229
275
  raise: await units(ctx, s.quote, s.basePrice * BigInt(TOTAL_SHARES)),
@@ -268,7 +314,9 @@ async function poolSide(ctx, token, sale, handler) {
268
314
  unit: `${sale.quoteSymbol || 'quote'} per token`,
269
315
  pool: q112(spot), blockStart: q112(blockStart), recentHigh: q112(high), average30m: q112(average),
270
316
  launchMintPerToken: formatUnits((sale.sharePriceRaw * 10n ** 18n) / TOKENS_PER_SHARE, 18),
271
- note: 'a post-launch mint never pays less per token than the pool price; mints pause while the pool is more than 10% below its 30-minute average or its recent high',
317
+ note: ctx.version === 1
318
+ ? 'a post-launch mint never pays less per token than the pool price; mints pause while the pool is more than 10% below its 30-minute average or its recent high'
319
+ : 'a post-launch mint never pays less per token than the pool price; with the guard on, mints pause while the pool is more than the guard below its average (postRules); the recent high is shown for information only',
272
320
  },
273
321
  protection: {
274
322
  active: t < Number(until), until: iso(Number(until)), endsIn: Math.max(0, Number(until) - t),
@@ -281,44 +329,80 @@ async function poolSide(ctx, token, sale, handler) {
281
329
  }
282
330
  }
283
331
 
284
- // FlywheelPostLogic: a post-launch mint is refused while the pool is more than 10% below its 30-minute average or its
285
- // recent high, or when its buyer price is more than 10% above the pool; FlywheelOracle: the previous block start counts
286
- // for 20 blocks
287
- const MAX_DROP_BPS = 1_000n, HIGH_GAP_BPS = 1_000n, TWAP_FLOOR_BPS = 100n, PREV_START_BLOCKS = 20n
288
- const PAUSE_WHY = {
289
- below_average: 'the pool price is more than 10% below its 30-minute average',
290
- below_recent_high: 'the pool price is more than 10% below its recent high',
291
- above_pool: 'a mint would be priced more than 10% above the pool (it dropped in the last blocks)',
292
- supply_cap: 'the token\'s supply cap leaves no room for a mint',
293
- }
294
- const RESUMES = 'minting resumes once the pool price is back within 10% of both its 30-minute average and its recent high (the high decays 0.5% a minute; the average follows the price over 30 minutes)'
332
+ // Post-launch mint rules (FlywheelPostLogic). V1: refused while the pool is more than 10% below its 30-minute average
333
+ // or its recent high, or when the buyer price (spot, the block start, or 99% of the highest of the high, the average and
334
+ // the previous block start, which counts for 20 blocks) is more than 10% above the pool. V2: refused only while the pool
335
+ // is more than the sale's guard below its TWAP (guard on), or when max(spot, block start) is more than 10% above the pool.
336
+ // Both: one share must fit under the supply cap. BPS = 10,000; prices are UQ112x112.
337
+ const BPS = 10_000n, GAP_BPS = 1_000n, TWAP_FLOOR_BPS = 100n, PREV_START_BLOCKS = 20n
295
338
 
296
339
  /**
297
- * Whether post-launch mints are refused now, by the rules mintPost checks (the wallet's own pace aside): the reads of
298
- * poolSide plus the handler's previous block start, as of the latest block. → { pausedNow, reason, reasons } where reason
299
- * is the first rule mintPost would hit.
340
+ * The rules a post-launch mint of one share breaks now, in the order mintPost checks them (the wallet's pace aside).
341
+ * v: 1 | 2; guardBps (V2): 0 = off; prev (V1): the previous block start (0n once more than 20 blocks old); one: the
342
+ * price of one share; room: the token's mintRoom.
300
343
  */
301
- async function mintPause(ctx, token, sale, handler, side) {
302
- const { spot, blockStart, high, average, room } = side.raw
303
- const BPS = 10_000n
344
+ export function pauseReasons({ v, spot, blockStart, high, average, prev = 0n, guardBps = 0n, one, room }) {
304
345
  const reasons = []
305
- if (spot * BPS < average * (BPS - MAX_DROP_BPS)) reasons.push('below_average')
306
- if (spot * BPS < high * (BPS - HIGH_GAP_BPS)) reasons.push('below_recent_high')
307
- const [bn, [b, bp], packed, one] = await Promise.all([
308
- ctx.client.getBlockNumber(), ctx.read(handler, FLY_HANDLER_ABI, 'blockRefOf', [token]),
309
- ctx.read(handler, FLY_HANDLER_ABI, 'prevBlockStartOf', [token]), ctx.read(ctx.pad, FLY_PAD_ABI, 'sharePrice', [token, 1n]),
310
- ])
311
- const [pb, pp] = BigInt(b) === bn ? [packed >> 224n, packed & ((1n << 224n) - 1n)] : [BigInt(b), bp]
312
- const prev = bn - pb > PREV_START_BLOCKS ? 0n : pp
313
- let ref = high > average ? high : average
314
- if (prev > ref) ref = prev
315
- const floor = (ref * (BPS - TWAP_FLOOR_BPS)) / BPS
316
346
  let price = spot > blockStart ? spot : blockStart
317
- if (floor > price) price = floor
318
- if (price * BPS > spot * (BPS + HIGH_GAP_BPS)) reasons.push('above_pool')
347
+ if (v === 1) {
348
+ if (spot * BPS < average * (BPS - GAP_BPS)) reasons.push('below_average')
349
+ if (spot * BPS < high * (BPS - GAP_BPS)) reasons.push('below_recent_high')
350
+ let ref = high > average ? high : average
351
+ if (prev > ref) ref = prev
352
+ const floor = (ref * (BPS - TWAP_FLOOR_BPS)) / BPS
353
+ if (floor > price) price = floor
354
+ } else if (guardBps !== 0n && spot * BPS < average * (BPS - guardBps)) {
355
+ reasons.push('below_guard') // gang.fun's code for V2's guard (V1 keeps below_average)
356
+ }
357
+ if (price * BPS > spot * (BPS + GAP_BPS)) reasons.push('above_pool')
319
358
  // one share: the buyer's tokens and the liquidity's (at most its price of quote at spot) must fit under the cap
320
359
  if (spot > 0n && price > 0n && (one * Q112) / price + (one * Q112) / spot > room) reasons.push('supply_cap')
321
- return { pausedNow: reasons.length > 0, ...(reasons.length && { reason: reasons[0], reasons, why: PAUSE_WHY[reasons[0]] }) }
360
+ return reasons
361
+ }
362
+
363
+ /** What a rule means and when it lets minting back, for this pad version and its post-launch rules. */
364
+ function pauseText(reason, v, rules) {
365
+ const avg = v === 1 ? '30-minute average' : `${rules.twapWindow / 60}-minute average (TWAP)`
366
+ const guard = v === 1 ? 10 : rules.guardBps / 100
367
+ return {
368
+ why: {
369
+ below_average: `the pool price is more than ${guard}% below its ${avg}`,
370
+ below_guard: `the pool price is more than ${guard}% below its ${avg} (the sale's guard)`,
371
+ below_recent_high: 'the pool price is more than 10% below its recent high',
372
+ above_pool: v === 1 ? 'a mint would be priced more than 10% above the pool (it dropped in the last blocks)' : 'a mint would be priced more than 10% above the pool (it dropped earlier in this block)',
373
+ supply_cap: 'the token\'s supply cap leaves no room for a mint',
374
+ }[reason],
375
+ resumes: reason === 'supply_cap' ? 'post-launch minting is over: the supply cap is reached'
376
+ : v === 1 ? 'minting resumes once the pool price is back within 10% of both its 30-minute average and its recent high (the high decays 0.5% a minute; the average follows the price over 30 minutes)'
377
+ : reason === 'above_pool' ? 'minting resumes in the next block (the price is checked against where the block started)'
378
+ : `minting resumes once the pool price is back within ${guard}% of its ${avg}`,
379
+ }
380
+ }
381
+
382
+ /** The post-launch rules of the token's sale: V2 reads its guard and TWAP window; V1's are fixed. */
383
+ async function postRules(ctx, token) {
384
+ if (ctx.version === 1) return { guardBps: 1_000, twapWindow: 1_800, recentHigh: true }
385
+ const [guardBps, twapWindow] = await ctx.read(ctx.pad, FLY_PAD_V2_ABI, 'postRulesOf', [token])
386
+ return { guardBps: Number(guardBps), twapWindow: Number(twapWindow), recentHigh: false }
387
+ }
388
+
389
+ /**
390
+ * Whether post-launch mints are refused now, by the rules mintPost checks on this token's pad (the wallet's own pace
391
+ * aside), as of the latest block. → { pausedNow, reason, reasons, why, resumes }; reason is the first rule mintPost hits.
392
+ */
393
+ async function mintPause(ctx, token, sale, handler, side) {
394
+ const { spot, blockStart, high, average, room } = side.raw
395
+ const [rules, one] = await Promise.all([postRules(ctx, token), ctx.read(ctx.pad, FLY_PAD_ABI, 'sharePrice', [token, 1n])])
396
+ let prev = 0n
397
+ if (ctx.version === 1) {
398
+ const [bn, [b, bp], packed] = await Promise.all([
399
+ ctx.client.getBlockNumber(), ctx.read(handler, FLY_HANDLER_ABI, 'blockRefOf', [token]), ctx.read(handler, FLY_HANDLER_ABI, 'prevBlockStartOf', [token]),
400
+ ])
401
+ const [pb, pp] = BigInt(b) === bn ? [packed >> 224n, packed & ((1n << 224n) - 1n)] : [BigInt(b), bp]
402
+ prev = bn - pb > PREV_START_BLOCKS ? 0n : pp
403
+ }
404
+ const reasons = pauseReasons({ v: ctx.version, spot, blockStart, high, average, prev, guardBps: BigInt(rules.guardBps), one, room })
405
+ return { pausedNow: reasons.length > 0, ...(reasons.length && { reason: reasons[0], reasons, ...pauseText(reasons[0], ctx.version, rules) }) }
322
406
  }
323
407
 
324
408
  async function poolReserves(ctx, token, pair) {
@@ -390,9 +474,16 @@ const WITHDRAW_TOLERANCE_BPS = 10n
390
474
 
391
475
  /** J-template preset (spec §3–4) and the plain one; every field a flag can override. */
392
476
  export const FLY_PRESETS = {
393
- j: { raise: 20, quota: 10, invite: 1, maxPerTx: 10, hold: 60, mintFee: 1, exitFee: 1, devCut: 10, buyPct: 30, sellTax: 2, launchDelay: 60, window: 600, capMul: 1, postMint: true, tier: 'standard', supplyCap: 100 },
394
- steady: { raise: 20, quota: 100, invite: 0, maxPerTx: 10, hold: 60, mintFee: 1, exitFee: 1, devCut: 0, buyPct: 0, sellTax: 1, launchDelay: 60, window: 600, capMul: 1, postMint: false, tier: 'flat', supplyCap: 100 },
477
+ j: { raise: 20, quota: 10, invite: 1, maxPerTx: 10, hold: 60, mintFee: 1, exitFee: 1, devCut: 10, buyPct: 30, sellTax: 2, launchDelay: 60, window: 600, capMul: 1, postMint: true, tier: 'standard', supplyCap: 100, guard: 'off', twapWindow: 30 },
478
+ steady: { raise: 20, quota: 100, invite: 0, maxPerTx: 10, hold: 60, mintFee: 1, exitFee: 1, devCut: 0, buyPct: 0, sellTax: 1, launchDelay: 60, window: 600, capMul: 1, postMint: false, tier: 'flat', supplyCap: 100, guard: 'off', twapWindow: 30 },
395
479
  }
480
+ // V2 only: the post-launch TWAP guard (off or 15 / 20 / 30% below the average) and its window (15 or 30 minutes). The
481
+ // guard is off by default (the user's choice): minting does not pause on a price drop, and V2's quota cap of 10 shares
482
+ // per wallet bounds what a wallet can mint; the window is still set (it only matters once the guard is on)
483
+ const GUARDS = { off: 0, 15: 1_500, 20: 2_000, 30: 3_000 }
484
+ const TWAP_WINDOWS = { 15: 900, 30: 1_800 }
485
+ // V2: with post-launch minting on, a wallet's quota is at most this many shares and an invite adds at most one
486
+ const MAX_POST_QUOTA = 10, MAX_POST_INVITE = 1
396
487
  // flag → [preset key, min, max, kind]
397
488
  const CREATE_FLAGS = {
398
489
  raise: ['raise', 3, 50, 'num'], quota: ['quota', 5, 100, 'int'], 'invite-bonus': ['invite', 0, 3, 'int'],
@@ -402,7 +493,7 @@ const CREATE_FLAGS = {
402
493
  'cap-mul': ['capMul', 1, 2, 'int'], 'supply-cap': ['supplyCap', 10, 500, 'int'],
403
494
  'step-pct': ['stepPct', 0, 10, 'num'], 'step-shares': ['stepShares', 100, 100_000, 'int'], 'max-mul': ['maxMul', 1, 10, 'num'],
404
495
  }
405
- export const FLY_CREATE_FLAGS = [...Object.keys(CREATE_FLAGS), 'preset', 'tier', 'post-mint', 'no-post-mint', 'dev-shares']
496
+ export const FLY_CREATE_FLAGS = [...Object.keys(CREATE_FLAGS), 'preset', 'tier', 'post-mint', 'no-post-mint', 'dev-shares', 'guard', 'twap-window']
406
497
 
407
498
  /**
408
499
  * Entry for `gang fly <sub>` (and the routed verbs of a fly token). io: { opt, flag, out, fail, summarize, resolveLogo,
@@ -425,6 +516,8 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
425
516
  return t
426
517
  }
427
518
  const loadSale = async (token) => {
519
+ // the token's own pad: V1 and V2 tokens both keep working
520
+ if (!(await bindPad(ctx, token))) fail(`not a 铸币飞轮 (Mint Flywheel) token${testnet ? ' on BSC testnet' : ''}`, { token, chainId, pads: ctx.pads.map((p) => p.address) })
428
521
  const sale = await saleOf(ctx, token)
429
522
  if (!sale) fail(`not a 铸币飞轮 (Mint Flywheel) token on this pad${testnet ? ' (BSC testnet)' : ''}`, { token, chainId, pad: ctx.pad })
430
523
  return sale
@@ -437,24 +530,37 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
437
530
  const limit = parseIntIn(fail, 'limit', opt('limit', '20'), 1, 200)
438
531
  const status = opt('status', 'all')
439
532
  if (!['all', 'minting', 'filled', 'launched'].includes(status)) fail('--status must be minting, filled, launched or all')
440
- const count = Number(await ctx.read(ctx.pad, FLY_PAD_ABI, 'tokenCount'))
533
+ // newest pad first, each newest first (V2's tokens are the newer ones)
534
+ const create = { pad: ctx.pad, version: ctx.version }
441
535
  const items = []
442
- for (let i = count - 1; i >= 0 && items.length < limit; i--) {
443
- const token = await ctx.read(ctx.pad, FLY_PAD_ABI, 'allTokens', [BigInt(i)])
444
- const s = await saleOf(ctx, token)
445
- if (!s) continue
446
- const st = s.status === 'stalled' || s.status === 'refund' ? 'filled' : s.status
447
- if (status !== 'all' && st !== status) continue
448
- items.push({
449
- token, symbol: await symbolOf(ctx, token), status: s.status, quote: s.quoteSymbol, sharePrice: s.sharePrice, raise: s.raise,
450
- sold: s.sold, sharesLeft: s.sharesLeft, mintedShares: s.mintedShares, baseQuota: s.rules.baseQuota, postMint: s.rules.postMint,
451
- pair: s.pair, link: `https://gang.fun/token/${token}`,
452
- next: s.status === 'minting' ? `gang mint --token ${token} --shares <n>${net}`
453
- : s.status === 'launched' ? (s.rules.postMint ? `gang mint --token ${token} --shares <n>${net}` : `gang buy --token ${token} --amount <quote>${net}`)
454
- : `gang info --token ${token}${net}`,
455
- })
536
+ let total = 0
537
+ for (const p of ctx.pads) {
538
+ ctx.pad = p.address
539
+ ctx.version = p.version
540
+ const count = Number(await ctx.read(ctx.pad, FLY_PAD_ABI, 'tokenCount'))
541
+ total += count
542
+ for (let i = count - 1; i >= 0 && items.length < limit; i--) {
543
+ const token = await ctx.read(ctx.pad, FLY_PAD_ABI, 'allTokens', [BigInt(i)])
544
+ const s = await saleOf(ctx, token)
545
+ if (!s) continue
546
+ const st = s.status === 'stalled' || s.status === 'refund' ? 'filled' : s.status
547
+ if (status !== 'all' && st !== status) continue
548
+ items.push({
549
+ token, symbol: await symbolOf(ctx, token), padVersion: p.version, status: s.status, quote: s.quoteSymbol, sharePrice: s.sharePrice, raise: s.raise,
550
+ sold: s.sold, sharesLeft: s.sharesLeft, mintedShares: s.mintedShares, baseQuota: s.rules.baseQuota, postMint: s.rules.postMint,
551
+ pair: s.pair, link: `https://gang.fun/token/${token}`,
552
+ next: s.status === 'minting' ? `gang mint --token ${token} --shares <n>${net}`
553
+ : s.status === 'launched' ? (s.rules.postMint ? `gang mint --token ${token} --shares <n>${net}` : `gang buy --token ${token} --amount <quote>${net}`)
554
+ : `gang info --token ${token}${net}`,
555
+ })
556
+ }
456
557
  }
457
- return out({ success: true, chainId, pad: ctx.pad, total: count, status, count: items.length, items, ...(!(await padOpen(ctx)) && { note: CLOSED }) })
558
+ ctx.pad = create.pad
559
+ ctx.version = create.version
560
+ return out({
561
+ success: true, chainId, createPad: ctx.pad, createPadVersion: ctx.version, pads: ctx.pads.map((p) => ({ version: p.version, pad: p.address })),
562
+ total, status, count: items.length, items, ...(!(await padOpen(ctx)) && { note: closed(ctx, testnet) }),
563
+ })
458
564
  }
459
565
 
460
566
  if (sub === 'info') {
@@ -469,9 +575,13 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
469
575
  Object.assign(extra, view)
470
576
  if (sale.rules.postMint) {
471
577
  const [one, pause] = await Promise.all([ctx.read(ctx.pad, FLY_PAD_ABI, 'sharePrice', [token, 1n]), mintPause(ctx, token, sale, handler, side)])
578
+ const rules = await postRules(ctx, token)
472
579
  extra.postMint = {
473
- sharePriceNow: await units(ctx, sale.quote, one), tierMulNow: Number((one * 100n) / sale.sharePriceRaw) / 100, ...pause,
474
- ...(pause.pausedNow && { resumes: pause.reason === 'supply_cap' ? 'post-launch minting is over: the supply cap is reached' : RESUMES }),
580
+ sharePriceNow: await units(ctx, sale.quote, one), tierMulNow: Number((one * 100n) / sale.sharePriceRaw) / 100,
581
+ rules: ctx.version === 1
582
+ ? { average: '30 minutes', pausesBelowAveragePct: 10, pausesBelowRecentHighPct: 10 }
583
+ : { guardPct: rules.guardBps ? rules.guardBps / 100 : 'off', twapWindowMin: rules.twapWindow / 60 },
584
+ ...pause,
475
585
  }
476
586
  }
477
587
  const [owedTax, swapBack] = await Promise.all([
@@ -537,7 +647,7 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
537
647
  }
538
648
  if (sale.rules.postMint) {
539
649
  const pause = await mintPause(ctx, token, sale, handler, side)
540
- pos.mintPaused = { ...pause, ...(pause.pausedNow && { resumes: pause.reason === 'supply_cap' ? 'post-launch minting is over: the supply cap is reached' : RESUMES }) }
650
+ pos.mintPaused = pause
541
651
  if (acct.view.quotaLeft > 0) {
542
652
  const [acc, paid, fee, tokensOut, ok] = await ctx.read(ctx.pad, FLY_PAD_ABI, 'previewMintPost', [token, who, 1n])
543
653
  pos.mintOneShareNow = acc ? { paid: await units(ctx, sale.quote, paid), fee: await units(ctx, sale.quote, fee), tokensOut: formatUnits(tokensOut, 18), ok } : null
@@ -583,7 +693,7 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
583
693
  const name = opt('name'), symbol = opt('symbol')
584
694
  if (!name || !symbol) fail('--name and --symbol are required')
585
695
  checkMeta()
586
- if (!(await padOpen(ctx))) fail(testnet ? 'the 铸币飞轮 pad on BSC testnet has no migrator set: it takes no creates right now' : CLOSED, { pad: ctx.pad })
696
+ if (!(await padOpen(ctx))) fail(closed(ctx, testnet), { pad: ctx.pad, padVersion: ctx.version })
587
697
  const presetName = opt('preset', 'j')
588
698
  const preset = FLY_PRESETS[presetName]
589
699
  if (!preset) fail(`--preset must be ${Object.keys(FLY_PRESETS).join(' or ')}`, { got: presetName })
@@ -599,9 +709,30 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
599
709
  if (flag('post-mint') && flag('no-post-mint')) fail('give --post-mint or --no-post-mint, not both')
600
710
  if (flag('post-mint')) v.postMint = true
601
711
  if (flag('no-post-mint')) v.postMint = false
712
+ // V2's post-launch rules; a V1 create target has none, so the flags are refused there rather than ignored
713
+ const v2 = ctx.version === 2
714
+ if (!v2 && (flag('guard') || flag('twap-window'))) fail('--guard / --twap-window are settings of the V2 Mint Flywheel pad, which is not live on this network yet: leave them out')
715
+ if (flag('guard')) {
716
+ v.guard = String(opt('guard'))
717
+ if (!(v.guard in GUARDS)) fail('--guard must be off, 15, 20 or 30 (% below the average at which post-launch mints pause)', { got: opt('guard') ?? null })
718
+ }
719
+ if (flag('twap-window')) {
720
+ v.twapWindow = Number(opt('twap-window'))
721
+ if (!(v.twapWindow in TWAP_WINDOWS)) fail('--twap-window must be 15 or 30 (minutes)', { got: opt('twap-window') ?? null })
722
+ }
723
+ if (v2 && v.postMint && v.quota > MAX_POST_QUOTA) {
724
+ fail(`--quota must be 5-${MAX_POST_QUOTA} with post-launch minting on (the V2 pad's rule): lower --quota, or add --no-post-mint`, { quota: v.quota })
725
+ }
726
+ if (v2 && v.postMint && v.invite > MAX_POST_INVITE) {
727
+ fail(`--invite-bonus must be 0-${MAX_POST_INVITE} with post-launch minting on (the V2 pad's rule): lower it, or add --no-post-mint`, { inviteBonus: v.invite })
728
+ }
602
729
  // a pad without the Agent ID gate takes no dev cut (checkConfig refuses one): the preset's goes to 0 unless asked for
603
730
  const gated = await ctx.read(ctx.pad, FLY_PAD_ABI, 'agentGateEnabled')
604
731
  if (!gated && !flag('dev-cut')) v.devCut = 0
732
+ // V2: post-launch minting needs the Agent ID gate (one wallet per ID is what bounds the per-wallet quota)
733
+ if (v2 && v.postMint && !gated) {
734
+ fail('post-launch minting needs the Agent ID gate, which this pad has off right now: add --no-post-mint for a sale that only mints before launch', { pad: ctx.pad })
735
+ }
605
736
  const linear = v.tier === 'linear'
606
737
  if (!linear && ['step-pct', 'step-shares', 'max-mul'].some(flag)) fail('--step-pct / --step-shares / --max-mul only apply with --tier linear')
607
738
  if (linear) { v.stepPct ??= 1; v.stepShares ??= 1_000; v.maxMul ??= 10 }
@@ -613,8 +744,11 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
613
744
  sellTaxBps: bps(v.sellTax), launchDelay: v.launchDelay, window: v.window, windowCapMul: v.capMul, postMint: v.postMint,
614
745
  tierMode: TIERS.indexOf(v.tier), stepBps: linear ? bps(v.stepPct) : 0, stepShares: linear ? v.stepShares : 0,
615
746
  maxMulX100: linear ? Math.round(v.maxMul * 100) : 0, supplyCapMul: v.supplyCap,
747
+ ...(v2 && { guardBps: GUARDS[v.guard], twapWindow: TWAP_WINDOWS[v.twapWindow] }),
616
748
  }
617
- const [ok, reason] = await ctx.read(ctx.pad, FLY_PAD_ABI, 'checkConfig', [cfg, BigInt(devShares)])
749
+ // V2 has its own create / checkConfig (FlyConfig grew): the ABI follows the create target
750
+ const padAbi = v2 ? FLY_PAD_V2_ABI : FLY_PAD_ABI
751
+ const [ok, reason] = await ctx.read(ctx.pad, padAbi, 'checkConfig', [cfg, BigInt(devShares)])
618
752
  if (!ok) fail(`setting out of bounds: ${reason}`, { config: cfgView(cfg) })
619
753
  const quote = flag('quote') ? opt('quote') : ctx.wbnb
620
754
  const refPool = flag('ref-pool') ? opt('ref-pool') : (defaultRefPool(ctx.chainId, quote) ?? zeroAddress)
@@ -640,16 +774,21 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
640
774
  const pre = await fund(ctx, { me: who, token: quote, need, spender: ctx.pad, sym }, rawOnly, summarize)
641
775
  if (pre) return out(pre)
642
776
  const createData = (logoURI, metaURI) => encodeFunctionData({
643
- abi: FLY_PAD_ABI, functionName: 'create', args: [[name, symbol, logoURI, metaURI], quote, refPool, cfg, BigInt(devShares)],
777
+ abi: padAbi, functionName: 'create', args: [[name, symbol, logoURI, metaURI], quote, refPool, cfg, BigInt(devShares)],
644
778
  })
645
779
  const dry = await dryRun(ctx, who, ctx.pad, createData('', ''))
646
780
  if (dry) return out({ success: false, step: 'create', ...dry })
647
781
  const logo = await resolveLogo()
648
782
  const meta = await resolveMeta({ name, symbol, logoURI: logo.logoURI })
649
783
  return out(write({ from: who, to: ctx.pad, data: createData(logo.logoURI, meta.metaURI) }, {
650
- step: 'create', kind: 'fly', name, symbol, logoURI: logo.logoURI, ...(logo.uploaded && { uploaded: true }),
784
+ step: 'create', kind: 'fly', padVersion: ctx.version, pad: ctx.pad, name, symbol, logoURI: logo.logoURI, ...(logo.uploaded && { uploaded: true }),
651
785
  metaURI: meta.metaURI, metadata: meta.metadata, quote: sym || quote, preset: presetName, config: cfgView(cfg),
652
786
  sharePrice: await units(ctx, quote, quoteWbnb ? price : (price * 100n) / 102n), devShares, devCost: await units(ctx, quote, need),
787
+ ...(v2 && v.postMint && {
788
+ guardNote: cfg.guardBps
789
+ ? `post-launch mints pause while the pool is more than ${cfg.guardBps / 100}% below its ${cfg.twapWindow / 60}-minute average (--guard ${cfg.guardBps / 100})`
790
+ : 'the price guard is off (the default): post-launch minting does not pause when the price drops; the quota cap of 10 shares per wallet bounds it. Turn it on with --guard 15|20|30 (% below the average, over --twap-window 15|30 minutes)',
791
+ }),
653
792
  minWallets: Math.ceil(TOTAL_SHARES / cfg.baseQuota),
654
793
  note: '10,000 shares at one price; it launches once they are sold (or you open early at ≥ 30%: gang fly open-early), launchDelay later, by anyone (gang fly launch; gang.fun\'s keeper does it too). Minters can sell back before that at the mint price less the exit fee. No GangBond or buy-back on these tokens.',
655
794
  }))
@@ -742,12 +881,13 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
742
881
  // a rule of the pad / handler / token counts: a quote-token revert (no allowance yet) says nothing about the rule
743
882
  const dry = await dryRun(ctx, who, ctx.pad, data, bnb ? maxSpent : 0n, bnb)
744
883
  const r = dry?.reverted && HINTS[dry.error] ? dry : null
745
- const cap = side.raw.room < tokensOut * 2n
884
+ // no rule from the simulation (e.g. it stopped at the quote transfer): the pad's rules read as gang info does,
885
+ // and what is left when none applies is this wallet's own pace
886
+ const pause = r ? null : await mintPause(ctx, token, sale, handler, side)
746
887
  return out({
747
- success: false, ...extra, error: `a post-launch mint is refused right now${r ? `: ${r.error}` : ''}`,
748
- ...(r ? { reason: r.error, hint: r.hint } : {
749
- reason: cap ? 'supply cap' : 'price or pace rule',
750
- hint: cap ? HINTS.CapExceeded : 'the pool price is more than 10% below its average / recent high, the mint price is more than 10% above the pool, or this wallet hit its 30-minute pace (2% of the pool): wait, or mint fewer shares',
888
+ success: false, ...extra, error: `a post-launch mint is refused right now${r ? `: ${r.error}` : `: ${pause.pausedNow ? pause.reason : 'pace'}`}`,
889
+ ...(r ? { reason: r.error, hint: r.hint } : pause.pausedNow ? { reason: pause.reason, hint: pause.why, resumes: pause.resumes } : {
890
+ reason: 'pace', hint: HINTS.PaceExceeded,
751
891
  }),
752
892
  prices: side.prices, supply: side.supply,
753
893
  })
@@ -977,6 +1117,7 @@ const cfgView = (c) => ({
977
1117
  mintFeePct: pct(c.mintFeeBps), exitFeePct: pct(c.exitFeeBps), devCutPct: pct(c.devCutBps), buyPct: pct(c.buyBps), sellTaxPct: pct(c.sellTaxBps),
978
1118
  launchDelaySec: c.launchDelay, protectionSec: c.window, protectionCapMul: c.windowCapMul, postMint: c.postMint, tier: TIERS[c.tierMode],
979
1119
  ...(c.tierMode === 2 && { stepPct: pct(c.stepBps), stepShares: c.stepShares, maxMul: c.maxMulX100 / 100 }), supplyCapMul: c.supplyCapMul,
1120
+ ...(c.guardBps !== undefined && { guardPct: c.guardBps ? pct(c.guardBps) : 'off', twapWindowMin: c.twapWindow / 60 }),
980
1121
  })
981
1122
 
982
1123
  /** The command that acts on the sale next. `paused`: mintPause (or the wallet's) after launch. */
package/src/index.js CHANGED
@@ -303,7 +303,8 @@ U / S pads) and run that kind's trade. Results of V3 / 打新 / 铸币飞轮 tok
303
303
  [--max-per-tx 1-10] [--hold 60-90] [--mint-fee 1-3] [--exit-fee 1-2] [--dev-cut 0-10] [--buy-pct 0-50]
304
304
  [--sell-tax 1-2] [--launch-delay 0-300] [--window 300-1800] [--cap-mul 1-2] [--post-mint | --no-post-mint]
305
305
  [--tier flat|standard|linear [--step-pct 0-10 --step-shares 100-100000 --max-mul 1-10]] [--supply-cap 10-500]
306
- [--dev-shares <n>] [--quote 0x… --ref-pool 0x…] [--logo …] [--website URL] [--twitter @handle] [--description …]
306
+ [--guard off|15|20|30] [--twap-window 15|30] [--dev-shares <n>] [--quote 0x… --ref-pool 0x…] [--logo …]
307
+ [--website URL] [--twitter @handle] [--description …]
307
308
  a 铸币飞轮 (Mint Flywheel, GangFlywheelPad) sale (mainnet; --testnet = BSC testnet
308
309
  set 2). 10,000 shares at raise / 10,000 each; a quota per wallet
309
310
  (--quota + --invite-bonus per wallet it invites), --max-per-tx per mint, Agent ID
@@ -506,7 +507,10 @@ GANG_PAD / GANG_TESTNET_PAD (the one GangLaunchpad behind both gang v3 and gang
506
507
  and GANG_V3_TESTNET_PAD / GANG_FAIR_TESTNET_PAD still work as aliases), GANG_TESTNET_RPC_URL (aliases
507
508
  GANG_V3_TESTNET_RPC_URL / GANG_FAIR_TESTNET_RPC_URL), GANG_ROUTER / GANG_TESTNET_ROUTER (alias GANG_ROUTER_TESTNET; GangRouter
508
509
  for BNB buys / mints and every pool trade; both default to the built-in mainnet / testnet set 10 addresses),
509
- GANG_FLY_PAD / GANG_TESTNET_FLY_PAD (GangFlywheelPad; default: the built-in mainnet / testnet set 2 addresses)
510
+ GANG_FLY_PAD / GANG_TESTNET_FLY_PAD (GangFlywheelPad V1; default: the built-in mainnet / testnet set 2 addresses),
511
+ GANG_FLY_PAD_V2 / GANG_TESTNET_FLY_PAD_V2 (V2, where new tokens go; default: the built-in mainnet / testnet V2). --guard / --twap-window
512
+ (V2 only): the guard is off by default (post-launch minting does not pause on a price drop; the quota cap of 10 per
513
+ wallet bounds it); --guard 15|20|30 pauses mints while the pool is that % below its average over --twap-window (30)
510
514
 
511
515
  Private RPC: this CLI never broadcasts itself. Trades go out through the Agentic Wallet (gang execute), which picks its
512
516
  own RPC; a --calldata tx is sent by whatever signs it. To keep a large pool buy out of the public mempool (front-running),