Merge branch 'main' into rename-and-fixes

This commit is contained in:
ARYAN
2024-12-25 05:10:33 +05:30
committed by GitHub
16 changed files with 1249 additions and 41 deletions

View File

@@ -28,6 +28,12 @@ import {
fetchPrice,
pythFetchPrice,
FEE_TIERS,
getAllDomainsTLDs,
getAllRegisteredAllDomains,
getOwnedDomainsForTLD,
getMainAllDomainsDomain,
getOwnedAllDomains,
resolveAllDomains,
} from "../tools";
import {
CollectionDeployment,
@@ -38,6 +44,7 @@ import {
PumpFunTokenOptions,
} from "../types";
import { BN } from "@coral-xyz/anchor";
import { NameAccountAndDomain } from "@onsol/tldparser";
/**
* Main class for interacting with Solana blockchain
@@ -197,8 +204,8 @@ export class SolanaAgentKit {
otherTokenMint: PublicKey,
initialPrice: Decimal,
maxPrice: Decimal,
feeTier: keyof typeof FEE_TIERS,
): Promise<string> {
feeTier: keyof typeof FEE_TIERS
) {
return createOrcaSingleSidedWhirlpool(
this,
depositTokenAmount,
@@ -206,15 +213,43 @@ export class SolanaAgentKit {
otherTokenMint,
initialPrice,
maxPrice,
feeTier,
feeTier
);
}
async resolveAllDomains(domain: string): Promise<PublicKey | undefined> {
return resolveAllDomains(this, domain);
}
async getOwnedAllDomains(
owner: PublicKey
): Promise<string[]> {
return getOwnedAllDomains(this, owner);
}
async getOwnedDomainsForTLD(
tld: string
):Promise<string[]> {
return getOwnedDomainsForTLD(this, tld);
}
async getAllDomainsTLDs(): Promise<String[]> {
return getAllDomainsTLDs(this);
}
async getAllRegisteredAllDomains(): Promise<string[]> {
return getAllRegisteredAllDomains(this);
}
async getMainAllDomainsDomain(owner: PublicKey): Promise<string | null> {
return getMainAllDomainsDomain(this, owner);
}
async raydiumCreateAmmV4(
marketId: PublicKey,
baseAmount: BN,
quoteAmount: BN,
startTime: BN,
startTime: BN
): Promise<string> {
return raydiumCreateAmmV4(
this,
@@ -223,8 +258,8 @@ export class SolanaAgentKit {
baseAmount,
quoteAmount,
startTime,
);
startTime
);;
}
async raydiumCreateClmm(
@@ -232,7 +267,7 @@ export class SolanaAgentKit {
mint2: PublicKey,
configId: PublicKey,
initialPrice: Decimal,
startTime: BN,
startTime: BN
): Promise<string> {
return raydiumCreateClmm(
this,
@@ -250,7 +285,7 @@ export class SolanaAgentKit {
configId: PublicKey,
mintAAmount: BN,
mintBAmount: BN,
startTime: BN,
startTime: BN
): Promise<string> {
return raydiumCreateCpmm(
this,
@@ -259,7 +294,8 @@ export class SolanaAgentKit {
configId,
mintAAmount,
mintBAmount,
startTime,
startTime
);
}
@@ -267,7 +303,7 @@ export class SolanaAgentKit {
baseMint: PublicKey,
quoteMint: PublicKey,
lotSize: number = 1,
tickSize: number = 0.01,
tickSize: number = 0.01
): Promise<string[]> {
return openbookCreateMarket(
this,

View File

@@ -341,10 +341,12 @@ export class SolanaRegisterDomainTool extends Tool {
export class SolanaResolveDomainTool extends Tool {
name = "solana_resolve_domain";
description = `Resolve a .sol domain to a Solana PublicKey.
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" or "pumpfun"(required)
domain: string, eg "pumpfun.sol" (required)
`;
constructor(private solanaKit: SolanaAgentKit) {
@@ -776,7 +778,9 @@ export class SolanaCreateSingleSidedWhirlpoolTool extends Tool {
if (!feeTier || !(feeTier in FEE_TIERS)) {
throw new Error(
`Invalid feeTier. Available options: ${Object.keys(FEE_TIERS).join(", ")}`,
`Invalid feeTier. Available options: ${Object.keys(FEE_TIERS).join(
", "
)}`
);
}
@@ -786,7 +790,7 @@ export class SolanaCreateSingleSidedWhirlpoolTool extends Tool {
otherTokenMint,
initialPrice,
maxPrice,
feeTier,
feeTier
);
return JSON.stringify({
@@ -827,7 +831,7 @@ export class SolanaRaydiumCreateAmmV4 extends Tool {
new PublicKey(inputFormat.marketId),
new BN(inputFormat.baseAmount),
new BN(inputFormat.quoteAmount),
new BN(inputFormat.startTime),
new BN(inputFormat.startTime)
);
return JSON.stringify({
@@ -872,7 +876,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({
@@ -920,7 +924,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({
@@ -962,7 +966,7 @@ export class SolanaOpenbookCreateMarket extends Tool {
new PublicKey(inputFormat.quoteMint),
inputFormat.lotSize,
inputFormat.tickSize,
inputFormat.tickSize
);
return JSON.stringify({
@@ -1012,6 +1016,171 @@ export class SolanaPythFetchPrice extends Tool {
}
}
export class SolanaResolveAllDomainsTool extends Tool {
name = "solana_resolve_all_domains";
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)`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
async _call(input: string): Promise<string> {
try {
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",
owner: owner?.toString(),
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "DOMAIN_RESOLUTION_ERROR",
});
}
}
}
export class SolanaGetOwnedDomains extends Tool {
name = "solana_get_owned_domains";
description = `Get all domains owned by a specific wallet address.
Inputs:
owner: string, eg "4Be9CvxqHW6BYiRAxW9Q3xu1ycTMWaL5z8NX4HR3ha7t" (required)`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
async _call(input: string): Promise<string> {
try {
const ownerPubkey = new PublicKey(input.trim());
const domains = await this.solanaKit.getOwnedAllDomains(ownerPubkey);
return JSON.stringify({
status: "success",
message: "Owned domains fetched successfully",
domains: domains,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "FETCH_OWNED_DOMAINS_ERROR",
});
}
}
}
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 "bonk" (required)`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
async _call(input: string): Promise<string> {
try {
const domains = await this.solanaKit.getOwnedDomainsForTLD(input);
return JSON.stringify({
status: "success",
message: "TLD domains fetched successfully",
domains: domains,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "FETCH_TLD_DOMAINS_ERROR",
});
}
}
}
export class SolanaGetAllTlds extends Tool {
name = "solana_get_all_tlds";
description = `Get all active top-level domains (TLDs) in the AllDomains Name Service`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
async _call(): Promise<string> {
try {
const tlds = await this.solanaKit.getAllDomainsTLDs();
return JSON.stringify({
status: "success",
message: "TLDs fetched successfully",
tlds: tlds,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "FETCH_TLDS_ERROR",
});
}
}
}
export class SolanaGetMainDomain extends Tool {
name = "solana_get_main_domain";
description = `Get the main/favorite domain for a given wallet address.
Inputs:
owner: string, eg "4Be9CvxqHW6BYiRAxW9Q3xu1ycTMWaL5z8NX4HR3ha7t" (required)`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
async _call(input: string): Promise<string> {
try {
const ownerPubkey = new PublicKey(input.trim());
const mainDomain = await this.solanaKit.getMainAllDomainsDomain(
ownerPubkey
);
return JSON.stringify({
status: "success",
message: "Main domain fetched successfully",
domain: mainDomain,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "FETCH_MAIN_DOMAIN_ERROR",
});
}
}
}
export function createSolanaTools(solanaKit: SolanaAgentKit) {
return [
new SolanaBalanceTool(solanaKit),
@@ -1029,7 +1198,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),
@@ -1040,6 +1208,11 @@ export function createSolanaTools(solanaKit: SolanaAgentKit) {
new SolanaOpenbookCreateMarket(solanaKit),
new SolanaCreateSingleSidedWhirlpoolTool(solanaKit),
new SolanaPythFetchPrice(solanaKit),
new SolanaResolveDomainTool(solanaKit),
new SolanaGetOwnedDomains(solanaKit),
new SolanaGetOwnedTldDomains(solanaKit),
new SolanaGetAllTlds(solanaKit),
new SolanaGetMainDomain(solanaKit),
new SolanaResolveAllDomainsTool(solanaKit),
];
}

View File

@@ -0,0 +1,19 @@
import { Connection, PublicKey } from "@solana/web3.js";
import { SolanaAgentKit } from "../index";
import { getAllTld } from "@onsol/tldparser";
/**
* 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<String[]> {
try {
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

@@ -0,0 +1,36 @@
import { getAllDomains } from "@bonfida/spl-name-service";
import { SolanaAgentKit } from "../agent";
import { PublicKey } from "@solana/web3.js";
import { getAllDomainsTLDs } from "./get_all_domains_tlds";
/**
* Get all registered domains across all TLDs
* @param agent SolanaAgentKit instance
* @returns Array of all registered domain names with their TLDs
*/
export async function getAllRegisteredAllDomains(
agent: SolanaAgentKit
): Promise<string[]> {
try {
// First get all TLDs
const tlds = await getAllDomainsTLDs(agent);
const allDomains: string[] = [];
// For each TLD, fetch all registered domains
for (const tld of tlds) {
const domains = await getAllDomains(
agent.connection,
new PublicKey("namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX")
);
// Add domains with TLD suffix
domains.forEach((domain) => {
allDomains.push(`${domain}.${tld}`);
});
}
return allDomains;
} catch (error: any) {
throw new Error(`Failed to fetch all registered domains: ${error.message}`);
}
}

View File

@@ -0,0 +1,24 @@
import { getFavoriteDomain as _getFavoriteDomain } from "@bonfida/spl-name-service";
import { PublicKey } from "@solana/web3.js";
/**
* Get the user's main/favorite domain for a SolanaAgentKit instance
* @param agent SolanaAgentKit instance
* @param owner Owner's public key
* @returns Promise resolving to the main domain name or null if not found
*/
export async function getMainAllDomainsDomain(
agent: any,
owner: PublicKey
): Promise<string | null> {
let mainDomain = null;
try {
mainDomain = await _getFavoriteDomain(agent.connection, owner);
return mainDomain.stale ? null : mainDomain.reverse;
} catch (error: any) {
console.log("No main/favorite domain found");
}
return null
}

View File

@@ -0,0 +1,21 @@
import { SolanaAgentKit } from "../agent";
import { PublicKey } from "@solana/web3.js";
import { NameAccountAndDomain, TldParser } from "@onsol/tldparser";
/**
* Get all domains owned domains for a specific TLD for the agent's wallet
* @param agent SolanaAgentKit instance
* @param owner - PublicKey of the owner
* @returns Promise resolving to an array of owned domains or an empty array if none are found
*/
export async function getOwnedAllDomains(
agent: SolanaAgentKit,
owner:PublicKey
): Promise<string[]> {
try {
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

@@ -0,0 +1,25 @@
import { TldParser } from "@onsol/tldparser";
import { SolanaAgentKit } from "../agent";
/**
* Get all domains owned by an address for a specific TLD
* @param agent SolanaAgentKit instance
* @param tld Top-level domain (e.g., "sol")
* @returns Promise resolving to an array of owned domain names for the specified TLD or an empty array if none are found
*/
export async function getOwnedDomainsForTLD(
agent: SolanaAgentKit,
tld: string
): Promise<string[]> {
try {
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

@@ -16,6 +16,21 @@ export * from "./stake_with_jup";
export * from "./fetch_price";
export * from "./send_compressed_airdrop";
export * from "./create_orca_single_sided_whirlpool";
export * from "./get_all_domains_tlds";
export * from "./get_all_registered_all_domains";
export * from "./get_owned_domains_for_tld";
export * from "./get_main_all_domains_domain";
export * from "./get_owned_all_domains";
export * from "./resolve_domain";
export * from "./get_all_domains_tlds";
export * from "./get_all_registered_all_domains";
export * from "./get_owned_domains_for_tld";
export * from "./get_main_all_domains_domain";
export * from "./get_owned_all_domains";
export * from "./resolve_domain";
export * from "./raydium_create_ammV4";
export * from "./raydium_create_clmm";
export * from "./raydium_create_cpmm";

View File

@@ -0,0 +1,30 @@
import { TldParser } from "@onsol/tldparser";
import { SolanaAgentKit } from "../index";
import { PublicKey } from "@solana/web3.js";
/**
* Resolve all domains for a given agent and domain
* @param agent SolanaAgentKit instance
* @param domain Domain name to resolve
* @returns Promise resolving to the domain or undefined if not found
*/
export async function resolveAllDomains(
agent: SolanaAgentKit,
domain: string
): Promise<PublicKey | undefined> {
try {
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}`);
}
}