@gangfun/cli 0.18.1 → 0.18.2

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
@@ -280,4 +280,4 @@ timed-out `gang_execute`, check `gang_status` / the wallet history instead of ex
280
280
 
281
281
  ## Version
282
282
 
283
- `0.18.1` · repo [gangfun/cli](https://github.com/gangfun/cli) · published to [npm](https://www.npmjs.com/package/@gangfun/cli) on push to `main`
283
+ `0.18.2` · 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
@@ -244,4 +244,4 @@ Claude Code:`claude mcp add gang -- gang mcp`。同一台机器上 `baw` 要
244
244
 
245
245
  ## 版本
246
246
 
247
- `0.18.1` · [gangfun/cli](https://github.com/gangfun/cli) · push 到 `main` 自动发布到 [npm](https://www.npmjs.com/package/@gangfun/cli)
247
+ `0.18.2` · [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.18.1",
3
+ "version": "0.18.2",
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
  "bin": {
package/src/discover.js CHANGED
@@ -94,7 +94,9 @@ function gangRow(r, quoteUsdOf) {
94
94
  volume24hUsd: inUsd('volume24hUsd', 'volume24hQuote'), trades24h: num(r.trades24h), trades: num(r.trades),
95
95
  holders: r.holders != null ? num(r.holders) : fair ? num(r.participants) : null,
96
96
  ...(fair && { sharePrice: w(r.sharePrice), sharesLeft: num(r.sharesLeft), minWalletsLeft: num(r.minWalletsLeft) }),
97
- ...(r.track === 'fly' && { status: r.status ?? null, postMint: !!r.postMint, baseQuota: num(r.baseQuota), inviteBonus: num(r.inviteBonus) }),
97
+ ...(r.track === 'fly' && {
98
+ status: r.status ?? null, postMint: !!r.postMint, mintPaused: !!r.mintPaused, baseQuota: num(r.baseQuota), inviteBonus: num(r.inviteBonus),
99
+ }),
98
100
  createdAt: r.createdAt, ageMin: r.createdAt ? Math.floor((now() - r.createdAt) / 60) : null,
99
101
  lastTradeAt: r.lastTradeAt || r.lastActivityAt || null, creatorHandle: r.creatorHandle || null, logoUrl: r.logoUrl || null,
100
102
  website: r.website && !websiteError(r.website) ? r.website : null,
@@ -183,7 +185,8 @@ const hint = (t) => {
183
185
  // mint); a filled sale waits for its launch, a refund-only one only sells back
184
186
  if (t.track === 'fly' && t.status === 'filled') return `gang info --token ${t.address}`
185
187
  if (t.track === 'fly' && t.status === 'refund') return `gang withdraw --token ${t.address} --all`
186
- if (t.track === 'fly' && (!t.graduated || t.postMint)) return `gang mint --token ${t.address} --shares <n>`
188
+ // launched with post-launch minting paused (the pool too far below its references): the pool, not a mint
189
+ if (t.track === 'fly' && (!t.graduated || (t.postMint && !t.mintPaused))) return `gang mint --token ${t.address} --shares <n>`
187
190
  if (t.graduated) return `gang buy --token ${t.address} ${amount}` // the PancakeSwap pool, through GangRouter
188
191
  if (t.track === 'fair') return `gang mint --token ${t.address} --shares <n>`
189
192
  if (t.track === 'v3') return `gang buy --token ${t.address} ${amount}`
package/src/fly.js CHANGED
@@ -82,6 +82,8 @@ export const FLY_HANDLER_ABI = parseAbi([
82
82
  'function eligibleShare(address token, address user) view returns (uint256)',
83
83
  'function owedOf(address token) view returns (uint256)',
84
84
  'function release(address token) returns (uint256 amount)',
85
+ 'function blockRefOf(address token) view returns (uint32 blockNumber, uint224 price)',
86
+ 'function prevBlockStartOf(address token) view returns (uint256)',
85
87
  'error ProtectionNotAgent()', 'error ProtectionCapExceeded()', 'error PriceBelowReference()', 'error NothingOwed()',
86
88
  'error SellDuringFlashSwap()', 'error OutOfGas()',
87
89
  'event Launched(address indexed token, uint256 protectedUntil, address gate, uint256 cap, uint256 launchPrice)',
@@ -275,10 +277,50 @@ async function poolSide(ctx, token, sale, handler) {
275
277
  },
276
278
  tax: { buyPct: BUY_TAX_PCT, sellPct: pct(sellTaxBps), split: 'the first 1%: holders 50% / platform 25% / creator 25%; sell tax above 1%: holders' },
277
279
  supply: { total: formatUnits(supply, 18), max: formatUnits(maxSupply, 18), mintRoom: formatUnits(room, 18) },
278
- raw: { spot, until: Number(until), gate, cap, sellTaxBps: Number(sellTaxBps), room },
280
+ raw: { spot, blockStart, high, average, until: Number(until), gate, cap, sellTaxBps: Number(sellTaxBps), room },
279
281
  }
280
282
  }
281
283
 
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)'
295
+
296
+ /**
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.
300
+ */
301
+ async function mintPause(ctx, token, sale, handler, side) {
302
+ const { spot, blockStart, high, average, room } = side.raw
303
+ const BPS = 10_000n
304
+ 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
+ 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')
319
+ // one share: the buyer's tokens and the liquidity's (at most its price of quote at spot) must fit under the cap
320
+ 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]] }) }
322
+ }
323
+
282
324
  async function poolReserves(ctx, token, pair) {
283
325
  if (!pair) return [0n, 0n]
284
326
  const [[r0, r1], t0] = await Promise.all([ctx.read(pair, PAIR_ABI, 'getReserves'), ctx.read(pair, PAIR_ABI, 'token0')])
@@ -426,8 +468,11 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
426
468
  const { raw: _r, ...view } = side
427
469
  Object.assign(extra, view)
428
470
  if (sale.rules.postMint) {
429
- const one = await ctx.read(ctx.pad, FLY_PAD_ABI, 'sharePrice', [token, 1n])
430
- extra.postMint = { sharePriceNow: await units(ctx, sale.quote, one), tierMulNow: Number((one * 100n) / sale.sharePriceRaw) / 100 }
471
+ const [one, pause] = await Promise.all([ctx.read(ctx.pad, FLY_PAD_ABI, 'sharePrice', [token, 1n]), mintPause(ctx, token, sale, handler, side)])
472
+ 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 }),
475
+ }
431
476
  }
