@gangfun/cli 0.17.7 → 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 CHANGED
@@ -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.7` · repo [gangfun/cli](https://github.com/gangfun/cli) · published to [npm](https://www.npmjs.com/package/@gangfun/cli) on push to `main`
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
@@ -231,4 +231,4 @@ Claude Code:`claude mcp add gang -- gang mcp`。同一台机器上 `baw` 要
231
231
 
232
232
  ## 版本
233
233
 
234
- `0.17.7` · [gangfun/cli](https://github.com/gangfun/cli) · push 到 `main` 自动发布到 [npm](https://www.npmjs.com/package/@gangfun/cli)
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.7",
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 new Error(JSON.stringify(r.error))
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 new Error(JSON.stringify(r.error))
51
+ if (!r.success) throw bawFailed('wallet settings', r.error)
31
52
  return r.data
32
53
  }
33
54
 
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 {
@@ -410,7 +410,7 @@ GANG_V3_TESTNET_RPC_URL / GANG_FAIR_TESTNET_RPC_URL), GANG_ROUTER / GANG_TESTNET
410
410
  for BNB buys / mints and every pool trade; both default to the built-in mainnet / testnet set 10 addresses)`
411
411
 
412
412
  function summarizePreview(p, extra = {}) {
413
- if (!p.success) return { success: false, step: extra.step, error: p.error }
413
+ if (!p.success) return { success: false, step: extra.step, ...bawError(p.error) }
414
414
  const d = p.data
415
415
  const changes = (d.simulationResult?.balanceChanges || []).map((b) => ({ token: b.contractAddress, type: b.tokenType, change: b.change }))
416
416
  return {
@@ -951,7 +951,7 @@ async function pendingReport() {
951
951
  const mine = recs.filter((r) => (r.chainId || '56') === chainId)
952
952
  const since = Math.min(...mine.map((r) => r.pendingAt)) - 60_000
953
953
  const h = baw(['wallet', 'tx-history', '--binanceChainId', chainId, '--type', 'confirmed', '--size', '100', '--startTime', String(since)])
954
- if (!h.success) throw new Error(`baw wallet tx-history failed: ${JSON.stringify(h.error)}`)
954
+ if (!h.success) throw bawFailed('wallet tx-history', h.error)
955
955
  const read = chainId === '56' ? client : v3Ctx(true).client
956
956
  const matched = await matchPending(mine, h.data?.transactions || [], async (hash) => {
957
957
  const tx = await read.getTransaction({ hash })
@@ -1257,7 +1257,7 @@ async function main() {
1257
1257
  case 'execute': {
1258
1258
  const id = opt('request-id'); if (!id) fail('--request-id required')
1259
1259
  const r = bawExecute(id)
1260
- if (!r.success) return out({ success: false, error: r.error })
1260
+ if (!r.success) return out({ success: false, ...bawError(r.error) })
1261
1261
  const d = r.data
1262
1262
  const pending = d.status === 'PENDING_CONFIRMATION'
1263
1263
  // 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
@@ -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/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, error: p.error,
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
  }