Skip to content

Commit

Permalink
Integrate Metaplex DAS API (sendaifun#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
thearyanag committed Jan 22, 2025
2 parents 343cf4c + 331482a commit 4b88522
Show file tree
Hide file tree
Showing 20 changed files with 1,219 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,12 @@ const signature = await agent.voltrWithdrawStrategy(
)
```

### Get a Solana asset by its ID

```typescript
const asset = await agent.getAsset("41Y8C4oxk4zgJT1KXyQr35UhZcfsp5mP86Z2G7UUzojU")
```

## Examples

### LangGraph Multi-Agent System
Expand All @@ -521,6 +527,7 @@ The toolkit relies on several key Solana and Metaplex libraries:

- @solana/web3.js
- @solana/spl-token
- @metaplex-foundation/digital-asset-standard-api
- @metaplex-foundation/mpl-token-metadata
- @metaplex-foundation/mpl-core
- @metaplex-foundation/umi
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@langchain/openai": "^0.3.16",
"@lightprotocol/compressed-token": "^0.17.1",
"@lightprotocol/stateless.js": "^0.17.1",
"@metaplex-foundation/digital-asset-standard-api": "^1.0.4",
"@metaplex-foundation/mpl-core": "^1.1.1",
"@metaplex-foundation/mpl-token-metadata": "^3.3.0",
"@metaplex-foundation/mpl-toolbox": "^0.9.4",
Expand Down
528 changes: 528 additions & 0 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ import lendAndBorrowAPYAction from "./drift/getLendAndBorrowAPY";
import getVoltrPositionValuesAction from "./voltr/getPositionValues";
import depositVoltrStrategyAction from "./voltr/depositStrategy";
import withdrawVoltrStrategyAction from "./voltr/withdrawStrategy";
import getAssetAction from "./metaplex/getAsset";
import getAssetsByAuthorityAction from "./metaplex/getAssetsByAuthority";
import getAssetsByCreatorAction from "./metaplex/getAssetsByCreator";
import searchAssetsAction from "./metaplex/searchAssets";

export const ACTIONS = {
WALLET_ADDRESS_ACTION: getWalletAddressAction,
Expand Down Expand Up @@ -150,6 +154,10 @@ export const ACTIONS = {
GET_VOLTR_POSITION_VALUES_ACTION: getVoltrPositionValuesAction,
DEPOSIT_VOLTR_STRATEGY_ACTION: depositVoltrStrategyAction,
WITHDRAW_VOLTR_STRATEGY_ACTION: withdrawVoltrStrategyAction,
GET_ASSET_ACTION: getAssetAction,
GET_ASSETS_BY_AUTHORITY_ACTION: getAssetsByAuthorityAction,
GET_ASSETS_BY_CREATOR_ACTION: getAssetsByCreatorAction,
SEARCH_ASSETS_ACTION: searchAssetsAction,
};

export type { Action, ActionExample, Handler } from "../types/action";
51 changes: 51 additions & 0 deletions src/actions/metaplex/getAsset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Action } from "../../types/action";
import { SolanaAgentKit } from "../../agent";
import { z } from "zod";
import { get_asset } from "../../tools/metaplex";

const getAssetAction: Action = {
name: "GET_ASSET",
similes: [
"fetch asset",
"retrieve asset",
"get asset details",
"fetch asset details",
],
description: `Fetch asset details using the Metaplex DAS API.`,
examples: [
[
{
input: {
assetId: "Asset ID",
},
output: {
status: "success",
message: "Asset retrieved successfully",
result: {
// Example asset details
name: "Example Asset",
symbol: "EXA",
uri: "https://example.com/asset.json",
},
},
explanation: "Fetch details of an asset using its ID",
},
],
],
schema: z.object({
assetId: z.string().min(1, "Asset ID is required"),
}),
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
const assetId = input.assetId;

const result = await get_asset(agent, assetId);

return {
status: "success",
message: "Asset retrieved successfully",
result,
};
},
};

export default getAssetAction;
103 changes: 103 additions & 0 deletions src/actions/metaplex/getAssetsByAuthority.ts
Original file line number Diff line number Diff line change
@@ -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: {
authority: "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({
authority: 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 changes: 105 additions & 0 deletions src/actions/metaplex/getAssetsByCreator.ts
Original file line number Diff line number Diff line change
@@ -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: {
creator: "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({
creator: 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;
Loading

0 comments on commit 4b88522

Please sign in to comment.