@gangfun/cli 0.19.1 → 0.21.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/README.md +12 -5
- package/README.zh-CN.md +12 -5
- package/package.json +1 -1
- package/src/fly.js +217 -76
- package/src/index.js +48 -12
- package/src/launch.js +105 -14
- package/src/lp.js +305 -0
- package/src/mcp.js +4 -4
- package/src/v3.js +6 -1
package/src/fly.js
CHANGED
|
@@ -14,14 +14,20 @@ import { poolPayBnb, poolTrade } from './pool.js'
|
|
|
14
14
|
* tokens are minted. Pool tax: buy 1%, sell 1–2%; holders who minted share part of it (the hold line, `holdBps`).
|
|
15
15
|
* No GangBond and no buy-back splitter on these tokens (phase 1).
|
|
16
16
|
* Contracts: gang-launchpad src/flywheel (GangFlywheelPad, FlywheelTaxHandler, GangMintToken; issue #75).
|
|
17
|
-
*
|
|
17
|
+
* Two pad versions: V1 (the first pad) and V2 (FlyConfig adds guardBps / twapWindow; post-launch mints check only the
|
|
18
|
+
* TWAP guard and the price above the pool). New tokens go to V2 once it is listed here; every other command uses the
|
|
19
|
+
* token's own pad (token.launchpad()). The tax handler, token and token deployer are the same code on both.
|
|
20
|
+
* Env: GANG_FLY_PAD / GANG_TESTNET_FLY_PAD override V1, GANG_FLY_PAD_V2 / GANG_TESTNET_FLY_PAD_V2 V2; the RPCs and the
|
|
21
|
+
* GangRouter (pool trades) are GangLaunchpad's.
|
|
18
22
|
*/
|
|
19
23
|
export const FLY_PADS = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
// V2 deployed 2026-10-31; creates go there (it says so while its migrator is unset: no fallback to V1)
|
|
25
|
+
mainnet: { v1: '0x631e66560F4FAE4e486B65349edE48189E48B029', v2: '0x281889ad915c1A95ffc4922235c6314b3Cbd8a5a', startBlock: 130634782n },
|
|
26
|
+
// V1: testnet set 2 (2026-10-30, after the pre-mainnet audit fixes); V2 from block 139842621 (2026-10-31)
|
|
27
|
+
testnet: { v1: '0xD6482850aCAC74BA889804931Fc797294777951c', v2: '0x706973e4F08dBf1604Cf540d0168428521e0E3d6', startBlock: 139749672n },
|
|
23
28
|
}
|
|
24
29
|
|
|
30
|
+
// V1's FlyConfig; V2 appends guardBps and twapWindow (CFG_V2): a new create / checkConfig selector and Created topic
|
|
25
31
|
const CFG = '(uint256 raiseBnb, uint16 baseQuota, uint8 inviteBonus, uint8 maxPerTx, uint16 holdBps, uint16 mintFeeBps, uint16 exitFeeBps, uint16 devCutBps, uint16 buyBps, uint16 sellTaxBps, uint32 launchDelay, uint32 window, uint8 windowCapMul, bool postMint, uint8 tierMode, uint16 stepBps, uint32 stepShares, uint16 maxMulX100, uint16 supplyCapMul)'
|
|
26
32
|
const SALE = '(address creator, address quote, address gate, address pair, uint128 basePrice, uint64 totalShares, uint64 filledAt, uint64 progressAt, uint16 sold, uint16 creatorShares, uint16 markSold, uint16 baseQuota, uint16 holdBps, uint16 mintFeeBps, uint16 exitFeeBps, uint16 devCutBps, uint16 buyBps, uint32 launchDelay, uint32 window, uint8 inviteBonus, uint8 maxPerTx, uint8 windowCapMul, uint8 tierMode, uint16 stepBps, uint32 stepShares, uint16 maxMulX100, bool postMint, bool launched)'
|
|
27
33
|
export const FLY_PAD_ABI = parseAbi([
|
|
@@ -75,6 +81,14 @@ export const FLY_PAD_ABI = parseAbi([
|
|
|
75
81
|
'event FeesFlushed(address indexed quote, uint256 amount)',
|
|
76
82
|
'event ShareWriteFailed(address indexed token, address indexed user, uint256 share)',
|
|
77
83
|
])
|
|
84
|
+
const CFG_V2 = CFG.replace(/\)$/, ', uint16 guardBps, uint32 twapWindow)')
|
|
85
|
+
/** What only the V2 pad has (everything else in FLY_PAD_ABI is the same on both). */
|
|
86
|
+
export const FLY_PAD_V2_ABI = parseAbi([
|
|
87
|
+
`function create(string[4] text, address quote, address refPool, ${CFG_V2} cfg, uint256 devShares) returns (address token)`,
|
|
88
|
+
`function checkConfig(${CFG_V2} cfg, uint256 devShares) view returns (bool ok, string reason)`,
|
|
89
|
+
'function postRulesOf(address token) view returns (uint16 guardBps, uint32 twapWindow)',
|
|
90
|
+
`event Created(address indexed token, address indexed creator, string name, string symbol, string logoURI, address quote, uint256 basePrice, ${CFG_V2} cfg)`,
|
|
91
|
+
])
|
|
78
92
|
export const FLY_HANDLER_ABI = parseAbi([
|
|
79
93
|
'function protectionOf(address token) view returns (uint64 until, address gate, uint256 cap)',
|
|
80
94
|
'function boughtInWindow(address token, address user) view returns (uint256)',
|
|
@@ -100,6 +114,7 @@ export const FLY_HANDLER_ABI = parseAbi([
|
|
|
100
114
|
'event ShareWriteFailed(address indexed token, address indexed user, uint256 share)',
|
|
101
115
|
])
|
|
102
116
|
const TOKEN_ABI = parseAbi([
|
|
117
|
+
'function launchpad() view returns (address)',
|
|
103
118
|
'function balanceOf(address) view returns (uint256)',
|
|
104
119
|
'function symbol() view returns (string)',
|
|
105
120
|
'function totalSupply() view returns (uint256)',
|
|
@@ -115,7 +130,7 @@ const DEX_ABI = parseAbi(['function getAmountsOut(uint256 amountIn, address[] pa
|
|
|
115
130
|
const GANG_ROUTER_VIEW = parseAbi(['function pancakeRouter() view returns (address)'])
|
|
116
131
|
|
|
117
132
|
/** What `gang tx` decodes a 铸币飞轮 tx's logs with (the pad, the tax handler, the holder-reward vault). */
|
|
118
|
-
export const FLY_EVENT_ABIS = [FLY_PAD_ABI, FLY_HANDLER_ABI, VAULT_ABI]
|
|
133
|
+
export const FLY_EVENT_ABIS = [FLY_PAD_ABI, FLY_PAD_V2_ABI, FLY_HANDLER_ABI, VAULT_ABI]
|
|
119
134
|
|
|
120
135
|
// platform constants (FlywheelLogic): the pad's own numbers, fixed in the contract
|
|
121
136
|
const TOTAL_SHARES = 10_000
|
|
@@ -142,7 +157,7 @@ const HINTS = {
|
|
|
142
157
|
TooEarly: 'too early: launch waits launchDelay after the fill; open-early needs at least 30% (3,000 shares) sold',
|
|
143
158
|
OnlyCreator: 'only the creator can open the sale early',
|
|
144
159
|
Slippage: 'fewer shares / tokens than the minimum: the sale or the price moved; re-run to re-quote',
|
|
145
|
-
PriceBelowAverage: 'the pool price is
|
|
160
|
+
PriceBelowAverage: 'the pool price is too far below its average (V1: 10% under 30 minutes; V2: the sale\'s guard under its TWAP window): post-launch mints pause until it recovers (gang info: postMint)',
|
|
146
161
|
PriceBelowRecentHigh: 'the pool price is more than 10% below its recent high: post-launch mints pause until it recovers (the high decays 0.5% a minute)',
|
|
147
162
|
PriceAbovePool: 'the mint price is more than 10% above the pool price right now (the pool just dropped): try again shortly',
|
|
148
163
|
PaceExceeded: 'this wallet minted too much too fast: recent post-launch mints (decaying over 30 minutes) plus this one may be at most 2% of the pool\'s quote side; mint fewer shares or wait',
|
|
@@ -164,32 +179,63 @@ const HINTS = {
|
|
|
164
179
|
}
|
|
165
180
|
const revertOf = (e) => revertIn(e, [FLY_PAD_ABI, FLY_HANDLER_ABI, TOKEN_ABI, ROUTER_ABI, MERGED_ERRORS_ABI], { ...MERGED_HINTS, ...ROUTER_HINTS, ...HINTS })
|
|
166
181
|
|
|
167
|
-
/**
|
|
182
|
+
/**
|
|
183
|
+
* Network settings: GangLaunchpad's chain, RPCs, WBNB and GangRouter (pool trades), with the fly pads. ctx.pad /
|
|
184
|
+
* ctx.version start as the create target (V2 when known, else V1); bindPad switches them to a token's own pad.
|
|
185
|
+
*/
|
|
168
186
|
export function flyCtx(testnet) {
|
|
169
187
|
const net = padNets('v3')[testnet ? 'testnet' : 'mainnet']
|
|
170
188
|
const fly = FLY_PADS[testnet ? 'testnet' : 'mainnet']
|
|
171
|
-
const
|
|
189
|
+
const env = (n) => process.env[testnet ? `GANG_TESTNET_${n}` : `GANG_${n}`]
|
|
190
|
+
const pads = [
|
|
191
|
+
{ address: env('FLY_PAD_V2') || fly.v2, version: 2 },
|
|
192
|
+
{ address: env('FLY_PAD') || fly.v1, version: 1 },
|
|
193
|
+
].filter((p) => p.address)
|
|
172
194
|
const client = createPublicClient({ chain: net.chain, transport: rpcTransport(net.rpcs) })
|
|
173
195
|
return {
|
|
174
|
-
...net, pad, startBlock: fly.startBlock, client,
|
|
196
|
+
...net, pads, pad: pads[0].address, version: pads[0].version, startBlock: fly.startBlock, client,
|
|
175
197
|
read: (address, abi, functionName, args = []) => client.readContract({ address, abi, functionName, args }),
|
|
176
198
|
}
|
|
177
199
|
}
|
|
178
200
|
|
|
179
|
-
/**
|
|
201
|
+
/**
|
|
202
|
+
* The fly pad `token` belongs to, or null (not a fly token on these pads). A GangMintToken names its pad
|
|
203
|
+
* (launchpad()); other tokens are asked of each pad's kindOf. Throws on an RPC error.
|
|
204
|
+
*/
|
|
205
|
+
async function padOf(ctx, token) {
|
|
206
|
+
const named = await ctx.read(token, TOKEN_ABI, 'launchpad').catch(() => null)
|
|
207
|
+
const known = named && ctx.pads.find((p) => same(p.address, named))
|
|
208
|
+
if (known) return known
|
|
209
|
+
for (const p of ctx.pads) {
|
|
210
|
+
if (Number(await ctx.read(p.address, FLY_PAD_ABI, 'kindOf', [token])) === 3) return p
|
|
211
|
+
}
|
|
212
|
+
return null
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** true when `token` is a 铸币飞轮 token on one of the pads; null on an RPC error. */
|
|
180
216
|
export async function isFlyToken(ctx, token) {
|
|
181
217
|
try {
|
|
182
|
-
return
|
|
218
|
+
return !!(await padOf(ctx, token))
|
|
183
219
|
} catch {
|
|
184
220
|
return null
|
|
185
221
|
}
|
|
186
222
|
}
|
|
187
223
|
|
|
224
|
+
/** Point ctx at `token`'s own pad (V1 or V2); false when it is on neither. */
|
|
225
|
+
async function bindPad(ctx, token) {
|
|
226
|
+
const p = await padOf(ctx, token)
|
|
227
|
+
if (!p) return false
|
|
228
|
+
ctx.pad = p.address
|
|
229
|
+
ctx.version = p.version
|
|
230
|
+
return true
|
|
231
|
+
}
|
|
232
|
+
|
|
188
233
|
/** The pad takes creates only once its migrator is set (mainnet: when the Safe opens it). */
|
|
189
234
|
export async function padOpen(ctx) {
|
|
190
235
|
return (await ctx.read(ctx.pad, FLY_PAD_ABI, 'migrator')) !== zeroAddress
|
|
191
236
|
}
|
|
192
|
-
|
|
237
|
+
/** The create target has no migrator yet: say which pad, and that existing tokens are not affected. */
|
|
238
|
+
const closed = (ctx, testnet) => `the ${ctx.version === 2 ? 'V2 ' : ''}铸币飞轮 (Mint Flywheel) pad on BSC ${testnet ? 'testnet' : 'mainnet'} is not open yet (no migrator set), so it takes no creates right now; existing 铸币飞轮 tokens keep working${testnet ? '' : '. Use --testnet to try it there'}`
|
|
193
239
|
|
|
194
240
|
const symbolOf = async (ctx, token) => { try { return await ctx.read(token, TOKEN_ABI, 'symbol') } catch { return null } }
|
|
195
241
|
const pct = (bps) => Number(bps) / 100
|
|
@@ -223,7 +269,7 @@ export async function saleOf(ctx, token) {
|
|
|
223
269
|
: t >= graceEnds ? (sold >= EARLY_OPEN_SHARES ? 'stalled' : 'refund')
|
|
224
270
|
: 'filled'
|
|
225
271
|
return {
|
|
226
|
-
token, status, creator: s.creator, quote: s.quote, quoteSymbol, gate: s.gate === zeroAddress ? null : s.gate,
|
|
272
|
+
token, status, padVersion: ctx.version, pad: ctx.pad, creator: s.creator, quote: s.quote, quoteSymbol, gate: s.gate === zeroAddress ? null : s.gate,
|
|
227
273
|
pair: s.pair === zeroAddress ? null : s.pair, launched: s.launched,
|
|
228
274
|
sharePriceRaw: s.basePrice, sharePrice: await units(ctx, s.quote, s.basePrice),
|
|
229
275
|
raise: await units(ctx, s.quote, s.basePrice * BigInt(TOTAL_SHARES)),
|
|
@@ -268,7 +314,9 @@ async function poolSide(ctx, token, sale, handler) {
|
|
|
268
314
|
unit: `${sale.quoteSymbol || 'quote'} per token`,
|
|
269
315
|
pool: q112(spot), blockStart: q112(blockStart), recentHigh: q112(high), average30m: q112(average),
|
|
270
316
|
launchMintPerToken: formatUnits((sale.sharePriceRaw * 10n ** 18n) / TOKENS_PER_SHARE, 18),
|
|
271
|
-
note:
|
|
317
|
+
note: ctx.version === 1
|
|
318
|
+
? 'a post-launch mint never pays less per token than the pool price; mints pause while the pool is more than 10% below its 30-minute average or its recent high'
|
|
319
|
+
: 'a post-launch mint never pays less per token than the pool price; with the guard on, mints pause while the pool is more than the guard below its average (postRules); the recent high is shown for information only',
|
|
272
320
|
},
|
|
273
321
|
protection: {
|
|
274
322
|
active: t < Number(until), until: iso(Number(until)), endsIn: Math.max(0, Number(until) - t),
|
|
@@ -281,44 +329,80 @@ async function poolSide(ctx, token, sale, handler) {
|
|
|
281
329
|
}
|
|
282
330
|
}
|
|
283
331
|
|
|
284
|
-
//
|
|
285
|
-
// recent high, or when
|
|
286
|
-
// for 20 blocks
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
below_recent_high: 'the pool price is more than 10% below its recent high',
|
|
291
|
-
above_pool: 'a mint would be priced more than 10% above the pool (it dropped in the last blocks)',
|
|
292
|
-
supply_cap: 'the token\'s supply cap leaves no room for a mint',
|
|
293
|
-
}
|
|
294
|
-
const RESUMES = 'minting resumes once the pool price is back within 10% of both its 30-minute average and its recent high (the high decays 0.5% a minute; the average follows the price over 30 minutes)'
|
|
332
|
+
// Post-launch mint rules (FlywheelPostLogic). V1: refused while the pool is more than 10% below its 30-minute average
|
|
333
|
+
// or its recent high, or when the buyer price (spot, the block start, or 99% of the highest of the high, the average and
|
|
334
|
+
// the previous block start, which counts for 20 blocks) is more than 10% above the pool. V2: refused only while the pool
|
|
335
|
+
// is more than the sale's guard below its TWAP (guard on), or when max(spot, block start) is more than 10% above the pool.
|
|
336
|
+
// Both: one share must fit under the supply cap. BPS = 10,000; prices are UQ112x112.
|
|
337
|
+
const BPS = 10_000n, GAP_BPS = 1_000n, TWAP_FLOOR_BPS = 100n, PREV_START_BLOCKS = 20n
|
|
295
338
|
|
|
296
339
|
/**
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
340
|
+
* The rules a post-launch mint of one share breaks now, in the order mintPost checks them (the wallet's pace aside).
|
|
341
|
+
* v: 1 | 2; guardBps (V2): 0 = off; prev (V1): the previous block start (0n once more than 20 blocks old); one: the
|
|
342
|
+
* price of one share; room: the token's mintRoom.
|
|
300
343
|
*/
|
|
301
|
-
|
|
302
|
-
const { spot, blockStart, high, average, room } = side.raw
|
|
303
|
-
const BPS = 10_000n
|
|
344
|
+
export function pauseReasons({ v, spot, blockStart, high, average, prev = 0n, guardBps = 0n, one, room }) {
|
|
304
345
|
const reasons = []
|
|
305
|
-
if (spot * BPS < average * (BPS - MAX_DROP_BPS)) reasons.push('below_average')
|
|
306
|
-
if (spot * BPS < high * (BPS - HIGH_GAP_BPS)) reasons.push('below_recent_high')
|
|
307
|
-
const [bn, [b, bp], packed, one] = await Promise.all([
|
|
308
|
-
ctx.client.getBlockNumber(), ctx.read(handler, FLY_HANDLER_ABI, 'blockRefOf', [token]),
|
|
309
|
-
ctx.read(handler, FLY_HANDLER_ABI, 'prevBlockStartOf', [token]), ctx.read(ctx.pad, FLY_PAD_ABI, 'sharePrice', [token, 1n]),
|
|
310
|
-
])
|
|
311
|
-
const [pb, pp] = BigInt(b) === bn ? [packed >> 224n, packed & ((1n << 224n) - 1n)] : [BigInt(b), bp]
|
|
312
|
-
const prev = bn - pb > PREV_START_BLOCKS ? 0n : pp
|
|
313
|
-
let ref = high > average ? high : average
|
|
314
|
-
if (prev > ref) ref = prev
|
|
315
|
-
const floor = (ref * (BPS - TWAP_FLOOR_BPS)) / BPS
|
|
316
346
|
let price = spot > blockStart ? spot : blockStart
|
|
317
|
-
if (
|
|
318
|
-
|
|
347
|
+
if (v === 1) {
|
|
348
|
+
if (spot * BPS < average * (BPS - GAP_BPS)) reasons.push('below_average')
|
|
349
|
+
if (spot * BPS < high * (BPS - GAP_BPS)) reasons.push('below_recent_high')
|
|
350
|
+
let ref = high > average ? high : average
|
|
351
|
+
if (prev > ref) ref = prev
|
|
352
|
+
const floor = (ref * (BPS - TWAP_FLOOR_BPS)) / BPS
|
|
353
|
+
if (floor > price) price = floor
|
|
354
|
+
} else if (guardBps !== 0n && spot * BPS < average * (BPS - guardBps)) {
|
|
355
|
+
reasons.push('below_guard') // gang.fun's code for V2's guard (V1 keeps below_average)
|
|
356
|
+
}
|
|
357
|
+
if (price * BPS > spot * (BPS + GAP_BPS)) reasons.push('above_pool')
|
|
319
358
|
// one share: the buyer's tokens and the liquidity's (at most its price of quote at spot) must fit under the cap
|
|
320
359
|
if (spot > 0n && price > 0n && (one * Q112) / price + (one * Q112) / spot > room) reasons.push('supply_cap')
|
|
321
|
-
return
|
|
360
|
+
return reasons
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/** What a rule means and when it lets minting back, for this pad version and its post-launch rules. */
|
|
364
|
+
function pauseText(reason, v, rules) {
|
|
365
|
+
const avg = v === 1 ? '30-minute average' : `${rules.twapWindow / 60}-minute average (TWAP)`
|
|
366
|
+
const guard = v === 1 ? 10 : rules.guardBps / 100
|
|
367
|
+
return {
|
|
368
|
+
why: {
|
|
369
|
+
below_average: `the pool price is more than ${guard}% below its ${avg}`,
|
|
370
|
+
below_guard: `the pool price is more than ${guard}% below its ${avg} (the sale's guard)`,
|
|
371
|
+
below_recent_high: 'the pool price is more than 10% below its recent high',
|
|
372
|
+
above_pool: v === 1 ? 'a mint would be priced more than 10% above the pool (it dropped in the last blocks)' : 'a mint would be priced more than 10% above the pool (it dropped earlier in this block)',
|
|
373
|
+
supply_cap: 'the token\'s supply cap leaves no room for a mint',
|
|
374
|
+
}[reason],
|
|
375
|
+
resumes: reason === 'supply_cap' ? 'post-launch minting is over: the supply cap is reached'
|
|
376
|
+
: v === 1 ? 'minting resumes once the pool price is back within 10% of both its 30-minute average and its recent high (the high decays 0.5% a minute; the average follows the price over 30 minutes)'
|
|
377
|
+
: reason === 'above_pool' ? 'minting resumes in the next block (the price is checked against where the block started)'
|
|
378
|
+
: `minting resumes once the pool price is back within ${guard}% of its ${avg}`,
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/** The post-launch rules of the token's sale: V2 reads its guard and TWAP window; V1's are fixed. */
|
|
383
|
+
async function postRules(ctx, token) {
|
|
384
|
+
if (ctx.version === 1) return { guardBps: 1_000, twapWindow: 1_800, recentHigh: true }
|
|
385
|
+
const [guardBps, twapWindow] = await ctx.read(ctx.pad, FLY_PAD_V2_ABI, 'postRulesOf', [token])
|
|
386
|
+
return { guardBps: Number(guardBps), twapWindow: Number(twapWindow), recentHigh: false }
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Whether post-launch mints are refused now, by the rules mintPost checks on this token's pad (the wallet's own pace
|
|
391
|
+
* aside), as of the latest block. → { pausedNow, reason, reasons, why, resumes }; reason is the first rule mintPost hits.
|
|
392
|
+
*/
|
|
393
|
+
async function mintPause(ctx, token, sale, handler, side) {
|
|
394
|
+
const { spot, blockStart, high, average, room } = side.raw
|
|
395
|
+
const [rules, one] = await Promise.all([postRules(ctx, token), ctx.read(ctx.pad, FLY_PAD_ABI, 'sharePrice', [token, 1n])])
|
|
396
|
+
let prev = 0n
|
|
397
|
+
if (ctx.version === 1) {
|
|
398
|
+
const [bn, [b, bp], packed] = await Promise.all([
|
|
399
|
+
ctx.client.getBlockNumber(), ctx.read(handler, FLY_HANDLER_ABI, 'blockRefOf', [token]), ctx.read(handler, FLY_HANDLER_ABI, 'prevBlockStartOf', [token]),
|
|
400
|
+
])
|
|
401
|
+
const [pb, pp] = BigInt(b) === bn ? [packed >> 224n, packed & ((1n << 224n) - 1n)] : [BigInt(b), bp]
|
|
402
|
+
prev = bn - pb > PREV_START_BLOCKS ? 0n : pp
|
|
403
|
+
}
|
|
404
|
+
const reasons = pauseReasons({ v: ctx.version, spot, blockStart, high, average, prev, guardBps: BigInt(rules.guardBps), one, room })
|
|
405
|
+
return { pausedNow: reasons.length > 0, ...(reasons.length && { reason: reasons[0], reasons, ...pauseText(reasons[0], ctx.version, rules) }) }
|
|
322
406
|
}
|
|
323
407
|
|
|
324
408
|
async function poolReserves(ctx, token, pair) {
|
|
@@ -390,9 +474,16 @@ const WITHDRAW_TOLERANCE_BPS = 10n
|
|
|
390
474
|
|
|
391
475
|
/** J-template preset (spec §3–4) and the plain one; every field a flag can override. */
|
|
392
476
|
export const FLY_PRESETS = {
|
|
393
|
-
j: { raise: 20, quota: 10, invite: 1, maxPerTx: 10, hold: 60, mintFee: 1, exitFee: 1, devCut: 10, buyPct: 30, sellTax: 2, launchDelay: 60, window: 600, capMul: 1, postMint: true, tier: 'standard', supplyCap: 100 },
|
|
394
|
-
steady: { raise: 20, quota: 100, invite: 0, maxPerTx: 10, hold: 60, mintFee: 1, exitFee: 1, devCut: 0, buyPct: 0, sellTax: 1, launchDelay: 60, window: 600, capMul: 1, postMint: false, tier: 'flat', supplyCap: 100 },
|
|
477
|
+
j: { raise: 20, quota: 10, invite: 1, maxPerTx: 10, hold: 60, mintFee: 1, exitFee: 1, devCut: 10, buyPct: 30, sellTax: 2, launchDelay: 60, window: 600, capMul: 1, postMint: true, tier: 'standard', supplyCap: 100, guard: 'off', twapWindow: 30 },
|
|
478
|
+
steady: { raise: 20, quota: 100, invite: 0, maxPerTx: 10, hold: 60, mintFee: 1, exitFee: 1, devCut: 0, buyPct: 0, sellTax: 1, launchDelay: 60, window: 600, capMul: 1, postMint: false, tier: 'flat', supplyCap: 100, guard: 'off', twapWindow: 30 },
|
|
395
479
|
}
|
|
480
|
+
// V2 only: the post-launch TWAP guard (off or 15 / 20 / 30% below the average) and its window (15 or 30 minutes). The
|
|
481
|
+
// guard is off by default (the user's choice): minting does not pause on a price drop, and V2's quota cap of 10 shares
|
|
482
|
+
// per wallet bounds what a wallet can mint; the window is still set (it only matters once the guard is on)
|
|
483
|
+
const GUARDS = { off: 0, 15: 1_500, 20: 2_000, 30: 3_000 }
|
|
484
|
+
const TWAP_WINDOWS = { 15: 900, 30: 1_800 }
|
|
485
|
+
// V2: with post-launch minting on, a wallet's quota is at most this many shares and an invite adds at most one
|
|
486
|
+
const MAX_POST_QUOTA = 10, MAX_POST_INVITE = 1
|
|
396
487
|
// flag → [preset key, min, max, kind]
|
|
397
488
|
const CREATE_FLAGS = {
|
|
398
489
|
raise: ['raise', 3, 50, 'num'], quota: ['quota', 5, 100, 'int'], 'invite-bonus': ['invite', 0, 3, 'int'],
|
|
@@ -402,7 +493,7 @@ const CREATE_FLAGS = {
|
|
|
402
493
|
'cap-mul': ['capMul', 1, 2, 'int'], 'supply-cap': ['supplyCap', 10, 500, 'int'],
|
|
403
494
|
'step-pct': ['stepPct', 0, 10, 'num'], 'step-shares': ['stepShares', 100, 100_000, 'int'], 'max-mul': ['maxMul', 1, 10, 'num'],
|
|
404
495
|
}
|
|
405
|
-
export const FLY_CREATE_FLAGS = [...Object.keys(CREATE_FLAGS), 'preset', 'tier', 'post-mint', 'no-post-mint', 'dev-shares']
|
|
496
|
+
export const FLY_CREATE_FLAGS = [...Object.keys(CREATE_FLAGS), 'preset', 'tier', 'post-mint', 'no-post-mint', 'dev-shares', 'guard', 'twap-window']
|
|
406
497
|
|
|
407
498
|
/**
|
|
408
499
|
* Entry for `gang fly <sub>` (and the routed verbs of a fly token). io: { opt, flag, out, fail, summarize, resolveLogo,
|
|
@@ -425,6 +516,8 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
|
|
|
425
516
|
return t
|
|
426
517
|
}
|
|
427
518
|
const loadSale = async (token) => {
|
|
519
|
+
// the token's own pad: V1 and V2 tokens both keep working
|
|
520
|
+
if (!(await bindPad(ctx, token))) fail(`not a 铸币飞轮 (Mint Flywheel) token${testnet ? ' on BSC testnet' : ''}`, { token, chainId, pads: ctx.pads.map((p) => p.address) })
|
|
428
521
|
const sale = await saleOf(ctx, token)
|
|
429
522
|
if (!sale) fail(`not a 铸币飞轮 (Mint Flywheel) token on this pad${testnet ? ' (BSC testnet)' : ''}`, { token, chainId, pad: ctx.pad })
|
|
430
523
|
return sale
|
|
@@ -437,24 +530,37 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
|
|
|
437
530
|
const limit = parseIntIn(fail, 'limit', opt('limit', '20'), 1, 200)
|
|
438
531
|
const status = opt('status', 'all')
|
|
439
532
|
if (!['all', 'minting', 'filled', 'launched'].includes(status)) fail('--status must be minting, filled, launched or all')
|
|
440
|
-
|
|
533
|
+
// newest pad first, each newest first (V2's tokens are the newer ones)
|
|
534
|
+
const create = { pad: ctx.pad, version: ctx.version }
|
|
441
535
|
const items = []
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
const
|
|
447
|
-
|
|
448
|
-
items.
|
|
449
|
-
token
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
536
|
+
let total = 0
|
|
537
|
+
for (const p of ctx.pads) {
|
|
538
|
+
ctx.pad = p.address
|
|
539
|
+
ctx.version = p.version
|
|
540
|
+
const count = Number(await ctx.read(ctx.pad, FLY_PAD_ABI, 'tokenCount'))
|
|
541
|
+
total += count
|
|
542
|
+
for (let i = count - 1; i >= 0 && items.length < limit; i--) {
|
|
543
|
+
const token = await ctx.read(ctx.pad, FLY_PAD_ABI, 'allTokens', [BigInt(i)])
|
|
544
|
+
const s = await saleOf(ctx, token)
|
|
545
|
+
if (!s) continue
|
|
546
|
+
const st = s.status === 'stalled' || s.status === 'refund' ? 'filled' : s.status
|
|
547
|
+
if (status !== 'all' && st !== status) continue
|
|
548
|
+
items.push({
|
|
549
|
+
token, symbol: await symbolOf(ctx, token), padVersion: p.version, status: s.status, quote: s.quoteSymbol, sharePrice: s.sharePrice, raise: s.raise,
|
|
550
|
+
sold: s.sold, sharesLeft: s.sharesLeft, mintedShares: s.mintedShares, baseQuota: s.rules.baseQuota, postMint: s.rules.postMint,
|
|
551
|
+
pair: s.pair, link: `https://gang.fun/token/${token}`,
|
|
552
|
+
next: s.status === 'minting' ? `gang mint --token ${token} --shares <n>${net}`
|
|
553
|
+
: s.status === 'launched' ? (s.rules.postMint ? `gang mint --token ${token} --shares <n>${net}` : `gang buy --token ${token} --amount <quote>${net}`)
|
|
554
|
+
: `gang info --token ${token}${net}`,
|
|
555
|
+
})
|
|
556
|
+
}
|
|
456
557
|
}
|
|
457
|
-
|
|
558
|
+
ctx.pad = create.pad
|
|
559
|
+
ctx.version = create.version
|
|
560
|
+
return out({
|
|
561
|
+
success: true, chainId, createPad: ctx.pad, createPadVersion: ctx.version, pads: ctx.pads.map((p) => ({ version: p.version, pad: p.address })),
|
|
562
|
+
total, status, count: items.length, items, ...(!(await padOpen(ctx)) && { note: closed(ctx, testnet) }),
|
|
563
|
+
})
|
|
458
564
|
}
|
|
459
565
|
|
|
460
566
|
if (sub === 'info') {
|
|
@@ -469,9 +575,13 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
|
|
|
469
575
|
Object.assign(extra, view)
|
|
470
576
|
if (sale.rules.postMint) {
|
|
471
577
|
const [one, pause] = await Promise.all([ctx.read(ctx.pad, FLY_PAD_ABI, 'sharePrice', [token, 1n]), mintPause(ctx, token, sale, handler, side)])
|
|
578
|
+
const rules = await postRules(ctx, token)
|
|
472
579
|
extra.postMint = {
|
|
473
|
-
sharePriceNow: await units(ctx, sale.quote, one), tierMulNow: Number((one * 100n) / sale.sharePriceRaw) / 100,
|
|
474
|
-
|
|
580
|
+
sharePriceNow: await units(ctx, sale.quote, one), tierMulNow: Number((one * 100n) / sale.sharePriceRaw) / 100,
|
|
581
|
+
rules: ctx.version === 1
|
|
582
|
+
? { average: '30 minutes', pausesBelowAveragePct: 10, pausesBelowRecentHighPct: 10 }
|
|
583
|
+
: { guardPct: rules.guardBps ? rules.guardBps / 100 : 'off', twapWindowMin: rules.twapWindow / 60 },
|
|
584
|
+
...pause,
|
|
475
585
|
}
|
|
476
586
|
}
|
|
477
587
|
const [owedTax, swapBack] = await Promise.all([
|
|
@@ -537,7 +647,7 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
|
|
|
537
647
|
}
|
|
538
648
|
if (sale.rules.postMint) {
|
|
539
649
|
const pause = await mintPause(ctx, token, sale, handler, side)
|
|
540
|
-
pos.mintPaused =
|
|
650
|
+
pos.mintPaused = pause
|
|
541
651
|
if (acct.view.quotaLeft > 0) {
|
|
542
652
|
const [acc, paid, fee, tokensOut, ok] = await ctx.read(ctx.pad, FLY_PAD_ABI, 'previewMintPost', [token, who, 1n])
|
|
543
653
|
pos.mintOneShareNow = acc ? { paid: await units(ctx, sale.quote, paid), fee: await units(ctx, sale.quote, fee), tokensOut: formatUnits(tokensOut, 18), ok } : null
|
|
@@ -583,7 +693,7 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
|
|
|
583
693
|
const name = opt('name'), symbol = opt('symbol')
|
|
584
694
|
if (!name || !symbol) fail('--name and --symbol are required')
|
|
585
695
|
checkMeta()
|
|
586
|
-
if (!(await padOpen(ctx))) fail(
|
|
696
|
+
if (!(await padOpen(ctx))) fail(closed(ctx, testnet), { pad: ctx.pad, padVersion: ctx.version })
|
|
587
697
|
const presetName = opt('preset', 'j')
|
|
588
698
|
const preset = FLY_PRESETS[presetName]
|
|
589
699
|
if (!preset) fail(`--preset must be ${Object.keys(FLY_PRESETS).join(' or ')}`, { got: presetName })
|
|
@@ -599,9 +709,30 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
|
|
|
599
709
|
if (flag('post-mint') && flag('no-post-mint')) fail('give --post-mint or --no-post-mint, not both')
|
|
600
710
|
if (flag('post-mint')) v.postMint = true
|
|
601
711
|
if (flag('no-post-mint')) v.postMint = false
|
|
712
|
+
// V2's post-launch rules; a V1 create target has none, so the flags are refused there rather than ignored
|
|
713
|
+
const v2 = ctx.version === 2
|
|
714
|
+
if (!v2 && (flag('guard') || flag('twap-window'))) fail('--guard / --twap-window are settings of the V2 Mint Flywheel pad, which is not live on this network yet: leave them out')
|
|
715
|
+
if (flag('guard')) {
|
|
716
|
+
v.guard = String(opt('guard'))
|
|
717
|
+
if (!(v.guard in GUARDS)) fail('--guard must be off, 15, 20 or 30 (% below the average at which post-launch mints pause)', { got: opt('guard') ?? null })
|
|
718
|
+
}
|
|
719
|
+
if (flag('twap-window')) {
|
|
720
|
+
v.twapWindow = Number(opt('twap-window'))
|
|
721
|
+
if (!(v.twapWindow in TWAP_WINDOWS)) fail('--twap-window must be 15 or 30 (minutes)', { got: opt('twap-window') ?? null })
|
|
722
|
+
}
|
|
723
|
+
if (v2 && v.postMint && v.quota > MAX_POST_QUOTA) {
|
|
724
|
+
fail(`--quota must be 5-${MAX_POST_QUOTA} with post-launch minting on (the V2 pad's rule): lower --quota, or add --no-post-mint`, { quota: v.quota })
|
|
725
|
+
}
|
|
726
|
+
if (v2 && v.postMint && v.invite > MAX_POST_INVITE) {
|
|
727
|
+
fail(`--invite-bonus must be 0-${MAX_POST_INVITE} with post-launch minting on (the V2 pad's rule): lower it, or add --no-post-mint`, { inviteBonus: v.invite })
|
|
728
|
+
}
|
|
602
729
|
// a pad without the Agent ID gate takes no dev cut (checkConfig refuses one): the preset's goes to 0 unless asked for
|
|
603
730
|
const gated = await ctx.read(ctx.pad, FLY_PAD_ABI, 'agentGateEnabled')
|
|
604
731
|
if (!gated && !flag('dev-cut')) v.devCut = 0
|
|
732
|
+
// V2: post-launch minting needs the Agent ID gate (one wallet per ID is what bounds the per-wallet quota)
|
|
733
|
+
if (v2 && v.postMint && !gated) {
|
|
734
|
+
fail('post-launch minting needs the Agent ID gate, which this pad has off right now: add --no-post-mint for a sale that only mints before launch', { pad: ctx.pad })
|
|
735
|
+
}
|
|
605
736
|
const linear = v.tier === 'linear'
|
|
606
737
|
if (!linear && ['step-pct', 'step-shares', 'max-mul'].some(flag)) fail('--step-pct / --step-shares / --max-mul only apply with --tier linear')
|
|
607
738
|
if (linear) { v.stepPct ??= 1; v.stepShares ??= 1_000; v.maxMul ??= 10 }
|
|
@@ -613,8 +744,11 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
|
|
|
613
744
|
sellTaxBps: bps(v.sellTax), launchDelay: v.launchDelay, window: v.window, windowCapMul: v.capMul, postMint: v.postMint,
|
|
614
745
|
tierMode: TIERS.indexOf(v.tier), stepBps: linear ? bps(v.stepPct) : 0, stepShares: linear ? v.stepShares : 0,
|
|
615
746
|
maxMulX100: linear ? Math.round(v.maxMul * 100) : 0, supplyCapMul: v.supplyCap,
|
|
747
|
+
...(v2 && { guardBps: GUARDS[v.guard], twapWindow: TWAP_WINDOWS[v.twapWindow] }),
|
|
616
748
|
}
|
|
617
|
-
|
|
749
|
+
// V2 has its own create / checkConfig (FlyConfig grew): the ABI follows the create target
|
|
750
|
+
const padAbi = v2 ? FLY_PAD_V2_ABI : FLY_PAD_ABI
|
|
751
|
+
const [ok, reason] = await ctx.read(ctx.pad, padAbi, 'checkConfig', [cfg, BigInt(devShares)])
|
|
618
752
|
if (!ok) fail(`setting out of bounds: ${reason}`, { config: cfgView(cfg) })
|
|
619
753
|
const quote = flag('quote') ? opt('quote') : ctx.wbnb
|
|
620
754
|
const refPool = flag('ref-pool') ? opt('ref-pool') : (defaultRefPool(ctx.chainId, quote) ?? zeroAddress)
|
|
@@ -640,16 +774,21 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
|
|
|
640
774
|
const pre = await fund(ctx, { me: who, token: quote, need, spender: ctx.pad, sym }, rawOnly, summarize)
|
|
641
775
|
if (pre) return out(pre)
|
|
642
776
|
const createData = (logoURI, metaURI) => encodeFunctionData({
|
|
643
|
-
abi:
|
|
777
|
+
abi: padAbi, functionName: 'create', args: [[name, symbol, logoURI, metaURI], quote, refPool, cfg, BigInt(devShares)],
|
|
644
778
|
})
|
|
645
779
|
const dry = await dryRun(ctx, who, ctx.pad, createData('', ''))
|
|
646
780
|
if (dry) return out({ success: false, step: 'create', ...dry })
|
|
647
781
|
const logo = await resolveLogo()
|
|
648
782
|
const meta = await resolveMeta({ name, symbol, logoURI: logo.logoURI })
|
|
649
783
|
return out(write({ from: who, to: ctx.pad, data: createData(logo.logoURI, meta.metaURI) }, {
|
|
650
|
-
step: 'create', kind: 'fly', name, symbol, logoURI: logo.logoURI, ...(logo.uploaded && { uploaded: true }),
|
|
784
|
+
step: 'create', kind: 'fly', padVersion: ctx.version, pad: ctx.pad, name, symbol, logoURI: logo.logoURI, ...(logo.uploaded && { uploaded: true }),
|
|
651
785
|
metaURI: meta.metaURI, metadata: meta.metadata, quote: sym || quote, preset: presetName, config: cfgView(cfg),
|
|
652
786
|
sharePrice: await units(ctx, quote, quoteWbnb ? price : (price * 100n) / 102n), devShares, devCost: await units(ctx, quote, need),
|
|
787
|
+
...(v2 && v.postMint && {
|
|
788
|
+
guardNote: cfg.guardBps
|
|
789
|
+
? `post-launch mints pause while the pool is more than ${cfg.guardBps / 100}% below its ${cfg.twapWindow / 60}-minute average (--guard ${cfg.guardBps / 100})`
|
|
790
|
+
: 'the price guard is off (the default): post-launch minting does not pause when the price drops; the quota cap of 10 shares per wallet bounds it. Turn it on with --guard 15|20|30 (% below the average, over --twap-window 15|30 minutes)',
|
|
791
|
+
}),
|
|
653
792
|
minWallets: Math.ceil(TOTAL_SHARES / cfg.baseQuota),
|
|
654
793
|
note: '10,000 shares at one price; it launches once they are sold (or you open early at ≥ 30%: gang fly open-early), launchDelay later, by anyone (gang fly launch; gang.fun\'s keeper does it too). Minters can sell back before that at the mint price less the exit fee. No GangBond or buy-back on these tokens.',
|
|
655
794
|
}))
|
|
@@ -742,12 +881,13 @@ export async function runFly(sub, { opt, flag, out, fail, summarize, resolveLogo
|
|
|
742
881
|
// a rule of the pad / handler / token counts: a quote-token revert (no allowance yet) says nothing about the rule
|
|
743
882
|
const dry = await dryRun(ctx, who, ctx.pad, data, bnb ? maxSpent : 0n, bnb)
|
|
744
883
|
const r = dry?.reverted && HINTS[dry.error] ? dry : null
|
|
745
|
-
|
|
884
|
+
// no rule from the simulation (e.g. it stopped at the quote transfer): the pad's rules read as gang info does,
|
|
885
|
+
// and what is left when none applies is this wallet's own pace
|
|
886
|
+
const pause = r ? null : await mintPause(ctx, token, sale, handler, side)
|
|
746
887
|
return out({
|
|
747
|
-
success: false, ...extra, error: `a post-launch mint is refused right now${r ? `: ${r.error}` : ''}`,
|
|
748
|
-
...(r ? { reason: r.error, hint: r.hint } : {
|
|
749
|
-
reason:
|
|
750
|
-
hint: cap ? HINTS.CapExceeded : 'the pool price is more than 10% below its average / recent high, the mint price is more than 10% above the pool, or this wallet hit its 30-minute pace (2% of the pool): wait, or mint fewer shares',
|
|
888
|
+
success: false, ...extra, error: `a post-launch mint is refused right now${r ? `: ${r.error}` : `: ${pause.pausedNow ? pause.reason : 'pace'}`}`,
|
|
889
|
+
...(r ? { reason: r.error, hint: r.hint } : pause.pausedNow ? { reason: pause.reason, hint: pause.why, resumes: pause.resumes } : {
|
|
890
|
+
reason: 'pace', hint: HINTS.PaceExceeded,
|
|
751
891
|
}),
|
|
752
892
|
prices: side.prices, supply: side.supply,
|
|
753
893
|
})
|
|
@@ -977,6 +1117,7 @@ const cfgView = (c) => ({
|
|
|
977
1117
|
mintFeePct: pct(c.mintFeeBps), exitFeePct: pct(c.exitFeeBps), devCutPct: pct(c.devCutBps), buyPct: pct(c.buyBps), sellTaxPct: pct(c.sellTaxBps),
|
|
978
1118
|
launchDelaySec: c.launchDelay, protectionSec: c.window, protectionCapMul: c.windowCapMul, postMint: c.postMint, tier: TIERS[c.tierMode],
|
|
979
1119
|
...(c.tierMode === 2 && { stepPct: pct(c.stepBps), stepShares: c.stepShares, maxMul: c.maxMulX100 / 100 }), supplyCapMul: c.supplyCapMul,
|
|
1120
|
+
...(c.guardBps !== undefined && { guardPct: c.guardBps ? pct(c.guardBps) : 'off', twapWindowMin: c.twapWindow / 60 }),
|
|
980
1121
|
})
|
|
981
1122
|
|
|
982
1123
|
/** The command that acts on the sale next. `paused`: mintPause (or the wallet's) after launch. */
|