432
477
  const [owedTax, swapBack] = await Promise.all([
433
478
  ctx.read(handler, FLY_HANDLER_ABI, 'owedOf', [token]),
@@ -438,7 +483,7 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
438
483
  }
439
484
  if (owed > 0n) extra.owedDevCut = await units(ctx, sale.quote, owed)
440
485
  if (extra.owedDevCut || extra.owedCreatorTax) extra.release = `gang release --token ${token}${net} (anyone; pays the creator)`
441
- return out({ success: true, chainId, kind: 'fly', ...pub(sale), ...extra, next: nextFor(sale, token, net) })
486
+ return out({ success: true, chainId, kind: 'fly', ...pub(sale), ...extra, next: nextFor(sale, token, net, undefined, extra.postMint) })
442
487
  }
443
488
 
444
489
  if (sub === 'status') {
@@ -490,12 +535,18 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
490
535
  } else {
491
536
  Object.assign(pos, { reward: 'none', pendingReward: reward.claimable, note: 'did not mint in this sale: the holder reward is only for minters' })
492
537
  }
493
- if (sale.rules.postMint && acct.view.quotaLeft > 0) {
494
- const [acc, paid, fee, tokensOut, ok] = await ctx.read(ctx.pad, FLY_PAD_ABI, 'previewMintPost', [token, who, 1n])
495
- pos.mintOneShareNow = acc ? { paid: await units(ctx, sale.quote, paid), fee: await units(ctx, sale.quote, fee), tokensOut: formatUnits(tokensOut, 18), ok } : null
538
+ if (sale.rules.postMint) {
539
+ 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 }) }
541
+ if (acct.view.quotaLeft > 0) {
542
+ const [acc, paid, fee, tokensOut, ok] = await ctx.read(ctx.pad, FLY_PAD_ABI, 'previewMintPost', [token, who, 1n])
543
+ pos.mintOneShareNow = acc ? { paid: await units(ctx, sale.quote, paid), fee: await units(ctx, sale.quote, fee), tokensOut: formatUnits(tokensOut, 18), ok } : null
544
+ // the sale's rules allow a mint, the wallet's own 30-minute pace does not
545
+ if (acc && !ok && !pause.pausedNow) pos.mintPaused = { pausedNow: true, reason: 'pace', why: 'this wallet\'s recent post-launch mints reach its 30-minute pace (2% of the pool\'s quote side)', resumes: 'the pace decays over 30 minutes' }
546
+ }
496
547
  }
