mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-17 23:26:46 +00:00
feat: fix merge
This commit is contained in:
1
src/tools/3land/index.ts
Normal file
1
src/tools/3land/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./create_3land_collectible";
|
||||
@@ -3,13 +3,13 @@ import {
|
||||
SystemProgram,
|
||||
TransactionInstruction,
|
||||
} from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { TOKENS, DEFAULT_OPTIONS } from "../constants";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
import { TOKENS, DEFAULT_OPTIONS } from "../../constants";
|
||||
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { BN } from "@coral-xyz/anchor";
|
||||
|
||||
import AdrenaClient from "../utils/AdrenaClient";
|
||||
import { sendTx } from "../utils/send_tx";
|
||||
import AdrenaClient from "../../utils/AdrenaClient";
|
||||
import { sendTx } from "../../utils/send_tx";
|
||||
|
||||
const PRICE_DECIMALS = 10;
|
||||
const ADRENA_PROGRAM_ID = new PublicKey(
|
||||
1
src/tools/adrena/index.ts
Normal file
1
src/tools/adrena/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./adrena_perp_trading";
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
import OpenAI from "openai";
|
||||
|
||||
/**
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
|
||||
/**
|
||||
* Get the agents wallet address
|
||||
2
src/tools/agent/index.ts
Normal file
2
src/tools/agent/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./create_image";
|
||||
export * from "./get_wallet_address";
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
import { getAllTld } from "@onsol/tldparser";
|
||||
|
||||
/**
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { TldParser } from "@onsol/tldparser";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { TldParser } from "@onsol/tldparser";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
/**
|
||||
* Get all domains owned by an address for a specific TLD
|
||||
* @param agent SolanaAgentKit instance
|
||||
4
src/tools/alldomains/index.ts
Normal file
4
src/tools/alldomains/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from "./get_all_domains_tlds";
|
||||
export * from "./get_owned_all_domains";
|
||||
export * from "./get_owned_domains_for_tld";
|
||||
export * from "./resolve_domain";
|
||||
@@ -1,5 +1,5 @@
|
||||
import { TldParser } from "@onsol/tldparser";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
|
||||
/**
|
||||
@@ -1,5 +1,5 @@
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { JupiterTokenData } from "../types";
|
||||
import { JupiterTokenData } from "../../types";
|
||||
|
||||
export async function getTokenDataByAddress(
|
||||
mint: PublicKey,
|
||||
1
src/tools/dexscreener/index.ts
Normal file
1
src/tools/dexscreener/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./get_token_data";
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ComputeBudgetProgram } from "@solana/web3.js";
|
||||
import { PoolConfig, Side } from "flash-sdk";
|
||||
import { BN } from "@coral-xyz/anchor";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
import {
|
||||
CLOSE_POSITION_CU,
|
||||
marketSdkInfo,
|
||||
@@ -10,8 +10,8 @@ import {
|
||||
fetchOraclePrice,
|
||||
createPerpClient,
|
||||
get_flash_privilege,
|
||||
} from "../utils/flashUtils";
|
||||
import { FlashCloseTradeParams } from "../types";
|
||||
} from "../../utils/flashUtils";
|
||||
import { FlashCloseTradeParams } from "../../types";
|
||||
|
||||
/**
|
||||
* Closes an existing position on Flash.Trade
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
Custody,
|
||||
} from "flash-sdk";
|
||||
import { BN } from "@coral-xyz/anchor";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
import {
|
||||
ALL_TOKENS,
|
||||
marketSdkInfo,
|
||||
@@ -18,8 +18,8 @@ import {
|
||||
fetchOraclePrice,
|
||||
createPerpClient,
|
||||
get_flash_privilege,
|
||||
} from "../utils/flashUtils";
|
||||
import { FlashTradeParams } from "../types";
|
||||
} from "../../utils/flashUtils";
|
||||
import { FlashTradeParams } from "../../types";
|
||||
|
||||
/**
|
||||
* Opens a new position on Flash.Trade
|
||||
2
src/tools/flash/index.ts
Normal file
2
src/tools/flash/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./flash_open_trade";
|
||||
export * from "./flash_close_trade";
|
||||
@@ -1,6 +1,6 @@
|
||||
import { VersionedTransaction } from "@solana/web3.js";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { GibworkCreateTaskReponse, SolanaAgentKit } from "../index";
|
||||
import { GibworkCreateTaskReponse, SolanaAgentKit } from "../../index";
|
||||
|
||||
/**
|
||||
* Create an new task on Gibwork
|
||||
1
src/tools/gibwork/index.ts
Normal file
1
src/tools/gibwork/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./create_gibwork_task";
|
||||
@@ -1,50 +1,25 @@
|
||||
export * from "./adrena_perp_trading";
|
||||
export * from "./close_empty_token_accounts";
|
||||
export * from "./create_3land_collectible";
|
||||
export * from "./create_gibwork_task";
|
||||
export * from "./create_image";
|
||||
export * from "./create_tiplinks";
|
||||
export * from "./deploy_collection";
|
||||
export * from "./deploy_token";
|
||||
export * from "./fetch_price";
|
||||
export * from "./flash_close_trade";
|
||||
export * from "./flash_open_trade";
|
||||
export * from "./get_all_domains_tlds";
|
||||
export * from "./get_all_registered_all_domains";
|
||||
export * from "./get_balance";
|
||||
export * from "./get_balance_other";
|
||||
export * from "./get_main_all_domains_domain";
|
||||
export * from "./get_owned_all_domains";
|
||||
export * from "./get_owned_domains_for_tld";
|
||||
export * from "./get_primary_domain";
|
||||
export * from "./get_token_data";
|
||||
export * from "./get_tps";
|
||||
export * from "./get_wallet_address";
|
||||
export * from "./launch_pumpfun_token";
|
||||
export * from "./lend";
|
||||
export * from "./manifest_trade";
|
||||
export * from "./mint_nft";
|
||||
export * from "./multisig_tools";
|
||||
export * from "./openbook_create_market";
|
||||
export * from "./orca_close_position";
|
||||
export * from "./orca_create_clmm";
|
||||
export * from "./orca_create_single_sided_liquidity_pool";
|
||||
export * from "./orca_fetch_positions";
|
||||
export * from "./orca_open_centered_position_with_liquidity";
|
||||
export * from "./orca_open_single_sided_position";
|
||||
export * from "./pyth_fetch_price";
|
||||
export * from "./raydium_create_ammV4";
|
||||
export * from "./raydium_create_clmm";
|
||||
export * from "./raydium_create_cpmm";
|
||||
export * from "./register_domain";
|
||||
export * from "./request_faucet_funds";
|
||||
export * from "./resolve_domain";
|
||||
export * from "./resolve_sol_domain";
|
||||
export * from "./rock_paper_scissor";
|
||||
export * from "./adrena";
|
||||
export * from "./sns";
|
||||
export * from "./dexscreener";
|
||||
export * from "./alldomains";
|
||||
export * from "./flash";
|
||||
export * from "./gibwork";
|
||||
export * from "./jupiter";
|
||||
export * from "./lulo";
|
||||
export * from "./manifest";
|
||||
export * from "./solana";
|
||||
export * from "./agent";
|
||||
export * from "./metaplex";
|
||||
export * from "./openbook";
|
||||
export * from "./orca";
|
||||
export * from "./pumpfun";
|
||||
export * from "./pyth";
|
||||
export * from "./raydium";
|
||||
export * from "./rugcheck";
|
||||
export * from "./send_compressed_airdrop";
|
||||
export * from "./stake_with_jup";
|
||||
export * from "./stake_with_solayer";
|
||||
export * from "./tensor_trade";
|
||||
export * from "./trade";
|
||||
export * from "./transfer";
|
||||
export * from "./sendarcade";
|
||||
export * from "./solayer";
|
||||
export * from "./tensor";
|
||||
export * from "./3land";
|
||||
export * from "./tiplink";
|
||||
export * from "./lightprotocol";
|
||||
export * from "./squads";
|
||||
|
||||
3
src/tools/jupiter/index.ts
Normal file
3
src/tools/jupiter/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./fetch_price";
|
||||
export * from "./stake_with_jup";
|
||||
export * from "./trade";
|
||||
@@ -1,5 +1,5 @@
|
||||
import { VersionedTransaction } from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
|
||||
/**
|
||||
* Stake SOL with Jup validator
|
||||
@@ -1,11 +1,11 @@
|
||||
import { VersionedTransaction, PublicKey } from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
import {
|
||||
TOKENS,
|
||||
DEFAULT_OPTIONS,
|
||||
JUP_API,
|
||||
JUP_REFERRAL_ADDRESS,
|
||||
} from "../constants";
|
||||
} from "../../constants";
|
||||
import { getMint } from "@solana/spl-token";
|
||||
/**
|
||||
* Swap tokens using Jupiter Exchange
|
||||
1
src/tools/lightprotocol/index.ts
Normal file
1
src/tools/lightprotocol/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./send_compressed_airdrop";
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
PublicKey,
|
||||
TransactionInstruction,
|
||||
} from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
import {
|
||||
buildAndSignTx,
|
||||
calculateComputeUnitPrice,
|
||||
1
src/tools/lulo/index.ts
Normal file
1
src/tools/lulo/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./lend";
|
||||
@@ -1,5 +1,5 @@
|
||||
import { VersionedTransaction } from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
|
||||
/**
|
||||
* Lend tokens for yields using Lulo
|
||||
1
src/tools/manifest/index.ts
Normal file
1
src/tools/manifest/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./manifest_trade";
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
Transaction,
|
||||
TransactionInstruction,
|
||||
} from "@solana/web3.js";
|
||||
import { BatchOrderPattern, OrderParams, SolanaAgentKit } from "../index";
|
||||
import { BatchOrderPattern, OrderParams, SolanaAgentKit } from "../../index";
|
||||
|
||||
export async function manifestCreateMarket(
|
||||
agent: SolanaAgentKit,
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
import {
|
||||
generateSigner,
|
||||
keypairIdentity,
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
mplCore,
|
||||
ruleSet,
|
||||
} from "@metaplex-foundation/mpl-core";
|
||||
import { CollectionOptions, CollectionDeployment } from "../types";
|
||||
import { CollectionOptions, CollectionDeployment } from "../../types";
|
||||
import {
|
||||
fromWeb3JsKeypair,
|
||||
toWeb3JsPublicKey,
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
|
||||
import { generateSigner, keypairIdentity } from "@metaplex-foundation/umi";
|
||||
3
src/tools/metaplex/index.ts
Normal file
3
src/tools/metaplex/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./deploy_collection";
|
||||
export * from "./mint_nft";
|
||||
export * from "./deploy_token";
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
import { generateSigner, keypairIdentity } from "@metaplex-foundation/umi";
|
||||
import { create, mplCore } from "@metaplex-foundation/mpl-core";
|
||||
import { fetchCollection } from "@metaplex-foundation/mpl-core";
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
toWeb3JsPublicKey,
|
||||
} from "@metaplex-foundation/umi-web3js-adapters";
|
||||
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
|
||||
import { MintCollectionNFTResponse } from "../types";
|
||||
import { MintCollectionNFTResponse } from "../../types";
|
||||
|
||||
/**
|
||||
* Mint a new NFT as part of an existing collection
|
||||
@@ -1,428 +0,0 @@
|
||||
import {
|
||||
LAMPORTS_PER_SOL,
|
||||
PublicKey,
|
||||
SystemProgram,
|
||||
Transaction,
|
||||
TransactionInstruction,
|
||||
TransactionMessage,
|
||||
} from "@solana/web3.js";
|
||||
import * as multisig from "@sqds/multisig";
|
||||
import {
|
||||
getAssociatedTokenAddress,
|
||||
createAssociatedTokenAccountInstruction,
|
||||
getMint,
|
||||
createTransferInstruction,
|
||||
} from "@solana/spl-token";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
|
||||
const { Multisig } = multisig.accounts;
|
||||
|
||||
/**
|
||||
* Creates a new Squads multisig account.
|
||||
*
|
||||
* @param agent - The SolanaAgentKit instance containing the connection and wallet information.
|
||||
* @param creator - The public key of the creator who will be a member of the multisig.
|
||||
* @returns A promise that resolves to the transaction ID of the multisig creation transaction.
|
||||
*
|
||||
* @throws Will throw an error if the transaction fails.
|
||||
*/
|
||||
export async function create_squads_multisig(
|
||||
agent: SolanaAgentKit,
|
||||
creator: PublicKey,
|
||||
): Promise<string> {
|
||||
const connection = agent.connection;
|
||||
const createKey = agent.wallet; // can be any keypair, using the agent wallet as only one multisig is required
|
||||
|
||||
const [multisigPda] = multisig.getMultisigPda({
|
||||
createKey: createKey.publicKey,
|
||||
});
|
||||
|
||||
const programConfigPda = multisig.getProgramConfigPda({})[0];
|
||||
|
||||
const programConfig =
|
||||
await multisig.accounts.ProgramConfig.fromAccountAddress(
|
||||
connection,
|
||||
programConfigPda,
|
||||
);
|
||||
|
||||
const configTreasury = programConfig.treasury;
|
||||
const tx = multisig.transactions.multisigCreateV2({
|
||||
blockhash: (await connection.getLatestBlockhash()).blockhash,
|
||||
treasury: configTreasury,
|
||||
createKey: createKey.publicKey,
|
||||
creator: agent.wallet.publicKey,
|
||||
multisigPda,
|
||||
configAuthority: null,
|
||||
timeLock: 0,
|
||||
threshold: 2,
|
||||
rentCollector: null,
|
||||
members: [
|
||||
{
|
||||
key: agent.wallet.publicKey,
|
||||
permissions: multisig.types.Permissions.all(),
|
||||
},
|
||||
{
|
||||
key: creator,
|
||||
permissions: multisig.types.Permissions.all(),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
tx.sign([agent.wallet, createKey]);
|
||||
|
||||
const txId = connection.sendRawTransaction(tx.serialize());
|
||||
|
||||
return txId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a proposal for a multisig transaction.
|
||||
*
|
||||
* @param {SolanaAgentKit} agent - The Solana agent kit instance.
|
||||
* @param {number | bigint} [transactionIndex] - Optional transaction index. If not provided, the current transaction index will be used.
|
||||
* @returns {Promise<string>} - The transaction ID of the created proposal.
|
||||
* @throws {Error} - Throws an error if the proposal creation fails.
|
||||
*/
|
||||
export async function multisig_create_proposal(
|
||||
agent: SolanaAgentKit,
|
||||
transactionIndex?: number | bigint,
|
||||
): Promise<string> {
|
||||
try {
|
||||
const createKey = agent.wallet;
|
||||
const [multisigPda] = multisig.getMultisigPda({
|
||||
createKey: createKey.publicKey,
|
||||
});
|
||||
const multisigInfo = await Multisig.fromAccountAddress(
|
||||
agent.connection,
|
||||
multisigPda,
|
||||
);
|
||||
const currentTransactionIndex = Number(multisigInfo.transactionIndex);
|
||||
if (!transactionIndex) {
|
||||
transactionIndex = BigInt(currentTransactionIndex);
|
||||
} else if (typeof transactionIndex !== "bigint") {
|
||||
transactionIndex = BigInt(transactionIndex);
|
||||
}
|
||||
const multisigTx = multisig.transactions.proposalCreate({
|
||||
blockhash: (await agent.connection.getLatestBlockhash()).blockhash,
|
||||
feePayer: agent.wallet_address,
|
||||
multisigPda,
|
||||
transactionIndex,
|
||||
creator: agent.wallet_address,
|
||||
});
|
||||
|
||||
multisigTx.sign([agent.wallet]);
|
||||
const tx = await agent.connection.sendRawTransaction(
|
||||
multisigTx.serialize(),
|
||||
);
|
||||
return tx;
|
||||
} catch (error: any) {
|
||||
throw new Error(`Create proposal failed: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfer SOL or SPL tokens to a multisig treasury vault.
|
||||
* @param agent SolanaAgentKit instance
|
||||
* @param amount Amount to transfer
|
||||
* @param vaultIndex Optional vault index, default is 0
|
||||
* @param mint Optional mint address for SPL tokens
|
||||
* @returns Transaction signature
|
||||
*/
|
||||
export async function multisig_deposit_to_treasury(
|
||||
agent: SolanaAgentKit,
|
||||
amount: number,
|
||||
vaultIndex?: number,
|
||||
mint?: PublicKey,
|
||||
): Promise<string> {
|
||||
try {
|
||||
let tx: string;
|
||||
if (!vaultIndex) {
|
||||
vaultIndex = 0;
|
||||
}
|
||||
const createKey = agent.wallet;
|
||||
const [multisigPda] = multisig.getMultisigPda({
|
||||
createKey: createKey.publicKey,
|
||||
});
|
||||
const [vaultPda] = multisig.getVaultPda({
|
||||
multisigPda,
|
||||
index: vaultIndex,
|
||||
});
|
||||
const to = vaultPda;
|
||||
if (!mint) {
|
||||
// Transfer native SOL
|
||||
const transaction = new Transaction().add(
|
||||
SystemProgram.transfer({
|
||||
fromPubkey: agent.wallet_address,
|
||||
toPubkey: to,
|
||||
lamports: amount * LAMPORTS_PER_SOL,
|
||||
}),
|
||||
);
|
||||
|
||||
tx = await agent.connection.sendTransaction(transaction, [agent.wallet]);
|
||||
} else {
|
||||
// Transfer SPL token
|
||||
const fromAta = await getAssociatedTokenAddress(
|
||||
mint,
|
||||
agent.wallet_address,
|
||||
);
|
||||
const transaction = new Transaction();
|
||||
const toAta = await getAssociatedTokenAddress(mint, to, true);
|
||||
const toTokenAccountInfo = await agent.connection.getAccountInfo(toAta);
|
||||
// Create associated token account if it doesn't exist
|
||||
if (!toTokenAccountInfo) {
|
||||
transaction.add(
|
||||
createAssociatedTokenAccountInstruction(
|
||||
agent.wallet_address,
|
||||
toAta,
|
||||
to,
|
||||
mint,
|
||||
),
|
||||
);
|
||||
}
|
||||
// Get mint info to determine decimals
|
||||
const mintInfo = await getMint(agent.connection, mint);
|
||||
const adjustedAmount = amount * Math.pow(10, mintInfo.decimals);
|
||||
|
||||
transaction.add(
|
||||
createTransferInstruction(
|
||||
fromAta,
|
||||
toAta,
|
||||
agent.wallet_address,
|
||||
adjustedAmount,
|
||||
),
|
||||
);
|
||||
|
||||
tx = await agent.connection.sendTransaction(transaction, [agent.wallet]);
|
||||
}
|
||||
|
||||
return tx;
|
||||
} catch (error: any) {
|
||||
throw new Error(`Transfer failed: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Approves a proposal in a Solana multisig wallet.
|
||||
*
|
||||
* @param {SolanaAgentKit} agent - The Solana agent kit instance.
|
||||
* @param {number | bigint} [transactionIndex] - The index of the transaction to approve. If not provided, the current transaction index will be used.
|
||||
* @returns {Promise<string>} - A promise that resolves to the transaction ID of the approved proposal.
|
||||
* @throws {Error} - Throws an error if the approval process fails.
|
||||
*/
|
||||
export async function multisig_approve_proposal(
|
||||
agent: SolanaAgentKit,
|
||||
transactionIndex?: number | bigint,
|
||||
): Promise<string> {
|
||||
try {
|
||||
const createKey = agent.wallet;
|
||||
const [multisigPda] = multisig.getMultisigPda({
|
||||
createKey: createKey.publicKey,
|
||||
});
|
||||
const multisigInfo = await Multisig.fromAccountAddress(
|
||||
agent.connection,
|
||||
multisigPda,
|
||||
);
|
||||
const currentTransactionIndex = Number(multisigInfo.transactionIndex);
|
||||
if (!transactionIndex) {
|
||||
transactionIndex = BigInt(currentTransactionIndex);
|
||||
} else if (typeof transactionIndex !== "bigint") {
|
||||
transactionIndex = BigInt(transactionIndex);
|
||||
}
|
||||
|
||||
// const [proposalPda, proposalBump] = multisig.getProposalPda({
|
||||
// multisigPda,
|
||||
// transactionIndex,
|
||||
// });
|
||||
|
||||
const multisigTx = multisig.transactions.proposalApprove({
|
||||
blockhash: (await agent.connection.getLatestBlockhash()).blockhash,
|
||||
feePayer: agent.wallet.publicKey,
|
||||
multisigPda,
|
||||
transactionIndex: transactionIndex,
|
||||
member: agent.wallet.publicKey,
|
||||
});
|
||||
|
||||
multisigTx.sign([agent.wallet]);
|
||||
const tx = await agent.connection.sendRawTransaction(
|
||||
multisigTx.serialize(),
|
||||
);
|
||||
return tx;
|
||||
} catch (error: any) {
|
||||
throw new Error(`Approve proposal failed: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a transaction on the Solana blockchain using the provided agent.
|
||||
*
|
||||
* @param {SolanaAgentKit} agent - The Solana agent kit instance containing the wallet and connection.
|
||||
* @param {number | bigint} [transactionIndex] - Optional transaction index to execute. If not provided, the current transaction index from the multisig account will be used.
|
||||
* @returns {Promise<string>} - A promise that resolves to the transaction signature string.
|
||||
* @throws {Error} - Throws an error if the transaction execution fails.
|
||||
*/
|
||||
export async function multisig_execute_proposal(
|
||||
agent: SolanaAgentKit,
|
||||
transactionIndex?: number | bigint,
|
||||
): Promise<string> {
|
||||
try {
|
||||
const createKey = agent.wallet;
|
||||
const [multisigPda] = multisig.getMultisigPda({
|
||||
createKey: createKey.publicKey,
|
||||
});
|
||||
const multisigInfo = await Multisig.fromAccountAddress(
|
||||
agent.connection,
|
||||
multisigPda,
|
||||
);
|
||||
const currentTransactionIndex = Number(multisigInfo.transactionIndex);
|
||||
if (!transactionIndex) {
|
||||
transactionIndex = BigInt(currentTransactionIndex);
|
||||
} else if (typeof transactionIndex !== "bigint") {
|
||||
transactionIndex = BigInt(transactionIndex);
|
||||
}
|
||||
const multisigTx = await multisig.transactions.vaultTransactionExecute({
|
||||
connection: agent.connection,
|
||||
blockhash: (await agent.connection.getLatestBlockhash()).blockhash,
|
||||
feePayer: agent.wallet.publicKey,
|
||||
multisigPda,
|
||||
transactionIndex,
|
||||
member: agent.wallet.publicKey,
|
||||
});
|
||||
|
||||
multisigTx.sign([agent.wallet]);
|
||||
const tx = await agent.connection.sendRawTransaction(
|
||||
multisigTx.serialize(),
|
||||
);
|
||||
return tx;
|
||||
} catch (error: any) {
|
||||
throw new Error(`Execute proposal failed: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rejects a proposal in a Solana multisig setup.
|
||||
*
|
||||
* @param agent - The SolanaAgentKit instance containing the wallet and connection.
|
||||
* @param transactionIndex - Optional. The index of the transaction to reject. If not provided, the current transaction index will be used.
|
||||
* @returns A promise that resolves to the transaction ID of the rejection transaction.
|
||||
* @throws Will throw an error if the transaction fails.
|
||||
*/
|
||||
export async function multisig_reject_proposal(
|
||||
agent: SolanaAgentKit,
|
||||
transactionIndex?: number | bigint,
|
||||
): Promise<string> {
|
||||
try {
|
||||
const createKey = agent.wallet;
|
||||
const [multisigPda] = multisig.getMultisigPda({
|
||||
createKey: createKey.publicKey,
|
||||
});
|
||||
const multisigInfo = await Multisig.fromAccountAddress(
|
||||
agent.connection,
|
||||
multisigPda,
|
||||
);
|
||||
const currentTransactionIndex = Number(multisigInfo.transactionIndex);
|
||||
if (!transactionIndex) {
|
||||
transactionIndex = BigInt(currentTransactionIndex);
|
||||
} else if (typeof transactionIndex !== "bigint") {
|
||||
transactionIndex = BigInt(transactionIndex);
|
||||
}
|
||||
|
||||
const multisigTx = multisig.transactions.proposalReject({
|
||||
blockhash: (await agent.connection.getLatestBlockhash()).blockhash,
|
||||
feePayer: agent.wallet.publicKey,
|
||||
multisigPda,
|
||||
transactionIndex: transactionIndex,
|
||||
member: agent.wallet.publicKey,
|
||||
});
|
||||
|
||||
multisigTx.sign([agent.wallet]);
|
||||
const tx = await agent.connection.sendRawTransaction(
|
||||
multisigTx.serialize(),
|
||||
);
|
||||
return tx;
|
||||
} catch (error: any) {
|
||||
throw new Error(`Reject proposal failed: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfer SOL or SPL tokens from a multisig treasury vault to a recipient.
|
||||
* @param agent - SolanaAgentKit instance.
|
||||
* @param amount - Amount to transfer.
|
||||
* @param to - Recipient's public key.
|
||||
* @param vaultIndex - Optional vault index, default is 0.
|
||||
* @param mint - Optional mint address for SPL tokens.
|
||||
* @returns Transaction signature.
|
||||
*/
|
||||
export async function multisig_transfer_from_treasury(
|
||||
agent: SolanaAgentKit,
|
||||
amount: number,
|
||||
to: PublicKey,
|
||||
vaultIndex: number = 0,
|
||||
mint?: PublicKey,
|
||||
): Promise<string> {
|
||||
try {
|
||||
let transferInstruction: TransactionInstruction;
|
||||
|
||||
const createKey = agent.wallet;
|
||||
const [multisigPda] = multisig.getMultisigPda({
|
||||
createKey: createKey.publicKey,
|
||||
});
|
||||
const multisigInfo = await Multisig.fromAccountAddress(
|
||||
agent.connection,
|
||||
multisigPda,
|
||||
);
|
||||
const currentTransactionIndex = Number(multisigInfo.transactionIndex);
|
||||
const transactionIndex = BigInt(currentTransactionIndex + 1);
|
||||
const [vaultPda] = multisig.getVaultPda({
|
||||
multisigPda,
|
||||
index: vaultIndex,
|
||||
});
|
||||
|
||||
if (!mint) {
|
||||
// Transfer native SOL
|
||||
transferInstruction = SystemProgram.transfer({
|
||||
fromPubkey: agent.wallet_address,
|
||||
toPubkey: to,
|
||||
lamports: amount * LAMPORTS_PER_SOL,
|
||||
});
|
||||
} else {
|
||||
// Transfer SPL token
|
||||
const fromAta = await getAssociatedTokenAddress(mint, vaultPda, true);
|
||||
const toAta = await getAssociatedTokenAddress(mint, to, true);
|
||||
const mintInfo = await getMint(agent.connection, mint);
|
||||
const adjustedAmount = amount * Math.pow(10, mintInfo.decimals);
|
||||
|
||||
transferInstruction = createTransferInstruction(
|
||||
fromAta,
|
||||
toAta,
|
||||
agent.wallet_address,
|
||||
adjustedAmount,
|
||||
);
|
||||
}
|
||||
|
||||
const transferMessage = new TransactionMessage({
|
||||
payerKey: vaultPda,
|
||||
recentBlockhash: (await agent.connection.getLatestBlockhash()).blockhash,
|
||||
instructions: [transferInstruction],
|
||||
});
|
||||
|
||||
const multisigTx = multisig.transactions.vaultTransactionCreate({
|
||||
blockhash: (await agent.connection.getLatestBlockhash()).blockhash,
|
||||
feePayer: agent.wallet_address,
|
||||
multisigPda,
|
||||
transactionIndex,
|
||||
creator: agent.wallet_address,
|
||||
vaultIndex: 0,
|
||||
ephemeralSigners: 0,
|
||||
transactionMessage: transferMessage,
|
||||
});
|
||||
|
||||
multisigTx.sign([agent.wallet]);
|
||||
const tx = await agent.connection.sendRawTransaction(
|
||||
multisigTx.serialize(),
|
||||
);
|
||||
return tx;
|
||||
} catch (error: any) {
|
||||
throw new Error(`Transfer failed: ${error}`);
|
||||
}
|
||||
}
|
||||
1
src/tools/openbook/index.ts
Normal file
1
src/tools/openbook/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./openbook_create_market";
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
} from "@raydium-io/raydium-sdk-v2";
|
||||
import { MintLayout, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
|
||||
export async function openbookCreateMarket(
|
||||
agent: SolanaAgentKit,
|
||||
6
src/tools/orca/index.ts
Normal file
6
src/tools/orca/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export * from "./orca_close_position";
|
||||
export * from "./orca_create_clmm";
|
||||
export * from "./orca_create_single_sided_liquidity_pool";
|
||||
export * from "./orca_fetch_positions";
|
||||
export * from "./orca_open_centered_position_with_liquidity";
|
||||
export * from "./orca_open_single_sided_position";
|
||||
@@ -4,15 +4,15 @@ import {
|
||||
TransactionMessage,
|
||||
VersionedTransaction,
|
||||
} from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { Wallet } from "../utils/keypair";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { Wallet } from "../../utils/keypair";
|
||||
import {
|
||||
ORCA_WHIRLPOOL_PROGRAM_ID,
|
||||
WhirlpoolContext,
|
||||
buildWhirlpoolClient,
|
||||
PDAUtil,
|
||||
} from "@orca-so/whirlpools-sdk";
|
||||
import { sendTx } from "../utils/send_tx";
|
||||
import { sendTx } from "../../utils/send_tx";
|
||||
import { Percentage } from "@orca-so/common-sdk";
|
||||
|
||||
/**
|
||||
@@ -4,8 +4,8 @@ import {
|
||||
TransactionMessage,
|
||||
VersionedTransaction,
|
||||
} from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { Wallet } from "../utils/keypair";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { Wallet } from "../../utils/keypair";
|
||||
import { Decimal } from "decimal.js";
|
||||
import {
|
||||
ORCA_WHIRLPOOL_PROGRAM_ID,
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
PoolUtil,
|
||||
buildWhirlpoolClient,
|
||||
} from "@orca-so/whirlpools-sdk";
|
||||
import { sendTx } from "../utils/send_tx";
|
||||
import { sendTx } from "../../utils/send_tx";
|
||||
import { FEE_TIERS } from "./orca_create_single_sided_liquidity_pool";
|
||||
|
||||
/**
|
||||
@@ -4,9 +4,9 @@ import {
|
||||
TransactionMessage,
|
||||
VersionedTransaction,
|
||||
} from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { BN } from "@coral-xyz/anchor";
|
||||
import { Wallet } from "../utils/keypair";
|
||||
import { Wallet } from "../../utils/keypair";
|
||||
import { Decimal } from "decimal.js";
|
||||
import {
|
||||
PDAUtil,
|
||||
@@ -37,7 +37,7 @@ import {
|
||||
getAssociatedTokenAddressSync,
|
||||
TOKEN_2022_PROGRAM_ID,
|
||||
} from "@solana/spl-token";
|
||||
import { sendTx } from "../utils/send_tx";
|
||||
import { sendTx } from "../../utils/send_tx";
|
||||
|
||||
/**
|
||||
* Maps fee tier bps to their corresponding tick spacing values in the Orca Whirlpool protocol.
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { Wallet } from "@coral-xyz/anchor";
|
||||
import {
|
||||
ORCA_WHIRLPOOL_PROGRAM_ID,
|
||||
@@ -5,8 +5,8 @@ import {
|
||||
TransactionMessage,
|
||||
VersionedTransaction,
|
||||
} from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { Wallet } from "../utils/keypair";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { Wallet } from "../../utils/keypair";
|
||||
import { Decimal } from "decimal.js";
|
||||
import {
|
||||
ORCA_WHIRLPOOL_PROGRAM_ID,
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
NO_TOKEN_EXTENSION_CONTEXT,
|
||||
} from "@orca-so/whirlpools-sdk";
|
||||
|
||||
import { sendTx } from "../utils/send_tx";
|
||||
import { sendTx } from "../../utils/send_tx";
|
||||
import { Percentage } from "@orca-so/common-sdk";
|
||||
import { TOKEN_2022_PROGRAM_ID } from "@solana/spl-token";
|
||||
|
||||
@@ -5,8 +5,8 @@ import {
|
||||
TransactionMessage,
|
||||
VersionedTransaction,
|
||||
} from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { Wallet } from "../utils/keypair";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { Wallet } from "../../utils/keypair";
|
||||
import { Decimal } from "decimal.js";
|
||||
import {
|
||||
ORCA_WHIRLPOOL_PROGRAM_ID,
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
TokenExtensionContextForPool,
|
||||
NO_TOKEN_EXTENSION_CONTEXT,
|
||||
} from "@orca-so/whirlpools-sdk";
|
||||
import { sendTx } from "../utils/send_tx";
|
||||
import { sendTx } from "../../utils/send_tx";
|
||||
import { Percentage } from "@orca-so/common-sdk";
|
||||
import { TOKEN_2022_PROGRAM_ID } from "@solana/spl-token";
|
||||
|
||||
1
src/tools/pumpfun/index.ts
Normal file
1
src/tools/pumpfun/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./launch_pumpfun_token";
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
PumpfunLaunchResponse,
|
||||
PumpFunTokenOptions,
|
||||
SolanaAgentKit,
|
||||
} from "../index";
|
||||
} from "../../index";
|
||||
|
||||
async function uploadMetadata(
|
||||
tokenName: string,
|
||||
1
src/tools/pyth/index.ts
Normal file
1
src/tools/pyth/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./pyth_fetch_price";
|
||||
@@ -1,5 +1,5 @@
|
||||
import BN from "bn.js";
|
||||
import { PythPriceFeedIDItem } from "../types";
|
||||
import { PythPriceFeedIDItem } from "../../types";
|
||||
|
||||
/**
|
||||
* Fetch the price feed ID for a given token symbol from Pyth
|
||||
3
src/tools/raydium/index.ts
Normal file
3
src/tools/raydium/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./raydium_create_ammV4";
|
||||
export * from "./raydium_create_clmm";
|
||||
export * from "./raydium_create_cpmm";
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
import { MintLayout, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
|
||||
export async function raydiumCreateAmmV4(
|
||||
agent: SolanaAgentKit,
|
||||
@@ -7,7 +7,7 @@ import { MintLayout } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import Decimal from "decimal.js";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
|
||||
export async function raydiumCreateClmm(
|
||||
agent: SolanaAgentKit,
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
import { MintLayout } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
|
||||
export async function raydiumCreateCpmm(
|
||||
agent: SolanaAgentKit,
|
||||
1
src/tools/rugcheck/index.ts
Normal file
1
src/tools/rugcheck/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./rugcheck";
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TokenCheck } from "../types";
|
||||
import { TokenCheck } from "../../types";
|
||||
|
||||
const BASE_URL = "https://api.rugcheck.xyz/v1";
|
||||
|
||||
1
src/tools/sendarcade/index.ts
Normal file
1
src/tools/sendarcade/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./rock_paper_scissor";
|
||||
@@ -1,5 +1,5 @@
|
||||
import { sendAndConfirmTransaction, Transaction } from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
|
||||
export async function rock_paper_scissor(
|
||||
agent: SolanaAgentKit,
|
||||
@@ -1,7 +1,7 @@
|
||||
import { getAllDomains } from "@bonfida/spl-name-service";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { getAllDomainsTLDs } from "./get_all_domains_tlds";
|
||||
import { getAllDomainsTLDs } from "../alldomains/get_all_domains_tlds";
|
||||
|
||||
/**
|
||||
* Get all registered domains across all TLDs
|
||||
@@ -1,6 +1,6 @@
|
||||
import { getPrimaryDomain as _getPrimaryDomain } from "@bonfida/spl-name-service";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
|
||||
/**
|
||||
* Retrieves the primary .sol domain associated with a given Solana public key.
|
||||
5
src/tools/sns/index.ts
Normal file
5
src/tools/sns/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export * from "./get_all_registered_all_domains";
|
||||
export * from "./get_main_all_domains_domain";
|
||||
export * from "./get_primary_domain";
|
||||
export * from "./register_domain";
|
||||
export * from "./resolve_sol_domain";
|
||||
@@ -1,8 +1,8 @@
|
||||
import { registerDomainNameV2 } from "@bonfida/spl-name-service";
|
||||
import { Transaction } from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
|
||||
import { TOKENS } from "../constants";
|
||||
import { TOKENS } from "../../constants";
|
||||
|
||||
/**
|
||||
* Register a .sol domain name using Bonfida Name Service
|
||||
@@ -1,6 +1,6 @@
|
||||
import { resolve } from "@bonfida/spl-name-service";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
|
||||
/**
|
||||
* Resolves a .sol domain to a Solana PublicKey.
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
Transaction,
|
||||
TransactionInstruction,
|
||||
} from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import {
|
||||
AccountLayout,
|
||||
createCloseAccountInstruction,
|
||||
@@ -1,5 +1,5 @@
|
||||
import { LAMPORTS_PER_SOL, PublicKey } from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
|
||||
/**
|
||||
* Get the balance of SOL or an SPL token for the agent's wallet
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
ParsedAccountData,
|
||||
PublicKey,
|
||||
} from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
|
||||
/**
|
||||
* Get the balance of SOL or an SPL token for the specified wallet address (other than the agent's wallet)
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
|
||||
export async function getTPS(agent: SolanaAgentKit): Promise<number> {
|
||||
const perfSamples = await agent.connection.getRecentPerformanceSamples();
|
||||
6
src/tools/solana/index.ts
Normal file
6
src/tools/solana/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export * from "./get_tps";
|
||||
export * from "./request_faucet_funds";
|
||||
export * from "./close_empty_token_accounts";
|
||||
export * from "./transfer";
|
||||
export * from "./get_balance";
|
||||
export * from "./get_balance_other";
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
import { LAMPORTS_PER_SOL } from "@solana/web3.js";
|
||||
|
||||
/**
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
import { PublicKey, SystemProgram, Transaction } from "@solana/web3.js";
|
||||
import { LAMPORTS_PER_SOL } from "@solana/web3.js";
|
||||
import {
|
||||
1
src/tools/solayer/index.ts
Normal file
1
src/tools/solayer/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./stake_with_solayer";
|
||||
@@ -1,5 +1,5 @@
|
||||
import { VersionedTransaction } from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
|
||||
/**
|
||||
* Stake SOL with Solayer
|
||||
52
src/tools/squads/approve_proposal.ts
Normal file
52
src/tools/squads/approve_proposal.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
import * as multisig from "@sqds/multisig";
|
||||
const { Multisig } = multisig.accounts;
|
||||
|
||||
/**
|
||||
* Approves a proposal in a Solana multisig wallet.
|
||||
*
|
||||
* @param {SolanaAgentKit} agent - The Solana agent kit instance.
|
||||
* @param {number | bigint} [transactionIndex] - The index of the transaction to approve. If not provided, the current transaction index will be used.
|
||||
* @returns {Promise<string>} - A promise that resolves to the transaction ID of the approved proposal.
|
||||
* @throws {Error} - Throws an error if the approval process fails.
|
||||
*/
|
||||
export async function multisig_approve_proposal(
|
||||
agent: SolanaAgentKit,
|
||||
transactionIndex?: number | bigint,
|
||||
): Promise<string> {
|
||||
try {
|
||||
const createKey = agent.wallet;
|
||||
const [multisigPda] = multisig.getMultisigPda({
|
||||
createKey: createKey.publicKey,
|
||||
});
|
||||
const multisigInfo = await Multisig.fromAccountAddress(
|
||||
agent.connection,
|
||||
multisigPda,
|
||||
);
|
||||
const currentTransactionIndex = Number(multisigInfo.transactionIndex);
|
||||
if (!transactionIndex) {
|
||||
transactionIndex = BigInt(currentTransactionIndex);
|
||||
} else if (typeof transactionIndex !== "bigint") {
|
||||
transactionIndex = BigInt(transactionIndex);
|
||||
}
|
||||
// const [proposalPda, proposalBump] = multisig.getProposalPda({
|
||||
// multisigPda,
|
||||
// transactionIndex,
|
||||
// });
|
||||
const multisigTx = multisig.transactions.proposalApprove({
|
||||
blockhash: (await agent.connection.getLatestBlockhash()).blockhash,
|
||||
feePayer: agent.wallet.publicKey,
|
||||
multisigPda,
|
||||
transactionIndex: transactionIndex,
|
||||
member: agent.wallet.publicKey,
|
||||
});
|
||||
|
||||
multisigTx.sign([agent.wallet]);
|
||||
const tx = await agent.connection.sendRawTransaction(
|
||||
multisigTx.serialize(),
|
||||
);
|
||||
return tx;
|
||||
} catch (error: any) {
|
||||
throw new Error(`Transfer failed: ${error}`);
|
||||
}
|
||||
}
|
||||
61
src/tools/squads/create_multisig.ts
Normal file
61
src/tools/squads/create_multisig.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import * as multisig from "@sqds/multisig";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
|
||||
/**
|
||||
* Creates a new Squads multisig account.
|
||||
*
|
||||
* @param agent - The SolanaAgentKit instance containing the connection and wallet information.
|
||||
* @param creator - The public key of the creator who will be a member of the multisig.
|
||||
* @returns A promise that resolves to the transaction ID of the multisig creation transaction.
|
||||
*
|
||||
* @throws Will throw an error if the transaction fails.
|
||||
*/
|
||||
export async function create_squads_multisig(
|
||||
agent: SolanaAgentKit,
|
||||
creator: PublicKey,
|
||||
): Promise<string> {
|
||||
const connection = agent.connection;
|
||||
const createKey = agent.wallet; // can be any keypair, using the agent wallet as only one multisig is required
|
||||
|
||||
const [multisigPda] = multisig.getMultisigPda({
|
||||
createKey: createKey.publicKey,
|
||||
});
|
||||
|
||||
const programConfigPda = multisig.getProgramConfigPda({})[0];
|
||||
|
||||
const programConfig =
|
||||
await multisig.accounts.ProgramConfig.fromAccountAddress(
|
||||
connection,
|
||||
programConfigPda,
|
||||
);
|
||||
|
||||
const configTreasury = programConfig.treasury;
|
||||
const tx = multisig.transactions.multisigCreateV2({
|
||||
blockhash: (await connection.getLatestBlockhash()).blockhash,
|
||||
treasury: configTreasury,
|
||||
createKey: createKey.publicKey,
|
||||
creator: agent.wallet.publicKey,
|
||||
multisigPda,
|
||||
configAuthority: null,
|
||||
timeLock: 0,
|
||||
threshold: 2,
|
||||
rentCollector: null,
|
||||
members: [
|
||||
{
|
||||
key: agent.wallet.publicKey,
|
||||
permissions: multisig.types.Permissions.all(),
|
||||
},
|
||||
{
|
||||
key: creator,
|
||||
permissions: multisig.types.Permissions.all(),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
tx.sign([agent.wallet, createKey]);
|
||||
|
||||
const txId = connection.sendRawTransaction(tx.serialize());
|
||||
|
||||
return txId;
|
||||
}
|
||||
48
src/tools/squads/create_proposal.ts
Normal file
48
src/tools/squads/create_proposal.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
import * as multisig from "@sqds/multisig";
|
||||
const { Multisig } = multisig.accounts;
|
||||
|
||||
/**
|
||||
* Creates a proposal for a multisig transaction.
|
||||
*
|
||||
* @param {SolanaAgentKit} agent - The Solana agent kit instance.
|
||||
* @param {number | bigint} [transactionIndex] - Optional transaction index. If not provided, the current transaction index will be used.
|
||||
* @returns {Promise<string>} - The transaction ID of the created proposal.
|
||||
* @throws {Error} - Throws an error if the proposal creation fails.
|
||||
*/
|
||||
export async function multisig_create_proposal(
|
||||
agent: SolanaAgentKit,
|
||||
transactionIndex?: number | bigint,
|
||||
): Promise<string> {
|
||||
try {
|
||||
const createKey = agent.wallet;
|
||||
const [multisigPda] = multisig.getMultisigPda({
|
||||
createKey: createKey.publicKey,
|
||||
});
|
||||
const multisigInfo = await Multisig.fromAccountAddress(
|
||||
agent.connection,
|
||||
multisigPda,
|
||||
);
|
||||
const currentTransactionIndex = Number(multisigInfo.transactionIndex);
|
||||
if (!transactionIndex) {
|
||||
transactionIndex = BigInt(currentTransactionIndex);
|
||||
} else if (typeof transactionIndex !== "bigint") {
|
||||
transactionIndex = BigInt(transactionIndex);
|
||||
}
|
||||
const multisigTx = multisig.transactions.proposalCreate({
|
||||
blockhash: (await agent.connection.getLatestBlockhash()).blockhash,
|
||||
feePayer: agent.wallet_address,
|
||||
multisigPda,
|
||||
transactionIndex,
|
||||
creator: agent.wallet_address,
|
||||
});
|
||||
|
||||
multisigTx.sign([agent.wallet]);
|
||||
const tx = await agent.connection.sendRawTransaction(
|
||||
multisigTx.serialize(),
|
||||
);
|
||||
return tx;
|
||||
} catch (error: any) {
|
||||
throw new Error(`Transfer failed: ${error}`);
|
||||
}
|
||||
}
|
||||
91
src/tools/squads/deposit_to_treasury.ts
Normal file
91
src/tools/squads/deposit_to_treasury.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
import { PublicKey, SystemProgram, Transaction } from "@solana/web3.js";
|
||||
import { LAMPORTS_PER_SOL } from "@solana/web3.js";
|
||||
import {
|
||||
getAssociatedTokenAddress,
|
||||
createTransferInstruction,
|
||||
getMint,
|
||||
createAssociatedTokenAccountInstruction,
|
||||
} from "@solana/spl-token";
|
||||
import * as multisig from "@sqds/multisig";
|
||||
|
||||
/**
|
||||
* Transfer SOL or SPL tokens to a multisig vault.
|
||||
* @param agent SolanaAgentKit instance
|
||||
* @param amount Amount to transfer
|
||||
* @param vaultIndex Optional vault index, default is 0
|
||||
* @param mint Optional mint address for SPL tokens
|
||||
* @returns Transaction signature
|
||||
*/
|
||||
export async function multisig_deposit_to_treasury(
|
||||
agent: SolanaAgentKit,
|
||||
amount: number,
|
||||
vaultIndex?: number,
|
||||
mint?: PublicKey,
|
||||
): Promise<string> {
|
||||
try {
|
||||
let tx: string;
|
||||
if (!vaultIndex) {
|
||||
vaultIndex = 0;
|
||||
}
|
||||
const createKey = agent.wallet;
|
||||
const [multisigPda] = multisig.getMultisigPda({
|
||||
createKey: createKey.publicKey,
|
||||
});
|
||||
const [vaultPda] = multisig.getVaultPda({
|
||||
multisigPda,
|
||||
index: vaultIndex,
|
||||
});
|
||||
const to = vaultPda;
|
||||
if (!mint) {
|
||||
// Transfer native SOL
|
||||
const transaction = new Transaction().add(
|
||||
SystemProgram.transfer({
|
||||
fromPubkey: agent.wallet_address,
|
||||
toPubkey: to,
|
||||
lamports: amount * LAMPORTS_PER_SOL,
|
||||
}),
|
||||
);
|
||||
|
||||
tx = await agent.connection.sendTransaction(transaction, [agent.wallet]);
|
||||
} else {
|
||||
// Transfer SPL token
|
||||
const fromAta = await getAssociatedTokenAddress(
|
||||
mint,
|
||||
agent.wallet_address,
|
||||
);
|
||||
const transaction = new Transaction();
|
||||
const toAta = await getAssociatedTokenAddress(mint, to, true);
|
||||
const toTokenAccountInfo = await agent.connection.getAccountInfo(toAta);
|
||||
// Create associated token account if it doesn't exist
|
||||
if (!toTokenAccountInfo) {
|
||||
transaction.add(
|
||||
createAssociatedTokenAccountInstruction(
|
||||
agent.wallet_address,
|
||||
toAta,
|
||||
to,
|
||||
mint,
|
||||
),
|
||||
);
|
||||
}
|
||||
// Get mint info to determine decimals
|
||||
const mintInfo = await getMint(agent.connection, mint);
|
||||
const adjustedAmount = amount * Math.pow(10, mintInfo.decimals);
|
||||
|
||||
transaction.add(
|
||||
createTransferInstruction(
|
||||
fromAta,
|
||||
toAta,
|
||||
agent.wallet_address,
|
||||
adjustedAmount,
|
||||
),
|
||||
);
|
||||
|
||||
tx = await agent.connection.sendTransaction(transaction, [agent.wallet]);
|
||||
}
|
||||
|
||||
return tx;
|
||||
} catch (error: any) {
|
||||
throw new Error(`Transfer failed: ${error}`);
|
||||
}
|
||||
}
|
||||
49
src/tools/squads/execute_proposal.ts
Normal file
49
src/tools/squads/execute_proposal.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
import * as multisig from "@sqds/multisig";
|
||||
const { Multisig } = multisig.accounts;
|
||||
|
||||
/**
|
||||
* Executes a transaction on the Solana blockchain using the provided agent.
|
||||
*
|
||||
* @param {SolanaAgentKit} agent - The Solana agent kit instance containing the wallet and connection.
|
||||
* @param {number | bigint} [transactionIndex] - Optional transaction index to execute. If not provided, the current transaction index from the multisig account will be used.
|
||||
* @returns {Promise<string>} - A promise that resolves to the transaction signature string.
|
||||
* @throws {Error} - Throws an error if the transaction execution fails.
|
||||
*/
|
||||
export async function multisig_execute_proposal(
|
||||
agent: SolanaAgentKit,
|
||||
transactionIndex?: number | bigint,
|
||||
): Promise<string> {
|
||||
try {
|
||||
const createKey = agent.wallet;
|
||||
const [multisigPda] = multisig.getMultisigPda({
|
||||
createKey: createKey.publicKey,
|
||||
});
|
||||
const multisigInfo = await Multisig.fromAccountAddress(
|
||||
agent.connection,
|
||||
multisigPda,
|
||||
);
|
||||
const currentTransactionIndex = Number(multisigInfo.transactionIndex);
|
||||
if (!transactionIndex) {
|
||||
transactionIndex = BigInt(currentTransactionIndex);
|
||||
} else if (typeof transactionIndex !== "bigint") {
|
||||
transactionIndex = BigInt(transactionIndex);
|
||||
}
|
||||
const multisigTx = await multisig.transactions.vaultTransactionExecute({
|
||||
connection: agent.connection,
|
||||
blockhash: (await agent.connection.getLatestBlockhash()).blockhash,
|
||||
feePayer: agent.wallet.publicKey,
|
||||
multisigPda,
|
||||
transactionIndex,
|
||||
member: agent.wallet.publicKey,
|
||||
});
|
||||
|
||||
multisigTx.sign([agent.wallet]);
|
||||
const tx = await agent.connection.sendRawTransaction(
|
||||
multisigTx.serialize(),
|
||||
);
|
||||
return tx;
|
||||
} catch (error: any) {
|
||||
throw new Error(`Transfer failed: ${error}`);
|
||||
}
|
||||
}
|
||||
7
src/tools/squads/index.ts
Normal file
7
src/tools/squads/index.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export * from "./create_multisig";
|
||||
export * from "./create_proposal";
|
||||
export * from "./approve_proposal";
|
||||
export * from "./deposit_to_treasury";
|
||||
export * from "./execute_proposal";
|
||||
export * from "./reject_proposal";
|
||||
export * from "./transfer_from_treasury";
|
||||
52
src/tools/squads/reject_proposal.ts
Normal file
52
src/tools/squads/reject_proposal.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
import * as multisig from "@sqds/multisig";
|
||||
const { Multisig } = multisig.accounts;
|
||||
|
||||
/**
|
||||
* Rejects a proposal in a Solana multisig setup.
|
||||
*
|
||||
* @param agent - The SolanaAgentKit instance containing the wallet and connection.
|
||||
* @param transactionIndex - Optional. The index of the transaction to reject. If not provided, the current transaction index will be used.
|
||||
* @returns A promise that resolves to the transaction ID of the rejection transaction.
|
||||
* @throws Will throw an error if the transaction fails.
|
||||
*/
|
||||
export async function multisig_reject_proposal(
|
||||
agent: SolanaAgentKit,
|
||||
transactionIndex?: number | bigint,
|
||||
): Promise<string> {
|
||||
try {
|
||||
const createKey = agent.wallet;
|
||||
const [multisigPda] = multisig.getMultisigPda({
|
||||
createKey: createKey.publicKey,
|
||||
});
|
||||
const multisigInfo = await Multisig.fromAccountAddress(
|
||||
agent.connection,
|
||||
multisigPda,
|
||||
);
|
||||
const currentTransactionIndex = Number(multisigInfo.transactionIndex);
|
||||
if (!transactionIndex) {
|
||||
transactionIndex = BigInt(currentTransactionIndex);
|
||||
} else if (typeof transactionIndex !== "bigint") {
|
||||
transactionIndex = BigInt(transactionIndex);
|
||||
}
|
||||
// const [proposalPda, proposalBump] = multisig.getProposalPda({
|
||||
// multisigPda,
|
||||
// transactionIndex,
|
||||
// });
|
||||
const multisigTx = multisig.transactions.proposalReject({
|
||||
blockhash: (await agent.connection.getLatestBlockhash()).blockhash,
|
||||
feePayer: agent.wallet.publicKey,
|
||||
multisigPda,
|
||||
transactionIndex: transactionIndex,
|
||||
member: agent.wallet.publicKey,
|
||||
});
|
||||
|
||||
multisigTx.sign([agent.wallet]);
|
||||
const tx = await agent.connection.sendRawTransaction(
|
||||
multisigTx.serialize(),
|
||||
);
|
||||
return tx;
|
||||
} catch (error: any) {
|
||||
throw new Error(`Transfer failed: ${error}`);
|
||||
}
|
||||
}
|
||||
98
src/tools/squads/transfer_from_treasury.ts
Normal file
98
src/tools/squads/transfer_from_treasury.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
import {
|
||||
PublicKey,
|
||||
SystemProgram,
|
||||
TransactionInstruction,
|
||||
TransactionMessage,
|
||||
} from "@solana/web3.js";
|
||||
import { LAMPORTS_PER_SOL } from "@solana/web3.js";
|
||||
import {
|
||||
getAssociatedTokenAddress,
|
||||
createTransferInstruction,
|
||||
getMint,
|
||||
} from "@solana/spl-token";
|
||||
import * as multisig from "@sqds/multisig";
|
||||
const { Multisig } = multisig.accounts;
|
||||
|
||||
/**
|
||||
* Transfer SOL or SPL tokens to a recipient from a multisig vault.
|
||||
* @param agent - SolanaAgentKit instance.
|
||||
* @param amount - Amount to transfer.
|
||||
* @param to - Recipient's public key.
|
||||
* @param vaultIndex - Optional vault index, default is 0.
|
||||
* @param mint - Optional mint address for SPL tokens.
|
||||
* @returns Transaction signature.
|
||||
*/
|
||||
export async function multisig_transfer_from_treasury(
|
||||
agent: SolanaAgentKit,
|
||||
amount: number,
|
||||
to: PublicKey,
|
||||
vaultIndex: number = 0,
|
||||
mint?: PublicKey,
|
||||
): Promise<string> {
|
||||
try {
|
||||
let transferInstruction: TransactionInstruction;
|
||||
|
||||
const createKey = agent.wallet;
|
||||
const [multisigPda] = multisig.getMultisigPda({
|
||||
createKey: createKey.publicKey,
|
||||
});
|
||||
const multisigInfo = await Multisig.fromAccountAddress(
|
||||
agent.connection,
|
||||
multisigPda,
|
||||
);
|
||||
const currentTransactionIndex = Number(multisigInfo.transactionIndex);
|
||||
const transactionIndex = BigInt(currentTransactionIndex + 1);
|
||||
const [vaultPda] = multisig.getVaultPda({
|
||||
multisigPda,
|
||||
index: vaultIndex,
|
||||
});
|
||||
|
||||
if (!mint) {
|
||||
// Transfer native SOL
|
||||
transferInstruction = SystemProgram.transfer({
|
||||
fromPubkey: agent.wallet_address,
|
||||
toPubkey: to,
|
||||
lamports: amount * LAMPORTS_PER_SOL,
|
||||
});
|
||||
} else {
|
||||
// Transfer SPL token
|
||||
const fromAta = await getAssociatedTokenAddress(mint, vaultPda, true);
|
||||
const toAta = await getAssociatedTokenAddress(mint, to, true);
|
||||
const mintInfo = await getMint(agent.connection, mint);
|
||||
const adjustedAmount = amount * Math.pow(10, mintInfo.decimals);
|
||||
|
||||
transferInstruction = createTransferInstruction(
|
||||
fromAta,
|
||||
toAta,
|
||||
agent.wallet_address,
|
||||
adjustedAmount,
|
||||
);
|
||||
}
|
||||
|
||||
const transferMessage = new TransactionMessage({
|
||||
payerKey: vaultPda,
|
||||
recentBlockhash: (await agent.connection.getLatestBlockhash()).blockhash,
|
||||
instructions: [transferInstruction],
|
||||
});
|
||||
|
||||
const multisigTx = multisig.transactions.vaultTransactionCreate({
|
||||
blockhash: (await agent.connection.getLatestBlockhash()).blockhash,
|
||||
feePayer: agent.wallet_address,
|
||||
multisigPda,
|
||||
transactionIndex,
|
||||
creator: agent.wallet_address,
|
||||
vaultIndex: 0,
|
||||
ephemeralSigners: 0,
|
||||
transactionMessage: transferMessage,
|
||||
});
|
||||
|
||||
multisigTx.sign([agent.wallet]);
|
||||
const tx = await agent.connection.sendRawTransaction(
|
||||
multisigTx.serialize(),
|
||||
);
|
||||
return tx;
|
||||
} catch (error: any) {
|
||||
throw new Error(`Transfer failed: ${error}`);
|
||||
}
|
||||
}
|
||||
1
src/tools/tensor/index.ts
Normal file
1
src/tools/tensor/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./tensor_trade";
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
import { TensorSwapSDK } from "@tensor-oss/tensorswap-sdk";
|
||||
import { PublicKey, Transaction } from "@solana/web3.js";
|
||||
import { AnchorProvider, Wallet } from "@coral-xyz/anchor";
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
getMint,
|
||||
createAssociatedTokenAccountInstruction,
|
||||
} from "@solana/spl-token";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
|
||||
const MINIMUM_SOL_BALANCE = 0.003 * LAMPORTS_PER_SOL;
|
||||
|
||||
1
src/tools/tiplink/index.ts
Normal file
1
src/tools/tiplink/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./create_tiplinks";
|
||||
Reference in New Issue
Block a user