@gangfun/cli 0.38.0 → 0.40.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/v3.js CHANGED
@@ -3,7 +3,7 @@ import { decimalsOf, defaultRefPool, dividendOf, VAULT_ABI, fundingStep as fund,
3
3
  import { API } from './discover.js'
4
4
  import { UA } from './version.js'
5
5
  import { walletFor } from './fair.js'
6
- import { atTokenPad, CREATOR_FEE_ABI, genFields, GRAD_TARGET_ABI, gradTargetBnbOf, gradTiersOf, KIND_UNREAD, MERGED_ERRORS_ABI, MERGED_HINTS, NOT_ON_MAINNET, notThisKind, PAD3_GEN, padNets, rpcTransport, tokenVaultOf, VAULT_GEN, VAULT_NO_BOND, vaultGenOf, vaultModeOf } from './gangpad.js'
6
+ import { atTokenPad, CREATOR_FEE_ABI, creatorFeeShareOf, genFields, GRAD_TARGET_ABI, gradTargetBnbOf, gradTiersOf, KIND_UNREAD, MERGED_ERRORS_ABI, MERGED_HINTS, NOT_ON_MAINNET, notThisKind, PAD3_GEN, padNets, rpcTransport, tokenVaultOf, VAULT_GEN, VAULT_NO_BOND, vaultGenOf, vaultModeOf } from './gangpad.js'
7
7
  import { createNote, curveCreatorFee } from './creatorfee.js'
8
8
  import { checkPromoter, DEFAULT_WINDOW_DAYS, firstBuyWarning, followPromoter, isMissingRead, HINTS as PROMOTE_HINTS, parsePromote, poolFactoryAddress, poolOf, promoteField, promoteLine, PROMOTE_PAD_ABI } from './promote.js'
9
9
  import { poolPayBnb, poolTrade } from './pool.js'
@@ -14,7 +14,9 @@ import { splitOf } from './split.js'
14
14
  import { lpOf } from './lp.js'
15
15
  import { comboOf, decoyWarning } from './combo.js'
16
16
  import { cappedOf, decoyWarning as cappedDecoyWarning } from './capped.js'
17
+ import { floorFactoryAddress, floorOf, floorShown, treasuryShare, typedFloorModule } from './floor.js'
17
18
  import { VANITY_ABI, vanityCreate, vanityDeployer } from './vanity.js'
19
+ import { BASE_LOST, BASE_NO_BOND, BASE_PAD_ABI, baseOf as baseVaultView, basePayoff, baseSupport, baseTaxLine, HINTS as BASE_HINTS, parseBase, scheduleLine } from './base.js'
18
20
 
19
21
  /**
20
22
  * `gang v3 …` — LaunchpadV3 (tax recipient): a token with its own buy / sell tax (1–5% each), a dividend share and a
@@ -161,7 +163,7 @@ const VIRTUAL_TOKEN = 1_066_666_666_666_666_666_666_666_667n
161
163
  const ceilDiv = (a, b) => (a + b - 1n) / b
162
164
 
163
165
  /** Revert name (+ BadTaxConfig reason) of a failed call, or null when it was the RPC. */
164
- const revertOf = (e) => revertIn(e, [PAD_ABI, VANITY_ABI, PROMOTE_PAD_ABI, CREATOR_FEE_ABI, GRAD_TARGET_ABI, TAX_ROUTER_ABI, GANG_ROUTER_ABI, MERGED_ERRORS_ABI], { BadPromoteTerms: PROMOTE_HINTS.BadPromoteTerms, TraderNotOrigin: PROMOTE_HINTS.TraderNotOrigin, ...MERGED_HINTS, ...ROUTER_HINTS, ...HINTS })
166
+ const revertOf = (e) => revertIn(e, [PAD_ABI, VANITY_ABI, BASE_PAD_ABI, PROMOTE_PAD_ABI, CREATOR_FEE_ABI, GRAD_TARGET_ABI, TAX_ROUTER_ABI, GANG_ROUTER_ABI, MERGED_ERRORS_ABI], { BadPromoteTerms: PROMOTE_HINTS.BadPromoteTerms, TraderNotOrigin: PROMOTE_HINTS.TraderNotOrigin, ...MERGED_HINTS, ...ROUTER_HINTS, ...BASE_HINTS, ...HINTS })
165
167
 
166
168
  /** eth_call `data` from `from`: { result } when it passes, { failed } with the revert (or RPC error) otherwise. */
167
169
  async function simulate(ctx, from, to, abi, functionName, args, value = 0n) {
@@ -191,8 +193,12 @@ async function taxContracts(ctx) {
191
193
  return ctx._tax
192
194
  }
193
195
 
194
- /** The call hit a contract without this function: a bare revert (no error data) or an empty return. */
196
+ /**
197
+ * The call hit a contract without this function: a bare revert (no error data) or an empty return. A node's internal
198
+ * error (-32603) also comes back from viem as a revert: it is the node's, never "no such function" (as gangpad.js).
199
+ */
195
200
  function noSuchFunction(e) {
201
+ if (e?.walk?.((x) => x?.code === -32603)) return false
196
202
  if (e?.walk?.((x) => x?.name === 'ContractFunctionZeroDataError')) return true
197
203
  const r = e?.walk?.((x) => x?.name === 'ContractFunctionRevertedError')
198
204
  return !!r && !r.data && (!r.raw || r.raw === '0x')
@@ -303,7 +309,7 @@ const USAGE = 'usage: gang v3 <list|info|status|create|buy|sell|claim|income|rel
303
309
  * Entry for `gang v3 <sub>`. io: { opt, flag, out, fail, summarize, resolveLogo, checkMeta, resolveMeta, notes } from
304
310
  * index.js (summarize = summarizePreview, so previews look like every other command's; notes = padNotes: --note / --follow).
305
311
  */
306
- export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo, checkMeta, resolveMeta, notes, launchPoolModule = null }) {
312
+ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo, checkMeta, resolveMeta, notes, launchPoolModule = null, launchFloor = null }) {
307
313
  if (!SUBS.includes(sub)) return fail(USAGE, { got: sub ?? null })
308
314
  const testnet = flag('testnet')
309
315
  const net = testnet ? ' --testnet' : ''
@@ -374,6 +380,16 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
374
380
  const capped = c.recipient && !c.recipientIsCreator && !buyback && !split && !lp && !combo
375
381
  ? await cappedOf(ctx.read, c.recipient, { wbnb: ctx.wbnb, pad: ctx.pad, extraAssets: [c.quote], ref: comboRef }) : null
376
382
  const cappedWarning = capped ? cappedDecoyWarning(capped, token, c.quote, comboRef) : null
383
+ // or the dev's floor module (floor-v1): the tax kept as a treasury holders can redeem. Only one GangFloorModuleFactory
384
+ // made, cloned for this very token, is this token's floor: anything else is shown with a warning, never as one
385
+ const floorRaw = c.recipient && !c.recipientIsCreator && !buyback && !split && !lp && !combo && !capped
386
+ ? await floorOf(ctx.read, c.recipient, { wbnb: ctx.wbnb, pad: ctx.pad, factory: ctx.floorFactory, extraAssets: [c.quote], ref: comboRef, getCode: (a) => ctx.client.getCode({ address: a }) }) : null
387
+ // not this token's floor (not made by the factory, unchecked, or cloned for another token): only the warning, no numbers
388
+ const floorSeen = floorRaw ? floorShown(floorRaw, token) : null
389
+ const floor = floorRaw && (floorSeen !== floorRaw ? floorSeen : {
390
+ ...floorRaw,
391
+ treasuryGets: treasuryShare({ buyTaxPct: c.buyTaxPct, sellTaxPct: c.sellTaxPct, platformTaxPct: fees.platformTaxPct, dividendPct: c.dividendPct, payBps: floorRaw.cap?.reached ? 0 : floorRaw.payBps }),
392
+ })
377
393
  const lpWarn = lp && lp.token && lp.token.toLowerCase() !== token.toLowerCase()
378
394
  ? { warning: `this token pays its tax to the LP splitter, but it is bound to another token (${lp.token}): the liquidity goes to that token's pair` } : null
379
395
  const splitWarn = split && split.token && split.token.toLowerCase() !== token.toLowerCase()
@@ -382,16 +398,20 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
382
398
  const gen = await curveCreatorFee(ctx, token, c, net)
383
399
  const vault = await vaultView(ctx, token, c, net)
384
400
  const promote = await promoteField(ctx, token, { recipient: c.recipient, dividendPct: c.dividendPct, testnet })
401
+ // 3.0: the opening base (gang create --base): the vault, its size, period and progress
402
+ const baseSeen = await baseVaultView(ctx, token).catch((e) => ({ raw: null, error: `could not read the token's base vault (${e.shortMessage || e.message.split('\n')[0]})`, retry: `gang base status --token ${token}${net}` }))
403
+ const { raw: _baseRaw, ...baseField } = baseSeen ?? {}
385
404
  // 3.0: the rule set the token was created under (fixed for good; an upgrade adds rules for new tokens only)
386
405
  const tokenVersion = ctx.gen === PAD3_GEN ? await ctx.read(ctx.pad, PAD_ABI, 'tokenVersionOf', [token]).then(Number).catch(() => null) : null
387
406
  const nonWbnb = c.quote.toLowerCase() !== String(ctx.wbnb).toLowerCase()
388
407
  const graduationNote = c.graduationTargetBnb != null && !c.graduated
389
408
  ? gradLine(c.graduationTargetBnb, nonWbnb ? `${c.graduationAt} ${c.quoteSymbol || 'of the quote'}` : null) : null
390
409
  return out({
391
- success: true, chainId: Number(ctx.chainId), ...fees, ...pub, ...gen, ...(promote && { promote }), ...(tokenVersion != null && { tokenVersion }), ...(vault && { vault }), ...(graduationNote && { graduationNote }), taxNote, ...(swapBack && { swapBack }), ...(buyback && { buyback }),
410
+ success: true, chainId: Number(ctx.chainId), ...fees, ...pub, ...gen, ...(promote && { promote }), ...(baseSeen && { base: { ...baseField, ...(!baseField.error && { more: `gang base status --token ${token}${net}` }) } }), ...(tokenVersion != null && { tokenVersion }), ...(vault && { vault }), ...(graduationNote && { graduationNote }), taxNote, ...(swapBack && { swapBack }), ...(buyback && { buyback }),
392
411
  ...(split && { split: { ...split, ...splitWarn } }), ...(lp && { lp: { ...lp, ...lpWarn } }),
393
412
  ...(combo && { combo: { ...combo, ...(comboWarning && { warning: comboWarning }) } }),
394
413
  ...(capped && { capped: { ...capped, ...(cappedWarning && { warning: cappedWarning }) } }),
414
+ ...(floor && { floor }),
395
415
  })
396
416
  }
397
417
 
@@ -479,6 +499,22 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
479
499
  fail(error, extra)
480
500
  }
