@gangfun/cli 0.34.0 → 0.36.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 +11 -1
- package/README.zh-CN.md +10 -0
- package/package.json +1 -1
- package/src/capabilities.js +7 -0
- package/src/capped.js +717 -0
- package/src/combo.js +1 -1
- package/src/creatorfee.js +25 -8
- package/src/gangpad.js +16 -5
- package/src/index.js +86 -15
- package/src/launch.js +193 -20
- package/src/mcp.js +9 -8
- package/src/promote.js +3 -3
- package/src/telemetry.js +1 -1
- package/src/trending.js +9 -2
- package/src/v3.js +6 -0
- package/src/weekly.js +357 -0
package/src/weekly.js
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `gang weekly`: Gang's weekly launch event (gang.fun/weekly). Each week the team picks one application; the pick launches
|
|
3
|
+
* on GangLaunchpad 3.0 (V3 curve) on Friday 20:00 UTC+8 from the wallet that applied, and is featured for 7 days: on the
|
|
4
|
+
* gang.fun homepage, in gang.fun's X / TG posts and as the `event` row of `gang trending` / `preflight` / `list`. No
|
|
5
|
+
* buy-back, no reward: attention only. An official event, not a recommendation.
|
|
6
|
+
*
|
|
7
|
+
* gang weekly the issue open for applications, the current pick, past issues, my application
|
|
8
|
+
* gang weekly apply … preview the application; with --yes sign it with the Agent wallet and submit it
|
|
9
|
+
* gang weekly withdraw [--yes] withdraw my application while applications are open
|
|
10
|
+
*
|
|
11
|
+
* The application is signed as EIP-712 typed data (domain "gang.fun weekly launch", chainId 56) by the baw wallet, which
|
|
12
|
+
* proves the wallet applying is the one that will create. Its `contact` is only seen by the gang.fun team.
|
|
13
|
+
*/
|
|
14
|
+
import { statSync } from 'node:fs'
|
|
15
|
+
import { keccak256, toBytes } from 'viem'
|
|
16
|
+
import { API, get as apiGet } from './discover.js'
|
|
17
|
+
import { baw, bawAddress, bawFailed, bawStatus } from './baw.js'
|
|
18
|
+
import { localTime } from './follow.js'
|
|
19
|
+
import { cdnUrl, checkGangLogo, ipfsCid, ipfsUri } from './logo.js'
|
|
20
|
+
import { normalizeTwitter, normalizeWebsite } from './links.js'
|
|
21
|
+
import { UA } from './version.js'
|
|
22
|
+
|
|
23
|
+
export const WEEKLY_NOTE = "Gang's official weekly launch event, not a recommendation. Never buy from it on your own."
|
|
24
|
+
export const WEEKLY_URL = 'https://gang.fun/weekly'
|
|
25
|
+
export const WEEKLY_MODULES = ['buyback', 'lp', 'split', 'combo', 'capped', 'bond', 'dividend', 'promote', 'tax']
|
|
26
|
+
export const APPLY_FLAGS = ['name', 'symbol', 'logo', 'logo-file', 'file-logo', 'logo-uri', 'description', 'contact',
|
|
27
|
+
'twitter', 'telegram', 'website', 'modules', 'issue', 'yes', 'keep-logo-uri']
|
|
28
|
+
|
|
29
|
+
export const WEEKLY_DOMAIN = { name: 'gang.fun weekly launch', version: '1', chainId: 56 }
|
|
30
|
+
const DOMAIN_TYPE = [{ name: 'name', type: 'string' }, { name: 'version', type: 'string' }, { name: 'chainId', type: 'uint256' }]
|
|
31
|
+
export const WEEKLY_TYPES = {
|
|
32
|
+
WeeklyApply: [{ name: 'wallet', type: 'address' }, { name: 'issue', type: 'string' }, { name: 'digest', type: 'bytes32' }, { name: 'expires', type: 'uint256' }],
|
|
33
|
+
WeeklyWithdraw: [{ name: 'wallet', type: 'address' }, { name: 'issue', type: 'string' }, { name: 'expires', type: 'uint256' }],
|
|
34
|
+
}
|
|
35
|
+
const SIGN_TTL_S = 30 * 60 // the signature's expires: the server takes up to 1 hour ahead
|
|
36
|
+
const ISSUE_RE = /^\d{4}-\d{2}-\d{2}$/
|
|
37
|
+
const POST_TIMEOUT_MS = 20_000
|
|
38
|
+
|
|
39
|
+
/** JSON with object keys sorted at every level, arrays in order, no whitespace: what the digest hashes (server does the same). */
|
|
40
|
+
export function canonical(v) {
|
|
41
|
+
if (Array.isArray(v)) return `[${v.map(canonical).join(',')}]`
|
|
42
|
+
if (v && typeof v === 'object') {
|
|
43
|
+
return `{${Object.keys(v).filter((k) => v[k] !== undefined).sort().map((k) => `${JSON.stringify(k)}:${canonical(v[k])}`).join(',')}}`
|
|
44
|
+
}
|
|
45
|
+
return JSON.stringify(v)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** keccak256 of the canonical application, wallet in lower case. */
|
|
49
|
+
export const applicationDigest = (app) => keccak256(toBytes(canonical({ ...app, wallet: String(app.wallet).toLowerCase() })))
|
|
50
|
+
|
|
51
|
+
/** The typed data baw signs (eth_signTypedData_v4 shape: EIP712Domain included in types). */
|
|
52
|
+
export function typedData(primaryType, message) {
|
|
53
|
+
return { types: { EIP712Domain: DOMAIN_TYPE, [primaryType]: WEEKLY_TYPES[primaryType] }, primaryType, domain: WEEKLY_DOMAIN, message }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** baw's { signature: r‖s hex, signatureRecovery: '00' | '01' } → a 65-byte 0x signature with v = 27 / 28. */
|
|
57
|
+
export function joinSignature(sig, recovery) {
|
|
58
|
+
const rs = String(sig ?? '').replace(/^0x/, '')
|
|
59
|
+
if (!/^[0-9a-fA-F]{128}$/.test(rs)) {
|
|
60
|
+
// some answers carry the full 65 bytes already
|
|
61
|
+
if (/^[0-9a-fA-F]{130}$/.test(rs)) return `0x${rs}`
|
|
62
|
+
throw new Error('baw returned no signature')
|
|
63
|
+
}
|
|
64
|
+
// without the recovery byte half the signatures would be wrong: refuse rather than guess
|
|
65
|
+
if (recovery == null || !/^(?:0x)?[0-9a-fA-F]{1,2}$/.test(String(recovery))) throw new Error('baw returned a signature without its recovery byte')
|
|
66
|
+
const rec = Number.parseInt(String(recovery).replace(/^0x/, ''), 16)
|
|
67
|
+
if (!(rec >= 0 && rec <= 1) && !(rec === 27 || rec === 28)) throw new Error(`baw returned an unknown signature recovery ${recovery}`)
|
|
68
|
+
return `0x${rs}${(rec >= 27 ? rec : 27 + rec).toString(16)}`
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Sign typed data with the baw wallet: preview, then execute. A signature that waits for the Binance App is polled for up
|
|
73
|
+
* to ~2 minutes. → 0x signature.
|
|
74
|
+
*/
|
|
75
|
+
export function bawSignTyped(wallet, td, { sleep = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms) } = {}) {
|
|
76
|
+
const message = JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'eth_signTypedData_v4', params: [wallet, JSON.stringify(td)] })
|
|
77
|
+
const p = baw(['sign-message', 'preview', '--binanceChainId', '56', '--signType', 'EIP712', '--message', message])
|
|
78
|
+
if (!p.success) throw bawFailed('sign-message preview', p.error)
|
|
79
|
+
let r = baw(['sign-message', 'execute', '--requestId', p.data.requestId])
|
|
80
|
+
if (!r.success) throw bawFailed('sign-message execute', r.error)
|
|
81
|
+
for (let i = 0; r.data?.status !== 'COMPLETED' && r.data?.orderId && i < 40; i++) {
|
|
82
|
+
if (['FAILED', 'REJECTED', 'CANCELLED', 'EXPIRED'].includes(r.data.status)) throw new Error(`the signature was ${r.data.status.toLowerCase()} in the wallet`)
|
|
83
|
+
sleep(3000)
|
|
84
|
+
const q = baw(['sign-message', 'result', '--order-id', r.data.orderId])
|
|
85
|
+
if (q.success) r = q
|
|
86
|
+
}
|
|
87
|
+
if (r.data?.status !== 'COMPLETED') throw Object.assign(new Error('the signature was not completed: approve it in the Binance App if it asks, then run the same command again'), { retryable: true })
|
|
88
|
+
return joinSignature(r.data.signature, r.data.signatureRecovery)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** --telegram as typed (@name, name, t.me/… link) → https://t.me/<name> ('' when empty). Throws bad_telegram. */
|
|
92
|
+
export function normalizeTelegram(raw) {
|
|
93
|
+
const s = String(raw ?? '').trim()
|
|
94
|
+
if (!s) return ''
|
|
95
|
+
const bad = () => new Error(`bad_telegram: --telegram takes a TG handle (@name) or a t.me link (got ${JSON.stringify(s)})`)
|
|
96
|
+
const handle = /^@?([A-Za-z0-9_]{4,32})$/.exec(s)
|
|
97
|
+
if (handle) return `https://t.me/${handle[1]}`
|
|
98
|
+
let u
|
|
99
|
+
try { u = new URL(/^https?:\/\//i.test(s) ? s : `https://${s}`) } catch { throw bad() }
|
|
100
|
+
if (!['https:', 'http:'].includes(u.protocol) || u.username || u.password || u.port || !['t.me', 'www.t.me', 'telegram.me'].includes(u.hostname)) throw bad()
|
|
101
|
+
const path = u.pathname.replace(/\/+$/, '')
|
|
102
|
+
if (!/^(?:\/\+?[A-Za-z0-9_-]{1,64}){1,2}$/.test(path)) throw bad()
|
|
103
|
+
return `https://t.me${path}`
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const chars = (s) => [...String(s ?? '')].length
|
|
107
|
+
// what gang.fun takes (its weekly.js): a symbol of letters, digits and CJK / kana / hangul; no control characters in name / contact
|
|
108
|
+
export const SYMBOL_RE = /^[A-Za-z0-9\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]+$/u
|
|
109
|
+
const CTRL_RE = /[\u0000-\u001f\u007f]/
|
|
110
|
+
// zero-width and bidi override / isolate characters: refused everywhere (they can disguise text in gang.fun's posts)
|
|
111
|
+
const HIDDEN_RE = /[\u00ad\u200b-\u200f\u202a-\u202e\u2060\u2066-\u2069\ufeff]/
|
|
112
|
+
// the description may span lines and use tabs, nothing else below U+0020
|
|
113
|
+
const DESC_CTRL_RE = /[\u0000-\u0008\u000b-\u001f\u007f]/
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The application's fields from the flags (without wallet / issue / logo), or throws Error('bad_field: …').
|
|
117
|
+
* Limits as gang.fun checks them; optional links left out when not given.
|
|
118
|
+
*/
|
|
119
|
+
export function applicationFields({ opt, flag }) {
|
|
120
|
+
const bad = (field, why) => Object.assign(new Error(`bad_field: --${field} ${why}`), { field })
|
|
121
|
+
const val = (name) => (flag(name) ? opt(name) : undefined)
|
|
122
|
+
const need = (name) => {
|
|
123
|
+
const v = val(name)
|
|
124
|
+
if (v == null || String(v).startsWith('--') || !String(v).trim()) throw bad(name, 'is required')
|
|
125
|
+
return String(v).trim()
|
|
126
|
+
}
|
|
127
|
+
const name = need('name'); if (chars(name) > 32 || CTRL_RE.test(name) || HIDDEN_RE.test(name)) throw bad('name', 'is at most 32 characters, on one line, no invisible characters')
|
|
128
|
+
const symbol = need('symbol')
|
|
129
|
+
if (chars(symbol) > 12 || !SYMBOL_RE.test(symbol)) throw bad('symbol', 'is at most 12 letters or digits (CJK, kana and hangul too), no spaces or signs')
|
|
130
|
+
// Windows line ends (a file, some agents) are plain newlines: the digest covers what is sent, so this is safe
|
|
131
|
+
const description = need('description').replace(/\r\n?/g, '\n')
|
|
132
|
+
if (chars(description) > 500 || DESC_CTRL_RE.test(description) || HIDDEN_RE.test(description)) throw bad('description', 'is at most 500 characters, no control or invisible characters')
|
|
133
|
+
const contact = need('contact'); if (chars(contact) > 64 || CTRL_RE.test(contact) || HIDDEN_RE.test(contact)) throw bad('contact', 'is at most 64 characters, on one line, no invisible characters')
|
|
134
|
+
const f = { name, symbol, description, contact }
|
|
135
|
+
const link = (flagName, norm) => {
|
|
136
|
+
const v = val(flagName)
|
|
137
|
+
if (v === undefined) return undefined
|
|
138
|
+
if (v == null || String(v).startsWith('--')) throw bad(flagName, 'needs a value')
|
|
139
|
+
try { return norm(v) || undefined } catch (e) { throw bad(flagName, e.message.replace(/^bad_\w+: --[\w-]+ /, '')) }
|
|
140
|
+
}
|
|
141
|
+
const x = link('twitter', normalizeTwitter); if (x) f.x = x
|
|
142
|
+
const tg = link('telegram', normalizeTelegram); if (tg) f.tg = tg
|
|
143
|
+
const website = link('website', normalizeWebsite)
|
|
144
|
+
if (website && !website.startsWith('https://')) throw bad('website', 'must be an https link')
|
|
145
|
+
if (website) f.website = website
|
|
146
|
+
if (flag('modules')) {
|
|
147
|
+
const raw = opt('modules')
|
|
148
|
+
if (raw == null || raw.startsWith('--')) throw bad('modules', `needs a list, e.g. lp,buyback (from ${WEEKLY_MODULES.join(', ')})`)
|
|
149
|
+
const list = [...new Set(raw.split(',').map((m) => m.trim().toLowerCase()).filter(Boolean))]
|
|
150
|
+
const unknown = list.filter((m) => !WEEKLY_MODULES.includes(m))
|
|
151
|
+
if (unknown.length) throw bad('modules', `knows ${WEEKLY_MODULES.join(', ')} (got ${unknown.join(', ')})`)
|
|
152
|
+
if (list.length) f.modules = list
|
|
153
|
+
}
|
|
154
|
+
return f
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** IssueView times → local text next to the unix seconds. */
|
|
158
|
+
const TIME_KEYS = ['applyOpensAt', 'applyClosesAt', 'opensAt', 'closesAt', 'teaserAt', 'launchAt', 'detectUntil', 'featuredUntil', 'until']
|
|
159
|
+
export function withTimes(v) {
|
|
160
|
+
if (!v || typeof v !== 'object') return v ?? null
|
|
161
|
+
const o = { ...v }
|
|
162
|
+
for (const k of TIME_KEYS) if (Number.isFinite(o[k]) && o[k] > 0) o[`${k}Local`] = localTime(o[k])
|
|
163
|
+
if (o.token?.address) o.token = { ...o.token, link: `https://gang.fun/token/${o.token.address}` }
|
|
164
|
+
return o
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** `event` of GET /trending → the row the CLI prints first (null when absent or malformed). */
|
|
168
|
+
export function eventRow(e) {
|
|
169
|
+
if (!e || e.kind !== 'weekly-launch' || !e.issue) return null
|
|
170
|
+
return withTimes({
|
|
171
|
+
kind: 'weekly-launch', issue: e.issue, number: e.number ?? null, status: e.status ?? null,
|
|
172
|
+
name: e.name ?? null, symbol: e.symbol ?? null, creatorHandle: e.creatorHandle ?? null,
|
|
173
|
+
launchAt: e.launchAt ?? null, until: e.until ?? null,
|
|
174
|
+
token: /^0x[0-9a-fA-F]{40}$/.test(e.token?.address ?? '') ? { address: e.token.address, symbol: e.token.symbol ?? e.symbol ?? null, progressPct: e.token.progressPct ?? null } : null,
|
|
175
|
+
url: WEEKLY_URL, note: WEEKLY_NOTE,
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async function post(path, body) {
|
|
180
|
+
let r
|
|
181
|
+
try {
|
|
182
|
+
r = await fetch(`${API}${path}`, {
|
|
183
|
+
method: 'POST', headers: { 'content-type': 'application/json', accept: 'application/json', 'user-agent': UA },
|
|
184
|
+
body: JSON.stringify(body), signal: AbortSignal.timeout(POST_TIMEOUT_MS),
|
|
185
|
+
})
|
|
186
|
+
} catch (e) {
|
|
187
|
+
throw Object.assign(new Error(`gang API unreachable (${API}${path}): ${e.cause?.message || e.message}`), { retryable: true })
|
|
188
|
+
}
|
|
189
|
+
let j = null
|
|
190
|
+
try { j = await r.json() } catch { /* below */ }
|
|
191
|
+
if (!r.ok || !j?.ok) {
|
|
192
|
+
const code = j?.error || `http_${r.status}`
|
|
193
|
+
throw Object.assign(new Error(`gang.fun refused it: ${j?.message || code}`), { apiCode: code, field: j?.field, retryable: r.status >= 500 || r.status === 429 })
|
|
194
|
+
}
|
|
195
|
+
return j
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const SIGN_IN = 'sign in to baw (baw auth signin): the application is signed by the wallet that will create the token'
|
|
199
|
+
const LOGO_FLAGS = ['logo', 'logo-file', 'file-logo']
|
|
200
|
+
// gang.fun's refusal → the CLI's code (DEVELOPERS.md): a bad field is the command's fault, the rest is state; apiCode keeps it
|
|
201
|
+
const API_CODES = { bad_field: 'USAGE', no_agent_id: 'NO_AGENT_ID', rate_limited: 'NETWORK' }
|
|
202
|
+
|
|
203
|
+
/** runWeekly(sub, io): io = { opt, flag, out, fail, resolveLogo } from index.js. */
|
|
204
|
+
export async function runWeekly(sub, { opt, flag, out, fail, resolveLogo }) {
|
|
205
|
+
const signedIn = () => { try { return bawStatus() === 'CONNECTED' } catch { return false } }
|
|
206
|
+
const wallet = () => { try { return bawAddress() } catch (e) { return fail(`${SIGN_IN} (${e.message})`) } }
|
|
207
|
+
const refused = (e) => fail(e.message, {
|
|
208
|
+
...(e.apiCode && { apiCode: e.apiCode, code: API_CODES[e.apiCode] || 'ERROR' }), ...(e.field && { field: e.field }),
|
|
209
|
+
...(e.retryable && { retry: 'same command again' }),
|
|
210
|
+
})
|
|
211
|
+
const board = async () => {
|
|
212
|
+
let b
|
|
213
|
+
try { b = await apiGet('/weekly', undefined, '') } catch (e) { fail(e.message, { retry: 'same command again' }) }
|
|
214
|
+
if (!b) fail(`gang.fun has no weekly launch event yet (${API}/weekly)`, { retry: 'later' })
|
|
215
|
+
return b
|
|
216
|
+
}
|
|
217
|
+
const issueOf = (b) => {
|
|
218
|
+
const i = flag('issue') ? opt('issue') : b.apply?.issue
|
|
219
|
+
if (!i || !ISSUE_RE.test(i)) fail('--issue takes the issue\'s Friday date, e.g. 2026-11-13', { got: i ?? null })
|
|
220
|
+
return i
|
|
221
|
+
}
|
|
222
|
+
const mine = async (issue, w) => {
|
|
223
|
+
if (!w || !issue) return null
|
|
224
|
+
try { return await apiGet(`/weekly/application?${new URLSearchParams({ issue, wallet: w.toLowerCase() })}`, undefined, '') } catch { return null }
|
|
225
|
+
}
|
|
226
|
+
const mineRow = (my) => (my ? { issue: my.issue, status: my.status, symbol: my.symbol, submittedAtLocal: localTime(my.submittedAt) } : null)
|
|
227
|
+
|
|
228
|
+
if (sub === undefined || sub === 'status' || sub.startsWith('--')) {
|
|
229
|
+
const b = await board()
|
|
230
|
+
const me = signedIn() ? wallet() : null
|
|
231
|
+
if (flag('issue')) {
|
|
232
|
+
const issue = issueOf(b)
|
|
233
|
+
let v
|
|
234
|
+
try { v = await apiGet(`/weekly/${issue}`, undefined, '') } catch (e) { fail(e.message, { retry: 'same command again' }) }
|
|
235
|
+
if (!v) fail(`gang.fun knows no weekly launch issue ${issue}`)
|
|
236
|
+
return out({ success: true, issue: withTimes(v), ...(me && { mine: [mineRow(await mine(issue, me))].filter(Boolean) }), url: WEEKLY_URL, note: WEEKLY_NOTE })
|
|
237
|
+
}
|
|
238
|
+
// my applications: the open issue's, the week before it (closed, being picked: the previous pick may still be the
|
|
239
|
+
// featured `current` then) and current's, newest first
|
|
240
|
+
const live = Array.isArray(b.live) ? b.live : b.current && ['teaser', 'launching', 'featured'].includes(b.current.status) ? [b.current] : []
|
|
241
|
+
const issues = [...new Set([b.apply?.issue, weekBefore(b.apply?.issue), b.current?.issue, ...live.map((v) => v?.issue)].filter((i) => ISSUE_RE.test(i ?? '')))]
|
|
242
|
+
.sort().reverse()
|
|
243
|
+
const mineRows = me ? (await Promise.all(issues.map((i) => mine(i, me)))).filter(Boolean).map(mineRow) : []
|
|
244
|
+
return out({
|
|
245
|
+
success: true,
|
|
246
|
+
// live: every issue in teaser / launching / featured, newest first (two from Thursday 20:00 until the last pick's week ends)
|
|
247
|
+
apply: withTimes(b.apply), current: withTimes(b.current), live: live.map(withTimes), past: (b.past || []).map(withTimes), rules: b.rules ?? null,
|
|
248
|
+
...(me && { mine: mineRows }),
|
|
249
|
+
url: WEEKLY_URL, note: WEEKLY_NOTE,
|
|
250
|
+
next: b.apply?.open ? 'gang weekly apply --name … --symbol … --logo ./logo.png --description "…" --contact @you (preview; add --yes to sign and submit)' : null,
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (sub === 'apply') {
|
|
255
|
+
const unknown = Object.keys(Object.fromEntries(process.argv.slice(4).filter((a) => a.startsWith('--')).map((a) => [a.slice(2), 1])))
|
|
256
|
+
.filter((f) => !APPLY_FLAGS.includes(f))
|
|
257
|
+
if (unknown.length) fail(`gang weekly apply does not take --${unknown[0]} (it takes --${APPLY_FLAGS.filter((f) => f !== 'keep-logo-uri').join(', --')})`)
|
|
258
|
+
if (flag('keep-logo-uri')) fail('--keep-logo-uri: the logo must be on gang.fun (--logo ./file.png, or --logo-uri with a gang upload-logo URL or another image URL, which is copied to gang.fun)')
|
|
259
|
+
let fields
|
|
260
|
+
try { fields = applicationFields({ opt, flag }) } catch (e) { fail(e.message, { code: 'USAGE', ...(e.field && { field: e.field }) }) }
|
|
261
|
+
// the logo: exactly one of a local file or a URL, checked here so the preview can't promise what --yes then refuses
|
|
262
|
+
const files = LOGO_FLAGS.filter((f) => flag(f))
|
|
263
|
+
if (!files.length && !flag('logo-uri')) fail('bad_field: --logo ./file.png (or --logo-uri <image URL>) is required', { code: 'USAGE', field: 'logo' })
|
|
264
|
+
if (files.length > 1 || (files.length && flag('logo-uri'))) fail('use either --logo <file> or --logo-uri <URL>, not both', { code: 'USAGE', field: 'logo' })
|
|
265
|
+
const logoArg = files.length ? opt(files[0]) : opt('logo-uri')
|
|
266
|
+
if (logoArg == null || logoArg.startsWith('--') || !logoArg.trim()) fail(`--${files[0] || 'logo-uri'} needs a value`, { code: 'USAGE', field: 'logo' })
|
|
267
|
+
if (files.length) {
|
|
268
|
+
try { if (!statSync(logoArg).isFile()) throw new Error('not a file') } catch { fail(`--${files[0]}: no file at ${logoArg}`, { code: 'USAGE', field: 'logo' }) }
|
|
269
|
+
} else if (ipfsCid(logoArg)) {
|
|
270
|
+
// ipfs://<cid> or the CDN URL must be a file on gang.fun's bucket (resolveLogoUri would offer --keep-logo-uri)
|
|
271
|
+
try { await checkGangLogo(cdnUrl(ipfsCid(logoArg))) } catch (e) {
|
|
272
|
+
fail(`--logo-uri: ${e.message}`, { field: 'logo', ...(e.retryable ? { retry: 'same command again' } : { code: 'USAGE' }) })
|
|
273
|
+
}
|
|
274
|
+
} else if (!/^https?:\/\//i.test(logoArg)) {
|
|
275
|
+
fail('--logo-uri takes a gang.fun logo (ipfs://<cid> or its cdn.gang.fun URL) or an http(s) image URL to copy there', { code: 'USAGE', field: 'logo' })
|
|
276
|
+
}
|
|
277
|
+
const b = await board()
|
|
278
|
+
const issue = issueOf(b)
|
|
279
|
+
const open = b.apply?.issue === issue && b.apply.open
|
|
280
|
+
if (!open) fail(`applications for ${issue} are not open${b.apply?.issue ? ` (open next: ${b.apply.issue}, ${localTime(b.apply.opensAt)} – ${localTime(b.apply.closesAt)})` : ''}`, { apply: withTimes(b.apply) })
|
|
281
|
+
if (!signedIn()) fail(SIGN_IN)
|
|
282
|
+
// gang.fun refuses a wallet without an Agent ID (no_agent_id); the create gate checks it again at launch
|
|
283
|
+
const w = wallet()
|
|
284
|
+
const rules = b.rules ?? {}
|
|
285
|
+
const terms = [
|
|
286
|
+
`If picked, launch it with gang create (a V3 curve token on ${rules.pad || 'GangLaunchpad 3.0'}, not --fair / --fly) from ${w} with symbol ${fields.symbol} at ${localTime(b.apply.launchAt) ?? 'Friday 20:00 UTC+8'}.`,
|
|
287
|
+
`The pin is withdrawn early if the creator sells more than ${((rules.revokeSellBps ?? 2000) / 100).toFixed(0)}% of their holding during the 7-day featured week.`,
|
|
288
|
+
'No buy-back and no reward: the event pays in attention (gang.fun homepage, X / TG posts, the CLI trending row).',
|
|
289
|
+
'Only the gang.fun team sees contact; everything else may be shown publicly once picked.',
|
|
290
|
+
]
|
|
291
|
+
if (!flag('yes')) {
|
|
292
|
+
return out({
|
|
293
|
+
success: true, preview: true, issue, number: b.apply.number ?? null,
|
|
294
|
+
// what --yes signs and sends, but the logo: a local file / another host's image becomes ipfs://<cid> on upload
|
|
295
|
+
application: { issue, wallet: w.toLowerCase(), ...fields, logo: ipfsCid(logoArg) ? ipfsUri(ipfsCid(logoArg)) : logoArg },
|
|
296
|
+
...(!ipfsCid(logoArg) && { logoNote: `${files.length ? 'the file' : 'the image'} is uploaded to gang.fun with --yes; the application carries its ipfs://<cid>` }),
|
|
297
|
+
terms, confirm: `${['gang', ...process.argv.slice(2)].map(shellWord).join(' ')} --yes`, url: WEEKLY_URL,
|
|
298
|
+
note: 'Nothing was signed or sent. Show this to the user; only on their OK run confirm (it uploads the logo, signs with the Agent wallet, no transaction, and submits). Applying again while open replaces the earlier application.',
|
|
299
|
+
})
|
|
300
|
+
}
|
|
301
|
+
const logo = await resolveLogo()
|
|
302
|
+
const cid = ipfsCid(logo.logoURI || '')
|
|
303
|
+
if (!cid) fail('the logo must be on gang.fun\'s IPFS bucket: use --logo ./file.png or --logo-uri with a gang upload-logo URL', { got: logo.logoURI || null })
|
|
304
|
+
const application = { issue, wallet: w.toLowerCase(), ...fields, logo: ipfsUri(cid) }
|
|
305
|
+
const expires = Math.floor(Date.now() / 1000) + SIGN_TTL_S
|
|
306
|
+
let signature
|
|
307
|
+
try {
|
|
308
|
+
signature = bawSignTyped(w, typedData('WeeklyApply', { wallet: w, issue, digest: applicationDigest(application), expires }))
|
|
309
|
+
} catch (e) { fail(e.message, e.retryable ? { retry: 'same command again' } : {}) }
|
|
310
|
+
let r
|
|
311
|
+
try { r = await post('/weekly/apply', { application, expires, signature }) } catch (e) { refused(e) }
|
|
312
|
+
return out({
|
|
313
|
+
success: true, issue, status: r.status ?? 'pending', replaced: !!r.replaced, application,
|
|
314
|
+
...(logo.uploaded && { logoUploaded: logo.upload?.url ?? true }),
|
|
315
|
+
note: `Submitted. The team picks one application on ${b.apply.launchAt > 0 ? localTime(b.apply.launchAt - 32 * 3600) : 'Thursday 12:00 UTC+8'} and contacts the pick; the pick goes public 24 hours before the launch. gang weekly lists it under mine, with its status.`,
|
|
316
|
+
url: WEEKLY_URL,
|
|
317
|
+
})
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (sub === 'withdraw') {
|
|
321
|
+
const b = await board()
|
|
322
|
+
const issue = issueOf(b)
|
|
323
|
+
if (!(b.apply?.issue === issue && b.apply.open)) fail(`applications for ${issue} are closed: an application can only be withdrawn while they are open`)
|
|
324
|
+
if (!signedIn()) fail(SIGN_IN)
|
|
325
|
+
const w = wallet()
|
|
326
|
+
const my = await mine(issue, w)
|
|
327
|
+
if (!my) fail(`no application from ${w} for ${issue}`)
|
|
328
|
+
if (my.status === 'withdrawn') fail(`the application from ${w} for ${issue} is already withdrawn`)
|
|
329
|
+
if (!flag('yes')) {
|
|
330
|
+
return out({
|
|
331
|
+
success: true, preview: true, withdraw: { issue, wallet: w.toLowerCase(), status: my.status, symbol: my.symbol },
|
|
332
|
+
confirm: `${['gang', ...process.argv.slice(2)].map(shellWord).join(' ')} --yes`,
|
|
333
|
+
note: 'Nothing was signed or sent. On the user\'s OK run confirm.',
|
|
334
|
+
})
|
|
335
|
+
}
|
|
336
|
+
const expires = Math.floor(Date.now() / 1000) + SIGN_TTL_S
|
|
337
|
+
let signature
|
|
338
|
+
try { signature = bawSignTyped(w, typedData('WeeklyWithdraw', { wallet: w, issue, expires })) } catch (e) { fail(e.message, e.retryable ? { retry: 'same command again' } : {}) }
|
|
339
|
+
let r
|
|
340
|
+
try { r = await post('/weekly/withdraw', { issue, wallet: w.toLowerCase(), expires, signature }) } catch (e) { refused(e) }
|
|
341
|
+
return out({ success: true, issue, status: r.status ?? 'withdrawn' })
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
fail(`unknown gang weekly command: ${sub} (gang weekly | gang weekly apply … | gang weekly withdraw)`)
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** The issue a week before (YYYY-MM-DD), or null. */
|
|
348
|
+
function weekBefore(issue) {
|
|
349
|
+
if (!ISSUE_RE.test(issue ?? '')) return null
|
|
350
|
+
const t = Date.parse(`${issue}T00:00:00Z`)
|
|
351
|
+
return Number.isFinite(t) ? new Date(t - 7 * 86400_000).toISOString().slice(0, 10) : null
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** A word as a POSIX shell reads it back: plain words as they are, the rest in single quotes. */
|
|
355
|
+
function shellWord(w) {
|
|
356
|
+
return /^[A-Za-z0-9_./:@,=+-]+$/.test(w) ? w : `'${String(w).replace(/'/g, `'\\''`)}'`
|
|
357
|
+
}
|