@gangfun/cli 0.29.0 → 0.30.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/src/fly.js CHANGED
@@ -2,26 +2,35 @@ import { createPublicClient, parseAbi, encodeFunctionData, decodeEventLog, forma
2
2
  import { defaultRefPool, dividendOf, VAULT_ABI, fundingStep as fund, parseAmount, parseIntIn, parseNum, poolSellQuote, POOL_SELL_HINT, revertOf as revertIn, roomyGas, ROUTER_ABI, ROUTER_HINTS, step, swapBackState, units, GAS_RESERVE } from './steps.js'
3
3
  import { API, get as apiGet } from './discover.js'
4
4
  import { walletFor } from './fair.js'
5
- import { MERGED_ERRORS_ABI, MERGED_HINTS, padNets, rpcTransport } from './gangpad.js'
5
+ import { MERGED_ERRORS_ABI, MERGED_HINTS, PAD3_GEN, padNets, rpcTransport } from './gangpad.js'
6
6
  import { poolPayBnb, poolTrade } from './pool.js'
7
7
 
8
8
  /**
9
- * `gang fly …` — 铸币飞轮 (Mint Flywheel, track `fly`): GangFlywheelPad, its own pad (kind 3) beside GangLaunchpad.
9
+ * `gang fly …` — 铸币飞轮 (Mint Flywheel, track `fly`): kind 3, on GangLaunchpad 3.0 and on GangFlywheelPad V1 / V2.
10
10
  * Before launch: 10,000 shares at one price (sale.basePrice), a quota per wallet (baseQuota + invite bonus), sell-back
11
11
  * at the mint price less an exit fee. The sale fills (or the creator opens it early at ≥ 30%), then anyone launches it
12
12
  * `launchDelay` later: a PancakeSwap pool at the mint price, with a protection window (Agent ID + a per-wallet buy cap).
13
13
  * After launch (sale.postMint) minting goes on at the tier price: the money goes into the pool (part of it buys), the
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
- * Contracts: gang-launchpad src/flywheel (GangFlywheelPad, FlywheelTaxHandler, GangMintToken; issue #75).
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.
16
+ * Contracts: gang-launchpad src/flywheel (GangFlywheelPad, FlywheelTaxHandler, GangMintToken; issue #75), src/gang
17
+ * Pad3FlyModule (docs/SPEC-GANG-LAUNCHPAD-3-2026-11-03.md §10).
18
+ * Three pad versions: V1 (the first pad), V2 (FlyConfig adds guardBps / twapWindow; post-launch mints check only the TWAP
19
+ * guard and the price above the pool) and 3 (GangLaunchpad 3.0's 铸币飞轮 mode: V2's rules and selectors at 3.0's address).
20
+ * New tokens go to 3.0; every other command uses the token's own pad. The tax handler, token and token deployer are the
21
+ * same code on all three. What differs on 3.0, which also holds curve and 打新 tokens:
22
+ * - kindOf(token) tells a fly token: its launchpad() does not (3.0's curve and 打新 tokens name 3.0 too), and allTokens /
23
+ * tokenCount cover every kind (padOf, flyTokensOf);
24
+ * - taxHandler() is the curve / 打新 one: a fly token's is flyTaxHandler() (handlerOf). The holder-reward vault is the same,
25
+ * but vault.launchpadOf(token) names 3.0's vault core, not 3.0, so nothing here reads it;
26
+ * - TOKENS_PER_SHARE() is 打新's 50,000: a fly share stays 100,000 (TOKENS_PER_SHARE below; shareSizeOf(token) on chain);
27
+ * - sales(token) has V2's shape only for a kind-3 token: read it after kindOf.
28
+ * Trades go direct to the pad (and the GangRouter's pool functions): GangGateway cannot mint or sell back 3.0's fly tokens.
29
+ * Env: GANG_FLY_PAD / GANG_TESTNET_FLY_PAD override V1, GANG_FLY_PAD_V2 / GANG_TESTNET_FLY_PAD_V2 V2; 3.0 and the RPCs are
30
+ * GangLaunchpad's (gangpad.js), and so is the GangRouter of pool trades.
22
31
  */
23
32
  export const FLY_PADS = {
24
- // V2 deployed 2026-10-31; creates go there (it says so while its migrator is unset: no fallback to V1)
33
+ // V2 deployed 2026-10-31; its tokens stay there (creates go to 3.0: flyCtx)
25
34
  mainnet: { v1: '0x631e66560F4FAE4e486B65349edE48189E48B029', v2: '0x281889ad915c1A95ffc4922235c6314b3Cbd8a5a', startBlock: 130634782n },
26
35
  // V1: testnet set 2 (2026-10-30, after the pre-mainnet audit fixes); V2 from block 139842621 (2026-10-31)
27
36
  testnet: { v1: '0xD6482850aCAC74BA889804931Fc797294777951c', v2: '0x706973e4F08dBf1604Cf540d0168428521e0E3d6', startBlock: 139749672n },
@@ -55,6 +64,8 @@ export const FLY_PAD_ABI = parseAbi([
55
64
  'function isAgent(address account) view returns (bool)',
56
65
  'function migrator() view returns (address)',
57
66
  'function taxHandler() view returns (address)',
67
+ 'function flyTaxHandler() view returns (address)',
68
+ 'function tokenVersionOf(address token) view returns (uint8)',
58
69
  'function dividendVault() view returns (address)',
59
70
  'function agentGateEnabled() view returns (bool)',
60
71
  'function tokenCount() view returns (uint256)',
@@ -80,9 +91,10 @@ export const FLY_PAD_ABI = parseAbi([
80
91
  'event FeeOwed(address indexed quote, uint256 amount)',
81
92
  'event FeesFlushed(address indexed quote, uint256 amount)',
82
93
  'event ShareWriteFailed(address indexed token, address indexed user, uint256 share)',
94
+ 'event TokenVersionSet(address indexed token, uint8 version)',
83
95
  ])
84
96
  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). */
97
+ /** What V1 does not have: V2's, and 3.0's with the same selectors (everything else in FLY_PAD_ABI is the same on all). */
86
98
  export const FLY_PAD_V2_ABI = parseAbi([
87
99
  `function create(string[4] text, address quote, address refPool, ${CFG_V2} cfg, uint256 devShares) returns (address token)`,
88
100
  `function checkConfig(${CFG_V2} cfg, uint256 devShares) view returns (bool ok, string reason)`,
@@ -145,7 +157,8 @@ const TIERS = ['flat', 'standard', 'linear']
145
157
  // can be the token's first pool touch in its block, which costs more than an estimate made against the block before.
146
158
  // Chapel fork: a pool buy at its bare estimate (431k) ran out of gas inside the holder-share sync and used 428k with
147
159
  // room; a sell that also sold a tax chunk ran out at 750k and used 661k with room (estimate 755k)
148
- const GAS_FLOOR = { buy: 750_000n, sell: 1_200_000n, mintPost: 900_000n, launch: 3_500_000n }
160
+ // a launch on 3.0: 2.54M to 3.80M measured on forks
161
+ const GAS_FLOOR = { buy: 750_000n, sell: 1_200_000n, mintPost: 900_000n, launch: 5_000_000n }
149
162
  const GAS_NOTE = 'gas limit set with room: a hot token\'s first trade in a block costs more than the estimate shows'
150
163
 
151
164
  const HINTS = {
@@ -171,7 +184,7 @@ const HINTS = {
171
184
  ProtectionNotAgent: 'launch protection: only Agent ID holders can buy from the pool until it ends (gang info: protection.until)',
172
185
  ProtectionCapExceeded: 'launch protection: this buy goes past the wallet\'s protected buy cap (gang status: protection.capLeftTokens)',
173
186
  VaultFloorTooHigh: 'the platform\'s dividend vault requires a larger holding than this pad allows, so no sale can be created right now; ask gang to fix the vault setting',
174
- QuoteNotAllowed: '--quote must be WBNB or a listed 18-decimal ERC-20 (leave it out to use WBNB)',
187
+ QuoteNotAllowed: '--quote must be WBNB or a listed 18-decimal ERC-20, and not a token of GangLaunchpad 3.0 (leave it out to use WBNB)',
175
188
  RefPoolRequired: 'this quote needs --ref-pool (a Pancake pool pricing it)',
176
189
  PriceTooSmall: 'the raise in this quote is too small to split into 10,000 shares',
177
190
  FeeOnTransferQuote: 'the quote token takes a fee on transfer; it cannot be used',
@@ -181,13 +194,14 @@ const revertOf = (e) => revertIn(e, [FLY_PAD_ABI, FLY_HANDLER_ABI, TOKEN_ABI, RO
181
194
 
182
195
  /**
183
196
  * 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.
197
+ * ctx.version start as the create target (3.0); bindPad switches them to a token's own pad.
185
198
  */
186
199
  export function flyCtx(testnet) {
187
200
  const net = padNets('v3')[testnet ? 'testnet' : 'mainnet']
188
201
  const fly = FLY_PADS[testnet ? 'testnet' : 'mainnet']
189
202
  const env = (n) => process.env[testnet ? `GANG_TESTNET_${n}` : `GANG_${n}`]
190
203
  const pads = [
204
+ { address: net.gens.find((g) => g.gen === PAD3_GEN)?.pad, version: 3 },
191
205
  { address: env('FLY_PAD_V2') || fly.v2, version: 2 },
192
206
  { address: env('FLY_PAD') || fly.v1, version: 1 },
193
207
  ].filter((p) => p.address)
@@ -201,13 +215,14 @@ export function flyCtx(testnet) {
201
215
  }
202
216
 
203
217
  /**
204
- * The fly pad `token` belongs to, or null (not a fly token on these pads). A GangMintToken names its pad
205
- * (launchpad()); other tokens are asked of each pad's kindOf. Throws on an RPC error.
218
+ * The fly pad `token` belongs to, or null (not a fly token on these pads). A GangMintToken names its pad (launchpad()),
219
+ * and every token of V1 / V2 is a fly token; 3.0 also holds curve and 打新 tokens that name it, so only its kindOf counts.
220
+ * Other tokens are asked of each pad's kindOf. Throws on an RPC error.
206
221
  */
207
222
  async function padOf(ctx, token) {
208
223
  const named = await ctx.read(token, TOKEN_ABI, 'launchpad').catch(() => null)
209
224
  const known = named && ctx.pads.find((p) => same(p.address, named))
210
- if (known) return known
225
+ if (known && known.version !== 3) return known
211
226
  for (const p of ctx.pads) {
212
227
  if (Number(await ctx.read(p.address, FLY_PAD_ABI, 'kindOf', [token])) === 3) return p
213
228
  }
@@ -223,7 +238,7 @@ export async function isFlyToken(ctx, token) {
223
238
  }
224
239
  }
225
240
 
226
- /** Point ctx at `token`'s own pad (V1 or V2); false when it is on neither. */
241
+ /** Point ctx at `token`'s own pad (V1, V2 or 3.0); false when it is on none. */
227
242
  async function bindPad(ctx, token) {
228
243
  const p = await padOf(ctx, token)
229
244
  if (!p) return false
@@ -237,7 +252,7 @@ export async function padOpen(ctx) {
237
252
  return (await ctx.read(ctx.pad, FLY_PAD_ABI, 'migrator')) !== zeroAddress
238
253
  }
239
254
  /** The create target has no migrator yet: say which pad, and that existing tokens are not affected. */
240
- 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'}`
255
+ const closed = (ctx, testnet) => `the ${{ 3: 'GangLaunchpad 3.0 ', 2: 'V2 ' }[ctx.version] ?? ''}铸币飞轮 (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'}`
241
256
 
242
257
  const symbolOf = async (ctx, token) => { try { return await ctx.read(token, TOKEN_ABI, 'symbol') } catch { return null } }
243
258
  const pct = (bps) => Number(bps) / 100
@@ -252,6 +267,25 @@ const q112 = (p) => formatUnits((p * 10n ** 18n) / Q112, 18)
252
267
  const same = (a, b) => String(a).toLowerCase() === String(b).toLowerCase()
253
268
  const short = (e) => e?.shortMessage || String(e?.message || e).split('\n')[0]
254
269
 
270
+ // 3.0's allTokens holds every kind: at most this many of its newest tokens are read, in multicall batches of FLY_BATCH
271
+ const FLY_SCAN = 5000
272
+ const FLY_BATCH = 400
273
+ /** `pad` (3.0)'s 铸币飞轮 tokens, newest first. */
274
+ async function flyTokensOf(ctx, pad, count) {
275
+ const take = Math.min(count, FLY_SCAN)
276
+ const multi = (functionName, args) => ctx.client.multicall({
277
+ allowFailure: false, batchSize: 0, contracts: args.map((a) => ({ address: pad, abi: FLY_PAD_ABI, functionName, args: [a] })),
278
+ })
279
+ const found = []
280
+ for (let from = 0; from < take; from += FLY_BATCH) {
281
+ const idx = Array.from({ length: Math.min(FLY_BATCH, take - from) }, (_, i) => BigInt(count - 1 - from - i))
282
+ const tokens = await multi('allTokens', idx)
283
+ const kinds = await multi('kindOf', tokens)
284
+ found.push(...tokens.filter((_, i) => Number(kinds[i]) === 3))
285
+ }
286
+ return found
287
+ }
288
+
255
289
  /** The site's invite link for `token` (the site reads ?ref= and passes it to the wallet's first mint). */
256
290
  export const inviteLink = (token, referrer) => `https://gang.fun/token/${token}?ref=${referrer}`
257
291
 
@@ -524,25 +558,29 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
524
558
  if (!sale) fail(`not a 铸币飞轮 (Mint Flywheel) token on this pad${testnet ? ' (BSC testnet)' : ''}`, { token, chainId, pad: ctx.pad })
525
559
  return sale
526
560
  }
527
- const handlerOf = () => ctx.read(ctx.pad, FLY_PAD_ABI, 'taxHandler')
561
+ // on 3.0 taxHandler() is the curve / 打新 one
562
+ const handlerOf = () => ctx.read(ctx.pad, FLY_PAD_ABI, ctx.version === 3 ? 'flyTaxHandler' : 'taxHandler')
528
563
  const me = () => walletFor(ctx, opt('from'))
529
564
 
530
565
  if (sub === 'list') {
531
- // on chain, newest first: the pad keeps every token it created
566
+ // on chain, newest first: the pad keeps every token it created (on 3.0, of every kind: its fly tokens are picked out)
532
567
  const limit = parseIntIn(fail, 'limit', opt('limit', '20'), 1, 200)
533
568
  const status = opt('status', 'all')
534
569
  if (!['all', 'minting', 'filled', 'launched'].includes(status)) fail('--status must be minting, filled, launched or all')
535
- // newest pad first, each newest first (V2's tokens are the newer ones)
570
+ // newest pad first, each newest first
536
571
  const create = { pad: ctx.pad, version: ctx.version }
537
572
  const items = []
538
- let total = 0
573
+ let total = 0, scanNote = null
539
574
  for (const p of ctx.pads) {
540
575
  ctx.pad = p.address
541
576
  ctx.version = p.version
542
577
  const count = Number(await ctx.read(ctx.pad, FLY_PAD_ABI, 'tokenCount'))
543
- total += count
544
- for (let i = count - 1; i >= 0 && items.length < limit; i--) {
545
- const token = await ctx.read(ctx.pad, FLY_PAD_ABI, 'allTokens', [BigInt(i)])
578
+ const own = p.version === 3 ? await flyTokensOf(ctx, p.address, count) : null
579
+ if (own && count > FLY_SCAN) scanNote = `only the newest ${FLY_SCAN} tokens of GangLaunchpad 3.0 were read`
580
+ const n = own ? own.length : count
581
+ total += n
582
+ for (let i = 0; i < n && items.length < limit; i++) {
583
+ const token = own ? own[i] : await ctx.read(ctx.pad, FLY_PAD_ABI, 'allTokens', [BigInt(n - 1 - i)])
546
584
  const s = await saleOf(ctx, token)
547
585
  if (!s) continue
548
586
  const st = s.status === 'stalled' || s.status === 'refund' ? 'filled' : s.status
@@ -561,7 +599,7 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
561
599
  ctx.version = create.version
562
600
  return out({
563
601
  success: true, chainId, createPad: ctx.pad, createPadVersion: ctx.version, pads: ctx.pads.map((p) => ({ version: p.version, pad: p.address })),
564
- total, status, count: items.length, items, ...(!(await padOpen(ctx)) && { note: closed(ctx, testnet) }),
602
+ total, status, count: items.length, items, ...(scanNote && { scanNote }), ...(!(await padOpen(ctx)) && { note: closed(ctx, testnet) }),
565
603
  })
566
604
  }
567
605
 
@@ -594,6 +632,12 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
594
632
  if (owedTax > 0n) extra.owedCreatorTax = await units(ctx, sale.quote, owedTax)
595
633
  }
596
634
  if (owed > 0n) extra.owedDevCut = await units(ctx, sale.quote, owed)
635
+ // 3.0: the rule set the sale was created under (fixed for good), as on its curve and 打新 tokens
636
+ if (ctx.version === 3) {
637
+ extra.padGen = PAD3_GEN
638
+ const tokenVersion = await ctx.read(ctx.pad, FLY_PAD_ABI, 'tokenVersionOf', [token]).then(Number).catch(() => null)
639
+ if (tokenVersion != null) extra.tokenVersion = tokenVersion
640
+ }
597
641
  if (extra.owedDevCut || extra.owedCreatorTax) extra.release = `gang release --token ${token}${net} (anyone; pays the creator)`
598
642
  return out({ success: true, chainId, kind: 'fly', ...pub(sale), ...extra, next: nextFor(sale, token, net, undefined, extra.postMint) })
599
643
  }
@@ -696,7 +740,7 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
696
740
  if (!name || !symbol) fail('--name and --symbol are required')
697
741
  checkMeta()
698
742
  if (!(await padOpen(ctx))) fail(closed(ctx, testnet), { pad: ctx.pad, padVersion: ctx.version })
699
- if (flag('grad')) fail('--grad is a V3 curve setting (the graduation target, 2.0): a 铸币飞轮 sale fills at its --raise instead, so leave --grad out')
743
+ if (flag('grad')) fail('--grad is a V3 curve setting (the graduation target, 2.0 / 3.0): a 铸币飞轮 sale fills at its --raise instead, so leave --grad out')
700
744
  const presetName = opt('preset', 'j')
701
745
  const preset = FLY_PRESETS[presetName]
702
746
  if (!preset) fail(`--preset must be ${Object.keys(FLY_PRESETS).join(' or ')}`, { got: presetName })
@@ -712,8 +756,8 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
712
756
  if (flag('post-mint') && flag('no-post-mint')) fail('give --post-mint or --no-post-mint, not both')
713
757
  if (flag('post-mint')) v.postMint = true
714
758
  if (flag('no-post-mint')) v.postMint = false
715
- // V2's post-launch rules; a V1 create target has none, so the flags are refused there rather than ignored
716
- const v2 = ctx.version === 2
759
+ // V2's post-launch rules (3.0 has them too); a V1 create target has none, so the flags are refused there rather than ignored
760
+ const v2 = ctx.version >= 2
717
761
  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')
718
762
  if (flag('guard')) {
719
763
  v.guard = String(opt('guard'))
@@ -724,10 +768,10 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
724
768
  if (!(v.twapWindow in TWAP_WINDOWS)) fail('--twap-window must be 15 or 30 (minutes)', { got: opt('twap-window') ?? null })
725
769
  }
726
770
  if (v2 && v.postMint && v.quota > MAX_POST_QUOTA) {
727
- 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 })
771
+ fail(`--quota must be 5-${MAX_POST_QUOTA} with post-launch minting on (the pad's rule): lower --quota, or add --no-post-mint`, { quota: v.quota })
728
772
  }
729
773
  if (v2 && v.postMint && v.invite > MAX_POST_INVITE) {
730
- 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 })
774
+ fail(`--invite-bonus must be 0-${MAX_POST_INVITE} with post-launch minting on (the pad's rule): lower it, or add --no-post-mint`, { inviteBonus: v.invite })
731
775
  }
732
776
  // a pad without the Agent ID gate takes no dev cut (checkConfig refuses one): the preset's goes to 0 unless asked for
733
777
  const gated = await ctx.read(ctx.pad, FLY_PAD_ABI, 'agentGateEnabled')
@@ -757,6 +801,10 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
757
801
  const refPool = flag('ref-pool') ? opt('ref-pool') : (defaultRefPool(ctx.chainId, quote) ?? zeroAddress)
758
802
  if (!isAddress(quote ?? '') || !isAddress(refPool ?? '')) fail('--quote / --ref-pool must be 0x addresses')
759
803
  const quoteWbnb = same(quote, ctx.wbnb)
804
+ // said before a wrap or approve step: 3.0 takes none of its own tokens (of any kind) as a quote
805
+ if (ctx.version === 3 && !quoteWbnb && Number(await ctx.read(ctx.pad, FLY_PAD_ABI, 'kindOf', [quote])) !== 0) {
806
+ fail('--quote cannot be a token of GangLaunchpad 3.0 (the pad refuses it): use WBNB or another listed 18-decimal ERC-20', { quote })
807
+ }
760
808
  // the share price: raise / 10,000 in a WBNB sale; another quote is priced by the pad at create (its ref pool's
761
809
  // TWAP), so the dev's cost is estimated with GangLaunchpad's preview of the same conversion and approved with 2% room
762
810
  let price
@@ -784,7 +832,7 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
784
832
  const logo = await resolveLogo()
785
833
  const meta = await resolveMeta({ name, symbol, logoURI: logo.logoURI })
786
834
  return out(write({ from: who, to: ctx.pad, data: createData(logo.logoURI, meta.metaURI) }, {
787
- step: 'create', kind: 'fly', padVersion: ctx.version, pad: ctx.pad, name, symbol, logoURI: logo.logoURI, ...(logo.uploaded && { uploaded: true }),
835
+ step: 'create', kind: 'fly', padVersion: ctx.version, ...(ctx.version === 3 && { padGen: PAD3_GEN }), pad: ctx.pad, name, symbol, logoURI: logo.logoURI, ...(logo.uploaded && { uploaded: true }),
788
836
  metaURI: meta.metaURI, metadata: meta.metadata, quote: sym || quote, preset: presetName, config: cfgView(cfg),
789
837
  sharePrice: await units(ctx, quote, quoteWbnb ? price : (price * 100n) / 102n), devShares, devCost: await units(ctx, quote, need),
790
838
  ...(v2 && v.postMint && {
@@ -818,7 +866,7 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
818
866
  const minShares = flag('min-shares') ? parseIntIn(fail, 'min-shares', opt('min-shares'), 1, Number(accepted)) : Number(accepted)
819
867
  const need = cost + fee
820
868
  const fills = sale.sold + Number(accepted) === TOTAL_SHARES
821
- // launchDelay 0: the mint that fills also launches (about 2.5M gas); near the end other mints landing first can make
869
+ // launchDelay 0: the mint that fills also launches (up to about 3.8M gas); near the end other mints landing first can make
822
870
  // this one that mint, so it gets a launch-sized gas limit
823
871
  const mayLaunch = sale.rules.launchDelaySec === 0 && sale.sharesLeft - Number(accepted) <= 10 * sale.rules.maxPerTx
824
872
  const extra = {
@@ -963,8 +1011,8 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
963
1011
  return out(write(tx, {
964
1012
  step: sub, kind: 'fly', token, sold: sale.sold, ...(tx.gas && { gasLimit: tx.gas.toString() }),
965
1013
  note: sub === 'launch'
966
- ? `creates the PancakeSwap pool at the mint price (about 2.5M gas); protection runs ${sale.rules.protectionSec}s after it`
967
- : sale.rules.launchDelaySec ? `stops the sale at ${sale.sold} shares; anyone can launch it ${sale.rules.launchDelaySec}s later (gang fly launch)` : `stops the sale at ${sale.sold} shares and launches in the same tx (about 2.5M gas)`,
1014
+ ? `creates the PancakeSwap pool at the mint price (up to about 3.8M gas); protection runs ${sale.rules.protectionSec}s after it`
1015
+ : sale.rules.launchDelaySec ? `stops the sale at ${sale.sold} shares; anyone can launch it ${sale.rules.launchDelaySec}s later (gang fly launch)` : `stops the sale at ${sale.sold} shares and launches in the same tx (up to about 3.8M gas)`,
968
1016
  }))
969
1017
  }
970
1018
 
package/src/gangpad.js CHANGED
@@ -1,13 +1,13 @@
1
- import { createTransport, http, parseAbi } from 'viem'
1
+ import { createTransport, encodeFunctionData, http, parseAbi, zeroAddress } from 'viem'
2
2
  import { bsc, bscTestnet } from 'viem/chains'
3
3
 
4
4
  /**
5
5
  * GangLaunchpad (contract merge, 2026-10-27): V3 tax tokens (bonding curve) and 打新 (fair-mint) sales live on ONE pad —
6
6
  * one address, one state, one tax handler, one GangRouter. `gang v3` and `gang fair` both talk to it; `kindOf(token)`
7
- * on the pad says which kind a token is (0 = not this pad's, 1 = V3 curve, 2 = 打新). The two `create` overloads keep
8
- * their old selectors, so each command keeps its own ABI fragment.
7
+ * on the pad says which kind a token is (0 = not this pad's, 1 = V3 curve, 2 = 打新, 3 = 铸币飞轮: on 3.0 only, see
8
+ * fly.js). The two `create` overloads keep their old selectors, so each command keeps its own ABI fragment.
9
9
  *
10
- * Each network may have several generations of this pad (GANG_GENS: 1.0, 2.0, 2.0 金库版); kindOf on each tells which one has a token.
10
+ * Each network may have several generations of this pad (GANG_GENS: 3.0, 2.0, 1.0, 2.0 金库版); kindOf on each tells which one has a token.
11
11
  *
12
12
  * Env (new name first; the old per-command names still work as aliases). The contracts set the create target (gangGens):
13
13
  * mainnet: GANG_PAD (aliases GANG_V3_PAD / GANG_FAIR_PAD), GANG_ROUTER, GANG_BOND, GANG_SPLITTER_FACTORY,
@@ -25,18 +25,40 @@ import { bsc, bscTestnet } from 'viem/chains'
25
25
  */
26
26
  export const VAULT_GEN = '2.0-vault'
27
27
 
28
+ /**
29
+ * GangLaunchpad 3.0 (docs/SPEC-GANG-LAUNCHPAD-3-2026-11-03.md): one permanent, upgradeable pad (a proxy) with 2.0's
30
+ * rules, functions and events (same selectors), plus tokenVersionOf (the rule set each token was created under) and a
31
+ * four.meme-shaped aggregator entry. An upgrade may add the vault mode (spec §9: createWithVault, vaultOf, lockedOf on
32
+ * the same address): vaultModeOf asks the pad, so this CLI follows the upgrade without a new release. Since 2026-11-04 it
33
+ * also has the 铸币飞轮 mode (spec §10, kind 3; fly.js), and gated 打新 sales trade through the entry (spec §2, §3). This
34
+ * CLI does not trade through the entry: it mints and sells back on the pad, or through the GangRouter.
35
+ */
36
+ export const PAD3_GEN = '3.0'
37
+
28
38
  /**
29
39
  * GangLaunchpad generations on each network, newest first (2.0 金库版 aside: always last, see VAULT_GEN). A create goes to
30
40
  * the first; a token already out stays on the pad that created it and is served with that generation's GangRouter,
31
41
  * GangBond and module factories (each of them is bound to one pad). 2.0 (docs/SPEC-CURVE-CREATOR-FEE-2026-10-31.md) has
32
42
  * the same V3 curves and 打新 sales, and keeps 70% of the 1% curve fee for the token's creator (creatorFeeOf /
33
- * claimCreatorFee); a 1.0 pad has neither.
43
+ * claimCreatorFee); a 1.0 pad has neither. 3.0 (PAD3_GEN) keeps 2.0's rules on one upgradeable address.
34
44
  */
35
45
  export const GANG_GENS = {
36
46
  mainnet: [
37
- // 2026-10-31, pad block 130874052: 2.0 with the creator fee and the graduation target the creator picks; its own
38
- // GangRouter, GangBond, buy-back factory (buyback-burn-v4), split-v1, lp-burn-v1 and combo-v1 factories, all bound to
39
- // this pad and listed on its own GangHandlerAdmin
47
+ // 2026-11-03, proxy block 131404298: 3.0 (docs/MAINNET-GANG-LAUNCHPAD-3-2026-11-03.md), the permanent address. Its own
48
+ // GangRouter, tax handler (owned by its GangHandlerAdmin 0xC833…Af76), GangBond and the four module factories, all
49
+ // bound to this proxy (docs/MAINNET-GANG-LAUNCHPAD-3-MODULES-2026-11-03.md). Vault mode since the Safe's upgrade at
50
+ // block 131454282 (implementation 0x88A4…028D, Pad3Module 0xa712…409A); vaultModeOf reads it from the pad. 铸币飞轮 mode
51
+ // and 打新 through the entry since 2026-11-04 (fly tax handler 0x7De9…3ba0, vault core 0x9d90…767E, deployer 0x2C95…072E)
52
+ {
53
+ gen: PAD3_GEN, pad: '0x2bEbED4be8c8F46C17776C71D7a6A45dbC5CAB29', router: '0xec9717E5C68b9F18fA76D3961C9Cd7e67b5E61e7',
54
+ bond: '0x830b38F695Ca1bCbdD313CD5AA5943e2125Be9D6', splitterFactory: '0xc1282e7Fd3DFa5e00e74E9EbF8c54fFfB5763194',
55
+ splitFactory: '0x904D4498a9257E4d7638afEbB95A1162cB2171f2', lpFactory: '0x98C506F0F4762F9d1Ec96C27499CE8B7e5981752',
56
+ comboFactory: '0x20188054dE31De844df205712768852BdeD3eA39',
57
+ },
58
+ // 2026-10-31, pad block 130874052: 2.0 with the creator fee and the graduation target the creator picks (the create
59
+ // target until 3.0; its tokens trade and claim here); its own GangRouter, GangBond, buy-back factory
60
+ // (buyback-burn-v4), split-v1, lp-burn-v1 and combo-v1 factories, all bound to this pad and listed on its own
61
+ // GangHandlerAdmin
40
62
  {
41
63
  gen: '2.0', pad: '0x770331a9accdb53ACb4a45B6c5B7D151fADCe557', router: '0xa83209d6bfC2B220cD86410cCDDC71FEb354844a',
42
64
  bond: '0x231339463d04A2127E6dD5756756Dd56853AE0D8', splitterFactory: '0x77e499c892e5E6B3eEe1721e6821e9DA1293803C',
@@ -65,8 +87,18 @@ export const GANG_GENS = {
65
87
  },
66
88
  ],
67
89
  testnet: [
90
+ // 2026-11-03, proxy block 140496214: 3.0 (docs/TESTNET-GANG-LAUNCHPAD-3-2026-11-03.md), vault mode since its fourth
91
+ // upgrade, 铸币飞轮 mode and 打新 through the entry since (fly tax handler 0x2d03…231f, vault core 0x570B…6494). Its own
92
+ // GangRouter, tax handler (GangHandlerAdmin 0x0fb8…9D23), GangBond and module factories
93
+ {
94
+ gen: PAD3_GEN, pad: '0x0508232833aE6849c03b28F7aA248BBd5cFCceE2', router: '0x09544Fd87c5Ff2c4fb05885A76861A12e83f87b9',
95
+ bond: '0xa87727dc3CC28a44709649A22aDbD77287B99fc1', splitterFactory: '0x3533E63EF0386adfBC96227C50f1b82EEA18d110',
96
+ splitFactory: '0xf8d4FA57FD65Bf16427Eef653518811fFa2606dc', lpFactory: '0x4A3aC160eAF4A2747046b119631988D5D8056B07',
97
+ comboFactory: '0xdc1687961c8aAf5A0340c1A73b604cf3a2be543C',
98
+ },
68
99
  // 2026-10-31, pad block 139940227: 2.0 with the graduation target the creator picks (GRAD_BNB_TIERS, createWithGradTarget;
69
- // docs/SPEC-CURVE-GRAD-TARGET-2026-10-31.md); buy-back factory buyback-burn-v4, split-v1, lp-burn-v1, its own GangBond
100
+ // docs/SPEC-CURVE-GRAD-TARGET-2026-10-31.md), the create target until 3.0; buy-back factory buyback-burn-v4, split-v1,
101
+ // lp-burn-v1, its own GangBond
70
102
  {
71
103
  gen: '2.0', pad: '0xb14d415f70D7F99f0D93Bd3BF76e0D6b38b53B3E', router: '0x5a4FA2D91638a305EdF027894753c943f095dDAA',
72
104
  bond: '0x39749B59066d9cd1c55E2Fc48B31a3978C9951F9', splitterFactory: '0xDC9EdA9a29F4Ff66E7dAb6E5A2142df5a7aC0f6e',
@@ -97,7 +129,7 @@ export const GANG_GENS = {
97
129
  },
98
130
  ],
99
131
  }
100
- // what a generation brings to a ctx (gen: '1.0' | '2.0' | VAULT_GEN, null for a pad named by the env that this CLI does not know)
132
+ // what a generation brings to a ctx (gen: '1.0' | '2.0' | PAD3_GEN | VAULT_GEN, null for a pad named by the env that this CLI does not know)
101
133
  const GEN_FIELDS = ['gen', 'pad', 'router', 'bond', 'splitterFactory', 'splitFactory', 'lpFactory', 'comboFactory']
102
134
  // the env names of each field, per network (new name first; the old per-command names still work as aliases)
103
135
  const GEN_ENV = {
@@ -199,6 +231,55 @@ export function gangGens(testnet) {
199
231
  /** The 2.0 金库版 generation of `gens` (a ctx's gens or gangGens(testnet)), or null when the network has none. */
200
232
  export const vaultGenOf = (gens) => gens.find((g) => g.gen === VAULT_GEN) ?? null
201
233
 
234
+ const VAULT_PROBE = encodeFunctionData({ abi: parseAbi(['function vaultOf(address token) view returns (address)']), functionName: 'vaultOf', args: [zeroAddress] })
235
+ const vaultModes = new Map()
236
+ const NOT_YET_MS = 10 * 60_000
237
+ // a call the contract refused (a revert, with or without data), not the node failing; an internal error (-32603) is the node's
238
+ const refused = (e) => !e?.walk?.((x) => x?.code === -32603)
239
+ && !!e?.walk?.((x) => x?.code === 3 || x?.name === 'ExecutionRevertedError' || /execution reverted/i.test(x?.details ?? ''))
240
+ /**
241
+ * Whether `pad` serves the vault mode (createWithVault, vaultOf, lockedOf, vaultCreator): the 2.0 金库版 pad always,
242
+ * 1.0 and 2.0 never (both known without a call); 3.0 (and a pad named by the env) once an upgrade added it, told by a
243
+ * vaultOf(address(0)) call that succeeds with exactly 32 bytes (before that upgrade 3.0 has no fallback: it reverts
244
+ * without data). A revert is false; any other error (the RPC) is thrown, never taken for "no vault mode".
245
+ */
246
+ export async function vaultModeOf(ctx, pad = ctx.pad) {
247
+ const known = [...GANG_GENS.mainnet, ...GANG_GENS.testnet].find((g) => sameAddr(g.pad, pad))
248
+ if (known?.gen === VAULT_GEN) return true
249
+ if (known && known.gen !== PAD3_GEN) return false
250
+ const key = `${ctx.chainId}:${pad.toLowerCase()}`
251
+ const hit = vaultModes.get(key)
252
+ // "served" is kept for the run; "not yet" for NOT_YET_MS only, so a long-lived process (gang mcp) sees the upgrade
253
+ if (!hit || (hit.no && Date.now() - hit.at > NOT_YET_MS)) {
254
+ const entry = { at: Date.now(), no: false }
255
+ entry.p = ctx.client.call({ to: pad, data: VAULT_PROBE }).then((r) => (r?.data?.length ?? 0) === 66).catch((e) => {
256
+ if (refused(e)) return false
257
+ vaultModes.delete(key)
258
+ throw e
259
+ }).then((yes) => { entry.no = !yes; return yes })
260
+ vaultModes.set(key, entry)
261
+ return entry.p
262
+ }
263
+ return hit.p
264
+ }
265
+
266
+ const VAULT_OF_ABI = parseAbi(['function vaultOf(address token) view returns (address)'])
267
+ /**
268
+ * The lock vault `token` is bound to on ctx.pad (ctx on the token's generation), or null: none (a pad without the vault
269
+ * mode, or a token created without one). Every 2.0 金库版 token has one. Throws on an RPC error.
270
+ */
271
+ export async function tokenVaultOf(ctx, token) {
272
+ if (!(await vaultModeOf(ctx))) return null
273
+ const v = await ctx.read(ctx.pad, VAULT_OF_ABI, 'vaultOf', [token])
274
+ return v === zeroAddress ? null : v
275
+ }
276
+
277
+ /**
278
+ * Why a vault-bound token takes no GangBond: report() slashes as soon as the creator's WALLET balance is below the
279
+ * promised holding, and tokens locked into the vault are not in the wallet, so one lock forfeits the whole bond.
280
+ */
281
+ export const VAULT_NO_BOND = 'this token is bound to a lock vault, so it takes no GangBond: a bond is slashed (anyone can report it) as soon as the creator\'s wallet balance drops below the promised holding, and tokens locked into the vault are no longer in the wallet, so a single lock (often made in the vault\'s own app) would forfeit the whole bond'
282
+
202
283
  /** A generation's contracts as ctx fields (missing ones null). */
203
284
  export const genFields = (g) => Object.fromEntries(GEN_FIELDS.map((k) => [k, g?.[k] ?? null]))
204
285
 
@@ -235,6 +316,8 @@ export const MERGED_ERRORS_ABI = parseAbi([
235
316
  'error StillLocked()', 'error SwapBackOutOfGas()', 'error SellDuringFlashSwap()', 'error BadKind()',
236
317
  // 2.0, both kinds: the graduation amount / raise in the quote is more than a PancakeSwap pair can hold
237
318
  'error QuoteAmountTooLarge()',
319
+ // the token deployer, on a create from a pad it no longer lists (a pad stops creating at a cut-over)
320
+ 'error OnlyLaunchpad()',
238
321
  ])
239
322
  export const MERGED_HINTS = {
240
323
  Untaxed: 'this token is untaxed (0% / 0%): it never gets a pool tax, a tax route or dividends; nothing to release or claim on it',
@@ -246,13 +329,14 @@ export const MERGED_HINTS = {
246
329
  StillLocked: 'the token has not graduated / launched yet',
247
330
  SwapBackOutOfGas: 'too little gas for the sell-time tax chunk: re-run with the estimated gas limit (do not cap it lower)',
248
331
  SellDuringFlashSwap: 'a sell paid in from a flash swap callback is refused by this token',
332
+ OnlyLaunchpad: 'on a create: this pad has stopped creating tokens (its token deployer no longer lists it); its existing tokens keep working. Leave GANG_PAD / GANG_TESTNET_PAD and their aliases unset to create on the current pad, or update the CLI (npm i -g @gangfun/cli@latest)',
249
333
  QuoteAmountTooLarge: 'in this quote the graduation target / raise is more than a PancakeSwap pair can hold (the quote is priced far below BNB, often by a skewed --ref-pool): pick another quote or reference pool',
250
334
  }
251
335
 
252
336
  const KIND_ABI = parseAbi(['function kindOf(address token) view returns (uint8)'])
253
- const KINDS = ['none', 'v3', 'fair']
337
+ const KINDS = ['none', 'v3', 'fair', 'fly']
254
338
 
255
- /** 'v3' | 'fair' | 'none' from the merged pad's kindOf; null on a pad without kindOf (before the merge) or on an RPC error. */
339
+ /** 'v3' | 'fair' | 'fly' | 'none' from the merged pad's kindOf (fly: 3.0 only); null on a pad without kindOf (before the merge) or on an RPC error. */
256
340
  export async function kindOf(ctx, token) {
257
341
  try {
258
342
  return KINDS[Number(await ctx.read(ctx.pad, KIND_ABI, 'kindOf', [token]))] ?? null
@@ -262,13 +346,14 @@ export async function kindOf(ctx, token) {
262
346
  }
263
347
 
264
348
  /**
265
- * Which generation's pad has `token`, asked of every pad of ctx.gens at once: { g, kind } with kind 'v3' | 'fair';
349
+ * Which generation's pad has `token`, asked of every pad of ctx.gens at once: { g, kind } with kind 'v3' | 'fair' |
350
+ * 'fly' (3.0's own 铸币飞轮 tokens; V1 / V2 ones are on GangFlywheelPad, not in ctx.gens: fly.js finds those);
266
351
  * { g: null, kind: 'none' } when no pad has it; kind null when a pad could not be read and no other one has it.
267
352
  */
268
353
  export async function genOf(ctx, token) {
269
354
  const gens = ctx.gens ?? [ctx]
270
355
  const kinds = await Promise.all(gens.map((g) => kindOf({ ...ctx, pad: g.pad }, token)))
271
- const i = kinds.findIndex((k) => k === 'v3' || k === 'fair')
356
+ const i = kinds.findIndex((k) => k === 'v3' || k === 'fair' || k === 'fly')
272
357
  if (i >= 0) return { g: gens[i], kind: kinds[i] }
273
358
  return { g: null, kind: kinds.includes(null) ? null : 'none' }
274
359
  }
@@ -405,6 +490,9 @@ export async function gradTargetBnbOf(ctx, token) {
405
490
  export async function notThisKind(ctx, token, want, net = '') {
406
491
  const kind = await kindOf(ctx, token)
407
492
  const ask = want === 'v3' ? 'a LaunchpadV3 (tax) token' : 'a 打新 (fair-mint) sale'
493
+ if (kind === 'fly') {
494
+ return { error: `this is a 铸币飞轮 (Mint Flywheel) token: gang info / buy / sell / mint / withdraw --token ${token}${net} pick the right pad code`, kind }
495
+ }
408
496
  if (kind === 'fair' && want === 'v3') {
409
497
  return { error: `this is a 打新 (fair-mint) token, not a V3 token: gang info / buy / sell / mint / withdraw --token ${token}${net} pick the right pad code`, kind }
410
498
  }