mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-14 07:26:46 +00:00
Implement getAssetsByCreator tool
This commit is contained in:
@@ -60,7 +60,8 @@ import driftUserAccountInfoAction from "./drift/driftUserAccountInfo";
|
||||
import deriveDriftVaultAddressAction from "./drift/deriveVaultAddress";
|
||||
import updateDriftVaultDelegateAction from "./drift/updateDriftVaultDelegate";
|
||||
import getAssetAction from "./metaplex/getAsset";
|
||||
import getAssetByAuthorityAction from "./metaplex/getAssetByAuthority";
|
||||
import getAssetsByAuthorityAction from "./metaplex/getAssetsByAuthority";
|
||||
import getAssetsByCreatorAction from "./metaplex/getAssetsByCreator";
|
||||
|
||||
export const ACTIONS = {
|
||||
WALLET_ADDRESS_ACTION: getWalletAddressAction,
|
||||
@@ -126,7 +127,8 @@ export const ACTIONS = {
|
||||
DERIVE_DRIFT_VAULT_ADDRESS_ACTION: deriveDriftVaultAddressAction,
|
||||
UPDATE_DRIFT_VAULT_DELEGATE_ACTION: updateDriftVaultDelegateAction,
|
||||
GET_ASSET_ACTION: getAssetAction,
|
||||
GET_ASSET_BY_AUTHORITY_ACTION: getAssetByAuthorityAction,
|
||||
GET_ASSETS_BY_AUTHORITY_ACTION: getAssetsByAuthorityAction,
|
||||
GET_ASSETS_BY_CREATOR_ACTION: getAssetsByCreatorAction,
|
||||
};
|
||||
|
||||
export type { Action, ActionExample, Handler } from "../types/action";
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
import { Action } from "../../types/action";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { z } from "zod";
|
||||
import { get_assets_by_authority } from "../../tools/metaplex";
|
||||
|
||||
const getAssetByAuthorityAction: Action = {
|
||||
name: "GET_ASSET_BY_AUTHORITY",
|
||||
similes: [
|
||||
"fetch assets by authority",
|
||||
"retrieve assets by authority",
|
||||
"get assets by authority address",
|
||||
"fetch authority assets",
|
||||
],
|
||||
description: `Fetch a list of assets owned by a specific address using the Metaplex DAS API.`,
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
authorityAddress: "mRdta4rc2RtsxEUDYuvKLamMZAdW6qHcwuq866Skxxv",
|
||||
limit: 10,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
message: "Assets retrieved successfully",
|
||||
result: [
|
||||
// Example asset details
|
||||
{
|
||||
name: "Example Asset 1",
|
||||
symbol: "EXA1",
|
||||
uri: "https://example.com/asset1.json",
|
||||
},
|
||||
{
|
||||
name: "Example Asset 2",
|
||||
symbol: "EXA2",
|
||||
uri: "https://example.com/asset2.json",
|
||||
},
|
||||
],
|
||||
},
|
||||
explanation: "Fetch a list of assets owned by a specific address",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
authorityAddress: z.string().min(1, "Authority address is required"),
|
||||
sortBy: z
|
||||
.object({
|
||||
sortBy: z.enum(["created", "updated", "recentAction", "none"]),
|
||||
sortDirection: z.enum(["asc", "desc"]),
|
||||
})
|
||||
.optional(),
|
||||
limit: z.number().optional(),
|
||||
page: z.number().optional(),
|
||||
before: z.string().optional(),
|
||||
after: z.string().optional(),
|
||||
}),
|
||||
handler: async (
|
||||
agent: SolanaAgentKit,
|
||||
input: z.infer<typeof getAssetByAuthorityAction.schema>,
|
||||
) => {
|
||||
const result = await get_assets_by_authority(agent, input);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
message: "Assets retrieved successfully",
|
||||
result,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export default getAssetByAuthorityAction;
|
||||
103
src/actions/metaplex/getAssetsByAuthority.ts
Normal file
103
src/actions/metaplex/getAssetsByAuthority.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
import { Action } from "../../types/action";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { z } from "zod";
|
||||
import { get_assets_by_authority } from "../../tools/metaplex";
|
||||
|
||||
const getAssetsByAuthorityAction: Action = {
|
||||
name: "GET_ASSETS_BY_AUTHORITY",
|
||||
similes: [
|
||||
"fetch assets by authority",
|
||||
"retrieve assets by authority",
|
||||
"get assets by authority address",
|
||||
"fetch authority assets",
|
||||
],
|
||||
description: `Fetch a list of assets owned by a specific address using the Metaplex DAS API.`,
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
authorityAddress: "mRdta4rc2RtsxEUDYuvKLamMZAdW6qHcwuq866Skxxv",
|
||||
limit: 10,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
message: "Assets retrieved successfully",
|
||||
result: {
|
||||
total: 2,
|
||||
limit: 10,
|
||||
items: [
|
||||
{
|
||||
interface: "V1_NFT",
|
||||
id: "ExampleAssetId1",
|
||||
content: {
|
||||
json_uri: "https://example.com/asset1.json",
|
||||
metadata: {
|
||||
name: "Example Asset 1",
|
||||
symbol: "EXA1",
|
||||
},
|
||||
},
|
||||
authorities: [],
|
||||
compression: {},
|
||||
grouping: [],
|
||||
royalty: {},
|
||||
creators: [],
|
||||
ownership: {},
|
||||
supply: {},
|
||||
mutable: true,
|
||||
burnt: false,
|
||||
},
|
||||
{
|
||||
interface: "V1_NFT",
|
||||
id: "ExampleAssetId2",
|
||||
content: {
|
||||
json_uri: "https://example.com/asset2.json",
|
||||
metadata: {
|
||||
name: "Example Asset 2",
|
||||
symbol: "EXA2",
|
||||
},
|
||||
},
|
||||
authorities: [],
|
||||
compression: {},
|
||||
grouping: [],
|
||||
royalty: {},
|
||||
creators: [],
|
||||
ownership: {},
|
||||
supply: {},
|
||||
mutable: true,
|
||||
burnt: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
explanation: "Fetch a list of assets owned by a specific address",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
authorityAddress: z.string().min(1, "Authority address is required"),
|
||||
sortBy: z
|
||||
.object({
|
||||
sortBy: z.enum(["created", "updated", "recentAction", "none"]),
|
||||
sortDirection: z.enum(["asc", "desc"]),
|
||||
})
|
||||
.optional(),
|
||||
limit: z.number().optional(),
|
||||
page: z.number().optional(),
|
||||
before: z.string().optional(),
|
||||
after: z.string().optional(),
|
||||
}),
|
||||
handler: async (
|
||||
agent: SolanaAgentKit,
|
||||
input: z.infer<typeof getAssetsByAuthorityAction.schema>,
|
||||
) => {
|
||||
const result = await get_assets_by_authority(agent, input);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
message: "Assets retrieved successfully",
|
||||
result,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export default getAssetsByAuthorityAction;
|
||||
105
src/actions/metaplex/getAssetsByCreator.ts
Normal file
105
src/actions/metaplex/getAssetsByCreator.ts
Normal file
@@ -0,0 +1,105 @@
|
||||
import { Action } from "../../types/action";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { z } from "zod";
|
||||
import { get_assets_by_creator } from "../../tools/metaplex";
|
||||
|
||||
const getAssetsByCreatorAction: Action = {
|
||||
name: "GET_ASSETS_BY_CREATOR",
|
||||
similes: [
|
||||
"fetch assets by creator",
|
||||
"retrieve assets by creator",
|
||||
"get assets by creator address",
|
||||
"fetch creator assets",
|
||||
],
|
||||
description: `Fetch a list of assets created by a specific address using the Metaplex DAS API.`,
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
creatorAddress: "D3XrkNZz6wx6cofot7Zohsf2KSsu2ArngNk8VqU9cTY3",
|
||||
onlyVerified: true,
|
||||
limit: 10,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
message: "Assets retrieved successfully",
|
||||
result: {
|
||||
total: 2,
|
||||
limit: 10,
|
||||
items: [
|
||||
{
|
||||
interface: "V1_NFT",
|
||||
id: "ExampleAssetId1",
|
||||
content: {
|
||||
json_uri: "https://example.com/asset1.json",
|
||||
metadata: {
|
||||
name: "Example Asset 1",
|
||||
symbol: "EXA1",
|
||||
},
|
||||
},
|
||||
authorities: [],
|
||||
compression: {},
|
||||
grouping: [],
|
||||
royalty: {},
|
||||
creators: [],
|
||||
ownership: {},
|
||||
supply: {},
|
||||
mutable: true,
|
||||
burnt: false,
|
||||
},
|
||||
{
|
||||
interface: "V1_NFT",
|
||||
id: "ExampleAssetId2",
|
||||
content: {
|
||||
json_uri: "https://example.com/asset2.json",
|
||||
metadata: {
|
||||
name: "Example Asset 2",
|
||||
symbol: "EXA2",
|
||||
},
|
||||
},
|
||||
authorities: [],
|
||||
compression: {},
|
||||
grouping: [],
|
||||
royalty: {},
|
||||
creators: [],
|
||||
ownership: {},
|
||||
supply: {},
|
||||
mutable: true,
|
||||
burnt: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
explanation: "Fetch a list of assets created by a specific address",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
creatorAddress: z.string().min(1, "Creator address is required"),
|
||||
onlyVerified: z.boolean(),
|
||||
sortBy: z
|
||||
.object({
|
||||
sortBy: z.enum(["created", "updated", "recentAction", "none"]),
|
||||
sortDirection: z.enum(["asc", "desc"]),
|
||||
})
|
||||
.optional(),
|
||||
limit: z.number().optional(),
|
||||
page: z.number().optional(),
|
||||
before: z.string().optional(),
|
||||
after: z.string().optional(),
|
||||
}),
|
||||
handler: async (
|
||||
agent: SolanaAgentKit,
|
||||
input: z.infer<typeof getAssetsByCreatorAction.schema>,
|
||||
) => {
|
||||
const result = await get_assets_by_creator(agent, input);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
message: "Assets retrieved successfully",
|
||||
result,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export default getAssetsByCreatorAction;
|
||||
@@ -119,8 +119,11 @@ import {
|
||||
} from "../types";
|
||||
import {
|
||||
DasApiAsset,
|
||||
DasApiAssetList,
|
||||
GetAssetsByAuthorityRpcInput,
|
||||
GetAssetsByCreatorRpcInput,
|
||||
} from "@metaplex-foundation/digital-asset-standard-api";
|
||||
import { get_assets_by_creator } from "../tools/metaplex/get_assets_by_creator";
|
||||
|
||||
/**
|
||||
* Main class for interacting with Solana blockchain
|
||||
@@ -833,7 +836,12 @@ export class SolanaAgentKit {
|
||||
}
|
||||
async getAssetsByAuthority(
|
||||
params: GetAssetsByAuthorityRpcInput,
|
||||
): Promise<DasApiAsset[]> {
|
||||
): Promise<DasApiAssetList> {
|
||||
return get_assets_by_authority(this, params);
|
||||
}
|
||||
async getAssetsByCreator(
|
||||
params: GetAssetsByCreatorRpcInput,
|
||||
): Promise<DasApiAssetList> {
|
||||
return get_assets_by_creator(this, params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,6 +116,7 @@ import {
|
||||
SolanaWithdrawFromDriftVaultTool,
|
||||
SolanaGetAssetTool,
|
||||
SolanaGetAssetsByAuthorityTool,
|
||||
SolanaGetAssetsByCreatorTool,
|
||||
} from "./index";
|
||||
|
||||
export function createSolanaTools(solanaKit: SolanaAgentKit) {
|
||||
@@ -212,5 +213,6 @@ export function createSolanaTools(solanaKit: SolanaAgentKit) {
|
||||
new SolanaWithdrawFromDriftVaultTool(solanaKit),
|
||||
new SolanaGetAssetTool(solanaKit),
|
||||
new SolanaGetAssetsByAuthorityTool(solanaKit),
|
||||
new SolanaGetAssetsByCreatorTool(solanaKit),
|
||||
];
|
||||
}
|
||||
|
||||
40
src/langchain/metaplex/get_assets_by_creator.ts
Normal file
40
src/langchain/metaplex/get_assets_by_creator.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Tool } from "langchain/tools";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
|
||||
export class SolanaGetAssetsByCreatorTool extends Tool {
|
||||
name = "solana_get_assets_by_creator";
|
||||
description = `Fetch a list of assets created by a specific address using the Metaplex DAS API.
|
||||
|
||||
Inputs (input is a JSON string):
|
||||
creatorAddress: string, eg "N4f6zftYsuu4yT7icsjLwh4i6pB1zvvKbseHj2NmSQw" (required)
|
||||
onlyVerified: boolean (optional)
|
||||
sortBy: { sortBy: "created" | "updated" | "recentAction" | "none", sortDirection: "asc" | "desc" } (optional)
|
||||
limit: number (optional)
|
||||
page: number (optional)
|
||||
before: string (optional)
|
||||
after: string (optional)`;
|
||||
|
||||
constructor(private solanaKit: SolanaAgentKit) {
|
||||
super();
|
||||
}
|
||||
|
||||
protected async _call(input: string): Promise<string> {
|
||||
try {
|
||||
const parsedInput = JSON.parse(input);
|
||||
|
||||
const result = await this.solanaKit.getAssetsByCreator(parsedInput);
|
||||
|
||||
return JSON.stringify({
|
||||
status: "success",
|
||||
message: "Assets retrieved successfully",
|
||||
result,
|
||||
});
|
||||
} catch (error: any) {
|
||||
return JSON.stringify({
|
||||
status: "error",
|
||||
message: error.message,
|
||||
code: error.code || "UNKNOWN_ERROR",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,4 +2,5 @@ export * from "./deploy_collection";
|
||||
export * from "./mint_nft";
|
||||
export * from "./deploy_token";
|
||||
export * from "./get_asset";
|
||||
export * from "./get_asset_by_authority";
|
||||
export * from "./get_assets_by_authority";
|
||||
export * from "./get_assets_by_creator";
|
||||
|
||||
@@ -10,6 +10,5 @@ export async function get_assets_by_authority(
|
||||
params: GetAssetsByAuthorityRpcInput,
|
||||
) {
|
||||
const umi = createUmi(agent.connection.rpcEndpoint).use(dasApi());
|
||||
const assets = await umi.rpc.getAssetsByAuthority(params);
|
||||
return assets.items;
|
||||
return await umi.rpc.getAssetsByAuthority(params);
|
||||
}
|
||||
|
||||
14
src/tools/metaplex/get_assets_by_creator.ts
Normal file
14
src/tools/metaplex/get_assets_by_creator.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
|
||||
import {
|
||||
dasApi,
|
||||
GetAssetsByCreatorRpcInput,
|
||||
} from "@metaplex-foundation/digital-asset-standard-api";
|
||||
|
||||
export async function get_assets_by_creator(
|
||||
agent: SolanaAgentKit,
|
||||
params: GetAssetsByCreatorRpcInput,
|
||||
) {
|
||||
const umi = createUmi(agent.connection.rpcEndpoint).use(dasApi());
|
||||
return await umi.rpc.getAssetsByCreator(params);
|
||||
}
|
||||
@@ -3,3 +3,4 @@ export * from "./mint_nft";
|
||||
export * from "./deploy_token";
|
||||
export * from "./get_asset";
|
||||
export * from "./get_assets_by_authority";
|
||||
export * from "./get_assets_by_creator";
|
||||
|
||||
Reference in New Issue
Block a user