@gangfun/cli 0.17.7 → 0.18.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 +19 -6
- package/README.zh-CN.md +18 -5
- package/package.json +1 -1
- package/src/baw.js +30 -5
- package/src/discover.js +21 -11
- package/src/fly.js +932 -0
- package/src/index.js +127 -29
- package/src/mcp.js +9 -8
- package/src/pool.js +15 -7
- package/src/portfolio.js +30 -5
- package/src/steps.js +22 -5
package/src/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
CONFIG, ADDR, listTokens, tokenInfo, quoteBuy, quoteSell, isAgent, balanceOf, allowance,
|
|
4
4
|
calldata, decodeTx, decodeLogs, parseEther, fmt, fmtTok, resolvePad, isAddress, client,
|
|
5
5
|
} from './chain.js'
|
|
6
|
-
import { baw, bawAddress, bawSettings, bawStatus, bawPreview, bawExecute } from './baw.js'
|
|
6
|
+
import { baw, bawAddress, bawError, bawFailed, bawSettings, bawStatus, bawPreview, bawExecute } from './baw.js'
|
|
7
7
|
import { uploadLogoFile, uploadMetadata, rehostLogoUrl, isGangLogo, checkGangLogo, tempHost, ipfsCid, ipfsUri, isIpfsUri, cdnUrl, LOGO_UI } from './logo.js'
|
|
8
8
|
import { API, fetchMarket, get as apiGet, rank, watch, parseDuration } from './discover.js'
|
|
9
9
|
import {
|
|
@@ -20,6 +20,7 @@ import { runFair, FAIR_EVENT_ABIS } from './fair.js'
|
|
|
20
20
|
import { runV3, v3Ctx, V3_EVENT_ABIS } from './v3.js'
|
|
21
21
|
import { runBond } from './bond.js'
|
|
22
22
|
import { runBuyback } from './buyback.js'
|
|
23
|
+
import { runFly, flyCtx, isFlyToken, FLY_EVENT_ABIS, FLY_CREATE_FLAGS } from './fly.js'
|
|
23
24
|
import { FAIR_DEV_BUY, isLaunch, LAUNCH_FLAGS, runLaunch } from './launch.js'
|
|
24
25
|
import { poolPayBnb, poolTrade } from './pool.js'
|
|
25
26
|
import { parseAmount, ROUTER_ABI, ROUTER_HINTS, revertOf as revertIn, step as writeStep } from './steps.js'
|
|
@@ -202,21 +203,22 @@ const followSkipped = (follow) =>
|
|
|
202
203
|
const HELP = `gang — agent-only launchpad on BNB Chain (Binance Agentic Wallet) · new tokens on GangLaunchpad (V3 / 打新)
|
|
203
204
|
|
|
204
205
|
One command per action, whatever pad the token is on: buy / sell / info / status / claim / mint / withdraw / release
|
|
205
|
-
read the token's kind (GangLaunchpad kindOf: V3 curve or 打新 sale; otherwise the V2 / Soft /
|
|
206
|
-
kind's trade. Results of V3 / 打新 tokens carry kind: "v3" | "fair". --testnet
|
|
207
|
-
only); --calldata prints the raw tx instead of a baw preview; --from
|
|
208
|
-
graduated tokens only).
|
|
206
|
+
read the token's kind (GangLaunchpad kindOf: V3 curve or 打新 sale; GangFlywheelPad: 持续打新; otherwise the V2 / Soft /
|
|
207
|
+
U / S pads) and run that kind's trade. Results of V3 / 打新 / 持续打新 tokens carry kind: "v3" | "fair" | "fly". --testnet
|
|
208
|
+
= BSC testnet (GangLaunchpad and GangFlywheelPad only); --calldata prints the raw tx instead of a baw preview; --from
|
|
209
|
+
<addr> reads / builds for that wallet (V2 / Soft: graduated tokens only).
|
|
209
210
|
|
|
210
211
|
gang version this CLI's version (also --version, -v); no wallet needed
|
|
211
212
|
gang mcp serve these commands as an MCP server on stdio (Claude Desktop / Code, Cursor, …):
|
|
212
213
|
gang_help (this text + the rules), reads, watch, buy / sell / follow previews,
|
|
213
214
|
execute, and gang_cli for every other command
|
|
214
215
|
gang preflight check sign-in, Developer Mode, tradeAllTokens, Agent ID
|
|
215
|
-
gang list [--limit 20] [--kind v3|fair [--status …]]
|
|
216
|
+
gang list [--limit 20] [--kind v3|fair|fly [--status …]]
|
|
216
217
|
V2 / Soft / U / S tokens read on chain (works without gang.fun), the newest --limit
|
|
217
218
|
per pad; --kind v3 (--status curve|graduated|all) / --kind fair
|
|
218
|
-
(--status minting|launched|all): GangLaunchpad tokens from gang.fun
|
|
219
|
-
|
|
219
|
+
(--status minting|launched|all): GangLaunchpad tokens from gang.fun; --kind fly
|
|
220
|
+
(--status minting|filled|launched|all): 持续打新 tokens read from the pad, newest first
|
|
221
|
+
gang hot [--limit 10] [--track all|v3|fair|fly|v2|soft] [--include-graduated]
|
|
220
222
|
tokens not yet graduated / launched, ranked by 24h USD volume
|
|
221
223
|
gang new [--limit 10] [--max-age 2h] [--track …] newest first
|
|
222
224
|
gang near-grad [--min-pct 50] [--limit 10] [--track …] closest to graduation (打新: to filling)
|
|
@@ -263,8 +265,9 @@ graduated tokens only).
|
|
|
263
265
|
sales pay native BNB through GangRouter in one tx (--use-wbnb: from WBNB)
|
|
264
266
|
gang withdraw --token <addr> (--shares <n> | --all)
|
|
265
267
|
打新: sell shares back before it fills: mint price − exit fee (none once stale)
|
|
266
|
-
gang claim --token <addr> V3: my dividend (the quote token);
|
|
267
|
-
gang release --token <addr> V3: push a tax payment that failed earlier (anyone may; the recipient gets it)
|
|
268
|
+
gang claim --token <addr> V3: my dividend (the quote token); 打新 / 持续打新: the holder reward
|
|
269
|
+
gang release --token <addr> V3: push a tax payment that failed earlier (anyone may; the recipient gets it).
|
|
270
|
+
持续打新: push the creator's dev cut / tax share that a transfer could not deliver
|
|
268
271
|
gang follow <note tx> --amount <n> [--slippage 1] [--note …]
|
|
269
272
|
buy the token that note is about, marked on-chain as following it (= gang buy
|
|
270
273
|
--follow; curve buys only)
|
|
@@ -294,6 +297,39 @@ graduated tokens only).
|
|
|
294
297
|
gang.fun; the token's contractURI / metaURI, permanent). --logo-uri images are copied
|
|
295
298
|
to gang.fun first (other hosts expire); --keep-logo-uri puts a permanent URL (e.g.
|
|
296
299
|
ipfs://) on-chain as is; gang.fun files always go on as ipfs://<cid>
|
|
300
|
+
gang create --fly --name <n> --symbol <s> [--preset j|steady] [--raise 3-50] [--quota 5-100] [--invite-bonus 0-3]
|
|
301
|
+
[--max-per-tx 1-10] [--hold 60-90] [--mint-fee 1-3] [--exit-fee 1-2] [--dev-cut 0-10] [--buy-pct 0-50]
|
|
302
|
+
[--sell-tax 1-2] [--launch-delay 0-300] [--window 300-1800] [--cap-mul 1-2] [--post-mint | --no-post-mint]
|
|
303
|
+
[--tier flat|standard|linear [--step-pct 0-10 --step-shares 100-100000 --max-mul 1-10]] [--supply-cap 10-500]
|
|
304
|
+
[--dev-shares <n>] [--quote 0x… --ref-pool 0x…] [--logo …] [--website URL] [--twitter @handle] [--description …]
|
|
305
|
+
a 持续打新 (continuous mint, GangFlywheelPad) sale, BSC testnet until the mainnet pad
|
|
306
|
+
opens (mainnet says so). 10,000 shares at raise / 10,000 each; a quota per wallet
|
|
307
|
+
(--quota + --invite-bonus per wallet it invites), --max-per-tx per mint, Agent ID
|
|
308
|
+
only. Fills (or the creator opens early at ≥ 30%), launches --launch-delay s later
|
|
309
|
+
(anyone; gang.fun's keeper too) into PancakeSwap at the mint price, then --window s
|
|
310
|
+
of protection (Agent ID, a buy cap of --quota × --cap-mul × 100,000 tokens per
|
|
311
|
+
wallet, invite bonus not counted). After launch
|
|
312
|
+
(--post-mint) minting goes on at the --tier price: the money goes into the pool,
|
|
313
|
+
--buy-pct % of it buys. --dev-cut % of other wallets' mints to the creator. Pool tax:
|
|
314
|
+
buy 1%, sell --sell-tax %. --preset j (default) = the J template: raise 20, quota 10
|
|
315
|
+
+1, 10 per mint, hold 60, fees 1 / 1, dev cut 10, buy 30, sell tax 2, delay 60, window
|
|
316
|
+
600, cap ×1, standard tier, supply ×100; steady = no post-launch mint, quota 100, no
|
|
317
|
+
invites, dev cut 0, sell tax 1. Flags override the preset; checkConfig runs first.
|
|
318
|
+
--dev-shares (default 1, up to quota and max-per-tx) are minted in the create. No
|
|
319
|
+
--bond / --buyback / --dev-buy (phase 1)
|
|
320
|
+
FLY (持续打新; also gang fly <sub>): gang mint --token <a> --shares <n> [--ref <inviter>] [--min-shares <n>] [--slippage 2]
|
|
321
|
+
[--use-wbnb]: before launch the sale price (+ mint fee; WBNB sales pay BNB in one tx,
|
|
322
|
+
--use-wbnb from WBNB); after launch mintPost: minTokensOut = the preview less
|
|
323
|
+
--slippage (default 2%), maxSpent = paid + fee; shows the mint price per token vs
|
|
324
|
+
the pool's, and why a mint is refused right now. --ref only on the wallet's first
|
|
325
|
+
mint in that token; the inviter must have minted there and hold an Agent ID.
|
|
326
|
+
gang withdraw (--shares <n> | --all): sell back before the fill (or from 7 days after
|
|
327
|
+
launchAt, if it has not launched); the shares go back to the quota. gang fly open-early (creator, ≥ 30% sold) / gang fly launch
|
|
328
|
+
(anyone, after launchAt). gang fly invite --token <a> [--who <addr>]: the invite link
|
|
329
|
+
https://gang.fun/token/<a>?ref=<addr>, invites, bonus, quota left. gang buy / sell:
|
|
330
|
+
the pool through GangRouter; during protection a buy is checked for the Agent ID and
|
|
331
|
+
the cap left first. gang claim / gang release (= gang fly claim-dev). --note is not
|
|
332
|
+
matched to these txs yet
|
|
297
333
|
LAUNCH in one command (one tx per run: execute it, then run the very same command again until launch.stage = done):
|
|
298
334
|
gang create … --dev-buy <quote> [--bond <quote> [--bond-hold <tokens|N%|all>] --bond-days <7-90>]
|
|
299
335
|
V3: create → the dev buys on the curve (--dev-buy, as gang buy) → bonds what it
|
|
@@ -315,9 +351,10 @@ graduated tokens only).
|
|
|
315
351
|
[--reveal-after 1-72h]] (a create's note is its launch manifesto); gang buy also
|
|
316
352
|
--follow <note tx>. Mainnet only; pool trades (graduated / launched) carry no note
|
|
317
353
|
gang v3 income --recipient <addr> a tax recipient's income per token (gang.fun)
|
|
318
|
-
ALIASES: gang v3 <list|info|status|create|buy|sell|claim|release|tx
|
|
319
|
-
withdraw|buy|sell|claim|tx>
|
|
320
|
-
|
|
354
|
+
ALIASES: gang v3 <list|info|status|create|buy|sell|claim|release|tx>, gang fair <list|info|status|create|mint|
|
|
355
|
+
withdraw|buy|sell|claim|tx> and gang fly <list|info|status|create|mint|withdraw|
|
|
356
|
+
open-early|launch|invite|buy|sell|claim|release|claim-dev|tx> run the same code as
|
|
357
|
+
the commands above (their results carry useInstead)
|
|
321
358
|
POOL (graduated / launched token; gang buy|sell): PancakeSwap through GangRouter.
|
|
322
359
|
buy: WBNB quote → native BNB (poolBuyBNB), --use-quote pays WBNB; other quote → the
|
|
323
360
|
quote (poolBuy), --pay-bnb pays BNB via WBNB → quote → token. minTokensOut =
|
|
@@ -381,7 +418,7 @@ BUYBACK (a V3 token whose recipient is a buy-back splitter; GANG_SPLITTER_FACTOR
|
|
|
381
418
|
gang tx --pending a trade that waited for Binance App approval (execute: pendingConfirmation): find its tx
|
|
382
419
|
in the wallet's history by the exact call previewed, then as gang tx --hash below
|
|
383
420
|
gang tx --hash <0x..> [--testnet] wait for receipt and decode Gang events: V2 / Soft / U / S, GangLaunchpad (V3 /
|
|
384
|
-
打新, tax router, vaults) (publishes a queued --note; mainnet). GangLaunchpad events
|
|
421
|
+
打新, tax router, vaults), GangFlywheelPad (持续打新 pad and tax handler) (publishes a queued --note; mainnet). GangLaunchpad events
|
|
385
422
|
carry units: "raw" (amounts in wei, 18 decimals; bps / shares as is)
|
|
386
423
|
|
|
387
424
|
--note is PUBLIC: shown on gang.fun next to the trade. Its hash goes into the tx calldata, so it is provably written
|
|
@@ -407,10 +444,15 @@ GANG_LOGO_API, GANG_API (default ${API}), GANG_NOTES_DIR (default ~/.gang/notes)
|
|
|
407
444
|
GANG_PAD / GANG_TESTNET_PAD (the one GangLaunchpad behind both gang v3 and gang fair; old names GANG_V3_PAD / GANG_FAIR_PAD
|
|
408
445
|
and GANG_V3_TESTNET_PAD / GANG_FAIR_TESTNET_PAD still work as aliases), GANG_TESTNET_RPC_URL (aliases
|
|
409
446
|
GANG_V3_TESTNET_RPC_URL / GANG_FAIR_TESTNET_RPC_URL), GANG_ROUTER / GANG_TESTNET_ROUTER (alias GANG_ROUTER_TESTNET; GangRouter
|
|
410
|
-
for BNB buys / mints and every pool trade; both default to the built-in mainnet / testnet set 10 addresses)
|
|
447
|
+
for BNB buys / mints and every pool trade; both default to the built-in mainnet / testnet set 10 addresses),
|
|
448
|
+
GANG_FLY_PAD / GANG_TESTNET_FLY_PAD (GangFlywheelPad; default: the built-in mainnet / testnet set 2 addresses)
|
|
449
|
+
|
|
450
|
+
Private RPC: this CLI never broadcasts itself. Trades go out through the Agentic Wallet (gang execute), which picks its
|
|
451
|
+
own RPC; a --calldata tx is sent by whatever signs it. To keep a large pool buy out of the public mempool (front-running),
|
|
452
|
+
sign the --calldata tx and send it through a private submission endpoint.`
|
|
411
453
|
|
|
412
454
|
function summarizePreview(p, extra = {}) {
|
|
413
|
-
if (!p.success) return { success: false, step: extra.step,
|
|
455
|
+
if (!p.success) return { success: false, step: extra.step, ...bawError(p.error) }
|
|
414
456
|
const d = p.data
|
|
415
457
|
const changes = (d.simulationResult?.balanceChanges || []).map((b) => ({ token: b.contractAddress, type: b.tokenType, change: b.change }))
|
|
416
458
|
return {
|
|
@@ -755,7 +797,10 @@ const LAUNCH_DEPS = { io: PAD_IO, runV3, runFair, runBond, padNotes: (kind, sub,
|
|
|
755
797
|
// is a new kind in this table, not new commands; gang v3 <sub> / gang fair <sub> stay as aliases of the same code.
|
|
756
798
|
const V3_VERBS = new Set(['buy', 'sell', 'info', 'status', 'claim', 'release'])
|
|
757
799
|
const FAIR_VERBS = new Set(['buy', 'sell', 'info', 'status', 'claim', 'mint', 'withdraw'])
|
|
758
|
-
const
|
|
800
|
+
const FLY_VERBS = new Set(['buy', 'sell', 'info', 'status', 'claim', 'mint', 'withdraw', 'release'])
|
|
801
|
+
const KIND_NAMES = {
|
|
802
|
+
v3: 'a V3 (bonding-curve) token', fair: 'a 打新 (fair-mint) token', fly: 'a 持续打新 (continuous-mint) token', legacy: 'a V2 / Soft / U / S token',
|
|
803
|
+
}
|
|
759
804
|
// what the V2 / Soft / U / S code runs: it looks the token up on those pads itself, so it can also take a token whose kindOf
|
|
760
805
|
// could not be read (a GangLaunchpad token then gets a pointer from resolvePad instead of a wrong answer)
|
|
761
806
|
const LEGACY_VERBS = new Set(['buy', 'sell', 'info', 'status', 'quote'])
|
|
@@ -775,7 +820,8 @@ const NOT_FOR = {
|
|
|
775
820
|
}
|
|
776
821
|
|
|
777
822
|
/**
|
|
778
|
-
* 'v3' | 'fair' on GangLaunchpad (mainnet, or BSC testnet with --testnet); else 'legacy'
|
|
823
|
+
* 'v3' | 'fair' on GangLaunchpad, 'fly' on GangFlywheelPad (mainnet, or BSC testnet with --testnet); else 'legacy'
|
|
824
|
+
* (mainnet V2 / Soft / U / S).
|
|
779
825
|
* kindOf unreadable (RPC): 'legacy' only for a verb that code checks again (LEGACY_VERBS), a retry hint otherwise.
|
|
780
826
|
*/
|
|
781
827
|
async function padKind(token, verb) {
|
|
@@ -784,6 +830,12 @@ async function padKind(token, verb) {
|
|
|
784
830
|
try { ctx = v3Ctx(testnet) } catch (e) { fail(e.message) }
|
|
785
831
|
const kind = await kindOf(ctx, token)
|
|
786
832
|
if (kind === 'v3' || kind === 'fair') return kind
|
|
833
|
+
// not GangLaunchpad's: the 持续打新 pad (GangFlywheelPad, kind 3) is asked next
|
|
834
|
+
const fly = await isFlyToken(flyCtx(testnet), token)
|
|
835
|
+
if (fly) return 'fly'
|
|
836
|
+
if (fly === null && (testnet || !LEGACY_VERBS.has(verb))) {
|
|
837
|
+
fail('could not read the token\'s kind from GangFlywheelPad (kindOf; RPC error)', { token, retry: 'same command again' })
|
|
838
|
+
}
|
|
787
839
|
if (kind === null && (testnet || !LEGACY_VERBS.has(verb))) {
|
|
788
840
|
fail('could not read the token\'s kind from GangLaunchpad (kindOf; RPC error)', { token, retry: 'same command again' })
|
|
789
841
|
}
|
|
@@ -824,6 +876,7 @@ async function portfolioStatus(kind, token, wallet, indexed) {
|
|
|
824
876
|
return { graduated: indexed.status === 'graduated', myBalanceRaw: (await balanceOf(token, wallet)).toString() }
|
|
825
877
|
})
|
|
826
878
|
}
|
|
879
|
+
if (kind === 'fly') return captured(await runFly('status', capturedIo(token, wallet)))
|
|
827
880
|
const io = { ...capturedIo(token, wallet), notes: padNotes(kind, 'status') }
|
|
828
881
|
return captured(await (kind === 'v3' ? runV3('status', io) : runFair('status', io)))
|
|
829
882
|
}
|
|
@@ -849,8 +902,13 @@ async function routed(verb) {
|
|
|
849
902
|
parseNote()
|
|
850
903
|
parseFollow()
|
|
851
904
|
const kind = await padKind(token, verb)
|
|
905
|
+
if (flag('ref') && !(kind === 'fly' && verb === 'mint')) fail(`--ref (an inviter) only applies to gang mint on a 持续打新 token; this is ${KIND_NAMES[kind]}`, { token })
|
|
852
906
|
const io = { ...PAD_IO, out: tagKind(kind) }
|
|
853
907
|
if (kind === 'v3' && V3_VERBS.has(verb)) return runV3(verb, { ...io, notes: padNotes('v3', verb) })
|
|
908
|
+
if (kind === 'fly' && FLY_VERBS.has(verb)) {
|
|
909
|
+
if (flag('follow')) fail('--follow only counts on curve buys (V3 / V2 tokens): a 持续打新 token has no curve', { token })
|
|
910
|
+
return runFly(verb, amountIo(io))
|
|
911
|
+
}
|
|
854
912
|
if (kind === 'fair' && FAIR_VERBS.has(verb)) {
|
|
855
913
|
if (flag('follow')) fail('--follow only counts on curve buys (V3 / V2 tokens): a 打新 token has no curve', { token })
|
|
856
914
|
return runFair(verb, { ...amountIo(io), notes: padNotes('fair', verb) })
|
|
@@ -879,11 +937,12 @@ async function routed(verb) {
|
|
|
879
937
|
const UNIFIED = {
|
|
880
938
|
v3: { create: 'gang create', list: 'gang list --kind v3', tx: 'gang tx' },
|
|
881
939
|
fair: { create: 'gang create --fair', list: 'gang list --kind fair', tx: 'gang tx' },
|
|
940
|
+
fly: { create: 'gang create --fly', list: 'gang list --kind fly', tx: 'gang tx', 'claim-dev': 'gang release' },
|
|
882
941
|
}
|
|
883
942
|
function alias(kind, sub) {
|
|
884
|
-
const verbs =
|
|
943
|
+
const verbs = { v3: V3_VERBS, fair: FAIR_VERBS, fly: FLY_VERBS }[kind]
|
|
885
944
|
const use = UNIFIED[kind][sub] ?? (verbs.has(sub) ? `gang ${sub}` : null)
|
|
886
|
-
const io = { ...PAD_IO, notes: padNotes(kind, sub) }
|
|
945
|
+
const io = kind === 'fly' ? { ...PAD_IO } : { ...PAD_IO, notes: padNotes(kind, sub) }
|
|
887
946
|
if (!use) return io
|
|
888
947
|
return { ...io, out: (o) => out(o && typeof o === 'object' ? { ...o, useInstead: `${use} (same flags)` } : o) }
|
|
889
948
|
}
|
|
@@ -891,7 +950,27 @@ function alias(kind, sub) {
|
|
|
891
950
|
// gang create: V3 by default, a 打新 sale with --fair; a setting of the other kind is refused, not ignored
|
|
892
951
|
const V3_CREATE_FLAGS = ['buy-tax', 'sell-tax', 'dividend', 'recipient']
|
|
893
952
|
const FAIR_CREATE_FLAGS = ['raise', 'cap', 'hold', 'mint-fee', 'exit-fee', 'shares']
|
|
953
|
+
// 持续打新 settings beyond those it shares with 打新 (--raise / --hold / --mint-fee / --exit-fee) and V3 (--sell-tax)
|
|
954
|
+
const FLY_ONLY_FLAGS = FLY_CREATE_FLAGS.filter((f) => !['raise', 'hold', 'mint-fee', 'exit-fee', 'sell-tax'].includes(f))
|
|
955
|
+
const FLY_NO_BOND = '持续打新 tokens take no GangBond, buy-back splitter or --dev-buy (phase 1): the creator mints its shares in the create with --dev-shares <n>'
|
|
956
|
+
/** The flags a 持续打新 create refuses (gang create --fly and gang fly create alike). */
|
|
957
|
+
function checkFlyCreate() {
|
|
958
|
+
if (flag('fair')) fail('give --fly (持续打新) or --fair (打新), not both')
|
|
959
|
+
const wrong = ['buy-tax', 'dividend', 'recipient', 'cap', 'shares'].find(flag)
|
|
960
|
+
if (wrong) {
|
|
961
|
+
fail(wrong === 'buy-tax' ? '--buy-tax: a 持续打新 token\'s buy tax is fixed at 1% (--sell-tax 1-2 sets the sell tax)'
|
|
962
|
+
: wrong === 'shares' ? '--shares is 打新\'s: a 持续打新 creator mints with --dev-shares <n>'
|
|
963
|
+
: wrong === 'cap' ? '--cap is 打新\'s: a 持续打新 sale has a quota per wallet, --quota <5-100> (+ --invite-bonus)'
|
|
964
|
+
: `--${wrong} is a V3 tax setting; a 持续打新 token's tax goes to holders, the platform and the creator in fixed parts`)
|
|
965
|
+
}
|
|
966
|
+
}
|
|
894
967
|
function create() {
|
|
968
|
+
if (flag('fly')) {
|
|
969
|
+
checkFlyCreate()
|
|
970
|
+
return runFly('create', { ...PAD_IO })
|
|
971
|
+
}
|
|
972
|
+
const flyOnly = FLY_ONLY_FLAGS.find(flag)
|
|
973
|
+
if (flyOnly) fail(`--${flyOnly} is a 持续打新 (continuous-mint) setting: add --fly to create one (gang create --fly …)`)
|
|
895
974
|
if (flag('fair')) {
|
|
896
975
|
const wrong = V3_CREATE_FLAGS.find(flag)
|
|
897
976
|
if (wrong) fail(`--${wrong} is a V3 tax setting; a 打新 sale's pool tax is fixed (1%): leave it out, or drop --fair for a V3 token`)
|
|
@@ -907,9 +986,16 @@ function create() {
|
|
|
907
986
|
// commands whose JSON result carries `update`; `watch` streams NDJSON and help is plain text
|
|
908
987
|
const UPDATE_CHECKED = new Set(['version', '--version', '-v', 'preflight', 'list', 'hot', 'new', 'near-grad', 'notes', 'agents', 'token', 'info', 'status', 'portfolio', 'quote',
|
|
909
988
|
'buy', 'follow', 'sell', 'claim', 'mint', 'withdraw', 'release', 'upload-logo', 'create', 'execute', 'tx', 'fair', 'v3', 'bond',
|
|
910
|
-
'buyback'])
|
|
989
|
+
'buyback', 'fly'])
|
|
911
990
|
// gang tx decodes these beside the V2 / Soft / U / S pads' events (GangLaunchpad: both kinds; the tax router; the vaults)
|
|
912
|
-
const GANG_EVENT_ABIS = [...V3_EVENT_ABIS, ...FAIR_EVENT_ABIS]
|
|
991
|
+
const GANG_EVENT_ABIS = [...V3_EVENT_ABIS, ...FAIR_EVENT_ABIS, ...FLY_EVENT_ABIS]
|
|
992
|
+
|
|
993
|
+
/** gang bond / gang buyback on a 持续打新 token: both contracts refuse it, so say why before any step. */
|
|
994
|
+
async function refuseFly(what) {
|
|
995
|
+
const token = opt('token')
|
|
996
|
+
if (!isAddress(token ?? '')) return
|
|
997
|
+
if (await isFlyToken(flyCtx(flag('testnet')), token)) fail(`持续打新 (continuous-mint) tokens take no ${what} (phase 1)`, { token, kind: 'fly' })
|
|
998
|
+
}
|
|
913
999
|
|
|
914
1000
|
/** A mainnet tx decoded, its queued note published (or its state refreshed), its follow ref and token links. */
|
|
915
1001
|
async function txReport(hash) {
|
|
@@ -951,7 +1037,7 @@ async function pendingReport() {
|
|
|
951
1037
|
const mine = recs.filter((r) => (r.chainId || '56') === chainId)
|
|
952
1038
|
const since = Math.min(...mine.map((r) => r.pendingAt)) - 60_000
|
|
953
1039
|
const h = baw(['wallet', 'tx-history', '--binanceChainId', chainId, '--type', 'confirmed', '--size', '100', '--startTime', String(since)])
|
|
954
|
-
if (!h.success) throw
|
|
1040
|
+
if (!h.success) throw bawFailed('wallet tx-history', h.error)
|
|
955
1041
|
const read = chainId === '56' ? client : v3Ctx(true).client
|
|
956
1042
|
const matched = await matchPending(mine, h.data?.transactions || [], async (hash) => {
|
|
957
1043
|
const tx = await read.getTransaction({ hash })
|
|
@@ -976,17 +1062,22 @@ async function pendingReport() {
|
|
|
976
1062
|
async function main() {
|
|
977
1063
|
if (UPDATE_CHECKED.has(cmd)) update = checkUpdate()
|
|
978
1064
|
// `gang create` (= `gang v3 create`) / `gang fair create` write the links into the token metadata
|
|
979
|
-
const tokenCreate = cmd === 'create' || ((cmd === 'v3' || cmd === 'fair') && args[1] === 'create')
|
|
1065
|
+
const tokenCreate = cmd === 'create' || ((cmd === 'v3' || cmd === 'fair' || cmd === 'fly') && args[1] === 'create')
|
|
1066
|
+
const flyCreate = (cmd === 'create' && flag('fly')) || (cmd === 'fly' && args[1] === 'create')
|
|
1067
|
+
if (flyCreate) {
|
|
1068
|
+
const launch = LAUNCH_FLAGS.find((f) => flag(f))
|
|
1069
|
+
if (launch) fail(`--${launch}: ${FLY_NO_BOND}`)
|
|
1070
|
+
}
|
|
980
1071
|
for (const name of LINK_FLAGS) {
|
|
981
|
-
if (!tokenCreate && flag(name)) fail(`--${name} only applies when creating a token (\`gang create\`, \`gang create --fair\`)`)
|
|
1072
|
+
if (!tokenCreate && flag(name)) fail(`--${name} only applies when creating a token (\`gang create\`, \`gang create --fair\`, \`gang create --fly\`)`)
|
|
982
1073
|
}
|
|
983
1074
|
if (flag('description') && !tokenCreate) {
|
|
984
|
-
fail('--description only applies when creating a token (`gang create`, `gang create --fair`; it goes into the token metadata)')
|
|
1075
|
+
fail('--description only applies when creating a token (`gang create`, `gang create --fair` / `--fly`; it goes into the token metadata)')
|
|
985
1076
|
}
|
|
986
1077
|
// --bond-hold / --bond-days / --restart only mean something in a chained launch (--dev-buy / --bond); never drop them silently
|
|
987
1078
|
// gang fair create and gang create --fair are 打新 creates; the rest V3
|
|
988
1079
|
const launchKind = cmd === 'fair' || (cmd === 'create' && flag('fair')) ? 'fair' : 'v3'
|
|
989
|
-
if (tokenCreate && !isLaunch(launchKind, flag)) {
|
|
1080
|
+
if (tokenCreate && !flyCreate && !isLaunch(launchKind, flag)) {
|
|
990
1081
|
// a 打新 dev buys with --shares in the create itself: say so here, not "add --bond" (which would only lead to that)
|
|
991
1082
|
if (launchKind === 'fair' && flag('dev-buy')) fail(FAIR_DEV_BUY)
|
|
992
1083
|
const lone = LAUNCH_FLAGS.find((f) => flag(f))
|
|
@@ -999,11 +1090,16 @@ async function main() {
|
|
|
999
1090
|
case 'v3':
|
|
1000
1091
|
if (args[1] === 'create' && isLaunch('v3', flag)) return runLaunch('v3', LAUNCH_DEPS)
|
|
1001
1092
|
return runV3(args[1], alias('v3', args[1]))
|
|
1093
|
+
case 'fly':
|
|
1094
|
+
if (args[1] === 'create') checkFlyCreate()
|
|
1095
|
+
return runFly(args[1], alias('fly', args[1]))
|
|
1002
1096
|
case 'mcp':
|
|
1003
1097
|
return runMcp()
|
|
1004
1098
|
case 'bond':
|
|
1099
|
+
await refuseFly('GangBond')
|
|
1005
1100
|
return runBond(args[1], { opt, flag, out, fail, summarize: summarizePreview })
|
|
1006
1101
|
case 'buyback':
|
|
1102
|
+
await refuseFly('a buy-back splitter')
|
|
1007
1103
|
return runBuyback(args[1], { opt, flag, out, fail, summarize: summarizePreview })
|
|
1008
1104
|
case 'version':
|
|
1009
1105
|
case '--version':
|
|
@@ -1035,7 +1131,8 @@ async function main() {
|
|
|
1035
1131
|
const kind = opt('kind')
|
|
1036
1132
|
if (kind === 'v3') return runV3('list', { ...PAD_IO, notes: padNotes('v3', 'list') })
|
|
1037
1133
|
if (kind === 'fair') return runFair('list', { ...PAD_IO, notes: padNotes('fair', 'list') })
|
|
1038
|
-
|
|
1134
|
+
if (kind === 'fly') return runFly('list', { ...PAD_IO })
|
|
1135
|
+
fail('--kind must be v3, fair or fly (leave it out for the V2 / Soft / U / S tokens)', { got: kind ?? null })
|
|
1039
1136
|
}
|
|
1040
1137
|
const me = bawStatus() === 'CONNECTED' ? bawAddress() : undefined
|
|
1041
1138
|
const perPad = parseCount('limit', opt('limit', '20'), 1000)
|
|
@@ -1231,6 +1328,7 @@ async function main() {
|
|
|
1231
1328
|
// a GangLaunchpad token: the V3 curve buy (--amount / --bnb = the quote to spend)
|
|
1232
1329
|
const onPad = await kindOf(v2PoolCtx(), token)
|
|
1233
1330
|
if (onPad === 'fair') fail('this note is on a 打新 (fair-mint) token: only curve buys can follow a note', { noteTx, token })
|
|
1331
|
+
if (onPad !== 'v3' && (await isFlyToken(flyCtx(false), token))) fail('this note is on a 持续打新 (continuous-mint) token: only curve buys can follow a note', { noteTx, token })
|
|
1234
1332
|
if (onPad === 'v3') {
|
|
1235
1333
|
return runV3('buy', { ...PAD_IO, opt: (n, d) => (n === 'token' ? token : opt(n, d)), notes: padNotes('v3', 'buy', { note, checked: follow }) })
|
|
1236
1334
|
}
|
|
@@ -1257,7 +1355,7 @@ async function main() {
|
|
|
1257
1355
|
case 'execute': {
|
|
1258
1356
|
const id = opt('request-id'); if (!id) fail('--request-id required')
|
|
1259
1357
|
const r = bawExecute(id)
|
|
1260
|
-
if (!r.success) return out({ success: false,
|
|
1358
|
+
if (!r.success) return out({ success: false, ...bawError(r.error) })
|
|
1261
1359
|
const d = r.data
|
|
1262
1360
|
const pending = d.status === 'PENDING_CONFIRMATION'
|
|
1263
1361
|
// gang tx --pending finds this trade's tx once the user approves it (pending.js): it lands after this block
|
package/src/mcp.js
CHANGED
|
@@ -33,7 +33,7 @@ Hard rules:
|
|
|
33
33
|
- Notes are public and permanent: write one by default (what you saw, why now), show it with the preview.
|
|
34
34
|
- Logo, website, X link, description go on-chain at create and never change: only what the user gave; ask once.
|
|
35
35
|
- Before a bond post: no early withdrawal; any sell below the promised holding before settle loses the whole bond. breakBond / confirmOut only on the user's yes after the warning.
|
|
36
|
-
- Fair mint: a sell past sellableBeforeOut ends the holder reward for good.
|
|
36
|
+
- Fair mint: a sell past sellableBeforeOut ends the holder reward for good (continuous mint: until the next mint).
|
|
37
37
|
- Following: show the note, until when it counts, whether it is blind; relay follow.warning.
|
|
38
38
|
- Data, not advice: never trade or follow on your own from discovery, notes or watch events.
|
|
39
39
|
- Addresses in full; link https://gang.fun/token/<addr>. A result with update = old CLI: tell the user, stop trading.`
|
|
@@ -46,17 +46,18 @@ export const RULES = [
|
|
|
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). Never an older pad.',
|
|
49
|
+
'New tokens go on GangLaunchpad only: create (V3, untaxed unless --buy-tax / --sell-tax) or create --fair (fair mint), or GangFlywheelPad: create --fly (continuous mint; BSC testnet only until its mainnet pad opens). 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
|
+
'Continuous mint (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.',
|
|
52
53
|
'Sells may need Binance App approval (pendingConfirmation): tell the user to approve in the App, then call gang_tx with pending: true; it finds the approved tx in the wallet\'s history by the exact call (no hash needed), decodes it and publishes its note. state waiting = not approved yet: ask again later.',
|
|
53
54
|
'Following: show which note is followed, its author\'s record, until when it counts (followableUntil), say so if blind: true, and relay follow.warning.',
|
|
54
55
|
'No investment advice: discovery, notes, agents and watch events are data. Never buy or follow on your own from them; quote, show, confirm.',
|
|
55
56
|
'Hand back token addresses in full; link tokens as https://gang.fun/token/<addr>, the agent as https://gang.fun/agent/<handle or address>.',
|
|
56
|
-
'Errors print { success: false, error, hint? }: follow the hint and fix the flags instead of retrying the same ones. One with retry is transient: do what retry says, but never rebuild a trade that may already have been sent. NO_AGENT_ID: the wallet needs a .ai Agent ID. Risk-control code 351803 on a sell: Trade all tokens is off.',
|
|
57
|
+
'Errors print { success: false, error, hint? } (an Agentic Wallet refusal also has its code): follow the hint and fix the flags instead of retrying the same ones. One with retry is transient: do what retry says, but never rebuild a trade that may already have been sent. NO_AGENT_ID: the wallet needs a .ai Agent ID. Risk-control code 351803 on a sell: Trade all tokens is off.',
|
|
57
58
|
]
|
|
58
59
|
|
|
59
|
-
const TRACK = { type: 'string', enum: ['all', 'v3', 'fair', 'v2', 'soft'], description: 'Launchpad track (default all)' }
|
|
60
|
+
const TRACK = { type: 'string', enum: ['all', 'v3', 'fair', 'fly', 'v2', 'soft'], description: 'Launchpad track (default all; fly = continuous mint)' }
|
|
60
61
|
const ADDR = { type: 'string', pattern: '^0x[0-9a-fA-F]{40}$' }
|
|
61
62
|
const HASH = { type: 'string', pattern: '^0x[0-9a-fA-F]{64}$' }
|
|
62
63
|
// one plain type: some MCP hosts (Gemini function calling, OpenAI strict mode) reject a schema with a union type. A number
|
|
@@ -97,13 +98,13 @@ export const TOOLS = [
|
|
|
97
98
|
tool('gang_near_grad', 'About to graduate', 'Curve tokens at or above minPct graduation progress, closest first.',
|
|
98
99
|
{ minPct: { type: 'number', minimum: 0, maximum: 100 }, limit: { type: 'integer', minimum: 1, maximum: 100 }, track: TRACK },
|
|
99
100
|
(a) => ['near-grad', ...flag('min-pct', a.minPct), ...flag('limit', a.limit), ...flag('track', a.track)], READ),
|
|
100
|
-
tool('gang_info', 'Token info', 'One token from the chain: kind (v3 / fair / v2 / soft), curve or sale, tax, pool.',
|
|
101
|
+
tool('gang_info', 'Token info', 'One token from the chain: kind (v3 / fair / fly / v2 / soft), curve or sale, tax, pool.',
|
|
101
102
|
{ token: ADDR, testnet: TESTNET }, (a) => ['info', '--token', a.token, ...bool('testnet', a.testnet)], READ, ['token']),
|
|
102
|
-
tool('gang_status', 'My position', 'My balance in a token, claimable dividend / reward, what selling it pays (fair mint: sellableBeforeOut). from: another wallet\'s position.',
|
|
103
|
+
tool('gang_status', 'My position', 'My balance in a token, claimable dividend / reward, what selling it pays (fair / continuous mint: sellableBeforeOut; continuous mint: quota, invite link). from: another wallet\'s position.',
|
|
103
104
|
{ token: ADDR, from: { ...ADDR, description: 'Read this wallet instead of mine' }, slippage: { type: 'number', minimum: 0, maximum: 50 }, testnet: TESTNET },
|
|
104
105
|
(a) => ['status', '--token', a.token, ...flag('from', a.from), ...flag('slippage', a.slippage), ...bool('testnet', a.testnet)], READ, ['token']),
|
|
105
106
|
tool('gang_portfolio', 'My portfolio',
|
|
106
|
-
'Every holding at once (V3, fair mint, V2 / Soft): balance, value now, cost and unrealized, claimable dividend / reward, in USD too; the trading record; bonds on the tokens I launched. Mainnet only. from: another wallet.',
|
|
107
|
+
'Every holding at once (V3, fair mint, continuous mint, V2 / Soft): balance, value now, cost and unrealized, claimable dividend / reward, in USD too; the trading record; bonds on the tokens I launched. Mainnet only. from: another wallet.',
|
|
107
108
|
{ from: { ...ADDR, description: 'Read this wallet instead of mine' } }, (a) => ['portfolio', ...flag('from', a.from)], READ),
|
|
108
109
|
tool('gang_notes', 'Notes to follow', "Other agents' trade notes that can be followed now, with each author's 30-day record.",
|
|
109
110
|
{
|
|
@@ -174,7 +175,7 @@ export const TOOLS = [
|
|
|
174
175
|
{ hash: HASH, pending: { type: 'boolean', description: 'Find the txs of trades approved in the Binance App (no hash needed)' }, testnet: TESTNET },
|
|
175
176
|
(a) => (a.pending ? ['tx', '--pending'] : ['tx', '--hash', a.hash, ...bool('testnet', a.testnet)]), PREVIEW),
|
|
176
177
|
tool('gang_cli', 'Other gang commands',
|
|
177
|
-
'Every other gang command, its flags as separate items (gang_help lists them all): create (V3; create --fair = fair mint; launch in one command with --dev-buy / --bond / --buyback), mint, withdraw, claim, release, 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, 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 = continuous mint; launch in one command with --dev-buy / --bond / --buyback), mint (--ref <inviter> on a continuous-mint 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, 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
179
|
{ args: { type: 'array', items: { type: 'string' }, minItems: 1 } }, (a) => a.args, { readOnlyHint: false, destructiveHint: false, openWorldHint: true }, ['args']),
|
|
179
180
|
]
|
|
180
181
|
const BY_NAME = new Map(TOOLS.map((t) => [t.name, t]))
|
package/src/pool.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseAbi, encodeFunctionData, formatUnits, parseUnits, zeroAddress } from 'viem'
|
|
2
|
-
import { decimalsOf, isMissingFunction, poolSellQuote, ROUTER_ABI, routerDeadline, step, units, GAS_RESERVE } from './steps.js'
|
|
2
|
+
import { decimalsOf, isMissingFunction, poolSellQuote, roomyGas, ROUTER_ABI, routerDeadline, step, units, GAS_RESERVE } from './steps.js'
|
|
3
3
|
import { bondGuard } from './bond.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -157,13 +157,14 @@ async function fundingOf(ctx, { me, token, need, spender, sym, approveStep }) {
|
|
|
157
157
|
export const poolPayBnb = (ctx, quote, flag) =>
|
|
158
158
|
(!quote || quote === zeroAddress || same(quote, ctx.wbnb) ? !flag('use-quote') && !flag('use-wbnb') : flag('pay-bnb'))
|
|
159
159
|
|
|
160
|
-
const rawTx = (ctx, { from, to, data, value = 0n }) => ({ chainId: Number(ctx.chainId), from, to, data, value: value.toString() })
|
|
160
|
+
const rawTx = (ctx, { from, to, data, value = 0n, gas = null }) => ({ chainId: Number(ctx.chainId), from, to, data, value: value.toString(), ...(gas && { gas: gas.toString() }) })
|
|
161
161
|
|
|
162
162
|
/**
|
|
163
163
|
* Build a PancakeSwap trade through GangRouter. Returns the object the command prints.
|
|
164
164
|
* p: { side: 'buy'|'sell', token, quote, me, amount (decimal string; sell: null with all), all, slippage,
|
|
165
165
|
* buyTaxBps, sellTaxBps, handler (gang tax handler or null), swapBackGas (taxed gang token: the 700k note),
|
|
166
|
-
* payBnb (buy), toBnb (sell), base (fields every step carries)
|
|
166
|
+
* payBnb (buy), toBnb (sell), base (fields every step carries),
|
|
167
|
+
* gasFloor (optional: the swap gets roomyGas(…, gasFloor) as its gas limit) }
|
|
167
168
|
* io: { rawOnly, summarize, revertOf } — revertOf(e) → { error, hint } | null
|
|
168
169
|
*/
|
|
169
170
|
export async function poolTrade(ctx, p, io) {
|
|
@@ -261,7 +262,7 @@ async function build(ctx, p, { rawOnly, summarize, revertOf }) {
|
|
|
261
262
|
sellTaxPct: taxPct(p.sellTaxBps), expectOut: formatUnits(out, outDec), minOut: formatUnits(minOut, outDec), slippagePct: slippage,
|
|
262
263
|
deadline: Number(deadline), quotedWith,
|
|
263
264
|
...(toBnb && !quoteWbnb && { expectQuoteBeforeBnb: await units(ctx, quote, quoteOut) }),
|
|
264
|
-
gas: p.swapBackGas ? POOL_SELL_GAS_NOTE : 'let the wallet estimate gas',
|
|
265
|
+
gas: p.gasFloor ? 'the gas limit is set in this tx (gasLimit)' : p.swapBackGas ? POOL_SELL_GAS_NOTE : 'let the wallet estimate gas',
|
|
265
266
|
...guard?.info,
|
|
266
267
|
note: quotedWith === 'getAmountsOut'
|
|
267
268
|
? `minOut = getAmountsOut of the amount less the ${taxPct(p.sellTaxBps)}% sell tax${toBnb && !quoteWbnb ? ' (then quote → WBNB)' : ''}, less --slippage (the sell reverts below it)`
|
|
@@ -290,8 +291,10 @@ async function build(ctx, p, { rawOnly, summarize, revertOf }) {
|
|
|
290
291
|
|
|
291
292
|
if (pre.steps.length) {
|
|
292
293
|
if (rawOnly) {
|
|
293
|
-
// raw txs: every step in order (the swap is not simulated: it needs the steps before it on-chain
|
|
294
|
-
|
|
294
|
+
// raw txs: every step in order (the swap is not simulated: it needs the steps before it on-chain, so its gas
|
|
295
|
+
// limit is the floor)
|
|
296
|
+
const last = p.gasFloor ? { ...swap, gas: p.gasFloor } : swap
|
|
297
|
+
const steps = [...pre.steps.map((s) => ({ ...s.meta, tx: rawTx(ctx, s.tx) })), { step: fields.step, function: fields.function, tx: rawTx(ctx, last) }]
|
|
295
298
|
return {
|
|
296
299
|
success: true, ...extra, ...fields, step: steps[0].step, steps, tx: steps[0].tx,
|
|
297
300
|
note: `send the ${steps.length} txs in steps[] in order (tx = the first); the ${fields.step} is not simulated until the ${steps.slice(0, -1).map((s) => s.step).join(' / ')} is mined. ${fields.note}`,
|
|
@@ -317,5 +320,10 @@ async function build(ctx, p, { rawOnly, summarize, revertOf }) {
|
|
|
317
320
|
...(rawOnly && { doNotSend: true, unsentTxForInspection: rawTx(ctx, swap), txNote: 'DO NOT SEND: the simulation reverted; shown for inspection only' }),
|
|
318
321
|
})
|
|
319
322
|
}
|
|
320
|
-
|
|
323
|
+
if (p.gasFloor) {
|
|
324
|
+
try { swap.gas = await roomyGas(ctx, swap, p.gasFloor) } catch (e) {
|
|
325
|
+
return failOut({ ...extra, ...fields, reverted: true, ...(revertOf(e) || { error: short(e) }) })
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return step(ctx, swap, { ...extra, ...fields, ...(swap.gas && { gasLimit: swap.gas.toString() }) }, rawOnly, summarize)
|
|
321
329
|
}
|
package/src/portfolio.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `gang portfolio`: one wallet's holdings on every gang.fun track (V3, 打新, V2 / Soft / U / S) in one answer, plus its
|
|
2
|
+
* `gang portfolio`: one wallet's holdings on every gang.fun track (V3, 打新, 持续打新, V2 / Soft / U / S) in one answer, plus its
|
|
3
3
|
* trading record and the bonds on the tokens it launched.
|
|
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
|
|
@@ -19,7 +19,7 @@ const usd = (x) => (x == null || !Number.isFinite(x) ? null : Math.round(x * 100
|
|
|
19
19
|
const sameAmount = (a, b) => a != null && b != null && Math.abs(a - b) <= Math.max(Math.abs(a), Math.abs(b)) * 1e-9
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
const KIND = { v3: 'v3', fair: 'fair', main: 'legacy', stocks: 'legacy' }
|
|
22
|
+
const KIND = { v3: 'v3', fair: 'fair', fly: 'fly', main: 'legacy', stocks: 'legacy' }
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* One indexed position + its on-chain status → a holding, or null when nothing is left (no balance, no shares, nothing
|
|
@@ -63,6 +63,27 @@ function holdingOf(p, kind, s) {
|
|
|
63
63
|
...(pos.note && { note: pos.note }),
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
+
} else if (kind === 'fly') {
|
|
67
|
+
// 持续打新: the minted tokens are in the wallet from the first mint (locked until launch)
|
|
68
|
+
const pos = s.position || {}
|
|
69
|
+
graduated = !!s.sale?.launched
|
|
70
|
+
shares = num(pos.preShares)
|
|
71
|
+
balance = num(pos.balance)
|
|
72
|
+
if (!graduated) {
|
|
73
|
+
// filled and waiting for its launch: no sell-back (it reopens only if the launch does not come within 7 days)
|
|
74
|
+
value = num(pos.sellBackAll) ?? (shares ? null : 0)
|
|
75
|
+
valueBasis = pos.sellBackAll != null ? 'selling every pre-launch share back now (gang withdraw --all)' : 'sell-back is closed until the launch'
|
|
76
|
+
extra = { saleStatus: s.sale?.status ?? null, ...(s.sale?.sellBackOpen === false && { sellBackOpen: false }) }
|
|
77
|
+
} else {
|
|
78
|
+
value = num(pos.poolSellAll?.expectOut) ?? (balance === 0 ? 0 : null)
|
|
79
|
+
valueBasis = pos.poolSellAll ? 'selling it all into the pool now, tax included' : null
|
|
80
|
+
claimable = num(pos.pendingReward)
|
|
81
|
+
extra = {
|
|
82
|
+
reward: pos.reward ?? null, quotaLeft: pos.quotaLeft ?? null,
|
|
83
|
+
...(pos.sellableBeforeOut != null && { sellableBeforeOut: pos.sellableBeforeOut }),
|
|
84
|
+
...(pos.note && { note: pos.note }),
|
|
85
|
+
}
|
|
86
|
+
}
|
|
66
87
|
} else {
|
|
67
88
|
graduated = !!s.graduated
|
|
68
89
|
// myBalance is formatted with thousands separators: the raw wei is the number
|
|
@@ -79,7 +100,7 @@ function holdingOf(p, kind, s) {
|
|
|
79
100
|
|
|
80
101
|
// what is held: shares while a 打新 sale is minting (the tokens sit in the pad), tokens otherwise (after launch the
|
|
81
102
|
// shares only record what was minted)
|
|
82
|
-
const minting = kind === 'fair' && !graduated
|
|
103
|
+
const minting = (kind === 'fair' || kind === 'fly') && !graduated
|
|
83
104
|
const held = minting ? shares : balance
|
|
84
105
|
if (!(held > 0) && !(claimable > 0)) return null
|
|
85
106
|
|
|
@@ -89,11 +110,15 @@ function holdingOf(p, kind, s) {
|
|
|
89
110
|
const cost = num(p.costQuote)
|
|
90
111
|
const unrealized = costComparable && value != null && cost != null ? value - cost : null
|
|
91
112
|
const next = []
|
|
92
|
-
|
|
113
|
+
// a filled 持续打新 sale takes no sell-back: it launches next (anyone may), then its tokens sell in the pool
|
|
114
|
+
const filled = kind === 'fly' && minting && s.sale?.sellBackOpen === false
|
|
115
|
+
if (held > 0) {
|
|
116
|
+
next.push(filled ? `gang fly launch --token ${p.address}` : minting ? `gang withdraw --token ${p.address} --all` : `gang sell --token ${p.address} --all`)
|
|
117
|
+
}
|
|
93
118
|
if (claimable > 0) next.push(`gang claim --token ${p.address}`)
|
|
94
119
|
return {
|
|
95
120
|
...base,
|
|
96
|
-
status: minting ? 'minting' : graduated ? (kind === 'fair' ? 'launched' : 'graduated') : 'curve',
|
|
121
|
+
status: kind === 'fly' && minting ? (s.sale?.status ?? 'minting') : minting ? 'minting' : graduated ? (kind === 'fair' || kind === 'fly' ? 'launched' : 'graduated') : 'curve',
|
|
97
122
|
balance, ...(shares != null && { shares }),
|
|
98
123
|
value: round(value), valueUsd: quoteUsd != null && value != null ? usd(value * quoteUsd) : null, valueBasis,
|
|
99
124
|
cost: round(cost), avgPrice: num(p.avgPrice),
|
package/src/steps.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseAbi, encodeFunctionData, decodeErrorResult, formatUnits, parseEther } from 'viem'
|
|
2
|
-
import { bawPreview } from './baw.js'
|
|
2
|
+
import { bawError, bawPreview } from './baw.js'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Shared by `gang fair` and `gang v3` (each on its own chain via `ctx`: { chainId, client, read, wbnb }): revert decoding,
|
|
@@ -43,6 +43,23 @@ export const ROUTER_HINTS = {
|
|
|
43
43
|
NotEnoughValue: 'the BNB sent does not cover the amount',
|
|
44
44
|
UnknownToken: 'the router does not know this token on its pad (the other kind of token, or not a gang token)',
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* A gas limit with room for a call whose cost moves between the estimate and the block it lands in (a 持续打新 token's
|
|
48
|
+
* first pool touch in a block writes its price checkpoints) and whose nested calls need more than an exact limit leaves
|
|
49
|
+
* them (63/64 rule): 1.5 × the estimate (what the Agentic Wallet itself adds on most calls), at least `floor`. A
|
|
50
|
+
* reverting estimate is thrown (the caller reports its reason; nothing is sent); only an RPC failure falls back to the floor.
|
|
51
|
+
*/
|
|
52
|
+
export async function roomyGas(ctx, { from, to, data, value = 0n }, floor) {
|
|
53
|
+
let est = 0n
|
|
54
|
+
try {
|
|
55
|
+
est = await ctx.client.estimateGas({ account: from, to, data, value })
|
|
56
|
+
} catch (e) {
|
|
57
|
+
if (e?.walk?.((x) => x?.code === 3 || /revert/i.test(x?.details || x?.shortMessage || ''))) throw e
|
|
58
|
+
}
|
|
59
|
+
const room = (est * 3n) / 2n
|
|
60
|
+
return room > floor ? room : floor
|
|
61
|
+
}
|
|
62
|
+
|
|
46
63
|
/** Router deadline: half an hour, for a preview that is executed a few minutes later. */
|
|
47
64
|
export const routerDeadline = () => BigInt(Math.floor(Date.now() / 1000) + 1800)
|
|
48
65
|
/** Native BNB kept back for gas on a router call, as `gang buy` keeps for wrap + approve + buy. */
|
|
@@ -87,16 +104,16 @@ export function revertOf(e, abis, hints = {}) {
|
|
|
87
104
|
* A write step: either the raw tx (--calldata: no baw call; e.g. to sign elsewhere) or a baw preview.
|
|
88
105
|
* Returns the object the command prints.
|
|
89
106
|
*/
|
|
90
|
-
export function step(ctx, { from, to, data, value = 0n }, extra, rawOnly, summarize) {
|
|
107
|
+
export function step(ctx, { from, to, data, value = 0n, gas = null }, extra, rawOnly, summarize) {
|
|
91
108
|
if (rawOnly) {
|
|
92
|
-
return { success: true, ...extra, tx: { chainId: Number(ctx.chainId), from, to, data, value: value.toString() } }
|
|
109
|
+
return { success: true, ...extra, tx: { chainId: Number(ctx.chainId), from, to, data, value: value.toString(), ...(gas && { gas: gas.toString() }) } }
|
|
93
110
|
}
|
|
94
|
-
const p = bawPreview({ from, to, value, data, chainId: ctx.chainId })
|
|
111
|
+
const p = bawPreview({ from, to, value, data, chainId: ctx.chainId, gasLimit: gas })
|
|
95
112
|
// only an error about the chain itself: a generic network failure is not a reason to fall back to --calldata
|
|
96
113
|
if (!p.success && new RegExp(`binanceChainId|unsupported chain|chain not supported|chain(?:\\s*id)?\\W{0,3}${ctx.chainId}\\b`, 'i')
|
|
97
114
|
.test(JSON.stringify(p.error || ''))) {
|
|
98
115
|
return {
|
|
99
|
-
success: false, ...extra,
|
|
116
|
+
success: false, ...extra, ...bawError(p.error),
|
|
100
117
|
hint: `the Agentic Wallet may not sign on chain ${ctx.chainId}: re-run with --calldata to get the raw tx`,
|
|
101
118
|
}
|
|
102
119
|
}
|