497
548
  }
498
- return out({ success: true, chainId, kind: 'fly', wallet: who, sale: pub(sale), position: pos, next: nextFor(sale, token, net, acct.view) })
549
+ return out({ success: true, chainId, kind: 'fly', wallet: who, sale: pub(sale), position: pos, next: nextFor(sale, token, net, acct.view, pos.mintPaused) })
499
550
  }
500
551
 
501
552
  if (sub === 'invite') {
@@ -517,6 +568,12 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
517
568
  inviteBonusPerInvite: sale.rules.inviteBonus, invited: acct.view.invited, bonusShares: acct.view.inviteBonusShares,
518
569
  quota: acct.view.quota, quotaLeft: acct.view.quotaLeft,
519
570
  ...(board?.invitees && { invitees: board.invitees }),
571
+ // gang.fun's board counts an invite only while it holds up (so sell-backs can't farm it); the bonus above is the
572
+ // pad's and stays either way. Older servers have no such counts: the output is as before
573
+ ...(Number.isFinite(board?.validInvites) && {
574
+ validInvites: board.validInvites, totalInvites: board.totalInvites ?? acct.view.invited,
575
+ validNote: 'gang.fun counts an invite as valid while the invitee still holds pre-launch shares (before the fill), once the sale has filled or launched, or when the invitee first minted after launch; none counts in a refund-only sale. The quota bonus is on chain and stays either way',
576
+ }),
520
577
  ...(!board && { inviteesNote: `the list of invitees comes from ${API} (/fly/tokens/<token>/invites) once it indexes this pad; the count here is read on chain` }),
521
578
  note: 'an invite counts on the invitee\'s first mint in this token (before or after launch), when it passes --ref (gang mint --ref <inviter>) or opens the link; the inviter must have minted here and hold an Agent ID',
522
579
  })
@@ -922,11 +979,13 @@ const cfgView = (c) => ({
922
979
  ...(c.tierMode === 2 && { stepPct: pct(c.stepBps), stepShares: c.stepShares, maxMul: c.maxMulX100 / 100 }), supplyCapMul: c.supplyCapMul,
923
980
  })
924
981
 
925
- /** The command that acts on the sale next. */
926
- function nextFor(sale, token, net, acct) {
982
+ /** The command that acts on the sale next. `paused`: mintPause (or the wallet's) after launch. */
983
+ function nextFor(sale, token, net, acct, paused) {
927
984
  if (sale.status === 'minting') return `gang mint --token ${token} --shares <n>${net}${acct && !acct.minted ? ' [--ref <inviter>]' : ''}`
928
985
  if (sale.status === 'filled') return sale.launchableNow ? `gang fly launch --token ${token}${net}` : `wait until ${sale.launchAt}, then gang fly launch --token ${token}${net}`
929
986
  if (sale.status === 'stalled') return `gang fly launch --token ${token}${net} (or gang withdraw to sell back)`
930
987
  if (sale.status === 'refund') return `gang withdraw --token ${token} --all${net}`
988
+ if (sale.rules.postMint && paused?.pausedNow) return `gang buy --token ${token} --amount <quote>${net} (post-launch minting is paused: ${paused.why})`
989
+ if (sale.rules.postMint && acct && !acct.quotaLeft) return `gang buy --token ${token} --amount <quote>${net} (this wallet's mint quota is used up)`
931
990
  return sale.rules.postMint ? `gang mint --token ${token} --shares <n>${net} (or gang buy in the pool)` : `gang buy --token ${token} --amount <quote>${net}`
932
991
  }