@gangfun/cli 0.30.0 → 0.30.1

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
@@ -348,4 +348,4 @@ a background process, so a command never waits on it. `GANG_TELEMETRY=0` (or `DO
348
348
 
349
349
  ## Version
350
350
 
351
- `0.30.0` · repo [gangfun/cli](https://github.com/gangfun/cli) · published to [npm](https://www.npmjs.com/package/@gangfun/cli) on push to `main`
351
+ `0.30.1` · 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
@@ -296,4 +296,4 @@ Claude Code:`claude mcp add gang -- gang mcp`。同一台机器上 `baw` 要
296
296
 
297
297
  ## 版本
298
298
 
299
- `0.30.0` · [gangfun/cli](https://github.com/gangfun/cli) · push 到 `main` 自动发布到 [npm](https://www.npmjs.com/package/@gangfun/cli)
299
+ `0.30.1` · [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.30.0",
3
+ "version": "0.30.1",
4
4
  "mcpName": "io.github.gangfun/gang",
5
5
  "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.",
6
6
  "type": "module",
package/src/chain.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createPublicClient, formatEther, parseEther, encodeFunctionData, decodeEventLog, isAddress, zeroAddress } from 'viem'
1
+ import { createPublicClient, formatEther, parseAbi, parseEther, encodeFunctionData, decodeEventLog, isAddress, zeroAddress } from 'viem'
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 { genOf, padNets, rpcTransport } from './gangpad.js'
@@ -6,7 +6,8 @@ import { mapLimit } from './limit.js'
6
6
 
7
7
  export const ADDR = {
8
8
  v2: '0x1B8F3f69DFa0a7F63d308C7EB0Fd38D8b099966E',
9
- soft: '0x4E6f13c8A453c1b8b4E20b590082bb233a5b80d7',
9
+ softFirst: '0x315Ba2e8952D06094CC636b2B84229FA32fb23A7', // holds the Soft tokens, GANG included
10
+ softLater: '0x4E6f13c8A453c1b8b4E20b590082bb233a5b80d7', // same ABI, no tokens yet
10
11
  u: '0xF81C4E51c48466c6025B0165b1Ea0F6978c712cb',
11
12
  s: '0x60aee38576035E757deD30fF8db8A8DA476430C1',
12
13
  wbnb: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
@@ -27,7 +28,8 @@ const read = (address, abi, functionName, args = []) => client.readContract({ ad
27
28
 
28
29
  const PADS = [
29
30
  { id: 'v2', address: ADDR.v2, kind: 'v2', abi: V2_ABI },
30
- { id: 'soft', address: ADDR.soft, kind: 'soft', abi: SOFT_ABI },
31
+ { id: 'soft', address: ADDR.softFirst, kind: 'soft', abi: SOFT_ABI },
32
+ { id: 'soft', address: ADDR.softLater, kind: 'soft', abi: SOFT_ABI },
31
33
  { id: 'u', address: ADDR.u, kind: 'v2', abi: V2_ABI },
32
34
  { id: 's', address: ADDR.s, kind: 'v2', abi: S_ABI }, // 9-field Curve (no taxed): see S_ABI
33
35
  ]
@@ -77,18 +79,28 @@ function sInfoFromCurve(c) {
77
79
  /** The curve of a resolved pad in one shape, whatever the pad's layout. */
78
80
  const curveInfo = (pad) => (pad.kind === 'soft' ? softInfoFromCurve(pad.curve) : pad.id === 's' ? sInfoFromCurve(pad.curve) : v2InfoFromCurve(pad.curve))
79
81
 
82
+ const PAIR_ABI = parseAbi(['function getReserves() view returns (uint112, uint112, uint32)', 'function token0() view returns (address)'])
83
+
84
+ /** A graduated Soft token's price in its PancakeSwap pool (always against WBNB): BNB per token, 1e18 scale. */
85
+ async function softPoolPrice(token, pair) {
86
+ const [[r0, r1], t0] = await Promise.all([read(pair, PAIR_ABI, 'getReserves'), read(pair, PAIR_ABI, 'token0')])
87
+ const [tokenReserve, bnbReserve] = t0.toLowerCase() === token.toLowerCase() ? [r0, r1] : [r1, r0]
88
+ return tokenReserve > 0n ? (bnbReserve * 10n ** 18n) / tokenReserve : null
89
+ }
90
+
80
91
  export async function tokenInfo(token, me) {
81
92
  const pad = await resolvePad(token)
82
93
  const base = curveInfo(pad)
83
94
  const [name, symbol] = await Promise.all([erc(token, 'name'), erc(token, 'symbol')])
84
95
  let locked = null
85
96
  try { locked = await erc(token, 'locked') } catch { /* */ }
97
+ // the wallet cap is the curve's: a graduated token has none
86
98
  let cap = null
87
- try { cap = await read(pad.address, pad.abi, 'MAX_PER_WALLET') } catch { /* */ }
99
+ if (!base.graduated) try { cap = await read(pad.address, pad.abi, 'MAX_PER_WALLET') } catch { /* */ }
88
100
 
89
101
  let price = null
90
102
  if (pad.kind === 'soft') {
91
- try { price = base.graduated ? 100000000000n : await read(pad.address, pad.abi, 'spotPrice', [token]) } catch { /* */ }
103
+ try { price = base.graduated ? await softPoolPrice(token, base.pair) : await read(pad.address, pad.abi, 'spotPrice', [token]) } catch { /* */ }
92
104
  } else if (base.virtualQuote && base.virtualQuote > 0n) {
93
105
  // spot ≈ virtualQuote / (VIRTUAL_TOKEN - sold) * 1e18-ish; expose raised/grad instead
94
106
  const vq = BigInt(base.virtualQuote)
@@ -99,7 +111,8 @@ export async function tokenInfo(token, me) {
99
111
  }
100
112
 
101
113
  const grad = base.gradAmt != null ? BigInt(base.gradAmt) : (pad.kind === 'soft' ? await read(pad.address, pad.abi, 'GRADUATION_BNB') : 15n * 10n ** 18n)
102
- const raised = BigInt(base.raised)
114
+ // a graduated Soft curve's realBnb went to the pool: it raised its whole target
115
+ const raised = pad.kind === 'soft' && base.graduated ? grad : BigInt(base.raised)
103
116
  const info = {
104
117
  token, name, symbol, creator: base.creator, graduated: base.graduated,
105
118
  pair: base.graduated ? base.pair : null, locked,
@@ -118,7 +131,7 @@ export async function tokenInfo(token, me) {
118
131
  if (me) {
119
132
  const bal = await erc(token, 'balanceOf', [me])
120
133
  info.myBalance = fmtTok(bal); info.myBalanceRaw = bal.toString()
121
- try {
134
+ if (!base.graduated) try {
122
135
  const room = await read(pad.address, pad.abi, 'walletRoom', [token, me])
123
136
  info.myRoomTokens = fmtTok(room); info.myRoomRaw = room.toString()
124
137
  } catch { /* */ }
@@ -129,7 +142,7 @@ export async function tokenInfo(token, me) {
129
142
  /**
130
143
  * `gang list` without --kind: the newest `perPad` tokens of each V2 / Soft / U / S pad, read on chain (the fallback when
131
144
  * gang.fun's API is down). Reading every token of every pad took minutes (LaunchpadV2 alone has hundreds), so the
132
- * newest first, a few reads at a time. → { tokens, pads: [{ pad, total, listed }] }
145
+ * newest first, a few reads at a time. → { tokens, pads: [{ pad, address, total, listed }] }
133
146
  */
134
147
  export async function listTokens(me, perPad = 20) {
135
148
  const tokens = []
@@ -142,8 +155,8 @@ export async function listTokens(me, perPad = 20) {
142
155
  const infos = await mapLimit(addrs, 8, (a) => tokenInfo(a, me).catch(() => null))
143
156
  const listed = infos.filter(Boolean)
144
157
  tokens.push(...listed)
145
- pads.push({ pad: pad.id, total: n, listed: listed.length })
146
- } catch { pads.push({ pad: pad.id, total: null, listed: 0, error: 'pad unreadable' }) }
158
+ pads.push({ pad: pad.id, address: pad.address, total: n, listed: listed.length })
159
+ } catch { pads.push({ pad: pad.id, address: pad.address, total: null, listed: 0, error: 'pad unreadable' }) }
147
160
  }
148
161
  return { tokens, pads }
149
162
  }
@@ -217,6 +230,9 @@ function v2QuoteSellFromCurve(base, tokensIn) {
217
230
 
218
231
  export async function quoteBuy(token, buyer, amountHuman) {
219
232
  const pad = await resolvePad(token)
233
+ if (curveInfo(pad).graduated) {
234
+ throw new Error(`${token} has graduated: it trades in its PancakeSwap pool, not on the curve. gang buy --amount <n> builds that trade`)
235
+ }
220
236
  const gross = parseEther(amountHuman)
221
237
  if (pad.kind === 'soft') {
222
238
  const [tokensOut, bnbIn, fee, refund] = await read(pad.address, pad.abi, 'quoteBuy', [token, buyer, gross])
@@ -253,7 +269,7 @@ export async function quoteSell(token, tokensIn) {
253
269
  export async function isAgent(account) {
254
270
  // Prefer V2 gate (create path); fall back Soft.
255
271
  try { return await read(ADDR.v2, V2_ABI, 'isAgent', [account]) } catch { /* */ }
256
- try { return await read(ADDR.soft, SOFT_ABI, 'isAgent', [account]) } catch { /* */ }
272
+ try { return await read(ADDR.softFirst, SOFT_ABI, 'isAgent', [account]) } catch { /* */ }
257
273
  return false
258
274
  }
259
275
 
package/src/index.js CHANGED
@@ -1067,8 +1067,7 @@ const captured = (r) => {
1067
1067
  }
1068
1068
  async function portfolioStatus(kind, token, wallet, indexed) {
1069
1069
  if (kind === 'legacy') {
1070
- // an old token none of today's V2 / Soft / U / S reads know (GANG itself, launched on an early Soft pad): the
1071
- // balance alone, from the token
1070
+ // an old token none of today's V2 / Soft / U / S reads know: the balance alone, from the token
1072
1071
  return tokenInfo(token, wallet).catch(async (e) => {
1073
1072
  if (!/not a Gang token/.test(e.message)) throw e
1074
1073
  return { graduated: indexed.status === 'graduated', myBalanceRaw: (await balanceOf(token, wallet)).toString() }