mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-27 15:11:14 +00:00
feat: fix readme issues, and add types
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Connection, Keypair, PublicKey } from "@solana/web3.js";;
|
||||
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
|
||||
import bs58 from "bs58";
|
||||
import Decimal from "decimal.js";
|
||||
import { DEFAULT_OPTIONS } from "../constants";
|
||||
@@ -25,9 +25,16 @@ import {
|
||||
stakeWithJup,
|
||||
sendCompressedAirdrop,
|
||||
createOrcaSingleSidedWhirlpool,
|
||||
FEE_TIERS
|
||||
FEE_TIERS,
|
||||
} from "../tools";
|
||||
import { CollectionOptions, PumpFunTokenOptions } from "../types";
|
||||
import {
|
||||
CollectionDeployment,
|
||||
CollectionOptions,
|
||||
JupiterTokenData,
|
||||
MintCollectionNFTResponse,
|
||||
PumpfunLaunchResponse,
|
||||
PumpFunTokenOptions,
|
||||
} from "../types";
|
||||
import { BN } from "@coral-xyz/anchor";
|
||||
|
||||
/**
|
||||
@@ -48,7 +55,7 @@ export class SolanaAgentKit {
|
||||
constructor(
|
||||
private_key: string,
|
||||
rpc_url = "https://api.mainnet-beta.solana.com",
|
||||
openai_api_key: string
|
||||
openai_api_key: string,
|
||||
) {
|
||||
this.connection = new Connection(rpc_url);
|
||||
this.wallet = Keypair.fromSecretKey(bs58.decode(private_key));
|
||||
@@ -66,40 +73,46 @@ export class SolanaAgentKit {
|
||||
uri: string,
|
||||
symbol: string,
|
||||
decimals: number = DEFAULT_OPTIONS.TOKEN_DECIMALS,
|
||||
initialSupply?: number
|
||||
) {
|
||||
initialSupply?: number,
|
||||
): Promise<{ mint: PublicKey }> {
|
||||
return deploy_token(this, name, uri, symbol, decimals, initialSupply);
|
||||
}
|
||||
|
||||
async deployCollection(options: CollectionOptions) {
|
||||
async deployCollection(
|
||||
options: CollectionOptions,
|
||||
): Promise<CollectionDeployment> {
|
||||
return deploy_collection(this, options);
|
||||
}
|
||||
|
||||
async getBalance(token_address?: PublicKey) {
|
||||
async getBalance(token_address?: PublicKey): Promise<number | null> {
|
||||
return get_balance(this, token_address);
|
||||
}
|
||||
|
||||
async mintNFT(
|
||||
collectionMint: PublicKey,
|
||||
metadata: Parameters<typeof mintCollectionNFT>[2],
|
||||
recipient?: PublicKey
|
||||
) {
|
||||
recipient?: PublicKey,
|
||||
): Promise<MintCollectionNFTResponse> {
|
||||
return mintCollectionNFT(this, collectionMint, metadata, recipient);
|
||||
}
|
||||
|
||||
async transfer(to: PublicKey, amount: number, mint?: PublicKey) {
|
||||
async transfer(
|
||||
to: PublicKey,
|
||||
amount: number,
|
||||
mint?: PublicKey,
|
||||
): Promise<string> {
|
||||
return transfer(this, to, amount, mint);
|
||||
}
|
||||
|
||||
async registerDomain(name: string, spaceKB?: number) {
|
||||
async registerDomain(name: string, spaceKB?: number): Promise<string> {
|
||||
return registerDomain(this, name, spaceKB);
|
||||
}
|
||||
|
||||
async resolveSolDomain(domain: string) {
|
||||
async resolveSolDomain(domain: string): Promise<PublicKey> {
|
||||
return resolveSolDomain(this, domain);
|
||||
}
|
||||
|
||||
async getPrimaryDomain(account: PublicKey) {
|
||||
async getPrimaryDomain(account: PublicKey): Promise<string> {
|
||||
return getPrimaryDomain(this, account);
|
||||
}
|
||||
|
||||
@@ -107,24 +120,28 @@ export class SolanaAgentKit {
|
||||
outputMint: PublicKey,
|
||||
inputAmount: number,
|
||||
inputMint?: PublicKey,
|
||||
slippageBps: number = DEFAULT_OPTIONS.SLIPPAGE_BPS
|
||||
) {
|
||||
slippageBps: number = DEFAULT_OPTIONS.SLIPPAGE_BPS,
|
||||
): Promise<string> {
|
||||
return trade(this, outputMint, inputAmount, inputMint, slippageBps);
|
||||
}
|
||||
|
||||
async lendAssets(amount: number) {
|
||||
async lendAssets(amount: number): Promise<string> {
|
||||
return lendAsset(this, amount);
|
||||
}
|
||||
|
||||
async getTPS() {
|
||||
async getTPS(): Promise<number> {
|
||||
return getTPS(this);
|
||||
}
|
||||
|
||||
async getTokenDataByAddress(mint: string) {
|
||||
async getTokenDataByAddress(
|
||||
mint: string,
|
||||
): Promise<JupiterTokenData | undefined> {
|
||||
return getTokenDataByAddress(new PublicKey(mint));
|
||||
}
|
||||
|
||||
async getTokenDataByTicker(ticker: string) {
|
||||
async getTokenDataByTicker(
|
||||
ticker: string,
|
||||
): Promise<JupiterTokenData | undefined> {
|
||||
return getTokenDataByTicker(ticker);
|
||||
}
|
||||
|
||||
@@ -133,19 +150,19 @@ export class SolanaAgentKit {
|
||||
tokenTicker: string,
|
||||
description: string,
|
||||
imageUrl: string,
|
||||
options?: PumpFunTokenOptions
|
||||
) {
|
||||
options?: PumpFunTokenOptions,
|
||||
): Promise<PumpfunLaunchResponse> {
|
||||
return launchPumpFunToken(
|
||||
this,
|
||||
tokenName,
|
||||
tokenTicker,
|
||||
description,
|
||||
imageUrl,
|
||||
options
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
async stake(amount: number) {
|
||||
async stake(amount: number): Promise<string> {
|
||||
return stakeWithJup(this, amount);
|
||||
}
|
||||
|
||||
@@ -155,7 +172,7 @@ export class SolanaAgentKit {
|
||||
decimals: number,
|
||||
recipients: string[],
|
||||
priorityFeeInLamports: number,
|
||||
shouldLog: boolean
|
||||
shouldLog: boolean,
|
||||
): Promise<string[]> {
|
||||
return await sendCompressedAirdrop(
|
||||
this,
|
||||
@@ -164,7 +181,7 @@ export class SolanaAgentKit {
|
||||
decimals,
|
||||
recipients.map((recipient) => new PublicKey(recipient)),
|
||||
priorityFeeInLamports,
|
||||
shouldLog
|
||||
shouldLog,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -175,7 +192,7 @@ export class SolanaAgentKit {
|
||||
initialPrice: Decimal,
|
||||
maxPrice: Decimal,
|
||||
feeTier: keyof typeof FEE_TIERS,
|
||||
) {
|
||||
): Promise<string> {
|
||||
return createOrcaSingleSidedWhirlpool(
|
||||
this,
|
||||
depositTokenAmount,
|
||||
@@ -183,18 +200,16 @@ export class SolanaAgentKit {
|
||||
otherTokenMint,
|
||||
initialPrice,
|
||||
maxPrice,
|
||||
feeTier
|
||||
)
|
||||
feeTier,
|
||||
);
|
||||
}
|
||||
|
||||
async raydiumCreateAmmV4(
|
||||
marketId: PublicKey,
|
||||
|
||||
baseAmount: BN,
|
||||
quoteAmount: BN,
|
||||
|
||||
startTime: BN,
|
||||
) {
|
||||
): Promise<string> {
|
||||
return raydiumCreateAmmV4(
|
||||
this,
|
||||
marketId,
|
||||
@@ -203,64 +218,51 @@ export class SolanaAgentKit {
|
||||
quoteAmount,
|
||||
|
||||
startTime,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
async raydiumCreateClmm(
|
||||
mint1: PublicKey,
|
||||
mint2: PublicKey,
|
||||
|
||||
configId: PublicKey,
|
||||
|
||||
initialPrice: Decimal,
|
||||
startTime: BN,
|
||||
) {
|
||||
): Promise<string> {
|
||||
return raydiumCreateClmm(
|
||||
this,
|
||||
|
||||
mint1,
|
||||
mint2,
|
||||
|
||||
configId,
|
||||
|
||||
initialPrice,
|
||||
startTime,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
async raydiumCreateCpmm(
|
||||
mint1: PublicKey,
|
||||
mint2: PublicKey,
|
||||
|
||||
configId: PublicKey,
|
||||
|
||||
mintAAmount: BN,
|
||||
mintBAmount: BN,
|
||||
|
||||
startTime: BN,
|
||||
) {
|
||||
): Promise<string> {
|
||||
return raydiumCreateCpmm(
|
||||
this,
|
||||
|
||||
mint1,
|
||||
mint2,
|
||||
|
||||
configId,
|
||||
|
||||
mintAAmount,
|
||||
mintBAmount,
|
||||
|
||||
startTime,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
async openbookCreateMarket(
|
||||
baseMint: PublicKey,
|
||||
quoteMint: PublicKey,
|
||||
|
||||
lotSize: number = 1,
|
||||
tickSize: number = 0.01,
|
||||
) {
|
||||
): Promise<string[]> {
|
||||
return openbookCreateMarket(
|
||||
this,
|
||||
baseMint,
|
||||
@@ -268,6 +270,6 @@ export class SolanaAgentKit {
|
||||
|
||||
lotSize,
|
||||
tickSize,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user