@gangfun/cli 0.22.0 → 0.24.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/gangpad.js CHANGED
@@ -7,27 +7,90 @@ import { bsc, bscTestnet } from 'viem/chains'
7
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
8
  * their old selectors, so each command keeps its own ABI fragment.
9
9
  *
10
- * Env (new name first; the old per-command names still work as aliases):
11
- * mainnet: GANG_PAD (aliases GANG_V3_PAD / GANG_FAIR_PAD), GANG_ROUTER, GANG_RPC_URL
10
+ * Each network may have several generations of this pad (GANG_GENS: 1.0, 2.0); kindOf on each tells which one has a token.
11
+ *
12
+ * Env (new name first; the old per-command names still work as aliases). The contracts set the create target (gangGens):
13
+ * mainnet: GANG_PAD (aliases GANG_V3_PAD / GANG_FAIR_PAD), GANG_ROUTER, GANG_BOND, GANG_SPLITTER_FACTORY,
14
+ * GANG_SPLIT_FACTORY, GANG_LP_FACTORY, GANG_RPC_URL
12
15
  * testnet: GANG_TESTNET_PAD (aliases GANG_V3_TESTNET_PAD / GANG_FAIR_TESTNET_PAD),
13
- * GANG_TESTNET_ROUTER (alias GANG_ROUTER_TESTNET),
16
+ * GANG_TESTNET_ROUTER (alias GANG_ROUTER_TESTNET), GANG_TESTNET_BOND, GANG_TESTNET_SPLITTER_FACTORY,
17
+ * GANG_TESTNET_SPLIT_FACTORY, GANG_TESTNET_LP_FACTORY,
14
18
  * GANG_TESTNET_RPC_URL (aliases GANG_V3_TESTNET_RPC_URL / GANG_FAIR_TESTNET_RPC_URL)
15
19
  * An RPC variable takes one URL or a comma-separated list; set, it replaces the public nodes below.
16
20
  */
17
21
 
