mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-31 07:36:46 +00:00
Updated protocol name instead of library name
This commit is contained in:
70
src/actions/sns/getAllRegisteredAllDomains.ts
Normal file
70
src/actions/sns/getAllRegisteredAllDomains.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import { Action } from "../../types/action";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { z } from "zod";
|
||||
import { getAllRegisteredAllDomains } from "../../tools";
|
||||
|
||||
const getAllRegisteredAllDomainsAction: Action = {
|
||||
name: "GET_ALL_REGISTERED_ALL_DOMAINS",
|
||||
similes: [
|
||||
"list registered domains",
|
||||
"get all domains",
|
||||
"fetch registered domains",
|
||||
"get domain list",
|
||||
"list active domains",
|
||||
"get registered names",
|
||||
],
|
||||
description: "Get a list of all registered domains across all TLDs",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
limit: 100,
|
||||
offset: 0,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
domains: ["solana.sol", "bonk.abc", "wallet.backpack"],
|
||||
total: 3,
|
||||
message: "Successfully retrieved registered domains",
|
||||
},
|
||||
explanation: "Get the first 100 registered domains across all TLDs",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
limit: z
|
||||
.number()
|
||||
.positive()
|
||||
.max(1000)
|
||||
.default(100)
|
||||
.describe("Maximum number of domains to return"),
|
||||
offset: z
|
||||
.number()
|
||||
.nonnegative()
|
||||
.default(0)
|
||||
.describe("Number of domains to skip"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const limit = input.limit || 100;
|
||||
const offset = input.offset || 0;
|
||||
|
||||
// Get all registered domains
|
||||
const domains = await getAllRegisteredAllDomains(agent);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
domains: domains.slice(offset, offset + limit),
|
||||
total: domains.length,
|
||||
message: "Successfully retrieved registered domains",
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to get registered domains: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default getAllRegisteredAllDomainsAction;
|
||||
67
src/actions/sns/getMainAllDomainsDomain.ts
Normal file
67
src/actions/sns/getMainAllDomainsDomain.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Action } from "../../types/action";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { z } from "zod";
|
||||
import { getMainAllDomainsDomain } from "../../tools";
|
||||
|
||||
const getMainAllDomainsDomainAction: Action = {
|
||||
name: "GET_MAIN_ALL_DOMAINS_DOMAIN",
|
||||
similes: [
|
||||
"get main domain",
|
||||
"fetch primary domain",
|
||||
"get default domain",
|
||||
"get main address name",
|
||||
"get primary name",
|
||||
"get main domain name",
|
||||
],
|
||||
description: "Get the main domain associated with a wallet address",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
address: "7nxQB...",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
domain: "solana.sol",
|
||||
message: "Successfully retrieved main domain",
|
||||
},
|
||||
explanation: "Get the main domain name for a given wallet address",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
address: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe("The wallet address to get the main domain for"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const mainDomain = await getMainAllDomainsDomain(
|
||||
agent,
|
||||
new PublicKey(input.address),
|
||||
);
|
||||
|
||||
if (!mainDomain) {
|
||||
return {
|
||||
status: "error",
|
||||
message: "No main domain found for this address",
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
domain: mainDomain,
|
||||
message: "Successfully retrieved main domain",
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to get main domain: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default getMainAllDomainsDomainAction;
|
||||
57
src/actions/sns/getPrimaryDomain.ts
Normal file
57
src/actions/sns/getPrimaryDomain.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Action } from "../../types/action";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { z } from "zod";
|
||||
import { getPrimaryDomain } from "../../tools";
|
||||
|
||||
const getPrimaryDomainAction: Action = {
|
||||
name: "GET_PRIMARY_DOMAIN",
|
||||
similes: [
|
||||
"get primary domain",
|
||||
"lookup primary domain",
|
||||
"check primary domain",
|
||||
"find primary domain",
|
||||
"get main domain",
|
||||
"primary sol domain",
|
||||
],
|
||||
description:
|
||||
"Get the primary .sol domain associated with a Solana wallet address",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
account: "7nxQB...",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
domain: "vitalik.sol",
|
||||
message: "Primary domain: vitalik.sol",
|
||||
},
|
||||
explanation: "Get the primary .sol domain for a wallet address",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
account: z.string().min(1).describe("The Solana wallet address to lookup"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const account = new PublicKey(input.account);
|
||||
|
||||
const response = await getPrimaryDomain(agent, account);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
domain: response,
|
||||
message: `Primary domain: ${response}`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to get primary domain: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default getPrimaryDomainAction;
|
||||
63
src/actions/sns/registerDomain.ts
Normal file
63
src/actions/sns/registerDomain.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { Action } from "../../types/action";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { z } from "zod";
|
||||
import { registerDomain } from "../../tools";
|
||||
|
||||
const registerDomainAction: Action = {
|
||||
name: "REGISTER_DOMAIN",
|
||||
similes: [
|
||||
"register domain",
|
||||
"buy domain",
|
||||
"get domain name",
|
||||
"register .sol",
|
||||
"purchase domain",
|
||||
"domain registration",
|
||||
],
|
||||
description: "Register a .sol domain name using Bonfida Name Service",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
name: "mydomain",
|
||||
spaceKB: 1,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
signature: "2ZE7Rz...",
|
||||
message: "Successfully registered mydomain.sol",
|
||||
},
|
||||
explanation: "Register a new .sol domain with 1KB storage space",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
name: z.string().min(1).describe("Domain name to register (without .sol)"),
|
||||
spaceKB: z
|
||||
.number()
|
||||
.min(1)
|
||||
.max(10)
|
||||
.default(1)
|
||||
.describe("Space allocation in KB (max 10KB)"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const name = input.name as string;
|
||||
const spaceKB = (input.spaceKB as number) || 1;
|
||||
|
||||
const signature = await registerDomain(agent, name, spaceKB);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
signature,
|
||||
message: `Successfully registered ${name}.sol`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Domain registration failed: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default registerDomainAction;
|
||||
59
src/actions/sns/resolveSolDomain.ts
Normal file
59
src/actions/sns/resolveSolDomain.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { Action } from "../../types/action";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { z } from "zod";
|
||||
import { resolveSolDomain } from "../../tools/";
|
||||
|
||||
const resolveSolDomainAction: Action = {
|
||||
name: "RESOLVE_SOL_DOMAIN",
|
||||
similes: [
|
||||
"resolve sol domain",
|
||||
"lookup sol domain",
|
||||
"get sol domain owner",
|
||||
"check sol domain",
|
||||
"find sol domain owner",
|
||||
"resolve .sol",
|
||||
],
|
||||
description:
|
||||
"Resolve a .sol domain to its corresponding Solana wallet address using Bonfida Name Service",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
domain: "vitalik.sol",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
owner: "7nxQB...",
|
||||
message: "Successfully resolved vitalik.sol",
|
||||
},
|
||||
explanation: "Resolve a .sol domain to get the owner's wallet address",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
domain: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe("The .sol domain to resolve (with or without .sol suffix)"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const domain = input.domain as string;
|
||||
|
||||
const res = await resolveSolDomain(agent, domain);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
owner: res.toString(),
|
||||
message: `Successfully resolved ${res}`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to resolve domain: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default resolveSolDomainAction;
|
||||
Reference in New Issue
Block a user