481
501
  if (promote && vault) fail('--promote and --vault can\'t go together: a token is made with one or the other')
502
+ // --base: the opening base (createWithBase, 3.0 once upgraded): 5% / 10% of the supply bought for the token's base
503
+ // vault in the create, paid in BNB, released to the creator after graduation. WBNB quote, no dividend, alone
504
+ if (flag('base-vest') && !flag('base')) fail('--base-vest goes with --base <5|10>')
505
+ const base = flag('base') ? parseBase(opt('base'), opt('base-vest')) : null
506
+ if (base?.error) {
507
+ const { error, ...extra } = base
508
+ fail(error, extra)
509
+ }
510
+ if (base) {
511
+ if (vault) fail('--base and --vault can\'t go together: a token with an opening base is not bound to a vault')
512
+ if (promote) fail('--base and --promote can\'t go together (not offered with the opening base)')
513
+ if (launchFloor || launchPoolModule) fail('--base goes on a plain create only: no chained launch')
514
+ if (flag('quote') && String(opt('quote')).toLowerCase() !== String(ctx.wbnb).toLowerCase()) fail('--base is for WBNB-quoted tokens only: leave --quote out', { got: opt('quote') })
515
+ if (flag('ref-pool')) fail('--base is for WBNB-quoted tokens only: leave --ref-pool out')
516
+ if (flag('dividend') && !/^0+(\.0+)?$/.test(opt('dividend') ?? '')) fail('--base can\'t go with a dividend: a base token takes --dividend 0 (the vault would take a share of the holders\' dividend)', { got: opt('dividend') })
517
+ }
482
518
  if (grad !== null && !(grad > 0)) fail('--grad must be the graduation target in BNB raised: 6, 9, 12 or 15', { got: opt('grad') ?? null })
