mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-13 23:16:55 +00:00
Merge branch 'main' into gib-bounty-sol062217
This commit is contained in:
40
.eslintrc
Normal file
40
.eslintrc
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": ["@typescript-eslint", "prettier"],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"prettier"
|
||||
],
|
||||
"rules": {
|
||||
"prettier/prettier": "error",
|
||||
"no-constant-condition": "off",
|
||||
"@typescript-eslint/explicit-function-return-type": "off",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }],
|
||||
"no-console": ["warn", { "allow": ["warn", "error"] }],
|
||||
"curly": ["error", "all"],
|
||||
"eqeqeq": ["error", "always"],
|
||||
"no-floating-decimal": "error",
|
||||
"no-var": "error",
|
||||
"prefer-const": "error"
|
||||
},
|
||||
"env": {
|
||||
"browser": true,
|
||||
"node": true,
|
||||
"es6": true
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2020,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["test/**/*", "src/utils/keypair.ts"],
|
||||
"rules": {
|
||||
"no-console": "off"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
4
.prettierignore
Normal file
4
.prettierignore
Normal file
@@ -0,0 +1,4 @@
|
||||
dist
|
||||
node_modules
|
||||
docs
|
||||
*.md
|
||||
12
.prettierrc
Normal file
12
.prettierrc
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"semi": true,
|
||||
"trailingComma": "all",
|
||||
"singleQuote": false,
|
||||
"printWidth": 80,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"bracketSpacing": true,
|
||||
"arrowParens": "always",
|
||||
"endOfLine": "lf",
|
||||
"bracketSameLine": false
|
||||
}
|
||||
2
LICENSE
2
LICENSE
@@ -186,7 +186,7 @@
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
Copyright [2024] [SendAI]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
15
package.json
15
package.json
@@ -8,7 +8,10 @@
|
||||
"build": "tsc",
|
||||
"docs": "typedoc src --out docs",
|
||||
"test": "ts-node test/index.ts",
|
||||
"generate": "ts-node src/utils/keypair.ts"
|
||||
"generate": "ts-node src/utils/keypair.ts",
|
||||
"lint": "eslint . --ext .ts",
|
||||
"lint:fix": "eslint . --ext .ts --fix",
|
||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\""
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=23.1.0",
|
||||
@@ -16,7 +19,7 @@
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "sendaifun",
|
||||
"license": "ISC",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@bonfida/spl-name-service": "^3.0.7",
|
||||
"@coral-xyz/anchor": "0.29",
|
||||
@@ -54,6 +57,12 @@
|
||||
"@types/chai": "^5.0.1",
|
||||
"@types/node": "^22.9.0",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.7.2"
|
||||
"typescript": "^5.7.2",
|
||||
"eslint": "^8.56.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-prettier": "^5.1.3",
|
||||
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
||||
"@typescript-eslint/parser": "^7.0.0",
|
||||
"prettier": "^3.2.5"
|
||||
}
|
||||
}
|
||||
|
||||
1039
pnpm-lock.yaml
generated
1039
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -46,7 +46,6 @@ import {
|
||||
PumpFunTokenOptions,
|
||||
} from "../types";
|
||||
import { BN } from "@coral-xyz/anchor";
|
||||
import { NameAccountAndDomain } from "@onsol/tldparser";
|
||||
|
||||
/**
|
||||
* Main class for interacting with Solana blockchain
|
||||
@@ -206,7 +205,7 @@ export class SolanaAgentKit {
|
||||
otherTokenMint: PublicKey,
|
||||
initialPrice: Decimal,
|
||||
maxPrice: Decimal,
|
||||
feeTier: keyof typeof FEE_TIERS
|
||||
feeTier: keyof typeof FEE_TIERS,
|
||||
) {
|
||||
return createOrcaSingleSidedWhirlpool(
|
||||
this,
|
||||
@@ -215,7 +214,7 @@ export class SolanaAgentKit {
|
||||
otherTokenMint,
|
||||
initialPrice,
|
||||
maxPrice,
|
||||
feeTier
|
||||
feeTier,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -223,18 +222,15 @@ export class SolanaAgentKit {
|
||||
return resolveAllDomains(this, domain);
|
||||
}
|
||||
|
||||
async getOwnedAllDomains(
|
||||
owner: PublicKey
|
||||
): Promise<string[]> {
|
||||
async getOwnedAllDomains(owner: PublicKey): Promise<string[]> {
|
||||
return getOwnedAllDomains(this, owner);
|
||||
}
|
||||
|
||||
async getOwnedDomainsForTLD(
|
||||
tld: string
|
||||
): Promise<string[]> {
|
||||
async getOwnedDomainsForTLD(tld: string): Promise<string[]> {
|
||||
return getOwnedDomainsForTLD(this, tld);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
async getAllDomainsTLDs(): Promise<String[]> {
|
||||
return getAllDomainsTLDs(this);
|
||||
}
|
||||
@@ -251,7 +247,7 @@ export class SolanaAgentKit {
|
||||
marketId: PublicKey,
|
||||
baseAmount: BN,
|
||||
quoteAmount: BN,
|
||||
startTime: BN
|
||||
startTime: BN,
|
||||
): Promise<string> {
|
||||
return raydiumCreateAmmV4(
|
||||
this,
|
||||
@@ -260,8 +256,8 @@ export class SolanaAgentKit {
|
||||
baseAmount,
|
||||
quoteAmount,
|
||||
|
||||
startTime
|
||||
);;
|
||||
startTime,
|
||||
);
|
||||
}
|
||||
|
||||
async raydiumCreateClmm(
|
||||
@@ -269,7 +265,7 @@ export class SolanaAgentKit {
|
||||
mint2: PublicKey,
|
||||
configId: PublicKey,
|
||||
initialPrice: Decimal,
|
||||
startTime: BN
|
||||
startTime: BN,
|
||||
): Promise<string> {
|
||||
return raydiumCreateClmm(
|
||||
this,
|
||||
@@ -287,7 +283,7 @@ export class SolanaAgentKit {
|
||||
configId: PublicKey,
|
||||
mintAAmount: BN,
|
||||
mintBAmount: BN,
|
||||
startTime: BN
|
||||
startTime: BN,
|
||||
): Promise<string> {
|
||||
return raydiumCreateCpmm(
|
||||
this,
|
||||
@@ -297,7 +293,7 @@ export class SolanaAgentKit {
|
||||
mintAAmount,
|
||||
mintBAmount,
|
||||
|
||||
startTime
|
||||
startTime,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -305,7 +301,7 @@ export class SolanaAgentKit {
|
||||
baseMint: PublicKey,
|
||||
quoteMint: PublicKey,
|
||||
lotSize: number = 1,
|
||||
tickSize: number = 0.01
|
||||
tickSize: number = 0.01,
|
||||
): Promise<string[]> {
|
||||
return openbookCreateMarket(
|
||||
this,
|
||||
|
||||
@@ -461,7 +461,7 @@ export class SolanaPumpfunTokenLaunchTool extends Tool {
|
||||
try {
|
||||
// Parse and normalize input
|
||||
input = input.trim();
|
||||
let parsedInput = JSON.parse(input);
|
||||
const parsedInput = JSON.parse(input);
|
||||
|
||||
this.validateInput(parsedInput);
|
||||
|
||||
@@ -543,7 +543,7 @@ export class SolanaLendAssetTool extends Tool {
|
||||
|
||||
async _call(input: string): Promise<string> {
|
||||
try {
|
||||
let amount = JSON.parse(input).amount || input;
|
||||
const amount = JSON.parse(input).amount || input;
|
||||
|
||||
const tx = await this.solanaKit.lendAssets(amount);
|
||||
|
||||
@@ -779,8 +779,8 @@ export class SolanaCreateSingleSidedWhirlpoolTool extends Tool {
|
||||
if (!feeTier || !(feeTier in FEE_TIERS)) {
|
||||
throw new Error(
|
||||
`Invalid feeTier. Available options: ${Object.keys(FEE_TIERS).join(
|
||||
", "
|
||||
)}`
|
||||
", ",
|
||||
)}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -790,7 +790,7 @@ export class SolanaCreateSingleSidedWhirlpoolTool extends Tool {
|
||||
otherTokenMint,
|
||||
initialPrice,
|
||||
maxPrice,
|
||||
feeTier
|
||||
feeTier,
|
||||
);
|
||||
|
||||
return JSON.stringify({
|
||||
@@ -825,13 +825,13 @@ export class SolanaRaydiumCreateAmmV4 extends Tool {
|
||||
|
||||
async _call(input: string): Promise<string> {
|
||||
try {
|
||||
let inputFormat = JSON.parse(input);
|
||||
const 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({
|
||||
@@ -867,7 +867,7 @@ export class SolanaRaydiumCreateClmm extends Tool {
|
||||
|
||||
async _call(input: string): Promise<string> {
|
||||
try {
|
||||
let inputFormat = JSON.parse(input);
|
||||
const inputFormat = JSON.parse(input);
|
||||
|
||||
const tx = await this.solanaKit.raydiumCreateClmm(
|
||||
new PublicKey(inputFormat.mint1),
|
||||
@@ -876,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({
|
||||
@@ -913,7 +913,7 @@ export class SolanaRaydiumCreateCpmm extends Tool {
|
||||
|
||||
async _call(input: string): Promise<string> {
|
||||
try {
|
||||
let inputFormat = JSON.parse(input);
|
||||
const inputFormat = JSON.parse(input);
|
||||
|
||||
const tx = await this.solanaKit.raydiumCreateCpmm(
|
||||
new PublicKey(inputFormat.mint1),
|
||||
@@ -924,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({
|
||||
@@ -959,14 +959,14 @@ export class SolanaOpenbookCreateMarket extends Tool {
|
||||
|
||||
async _call(input: string): Promise<string> {
|
||||
try {
|
||||
let inputFormat = JSON.parse(input);
|
||||
const 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({
|
||||
@@ -998,14 +998,14 @@ export class SolanaPythFetchPrice extends Tool {
|
||||
async _call(input: string): Promise<string> {
|
||||
try {
|
||||
const price = await this.solanaKit.pythFetchPrice(input);
|
||||
let response: PythFetchPriceResponse = {
|
||||
const response: PythFetchPriceResponse = {
|
||||
status: "success",
|
||||
priceFeedID: input,
|
||||
price: price,
|
||||
};
|
||||
return JSON.stringify(response);
|
||||
} catch (error: any) {
|
||||
let response: PythFetchPriceResponse = {
|
||||
const response: PythFetchPriceResponse = {
|
||||
status: "error",
|
||||
priceFeedID: input,
|
||||
message: error.message,
|
||||
@@ -1033,7 +1033,7 @@ export class SolanaResolveAllDomainsTool extends Tool {
|
||||
try {
|
||||
const owner = await this.solanaKit.resolveAllDomains(input);
|
||||
|
||||
if(!owner) {
|
||||
if (!owner) {
|
||||
return JSON.stringify({
|
||||
status: "error",
|
||||
message: "Domain not found",
|
||||
@@ -1056,7 +1056,6 @@ 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.
|
||||
@@ -1088,7 +1087,6 @@ 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.
|
||||
@@ -1119,7 +1117,6 @@ 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 AllDomains Name Service`;
|
||||
@@ -1147,7 +1144,6 @@ export class SolanaGetAllTlds extends Tool {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class SolanaGetMainDomain extends Tool {
|
||||
name = "solana_get_main_domain";
|
||||
description = `Get the main/favorite domain for a given wallet address.
|
||||
@@ -1162,9 +1158,8 @@ export class SolanaGetMainDomain extends Tool {
|
||||
async _call(input: string): Promise<string> {
|
||||
try {
|
||||
const ownerPubkey = new PublicKey(input.trim());
|
||||
const mainDomain = await this.solanaKit.getMainAllDomainsDomain(
|
||||
ownerPubkey
|
||||
);
|
||||
const mainDomain =
|
||||
await this.solanaKit.getMainAllDomainsDomain(ownerPubkey);
|
||||
|
||||
return JSON.stringify({
|
||||
status: "success",
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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}`);
|
||||
}
|
||||
|
||||
@@ -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}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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}`);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -4,4 +4,4 @@ import bs58 from "bs58";
|
||||
export const keypair = Keypair.generate();
|
||||
|
||||
console.log(keypair.publicKey.toString());
|
||||
console.log(bs58.encode(keypair.secretKey));
|
||||
console.log(bs58.encode(keypair.secretKey));
|
||||
|
||||
@@ -86,7 +86,7 @@ export async function sendTx(
|
||||
}
|
||||
|
||||
tx.sign(agent.wallet, ...(otherKeypairs ?? []));
|
||||
let txid = await agent.connection.sendRawTransaction(tx.serialize());
|
||||
const txid = await agent.connection.sendRawTransaction(tx.serialize());
|
||||
await agent.connection.confirmTransaction({
|
||||
signature: txid,
|
||||
blockhash: (await agent.connection.getLatestBlockhash()).blockhash,
|
||||
|
||||
Reference in New Issue
Block a user