@gangfun/cli 0.21.0 → 0.23.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/launch.js CHANGED
@@ -3,13 +3,15 @@ import { mkdirSync, readdirSync, readFileSync, renameSync, statSync, unlinkSync,
3
3
  import { dirname, join } from 'node:path'
4
4
  import { createPublicClient, parseAbi, formatUnits, encodeFunctionData, isAddress, zeroAddress } from 'viem'
5
5
  import { DIR } from './notes.js'
6
- import { padNets, NOT_ON_MAINNET, rpcTransport } from './gangpad.js'
6
+ import { creatorFeeShareOf, gradTiersOf, padNets, NOT_ON_MAINNET, rpcTransport } from './gangpad.js'
7
7
  import { bondAddress, BOND_ABI } from './bond.js'
8
8
  import { walletFor } from './fair.js'
9
9
  import { parseAmount, parseIntIn, step } from './steps.js'
10
10
  import { buybackBpsOf, FACTORY_ABI, notDeployed, simulateCall, SPLITTER_ABI, splitterFactoryAddress, splitterOf } from './buyback.js'
11
11
  import { parseSplitSpec, simulateSplit, SPLIT_ABI, SPLIT_FACTORY_ABI, splitFactoryAddress, splitLine, splitNotDeployed, splitOf } from './split.js'
12
12
  import { LP_ABI, LP_FACTORY_ABI, lpBpsOf, lpFactoryAddress, lpNotDeployed, lpOf, simulateLp } from './lp.js'
13
+ import { claimCmd, notThroughModule } from './creatorfee.js'
14
+ import { COMBO_ABI, COMBO_FACTORY_ABI, comboFactoryAddress, comboLine, comboNotDeployed, comboOf, comboParts, parseComboSpec, PERMANENT_NOTE, simulateCombo } from './combo.js'
13
15
 
14
16
  /**
15
17
  * One command for a launch: `gang create … [--buyback <pct>] [--dev-buy <quote> [--bond <quote> [--bond-hold <tokens|N%|all>]
@@ -36,9 +38,16 @@ import { LP_ABI, LP_FACTORY_ABI, lpBpsOf, lpFactoryAddress, lpNotDeployed, lpOf,
36
38
  * --lp <pct> [--lp-to <addr>] (V3, taxed): the same three steps with GangLiquiditySplitterFactory — the dev's LP splitter
37
39
  * (lp-burn-v1: --lp % of the recipient's part added to the pair as liquidity, the LP to 0xdead) is cloned at
38
40
  * predict(dev, salt), named as the recipient, then bound (`module: 'lp'` in the plan). A launch keeps the ratio and payee
39
- * it began with. --buyback, --split, --lp and --recipient are exclusive (each sets the recipient).
41
+ * it began with. --recipient goes with none of them (each sets the recipient).
42
+ * More than one of --buyback, --lp, --split (taxed V3): the same three steps with GangComboSplitterFactory — the dev's
43
+ * combined recipient (combo-v1: --buyback % of the recipient's part bought back and burned, --lp % added as liquidity, the
44
+ * rest pushed to the --split payees, or to the dev alone without --split) is cloned at predict(dev, salt), named as the
45
+ * recipient, then bound (`module: 'combo'`). Everything in it is fixed for good, so a re-run with other ratios or payees
46
+ * is refused rather than starting over. --buyback-to / --lp-to don't apply (the payees are --split's).
40
47
  */
41
48
 
49
+ // the dev's recipient modules by flag, as the creator-fee note names them
50
+ const MODULE_NAMES = { buyback: 'buy-back splitter', split: 'split module', lp: 'LP splitter', combo: 'combined recipient' }
42
51
  const LAUNCH_DIR = process.env.GANG_LAUNCH_DIR || join(dirname(DIR), 'launch')
43
52
  const TTL_MS = 7 * 24 * 3600_000
44
53
  const PAD_ABI = parseAbi([
@@ -61,7 +70,7 @@ const REGISTRY_ABI = parseAbi(['function quoteRegistry() view returns (address)'
61
70
  * --split takes the same quotes: a quote that calls the receiver back on transfer would let one payee make every split
62
71
  * run out of gas, and the keeper splits only these quotes anyway (split spec §2.4).
63
72
  * --lp takes the same quotes: the keeper adds liquidity only over these, and an unlisted quote may tax or block the
64
- * transfers into the pair every chunk makes.
73
+ * transfers into the pair every chunk makes. A combined recipient (several of them) takes the same quotes for all reasons.
65
74
  * null when trusted; otherwise the failure to report.
66
75
  */
67
76
  const UNTRUSTED = {
@@ -77,6 +86,10 @@ const UNTRUSTED = {
77
86
  why: '--lp needs WBNB, GANG or a quote listed in the pad\'s QuoteRegistry: the keeper adds liquidity only over those quotes, and an unlisted quote may tax or block the transfers into the pair every chunk makes',
78
87
  hint: 'drop --quote (WBNB), use a listed quote, or launch without --lp',
79
88
  },
89
+ combo: {
90
+ why: 'a combined recipient (more than one of --buyback / --lp / --split) needs WBNB, GANG or a quote listed in the pad\'s QuoteRegistry: its buy-backs and liquidity adds price on what the pair receives (a quote that taxes transfers into the pair fails every chunk), the keeper serves only those quotes, and an unlisted quote may call a payee back on transfer',
91
+ hint: 'drop --quote (WBNB), use a listed quote, or launch without --buyback / --lp / --split',
92
+ },
80
93
  }
81
94
  export async function untrustedBuybackQuote(read, net, quote, mode = 'buyback') {
82
95
  if (!isAddress(quote ?? '')) return { error: '--quote must be a 0x address', got: quote ?? null }
@@ -102,8 +115,10 @@ export const FAIR_DEV_BUY = 'a 打新 dev buys its shares in the create itself:
102
115
 
103
116
  /** The run asks for a chained launch (`kind` 'v3' | 'fair'). */
104
117
  export const isLaunch = (kind, flag) => flag('bond') || flag('buyback') || flag('split') || flag('lp') || (kind === 'v3' && flag('dev-buy'))
105
- /** The recipient modules a launch can clone (their flags), at most one per launch. */
118
+ /** The recipient modules a launch can clone (their flags): one alone clones its own module, several a combined one. */
106
119
  const MODULE_FLAGS = ['buyback', 'split', 'lp']
120
+ /** How a module's flags read in a message. */
121
+ const MOD_FLAG = { buyback: '--buyback', split: '--split', lp: '--lp', combo: 'more than one of --buyback / --lp / --split' }
107
122
 
108
123
  const planPath = (key) => join(LAUNCH_DIR, `${createHash('sha256').update(key).digest('hex').slice(0, 32)}.json`)
109
124
 
@@ -149,9 +164,9 @@ export async function runLaunch(kind, { io, runV3, runFair, runBond, padNotes })
149
164
  if (kind === 'fair' && flag('buyback')) fail('--buyback is for V3 tokens: it makes the tax recipient a buy-back splitter, and a 打新 token has no recipient')
150
165
  if (kind === 'fair' && flag('split')) fail('--split is for V3 tokens: it makes the tax recipient a split module, and a 打新 token has no recipient')
151
166
  if (kind === 'fair' && flag('lp')) fail('--lp is for V3 tokens: it makes the tax recipient an LP splitter, and a 打新 token has no recipient')
152
- if (flag('split') && flag('buyback')) fail('give --split or --buyback, not both: each makes the tax recipient its own module (a split with a buy-back is not supported)')
153
167
  const mods = MODULE_FLAGS.filter((f) => flag(f))
154
- if (mods.length > 1) fail(`give one of --${mods.join(' / --')}, not several: each makes the tax recipient its own module`)
168
+ // more than one: one combined recipient (GangComboSplitter) does them all
169
+ const combo = mods.length > 1
155
170
 
156
171
  // everything checked before the create, so a launch never stops half way on a bad flag
157
172
  const devBuy = kind === 'v3' && flag('dev-buy') ? parseAmount(fail, 'dev-buy', opt('dev-buy')) : null
@@ -169,10 +184,27 @@ export async function runLaunch(kind, { io, runV3, runFair, runBond, padNotes })
169
184
  bond = { amount: parseAmount(fail, 'bond', opt('bond')), hold, days: parseIntIn(fail, 'bond-days', opt('bond-days'), 7, 90) }
170
185
  }
171
186
 
187
+ // several of --buyback / --lp / --split: a taxed V3 token whose recipient is the dev's combined recipient
188
+ let comboFactory = null
189
+ if (combo) {
190
+ const names = mods.map((f) => `--${f}`).join(' + ')
191
+ comboFactory = comboFactoryAddress(testnet)
192
+ if (!comboFactory) fail(comboNotDeployed(testnet), { flags: mods.map((f) => `--${f}`) })
193
+ for (const to of ['buyback-to', 'lp-to']) {
194
+ if (flag(to)) fail(`--${to} does not apply to a combined recipient (${names}): the part not bought back or added goes to the payees — name them with --split self:<pct>,<addr>:<pct>,… (shares of that rest; without --split it all goes to you)`)
195
+ }
196
+ const zero = (f) => /^0+(\.0+)?$/.test(opt(f) ?? '')
197
+ if (!flag('buy-tax') || !flag('sell-tax') || (zero('buy-tax') && zero('sell-tax'))) {
198
+ fail(`${names} needs a taxed token: add --buy-tax and --sell-tax (each 1–5, in %); the combined recipient is paid from the tax`)
199
+ }
200
+ if (flag('recipient')) fail(`${names} makes the recipient your combined recipient: leave --recipient out`)
201
+ if (/^0*100(\.0+)?$/.test(opt('dividend', '0'))) fail(`--dividend 100 leaves nothing for the recipient: lower it or drop ${names}`)
202
+ }
203
+
172
204
  // --buyback: a taxed V3 token whose recipient (the part left after holders) is the dev's splitter
173
205
  let buyback = null
174
206
  if (flag('buyback-to') && !flag('buyback')) fail('--buyback-to <addr> goes with --buyback <pct>: it names where the part not bought back goes')
175
- if (flag('buyback')) {
207
+ if (flag('buyback') && !combo) {
176
208
  const zero = (f) => /^0+(\.0+)?$/.test(opt(f) ?? '')
177
209
  if (!flag('buy-tax') || !flag('sell-tax') || (zero('buy-tax') && zero('sell-tax'))) {
178
210
  fail('--buyback needs a taxed token: add --buy-tax and --sell-tax (each 1–5, in %); the buy-back is paid from the tax')
@@ -191,9 +223,24 @@ export async function runLaunch(kind, { io, runV3, runFair, runBond, padNotes })
191
223
 
192
224
  const me = walletFor({ chainId: net.chainId }, opt('from'))
193
225
 
226
+ // the combined recipient's ratios and payees (shares of the rest), checked as its initialize checks them
227
+ let comboSpec = null
228
+ if (combo) {
229
+ const spec = parseComboSpec({
230
+ buybackBps: flag('buyback') ? buybackBpsOf(fail, opt('buyback')) : 0,
231
+ lpBps: flag('lp') ? lpBpsOf(fail, opt('lp')) : 0,
232
+ split: flag('split') ? (opt('split') ?? '') : undefined,
233
+ }, me)
234
+ if (spec.error) {
235
+ const { error, ...extra } = spec
236
+ fail(error, extra)
237
+ }
238
+ comboSpec = { ...spec, factory: comboFactory }
239
+ }
240
+
194
241
  // --split: a taxed V3 token whose recipient is the dev's split module (fixed payees and shares)
195
242
  let split = null
196
- if (flag('split')) {
243
+ if (flag('split') && !combo) {
197
244
  const zero = (f) => /^0+(\.0+)?$/.test(opt(f) ?? '')
198
245
  if (!flag('buy-tax') || !flag('sell-tax') || (zero('buy-tax') && zero('sell-tax'))) {
199
246
  fail('--split needs a taxed token: add --buy-tax and --sell-tax (each 1–5, in %); the split is paid from the tax')
@@ -213,7 +260,7 @@ export async function runLaunch(kind, { io, runV3, runFair, runBond, padNotes })
213
260
  // --lp: a taxed V3 token whose recipient is the dev's LP splitter (auto-liquidity, the LP to 0xdead)
214
261
  let lp = null
215
262
  if (flag('lp-to') && !flag('lp')) fail('--lp-to <addr> goes with --lp <pct>: it names where the part not added to the pool goes')
216
- if (flag('lp')) {
263
+ if (flag('lp') && !combo) {
217
264
  const zero = (f) => /^0+(\.0+)?$/.test(opt(f) ?? '')
218
265
  if (!flag('buy-tax') || !flag('sell-tax') || (zero('buy-tax') && zero('sell-tax'))) {
219
266
  fail('--lp needs a taxed token: add --buy-tax and --sell-tax (each 1–5, in %); the liquidity is paid from the tax')
@@ -229,12 +276,18 @@ export async function runLaunch(kind, { io, runV3, runFair, runBond, padNotes })
229
276
  }
230
277
  lp = { bps: lpBpsOf(fail, opt('lp')), factory, payee }
231
278
  }
232
- const mod = buyback ? 'buyback' : split ? 'split' : lp ? 'lp' : null
279
+ const mod = comboSpec ? 'combo' : buyback ? 'buyback' : split ? 'split' : lp ? 'lp' : null
233
280
 
234
281
  const client = createPublicClient({ chain: net.chain, transport: rpcTransport(net.rpcs) })
235
282
  const read = (address, abi, functionName, args = []) => client.readContract({ address, abi, functionName, args })
283
+ // --grad (2.0): checked here, before a module clone, since the create that takes it comes later
284
+ if (kind === 'v3' && flag('grad')) {
285
+ const tiers = await gradTiersOf({ chainId: net.chainId, pad: net.pad, read })
286
+ if (!tiers) fail(`--grad: GangLaunchpad ${net.gen ?? net.pad} has no graduation target to pick: leave --grad out`)
287
+ if (!tiers.includes(Number(opt('grad')))) fail(`--grad must be one of ${tiers.join(' / ')} (BNB raised)`, { got: opt('grad') ?? null })
288
+ }
236
289
  const key = [net.chainId, net.pad, me.toLowerCase(), kind, name, symbol].join('|')
237
- const cloneStep = buyback ? 'buyback-splitter' : split ? 'split-module' : 'lp-splitter'
290
+ const cloneStep = { buyback: 'buyback-splitter', split: 'split-module', lp: 'lp-splitter', combo: 'combo-module' }[mod]
238
291
  const steps = [...(mod ? [cloneStep] : []), kind === 'v3' ? 'create' : 'create (dev shares included)', ...(mod ? ['bind'] : []),
239
292
  ...(devBuy ? ['dev-buy'] : []), ...(bond ? ['bond'] : [])]
240
293
  const rerun = 're-run this same command after executing it'
@@ -242,18 +295,35 @@ export async function runLaunch(kind, { io, runV3, runFair, runBond, padNotes })
242
295
  const withTag = (stage, extra) => (o) => out({ ...o, ...tag(stage, extra) })
243
296
 
244
297
  let plan = flag('restart') ? null : readPlan(key)
298
+ // a launch begun on another generation's pad (an older CLI) and not done: its module and token belong to that pad, so
299
+ // it is never carried on here, nor started again without --restart
300
+ if (!plan && !flag('restart')) {
301
+ const old = net.gens.slice(1).map((g) => ({ g, p: readPlan([net.chainId, g.pad, me.toLowerCase(), kind, name, symbol].join('|')) })).find((x) => x.p && !x.p.done)
302
+ if (old) {
303
+ const tn = testnet ? ' --testnet' : ''
304
+ // two pads of one generation (testnet: 2.0 before and after the graduation pick) are told apart by address
305
+ const same = old.g.gen === net.gen
306
+ const lbl = (g) => (same ? `${g.gen ?? ''} pad ${g.pad}`.trim() : g.gen ?? g.pad)
307
+ const [was, now] = [lbl(old.g), lbl(net)]
308
+ return fail(`this launch began on GangLaunchpad ${was} and is not done; new tokens now go to ${now}`, {
309
+ ...(old.p.token ? { token: old.p.token, hint: `the token is out on ${was}: finish its steps one by one (gang buy --token ${old.p.token} --amount <quote>${tn}, gang bond post --token ${old.p.token} …${tn}), or add --restart to launch a new token on ${now}` }
310
+ : { hint: `${old.p.splitter ? `its module ${old.p.splitter} was made for the ${was} pad and does not work with ${now}: ` : ''}add --restart to launch on ${now}` }),
311
+ })
312
+ }
313
+ }
245
314
  const base = { kind, name, symbol, me, chainId: net.chainId, pad: net.pad }
246
315
 
247
316
  // ---- a launch keeps the mode it began with (the create, once built, is never redone by a changed flag)
248
317
  const created = plan?.startCount !== undefined
249
- // the module this plan cloned: 'split' / 'lp' when it says so, else a --buyback splitter (plans from before --split)
250
- const planMod = plan?.salt ? (plan.module === 'split' || plan.module === 'lp' ? plan.module : 'buyback') : null
251
- const modNoun = { buyback: 'splitter', split: 'split module', lp: 'LP splitter' }
318
+ // the module this plan cloned: 'split' / 'lp' / 'combo' when it says so, else a --buyback splitter (plans from before --split)
319
+ const planMod = plan?.salt ? (['split', 'lp', 'combo'].includes(plan.module) ? plan.module : 'buyback') : null
320
+ const modNoun = { buyback: 'splitter', split: 'split module', lp: 'LP splitter', combo: 'combined recipient' }
252
321
  if (mod && created && !plan.splitter) {
253
- return fail(`this launch was created without --${mod} (its recipient is fixed): run it again without --${mod}, or add --restart for a new token`)
322
+ return fail(`this launch was created without ${MOD_FLAG[mod]} (its recipient is fixed): run it again without ${mod === 'combo' ? '--buyback / --lp / --split' : MOD_FLAG[mod]}, or add --restart for a new token`)
254
323
  }
255
324
  if (planMod && mod !== planMod && (!created || mod)) {
256
- return fail(`this launch began with --${planMod} (its ${modNoun[planMod]} is cloned or on the way): run it again with --${planMod}${mod ? ` instead of --${mod}` : ''}, or add --restart${mod ? '' : ` without it`}`)
325
+ const again = planMod === 'combo' ? 'the same --buyback / --lp / --split as before' : MOD_FLAG[planMod]
326
+ return fail(`this launch began with ${MOD_FLAG[planMod]} (its ${modNoun[planMod]} is cloned or on the way): run it again with ${again}${mod ? ` instead of ${MOD_FLAG[mod]}` : ''}, or add --restart${mod ? '' : ' without it'}`)
257
327
  }
258
328
 
259
329
  // ---- buy-back splitter: cloned for the dev before the create, at predict(dev, plan.salt)
@@ -389,6 +459,54 @@ export async function runLaunch(kind, { io, runV3, runFair, runBond, padNotes })
389
459
  }
390
460
  }
391
461
 
462
+ // ---- combined recipient: cloned for the dev before the create, at predict(dev, plan.salt)
463
+ if (comboSpec && !created) {
464
+ if (!plan?.salt) {
465
+ const refused = await untrustedBuybackQuote(read, net, flag('quote') ? opt('quote') : net.wbnb, 'combo')
466
+ if (refused) {
467
+ const { error, ...extra } = refused
468
+ return fail(error, extra)
469
+ }
470
+ if ((await client.getCode({ address: comboSpec.factory }) ?? '0x') === '0x') {
471
+ const env = testnet ? 'GANG_TESTNET_COMBO_FACTORY' : 'GANG_COMBO_FACTORY'
472
+ return fail(`GangComboSplitterFactory has no code at ${comboSpec.factory} on ${testnet ? 'the BSC testnet' : 'BSC mainnet'}: give one of --buyback / --lp / --split alone for now${process.env[env] ? ` (or fix ${env})` : ''}`, { factory: comboSpec.factory })
473
+ }
474
+ const salt = `0x${randomBytes(32).toString('hex')}`
475
+ const at = await read(comboSpec.factory, COMBO_FACTORY_ABI, 'predict', [me, salt])
476
+ if (comboSpec.payees.some((p) => p.toLowerCase() === at.toLowerCase())) return fail('--split: a payee cannot be the combined recipient itself', { module: at })
477
+ const args = [comboSpec.buybackBps, comboSpec.lpBps, comboSpec.payees, comboSpec.shares, salt]
478
+ const sim = await simulateCombo(client, me, comboSpec.factory, COMBO_FACTORY_ABI, 'create', args)
479
+ if (sim.failed) return out({ success: false, step: 'combo-module', factory: comboSpec.factory, ...tag('combo-module'), ...sim.failed })
480
+ writePlan(key, { ...base, salt, splitter: at, factory: comboSpec.factory, module: 'combo' })
481
+ const data = encodeFunctionData({ abi: COMBO_FACTORY_ABI, functionName: 'create', args })
482
+ const parts = comboParts(comboSpec.buybackBps, comboSpec.lpBps, comboSpec.payees.length)
483
+ return out({
484
+ ...step({ chainId: net.chainId }, { from: me, to: comboSpec.factory, data }, {
485
+ step: 'combo-module', chainId: Number(net.chainId), factory: comboSpec.factory, module: at,
486
+ buybackPct: comboSpec.buybackBps / 100, lpPct: comboSpec.lpBps / 100, payeesPct: (10_000 - comboSpec.buybackBps - comboSpec.lpBps) / 100,
487
+ payees: comboSpec.list, permanent: true, parts,
488
+ note: `clones your combined recipient (combo-v1, listed as a tax recipient in the same tx). Of the recipient's part of the tax: ${comboLine(comboSpec.buybackBps, comboSpec.lpBps, comboSpec.payees, comboSpec.shares)}. ${PERMANENT_NOTE}. ${parts.otherAssets[0].toUpperCase()}${parts.otherAssets.slice(1)}`,
489
+ }, flag('calldata'), io.summarize),
490
+ ...tag('combo-module', { module: at, next: `${rerun}: it then builds the create with the combined recipient as the recipient` }),
491
+ })
492
+ }
493
+ if ((await client.getCode({ address: plan.splitter }) ?? '0x') === '0x') {
494
+ return out({
495
+ success: false, ...tag('combo-module', { module: plan.splitter }), error: 'the combined recipient is not on chain yet',
496
+ hint: `if the clone was executed, wait for it to land and ${rerun.replace(' after executing it', '')}; if it was not, add --restart to build it again`,
497
+ })
498
+ }
499
+ const s = await comboOf(read, plan.splitter, { wbnb: net.wbnb })
500
+ if (!s || s.dev.toLowerCase() !== me.toLowerCase() || s.token) {
501
+ return fail('the module at this launch\'s address is not an unbound combined recipient of this wallet: add --restart', { module: plan.splitter })
502
+ }
503
+ const same = s.buybackBps === comboSpec.buybackBps && s.lpBps === comboSpec.lpBps && s.payees.length === comboSpec.payees.length
504
+ && s.payees.every((p, i) => p.payee.toLowerCase() === comboSpec.payees[i].toLowerCase() && p.bps === comboSpec.shares[i])
505
+ if (!same) {
506
+ return fail(`this launch's combined recipient is ${comboLine(s.buybackBps, s.lpBps, s.payees.map((p) => p.payee), s.payees.map((p) => p.bps))}, not what --buyback / --lp / --split say: run it again with those, or add --restart for a new one (nothing in it can change after the clone)`, { module: plan.splitter })
507
+ }
508
+ }
509
+
392
510
  // ---- create
393
511
  if (!created) {
394
512
  const startCount = (await read(net.pad, PAD_ABI, 'tokenCount')).toString()
@@ -403,6 +521,8 @@ export async function runLaunch(kind, { io, runV3, runFair, runBond, padNotes })
403
521
  const after = steps[steps.indexOf(kind === 'v3' ? 'create' : 'create (dev shares included)') + 1]
404
522
  return out({
405
523
  ...o,
524
+ // 2.0: the creator fee is the dev's own, not the module's
525
+ ...(o.creatorFee && mod && { creatorFee: `${o.creatorFee} ${notThroughModule(MODULE_NAMES[mod], { at: plan?.splitter, net: testnet ? ' --testnet' : '', kind: mod })}` }),
406
526
  ...tag('create', built ? { next: `${rerun}: it finds the new token and continues with ${after ?? 'nothing'}` } : o.success ? { next: `${rerun}: it then builds the create` } : {}),
407
527
  })
408
528
  },
@@ -439,7 +559,9 @@ export async function runLaunch(kind, { io, runV3, runFair, runBond, padNotes })
439
559
  const bal = await read(token, ERC20_ABI, 'balanceOf', [me])
440
560
  const isSplit = plan.module === 'split'
441
561
  const isLp = plan.module === 'lp'
442
- const buybackState = () => (plan.splitter && !isSplit && !isLp ? splitterOf(read, plan.splitter) : null)
562
+ const isCombo = plan.module === 'combo'
563
+ const buybackState = () => (plan.splitter && !isSplit && !isLp && !isCombo ? splitterOf(read, plan.splitter) : null)
564
+ const comboState = () => (plan.splitter && isCombo ? comboOf(read, plan.splitter, { wbnb: net.wbnb, pad: net.pad, ref: `--token ${token}${testnet ? ' --testnet' : ''}` }) : null)
443
565
  const lpState = () => (plan.splitter && isLp ? lpOf(read, plan.splitter, { pad: net.pad }) : null)
444
566
  const splitState = () => (plan.splitter && isSplit ? splitOf(read, plan.splitter, { wbnb: net.wbnb, ref: `--token ${token}${testnet ? ' --testnet' : ''}` }) : null)
445
567
 
@@ -455,23 +577,32 @@ export async function runLaunch(kind, { io, runV3, runFair, runBond, padNotes })
455
577
  if (sp) done.split = sp
456
578
  const lps = await lpState()
457
579
  if (lps) done.lp = lps
580
+ const cs = await comboState()
581
+ if (cs) done.combo = cs
582
+ // 2.0: where the creator fee of a V3 token is claimed (and that a module does not get it)
583
+ const share = kind === 'v3' ? await creatorFeeShareOf({ chainId: net.chainId, pad: net.pad, read }).catch(() => null) : null
584
+ if (share != null) {
585
+ done.creatorFee = `${share / 100}% of the 1% curve fee is kept for you, the creator: ${claimCmd(token, testnet ? ' --testnet' : '')}${plan.splitter ? `. ${notThroughModule(MODULE_NAMES[planMod], { token, at: plan.splitter, net: testnet ? ' --testnet' : '', kind: planMod })}` : ''}`
586
+ }
458
587
  if (!bond) return out({ ...done, note: `launched: gang ${kind} info --token ${token}${testnet ? ' --testnet' : ''}` })
459
588
  return runBond('status', { ...stepIo({}), out: (o) => out({ ...done, bondStatus: o, note: `launched and bonded: gang bond status --token ${token}${testnet ? ' --testnet' : ''}` }) })
460
589
  }
461
590
  if (plan.done) return report()
462
591
 
463
- // ---- bind the splitter / split module / LP splitter to the token (anyone may; the launch does it right after the create)
592
+ // ---- bind the splitter / split module / LP splitter / combined recipient to the token (anyone may; the launch does it right after the create)
464
593
  if (plan.splitter) {
465
- const abi = isSplit ? SPLIT_ABI : isLp ? LP_ABI : SPLITTER_ABI
594
+ const abi = isCombo ? COMBO_ABI : isSplit ? SPLIT_ABI : isLp ? LP_ABI : SPLITTER_ABI
466
595
  const bound = await read(plan.splitter, abi, 'token')
467
596
  if (bound === zeroAddress) {
468
- const sim = await (isSplit ? simulateSplit : isLp ? simulateLp : simulateCall)(client, me, plan.splitter, abi, 'bind', [token])
597
+ const sim = await (isCombo ? simulateCombo : isSplit ? simulateSplit : isLp ? simulateLp : simulateCall)(client, me, plan.splitter, abi, 'bind', [token])
469
598
  if (sim.failed) return out({ success: false, step: 'bind', ...tag('bind', { token }), ...sim.failed })
470
599
  const data = encodeFunctionData({ abi, functionName: 'bind', args: [token] })
471
600
  return out({
472
601
  ...step({ chainId: net.chainId }, { from: me, to: plan.splitter, data }, {
473
- step: 'bind', chainId: Number(net.chainId), token, ...(isSplit ? { module: plan.splitter } : { splitter: plan.splitter }),
474
- note: isSplit
602
+ step: 'bind', chainId: Number(net.chainId), token, ...(isSplit || isCombo ? { module: plan.splitter } : { splitter: plan.splitter }),
603
+ note: isCombo
604
+ ? 'ties the combined recipient to this token for good: its quote is what gets split, and its pair is where the buy-backs and liquidity go (from graduation on). Nothing is split before this'
605
+ : isSplit
475
606
  ? 'ties the split module to this token for good: the keeper then splits its quote among the payees'
476
607
  : isLp
477
608
  ? 'ties the LP splitter to this token for good: its pair is where the liquidity goes (from graduation on)'
@@ -481,7 +612,7 @@ export async function runLaunch(kind, { io, runV3, runFair, runBond, padNotes })
481
612
  })
482
613
  }
483
614
  if (bound.toLowerCase() !== token.toLowerCase()) {
484
- return out({ success: false, ...tag('bind', { token }), error: `the ${isSplit ? 'split module' : isLp ? 'LP splitter' : 'splitter'} is bound to another token`, [isSplit ? 'module' : 'splitter']: plan.splitter, boundTo: bound })
615
+ return out({ success: false, ...tag('bind', { token }), error: `the ${isCombo ? 'combined recipient' : isSplit ? 'split module' : isLp ? 'LP splitter' : 'splitter'} is bound to another token`, [isSplit || isCombo ? 'module' : 'splitter']: plan.splitter, boundTo: bound })
485
616
  }
486
617
  }
487
618
 
package/src/lp.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { createPublicClient, parseAbi, encodeFunctionData, formatUnits, hexToString, isAddress, maxUint128, zeroAddress } from 'viem'
2
- import { padNets, NOT_ON_MAINNET, rpcTransport } from './gangpad.js'
2
+ import { atPad, atTokenPad, GANG_GENS, KIND_UNREAD, gangGens, listedBy, padNets, NOT_ON_MAINNET, rpcTransport } from './gangpad.js'
3
+ import { notListed, splitPlan, sweepAsset, sweepPlan, sweepReads } from './buyback.js'
3
4
  import { walletFor } from './fair.js'
4
5
  import { parseNum, revertOf as revertIn, step } from './steps.js'
5
6
 
@@ -18,13 +19,12 @@ import { parseNum, revertOf as revertIn, step } from './steps.js'
18
19
  * for the next chunk.
19
20
  * Gas: a chunk takes ~0.53–0.75M (the deposit lets the tax handler sell a chunk of its tax first). The CLI never sets a
20
21
  * gas limit: the wallet / node estimates it; a fixed or trimmed limit can revert.
21
- * Env: GANG_LP_FACTORY / GANG_TESTNET_LP_FACTORY override the built-in factory addresses.
22
+ * Env: GANG_LP_FACTORY / GANG_TESTNET_LP_FACTORY override the create target's factory (gangpad.js).
22
23
  */
23
24
 
24
- // BSC 56: deployed 2026-10-31, allowed on GangHandlerAdmin by the platform's Safe the same day
25
- export const MAINNET_LP_FACTORY = '0xE0436867dAFcf42Ee1418083251a9B8B61F0C248'
26
- // BSC 97, set 10 (docs/TESTNET-LP-MODULE-2026-10-30.md)
27
- export const TESTNET_LP_FACTORY = '0xA729C60FCa0Bd0D28a55E22126D3fE412AA41591'
25
+ // one factory per GangLaunchpad generation (it is bound to one pad): the create target's (GANG_GENS in gangpad.js)
26
+ export const MAINNET_LP_FACTORY = GANG_GENS.mainnet[0].lpFactory
27
+ export const TESTNET_LP_FACTORY = GANG_GENS.testnet[0].lpFactory
28
28
  export const LP_TYPE = 'lp-burn-v1'
29
29
  const BPS = 10_000n
30
30
  const CHUNK_GAP_S = 4 * 60
@@ -65,6 +65,7 @@ export const LP_ABI = parseAbi([
65
65
  'function applyLpBps()',
66
66
  'function setPayee(address newPayee)',
67
67
  'function split()',
68
+ 'function pad() view returns (address)',
68
69
  'function releaseDev() returns (uint256)',
69
70
  'function addChunk(uint256 minTokensOut) returns (uint256 quoteIn, uint256 tokensIn, uint256 liquidity)',
70
71
  'function work(uint256 minOut)',
@@ -128,8 +129,7 @@ export async function simulateLp(client, from, address, abi, functionName, args
128
129
  }
129
130
 
130
131
  export function lpFactoryAddress(testnet) {
131
- return (testnet ? process.env.GANG_TESTNET_LP_FACTORY || TESTNET_LP_FACTORY
132
- : process.env.GANG_LP_FACTORY || MAINNET_LP_FACTORY) || null
132
+ return gangGens(testnet)[0].lpFactory || null
133
133
  }
134
134
 
135
135
  export const lpNotDeployed = (testnet) =>
@@ -207,8 +207,8 @@ function lpCtx(testnet) {
207
207
  return { ...net, client, read: (address, abi, functionName, args = []) => client.readContract({ address, abi, functionName, args }) }
208
208
  }
209
209
 
210
- const SUBS = ['status', 'set', 'set-payee', 'apply', 'bind', 'release', 'add']
211
- const USAGE = 'usage: gang lp <status|set|set-payee|apply|bind|release|add> --token <addr> [--pct <0-100>] [--to <addr>] [--slippage 1] [--testnet] — see gang help'
210
+ const SUBS = ['status', 'set', 'set-payee', 'apply', 'bind', 'release', 'split', 'sweep', 'add']
211
+ const USAGE = 'usage: gang lp <status|set|set-payee|apply|bind|release|split|sweep|add> --token <addr> (split / sweep: or --module <addr>) [--pct <0-100>] [--to <addr>] [--asset <addr>|wbnb] [--slippage 1] [--testnet] — see gang help'
212
212
 
213
213
  /** `gang lp <sub>`: the LP splitter of a V3 token (its tax recipient), found from --token. */
214
214
  export async function runLp(sub, { opt, flag, out, fail, summarize }) {
@@ -217,15 +217,30 @@ export async function runLp(sub, { opt, flag, out, fail, summarize }) {
217
217
  const rawOnly = flag('calldata')
218
218
  let ctx
219
219
  try { ctx = lpCtx(testnet) } catch (e) { return fail(e.message) }
220
- const token = opt('token')
221
- if (!isAddress(token ?? '')) fail('--token must be a V3 token address (0x…)', { got: token ?? null })
220
+ // split / sweep may name the splitter itself (--module), e.g. the --to of a creator-fee claim
221
+ const named = (sub === 'split' || sub === 'sweep') && flag('module')
222
+ if (named && flag('token')) fail('give --token (its tax recipient is the splitter) or --module, not both')
223
+ let token = opt('token')
222
224
  const chainId = Number(ctx.chainId)
223
225
  let recipient
224
- try { recipient = (await ctx.read(ctx.pad, PAD_ABI, 'taxConfigOf', [token]))[3] } catch {
225
- return fail(`not a V3 token on this pad (${testnet ? 'BSC testnet' : 'BSC mainnet; add --testnet for a testnet token'})`, { token, chainId })
226
+ if (named) {
227
+ recipient = opt('module')
228
+ if (!isAddress(recipient ?? '')) fail('--module must be an LP splitter address (0x…)', { got: recipient ?? null })
229
+ const pad = await ctx.read(recipient, LP_ABI, 'pad').catch(() => null)
230
+ if (!pad || !atPad(ctx, pad, testnet)) return fail(notListed('LP splitter', testnet), { module: recipient })
231
+ } else {
232
+ if (!isAddress(token ?? '')) fail('--token must be a V3 token address (0x…)', { got: token ?? null })
233
+ if ((await atTokenPad(ctx, token)) === null) return fail(KIND_UNREAD.error, { token: token, retry: KIND_UNREAD.retry }) // else on the pad of the token's generation
234
+ try { recipient = (await ctx.read(ctx.pad, PAD_ABI, 'taxConfigOf', [token]))[3] } catch {
235
+ return fail(`not a V3 token on this pad (${testnet ? 'BSC testnet' : 'BSC mainnet; add --testnet for a testnet token'})`, { token, chainId })
236
+ }
226
237
  }
227
238
  const s = await lpOf(ctx.read, recipient, { pad: ctx.pad })
228
- if (!s) return fail('this token\'s tax recipient is not an LP splitter (lp-burn-v1)', { token, recipient: recipient === zeroAddress ? null : recipient })
239
+ if (!s) {
240
+ return fail(named ? 'not an LP splitter (lp-burn-v1)' : 'this token\'s tax recipient is not an LP splitter (lp-burn-v1)',
241
+ named ? { module: recipient } : { token, recipient: recipient === zeroAddress ? null : recipient })
242
+ }
243
+ if (named) token = s.token
229
244
  const tn = testnet ? ' --testnet' : ''
230
245
  // the token pays this splitter, which is bound to another token: it adds liquidity only to that one's pair
231
246
  const warning = s.token && s.token.toLowerCase() !== token.toLowerCase()
@@ -276,6 +291,28 @@ export async function runLp(sub, { opt, flag, out, fail, summarize }) {
276
291
  return send('applyLpBps', [], { step: 'apply-cut', fromPct: s.lpPct, toPct: s.pendingCut.toPct, note: 'anyone may apply a cut once its notice ran' })
277
292
  }
278
293
 
294
+ if (sub === 'split') {
295
+ if (!(await listedBy(ctx, s.splitter))) return fail(notListed('LP splitter', testnet), { module: s.splitter })
296
+ const [waiting, left] = await Promise.all(['unsplit', 'lpLeft'].map((f) => ctx.read(s.splitter, LP_ABI, f)))
297
+ const plan = splitPlan({ unsplit: waiting, bps: s.lpBps, left, payee: s.payee, part: 'liquidity', leftField: 'lpLeft', symbol: s.quoteSymbol ?? null, unbound: !s.token })
298
+ if (plan.error) return fail(plan.error, { splitter: s.splitter, lpLeft: s.lpLeft, devOwed: s.devOwed })
299
+ return send('split', [], {
300
+ step: 'split', ...plan,
301
+ note: `anyone may: splits what arrived since the last split. ${plan.toPayee} goes to the payee now (should that push fail, it is owed: gang lp release --token ${s.token}${tn}); ${plan.setAside} (${s.lpPct}%) is set aside for the pool, which the keeper adds in chunks once the token trades in its pair (each chunk splits first too, so after graduation this runs by itself)`,
302
+ })
303
+ }
304
+
305
+ if (sub === 'sweep') {
306
+ if (!(await listedBy(ctx, s.splitter))) return fail(notListed('LP splitter', testnet), { module: s.splitter })
307
+ const asset = sweepAsset(opt, fail, ctx.wbnb)
308
+ const plan = sweepPlan({ asset, ...(await sweepReads(ctx.read, s.splitter, LP_ABI, asset)), payee: s.payee, cmd: 'gang lp' })
309
+ if (plan.error) return fail(plan.error, { splitter: s.splitter, asset })
310
+ return send('sweep', [asset], {
311
+ step: 'sweep', ...plan,
312
+ note: 'anyone may: sends the splitter\'s whole balance of this asset (not its own quote; e.g. a creator fee or another token\'s tax in another quote) to the payee; none of it goes into the pool',
313
+ })
314
+ }
315
+
279
316
  if (sub === 'release') {
280
317
  if (!(Number(s.devOwed) > 0)) return fail(HINTS.NothingOwed)
281
318
  return send('releaseDev', [], { step: 'release', amount: s.devOwed, payee: s.payee, note: 'anyone may; the payee gets what a failed push left owed' })
package/src/mcp.js CHANGED
@@ -24,7 +24,7 @@ const WATCH_MAX_SEC = 30 * 60
24
24
 
25
25
  // what the host shows the agent up front; some hosts cut server instructions near 2,000 characters, so the long form is in
26
26
  // RULES (gang_help). Keep both in step with skill/SKILL.md "Hard rules"
27
- const INSTRUCTIONS = `Gang (gang.fun): agent-only token launchpad on BNB Chain. Curve trades need a Binance Agentic Wallet with a .ai Agent ID: call gang_preflight first, relay each issues[].fix. Call gang_help for all flags and the full rules before any create, launch, bond, buyback, split, lp, mint or withdraw.
27
+ const INSTRUCTIONS = `Gang (gang.fun): agent-only token launchpad on BNB Chain. Curve trades need a Binance Agentic Wallet with a .ai Agent ID: call gang_preflight first, relay each issues[].fix. Call gang_help for all flags and the full rules before any create, launch, bond, buyback, split, lp, combo, mint or withdraw.
28
28
  Hard rules:
29
29
  - Preview -> show the user -> wait for a yes -> gang_execute. gang_buy / gang_sell / gang_follow and writes via gang_cli only preview; never gang_execute without the user's OK on that preview, unless they said to skip confirmation.
30
30
  - step wrap-bnb | approve | approve-quote = setup: execute it, check gang_tx, run the same tool again. A launch in one command is re-run until launch.stage is done.
@@ -42,11 +42,11 @@ Hard rules:
42
42
  export const RULES = [
43
43
  'Start: gang_preflight; relay each issues[].fix. A result carrying update: { cmd, skill } means this CLI is older than the rules: tell the user to run cmd, and do not trade on it.',
44
44
  'Preview -> show -> confirm -> execute. Every write first returns a preview with a requestId: show it, get the user\'s OK, then gang_execute. Chain steps without asking only when the user said to skip confirmation.',
45
- 'Setup steps: a preview with step wrap-bnb | approve-quote | approve is executed first; once gang_tx shows it landed, run the same tool again for the real step. A launch in one command (create with --dev-buy / --bond / --buyback / --split / --lp, or create --fair with --bond) is one tx per run: execute it, run the very same gang_cli args again until launch.stage is done.',
45
+ 'Setup steps: a preview with step wrap-bnb | approve-quote | approve is executed first; once gang_tx shows it landed, run the same tool again for the real step. A launch in one command (create with --dev-buy / --bond / --buyback / --split / --lp, two or three of the last three together for one combined recipient whose ratios and payees are fixed for good, or create --fair with --bond) is one tx per run: execute it, run the very same gang_cli args again until launch.stage is done.',
46
46
  'A gang_execute that timed out or was cancelled on your side keeps running here (the wallet may have sent it): never execute it again or build a new preview for the same trade before checking gang_status or gang_tx with pending: true; then gang_tx (hash, or pending: true) for the result and the note.',
47
47
  'Notes (--note) are public and permanent: write one by default on every buy, sell, mint, withdraw (one line: what you saw, why now) and every create (the launch manifesto). Base it on data you checked, show its text with the preview, leave it out only when the user says so. No links. --conf is an honest 0-100.',
48
48
  'Permanent token data: the logo, website, X link and description go on-chain at create and can never change. Use only links the user gave; ask once if they have not said. Never host a logo on a temporary file host. Local files (--logo, upload-logo --file) are read by this MCP server: pass an absolute path, or --logo-uri <image URL>.',
49
- 'New tokens go on GangLaunchpad only: create (V3, untaxed unless --buy-tax / --sell-tax) or create --fair (fair mint), or GangFlywheelPad: create --fly (Mint Flywheel). Never an older pad.',
49
+ 'New tokens go on GangLaunchpad only: create (V3, untaxed unless --buy-tax / --sell-tax; on GangLaunchpad 2.0 --grad 6|9|12|15 picks the graduation target in BNB, default 9) or create --fair (fair mint), or GangFlywheelPad: create --fly (Mint Flywheel). Never an older pad.',
50
50
  'Bonds: before a bond post, tell the user there is no early withdrawal and any sell below the promised holding before settle, anywhere, loses the whole bond. Posted before graduation / launch, the promise binds at once and its days start at graduation / launch; only if there is still no pair 30 days after the post can the creator ask for it back (bond refund; it returns 3 days after asking, and a graduation meanwhile voids that). Relay warning. breakBond (--break-bond) only when the user, told that, still says sell. bond report only when the user asks.',
51
51
  'Fair mint holder reward: before a sell or transfer of a fair-mint token check sellableBeforeOut (gang_status); going past it ends the reward for good. confirmOut (--confirm-out) only with the user\'s yes.',
52
52
  'Mint Flywheel (fly): the same hold line, but a wallet that falls below it earns again after its next mint. An inviter (--ref) only counts on a wallet\'s first mint in that token; never invent one, use the address or link the user gave.',
@@ -85,7 +85,7 @@ const tool = (name, title, description, properties, args, annotations, required
85
85
 
86
86
  export const TOOLS = [
87
87
  tool('gang_help', 'Commands and rules',
88
- 'Every gang command with all its flags (the CLI help) and the full rules. Read it before a create, launch, bond, buyback, split, lp, mint or withdraw, and whenever a flag is unclear; those commands then go through gang_cli.',
88
+ 'Every gang command with all its flags (the CLI help) and the full rules. Read it before a create, launch, bond, buyback, split, lp, combo, mint or withdraw, and whenever a flag is unclear; those commands then go through gang_cli.',
89
89
  {}, () => [], READ),
90
90
  tool('gang_preflight', 'Check wallet setup', 'Signed in to baw, Developer Mode, Trade all tokens, Agent ID; each issue comes with a fix.',
91
91
  {}, () => ['preflight'], READ),
@@ -175,7 +175,7 @@ export const TOOLS = [
175
175
  { hash: HASH, pending: { type: 'boolean', description: 'Find the txs of trades approved in the Binance App (no hash needed)' }, testnet: TESTNET },
176
176
  (a) => (a.pending ? ['tx', '--pending'] : ['tx', '--hash', a.hash, ...bool('testnet', a.testnet)]), PREVIEW),
177
177
  tool('gang_cli', 'Other gang commands',
178
- 'Every other gang command, its flags as separate items (gang_help lists them all): create (V3; create --fair = fair mint; create --fly = Mint Flywheel; launch in one command with --dev-buy / --bond / --buyback / --split / --lp), mint (--ref <inviter> on a Mint Flywheel token), withdraw, claim, release, fly open-early|launch|invite, quote, list, upload-logo, bond post|topup|raise-hold|extend|status|start|report|settle|refund|burn|tx, buyback status|set|set-payee|apply|bind|release, split status|distribute|release|set-payee|bind, lp status|set|set-payee|apply|bind|release|add, v3 income, version; the flags no other tool takes (--calldata, --from, …) too. E.g. ["create","--name","My Token","--symbol","MYT","--logo","/Users/me/avatar.png"], ["bond","status","--token","0x…"]. Local files are read by this server: absolute paths, or --logo-uri <image URL>. Writes only preview, as above. execute / watch / help have their own tools.',
178
+ 'Every other gang command, its flags as separate items (gang_help lists them all): create (V3; create --fair = fair mint; create --fly = Mint Flywheel; launch in one command with --dev-buy / --bond / --buyback / --split / --lp, several of the last three = one combined recipient), mint (--ref <inviter> on a Mint Flywheel token), withdraw, claim, release, fly open-early|launch|invite, quote, list, upload-logo, bond post|topup|raise-hold|extend|status|start|report|settle|refund|burn|tx, buyback status|set|set-payee|apply|bind|release|split|sweep, split status|distribute|release|set-payee|bind, lp status|set|set-payee|apply|bind|release|split|sweep|add, combo status|distribute|release|set-payee|bind|chunk, creator-fee [--token] [--claim [--to]] (GangLaunchpad 2.0: 70% of the curve fee, kept for the creator), v3 income, version; the flags no other tool takes (--calldata, --from, …) too. E.g. ["create","--name","My Token","--symbol","MYT","--logo","/Users/me/avatar.png"], ["bond","status","--token","0x…"]. Local files are read by this server: absolute paths, or --logo-uri <image URL>. Writes only preview, as above. execute / watch / help have their own tools.',
179
179
  { args: { type: 'array', items: { type: 'string' }, minItems: 1 } }, (a) => a.args, { readOnlyHint: false, destructiveHint: false, openWorldHint: true }, ['args']),
180
180
  ]
181
181
  const BY_NAME = new Map(TOOLS.map((t) => [t.name, t]))
package/src/portfolio.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * `gang portfolio`: one wallet's holdings on every gang.fun track (V3, 打新, 铸币飞轮, V2 / Soft / U / S) in one answer, plus its
3
- * trading record and the bonds on the tokens it launched.
3
+ * trading record, the bonds on the tokens it launched and the creator fee they keep for it (GangLaunchpad 2.0).
4
4
  *
5
5
  * Which tokens: gang.fun's index of the wallet's curve and sale trades (/agents/<addr>/positions), which also gives the
6
6
  * cost basis, the average price, the realized PnL and the USD price of each quote. Balance, value and what is claimable
@@ -168,18 +168,21 @@ function bondRow(l, b) {
168
168
  /**
169
169
  * wallet: 0x address. get(path) → JSON or null (discover.js get). statusOf(kind, token, wallet, position) → the
170
170
  * `gang status` result of that kind, or throws (legacy: tokenInfo, or { graduated, myBalanceRaw } for a token no known
171
- * pad has). bondOf(token) → the `gang bond status` view, or throws.
171
+ * pad has). bondOf(token) → the `gang bond status` view, or throws. creatorFeesOf(wallet) → creatorfee.js creatorFeeList
172
+ * (the wallet's 2.0 tokens and their creator fee, read on chain), or throws; optional.
172
173
  */
173
- export async function portfolio({ wallet, get, statusOf, bondOf, concurrency = 6 }) {
174
+ export async function portfolio({ wallet, get, statusOf, bondOf, creatorFeesOf, concurrency = 6 }) {
174
175
  const w = wallet.toLowerCase()
175
- const [profile, positions, launches] = await Promise.all([
176
+ const [profile, positions, launches, fees] = await Promise.all([
176
177
  get(`/agents/${w}`),
177
178
  get(`/agents/${w}/positions`),
178
179
  get(`/agents/${w}/launches?limit=${MAX_LAUNCHES}`),
180
+ creatorFeesOf ? creatorFeesOf(wallet).catch((e) => ({ error: e.message })) : null,
179
181
  ])
180
182
  if (!Array.isArray(positions?.items)) throw new Error('gang API has no positions at /agents/<addr>/positions')
181
183
 
182
184
  const errors = []
185
+ if (fees?.error) errors.push({ creatorFee: fees.error })
183
186
  const rows = await mapLimit(positions.items, concurrency, async (p) => {
184
187
  const kind = KIND[p.track]
185
188
  if (!kind) return null
@@ -228,6 +231,7 @@ export async function portfolio({ wallet, get, statusOf, bondOf, concurrency = 6
228
231
  launches: l.count ?? null, launchesGraduated: l.graduated ?? null,
229
232
  },
230
233
  bonds,
234
+ ...creatorFeeRows(fees),
231
235
  ...(launches?.hasMore && { bondsNote: `bonds were looked up on the newest ${MAX_LAUNCHES} launches only` }),
232
236
  ...(errors.length && { errors }),
233
237
  note: 'Holdings are the tokens gang.fun saw this wallet trade on a curve or sale; balance and value are read on chain now. '
@@ -235,4 +239,20 @@ export async function portfolio({ wallet, get, statusOf, bondOf, concurrency = 6
235
239
  }
236
240
  }
237
241
 
238
- export const _test = { holdingOf, bondRow, withBond, mapLimit }
242
+ /**
243
+ * The 2.0 creator fee waiting for this wallet on the tokens it created: { creatorFees: { tokens, totals } } with the
244
+ * tokens that have some, or nothing when the network has no 2.0 pad (or the read failed: then it is in errors).
245
+ */
246
+ function creatorFeeRows(fees) {
247
+ if (!fees?.scanned?.length) return {}
248
+ const due = fees.tokens.filter((x) => x.claimableRaw !== '0')
249
+ return {
250
+ creatorFees: {
251
+ tokens: due.map((x) => ({ token: x.token, symbol: x.symbol, quote: x.quoteSymbol, claimable: num(x.claimable), padGen: x.padGen, next: `gang creator-fee --token ${x.token} --claim` })),
252
+ totals: fees.totals.filter((x) => num(x.claimable) > 0),
253
+ note: 'GangLaunchpad 2.0 keeps 70% of the 1% curve fee of your V3 tokens for you; gang creator-fee lists every one of them',
254
+ },
255
+ }
256
+ }
257
+
258
+ export const _test = { holdingOf, bondRow, withBond, mapLimit, creatorFeeRows }
package/src/split.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createPublicClient, parseAbi, encodeFunctionData, formatUnits, getAddress, hexToString, isAddress, maxUint256, parseUnits, zeroAddress } from 'viem'
2
- import { padNets, NOT_ON_MAINNET, rpcTransport } from './gangpad.js'
2
+ import { atTokenPad, GANG_GENS, KIND_UNREAD, gangGens, padNets, NOT_ON_MAINNET, rpcTransport } from './gangpad.js'
3
3
  import { walletFor } from './fair.js'
4
4
  import { parseAmount, revertOf as revertIn, step } from './steps.js'
5
5
 
@@ -15,13 +15,12 @@ import { parseAmount, revertOf as revertIn, step } from './steps.js'
15
15
  * Gas: each payee's push needs about 365k gas left before it (PUSH_GAS 300k × 64/63 + a 60k reserve), so a split needs a
16
16
  * gas limit far above the gas it uses. The CLI never sets or lowers one: the wallet / node estimates it (eth_estimateGas
17
17
  * searches for a limit that passes); a lower limit reverts PushStarved, and nothing moves.
18
- * Env: GANG_SPLIT_FACTORY / GANG_TESTNET_SPLIT_FACTORY override the built-in factory addresses.
18
+ * Env: GANG_SPLIT_FACTORY / GANG_TESTNET_SPLIT_FACTORY override the create target's factory (gangpad.js).
19
19
  */
20
20
 
21
- // BSC 56: deployed 2026-10-30, allowed on GangHandlerAdmin by the platform's Safe the same day (docs/MAINNET-SPLIT-MODULE-2026-10-30.md)
22
- export const MAINNET_SPLIT_FACTORY = '0x27e08271E52B2D129c824CD245e69471a8d3067c'
23
- // BSC 97, set 10 (docs/TESTNET-SPLIT-MODULE-2026-10-30.md)
24
- export const TESTNET_SPLIT_FACTORY = '0x5F7dC7502E945A860Cf49cca72dA8bD60Fb1567E'
21
+ // one factory per GangLaunchpad generation (it is bound to one pad): the create target's (GANG_GENS in gangpad.js)
22
+ export const MAINNET_SPLIT_FACTORY = GANG_GENS.mainnet[0].splitFactory
23
+ export const TESTNET_SPLIT_FACTORY = GANG_GENS.testnet[0].splitFactory
25
24
  export const SPLIT_TYPE = 'split-v1'
26
25
  export const MAX_PAYEES = 10
27
26
  const BPS = 10_000
@@ -110,8 +109,7 @@ export async function simulateSplit(client, from, address, abi, functionName, ar
110
109
  }
111
110
 
112
111
  export function splitFactoryAddress(testnet) {
113
- return (testnet ? process.env.GANG_TESTNET_SPLIT_FACTORY || TESTNET_SPLIT_FACTORY
114
- : process.env.GANG_SPLIT_FACTORY || MAINNET_SPLIT_FACTORY) || null
112
+ return gangGens(testnet)[0].splitFactory || null
115
113
  }
116
114
 
117
115
  export const splitNotDeployed = (testnet) =>
@@ -295,6 +293,7 @@ export async function runSplit(sub, { opt, flag, out, fail, summarize }) {
295
293
  } else {
296
294
  token = opt('token')
297
295
  if (!isAddress(token ?? '')) fail('--token must be a V3 token address (0x…), or name the module with --module <addr>', { got: token ?? null })
296
+ if ((await atTokenPad(ctx, token)) === null) return fail(KIND_UNREAD.error, { token: token, retry: KIND_UNREAD.retry }) // else on the pad of the token's generation
298
297
  try {
299
298
  const [creator, quote] = await ctx.read(ctx.pad, PAD_ABI, 'curves', [token])
300
299
  if (creator === zeroAddress) throw new Error('not a curve')