Merge branch 'main' into getTokenDataByAddress

This commit is contained in:
0xiaorun
2025-01-04 13:19:28 +08:00
committed by GitHub
55 changed files with 3540 additions and 1035 deletions

View File

@@ -16,6 +16,7 @@ export async function getMainAllDomainsDomain(
mainDomain = await _getFavoriteDomain(agent.connection, owner);
return mainDomain.stale ? null : mainDomain.reverse;
} catch (error: any) {
console.error(error);
return null;
}
}

View File

@@ -29,7 +29,8 @@ export async function getPrimaryDomain(
);
}
return reverse;
} catch (error) {
} catch (error: any) {
console.error(error);
throw new Error(
`Failed to get primary domain for account: ${account.toBase58()}`,
);

View File

@@ -0,0 +1,10 @@
import { SolanaAgentKit } from "..";
/**
* Get the agents wallet address
* @param agent - SolanaAgentKit instance
* @returns string
*/
export function get_wallet_address(agent: SolanaAgentKit) {
return agent.wallet_address.toBase58();
}

View File

@@ -1,3 +1,6 @@
export * from "./get_wallet_address";
export * from "./request_faucet_funds";
export * from "./get_wallet_address";
export * from "./request_faucet_funds";
export * from "./deploy_token";
export * from "./deploy_collection";
@@ -18,6 +21,7 @@ export * from "./lend";
export * from "./get_tps";
export * from "./get_token_data";
export * from "./stake_with_jup";
export * from "./stake_with_solayer";
export * from "./fetch_price";
export * from "./send_compressed_airdrop";
export * from "./orca_close_position";
@@ -53,3 +57,4 @@ export * from "./rock_paper_scissor";
export * from "./create_tiplinks";
export * from "./tensor_trade";
export * from "./rugcheck";

View File

@@ -24,7 +24,8 @@ export async function resolveSolDomain(
try {
return await resolve(agent.connection, domain);
} catch (error) {
} catch (error: any) {
console.error(error);
throw new Error(`Failed to resolve domain: ${domain}`);
}
}

53
src/tools/rugcheck.ts Normal file
View File

@@ -0,0 +1,53 @@
import { TokenCheck } from "../types";
const BASE_URL = "https://api.rugcheck.xyz/v1";
/**
* Fetches a summary report for a specific token.
* @async
* @param {string} mint - The mint address of the token.
* @returns {Promise<TokenCheck>} The token summary report.
* @throws {Error} If the API call fails.
*/
export async function fetchTokenReportSummary(
mint: string,
): Promise<TokenCheck> {
try {
const response = await fetch(`${BASE_URL}/tokens/${mint}/report/summary`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
} catch (error: any) {
console.error(
`Error fetching report summary for token ${mint}:`,
error.message,
);
throw new Error(`Failed to fetch report summary for token ${mint}.`);
}
}
/**
* Fetches a detailed report for a specific token.
* @async
* @param {string} mint - The mint address of the token.
* @returns {Promise<TokenCheck>} The detailed token report.
* @throws {Error} If the API call fails.
*/
export async function fetchTokenDetailedReport(
mint: string,
): Promise<TokenCheck> {
try {
const response = await fetch(`${BASE_URL}/tokens/${mint}/report`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
} catch (error: any) {
console.error(
`Error fetching detailed report for token ${mint}:`,
error.message,
);
throw new Error(`Failed to fetch detailed report for token ${mint}.`);
}
}

View File

@@ -88,6 +88,7 @@ export async function sendCompressedAirdrop(
agent.wallet.publicKey,
);
} catch (error) {
console.error(error);
throw new Error(
"Source token account not found and failed to create it. Please add funds to your wallet and try again.",
);

View File

@@ -0,0 +1,64 @@
import { VersionedTransaction } from "@solana/web3.js";
import { SolanaAgentKit } from "../index";
/**
* Stake SOL with Solayer
* @param agent SolanaAgentKit instance
* @param amount Amount of SOL to stake
* @returns Transaction signature
*/
export async function stakeWithSolayer(
agent: SolanaAgentKit,
amount: number,
): Promise<string> {
try {
const response = await fetch(
`https://app.solayer.org/api/action/restake/ssol?amount=${amount}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
account: agent.wallet.publicKey.toBase58(),
}),
},
);
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.message || 'Staking request failed');
}
const data = await response.json();
// Deserialize and prepare transaction
const txn = VersionedTransaction.deserialize(
Buffer.from(data.transaction, "base64"),
);
// Update blockhash
const { blockhash } = await agent.connection.getLatestBlockhash();
txn.message.recentBlockhash = blockhash;
// Sign and send transaction
txn.sign([agent.wallet]);
const signature = await agent.connection.sendTransaction(txn, {
preflightCommitment: "confirmed",
maxRetries: 3,
});
// Wait for confirmation
const latestBlockhash = await agent.connection.getLatestBlockhash();
await agent.connection.confirmTransaction({
signature,
blockhash: latestBlockhash.blockhash,
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
});
return signature;
} catch (error: any) {
console.error(error);
throw new Error(`Solayer sSOL staking failed: ${error.message}`);
}
}

View File

@@ -33,6 +33,7 @@ export async function listNFTForSale(
throw new Error(`You don't own this NFT (${nftMint.toString()})`);
}
} catch (error: any) {
console.error(error);
throw new Error(
`No token account found for mint ${nftMint.toString()}. Make sure you own this NFT.`,
);