483
519
  const buyTax = taxed ? taxOf('buy-tax') : 0
484
520
  const sellTax = taxed ? taxOf('sell-tax') : 0
@@ -529,12 +565,33 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
529
565
  fail(`--grad: this GangLaunchpad${ctx.gen ? ` (${ctx.gen})` : ''} has no graduation target to pick; every curve graduates at ${bnbOf(await ctx.read(ctx.pad, GRAD_TARGET_ABI, 'TARGET_GRAD_BNB'))} BNB raised: leave --grad out`)
530
566
  }
531
567
  if (grad !== null && !tiers.includes(grad)) fail(`--grad must be one of ${tiers.join(' / ')} (BNB raised)`, { got: opt('grad') })
568
+ // --base: asked of the pad before anything else is checked (mainnet before its upgrade has no opening base)
569
+ if (base) {
570
+ const support = await baseSupport(ctx)
571
+ if (support.unread) fail('could not check the pad for the opening base (RPC error)', { pad: ctx.pad, detail: support.unread, retry: 'same command again' })
572
+ if (!support.open) fail(`${support.why}: drop --base${testnet ? '' : ' (it is on the BSC testnet: --testnet)'}`, { pad: ctx.pad })
573
+ }
532
574
  // the recipient may be the creator itself: checkTaxConfigFor knows who creates (a pad without it: checkTaxConfig)
