From c9e1c3ade57120f84279dbb3436961f565d03e6a Mon Sep 17 00:00:00 2001 From: mooncitydev Date: Thu, 2 Apr 2026 05:03:14 +0900 Subject: [PATCH] fix version flag and compute unit price option, spl-token typings for build Made-with: Cursor --- README.md | 13 ++++++++----- src/index.ts | 12 ++++++++++-- src/lib/api.ts | 41 +++++++++++++++++++++++++++++++++-------- 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index a0bc47f..df9cf2e 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,12 @@ Nodejs version >= 16 `npm install -g @sqds/cli` ### Running the tool -Running the simple command will start the tool and ask a few setup questions for the wallet and the network cluster.\ -`squads-cli` +Run `squads-cli` to start the tool; it will prompt for wallet path and cluster (unless you pass flags below). -### Cluster Option -Providing the cluster will bypass the question upon startup\ -`squads-cli --cluster https://api.mainnet-beta.solana.com` \ No newline at end of file +### Cluster option +Pass a cluster RPC URL to skip the cluster prompt: + +`squads-cli --cluster https://api.mainnet-beta.solana.com` + +### Optional flags +Run `squads-cli --help` for the exact names. Useful options include `--computeUnitPrice` (priority fee in micro-lamports) and `--programId` / `--programManagerId` / `--txMetaProgramId` when you need to override program IDs. \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 0cf365d..531111b 100755 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,8 @@ #!/usr/bin/env node import clear from 'clear'; import chalk from 'chalk'; +import { readFileSync } from 'fs'; +import { join } from 'path'; import Menu from "./lib/menu.js"; import CliWallet from './lib/wallet.js'; @@ -11,13 +13,19 @@ import yargs from 'yargs'; import {hideBin} from 'yargs/helpers' import {parseLedgerWallet} from "@marinade.finance/ledger-utils"; -const VERSION = "2.1.3"; +const { version: cliVersion } = JSON.parse( + readFileSync(join(__dirname, '../package.json'), 'utf-8'), +) as { version: string }; const argv = yargs(hideBin(process.argv)).options({ cluster: { type: 'string'}, programId: { type: 'string'}, programManagerId: { type: 'string'}, txMetaProgramId: { type: 'string'}, + computeUnitPrice: { + type: 'number', + describe: 'Optional priority fee in micro-lamports (ComputeBudget setComputeUnitPrice)', + }, }).parseSync(); const load = async ( @@ -75,7 +83,7 @@ if (typeof argv.computeUnitPrice == "number") { if (argv.help){ help(); }else if (argv.version || argv.v){ - console.log(VERSION); + console.log(cliVersion); }else { clear(); load(cluster, programId, programManagerId, txMetaProgramId, computeUnitPrice); diff --git a/src/lib/api.ts b/src/lib/api.ts index 39bee3c..5045af0 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -4,12 +4,31 @@ import * as anchor from "@coral-xyz/anchor"; import BN from "bn.js"; import { getProgramData, upgradeSetAuthorityIx } from "./program.js"; import { getAssets } from "./assets.js"; -import {getAssociatedTokenAddress,createAssociatedTokenAccountInstruction} from "@solana/spl-token"; import {idl} from "../info"; -import { ASSOCIATED_TOKEN_PROGRAM_ID } from "@solana/spl-token"; -import { TOKEN_PROGRAM_ID } from "@solana/spl-token"; import { Wallet } from "@coral-xyz/anchor"; -import {Connection, LAMPORTS_PER_SOL, PublicKey, VoteProgram} from "@solana/web3.js"; +import {Connection, LAMPORTS_PER_SOL, PublicKey, TransactionInstruction, VoteProgram} from "@solana/web3.js"; + +type SplTokenModule = { + getAssociatedTokenAddress: ( + mint: PublicKey, + owner: PublicKey, + allowOwnerOffCurve?: boolean, + programId?: PublicKey, + associatedTokenProgramId?: PublicKey + ) => Promise; + createAssociatedTokenAccountInstruction: ( + payer: PublicKey, + associatedToken: PublicKey, + owner: PublicKey, + mint: PublicKey, + programId?: PublicKey, + associatedTokenProgramId?: PublicKey + ) => TransactionInstruction; + TOKEN_PROGRAM_ID: PublicKey; + ASSOCIATED_TOKEN_PROGRAM_ID: PublicKey; +}; + +const splToken = require("@solana/spl-token") as SplTokenModule; class API{ squads; @@ -311,14 +330,20 @@ class API{ } async createATA(mint: PublicKey, owner: PublicKey){ - const ataPubkey = await getAssociatedTokenAddress(mint,owner,true,TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID) - const createATAIx = await createAssociatedTokenAccountInstruction( + const ataPubkey = await splToken.getAssociatedTokenAddress( + mint, + owner, + true, + splToken.TOKEN_PROGRAM_ID, + splToken.ASSOCIATED_TOKEN_PROGRAM_ID, + ); + const createATAIx = splToken.createAssociatedTokenAccountInstruction( this.wallet.publicKey, ataPubkey, owner, mint, - TOKEN_PROGRAM_ID, - ASSOCIATED_TOKEN_PROGRAM_ID, + splToken.TOKEN_PROGRAM_ID, + splToken.ASSOCIATED_TOKEN_PROGRAM_ID, ); const {blockhash, lastValidBlockHeight} = await this.connection.getLatestBlockhash();