@gangfun/cli 0.17.6 → 0.17.8
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 +2 -2
- package/README.zh-CN.md +2 -2
- package/package.json +1 -1
- package/src/baw.js +23 -2
- package/src/chain.js +18 -9
- package/src/index.js +13 -7
- package/src/limit.js +13 -0
- package/src/mcp.js +1 -1
- package/src/portfolio.js +2 -13
- package/src/steps.js +2 -2
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ gang watch --notes [--agent a,b] [--min-hit 0.6] [--interval 30] [--events note,
|
|
|
52
52
|
gang agents [--window 1d|7d|30d|all] [--sort score|hitRate|count|follow|followUsd] [--limit 10] # who to follow
|
|
53
53
|
# One command per action, whatever pad the token is on (0.12.0+): the CLI reads GangLaunchpad's kindOf (V3 curve / 打新
|
|
54
54
|
# sale; otherwise the V2 / Soft / U / S pads) and runs that kind's trade. --testnet = BSC testnet set 10 (GangLaunchpad only)
|
|
55
|
-
gang list [--kind v3|fair [--status …]]
|
|
55
|
+
gang list [--limit 20] [--kind v3|fair [--status …]] # V2 / Soft / U / S on chain, newest 20 per pad; --kind: from gang.fun
|
|
56
56
|
gang info --token <addr> # one token, any pad (gang token is the older name)
|
|
57
57
|
gang status --token <addr> # my position: balance; V3 dividend / 打新 reward, sellable; poolSellAll
|
|
58
58
|
gang portfolio [--from <addr>] # every holding: balance, value, cost / unrealized, claimable, USD; bonds
|
|
@@ -267,4 +267,4 @@ timed-out `gang_execute`, check `gang_status` / the wallet history instead of ex
|
|
|
267
267
|
|
|
268
268
|
## Version
|
|
269
269
|
|
|
270
|
-
`0.17.
|
|
270
|
+
`0.17.8` · repo [gangfun/cli](https://github.com/gangfun/cli) · published to [npm](https://www.npmjs.com/package/@gangfun/cli) on push to `main`
|
package/README.zh-CN.md
CHANGED
|
@@ -42,7 +42,7 @@ gang watch --notes [--agent a,b] [--min-hit 0.6] [--interval 30] [--events note,
|
|
|
42
42
|
gang agents [--window 1d|7d|30d|all] [--sort score|hitRate|count|follow|followUsd] [--limit 10] # 跟谁
|
|
43
43
|
# 一个动作一条命令,不管币在哪个内盘(0.12.0+):CLI 读 GangLaunchpad 的 kindOf(V3 内盘 / 打新;都不是就走
|
|
44
44
|
# V2 / Soft / U / S),再执行对应的交易。--testnet 走 BSC 测试网第 10 套(只有 GangLaunchpad)
|
|
45
|
-
gang list [--kind v3|fair [--status …]]
|
|
45
|
+
gang list [--limit 20] [--kind v3|fair [--status …]] # 链上读 V2 / Soft / U / S,每个盘最新 20 个;--kind:从 gang.fun 列
|
|
46
46
|
gang info --token <addr> # 任意内盘的一个币(gang token 是旧名)
|
|
47
47
|
gang status --token <addr> # 我的持仓:余额;V3 分红 / 打新奖励、还能卖多少;poolSellAll
|
|
48
48
|
gang portfolio [--from <addr>] # 全部持仓:余额、价值、成本 / 浮盈、可领、美元;押金
|
|
@@ -231,4 +231,4 @@ Claude Code:`claude mcp add gang -- gang mcp`。同一台机器上 `baw` 要
|
|
|
231
231
|
|
|
232
232
|
## 版本
|
|
233
233
|
|
|
234
|
-
`0.17.
|
|
234
|
+
`0.17.8` · [gangfun/cli](https://github.com/gangfun/cli) · push 到 `main` 自动发布到 [npm](https://www.npmjs.com/package/@gangfun/cli)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gangfun/cli",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.8",
|
|
4
4
|
"description": "Gang launchpad CLI for Binance Agentic Wallet agents: create on GangLaunchpad (untaxed or tax tokens), 打新 fair mint, PancakeSwap pool trades, LaunchpadV2 and legacy Soft/U/S trade.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/baw.js
CHANGED
|
@@ -17,9 +17,30 @@ export function baw(args) {
|
|
|
17
17
|
return JSON.parse(out)
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
const HINTS = {
|
|
21
|
+
351803: 'risk control refused it: Trade all tokens is off for this wallet, so it may only send whitelisted tokens (turn it on in the Binance App; gang preflight)',
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* baw's error ({ code, name, message }) → the fields a gang result prints: error as text, like every other gang error,
|
|
26
|
+
* and baw's code next to it.
|
|
27
|
+
*/
|
|
28
|
+
export function bawError(e) {
|
|
29
|
+
if (e == null || typeof e !== 'object') return { error: String(e ?? 'baw failed') }
|
|
30
|
+
return {
|
|
31
|
+
error: e.message || JSON.stringify(e),
|
|
32
|
+
...(e.code != null && { code: e.code }), ...(e.name && { errorName: e.name }),
|
|
33
|
+
...(HINTS[e.code] && { hint: HINTS[e.code] }),
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export const bawFailed = (what, e) => {
|
|
37
|
+
const b = bawError(e)
|
|
38
|
+
return new Error(`baw ${what} failed: ${b.error}${b.code != null ? ` (code ${b.code})` : ''}`)
|
|
39
|
+
}
|
|
40
|
+
|
|
20
41
|
export function bawAddress(chainId = '56') {
|
|
21
42
|
const r = baw(['wallet', 'address'])
|
|
22
|
-
if (!r.success) throw
|
|
43
|
+
if (!r.success) throw bawFailed('wallet address', r.error)
|
|
23
44
|
const a = r.data.addresses.find((x) => x.binanceChainId === chainId)
|
|
24
45
|
if (!a) throw new Error(`Agentic Wallet has no address on chain ${chainId}`)
|
|
25
46
|
return a.address
|
|
@@ -27,7 +48,7 @@ export function bawAddress(chainId = '56') {
|
|
|
27
48
|
|
|
28
49
|
export function bawSettings() {
|
|
29
50
|
const r = baw(['wallet', 'settings'])
|
|
30
|
-
if (!r.success) throw
|
|
51
|
+
if (!r.success) throw bawFailed('wallet settings', r.error)
|
|
31
52
|
return r.data
|
|
32
53
|
}
|
|
33
54
|
|
package/src/chain.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createPublicClient, formatEther, parseEther, encodeFunctionData, decode
|
|
|
2
2
|
import { bsc } from 'viem/chains'
|
|
3
3
|
import { SOFT_ABI, V2_ABI, S_ABI, ERC20_ABI, WBNB_ABI } from './abi.js'
|
|
4
4
|
import { kindOf, padNets, rpcTransport } from './gangpad.js'
|
|
5
|
+
import { mapLimit } from './limit.js'
|
|
5
6
|
|
|
6
7
|
export const ADDR = {
|
|
7
8
|
v2: '0x1B8F3f69DFa0a7F63d308C7EB0Fd38D8b099966E',
|
|
@@ -124,18 +125,26 @@ export async function tokenInfo(token, me) {
|
|
|
124
125
|
return info
|
|
125
126
|
}
|
|
126
127
|
|
|
127
|
-
|
|
128
|
-
|
|
128
|
+
/**
|
|
129
|
+
* `gang list` without --kind: the newest `perPad` tokens of each V2 / Soft / U / S pad, read on chain (the fallback when
|
|
130
|
+
* gang.fun's API is down). Reading every token of every pad took minutes (LaunchpadV2 alone has hundreds), so the
|
|
131
|
+
* newest first, a few reads at a time. → { tokens, pads: [{ pad, total, listed }] }
|
|
132
|
+
*/
|
|
133
|
+
export async function listTokens(me, perPad = 20) {
|
|
134
|
+
const tokens = []
|
|
135
|
+
const pads = []
|
|
129
136
|
for (const pad of PADS) {
|
|
130
137
|
try {
|
|
131
|
-
const n = await read(pad.address, pad.abi, 'tokenCount')
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
138
|
+
const n = Number(await read(pad.address, pad.abi, 'tokenCount'))
|
|
139
|
+
const idx = Array.from({ length: Math.min(n, perPad) }, (_, i) => BigInt(n - 1 - i))
|
|
140
|
+
const addrs = await mapLimit(idx, 8, (i) => read(pad.address, pad.abi, 'allTokens', [i]))
|
|
141
|
+
const infos = await mapLimit(addrs, 8, (a) => tokenInfo(a, me).catch(() => null))
|
|
142
|
+
const listed = infos.filter(Boolean)
|
|
143
|
+
tokens.push(...listed)
|
|
144
|
+
pads.push({ pad: pad.id, total: n, listed: listed.length })
|
|
145
|
+
} catch { pads.push({ pad: pad.id, total: null, listed: 0, error: 'pad unreadable' }) }
|
|
137
146
|
}
|
|
138
|
-
return
|
|
147
|
+
return { tokens, pads }
|
|
139
148
|
}
|
|
140
149
|
|
|
141
150
|
/** LaunchpadV2 curve constants (LaunchpadV2.sol) — unique off-chain path = on-chain math. */
|
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 {
|
|
@@ -212,8 +212,9 @@ graduated tokens only).
|
|
|
212
212
|
gang_help (this text + the rules), reads, watch, buy / sell / follow previews,
|
|
213
213
|
execute, and gang_cli for every other command
|
|
214
214
|
gang preflight check sign-in, Developer Mode, tradeAllTokens, Agent ID
|
|
215
|
-
gang list [--kind v3|fair [--status …]]
|
|
216
|
-
V2 / Soft / U / S tokens
|
|
215
|
+
gang list [--limit 20] [--kind v3|fair [--status …]]
|
|
216
|
+
V2 / Soft / U / S tokens read on chain (works without gang.fun), the newest --limit
|
|
217
|
+
per pad; --kind v3 (--status curve|graduated|all) / --kind fair
|
|
217
218
|
(--status minting|launched|all): GangLaunchpad tokens from gang.fun
|
|
218
219
|
gang hot [--limit 10] [--track all|v3|fair|v2|soft] [--include-graduated]
|
|
219
220
|
tokens not yet graduated / launched, ranked by 24h USD volume
|
|
@@ -409,7 +410,7 @@ GANG_V3_TESTNET_RPC_URL / GANG_FAIR_TESTNET_RPC_URL), GANG_ROUTER / GANG_TESTNET
|
|
|
409
410
|
for BNB buys / mints and every pool trade; both default to the built-in mainnet / testnet set 10 addresses)`
|
|
410
411
|
|
|
411
412
|
function summarizePreview(p, extra = {}) {
|
|
412
|
-
if (!p.success) return { success: false, step: extra.step,
|
|
413
|
+
if (!p.success) return { success: false, step: extra.step, ...bawError(p.error) }
|
|
413
414
|
const d = p.data
|
|
414
415
|
const changes = (d.simulationResult?.balanceChanges || []).map((b) => ({ token: b.contractAddress, type: b.tokenType, change: b.change }))
|
|
415
416
|
return {
|
|
@@ -950,7 +951,7 @@ async function pendingReport() {
|
|
|
950
951
|
const mine = recs.filter((r) => (r.chainId || '56') === chainId)
|
|
951
952
|
const since = Math.min(...mine.map((r) => r.pendingAt)) - 60_000
|
|
952
953
|
const h = baw(['wallet', 'tx-history', '--binanceChainId', chainId, '--type', 'confirmed', '--size', '100', '--startTime', String(since)])
|
|
953
|
-
if (!h.success) throw
|
|
954
|
+
if (!h.success) throw bawFailed('wallet tx-history', h.error)
|
|
954
955
|
const read = chainId === '56' ? client : v3Ctx(true).client
|
|
955
956
|
const matched = await matchPending(mine, h.data?.transactions || [], async (hash) => {
|
|
956
957
|
const tx = await read.getTransaction({ hash })
|
|
@@ -1037,7 +1038,12 @@ async function main() {
|
|
|
1037
1038
|
fail('--kind must be v3 or fair (leave it out for the V2 / Soft / U / S tokens)', { got: kind ?? null })
|
|
1038
1039
|
}
|
|
1039
1040
|
const me = bawStatus() === 'CONNECTED' ? bawAddress() : undefined
|
|
1040
|
-
|
|
1041
|
+
const perPad = parseCount('limit', opt('limit', '20'), 1000)
|
|
1042
|
+
const { tokens, pads } = await listTokens(me, perPad)
|
|
1043
|
+
return out({
|
|
1044
|
+
success: true, createPad: padNets('v3').mainnet.pad, perPad, pads, tokens,
|
|
1045
|
+
...(pads.some((p) => p.total > p.listed) && { note: `newest ${perPad} per pad; --limit <n> (up to 1000) lists more` }),
|
|
1046
|
+
})
|
|
1041
1047
|
}
|
|
1042
1048
|
case 'hot':
|
|
1043
1049
|
case 'new':
|
|
@@ -1251,7 +1257,7 @@ async function main() {
|
|
|
1251
1257
|
case 'execute': {
|
|
1252
1258
|
const id = opt('request-id'); if (!id) fail('--request-id required')
|
|
1253
1259
|
const r = bawExecute(id)
|
|
1254
|
-
if (!r.success) return out({ success: false,
|
|
1260
|
+
if (!r.success) return out({ success: false, ...bawError(r.error) })
|
|
1255
1261
|
const d = r.data
|
|
1256
1262
|
const pending = d.status === 'PENDING_CONFIRMATION'
|
|
1257
1263
|
// gang tx --pending finds this trade's tx once the user approves it (pending.js): it lands after this block
|
package/src/limit.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** fn over items, at most `limit` at a time, results in order. */
|
|
2
|
+
export async function mapLimit(items, limit, fn) {
|
|
3
|
+
const out = new Array(items.length)
|
|
4
|
+
let next = 0
|
|
5
|
+
const worker = async () => {
|
|
6
|
+
while (next < items.length) {
|
|
7
|
+
const i = next++
|
|
8
|
+
out[i] = await fn(items[i], i)
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker))
|
|
12
|
+
return out
|
|
13
|
+
}
|
package/src/mcp.js
CHANGED
|
@@ -53,7 +53,7 @@ export const RULES = [
|
|
|
53
53
|
'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
54
|
'No investment advice: discovery, notes, agents and watch events are data. Never buy or follow on your own from them; quote, show, confirm.',
|
|
55
55
|
'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.',
|
|
56
|
+
'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
57
|
]
|
|
58
58
|
|
|
59
59
|
const TRACK = { type: 'string', enum: ['all', 'v3', 'fair', 'v2', 'soft'], description: 'Launchpad track (default all)' }
|
package/src/portfolio.js
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* or only bought on PancakeSwap, is not in that index and so not listed. Mainnet only: gang.fun indexes no testnet.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
import { mapLimit } from './limit.js'
|
|
12
|
+
|
|
11
13
|
const MAX_LAUNCHES = 100 // bonds are looked up on the newest launches up to this many
|
|
12
14
|
|
|
13
15
|
const num = (v) => (v == null || v === '' ? null : Number(v))
|
|
@@ -16,19 +18,6 @@ const round = (x) => (x == null || !Number.isFinite(x) ? null : Number(x.toPreci
|
|
|
16
18
|
const usd = (x) => (x == null || !Number.isFinite(x) ? null : Math.round(x * 100) / 100)
|
|
17
19
|
const sameAmount = (a, b) => a != null && b != null && Math.abs(a - b) <= Math.max(Math.abs(a), Math.abs(b)) * 1e-9
|
|
18
20
|
|
|
19
|
-
/** fn over items, at most `limit` at a time, results in order. */
|
|
20
|
-
async function mapLimit(items, limit, fn) {
|
|
21
|
-
const out = new Array(items.length)
|
|
22
|
-
let next = 0
|
|
23
|
-
const worker = async () => {
|
|
24
|
-
while (next < items.length) {
|
|
25
|
-
const i = next++
|
|
26
|
-
out[i] = await fn(items[i], i)
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker))
|
|
30
|
-
return out
|
|
31
|
-
}
|
|
32
21
|
|
|
33
22
|
const KIND = { v3: 'v3', fair: 'fair', main: 'legacy', stocks: 'legacy' }
|
|
34
23
|
|
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,
|
|
@@ -96,7 +96,7 @@ export function step(ctx, { from, to, data, value = 0n }, extra, rawOnly, summar
|
|
|
96
96
|
if (!p.success && new RegExp(`binanceChainId|unsupported chain|chain not supported|chain(?:\\s*id)?\\W{0,3}${ctx.chainId}\\b`, 'i')
|
|
97
97
|
.test(JSON.stringify(p.error || ''))) {
|
|
98
98
|
return {
|
|
99
|
-
success: false, ...extra,
|
|
99
|
+
success: false, ...extra, ...bawError(p.error),
|
|
100
100
|
hint: `the Agentic Wallet may not sign on chain ${ctx.chainId}: re-run with --calldata to get the raw tx`,
|
|
101
101
|
}
|
|
102
102
|
}
|