533
575
  const [ok, reason] = await ctx.read(ctx.pad, PAD_ABI, 'checkTaxConfigFor', [me, tax]).catch((e) => {
534
576
  if (!noSuchFunction(e)) throw e
535
577
  return ctx.read(ctx.pad, PAD_ABI, 'checkTaxConfig', [tax])
536
578
  })
537
579
  if (!ok) fail(`tax setting refused: ${reason}`, { hint: HINTS.BadTaxConfig, tax: { buyTax, sellTax, dividend, recipient } })
580
+ // a floor module serves the one token address it was cloned for: a token that names one by hand lands elsewhere, and
581
+ // its tax goes into a module that can never bind it — for good. Only the launch that cloned it for this very token
582
+ // names it. Checked on the chain's own records, at one block, and nothing is built on an answer that is not sure
583
+ if (recipient !== zeroAddress && !launchFloor && recipient.toLowerCase() !== String(me).toLowerCase()) {
584
+ // the floor factory of the create target's generation, even when --vault moved ctx to the vault pad (whose own
585
+ // generation has none: its handler lists no floor module, so nothing matches there)
586
+ const typed = await typedFloorModule({ client: ctx.client, pad: ctx.pad }, recipient, floorFactoryAddress(testnet))
587
+ if (typed.floor) {
588
+ fail('--recipient is a floor module: a token can\'t name one by hand. A floor module serves only the token address it was cloned for, so this token\'s tax would go into a module that can never bind it, and the token would have no floor. Leave --recipient out and add --floor: the launch clones a module for this token', { recipient, seenBy: typed.by })
589
+ }
590
+ // the pad just took this recipient, so it is listed: a node that says otherwise is behind (or the two answers are
591
+ // of different blocks). Not sure → nothing is built
592
+ if (typed.unlisted) fail('could not check --recipient: the pad accepts it, but the tax handler did not show it as listed at the block it was checked on (a node may be behind)', { recipient, retry: 'same command again' })
593
+ if (typed.unread) fail('could not check --recipient (RPC error)', { detail: typed.unread, retry: 'same command again' })
594
+ }
538
595
  if (!(await ctx.read(ctx.pad, PAD_ABI, 'isAgent', [me]))) fail('this wallet holds no Agent ID; V3 create is Agent-only', { wallet: me })
539
596
  // the target: --grad (2.0, createWithGradTarget) or the pad's default (create: 9 BNB on 2.0, 15 on 1.0)
