feat: linting + prettier

This commit is contained in:
aryan
2024-12-25 17:08:17 +05:30
parent 2753794342
commit c81aa7f892
25 changed files with 1202 additions and 103 deletions

View File

@@ -157,8 +157,9 @@ export async function createOrcaSingleSidedWhirlpool(
}
const mintAAccount = await fetcher.getMintInfo(mintA);
const mintBAccount = await fetcher.getMintInfo(mintB);
if (mintAAccount === null || mintBAccount === null)
if (mintAAccount === null || mintBAccount === null) {
throw Error("Mint account not found");
}
const tickSpacing = FEE_TIERS[feeTier];
const tickIndex = PriceMath.priceToTickIndex(
initialPrice,
@@ -273,8 +274,9 @@ export async function createOrcaSingleSidedWhirlpool(
if (
!TickUtil.checkTickInBounds(tickLowerInitializableIndex) ||
!TickUtil.checkTickInBounds(tickUpperInitializableIndex)
)
) {
throw Error("Prices out of bounds");
}
const increasLiquidityQuoteParam: IncreaseLiquidityQuoteParam = {
inputTokenAmount: new BN(depositTokenAmount),
inputTokenMint: depositTokenMint,

View File

@@ -1,4 +1,3 @@
import { Connection, PublicKey } from "@solana/web3.js";
import { SolanaAgentKit } from "../index";
import { getAllTld } from "@onsol/tldparser";
@@ -8,12 +7,13 @@ import { getAllTld } from "@onsol/tldparser";
* @returns Array of active TLD strings
*/
export async function getAllDomainsTLDs(
agent: SolanaAgentKit
agent: SolanaAgentKit,
// eslint-disable-next-line @typescript-eslint/ban-types
): Promise<String[]> {
try {
let tlds = await getAllTld(agent.connection)
return tlds.map((tld) => tld.tld)
const 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

@@ -9,7 +9,7 @@ import { getAllDomainsTLDs } from "./get_all_domains_tlds";
* @returns Array of all registered domain names with their TLDs
*/
export async function getAllRegisteredAllDomains(
agent: SolanaAgentKit
agent: SolanaAgentKit,
): Promise<string[]> {
try {
// First get all TLDs
@@ -20,7 +20,7 @@ export async function getAllRegisteredAllDomains(
for (const tld of tlds) {
const domains = await getAllDomains(
agent.connection,
new PublicKey("namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX")
new PublicKey("namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX"),
);
// Add domains with TLD suffix

View File

@@ -11,11 +11,12 @@ export async function get_balance(
agent: SolanaAgentKit,
token_address?: PublicKey,
): Promise<number> {
if (!token_address)
if (!token_address) {
return (
(await agent.connection.getBalance(agent.wallet_address)) /
LAMPORTS_PER_SOL
);
}
const token_account =
await agent.connection.getTokenAccountBalance(token_address);

View File

@@ -1,7 +1,6 @@
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
@@ -10,15 +9,13 @@ import { PublicKey } from "@solana/web3.js";
*/
export async function getMainAllDomainsDomain(
agent: any,
owner: PublicKey
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;
}
return null
}

View File

@@ -1,6 +1,6 @@
import { SolanaAgentKit } from "../agent";
import { PublicKey } from "@solana/web3.js";
import { NameAccountAndDomain, TldParser } from "@onsol/tldparser";
import { TldParser } from "@onsol/tldparser";
/**
* Get all domains owned domains for a specific TLD for the agent's wallet
@@ -10,11 +10,13 @@ import { NameAccountAndDomain, TldParser } from "@onsol/tldparser";
*/
export async function getOwnedAllDomains(
agent: SolanaAgentKit,
owner:PublicKey
owner: PublicKey,
): Promise<string[]> {
try {
let domains = await new TldParser(agent.connection).getParsedAllUserDomains(owner);
return domains.map((domain) => domain.domain)
const 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

@@ -4,22 +4,18 @@ 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
* @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
tld: string,
): Promise<string[]> {
try {
let domains = await new TldParser(agent.connection)
.getParsedAllUserDomainsFromTld(
agent.wallet_address,
tld
)
return domains.map((domain) => domain.domain)
const 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

@@ -27,11 +27,11 @@ export async function getTokenDataByAddress(
}
export async function getTokenAddressFromTicker(
ticker: string
ticker: string,
): Promise<string | null> {
try {
const response = await fetch(
`https://api.dexscreener.com/latest/dex/search?q=${ticker}`
`https://api.dexscreener.com/latest/dex/search?q=${ticker}`,
);
const data = await response.json();
@@ -46,7 +46,7 @@ export async function getTokenAddressFromTicker(
solanaPairs = solanaPairs.filter(
(pair: any) =>
pair.baseToken.symbol.toLowerCase() === ticker.toLowerCase()
pair.baseToken.symbol.toLowerCase() === ticker.toLowerCase(),
);
// Return the address of the highest FDV Solana pair
@@ -58,11 +58,11 @@ export async function getTokenAddressFromTicker(
}
export async function getTokenDataByTicker(
ticker: string
ticker: string,
): Promise<JupiterTokenData | undefined> {
const address = await getTokenAddressFromTicker(ticker);
if (!address) {
throw new Error(`Token address not found for ticker: ${ticker}`);
}
return getTokenDataByAddress(new PublicKey(address));
}
}

View File

@@ -23,7 +23,6 @@ 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";

View File

@@ -21,9 +21,15 @@ async function uploadMetadata(
formData.append("showName", "true");
if (options?.twitter) formData.append("twitter", options.twitter);
if (options?.telegram) formData.append("telegram", options.telegram);
if (options?.website) formData.append("website", options.website);
if (options?.twitter) {
formData.append("twitter", options.twitter);
}
if (options?.telegram) {
formData.append("telegram", options.telegram);
}
if (options?.website) {
formData.append("website", options.website);
}
const imageResponse = await fetch(imageUrl);
const imageBlob = await imageResponse.blob();

View File

@@ -27,11 +27,11 @@ export async function pythFetchPrice(priceFeedID: string): Promise<string> {
}
// get price and exponent from price feed
let price = new BN(currentPrice[0].getPriceUnchecked().price);
let exponent = new BN(currentPrice[0].getPriceUnchecked().expo);
const price = new BN(currentPrice[0].getPriceUnchecked().price);
const exponent = new BN(currentPrice[0].getPriceUnchecked().expo);
// convert to scaled price
let scaledPrice = price.div(new BN(10).pow(exponent));
const scaledPrice = price.div(new BN(10).pow(exponent));
return scaledPrice.toString();
} catch (error: any) {

View File

@@ -25,8 +25,9 @@ export async function raydiumCreateClmm(
const [mintInfo1, mintInfo2] = await agent.connection.getMultipleAccountsInfo(
[mint1, mint2],
);
if (mintInfo1 === null || mintInfo2 === null)
if (mintInfo1 === null || mintInfo2 === null) {
throw Error("fetch mint info error");
}
const mintDecodeInfo1 = MintLayout.decode(mintInfo1.data);
const mintDecodeInfo2 = MintLayout.decode(mintInfo2.data);
@@ -59,7 +60,7 @@ export async function raydiumCreateClmm(
// programId: DEVNET_PROGRAM_ID.CLMM,
mint1: mintFormatInfo1,
mint2: mintFormatInfo2,
// @ts-ignore
// @ts-expect-error sdk bug
ammConfig: { id: configId },
initialPrice,
startTime,

View File

@@ -26,8 +26,9 @@ export async function raydiumCreateCpmm(
const [mintInfoA, mintInfoB] = await agent.connection.getMultipleAccountsInfo(
[mintA, mintB],
);
if (mintInfoA === null || mintInfoB === null)
if (mintInfoA === null || mintInfoB === null) {
throw Error("fetch mint info error");
}
const mintDecodeInfoA = MintLayout.decode(mintInfoA.data);
const mintDecodeInfoB = MintLayout.decode(mintInfoB.data);
@@ -55,7 +56,7 @@ export async function raydiumCreateCpmm(
extensions: {},
};
const { execute, extInfo } = await raydium.cpmm.createPool({
const { execute } = await raydium.cpmm.createPool({
programId: CREATE_CPMM_POOL_PROGRAM,
poolFeeAccount: CREATE_CPMM_POOL_FEE_ACC,
mintA: mintFormatInfoA,
@@ -63,7 +64,7 @@ export async function raydiumCreateCpmm(
mintAAmount,
mintBAmount,
startTime,
//@ts-ignore
//@ts-expect-error sdk bug
feeConfig: { id: configId.toString() },
associatedOnly: false,
ownerInfo: {

View File

@@ -10,20 +10,20 @@ import { PublicKey } from "@solana/web3.js";
*/
export async function resolveAllDomains(
agent: SolanaAgentKit,
domain: string
domain: string,
): Promise<PublicKey | undefined> {
try {
console.log("domain", domain);
let tld = await new TldParser(agent.connection).getOwnerFromDomainTld(
domain
const 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
if (
error.message.includes(
"Cannot read properties of undefined (reading 'owner')",
)
) {
return undefined;
}
throw new Error(`Domain resolution failed: ${error.message}`);
}

View File

@@ -18,7 +18,7 @@ import {
CompressedTokenProgram,
createTokenPool,
} from "@lightprotocol/compressed-token";
import { Account, getOrCreateAssociatedTokenAccount } from "@solana/spl-token";
import { getOrCreateAssociatedTokenAccount } from "@solana/spl-token";
// arbitrary
const MAX_AIRDROP_RECIPIENTS = 1000;
@@ -80,9 +80,8 @@ export async function sendCompressedAirdrop(
);
}
let sourceTokenAccount: Account;
try {
sourceTokenAccount = await getOrCreateAssociatedTokenAccount(
await getOrCreateAssociatedTokenAccount(
agent.connection,
agent.wallet,
mintAddress,