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

@@ -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}`);
}
}