540
597
  const targetBnb = grad ?? bnbOf(await ctx.read(ctx.pad, GRAD_TARGET_ABI, 'TARGET_GRAD_BNB'))
@@ -553,24 +610,56 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
553
610
  fail(`GangLaunchpad ${ctx.gen ?? ctx.pad} has no promoter share yet: drop --promote`, { pad: ctx.pad })
554
611
  }
555
612
  }
556
- // createWithVault and createWithPromote always take the target (the pad's default when --grad is left out)
557
- const fn = vault ? 'createWithVault' : promote ? 'createWithPromote' : grad !== null ? 'createWithGradTarget' : 'create'
558
- const argsOf = (logoURI, metaURI) => [name, symbol, logoURI, metaURI, quote, refPool, tax,
559
- ...(vault ? [parseUnits(String(targetBnb), 18), vault] : promote ? [parseUnits(String(targetBnb), 18), promote.shareBps, promote.window] : grad !== null ? [parseUnits(String(grad), 18)] : [])]
560
- const createData = (logoURI, metaURI) => encodeFunctionData({ abi: PAD_ABI, functionName: fn, args: argsOf(logoURI, metaURI) })
613
+ // --base: the pad must have it (mainnet before its upgrade has not), and it names the exact BNB the create takes
614
+ let baseCost = 0n
615
+ if (base) {
616
+ try { baseCost = await ctx.read(ctx.pad, BASE_PAD_ABI, 'previewBaseCost', [parseUnits(String(targetBnb), 18), base.baseBps]) } catch (e) {
617
+ return fail('could not read the base cost from the pad (previewBaseCost)', revertOf(e) || { detail: e.shortMessage || e.message.split('\n')[0], retry: 'same command again' })
618
+ }
619
+ const native = await ctx.client.getBalance({ address: me })
620
+ if (native < baseCost) {
621
+ fail(`not enough BNB for the base: the create pays exactly ${formatUnits(baseCost, 18)} BNB, plus gas`, { wallet: me, haveBnb: formatUnits(native, 18), needBnb: formatUnits(baseCost, 18) })
622
+ }
623
+ }
624
+ // createWithVault, createWithPromote and createWithBase always take the target (the pad's default when --grad is left out)
625
+ const fn = base ? 'createWithBase' : vault ? 'createWithVault' : promote ? 'createWithPromote' : grad !== null ? 'createWithGradTarget' : 'create'
626
+ const argsOf = (logoURI, metaURI) => (base
627
+ ? [name, symbol, logoURI, metaURI, tax, parseUnits(String(targetBnb), 18), { baseBps: base.baseBps, vestDays: base.vestDays }]
628
+ : [name, symbol, logoURI, metaURI, quote, refPool, tax,
629
+ ...(vault ? [parseUnits(String(targetBnb), 18), vault] : promote ? [parseUnits(String(targetBnb), 18), promote.shareBps, promote.window] : grad !== null ? [parseUnits(String(grad), 18)] : [])])
630
+ const createAbi = base ? BASE_PAD_ABI : PAD_ABI
631
+ const createData = (logoURI, metaURI) => encodeFunctionData({ abi: createAbi, functionName: fn, args: argsOf(logoURI, metaURI) })
561
632
  const vanity = await vanityDeployer(ctx)
562
633
  const handler = vanity && taxed ? (await taxContracts(ctx)).handler : zeroAddress
