Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
### 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.
12 changes: 10 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 (
Expand Down Expand Up @@ -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);
Expand Down
41 changes: 33 additions & 8 deletions src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PublicKey>;
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;
Expand Down Expand Up @@ -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();
Expand Down