feat: tool description + types

This commit is contained in:
aryan
2024-12-25 04:26:06 +05:30
parent d81d17e2fd
commit 737d5ce86b
7 changed files with 64 additions and 80 deletions

View File

@@ -7,7 +7,8 @@
"scripts": {
"build": "tsc",
"docs": "typedoc src --out docs",
"test": "ts-node test/**/*.ts",
"test": "ts-node test/index.ts",
"test:domain": "ts-node test/domain_methods.test.ts",
"generate": "ts-node src/utils/keypair.ts"
},
"engines": {

View File

@@ -218,20 +218,17 @@ export class SolanaAgentKit {
async getOwnedAllDomains(
owner: PublicKey
): Promise<NameAccountAndDomain[]> {
): Promise<string[]> {
return getOwnedAllDomains(this, owner);
}
async getOwnedDomainsForTLD(
tld: string
):Promise<NameAccountAndDomain[]> {
):Promise<string[]> {
return getOwnedDomainsForTLD(this, tld);
}
async getAllDomainsTLDs(): Promise<Array<{
tld: String;
parentAccount: PublicKey;
}>> {
async getAllDomainsTLDs(): Promise<String[]> {
return getAllDomainsTLDs(this);
}

View File

@@ -342,8 +342,9 @@ export class SolanaRegisterDomainTool extends Tool {
export class SolanaResolveDomainTool extends Tool {
name = "solana_resolve_domain";
description = `Resolve a .sol domain to a Solana PublicKey.
For other domains, use the solana_resolve_all_domains tool.
description = `Resolve ONLY .sol domain names to a Solana PublicKey.
This tool is exclusively for .sol domains.
DO NOT use this for other domain types like .blink, .bonk, etc.
Inputs:
domain: string, eg "pumpfun.sol" (required)
@@ -777,7 +778,11 @@ export class SolanaCreateSingleSidedWhirlpoolTool extends Tool {
const feeTier = inputFormat.feeTier;
if (!feeTier || !(feeTier in FEE_TIERS)) {
throw new Error(`Invalid feeTier. Available options: ${Object.keys(FEE_TIERS).join(", ")}`);
throw new Error(
`Invalid feeTier. Available options: ${Object.keys(FEE_TIERS).join(
", "
)}`
);
}
const txId = await this.solanaKit.createOrcaSingleSidedWhirlpool(
@@ -786,7 +791,7 @@ export class SolanaCreateSingleSidedWhirlpoolTool extends Tool {
otherTokenMint,
initialPrice,
maxPrice,
feeTier,
feeTier
);
return JSON.stringify({
@@ -804,7 +809,6 @@ export class SolanaCreateSingleSidedWhirlpoolTool extends Tool {
}
}
export class SolanaRaydiumCreateAmmV4 extends Tool {
name = "raydium_create_ammV4";
description = `Raydium's Legacy AMM that requiers an OpenBook marketID
@@ -822,13 +826,13 @@ export class SolanaRaydiumCreateAmmV4 extends Tool {
async _call(input: string): Promise<string> {
try {
let inputFormat = JSON.parse(input)
let inputFormat = JSON.parse(input);
const tx = await this.solanaKit.raydiumCreateAmmV4(
new PublicKey(inputFormat.marketId),
new BN(inputFormat.baseAmount),
new BN(inputFormat.quoteAmount),
new BN(inputFormat.startTime),
new BN(inputFormat.startTime)
);
return JSON.stringify({
@@ -864,7 +868,7 @@ export class SolanaRaydiumCreateClmm extends Tool {
async _call(input: string): Promise<string> {
try {
let inputFormat = JSON.parse(input)
let inputFormat = JSON.parse(input);
const tx = await this.solanaKit.raydiumCreateClmm(
new PublicKey(inputFormat.mint1),
@@ -873,7 +877,7 @@ export class SolanaRaydiumCreateClmm extends Tool {
new PublicKey(inputFormat.configId),
new Decimal(inputFormat.initialPrice),
new BN(inputFormat.startTime),
new BN(inputFormat.startTime)
);
return JSON.stringify({
@@ -910,7 +914,7 @@ export class SolanaRaydiumCreateCpmm extends Tool {
async _call(input: string): Promise<string> {
try {
let inputFormat = JSON.parse(input)
let inputFormat = JSON.parse(input);
const tx = await this.solanaKit.raydiumCreateCpmm(
new PublicKey(inputFormat.mint1),
@@ -921,7 +925,7 @@ export class SolanaRaydiumCreateCpmm extends Tool {
new BN(inputFormat.mintAAmount),
new BN(inputFormat.mintBAmount),
new BN(inputFormat.startTime),
new BN(inputFormat.startTime)
);
return JSON.stringify({
@@ -956,14 +960,14 @@ export class SolanaOpenbookCreateMarket extends Tool {
async _call(input: string): Promise<string> {
try {
let inputFormat = JSON.parse(input)
let inputFormat = JSON.parse(input);
const tx = await this.solanaKit.openbookCreateMarket(
new PublicKey(inputFormat.baseMint),
new PublicKey(inputFormat.quoteMint),
inputFormat.lotSize,
inputFormat.tickSize,
inputFormat.tickSize
);
return JSON.stringify({
@@ -1015,7 +1019,9 @@ export class SolanaPythFetchPrice extends Tool {
export class SolanaResolveAllDomainsTool extends Tool {
name = "solana_resolve_all_domains";
description = `Resolve a domain name to a public key.
description = `Resolve domain names to a public key for ALL domain types EXCEPT .sol domains.
Use this for domains like .blink, .bonk, etc.
DO NOT use this for .sol domains (use solana_resolve_domain instead).
Input:
domain: string, eg "mydomain.blink" or "mydomain.bonk" (required)`;
@@ -1026,9 +1032,16 @@ export class SolanaResolveAllDomainsTool extends Tool {
async _call(input: string): Promise<string> {
try {
console.log(input)
const owner = await this.solanaKit.resolveAllDomains(input);
if(!owner) {
return JSON.stringify({
status: "error",
message: "Domain not found",
code: "DOMAIN_NOT_FOUND",
});
}
return JSON.stringify({
status: "success",
message: "Domain resolved successfully",
@@ -1044,6 +1057,7 @@ export class SolanaResolveAllDomainsTool extends Tool {
}
}
export class SolanaGetOwnedDomains extends Tool {
name = "solana_get_owned_domains";
description = `Get all domains owned by a specific wallet address.
@@ -1057,7 +1071,7 @@ export class SolanaGetOwnedDomains extends Tool {
async _call(input: string): Promise<string> {
try {
const ownerPubkey = new PublicKey(input);
const ownerPubkey = new PublicKey(input.trim());
const domains = await this.solanaKit.getOwnedAllDomains(ownerPubkey);
return JSON.stringify({
@@ -1075,12 +1089,13 @@ export class SolanaGetOwnedDomains extends Tool {
}
}
export class SolanaGetOwnedTldDomains extends Tool {
name = "solana_get_owned_tld_domains";
description = `Get all domains owned by the agent's wallet for a specific TLD.
Inputs:
tld: string, eg "sol" (required)`;
tld: string, eg "bonk" (required)`;
constructor(private solanaKit: SolanaAgentKit) {
super();
@@ -1088,9 +1103,7 @@ export class SolanaGetOwnedTldDomains extends Tool {
async _call(input: string): Promise<string> {
try {
const domains = await this.solanaKit.getOwnedDomainsForTLD(
input
);
const domains = await this.solanaKit.getOwnedDomainsForTLD(input);
return JSON.stringify({
status: "success",
@@ -1107,9 +1120,10 @@ export class SolanaGetOwnedTldDomains extends Tool {
}
}
export class SolanaGetAllTlds extends Tool {
name = "solana_get_all_tlds";
description = `Get all active top-level domains (TLDs) in the Solana name service`
description = `Get all active top-level domains (TLDs) in the AllDomains Name Service`;
constructor(private solanaKit: SolanaAgentKit) {
super();
@@ -1134,38 +1148,12 @@ export class SolanaGetAllTlds extends Tool {
}
}
export class SolanaGetAllRegisteredDomains extends Tool {
name = "solana_get_all_registered_domains";
description = `Get all registered domains across all TLDs in the Solana name service`
constructor(private solanaKit: SolanaAgentKit) {
super();
}
async _call(): Promise<string> {
try {
const domains = await this.solanaKit.getAllRegisteredAllDomains();
return JSON.stringify({
status: "success",
message: "All registered domains fetched successfully",
domains: domains,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "FETCH_ALL_DOMAINS_ERROR",
});
}
}
}
export class SolanaGetMainDomain extends Tool {
name = "solana_get_main_domain";
description = `Get the main/favorite domain for a given wallet address.
Inputs (input is a JSON string):
Inputs:
owner: string, eg "4Be9CvxqHW6BYiRAxW9Q3xu1ycTMWaL5z8NX4HR3ha7t" (required)`;
constructor(private solanaKit: SolanaAgentKit) {
@@ -1174,8 +1162,7 @@ export class SolanaGetMainDomain extends Tool {
async _call(input: string): Promise<string> {
try {
let inputFormat = JSON.parse(input);
const ownerPubkey = new PublicKey(inputFormat.owner);
const ownerPubkey = new PublicKey(input.trim());
const mainDomain = await this.solanaKit.getMainAllDomainsDomain(
ownerPubkey
);
@@ -1212,7 +1199,6 @@ export function createSolanaTools(solanaKit: SolanaAgentKit) {
new SolanaTPSCalculatorTool(solanaKit),
new SolanaStakeTool(solanaKit),
new SolanaFetchPriceTool(solanaKit),
new SolanaResolveDomainTool(solanaKit),
new SolanaGetDomainTool(solanaKit),
new SolanaTokenDataTool(solanaKit),
new SolanaTokenDataByTickerTool(solanaKit),
@@ -1227,14 +1213,7 @@ export function createSolanaTools(solanaKit: SolanaAgentKit) {
new SolanaGetOwnedDomains(solanaKit),
new SolanaGetOwnedTldDomains(solanaKit),
new SolanaGetAllTlds(solanaKit),
new SolanaGetAllRegisteredDomains(solanaKit),
new SolanaGetMainDomain(solanaKit),
new SolanaResolveAllDomainsTool(solanaKit),
new SolanaGetOwnedDomains(solanaKit),
new SolanaGetOwnedTldDomains(solanaKit),
new SolanaGetAllTlds(solanaKit),
new SolanaGetAllRegisteredDomains(solanaKit),
new SolanaGetMainDomain(solanaKit),
];
}

View File

@@ -3,18 +3,16 @@ import { SolanaAgentKit } from "../index";
import { getAllTld } from "@onsol/tldparser";
/**
* Get all active top-level domains (TLDs) in the Solana name service
* Get all active top-level domains (TLDs) in the AllDomains Name Service
* @param agent SolanaAgentKit instance
* @returns Array of active TLD strings
*/
export async function getAllDomainsTLDs(
agent: SolanaAgentKit
): Promise<Array<{
tld: String;
parentAccount: PublicKey;
}>> {
): Promise<String[]> {
try {
return getAllTld(agent.connection)
let tlds = await getAllTld(agent.connection)
return tlds.map((tld) => tld.tld)
} catch (error: any) {
throw new Error(`Failed to fetch TLDs: ${error.message}`);
}

View File

@@ -11,9 +11,10 @@ import { NameAccountAndDomain, TldParser } from "@onsol/tldparser";
export async function getOwnedAllDomains(
agent: SolanaAgentKit,
owner:PublicKey
): Promise<NameAccountAndDomain[]> {
): Promise<string[]> {
try {
return new TldParser(agent.connection).getParsedAllUserDomains(owner);
let domains = await new TldParser(agent.connection).getParsedAllUserDomains(owner);
return domains.map((domain) => domain.domain)
} catch (error: any) {
throw new Error(`Failed to fetch owned domains: ${error.message}`);
}

View File

@@ -1,6 +1,5 @@
import { NameAccountAndDomain, TldParser } from "@onsol/tldparser";
import { TldParser } from "@onsol/tldparser";
import { SolanaAgentKit } from "../agent";
import { PublicKey } from "@solana/web3.js";
/**
* Get all domains owned by an address for a specific TLD
* @param agent SolanaAgentKit instance
@@ -10,13 +9,14 @@ import { PublicKey } from "@solana/web3.js";
export async function getOwnedDomainsForTLD(
agent: SolanaAgentKit,
tld: string
): Promise<NameAccountAndDomain[]> {
): Promise<string[]> {
try {
return new TldParser(agent.connection)
let domains = await new TldParser(agent.connection)
.getParsedAllUserDomainsFromTld(
agent.wallet_address,
tld
)
return domains.map((domain) => domain.domain)
} catch (error: any) {
throw new Error(`Failed to fetch domains for TLD: ${error.message}`);
}

View File

@@ -13,10 +13,18 @@ export async function resolveAllDomains(
domain: string
): Promise<PublicKey | undefined> {
try {
let tld = new TldParser(agent.connection).getOwnerFromDomainTld(domain)
return tld;
console.log("domain", domain);
let tld = await new TldParser(agent.connection).getOwnerFromDomainTld(
domain
);
console.log("tld", tld);
return tld;
} catch (error: any) {
// console.log("error", error.);
if(error.message.includes("Cannot read properties of undefined (reading 'owner')")) {
return undefined
}
throw new Error(`Domain resolution failed: ${error.message}`);
}
}