mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-06-03 23:26:50 +00:00
feat: langchain tool
This commit is contained in:
2514
pnpm-lock.yaml
generated
2514
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -49,13 +49,13 @@ export class SolanaAgentKit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async deployToken(
|
async deployToken(
|
||||||
decimals: number = DEFAULT_OPTIONS.TOKEN_DECIMALS,
|
|
||||||
name: string,
|
name: string,
|
||||||
uri: string,
|
uri: string,
|
||||||
symbol: string,
|
symbol: string,
|
||||||
|
decimals: number = DEFAULT_OPTIONS.TOKEN_DECIMALS,
|
||||||
initialSupply?: number,
|
initialSupply?: number,
|
||||||
) {
|
) {
|
||||||
return deploy_token(this, decimals, name, uri, symbol, initialSupply);
|
return deploy_token(this, name, uri, symbol, decimals, initialSupply);
|
||||||
}
|
}
|
||||||
|
|
||||||
async deployCollection(options: CollectionOptions) {
|
async deployCollection(options: CollectionOptions) {
|
||||||
|
|||||||
@@ -87,38 +87,32 @@ export class SolanaTransferTool extends Tool {
|
|||||||
|
|
||||||
export class SolanaDeployTokenTool extends Tool {
|
export class SolanaDeployTokenTool extends Tool {
|
||||||
name = "solana_deploy_token";
|
name = "solana_deploy_token";
|
||||||
description =
|
description = `Deploy a new token on Solana blockchain.
|
||||||
"Deploy a new SPL token. Input should be JSON string with: {decimals?: number, initialSupply?: number}";
|
|
||||||
|
Inputs (input is a JSON string):
|
||||||
|
name: string, eg "My Token" (required)
|
||||||
|
uri: string, eg "https://example.com/token.json" (required)
|
||||||
|
symbol: string, eg "MTK" (required)
|
||||||
|
decimals?: number, eg 9 (optional, defaults to 9)
|
||||||
|
initialSupply?: number, eg 1000000 (optional)`;
|
||||||
|
|
||||||
constructor(private solanaKit: SolanaAgentKit) {
|
constructor(private solanaKit: SolanaAgentKit) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
private validateInput(input: any): void {
|
|
||||||
if (
|
|
||||||
input.decimals !== undefined &&
|
|
||||||
(typeof input.decimals !== "number" ||
|
|
||||||
input.decimals < 0 ||
|
|
||||||
input.decimals > 9)
|
|
||||||
) {
|
|
||||||
throw new Error(
|
|
||||||
"decimals must be a number between 0 and 9 when provided"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
input.initialSupply !== undefined &&
|
|
||||||
(typeof input.initialSupply !== "number" || input.initialSupply <= 0)
|
|
||||||
) {
|
|
||||||
throw new Error("initialSupply must be a positive number when provided");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async _call(input: string): Promise<string> {
|
protected async _call(input: string): Promise<string> {
|
||||||
try {
|
try {
|
||||||
const parsedInput = toJSON(input);
|
const parsedInput = JSON.parse(input);
|
||||||
this.validateInput(parsedInput);
|
|
||||||
|
|
||||||
const result = await this.solanaKit.deployToken(parsedInput.decimals);
|
console.log(parsedInput);
|
||||||
|
|
||||||
|
const result = await this.solanaKit.deployToken(
|
||||||
|
parsedInput.name,
|
||||||
|
parsedInput.uri,
|
||||||
|
parsedInput.symbol,
|
||||||
|
parsedInput.decimals,
|
||||||
|
parsedInput.initialSupply
|
||||||
|
);
|
||||||
|
|
||||||
return JSON.stringify({
|
return JSON.stringify({
|
||||||
status: "success",
|
status: "success",
|
||||||
|
|||||||
@@ -1,10 +1,22 @@
|
|||||||
import { SolanaAgentKit } from "../index";
|
import { SolanaAgentKit } from "../index";
|
||||||
import { PublicKey } from "@solana/web3.js";
|
import { PublicKey } from "@solana/web3.js";
|
||||||
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
|
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
|
||||||
import { generateSigner } from "@metaplex-foundation/umi";
|
import {
|
||||||
import { createFungible, mintV1, TokenStandard } from "@metaplex-foundation/mpl-token-metadata";
|
generateSigner,
|
||||||
import { fromWeb3JsPublicKey, toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
keypairIdentity,
|
||||||
|
signerIdentity,
|
||||||
|
} from "@metaplex-foundation/umi";
|
||||||
|
import {
|
||||||
|
createFungible,
|
||||||
|
mintV1,
|
||||||
|
TokenStandard,
|
||||||
|
} from "@metaplex-foundation/mpl-token-metadata";
|
||||||
|
import {
|
||||||
|
fromWeb3JsKeypair,
|
||||||
|
fromWeb3JsPublicKey,
|
||||||
|
toWeb3JsPublicKey,
|
||||||
|
} from "@metaplex-foundation/umi-web3js-adapters";
|
||||||
|
import bs58 from "bs58";
|
||||||
/**
|
/**
|
||||||
* Deploy a new SPL token
|
* Deploy a new SPL token
|
||||||
* @param agent SolanaAgentKit instance
|
* @param agent SolanaAgentKit instance
|
||||||
@@ -17,29 +29,28 @@ import { fromWeb3JsPublicKey, toWeb3JsPublicKey } from "@metaplex-foundation/umi
|
|||||||
*/
|
*/
|
||||||
export async function deploy_token(
|
export async function deploy_token(
|
||||||
agent: SolanaAgentKit,
|
agent: SolanaAgentKit,
|
||||||
decimals: number = 9,
|
|
||||||
name: string,
|
name: string,
|
||||||
uri: string,
|
uri: string,
|
||||||
symbol: string,
|
symbol: string,
|
||||||
initialSupply?: number,
|
decimals: number = 9,
|
||||||
|
initialSupply?: number
|
||||||
): Promise<{ mint: PublicKey }> {
|
): Promise<{ mint: PublicKey }> {
|
||||||
try {
|
try {
|
||||||
// Create UMI instance from agent
|
// Create UMI instance from agent
|
||||||
const umi = createUmi(agent.connection.rpcEndpoint)
|
const umi = createUmi(agent.connection.rpcEndpoint).use(
|
||||||
|
keypairIdentity(fromWeb3JsKeypair(agent.wallet))
|
||||||
|
);
|
||||||
|
|
||||||
// Create new token mint
|
// Create new token mint
|
||||||
const mint = generateSigner(umi);
|
const mint = generateSigner(umi);
|
||||||
|
|
||||||
console.log("Mint address: ", mint.publicKey.toString());
|
|
||||||
console.log("Agent address: ", agent.wallet_address.toString());
|
|
||||||
|
|
||||||
let builder = createFungible(umi, {
|
let builder = createFungible(umi, {
|
||||||
name,
|
name,
|
||||||
uri,
|
uri,
|
||||||
symbol,
|
symbol,
|
||||||
sellerFeeBasisPoints: {
|
sellerFeeBasisPoints: {
|
||||||
basisPoints: 0n,
|
basisPoints: 0n,
|
||||||
identifier: '%',
|
identifier: "%",
|
||||||
decimals: 2,
|
decimals: 2,
|
||||||
},
|
},
|
||||||
decimals,
|
decimals,
|
||||||
@@ -47,12 +58,14 @@ export async function deploy_token(
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (initialSupply) {
|
if (initialSupply) {
|
||||||
builder = builder.add(mintV1(umi, {
|
builder = builder.add(
|
||||||
mint: mint.publicKey,
|
mintV1(umi, {
|
||||||
tokenStandard: TokenStandard.Fungible,
|
mint: mint.publicKey,
|
||||||
tokenOwner: fromWeb3JsPublicKey(agent.wallet_address),
|
tokenStandard: TokenStandard.Fungible,
|
||||||
amount: initialSupply,
|
tokenOwner: fromWeb3JsPublicKey(agent.wallet_address),
|
||||||
}));
|
amount: initialSupply,
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.sendAndConfirm(umi);
|
builder.sendAndConfirm(umi);
|
||||||
|
|||||||
Reference in New Issue
Block a user