563
- const prepareCreate = (logoURI, metaURI) => vanityCreate(ctx, me, createData(logoURI, metaURI), {
564
- args: [name, symbol, metaURI, handler, tax.buyTaxBps, tax.sellTaxBps, false],
634
+ const prepareCreate = (logoURI, metaURI, fixed = null) => vanityCreate(ctx, me, createData(logoURI, metaURI), {
635
+ args: [name, symbol, metaURI, handler, tax.buyTaxBps, tax.sellTaxBps, false], fixed,
565
636
  })
566
637
  // the logo / metadata strings never decide a revert: dry-run without them, so a create that would fail uploads nothing
567
638
  const probe = await prepareCreate('', '')
568
- const dry = await simulate(ctx, me, ctx.pad, probe.salt ? VANITY_ABI : PAD_ABI,
569
- probe.salt ? 'createWithSalt' : fn, probe.salt ? [probe.salt, createData('', '')] : argsOf('', ''))
639
+ // createWithSalt (abcd) or the entry itself; a base create sends exactly its cost either way
640
+ const dry = await simulate(ctx, me, ctx.pad, probe.salt ? VANITY_ABI : createAbi,
641
+ probe.salt ? 'createWithSalt' : fn, probe.salt ? [probe.salt, createData('', '')] : argsOf('', ''), baseCost)
570
642
  if (dry.failed) return out({ success: false, step: 'create', ...dry.failed })
571
- const logo = await resolveLogo()
572
- const meta = await resolveMeta({ name, symbol, logoURI: logo.logoURI })
573
- const launch = await prepareCreate(logo.logoURI, meta.metaURI)
643
+ // a floor launch: the module was cloned for one token address, so the create reuses the metadata and the salt that
644
+ // give it, and is refused when anything that decides the address (name, symbol, tax rates) changed since
645
+ const logo = launchFloor ? { logoURI: launchFloor.logoURI, uploaded: !!launchFloor.uploaded } : await resolveLogo()
646
+ const meta = launchFloor ? { metaURI: launchFloor.metaURI, metadata: launchFloor.metadata } : await resolveMeta({ name, symbol, logoURI: logo.logoURI })
647
+ const launch = await prepareCreate(logo.logoURI, meta.metaURI, launchFloor ? { salt: launchFloor.salt, token: launchFloor.token } : null)
648
+ if (launch.mismatch) {
649
+ return fail(launch.mismatch.got
650
+ ? 'this create would put the token at another address than the one its floor module was cloned for: the name, the symbol or a tax rate changed since the module was cloned. Run the launch again with what it began with, or add --restart for a new module and token'
651
+ : 'the pad\'s token deployer could not be read: a floor launch creates its token at the address its module was cloned for, so nothing is built without it', {
652
+ floorToken: launch.mismatch.expected, ...(launch.mismatch.got && { wouldBe: launch.mismatch.got }), retry: launch.mismatch.got ? undefined : 'same command again',
653
+ })
654
+ }
655
+ if (launchFloor) {
656
+ // the last check before the tx: the pad itself says where this exact call puts the token
657
+ const sure = await simulate(ctx, me, ctx.pad, VANITY_ABI, 'createWithSalt', [launch.salt, createData(logo.logoURI, meta.metaURI)])
658
+ if (sure.failed) return out({ success: false, step: 'create', ...sure.failed })
659
+ if (String(sure.result).toLowerCase() !== String(launchFloor.token).toLowerCase()) {
660
+ return fail('the pad would create this token at another address than the one its floor module was cloned for: nothing is built. Add --restart for a new module and token', { floorToken: launchFloor.token, padSays: sure.result })
661
+ }
662
+ }
574
663
  let label = null
575
664
  const selfRecipient = recipient !== zeroAddress && recipient.toLowerCase() === String(me).toLowerCase()
576
665
  if (recipient !== zeroAddress && !selfRecipient) {
@@ -581,7 +670,18 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
581
670
  const baseCreatorFee = await createNote(ctx, net)
582
671
  const creatorFee = baseCreatorFee && promote ? `${baseCreatorFee} Less the ${promote.shareBps / 100}% of it you give promoters on their bound wallets' trades.` : baseCreatorFee
583
672
  const poolModule = promote && !!launchPoolModule
584
- return out(notes.step(ctx, { from: me, to: ctx.pad, data: launch.data }, {
673
+ const baseView = base && {
674
+ sizePct: base.baseBps / 100, vestDays: base.vestDays, costBnb: formatUnits(baseCost, 18), payWithThisTx: `${formatUnits(baseCost, 18)} BNB (the tx's value: exactly what the pad's previewBaseCost asks for a ${base.baseBps / 100}% base at the ${targetBnb} BNB target)`,
675
+ what: `the pad buys ${base.baseBps / 100}% of the supply on the curve as the token's very first trade, for this token's own base vault (GangBaseVault, base-v1). The vault never trades and approves no one: the base cannot move before graduation`,
676
+ schedule: scheduleLine(base.vestDays),
677
+ payoff: basePayoff({ gradBnb: targetBnb, baseBps: base.baseBps, vestDays: base.vestDays, cost: baseCost, creatorFeeShareBps: (await creatorFeeShareOf(ctx).catch(() => null)) ?? undefined }),
678
+ ...(taxed && { tax: baseTaxLine({ taxed, sellTaxPct: sellTax, platformTaxPct: fees.platformTaxPct, selfRecipient }) }),
679
+ neverGraduates: BASE_LOST,
680
+ bond: BASE_NO_BOND,
681
+ wallet: 'the release always goes to the wallet that creates (this one), for good: if it is lost, the base goes there anyway. That wallet can still buy up to 1% on the curve on its own',
682
+ warning: `PERMANENT: ${formatUnits(baseCost, 18)} BNB is spent in this create; if the token never graduates, it and the base are locked for good. The size, the period and the recipient never change`,
683
+ }
684
+ return out(notes.step(ctx, { from: me, to: ctx.pad, data: launch.data, ...(base && { value: baseCost }) }, {
585
685
  step: 'create', chainId: Number(ctx.chainId), name, symbol, logoURI: logo.logoURI, ...(logo.uploaded && { uploaded: true }),
586
686
  metaURI: meta.metaURI, metadata: meta.metadata,
587
687
  quote: (await symbolOf(ctx, quote)) || quote, graduationTargetBnb: targetBnb, graduationAt: await units(ctx, quote, gradAmt),
@@ -590,6 +690,7 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
590
690
  buyTaxPct: buyTax, sellTaxPct: sellTax, dividendPct: dividend,
591
691
  recipient: recipient === zeroAddress ? null : recipient, recipientLabel: selfRecipient ? 'you (the creator)' : label, tokenIfNext: launch.token ?? dry.result,
592
692
  ...(launch.token && { addressSuffix: 'abcd' }),
693
+ ...(launchFloor && { floorToken: launchFloor.token, metadataFixed: 'the metadata is the one fixed when the floor module was cloned (its URL is part of the token\'s address); --logo / --description / --website / --twitter given now are not read again' }),
593
694
  split: taxed
594
695
  ? `of each ${buyTax}% buy / ${sellTax}% sell tax in the PancakeSwap pool (after graduation; the curve charges no tax): ${fees.platformTaxPct}% of volume to the platform, then ${dividend}% of the rest to holders, ${rest}% to the recipient in the quote`
595
696
  + (dividend > 0 ? '; if no holder has 10,000+ tokens when a tax is paid, the holders\' part goes to the recipient too' : '')
@@ -603,6 +704,7 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
603
704
  note: promoteLine({ shareBps: promote.shareBps, windowDays: promote.windowDays, pool: poolModule, taxed, dividendPct: dividend }),
604
705
  },
605
706
  }),
707
+ ...(base && { base: baseView }),
606
708
  ...(vault && {
607
709
  padGen: ctx.gen, pad: ctx.pad, vault,
608
710
  vaultNote: 'the token is bound to this vault for good. Until graduation the token moves only through the pad: the vault locks a holder\'s tokens (counted in that holder\'s 1% cap) and releases them through the pad, for the holder that sends the tx and holds an Agent ID; after graduation it is a plain token. This create uses up the wallet\'s naming for the vault: one token per naming. A vault-bound token takes no GangBond (gang bond post refuses it): a lock moves tokens out of the creator\'s wallet, which would forfeit a bond',
package/src/vanity.js CHANGED
@@ -4,12 +4,26 @@ import { PAD3_GEN } from './gangpad.js'
4
4
 
5
5
  export const VANITY_ABI = parseAbi([
6
6
  'function vanityDeployer() view returns (address)',
7
- 'function createWithSalt(bytes32 salt, bytes data) returns (address token)',
7
+ // payable since the opening base (createWithBase takes BNB through it); every other entry it reaches takes none
8
+ 'function createWithSalt(bytes32 salt, bytes data) payable returns (address token)',
8
9
  'function tokenInitCodeHash(string name, string symbol, string uri, address handler, uint16 buyTaxBps, uint16 sellTaxBps, bool reclaimable) view returns (bytes32)',
9
10
  'function mintInitCodeHash(string name, string symbol, string uri, address handler, uint16 buyTaxBps, uint16 sellTaxBps, uint256 startSupply, uint256 maxSupply) view returns (bytes32)',
10
11
  'error InvalidSuffix()', 'error VanityContextRequired()', 'error BadVanityCall()',
11
12
  ])
12
13
 
14
+ /** The CREATE2 address `creator`'s user `salt` gives for `initCodeHash` (the pad binds the salt to the creator). */
15
+ export function vanityAddress(deployer, creator, initCodeHash, salt) {
16
+ const bound = new Uint8Array(64)
17
+ bound.set(hexToBytes(creator), 12)
18
+ bound.set(hexToBytes(salt), 32)
19
+ const preimage = new Uint8Array(85)
20
+ preimage[0] = 0xff
21
+ preimage.set(hexToBytes(deployer), 1)
22
+ preimage.set(hexToBytes(keccak256(bound)), 21)
23
+ preimage.set(hexToBytes(initCodeHash), 53)
24
+ return `0x${keccak256(preimage).slice(-40)}`
25
+ }
26
+
13
27
  /** No RPC calls per attempt. Only the chosen candidate is checked for existing code. */
14
28
  export async function mineSalt(deployer, creator, initCodeHash, start = BigInt(toHex(randomBytes(32)))) {
15
29
  const bound = new Uint8Array(64)
@@ -43,15 +57,42 @@ export async function vanityDeployer(ctx) {
43
57
  return ctx._vanityDeployer
44
58
  }
45
59
 
46
- export async function vanityCreate(ctx, creator, data, { mint = false, args }) {
60
+ /**
61
+ * A salt whose address ends in abcd and has no code yet, for a token with these constructor `args`
62
+ * (tokenInitCodeHash's / mintInitCodeHash's): the address the token will have, known before it exists. null on a pad
63
+ * without the deployer.
64
+ */
65
+ export async function mineToken(ctx, creator, { mint = false, args }) {
47
66
  const deployer = await vanityDeployer(ctx)
48
- if (!deployer) return { data }
67
+ if (!deployer) return null
49
68
  const initCodeHash = await ctx.read(deployer, VANITY_ABI, mint ? 'mintInitCodeHash' : 'tokenInitCodeHash', args)
50
69
  let found
51
70
  do { found = await mineSalt(deployer, creator, initCodeHash) }
52
71
  while (await ctx.client.getBytecode({ address: found.token }).then((code) => code && code !== '0x'))
72
+ return { ...found, deployer, initCodeHash }
73
+ }
74
+
75
+ /**
76
+ * The create through the deployer. `fixed` ({ salt, token }): a launch that already named the token's address (a floor
77
+ * module is cloned for it) — the same salt is used, and when these `args` no longer lead to that address the result is
78
+ * { mismatch: { expected, got } } instead of a tx: the token would land elsewhere.
79
+ */
80
+ export async function vanityCreate(ctx, creator, data, { mint = false, args, fixed = null }) {
81
+ if (fixed) {
82
+ const deployer = await vanityDeployer(ctx)
83
+ if (!deployer) return { mismatch: { expected: fixed.token, got: null } }
84
+ const initCodeHash = await ctx.read(deployer, VANITY_ABI, mint ? 'mintInitCodeHash' : 'tokenInitCodeHash', args)
85
+ const got = vanityAddress(deployer, creator, initCodeHash, fixed.salt)
86
+ if (got.toLowerCase() !== String(fixed.token).toLowerCase()) return { mismatch: { expected: fixed.token, got } }
87
+ return {
88
+ salt: fixed.salt, token: got,
89
+ data: encodeFunctionData({ abi: VANITY_ABI, functionName: 'createWithSalt', args: [fixed.salt, data] }),
90
+ }
91
+ }
92
+ const found = await mineToken(ctx, creator, { mint, args })
93
+ if (!found) return { data }
53
94
  return {
54
- ...found,
95
+ salt: found.salt, token: found.token,
55
96
  data: encodeFunctionData({ abi: VANITY_ABI, functionName: 'createWithSalt', args: [found.salt, data] }),
56
97
  }
57
98
  }