@gangfun/cli 0.33.0 → 0.35.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/DEVELOPERS.md +14 -1
- package/DEVELOPERS.zh-CN.md +14 -1
- package/README.md +11 -2
- package/README.zh-CN.md +10 -1
- package/package.json +1 -1
- package/src/capabilities.js +15 -0
- package/src/capped.js +717 -0
- package/src/combo.js +1 -1
- package/src/creatorfee.js +31 -11
- package/src/flags.js +15 -1
- package/src/gangpad.js +25 -8
- package/src/index.js +140 -19
- package/src/launch.js +279 -23
- package/src/mcp.js +8 -5
- package/src/portfolio.js +1 -1
- package/src/promote.js +669 -0
- package/src/telemetry.js +1 -1
- package/src/v3.js +82 -10
package/src/telemetry.js
CHANGED
|
@@ -31,7 +31,7 @@ const NAME = /^[a-z0-9-]{1,24}$/
|
|
|
31
31
|
const CODE = /^[A-Za-z0-9_.:-]{1,48}$/
|
|
32
32
|
const MAX_FLAGS = 16
|
|
33
33
|
// commands whose second word is a subcommand (gang fly mint, gang bond create, …)
|
|
34
|
-
const WITH_SUB = new Set(['fair', 'v3', 'fly', 'bond', 'buyback', 'split', 'lp', 'combo', 'creator-fee'])
|
|
34
|
+
const WITH_SUB = new Set(['fair', 'v3', 'fly', 'bond', 'buyback', 'split', 'lp', 'combo', 'capped', 'creator-fee'])
|
|
35
35
|
|
|
36
36
|
export const enabled = () => process.env.GANG_TELEMETRY !== '0' && process.env.DO_NOT_TRACK !== '1'
|
|
37
37
|
|
package/src/v3.js
CHANGED
|
@@ -5,12 +5,14 @@ import { UA } from './version.js'
|
|
|
5
5
|
import { walletFor } from './fair.js'
|
|
6
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'
|
|
7
7
|
import { createNote, curveCreatorFee } from './creatorfee.js'
|
|
8
|
+
import { checkPromoter, DEFAULT_WINDOW_DAYS, firstBuyWarning, isMissingRead, HINTS as PROMOTE_HINTS, parsePromote, poolFactoryAddress, poolOf, promoteField, promoteLine, PROMOTE_PAD_ABI } from './promote.js'
|
|
8
9
|
import { poolPayBnb, poolTrade } from './pool.js'
|
|
9
10
|
import { bondGuard } from './bond.js'
|
|
10
11
|
import { splitterOf } from './buyback.js'
|
|
11
12
|
import { splitOf } from './split.js'
|
|
12
13
|
import { lpOf } from './lp.js'
|
|
13
14
|
import { comboOf, decoyWarning } from './combo.js'
|
|
15
|
+
import { cappedOf, decoyWarning as cappedDecoyWarning } from './capped.js'
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
18
|
* `gang v3 …` — LaunchpadV3 (tax recipient): a token with its own buy / sell tax (1–5% each), a dividend share and a
|
|
@@ -27,6 +29,7 @@ const PAD_ABI = parseAbi([
|
|
|
27
29
|
`function createWithGradTarget(string name, string symbol, string logoURI, string metaURI, address quote, address refPool, ${TAX} tax, uint256 gradBnb) returns (address)`,
|
|
28
30
|
// 2.0 金库版 (GangVaultLaunchpad): its only create, binding the token to a listed vault for good; 3.0 has the same once
|
|
29
31
|
// an upgrade added its vault mode (vaultModeOf), beside its other creates
|
|
32
|
+
`function createWithPromote(string name, string symbol, string logoURI, string metaURI, address quote, address refPool, ${TAX} tax, uint256 gradBnb, uint16 shareBps, uint32 window) returns (address)`,
|
|
30
33
|
`function createWithVault(string name, string symbol, string logoURI, string metaURI, address quote, address refPool, ${TAX} tax, uint256 gradBnb, address vault) returns (address)`,
|
|
31
34
|
'function isVault(address vault) view returns (bool)',
|
|
32
35
|
'function vaultOf(address token) view returns (address)',
|
|
@@ -156,7 +159,7 @@ const VIRTUAL_TOKEN = 1_066_666_666_666_666_666_666_666_667n
|
|
|
156
159
|
const ceilDiv = (a, b) => (a + b - 1n) / b
|
|
157
160
|
|
|
158
161
|
/** Revert name (+ BadTaxConfig reason) of a failed call, or null when it was the RPC. */
|
|
159
|
-
const revertOf = (e) => revertIn(e, [PAD_ABI, CREATOR_FEE_ABI, GRAD_TARGET_ABI, TAX_ROUTER_ABI, GANG_ROUTER_ABI, MERGED_ERRORS_ABI], { ...MERGED_HINTS, ...ROUTER_HINTS, ...HINTS })
|
|
162
|
+
const revertOf = (e) => revertIn(e, [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, ...HINTS })
|
|
160
163
|
|
|
161
164
|
/** eth_call `data` from `from`: { result } when it passes, { failed } with the revert (or RPC error) otherwise. */
|
|
162
165
|
async function simulate(ctx, from, to, abi, functionName, args, value = 0n) {
|
|
@@ -298,7 +301,7 @@ const USAGE = 'usage: gang v3 <list|info|status|create|buy|sell|claim|income|rel
|
|
|
298
301
|
* Entry for `gang v3 <sub>`. io: { opt, flag, out, fail, summarize, resolveLogo, checkMeta, resolveMeta, notes } from
|
|
299
302
|
* index.js (summarize = summarizePreview, so previews look like every other command's; notes = padNotes: --note / --follow).
|
|
300
303
|
*/
|
|
301
|
-
export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo, checkMeta, resolveMeta, notes }) {
|
|
304
|
+
export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo, checkMeta, resolveMeta, notes, launchPoolModule = null }) {
|
|
302
305
|
if (!SUBS.includes(sub)) return fail(USAGE, { got: sub ?? null })
|
|
303
306
|
const testnet = flag('testnet')
|
|
304
307
|
const net = testnet ? ' --testnet' : ''
|
|
@@ -365,6 +368,10 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
|
|
|
365
368
|
const combo = c.recipient && !c.recipientIsCreator && !buyback && !split && !lp
|
|
366
369
|
? await comboOf(ctx.read, c.recipient, { wbnb: ctx.wbnb, pad: ctx.pad, extraAssets: [c.quote], ref: comboRef }) : null
|
|
367
370
|
const comboWarning = combo ? decoyWarning(combo, token, c.quote, comboRef) : null
|
|
371
|
+
// or the dev's capped recipient (capped-v1): payees up to a fixed cap, then buy-back + LP; the cap's progress
|
|
372
|
+
const capped = c.recipient && !c.recipientIsCreator && !buyback && !split && !lp && !combo
|
|
373
|
+
? await cappedOf(ctx.read, c.recipient, { wbnb: ctx.wbnb, pad: ctx.pad, extraAssets: [c.quote], ref: comboRef }) : null
|
|
374
|
+
const cappedWarning = capped ? cappedDecoyWarning(capped, token, c.quote, comboRef) : null
|
|
368
375
|
const lpWarn = lp && lp.token && lp.token.toLowerCase() !== token.toLowerCase()
|
|
369
376
|
? { 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
|
|
370
377
|
const splitWarn = split && split.token && split.token.toLowerCase() !== token.toLowerCase()
|
|
@@ -372,15 +379,17 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
|
|
|
372
379
|
// 2.0: the creator's part of the curve fee, waiting on the pad
|
|
373
380
|
const gen = await curveCreatorFee(ctx, token, c, net)
|
|
374
381
|
const vault = await vaultView(ctx, token, c, net)
|
|
382
|
+
const promote = await promoteField(ctx, token, { recipient: c.recipient, dividendPct: c.dividendPct, testnet })
|
|
375
383
|
// 3.0: the rule set the token was created under (fixed for good; an upgrade adds rules for new tokens only)
|
|
376
384
|
const tokenVersion = ctx.gen === PAD3_GEN ? await ctx.read(ctx.pad, PAD_ABI, 'tokenVersionOf', [token]).then(Number).catch(() => null) : null
|
|
377
385
|
const nonWbnb = c.quote.toLowerCase() !== String(ctx.wbnb).toLowerCase()
|
|
378
386
|
const graduationNote = c.graduationTargetBnb != null && !c.graduated
|
|
379
387
|
? gradLine(c.graduationTargetBnb, nonWbnb ? `${c.graduationAt} ${c.quoteSymbol || 'of the quote'}` : null) : null
|
|
380
388
|
return out({
|
|
381
|
-
success: true, chainId: Number(ctx.chainId), ...fees, ...pub, ...gen, ...(tokenVersion != null && { tokenVersion }), ...(vault && { vault }), ...(graduationNote && { graduationNote }), taxNote, ...(swapBack && { swapBack }), ...(buyback && { buyback }),
|
|
389
|
+
success: true, chainId: Number(ctx.chainId), ...fees, ...pub, ...gen, ...(promote && { promote }), ...(tokenVersion != null && { tokenVersion }), ...(vault && { vault }), ...(graduationNote && { graduationNote }), taxNote, ...(swapBack && { swapBack }), ...(buyback && { buyback }),
|
|
382
390
|
...(split && { split: { ...split, ...splitWarn } }), ...(lp && { lp: { ...lp, ...lpWarn } }),
|
|
383
391
|
...(combo && { combo: { ...combo, ...(comboWarning && { warning: comboWarning }) } }),
|
|
392
|
+
...(capped && { capped: { ...capped, ...(cappedWarning && { warning: cappedWarning }) } }),
|
|
384
393
|
})
|
|
385
394
|
}
|
|
386
395
|
|
|
@@ -396,11 +405,12 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
|
|
|
396
405
|
const q = c.graduated && c.pair && bal > 0n ? await poolSellQuote(ctx, c.taxHandler, token, bal) : null
|
|
397
406
|
// the creator's own view also shows its creator fee (2.0)
|
|
398
407
|
const { creatorFee } = me.toLowerCase() === c.creator.toLowerCase() ? await curveCreatorFee(ctx, token, c, net) : {}
|
|
408
|
+
const promote = await promoteField(ctx, token, { recipient: c.recipient, dividendPct: c.dividendPct, testnet })
|
|
399
409
|
// a token with a vault (2.0 金库版, 3.0 --vault), before graduation: what this wallet has in it, counted in its 1% cap
|
|
400
410
|
const locked = !c.graduated && (await vaultOfToken(ctx, token).catch(() => null)) ? await ctx.read(ctx.pad, PAD_ABI, 'lockedOf', [token, me]) : null
|
|
401
411
|
return out({
|
|
402
412
|
success: true, chainId: Number(ctx.chainId), wallet: me, token, quote: c.quoteSymbol, graduated: c.graduated,
|
|
403
|
-
balance: formatUnits(bal, 18), ...(locked !== null && { lockedInVault: formatUnits(locked, 18) }), dividendPct: c.dividendPct, ...(creatorFee && { creatorFee }),
|
|
413
|
+
balance: formatUnits(bal, 18), ...(locked !== null && { lockedInVault: formatUnits(locked, 18) }), dividendPct: c.dividendPct, ...(creatorFee && { creatorFee }), ...(promote && { promote }),
|
|
404
414
|
graduationTargetBnb: c.graduationTargetBnb, graduationAt: c.graduationAt, progressPct: c.progressPct,
|
|
405
415
|
...(q && {
|
|
406
416
|
poolSellAll: {
|
|
@@ -459,6 +469,14 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
|
|
|
459
469
|
const vault = flag('vault') ? addrArg(opt, fail, 'vault', 'the vault gang listed for your token') : null
|
|
460
470
|
// --grad: the graduation target in BNB raised, one of the pad's GRAD_BNB_TIERS (2.0); left out: the pad's default
|
|
461
471
|
const grad = flag('grad') ? Number(opt('grad')) : null
|
|
472
|
+
// --promote: a promoter's share of the creator fee, for a window, fixed for good (createWithPromote, 3.0 once upgraded)
|
|
473
|
+
if (flag('promote-days') && !flag('promote')) fail('--promote-days goes with --promote <pct>')
|
|
474
|
+
const promote = flag('promote') ? parsePromote(opt('promote'), opt('promote-days')) : null
|
|
475
|
+
if (promote?.error) {
|
|
476
|
+
const { error, ...extra } = promote
|
|
477
|
+
fail(error, extra)
|
|
478
|
+
}
|
|
479
|
+
if (promote && vault) fail('--promote and --vault can\'t go together: a token is made with one or the other')
|
|
462
480
|
if (grad !== null && !(grad > 0)) fail('--grad must be the graduation target in BNB raised: 6, 9, 12 or 15', { got: opt('grad') ?? null })
|
|
463
481
|
const buyTax = taxed ? taxOf('buy-tax') : 0
|
|
464
482
|
const sellTax = taxed ? taxOf('sell-tax') : 0
|
|
@@ -492,6 +510,13 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
|
|
|
492
510
|
// partner, or yourself), else the creator itself
|
|
493
511
|
const recipient = !taxed || (dividend === 100 && !flag('recipient')) ? zeroAddress
|
|
494
512
|
: flag('recipient') ? addrArg(opt, fail, 'recipient', 'the tax recipient: your own address, or a whitelisted partner') : me
|
|
513
|
+
// a promoter pool module pays only when the launch that cloned it binds it, and pays its own dev: never one typed here
|
|
514
|
+
const typedPool = recipient !== zeroAddress && !(launchPoolModule && recipient.toLowerCase() === launchPoolModule.toLowerCase())
|
|
515
|
+
? await poolOf(ctx.read, (a) => ctx.client.getCode({ address: a }), recipient, poolFactoryAddress(testnet)).catch((e) => fail('could not check --recipient (RPC error)', { detail: e.shortMessage || e.message.split('\n')[0], retry: 'same command again' }))
|
|
516
|
+
: null
|
|
517
|
+
if (typedPool) {
|
|
518
|
+
fail('--recipient is a promoter pool module: a token can\'t name one by hand. Leave --recipient out and add --promote: the launch clones yours and binds it', { recipient })
|
|
519
|
+
}
|
|
495
520
|
const quote = flag('quote') ? opt('quote') : ctx.wbnb
|
|
496
521
|
const refPool = flag('ref-pool') ? opt('ref-pool') : (defaultRefPool(ctx.chainId, quote) ?? zeroAddress)
|
|
497
522
|
if (!isAddress(quote ?? '') || !isAddress(refPool ?? '')) fail('--quote / --ref-pool must be 0x addresses')
|
|
@@ -520,10 +545,16 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
|
|
|
520
545
|
} catch (e) {
|
|
521
546
|
return fail('cannot price the graduation target in this quote', revertOf(e) || { detail: e.shortMessage || e.message })
|
|
522
547
|
}
|
|
523
|
-
|
|
524
|
-
|
|
548
|
+
if (promote) {
|
|
549
|
+
try { await ctx.read(ctx.pad, PROMOTE_PAD_ABI, 'promoteOf', [zeroAddress]) } catch (e) {
|
|
550
|
+
if (!isMissingRead(e)) fail('could not check the pad for a promoter share (RPC error)', { pad: ctx.pad, retry: 'same command again' })
|
|
551
|
+
fail(`GangLaunchpad ${ctx.gen ?? ctx.pad} has no promoter share yet: drop --promote`, { pad: ctx.pad })
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
// createWithVault and createWithPromote always take the target (the pad's default when --grad is left out)
|
|
555
|
+
const fn = vault ? 'createWithVault' : promote ? 'createWithPromote' : grad !== null ? 'createWithGradTarget' : 'create'
|
|
525
556
|
const argsOf = (logoURI, metaURI) => [name, symbol, logoURI, metaURI, quote, refPool, tax,
|
|
526
|
-
...(vault ? [parseUnits(String(targetBnb), 18), vault] : grad !== null ? [parseUnits(String(grad), 18)] : [])]
|
|
557
|
+
...(vault ? [parseUnits(String(targetBnb), 18), vault] : promote ? [parseUnits(String(targetBnb), 18), promote.shareBps, promote.window] : grad !== null ? [parseUnits(String(grad), 18)] : [])]
|
|
527
558
|
const createData = (logoURI, metaURI) => encodeFunctionData({ abi: PAD_ABI, functionName: fn, args: argsOf(logoURI, metaURI) })
|
|
528
559
|
// the logo / metadata strings never decide a revert: dry-run without them, so a create that would fail uploads nothing
|
|
529
560
|
const dry = await simulate(ctx, me, ctx.pad, PAD_ABI, fn, argsOf('', ''))
|
|
@@ -537,7 +568,9 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
|
|
|
537
568
|
}
|
|
538
569
|
const rest = 100 - dividend
|
|
539
570
|
const fees = await feesOf(ctx)
|
|
540
|
-
const
|
|
571
|
+
const baseCreatorFee = await createNote(ctx, net)
|
|
572
|
+
const creatorFee = baseCreatorFee && promote ? `${baseCreatorFee} Less the ${promote.shareBps / 100}% of it you give promoters on their bound wallets' trades.` : baseCreatorFee
|
|
573
|
+
const poolModule = promote && !!launchPoolModule
|
|
541
574
|
return out(notes.step(ctx, { from: me, to: ctx.pad, data: createData(logo.logoURI, meta.metaURI) }, {
|
|
542
575
|
step: 'create', chainId: Number(ctx.chainId), name, symbol, logoURI: logo.logoURI, ...(logo.uploaded && { uploaded: true }),
|
|
543
576
|
metaURI: meta.metaURI, metadata: meta.metadata,
|
|
@@ -551,6 +584,14 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
|
|
|
551
584
|
+ (dividend > 0 ? '; if no holder has 10,000+ tokens when a tax is paid, the holders\' part goes to the recipient too' : '')
|
|
552
585
|
: 'untaxed: no tax in the PancakeSwap pool after graduation, no dividend, no recipient',
|
|
553
586
|
...(creatorFee && { creatorFee }),
|
|
587
|
+
...(promote && {
|
|
588
|
+
promote: {
|
|
589
|
+
sharePct: promote.shareBps / 100, windowDays: promote.windowDays,
|
|
590
|
+
...(!flag('promote-days') && { defaultWindow: `--promote-days left out: ${DEFAULT_WINDOW_DAYS} days` }),
|
|
591
|
+
poolShare: poolModule,
|
|
592
|
+
note: promoteLine({ shareBps: promote.shareBps, windowDays: promote.windowDays, pool: poolModule, taxed, dividendPct: dividend }),
|
|
593
|
+
},
|
|
594
|
+
}),
|
|
554
595
|
...(vault && {
|
|
555
596
|
padGen: ctx.gen, pad: ctx.pad, vault,
|
|
556
597
|
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',
|
|
@@ -567,6 +608,7 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
|
|
|
567
608
|
// graduated: buy in the PancakeSwap pool through GangRouter (the buy tax applies; no Agent gate, no wallet cap)
|
|
568
609
|
if (!c.pair) return fail('the pad marks this token graduated but has no PancakeSwap pair on record: nothing to trade it on', { token })
|
|
569
610
|
if (notes.following) fail('--follow only counts on curve buys before graduation; this token trades on PancakeSwap now', { pair: c.pair })
|
|
611
|
+
if (flag('promoter')) fail('--promoter binds on the curve only, and this token has graduated: on a token with a pool share, a wallet bound on the curve keeps counting for its promoter here, inside its window', { token })
|
|
570
612
|
if (!flag('amount') && !flag('bnb')) fail('--amount <quote (or BNB) to spend> required')
|
|
571
613
|
const raw = parseAmount(fail, flag('amount') ? 'amount' : 'bnb', opt('amount') ?? opt('bnb'))
|
|
572
614
|
return out(await poolTrade(ctx, {
|
|
@@ -601,8 +643,38 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
|
|
|
601
643
|
step: 'buy', chainId: Number(ctx.chainId), token, spend: raw, quote: c.quoteSymbol, expectTokens: formatUnits(tokensOut, 18),
|
|
602
644
|
minTokensOut: formatUnits(minOut, 18), ...(await cutOf(tokensOut, refundAs)), curveTaxPct: 0, ...(c.buyTaxPct > 0 && { poolBuyTaxPct: c.buyTaxPct }),
|
|
603
645
|
})
|
|
646
|
+
// --promoter: the wallet's first buy, sent directly to the pad (buyWithPromoter refuses any contract, the router too)
|
|
647
|
+
if (flag('promoter')) {
|
|
648
|
+
const raw_ = opt('promoter')
|
|
649
|
+
if (!isAddress(raw_ ?? '') || raw_ === zeroAddress) fail('--promoter must be the promoter\'s 0x address', { got: raw_ ?? null })
|
|
650
|
+
const bind = await checkPromoter(ctx, { token, me, raw: raw_, creator: c.creator })
|
|
651
|
+
if (bind.refuse) fail(bind.refuse, { token, promoter: bind.promoter, ...(bind.retry && { retry: bind.retry }) })
|
|
652
|
+
const wbnbQuoted = c.quote.toLowerCase() === String(ctx.wbnb).toLowerCase()
|
|
653
|
+
if (wbnbQuoted && flag('use-wbnb')) fail('--use-wbnb can\'t go with --promoter: a WBNB-quoted buy naming a promoter pays native BNB')
|
|
654
|
+
if (wbnbQuoted) {
|
|
655
|
+
const native = await ctx.client.getBalance({ address: me })
|
|
656
|
+
if (native < quoteIn + GAS_RESERVE) {
|
|
657
|
+
fail('not enough BNB for this buy (native BNB must also cover gas)', { haveBnb: formatUnits(native, 18), needBnb: raw, reserveForGas: formatUnits(GAS_RESERVE, 18) })
|
|
658
|
+
}
|
|
659
|
+
} else {
|
|
660
|
+
const pre = await fundingStep(ctx, me, c.quote, quoteIn, c.quoteSymbol, 'approve-quote', rawOnly, summarize)
|
|
661
|
+
if (pre) return out(pre.success ? { ...pre, ...notes.skipped(follow) } : pre)
|
|
662
|
+
}
|
|
663
|
+
const value = wbnbQuoted ? quoteIn : 0n
|
|
664
|
+
const sim = await simulate(ctx, me, ctx.pad, PROMOTE_PAD_ABI, 'buyWithPromoter', [token, quoteIn, 0n, bind.promoter], value)
|
|
665
|
+
if (sim.failed) return out({ success: false, step: 'buy', ...sim.failed })
|
|
666
|
+
const [tokensOut] = sim.result
|
|
667
|
+
const minOut = minOf(tokensOut, slippage)
|
|
668
|
+
const data = encodeFunctionData({ abi: PROMOTE_PAD_ABI, functionName: 'buyWithPromoter', args: [token, quoteIn, minOut, bind.promoter] })
|
|
669
|
+
return out(notes.step(ctx, { from: me, to: ctx.pad, data, ...(value > 0n && { value }) }, {
|
|
670
|
+
...(await extra(tokensOut, minOut, wbnbQuoted ? 'WBNB (not BNB)' : c.quoteSymbol)), curveFeePct: (await feesOf(ctx)).curveFeePct, promoter: bind.promoter,
|
|
671
|
+
note: 'binds this wallet to the promoter for good, by its first trade of this token, sent directly from the wallet. You pay the same price and fee: the promoter\'s part comes out of the creator\'s fee, and after graduation, on a token with a pool share and inside the window, out of the tax recipient\'s part. Pool trades count only if this wallet itself moves the tokens or calls a listed router directly: tokens moved to another address first, or sold through an unlisted contract, don\'t',
|
|
672
|
+
}, 'buy', await priced(tokensOut)))
|
|
673
|
+
}
|
|
604
674
|
// WBNB-quoted: pay native BNB through the router in one tx (it wraps; tokens land in this wallet; a cap / graduation
|
|
605
675
|
// refund comes back from the pad to this wallet as WBNB, not BNB)
|
|
676
|
+
const bindWarning = await firstBuyWarning(ctx, token, me)
|
|
677
|
+
const warned = bindWarning ? { promoteWarning: bindWarning } : {}
|
|
606
678
|
if (viaRouter(ctx, c.quote, flag)) {
|
|
607
679
|
const native = await ctx.client.getBalance({ address: me })
|
|
608
680
|
if (native < quoteIn + GAS_RESERVE) {
|
|
@@ -615,7 +687,7 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
|
|
|
615
687
|
const minOut = minOf(sim.result, slippage)
|
|
616
688
|
const data = encodeFunctionData({ abi: GANG_ROUTER_ABI, functionName: 'v3BuyBNB', args: [token, minOut, routerDeadline()] })
|
|
617
689
|
return out(notes.step(ctx, { from: me, to: ctx.router, data, value: quoteIn }, {
|
|
618
|
-
...(await extra(sim.result, minOut, 'WBNB (not BNB)')), via: 'router', curveFeePct: (await feesOf(ctx)).curveFeePct,
|
|
690
|
+
...(await extra(sim.result, minOut, 'WBNB (not BNB)')), via: 'router', curveFeePct: (await feesOf(ctx)).curveFeePct, ...warned,
|
|
619
691
|
note: 'paid in BNB through GangRouter; spend includes the 1% curve fee (no tax on the curve; the buy tax applies only in the pool after graduation); at the 1% wallet cap or the graduation cut the excess comes back to this wallet as WBNB (not BNB)',
|
|
620
692
|
}, 'buy', await priced(sim.result)))
|
|
621
693
|
}
|
|
@@ -625,7 +697,7 @@ export async function runV3(sub, { opt, flag, out, fail, summarize, resolveLogo,
|
|
|
625
697
|
if (sim.failed) return out({ success: false, step: 'buy', ...sim.failed })
|
|
626
698
|
const minOut = minOf(sim.result, slippage)
|
|
627
699
|
return out(notes.step(ctx, { from: me, to: ctx.pad, data: encodeFunctionData({ abi: PAD_ABI, functionName: 'buy', args: [token, quoteIn, minOut] }) }, {
|
|
628
|
-
...(await extra(sim.result, minOut)), curveFeePct: (await feesOf(ctx)).curveFeePct,
|
|
700
|
+
...(await extra(sim.result, minOut)), curveFeePct: (await feesOf(ctx)).curveFeePct, ...warned,
|
|
629
701
|
note: 'spend includes the 1% curve fee (no tax on the curve; the buy tax applies only in the pool after graduation); at the 1% wallet cap the excess is refunded',
|
|
630
702
|
}, 'buy', await priced(sim.result)))
|
|
631
703
|
}
|