18
- // the current testnet set (set 10, 2026-10-27: §23 aggregator entries); the name is kept from set 8
19
- export const TESTNET_SET8 = { pad: '0xFebF58ba418ab4a3B3f054827eb11E99369C5BB1', router: '0x6bB660f310a9644Dc173E7Cf2F73498716D9C9F6' }
20
- // Mainnet (2026-10-27, pad block 130104322). router = the GangRouter proxy: BNB buys and every PancakeSwap trade of a
21
- // graduated token (V3, 打新 and V2 / Soft / U / S alike). GANG_PAD / GANG_ROUTER still override.
22
- export const MAINNET_GANG = {
23
- pad: '0x15CFD2dc8278Fb87a1783ef42111618E20874365',
24
- router: '0xE040445690Aa56C8b68B7f7038C7b2562B5079C4',
22
+ /**
23
+ * GangLaunchpad generations on each network, newest first. A create goes to the first; a token already out stays on the
24
+ * pad that created it and is served with that generation's GangRouter, GangBond and module factories (each of them is
25
+ * bound to one pad). 2.0 (docs/SPEC-CURVE-CREATOR-FEE-2026-10-31.md) has the same V3 curves and 打新 sales, and keeps
26
+ * 70% of the 1% curve fee for the token's creator (creatorFeeOf / claimCreatorFee); a 1.0 pad has neither.
27
+ */
28
+ export const GANG_GENS = {
29
+ mainnet: [
30
+ // 2026-10-31, pad block 130874052: 2.0 with the creator fee and the graduation target the creator picks; its own
31
+ // GangRouter, GangBond, buy-back factory (buyback-burn-v4), split-v1, lp-burn-v1 and combo-v1 factories, all bound to
32
+ // this pad and listed on its own GangHandlerAdmin
33
+ {
34
+ gen: '2.0', pad: '0x770331a9accdb53ACb4a45B6c5B7D151fADCe557', router: '0xa83209d6bfC2B220cD86410cCDDC71FEb354844a',
35
+ bond: '0x231339463d04A2127E6dD5756756Dd56853AE0D8', splitterFactory: '0x77e499c892e5E6B3eEe1721e6821e9DA1293803C',
36
+ splitFactory: '0xa73dC3d63AAf72E70b1cb012e5f3A541360Bec59', lpFactory: '0x8ac85f150f87B536fb05eA163908b1077D95c0E4',
37
+ comboFactory: '0xcCeA388DbC0Edb206eC25C9715546d57029198Be',
38
+ },
39
+ // 2026-10-27, pad block 130104322. router = the GangRouter proxy: BNB buys and every PancakeSwap trade of a graduated
40
+ // token (V3, 打新 and V2 / Soft / U / S alike). GangBond 2026-10-29 with the re-review L-1 fix; it replaces 0xf26F…C817
41
+ // (never used; CLI 0.15.1–0.16.1) (docs/MAINNET-GANG-BOND-2026-10-29.md). Buy-back factory v3 (one chunk per 4 minutes;
42
+ // docs/MAINNET-BUYBACK-SPLITTER-2026-10-28.md; v2 0x9346…8F2f and v1 0x6bcd…8546 are stopped, their clones keep
43
+ // working). Split factory 2026-10-30 (docs/MAINNET-SPLIT-MODULE-2026-10-30.md), LP factory 2026-10-31
44
+ {
45
+ gen: '1.0', pad: '0x15CFD2dc8278Fb87a1783ef42111618E20874365', router: '0xE040445690Aa56C8b68B7f7038C7b2562B5079C4',
46
+ bond: '0xe92dC940CB23Dc328639A7334e69F9CCdf3a14E4', splitterFactory: '0xf1d5CA816d72e6F130f42662d11b238312A7F1Cd',
47
+ splitFactory: '0x27e08271E52B2D129c824CD245e69471a8d3067c', lpFactory: '0xE0436867dAFcf42Ee1418083251a9B8B61F0C248',
48
+ // combo-v1, 2026-10-31 (the Safe allowed it on GangHandlerAdmin at block 130811492)
49
+ comboFactory: '0xd33C38BE3f8472b3013167830F0638C1704e1DBd',
50
+ },
51
+ ],
52
+ testnet: [
53
+ // 2026-10-31, pad block 139940227: 2.0 with the graduation target the creator picks (GRAD_BNB_TIERS, createWithGradTarget;
54
+ // docs/SPEC-CURVE-GRAD-TARGET-2026-10-31.md); buy-back factory buyback-burn-v4, split-v1, lp-burn-v1, its own GangBond
55
+ {
56
+ gen: '2.0', pad: '0xb14d415f70D7F99f0D93Bd3BF76e0D6b38b53B3E', router: '0x5a4FA2D91638a305EdF027894753c943f095dDAA',
57
+ bond: '0x39749B59066d9cd1c55E2Fc48B31a3978C9951F9', splitterFactory: '0xDC9EdA9a29F4Ff66E7dAb6E5A2142df5a7aC0f6e',
58
+ splitFactory: '0xb9ab949C717a4F7f05c7B003C612C437280C3513', lpFactory: '0xAEec7e7948FfDb7a212E14c0b9cc1DA2922436E4',
59
+ comboFactory: '0x312c86F7139b3e3a75ee66b4D5Bfdbe5077584BD',
60
+ },
61
+ // 2026-10-31, pad block 139866088: the first 2.0 (creator fee, no graduation pick), no longer creating; its tokens trade
62
+ // and claim here. Its modules from the same scripts as 1.0's (docs/TESTNET-GANGLAUNCHPAD2-2026-10-31.md)
63
+ {
64
+ gen: '2.0', pad: '0x6381707406eb7E8EF8EdaF2DedBfFcEFFC0b39be', router: '0xb21828C49A526FA293C48990070a518e9ab9FC08',
65
+ bond: '0x913966122b9f8CC00C0d81000988A483c6B7F97f', splitterFactory: '0xBc26A6585B3Dc2Cbf1522475fB5b18df6C1033AE',
66
+ splitFactory: '0x860D51808E9FBB4f887FC7d0Aa9e1F8E19E00879', lpFactory: '0x4f1544e4e8853fC62088f0A4eCbEF409D2e11619',
67
+ comboFactory: null, // none: its tokens can't have a combined recipient
68
+ },
69
+ // set 10 (2026-10-27: §23 aggregator entries). GangBond 2026-10-29, block 139463214 — the audited version (earlier:
70
+ // 0x587f…5d7E, 0x5a99…d716, 0xB034…EBE3; docs/TESTNET-GANG-BOND-2026-10-28.md); split and LP factories
71
+ // docs/TESTNET-SPLIT-MODULE-2026-10-30.md, docs/TESTNET-LP-MODULE-2026-10-30.md
72
+ {
73
+ gen: '1.0', pad: '0xFebF58ba418ab4a3B3f054827eb11E99369C5BB1', router: '0x6bB660f310a9644Dc173E7Cf2F73498716D9C9F6',
74
+ bond: '0xd6a8dd5d1E6641a34A255f25Db2B3ED397CB1086', splitterFactory: '0x7E63fF8A9FB9Ab1BE4e2128e9f6C8D1054292BBe',
75
+ splitFactory: '0x5F7dC7502E945A860Cf49cca72dA8bD60Fb1567E', lpFactory: '0xA729C60FCa0Bd0D28a55E22126D3fE412AA41591',
76
+ comboFactory: '0x52a8f90a92E5C1828b4436a0B99C6b293f7F4CFE',
77
+ },
78
+ ],
25
79
  }
26
- // Unused while TESTNET_SET8 (set 10) is filled; kept as the fallback shape: testnet set 7 (one pad per kind, one router).
27
- const TESTNET_SET7 = {
28
- v3: '0x771b6dAA5240e3Cc0F0819535E8200774AFedEED',
29
- fair: '0xF45C221cF453d3943b00F905f66d66e34380956A',
30
- router: '0x9dBb3D25Ff5c8107814fBD96A88D6eD015dfA279',
80
+ // what a generation brings to a ctx (gen: '1.0' | '2.0', null for a pad named by the env that this CLI does not know)
81
+ const GEN_FIELDS = ['gen', 'pad', 'router', 'bond', 'splitterFactory', 'splitFactory', 'lpFactory', 'comboFactory']
82
+ // the env names of each field, per network (new name first; the old per-command names still work as aliases)
83
+ const GEN_ENV = {
84
+ mainnet: {
85
+ pad: ['GANG_PAD', 'GANG_V3_PAD', 'GANG_FAIR_PAD'], router: ['GANG_ROUTER'], bond: ['GANG_BOND'],
86
+ splitterFactory: ['GANG_SPLITTER_FACTORY'], splitFactory: ['GANG_SPLIT_FACTORY'], lpFactory: ['GANG_LP_FACTORY'],
87
+ comboFactory: ['GANG_COMBO_FACTORY'],
88
+ },
89
+ testnet: {
90
+ pad: ['GANG_TESTNET_PAD', 'GANG_V3_TESTNET_PAD', 'GANG_FAIR_TESTNET_PAD'], router: ['GANG_TESTNET_ROUTER', 'GANG_ROUTER_TESTNET'],
91
+ bond: ['GANG_TESTNET_BOND'], splitterFactory: ['GANG_TESTNET_SPLITTER_FACTORY'], splitFactory: ['GANG_TESTNET_SPLIT_FACTORY'],
92
+ lpFactory: ['GANG_TESTNET_LP_FACTORY'], comboFactory: ['GANG_TESTNET_COMBO_FACTORY'],
93
+ },
31
94
  }
32
95
 
33
96
  // Public BSC nodes, tried in this order (2026-10-30: each answered eth_call with revert data, tx and receipt reads).
@@ -93,23 +156,45 @@ const env = (...names) => {
93
156
  return null
94
157
  }
95
158
 
96
- /** Network settings for `gang v3` (kind 'v3') or `gang fair` (kind 'fair'): the same pad on a merged deployment. */
159
+ const sameAddr = (a, b) => !!a && !!b && a.toLowerCase() === b.toLowerCase()
160
+
161
+ /**
162
+ * The generations of a network as this run sees them, newest first. The env overrides the create target (the first):
163
+ * a GANG_PAD naming a known pad makes that generation the target, with its own contracts; an unknown pad gets only the
164
+ * router, bond and factories the env names. Every contract the env does not override stays the generation's own, so a
165
+ * pad is never paired with another generation's router or bond: a variable naming another built-in generation's
166
+ * contract (an old GANG_TESTNET_ROUTER set for set 10, say) is left out — that generation's tokens use it anyway.
167
+ */
168
+ export function gangGens(testnet) {
169
+ const net = testnet ? 'testnet' : 'mainnet'
170
+ const set = Object.fromEntries(Object.entries(GEN_ENV[net]).map(([k, names]) => [k, env(...names)]))
171
+ const list = GANG_GENS[net]
172
+ const first = { ...(set.pad ? (list.find((g) => sameAddr(g.pad, set.pad)) ?? { gen: null, pad: set.pad }) : list[0]) }
173
+ for (const k of GEN_FIELDS.slice(2)) {
174
+ if (set[k] && !list.some((g) => !sameAddr(g.pad, first.pad) && sameAddr(g[k], set[k]))) first[k] = set[k]
175
+ }
176
+ return [first, ...list.filter((g) => !sameAddr(g.pad, first.pad))].map(genFields)
177
+ }
178
+
179
+ /** A generation's contracts as ctx fields (missing ones null). */
180
+ export const genFields = (g) => Object.fromEntries(GEN_FIELDS.map((k) => [k, g?.[k] ?? null]))
181
+
182
+ /**
183
+ * Network settings for `gang v3` (kind 'v3') or `gang fair` (kind 'fair'): the same pad on a merged deployment. pad,
184
+ * router, bond and the factories are the create target's; `gens` lists every generation (atTokenPad moves a ctx to the
185
+ * one that has a token).
186
+ */
97
187
  export function padNets(kind) {
98
188
  const alias = kind === 'v3' ? 'V3' : 'FAIR'
99
- // one deployment set at a time: never pair a set-8 pad with the set-7 router or the other way round
100
- const set = TESTNET_SET8.pad ? TESTNET_SET8 : { pad: TESTNET_SET7[kind], router: TESTNET_SET7.router }
189
+ const [main, test] = [gangGens(false), gangGens(true)]
101
190
  return {
102
191
  mainnet: {
103
- chainId: '56', chain: bsc,
104
- pad: env('GANG_PAD', `GANG_${alias}_PAD`) || MAINNET_GANG.pad || null,
192
+ chainId: '56', chain: bsc, ...genFields(main[0]), gens: main,
105
193
  rpcs: rpcList(env('GANG_RPC_URL')) || MAINNET_RPCS,
106
194
  wbnb: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', explorer: 'https://bscscan.com',
107
- router: env('GANG_ROUTER') || MAINNET_GANG.router || null,
108
195
  },
109
196
  testnet: {
110
- chainId: '97', chain: bscTestnet,
111
- pad: env('GANG_TESTNET_PAD', `GANG_${alias}_TESTNET_PAD`) || set.pad,
112
- router: env('GANG_TESTNET_ROUTER', 'GANG_ROUTER_TESTNET') || set.router || null,
197
+ chainId: '97', chain: bscTestnet, ...genFields(test[0]), gens: test,
113
198
  rpcs: rpcList(env('GANG_TESTNET_RPC_URL', `GANG_${alias}_TESTNET_RPC_URL`)) || TESTNET_RPCS,
114
199
  wbnb: '0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd', explorer: 'https://testnet.bscscan.com',
115
200
  },
@@ -125,6 +210,8 @@ export const NOT_ON_MAINNET = 'no gang launchpad address for this network — se
125
210
  export const MERGED_ERRORS_ABI = parseAbi([
126
211
  'error Untaxed()', 'error NotReclaimable()', 'error NotLocked()', 'error WrongKind()', 'error TransfersLocked()',
127
212
  'error StillLocked()', 'error SwapBackOutOfGas()', 'error SellDuringFlashSwap()', 'error BadKind()',
213
+ // 2.0, both kinds: the graduation amount / raise in the quote is more than a PancakeSwap pair can hold
214
+ 'error QuoteAmountTooLarge()',
128
215
  ])
129
216
  export const MERGED_HINTS = {
130
217
  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',
@@ -136,6 +223,7 @@ export const MERGED_HINTS = {
136
223
  StillLocked: 'the token has not graduated / launched yet',
137
224
  SwapBackOutOfGas: 'too little gas for the sell-time tax chunk: re-run with the estimated gas limit (do not cap it lower)',
138
225
  SellDuringFlashSwap: 'a sell paid in from a flash swap callback is refused by this token',
226
+ 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',
139
227
  }
140
228
 
141
229
  const KIND_ABI = parseAbi(['function kindOf(address token) view returns (uint8)'])
@@ -150,6 +238,143 @@ export async function kindOf(ctx, token) {
150
238
  }
151
239
  }
152
240
 
241
+ /**
242
+ * Which generation's pad has `token`, asked of every pad of ctx.gens at once: { g, kind } with kind 'v3' | 'fair';
243
+ * { g: null, kind: 'none' } when no pad has it; kind null when a pad could not be read and no other one has it.
244
+ */
245
+ export async function genOf(ctx, token) {
246
+ const gens = ctx.gens ?? [ctx]
247
+ const kinds = await Promise.all(gens.map((g) => kindOf({ ...ctx, pad: g.pad }, token)))
248
+ const i = kinds.findIndex((k) => k === 'v3' || k === 'fair')
249
+ if (i >= 0) return { g: gens[i], kind: kinds[i] }
250
+ return { g: null, kind: kinds.includes(null) ? null : 'none' }
251
+ }
252
+
253
+ /**
254
+ * Move ctx to the generation whose pad has `token`: its pad, router, GangBond and factories. ctx stays on the create
255
+ * target when no pad has the token (the caller then says what it is not). → the token's kind as genOf gives it (null:
256
+ * a pad could not be read, see KIND_UNREAD); undefined when `token` is not an address (the caller refuses it).
257
+ */
258
+ export async function atTokenPad(ctx, token) {
259
+ if (!/^0x[0-9a-fA-F]{40}$/.test(token ?? '')) return undefined
260
+ const { g, kind } = await genOf(ctx, token)
261
+ if (g && !sameAddr(g.pad, ctx.pad)) {
262
+ Object.assign(ctx, genFields(g))
263
+ delete ctx._tax // the tax handler and the fee constants are the pad's
264
+ delete ctx.fees
265
+ }
266
+ return kind
267
+ }
268
+
269
+ /**
270
+ * Point ctx at the generation whose pad is `pad` (a module's own pad()), as atTokenPad does for a token; false when `pad`
271
+ * is none of this network's GangLaunchpad pads.
272
+ */
273
+ export function atPad(ctx, pad, testnet) {
274
+ const g = gangGens(testnet).find((x) => sameAddr(x.pad, pad))
275
+ if (!g) return false
276
+ if (!sameAddr(g.pad, ctx.pad)) {
277
+ Object.assign(ctx, genFields(g))
278
+ delete ctx._tax
279
+ delete ctx.fees
280
+ }
281
+ return true
282
+ }
283
+
284
+ const LISTING_ABI = parseAbi([
285
+ 'function taxHandler() view returns (address)',
286
+ 'function owner() view returns (address)',
287
+ 'function moduleOf(address module) view returns (address)',
288
+ ])
289
+ /**
290
+ * The factory that listed `module` on ctx.pad's tax handler (GangHandlerAdmin, the handler's owner: moduleOf), or null
291
+ * when it never listed it: not one of the platform's modules, whatever its moduleType() says.
292
+ */
293
+ export async function listedBy(ctx, module) {
294
+ const handler = await ctx.read(ctx.pad, LISTING_ABI, 'taxHandler')
295
+ const admin = await ctx.read(handler, LISTING_ABI, 'owner')
296
+ const factory = await ctx.read(admin, LISTING_ABI, 'moduleOf', [module])
297
+ return /^0x0{40}$/.test(factory) ? null : factory
298
+ }
299
+
300
+ /** What a command says when atTokenPad could not read every pad (null): retry rather than a wrong "not this kind". */
301
+ export const KIND_UNREAD = { error: 'could not read which GangLaunchpad has this token (kindOf; RPC error)', retry: 'same command again' }
302
+
303
+ /** The 2.0 creator fee: 70% of the 1% curve fee of each V3 curve trade, kept on the pad for the token's creator. */
304
+ export const CREATOR_FEE_ABI = parseAbi([
305
+ 'function CREATOR_FEE_SHARE_BPS() view returns (uint256)',
306
+ 'function creatorFeeOf(address token) view returns (uint256)',
307
+ 'function claimCreatorFee(address token, address to) returns (uint256 amount)',
308
+ 'error NotCreator()',
309
+ 'event CreatorFeeAccrued(address indexed token, address indexed creator, uint256 amount)',
310
+ 'event CreatorFeeClaimed(address indexed token, address indexed creator, address indexed to, uint256 amount)',
311
+ ])
312
+ const feeShares = new Map()
313
+ // a call that hit a contract without the function: no return data, or a revert without data. An RPC's internal error
314
+ // (-32603) also comes back from viem as a revert, so it is told apart by its code
315
+ const noSuchFunction = (e) => !e?.walk?.((x) => x?.code === -32603)
316
+ && !!e?.walk?.((x) => x?.name === 'ContractFunctionZeroDataError' || (x?.name === 'ContractFunctionRevertedError' && !x.data && (!x.raw || x.raw === '0x')))
317
+ /**
318
+ * The pad's creator share of the curve fee in bps (7000 on 2.0); null on a 1.0 pad. A built-in generation is known
319
+ * without a call (1.0: null); a pad named by the env is asked: a 1.0 pad has no CREATOR_FEE_SHARE_BPS (the call reverts
320
+ * without data). Any other error (the RPC) is thrown, so a 2.0 token is never shown as 1.0.
321
+ */
322
+ export async function creatorFeeShareOf(ctx, pad = ctx.pad) {
323
+ const known = [...GANG_GENS.mainnet, ...GANG_GENS.testnet].find((g) => sameAddr(g.pad, pad))
324
+ if (known?.gen === '1.0') return null
325
+ const key = `${ctx.chainId}:${pad.toLowerCase()}`
326
+ if (!feeShares.has(key)) {
327
+ const p = ctx.read(pad, CREATOR_FEE_ABI, 'CREATOR_FEE_SHARE_BPS').then(Number).catch((e) => {
328
+ if (!known && noSuchFunction(e)) return null
329
+ feeShares.delete(key)
330
+ throw e
331
+ })
332
+ feeShares.set(key, p)
333
+ }
334
+ return feeShares.get(key)
335
+ }
336
+
337
+ /**
338
+ * The V3 curve graduation target (GangLaunchpad 2.0): the creator picks one of GRAD_BNB_TIERS (BNB raised) with
339
+ * createWithGradTarget, create takes TARGET_GRAD_BNB (9 on 2.0). 1.0 has neither pick nor tiers: every curve 15 BNB.
340
+ */
341
+ export const GRAD_TARGET_ABI = parseAbi([
342
+ 'function GRAD_BNB_TIERS() pure returns (uint256[4])',
343
+ 'function TARGET_GRAD_BNB() view returns (uint256)',
344
+ 'function gradTargetOf(address token) view returns (uint256)',
345
+ 'function graduationAmountFor(address quote, address refPool, uint256 gradBnb) view returns (uint256)',
346
+ 'error BadGradTarget()',
347
+ 'event GradTargetSet(address indexed token, uint256 gradBnb)',
348
+ ])
349
+ const gradTiers = new Map()
350
+ const bnbNum = (wei) => Number(wei / 10n ** 15n) / 1000
351
+ /**
352
+ * The graduation targets a creator may pick on `pad`, in BNB ([6, 9, 12, 15]); null on a pad without the pick (1.0,
353
+ * known without a call, or an older 2.0 build: GRAD_BNB_TIERS reverts without data). An RPC error is thrown.
354
+ */
355
+ export async function gradTiersOf(ctx, pad = ctx.pad) {
356
+ const known = [...GANG_GENS.mainnet, ...GANG_GENS.testnet].find((g) => sameAddr(g.pad, pad))
357
+ if (known?.gen === '1.0') return null
358
+ const key = `${ctx.chainId}:${pad.toLowerCase()}`
359
+ if (!gradTiers.has(key)) {
360
+ const p = ctx.read(pad, GRAD_TARGET_ABI, 'GRAD_BNB_TIERS').then((t) => t.map(bnbNum)).catch((e) => {
361
+ if (noSuchFunction(e)) return null
362
+ gradTiers.delete(key)
363
+ throw e
364
+ })
365
+ gradTiers.set(key, p)
366
+ }
367
+ return gradTiers.get(key)
368
+ }
369
+ /** A token's graduation target in BNB raised: its pick (gradTargetOf) where the pad has one, else the pad's TARGET_GRAD_BNB. */
370
+ export async function gradTargetBnbOf(ctx, token) {
371
+ if (await gradTiersOf(ctx)) {
372
+ const v = await ctx.read(ctx.pad, GRAD_TARGET_ABI, 'gradTargetOf', [token])
373
+ if (v > 0n) return bnbNum(v)
374
+ }
375
+ return bnbNum(await ctx.read(ctx.pad, GRAD_TARGET_ABI, 'TARGET_GRAD_BNB'))
376
+ }
377
+
153
378
  /**
154
379
  * Why `token` is not a `want` ('v3' | 'fair') token on this pad, as { error, hint, kind } for fail(): points at the right
155
380
  * subcommand when kindOf says it is the other kind. `net` is appended to the suggested command (' --testnet' or '').
package/src/index.js CHANGED
@@ -27,10 +27,13 @@ import { runFly, flyCtx, isFlyToken, FLY_EVENT_ABIS, FLY_CREATE_FLAGS } from './
27
27
  import { FAIR_DEV_BUY, isLaunch, LAUNCH_FLAGS, runLaunch } from './launch.js'
28
28
  import { poolPayBnb, poolTrade } from './pool.js'
29
29
  import { parseAmount, ROUTER_ABI, ROUTER_HINTS, revertOf as revertIn, step as writeStep } from './steps.js'
30
- import { MERGED_ERRORS_ABI, kindOf, padNets } from './gangpad.js'
30
+ import { MERGED_ERRORS_ABI, genOf, padNets } from './gangpad.js'
31
+ import { creatorFeeCtx, creatorFeeList, runCreatorFee } from './creatorfee.js'
31
32
  import { V2_ABI } from './abi.js'
32
33
  import { runMcp } from './mcp.js'
33
34
  import { portfolio } from './portfolio.js'
35
+ import { record } from './telemetry.js'
36
+ import { trending, trendingBlock, TRENDING_NOTE } from './trending.js'
34
37
  import { parseAbi } from 'viem'
35
38
 
36
39
  const args = process.argv.slice(2)
@@ -39,11 +42,17 @@ const opt = (name, def) => { const i = args.indexOf(`--${name}`); return i >= 0
39
42
  const flag = (name) => args.includes(`--${name}`)
40
43
  // set once in main() when npm has a newer CLI; every JSON result then carries it (`gang watch` streams don't)
41
44
  let update = null
42
- const out = (o) => console.log(JSON.stringify(update ? { ...o, update } : o, (_, v) => (typeof v === 'bigint' ? v.toString() : v), 2))
45
+ // the first result of a run is also counted (anonymously, telemetry.js) unless GANG_TELEMETRY=0
46
+ const out = (o) => {
47
+ record(args, o)
48
+ console.log(JSON.stringify(update ? { ...o, update } : o, (_, v) => (typeof v === 'bigint' ? v.toString() : v), 2))
49
+ }
43
50
  // `gang watch` speaks NDJSON, so its failures are one line too (with event/fatal for stream consumers)
44
51
  const fail = (msg, extra = {}) => {
45
- if (cmd === 'watch') console.log(JSON.stringify({ event: 'error', fatal: true, success: false, error: msg, ...extra }))
46
- else out({ success: false, error: msg, ...extra })
52
+ if (cmd === 'watch') {
53
+ record(args, { success: false, error: msg, ...extra })
54
+ console.log(JSON.stringify({ event: 'error', fatal: true, success: false, error: msg, ...extra }))
55
+ } else out({ success: false, error: msg, ...extra })
47
56
  process.exit(1)
48
57
  }
49
58
 
@@ -216,6 +225,9 @@ U / S pads) and run that kind's trade. Results of V3 / 打新 / 铸币飞轮 tok
216
225
  gang_help (this text + the rules), reads, watch, buy / sell / follow previews,
217
226
  execute, and gang_cli for every other command
218
227
  gang preflight check sign-in, Developer Mode, tradeAllTokens, Agent ID
228
+ gang trending what other agents buy now: up to 5 tokens with the most distinct agent buyers in 6h,
229
+ up to 3 followable notes by 60%+ authors (also carried by preflight and list as
230
+ trending). Not a recommendation: never buy from it on your own
219
231
  gang list [--limit 20] [--kind v3|fair|fly [--status …]]
220
232
  V2 / Soft / U / S tokens read on chain (works without gang.fun), the newest --limit
221
233
  per pad; --kind v3 (--status curve|graduated|all) / --kind fair
@@ -278,14 +290,17 @@ U / S pads) and run that kind's trade. Results of V3 / 打新 / 铸币飞轮 tok
278
290
  copy an image to gang.fun → logoUrl (ipfs://<cid>, for --logo-uri) and url (CDN)
279
291
 
280
292
  gang create --name <n> --symbol <s> [--buy-tax <1-5> --sell-tax <1-5> [--dividend 0-100] [--recipient <0x…>]]
281
- [--quote 0x… --ref-pool 0x…] [--logo <file> | --logo-uri URL] [--website URL] [--twitter @handle]
282
- [--description <text>] [--testnet]
293
+ [--grad 6|9|12|15] [--quote 0x… --ref-pool 0x…] [--logo <file> | --logo-uri URL] [--website URL]
294
+ [--twitter @handle] [--description <text>] [--testnet]
283
295
  a V3 token on GangLaunchpad (LaunchpadV2 / Soft / U / S take no new tokens; --taxed,
284
296
  the old V2 track, is refused). No --buy-tax / --sell-tax: untaxed (no pool tax, no
285
297
  dividend, no recipient). Taxed: own buy / sell tax in % (fixed at create), only in the
286
298
  pool after graduation: 0.5% of volume to the platform; of the rest --dividend % to
287
299
  holders, the remainder to --recipient (default: you, the creator; or a partner on the
288
- platform whitelist) in the quote. Curve trades pay only the 1% fee, no tax
300
+ platform whitelist) in the quote. Curve trades pay only the 1% fee, no tax.
301
+ --grad (GangLaunchpad 2.0): the graduation target in BNB raised, 6 / 9 / 12 / 15
302
+ (default 9; market cap at graduation ≈ 5×); 1.0 graduates every curve at 15 and
303
+ refuses --grad. info / status show each token's graduationTargetBnb
289
304
  gang create --fair --name <n> --symbol <s> [--raise 15] [--cap 0.5] [--hold 60] [--mint-fee 1] [--exit-fee 1]
290
305
  [--shares 1] [--quote 0x… --ref-pool 0x…] [--logo …] [--website URL] [--twitter @handle] [--description …]
291
306
  a 打新 (fair mint) sale: one price per share both ways, the last share launches on
@@ -294,7 +309,7 @@ U / S pads) and run that kind's trade. Results of V3 / 打新 / 铸币飞轮 tok
294
309
  mint fee 1–3%, withdraw fee 1–2% (none after 7 days without 10 new shares). Wraps /
295
310
  approves first when needed (re-run after each)
296
311
  both: --quote = WBNB (default) or any 18-decimal token; --ref-pool = a Pancake V2 pair
297
- or V3 pool holding it, which prices the 15 BNB graduation target / the raise (mainnet
312
+ or V3 pool holding it, which prices the graduation target / the raise (mainnet
298
313
  USDT defaults to the USDT/WBNB pool) unless gang set a fixed rate. --website /
299
314
  --twitter / --description and the logo go into the token's metadata JSON (uploaded to
300
315
  gang.fun; the token's contractURI / metaURI, permanent). --logo-uri images are copied
@@ -410,6 +425,16 @@ U / S pads) and run that kind's trade. Results of V3 / 打新 / 铸币飞轮 tok
410
425
  past the deadline, --settle-first settles the bond before the sell (asks first;
411
426
  settles 1 hour later).
412
427
 
428
+ CREATOR FEE (GangLaunchpad 2.0: of the 1% fee on every V3 curve buy and sell, 70% is kept on the pad for the token's
429
+ creator, before and after graduation, no deadline; 1.0 tokens and 打新 sales have none):
430
+ gang creator-fee [--from <creator>] every 2.0 V3 token this wallet created and what it can claim (read on chain), with
431
+ totals per quote
432
+ gang creator-fee --token <addr> one token: padGen, sharePct, claimable
433
+ gang creator-fee --token <addr> --claim [--to <addr>]
434
+ claim all of it (the creator only), to this wallet or --to (not 0x0 or the pad).
435
+ The fee is the creator's own: never the tax recipient's or a buy-back / split / LP
436
+ module's. gang info / status (the creator's) and gang portfolio show it too
437
+
413
438
  BOND (押金承诺, GangBond; any GangLaunchpad token, from create on; GANG_BOND / GANG_TESTNET_BOND = its address):
414
439
  gang bond post --token <addr> --hold <tokens|N%> --days <7-90> (--amount <quote> | --cover <coverage %>) [--use-wbnb]
415
440
  creator only, any time after create (V3: buy on the curve first): bond in the token's
@@ -453,7 +478,16 @@ BUYBACK (a V3 token whose recipient is a buy-back splitter; GANG_SPLITTER_FACTOR
453
478
  gang buyback apply --token <addr> anyone: apply a cut whose notice ran (within 7 days, or it lapses)
454
479
  gang buyback bind --token <addr> | gang buyback release --token <addr>
455
480
  anyone: bind the splitter to its token (the launch does it) / push the payee what a
456
- failed payment left owed. --testnet, --calldata, --from as in gang v3
481
+ failed payment left owed
482
+ gang buyback split (--token <addr> | --module <splitter>)
483
+ anyone: split what arrived since the last split: the payee's part is pushed now, the
484
+ buy-back part set aside (the preview shows both). The keeper's chunks split first, so
485
+ after graduation it runs by itself; before it (a creator fee claimed --to the
486
+ splitter) only this pays the payee. Only a splitter a GangLaunchpad pad listed.
487
+ gang buyback sweep (--token <addr> | --module <splitter>) --asset <addr>|wbnb
488
+ anyone: send the splitter's whole balance of an asset that is not its own quote (a
489
+ creator fee or a tax in another quote) to the payee; split never moves it.
490
+ --testnet, --calldata, --from as in gang v3
457
491
  SPLIT (a V3 token whose recipient is a split module, split-v1; GANG_SPLIT_FACTORY / GANG_TESTNET_SPLIT_FACTORY):
458
492
  gang split status --token <addr> payees and shares (fixed), the dev, the bound token / quote, what waits to be split
459
493
  and what each slot is owed (bound quote, WBNB, GANG, the token's quote), whether the
@@ -486,6 +520,11 @@ LP (a V3 token whose recipient is an LP splitter, lp-burn-v1; GANG_LP_FACTORY /
486
520
  gang lp bind --token <addr> | gang lp release --token <addr>
487
521
  anyone: bind the splitter to its token (the launch does it) / push the payee what a
488
522
  failed payment left owed
523
+ gang lp split (--token <addr> | --module <splitter>)
524
+ anyone: split what arrived since the last split: the payee's part is pushed now, the
525
+ pool's part set aside (the preview shows both); as gang buyback split
526
+ gang lp sweep (--token <addr> | --module <splitter>) --asset <addr>|wbnb
527
+ anyone: another asset than the splitter's quote to the payee; as gang buyback sweep
489
528
  gang lp add --token <addr> [--slippage 1]
490
529
  anyone: one chunk now, as the keeper does (graduated tokens; one per 4 minutes; ≤ 0.5%
491
530
  of the pair's quote reserve; waits for a 10-minute average and skips when the price is
@@ -547,10 +586,12 @@ off, GANG_UPDATE_URL points it at an npm mirror).
547
586
 
548
587
  env: GANG_RPC_URL (one URL or a comma list; unset: five public BSC nodes, the next one tried when one fails),
549
588
  GANG_LOGO_API, GANG_API (default ${API}), GANG_NOTES_DIR (default ~/.gang/notes), GANG_UPDATE_CHECK, GANG_UPDATE_URL,
550
- GANG_PAD / GANG_TESTNET_PAD (the one GangLaunchpad behind both gang v3 and gang fair; old names GANG_V3_PAD / GANG_FAIR_PAD
551
- and GANG_V3_TESTNET_PAD / GANG_FAIR_TESTNET_PAD still work as aliases), GANG_TESTNET_RPC_URL (aliases
589
+ GANG_PAD / GANG_TESTNET_PAD (the GangLaunchpad new tokens go to, behind both gang v3 and gang fair; old names GANG_V3_PAD /
590
+ GANG_FAIR_PAD and GANG_V3_TESTNET_PAD / GANG_FAIR_TESTNET_PAD still work as aliases), GANG_TESTNET_RPC_URL (aliases
552
591
  GANG_V3_TESTNET_RPC_URL / GANG_FAIR_TESTNET_RPC_URL), GANG_ROUTER / GANG_TESTNET_ROUTER (alias GANG_ROUTER_TESTNET; GangRouter
553
- for BNB buys / mints and every pool trade; both default to the built-in mainnet / testnet set 10 addresses),
592
+ for BNB buys / mints and every pool trade). Built in: GangLaunchpad 1.0 on mainnet; 2.0 (where new tokens go) and 1.0
593
+ on the testnet. A token is always served by its own generation's pad, router, GangBond and module factories; these
594
+ variables (and GANG_BOND / GANG_*_FACTORY) set the create target's only,
554
595
  GANG_FLY_PAD / GANG_TESTNET_FLY_PAD (GangFlywheelPad V1; default: the built-in mainnet / testnet set 2 addresses),
555
596
  GANG_FLY_PAD_V2 / GANG_TESTNET_FLY_PAD_V2 (V2, where new tokens go; default: the built-in mainnet / testnet V2). --guard / --twap-window
556
597
  (V2 only): the guard is off by default (post-launch minting does not pause on a price drop; the quota cap of 10 per
@@ -937,7 +978,8 @@ async function padKind(token, verb) {
937
978
  const testnet = flag('testnet')
938
979
  let ctx
939
980
  try { ctx = v3Ctx(testnet) } catch (e) { fail(e.message) }
940
- const kind = await kindOf(ctx, token)
981
+ // every GangLaunchpad generation of this network (1.0, 2.0) is asked
982
+ const { kind } = await genOf(ctx, token)
941
983
  if (kind === 'v3' || kind === 'fair') return kind
942
984
  // not GangLaunchpad's: the 铸币飞轮 pad (GangFlywheelPad, kind 3) is asked next
943
985
  const fly = await isFlyToken(flyCtx(testnet), token)
@@ -1073,7 +1115,10 @@ function checkFlyCreate() {
1073
1115
  : `--${wrong} is a V3 tax setting; a 铸币飞轮 token's tax goes to holders, the platform and the creator in fixed parts`)
1074
1116
  }
1075
1117
  }
1118
+ // --grad picks a V3 curve's graduation target (2.0); a 打新 / 铸币飞轮 sale ends at its own --raise
1119
+ const GRAD_ONLY_V3 = (what) => `--grad is a V3 curve setting (the graduation target, 2.0): ${what} fills at its --raise instead, so leave --grad out`
1076
1120
  function create() {
1121
+ if (flag('grad') && (flag('fly') || flag('fair'))) fail(GRAD_ONLY_V3(flag('fly') ? 'a 铸币飞轮 sale' : 'a 打新 sale'))
1077
1122
  if (flag('fly')) {
1078
1123
  checkFlyCreate()
1079
1124
  return runFly('create', { ...PAD_IO })
@@ -1092,10 +1137,16 @@ function create() {
1092
1137
  return runV3('create', { ...PAD_IO, notes: padNotes('v3', 'create') })
1093
1138
  }
1094
1139
 
1140
+ // after a clean preflight: where a first trade usually starts
1141
+ const PREFLIGHT_NEXT = [
1142
+ 'gang trending: what other agents buy now',
1143
+ 'gang notes --min-hit 0.6: followable calls by authors who hit 60%+',
1144
+ 'a first buy can be small: gang buy --token <addr> --amount 0.01 previews it, nothing is sent before gang execute',
1145
+ ]
1095
1146
  // commands whose JSON result carries `update`; `watch` streams NDJSON and help is plain text
1096
- const UPDATE_CHECKED = new Set(['version', '--version', '-v', 'preflight', 'list', 'hot', 'new', 'near-grad', 'notes', 'agents', 'token', 'info', 'status', 'portfolio', 'quote',
1147
+ const UPDATE_CHECKED = new Set(['version', '--version', '-v', 'preflight', 'list', 'trending', 'hot', 'new', 'near-grad', 'notes', 'agents', 'token', 'info', 'status', 'portfolio', 'quote',
1097
1148
  'buy', 'follow', 'sell', 'claim', 'mint', 'withdraw', 'release', 'upload-logo', 'create', 'execute', 'tx', 'fair', 'v3', 'bond',
1098
- 'buyback', 'split', 'lp', 'combo', 'fly'])
1149
+ 'buyback', 'split', 'lp', 'combo', 'fly', 'creator-fee'])
1099
1150
  // gang tx decodes these beside the V2 / Soft / U / S pads' events (GangLaunchpad: both kinds; the tax router; the vaults)
1100
1151
  const GANG_EVENT_ABIS = [...V3_EVENT_ABIS, ...FAIR_EVENT_ABIS, ...FLY_EVENT_ABIS, ...SPLIT_EVENT_ABIS, ...LP_EVENT_ABIS, ...COMBO_EVENT_ABIS]
1101
1152
 
@@ -1170,6 +1221,8 @@ async function pendingReport() {
1170
1221
 
1171
1222
  async function main() {
1172
1223
  if (UPDATE_CHECKED.has(cmd)) update = checkUpdate()
1224
+ // streams and the MCP server print no single result: count the start (MCP tools run this CLI, so each one counts itself)
1225
+ if (cmd === 'watch' || cmd === 'mcp') record(args, { success: true })
1173
1226
  // `gang create` (= `gang v3 create`) / `gang fair create` write the links into the token metadata
1174
1227
  const tokenCreate = cmd === 'create' || ((cmd === 'v3' || cmd === 'fair' || cmd === 'fly') && args[1] === 'create')
1175
1228
  const flyCreate = (cmd === 'create' && flag('fly')) || (cmd === 'fly' && args[1] === 'create')
@@ -1204,6 +1257,8 @@ async function main() {
1204
1257
  return runFly(args[1], alias('fly', args[1]))
1205
1258
  case 'mcp':
1206
1259
  return runMcp()
1260
+ case 'creator-fee':
1261
+ return runCreatorFee({ opt, flag, out, fail, summarize: summarizePreview })
1207
1262
  case 'bond':
1208
1263
  await refuseFly('GangBond')
1209
1264
  return runBond(args[1], { opt, flag, out, fail, summarize: summarizePreview })
@@ -1235,12 +1290,16 @@ async function main() {
1235
1290
  agent = await createGateAgent(me)
1236
1291
  if (!agent) issues.push({ code: 'NO_AGENT_ID', fix: 'Claim a .ai Agent ID in Binance Wallet (Agent ID banner). Gang only lets Agent ID holders buy/create.' })
1237
1292
  }
1293
+ // after the baw calls: they block the event loop, and the fetch's short timeout would run out meanwhile
1294
+ const hot = trendingBlock()
1238
1295
  return out({
1239
1296
  success: issues.length === 0, cliVersion: VERSION, status, address: me,
1240
1297
  // `launchpad` = createPad: kept for readers of the old field (it used to be the V2 create target)
1241
- launchpad: padNets('v3').mainnet.pad, createPad: padNets('v3').mainnet.pad, isAgent: agent,
1298
+ launchpad: padNets('v3').mainnet.pad, createPad: padNets('v3').mainnet.pad, createPadGen: padNets('v3').mainnet.gen, isAgent: agent,
1242
1299
  devMode: settings?.devMode?.enabled ?? null, tradeAllTokens: settings?.tradeAllTokens ?? null, issues,
1243
1300
  note: 'New create → GangLaunchpad (gang create = gang v3 create; gang fair create for 打新). LaunchpadV2 / Soft / U / S take no new tokens: existing buy / sell only.',
1301
+ ...(!issues.length && { next: PREFLIGHT_NEXT }),
1302
+ ...await hot.then((t) => (t ? { trending: t } : {})),
1244
1303
  })
1245
1304
  }
1246
1305
  case 'list': {
@@ -1254,10 +1313,20 @@ async function main() {
1254
1313
  }
1255
1314
  const me = bawStatus() === 'CONNECTED' ? bawAddress() : undefined
1256
1315
  const perPad = parseCount('limit', opt('limit', '20'), 1000)
1316
+ const hot = trendingBlock()
1257
1317
  const { tokens, pads } = await listTokens(me, perPad)
1258
1318
  return out({
1259
1319
  success: true, createPad: padNets('v3').mainnet.pad, perPad, pads, tokens,
1260
1320
  ...(pads.some((p) => p.total > p.listed) && { note: `newest ${perPad} per pad; --limit <n> (up to 1000) lists more` }),
1321
+ ...await hot.then((t) => (t ? { trending: t } : {})),
1322
+ })
1323
+ }
1324
+ case 'trending': {
1325
+ const t = await trending()
1326
+ if (!t) fail(`gang.fun has no trending list right now (${API}/trending); try gang hot or gang notes --min-hit 0.6`, { retry: true })
1327
+ return out({
1328
+ success: true, at: t.at ? localTime(t.at) : null, tokens: t.tokens, calls: t.calls, note: TRENDING_NOTE,
1329
+ ...(!t.tokens.length && !t.calls.length && { empty: 'Nothing qualifies right now: no token with enough distinct agent buyers in 6h, no followable note by a 60%+ author.' }),
1261
1330
  })
1262
1331
  }
1263
1332
  case 'hot':
@@ -1403,7 +1472,10 @@ async function main() {
1403
1472
  case 'portfolio': {
1404
1473
  if (flag('testnet')) fail('gang portfolio is mainnet only: gang.fun indexes no testnet trades (gang status --testnet reads one token)')
1405
1474
  const me = fromArg() || bawAddress()
1406
- return out(await portfolio({ wallet: me, get: (path) => apiGet(path, undefined, null), statusOf: portfolioStatus, bondOf: portfolioBond })
1475
+ return out(await portfolio({
1476
+ wallet: me, get: (path) => apiGet(path, undefined, null), statusOf: portfolioStatus, bondOf: portfolioBond,
1477
+ creatorFeesOf: (w) => creatorFeeList(creatorFeeCtx(false), w),
1478
+ })
1407
1479
  .catch((e) => fail(e.message, retryHint(e))))
1408
1480
  }
1409
1481
  case 'status':
@@ -1444,7 +1516,7 @@ async function main() {
1444
1516
  const { token, follow } = await confirmFollow(noteTx, fromArg() || bawAddress())
1445
1517
  if (!token) fail('gang.fun did not say which token this note is about', { noteTx })
1446
1518
  // a GangLaunchpad token: the V3 curve buy (--amount / --bnb = the quote to spend)
1447
- const onPad = await kindOf(v2PoolCtx(), token)
1519
+ const { kind: onPad } = await genOf({ ...v2PoolCtx(), gens: padNets('v3').mainnet.gens }, token)
1448
1520
  if (onPad === 'fair') fail('this note is on a 打新 (fair-mint) token: only curve buys can follow a note', { noteTx, token })
1449
1521
  if (onPad !== 'v3' && (await isFlyToken(flyCtx(false), token))) fail('this note is on a 铸币飞轮 (Mint Flywheel) token: only curve buys can follow a note', { noteTx, token })
1450
1522
  if (onPad === 'v3') {