mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-13 23:16:55 +00:00
refactor create single and added create collection tool
This commit is contained in:
@@ -8,7 +8,12 @@ import {
|
||||
PythFetchPriceResponse,
|
||||
SolanaAgentKit,
|
||||
} from "../index";
|
||||
import { create_image, FEE_TIERS, generateOrdersfromPattern } from "../tools";
|
||||
import { create_image, FEE_TIERS } from "../tools";
|
||||
import {
|
||||
CreateCollectionOptions,
|
||||
CreateSingleOptions,
|
||||
StoreInitOptions,
|
||||
} from "@3land/listings-sdk/dist/types/implementation/implementationTypes";
|
||||
|
||||
export class SolanaBalanceTool extends Tool {
|
||||
name = "solana_balance";
|
||||
@@ -2255,9 +2260,17 @@ export class Solana3LandCreateSingle extends Tool {
|
||||
description = `Creates an NFT and lists it on 3.land's website
|
||||
|
||||
Inputs:
|
||||
optionsWithBase58 (required): represents the privateKey of the wallet - can be an array of numbers, Uint8Array or base58 string
|
||||
privateKey (required): represents the privateKey of the wallet - can be an array of numbers, Uint8Array or base58 string
|
||||
collectionAccount (optional): represents the account for the nft collection
|
||||
createItemOptions (required): the options for the creation of the single NFT listing
|
||||
itemName (required): the name of the NFT
|
||||
sellerFee (required): the fee of the seller
|
||||
itemAmount (required): the amount of the NFTs that can be minted
|
||||
itemDescription (required): the description of the NFT
|
||||
traits (required): the traits of the NFT [{trait_type: string, value: string}]
|
||||
price (required): the price of the item, if is 0 the listing will be free
|
||||
mainImageUrl (required): the main image of the NFT
|
||||
coverImageUrl (optional): the cover image of the NFT
|
||||
splHash (optional): the hash of the spl token, if not provided listing will be in $SOL
|
||||
isMainnet (required): defines is the tx takes places in mainnet
|
||||
`;
|
||||
|
||||
@@ -2268,22 +2281,43 @@ export class Solana3LandCreateSingle extends Tool {
|
||||
protected async _call(input: string): Promise<string> {
|
||||
try {
|
||||
const inputFormat = JSON.parse(input);
|
||||
const optionsWithBase58 = inputFormat.optionsWithBase58;
|
||||
let collectionAccount = inputFormat.collectionAccount;
|
||||
const createItemOptions = inputFormat.createItemOptions;
|
||||
const privateKey = inputFormat.privateKey;
|
||||
const isMainnet = inputFormat.isMainnet;
|
||||
|
||||
if (!collectionAccount) {
|
||||
collectionAccount = "Fpm8XgXEuNxxjmqUQuqEFkGusiSsKM6astUGPs5U9x6v";
|
||||
}
|
||||
const optionsWithBase58: StoreInitOptions = {
|
||||
...(privateKey && { privateKey }),
|
||||
...(isMainnet && { isMainnet }),
|
||||
};
|
||||
|
||||
console.log(
|
||||
"options inside 3land func: ",
|
||||
optionsWithBase58,
|
||||
collectionAccount,
|
||||
createItemOptions,
|
||||
isMainnet,
|
||||
);
|
||||
let collectionAccount = inputFormat.collectionAccount;
|
||||
|
||||
const itemName = inputFormat?.itemName;
|
||||
const sellerFee = inputFormat?.sellerFee;
|
||||
const itemAmount = inputFormat?.itemAmount;
|
||||
const itemSymbol = inputFormat?.itemSymbol;
|
||||
const itemDescription = inputFormat?.itemDescription;
|
||||
const traits = inputFormat?.traits;
|
||||
const price = inputFormat?.price;
|
||||
const mainImageUrl = inputFormat?.mainImageUrl;
|
||||
const coverImageUrl = inputFormat?.coverImageUrl;
|
||||
const splHash = inputFormat?.splHash;
|
||||
|
||||
const createItemOptions: CreateSingleOptions = {
|
||||
...(itemName && { itemName }),
|
||||
...(sellerFee && { sellerFee }),
|
||||
...(itemAmount && { itemAmount }),
|
||||
...(itemSymbol && { itemSymbol }),
|
||||
...(itemDescription && { itemDescription }),
|
||||
...(traits && { traits }),
|
||||
...(price && { price }),
|
||||
...(mainImageUrl && { mainImageUrl }),
|
||||
...(coverImageUrl && { coverImageUrl }),
|
||||
...(splHash && { splHash }),
|
||||
};
|
||||
|
||||
if (!collectionAccount) {
|
||||
throw new Error("Collection account is required");
|
||||
}
|
||||
|
||||
const tx = await this.solanaKit.create3LandNft(
|
||||
optionsWithBase58,
|
||||
@@ -2306,6 +2340,68 @@ export class Solana3LandCreateSingle extends Tool {
|
||||
}
|
||||
}
|
||||
|
||||
export class Solana3LandCreateCollection extends Tool {
|
||||
name = "3land_minting_tool";
|
||||
description = `Creates an NFT Collection that you can visit on 3.land's website (3.land/collection/{collectionAccount})
|
||||
|
||||
Inputs:
|
||||
privateKey (required): represents the privateKey of the wallet - can be an array of numbers, Uint8Array or base58 string
|
||||
isMainnet (required): defines is the tx takes places in mainnet
|
||||
collectionSymbol (required): the symbol of the collection
|
||||
collectionName (required): the name of the collection
|
||||
collectionDescription (required): the description of the collection
|
||||
mainImageUrl (required): the image of the collection
|
||||
coverImageUrl (optional): the cover image of the collection
|
||||
`;
|
||||
|
||||
constructor(private solanaKit: SolanaAgentKit) {
|
||||
super();
|
||||
}
|
||||
|
||||
protected async _call(input: string): Promise<string> {
|
||||
try {
|
||||
const inputFormat = JSON.parse(input);
|
||||
const privateKey = inputFormat.privateKey;
|
||||
const isMainnet = inputFormat.isMainnet;
|
||||
|
||||
const optionsWithBase58: StoreInitOptions = {
|
||||
...(privateKey && { privateKey }),
|
||||
...(isMainnet && { isMainnet }),
|
||||
};
|
||||
|
||||
const collectionSymbol = inputFormat?.collectionSymbol;
|
||||
const collectionName = inputFormat?.collectionName;
|
||||
const collectionDescription = inputFormat?.collectionDescription;
|
||||
const mainImageUrl = inputFormat?.mainImageUrl;
|
||||
const coverImageUrl = inputFormat?.coverImageUrl;
|
||||
|
||||
const collectionOpts: CreateCollectionOptions = {
|
||||
...(collectionSymbol && { collectionSymbol }),
|
||||
...(collectionName && { collectionName }),
|
||||
...(collectionDescription && { collectionDescription }),
|
||||
...(mainImageUrl && { mainImageUrl }),
|
||||
...(coverImageUrl && { coverImageUrl }),
|
||||
};
|
||||
|
||||
const tx = await this.solanaKit.create3LandCollection(
|
||||
optionsWithBase58,
|
||||
collectionOpts,
|
||||
);
|
||||
return JSON.stringify({
|
||||
status: "success",
|
||||
message: `Created Collection successfully ${tx}`,
|
||||
transaction: tx,
|
||||
});
|
||||
} catch (error: any) {
|
||||
return JSON.stringify({
|
||||
status: "error",
|
||||
message: error.message,
|
||||
code: error.code || "UNKNOWN_ERROR",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function createSolanaTools(solanaKit: SolanaAgentKit) {
|
||||
return [
|
||||
new SolanaBalanceTool(solanaKit),
|
||||
@@ -2358,6 +2454,8 @@ export function createSolanaTools(solanaKit: SolanaAgentKit) {
|
||||
new SolanaCancelNFTListingTool(solanaKit),
|
||||
new SolanaFetchTokenReportSummaryTool(solanaKit),
|
||||
new SolanaFetchTokenDetailedReportTool(solanaKit),
|
||||
new Solana3LandCreateSingle(solanaKit),
|
||||
new Solana3LandCreateCollection(solanaKit),
|
||||
new SolanaPerpOpenTradeTool(solanaKit),
|
||||
new SolanaPerpCloseTradeTool(solanaKit),
|
||||
new SolanaFlashOpenTrade(solanaKit),
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"skipLibCheck": true,
|
||||
"resolveJsonModule": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist", "**/*.test.ts"]
|
||||
|
||||
Reference in New Issue
Block a user