mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-06-01 07:36:46 +00:00
feat: linting + prettier
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
|
same "printed page" as the copyright notice for easier
|
||||||
identification within third-party archives.
|
identification within third-party archives.
|
||||||
|
|
||||||
Copyright [yyyy] [name of copyright owner]
|
Copyright [2024] [SendAI]
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with 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",
|
"build": "tsc",
|
||||||
"docs": "typedoc src --out docs",
|
"docs": "typedoc src --out docs",
|
||||||
"test": "ts-node test/index.ts",
|
"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": {
|
"engines": {
|
||||||
"node": ">=23.1.0",
|
"node": ">=23.1.0",
|
||||||
@@ -16,7 +19,7 @@
|
|||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "sendaifun",
|
"author": "sendaifun",
|
||||||
"license": "ISC",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@bonfida/spl-name-service": "^3.0.7",
|
"@bonfida/spl-name-service": "^3.0.7",
|
||||||
"@coral-xyz/anchor": "0.29",
|
"@coral-xyz/anchor": "0.29",
|
||||||
@@ -54,6 +57,12 @@
|
|||||||
"@types/chai": "^5.0.1",
|
"@types/chai": "^5.0.1",
|
||||||
"@types/node": "^22.9.0",
|
"@types/node": "^22.9.0",
|
||||||
"ts-node": "^10.9.2",
|
"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
@@ -44,7 +44,6 @@ import {
|
|||||||
PumpFunTokenOptions,
|
PumpFunTokenOptions,
|
||||||
} from "../types";
|
} from "../types";
|
||||||
import { BN } from "@coral-xyz/anchor";
|
import { BN } from "@coral-xyz/anchor";
|
||||||
import { NameAccountAndDomain } from "@onsol/tldparser";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main class for interacting with Solana blockchain
|
* Main class for interacting with Solana blockchain
|
||||||
@@ -204,7 +203,7 @@ export class SolanaAgentKit {
|
|||||||
otherTokenMint: PublicKey,
|
otherTokenMint: PublicKey,
|
||||||
initialPrice: Decimal,
|
initialPrice: Decimal,
|
||||||
maxPrice: Decimal,
|
maxPrice: Decimal,
|
||||||
feeTier: keyof typeof FEE_TIERS
|
feeTier: keyof typeof FEE_TIERS,
|
||||||
) {
|
) {
|
||||||
return createOrcaSingleSidedWhirlpool(
|
return createOrcaSingleSidedWhirlpool(
|
||||||
this,
|
this,
|
||||||
@@ -213,7 +212,7 @@ export class SolanaAgentKit {
|
|||||||
otherTokenMint,
|
otherTokenMint,
|
||||||
initialPrice,
|
initialPrice,
|
||||||
maxPrice,
|
maxPrice,
|
||||||
feeTier
|
feeTier,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,18 +220,15 @@ export class SolanaAgentKit {
|
|||||||
return resolveAllDomains(this, domain);
|
return resolveAllDomains(this, domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOwnedAllDomains(
|
async getOwnedAllDomains(owner: PublicKey): Promise<string[]> {
|
||||||
owner: PublicKey
|
|
||||||
): Promise<string[]> {
|
|
||||||
return getOwnedAllDomains(this, owner);
|
return getOwnedAllDomains(this, owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOwnedDomainsForTLD(
|
async getOwnedDomainsForTLD(tld: string): Promise<string[]> {
|
||||||
tld: string
|
|
||||||
):Promise<string[]> {
|
|
||||||
return getOwnedDomainsForTLD(this, tld);
|
return getOwnedDomainsForTLD(this, tld);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
async getAllDomainsTLDs(): Promise<String[]> {
|
async getAllDomainsTLDs(): Promise<String[]> {
|
||||||
return getAllDomainsTLDs(this);
|
return getAllDomainsTLDs(this);
|
||||||
}
|
}
|
||||||
@@ -249,7 +245,7 @@ export class SolanaAgentKit {
|
|||||||
marketId: PublicKey,
|
marketId: PublicKey,
|
||||||
baseAmount: BN,
|
baseAmount: BN,
|
||||||
quoteAmount: BN,
|
quoteAmount: BN,
|
||||||
startTime: BN
|
startTime: BN,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
return raydiumCreateAmmV4(
|
return raydiumCreateAmmV4(
|
||||||
this,
|
this,
|
||||||
@@ -258,8 +254,8 @@ export class SolanaAgentKit {
|
|||||||
baseAmount,
|
baseAmount,
|
||||||
quoteAmount,
|
quoteAmount,
|
||||||
|
|
||||||
startTime
|
startTime,
|
||||||
);;
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async raydiumCreateClmm(
|
async raydiumCreateClmm(
|
||||||
@@ -267,7 +263,7 @@ export class SolanaAgentKit {
|
|||||||
mint2: PublicKey,
|
mint2: PublicKey,
|
||||||
configId: PublicKey,
|
configId: PublicKey,
|
||||||
initialPrice: Decimal,
|
initialPrice: Decimal,
|
||||||
startTime: BN
|
startTime: BN,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
return raydiumCreateClmm(
|
return raydiumCreateClmm(
|
||||||
this,
|
this,
|
||||||
@@ -285,7 +281,7 @@ export class SolanaAgentKit {
|
|||||||
configId: PublicKey,
|
configId: PublicKey,
|
||||||
mintAAmount: BN,
|
mintAAmount: BN,
|
||||||
mintBAmount: BN,
|
mintBAmount: BN,
|
||||||
startTime: BN
|
startTime: BN,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
return raydiumCreateCpmm(
|
return raydiumCreateCpmm(
|
||||||
this,
|
this,
|
||||||
@@ -295,7 +291,7 @@ export class SolanaAgentKit {
|
|||||||
mintAAmount,
|
mintAAmount,
|
||||||
mintBAmount,
|
mintBAmount,
|
||||||
|
|
||||||
startTime
|
startTime,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,7 +299,7 @@ export class SolanaAgentKit {
|
|||||||
baseMint: PublicKey,
|
baseMint: PublicKey,
|
||||||
quoteMint: PublicKey,
|
quoteMint: PublicKey,
|
||||||
lotSize: number = 1,
|
lotSize: number = 1,
|
||||||
tickSize: number = 0.01
|
tickSize: number = 0.01,
|
||||||
): Promise<string[]> {
|
): Promise<string[]> {
|
||||||
return openbookCreateMarket(
|
return openbookCreateMarket(
|
||||||
this,
|
this,
|
||||||
|
|||||||
@@ -461,7 +461,7 @@ export class SolanaPumpfunTokenLaunchTool extends Tool {
|
|||||||
try {
|
try {
|
||||||
// Parse and normalize input
|
// Parse and normalize input
|
||||||
input = input.trim();
|
input = input.trim();
|
||||||
let parsedInput = JSON.parse(input);
|
const parsedInput = JSON.parse(input);
|
||||||
|
|
||||||
this.validateInput(parsedInput);
|
this.validateInput(parsedInput);
|
||||||
|
|
||||||
@@ -543,7 +543,7 @@ export class SolanaLendAssetTool extends Tool {
|
|||||||
|
|
||||||
async _call(input: string): Promise<string> {
|
async _call(input: string): Promise<string> {
|
||||||
try {
|
try {
|
||||||
let amount = JSON.parse(input).amount || input;
|
const amount = JSON.parse(input).amount || input;
|
||||||
|
|
||||||
const tx = await this.solanaKit.lendAssets(amount);
|
const tx = await this.solanaKit.lendAssets(amount);
|
||||||
|
|
||||||
@@ -779,8 +779,8 @@ export class SolanaCreateSingleSidedWhirlpoolTool extends Tool {
|
|||||||
if (!feeTier || !(feeTier in FEE_TIERS)) {
|
if (!feeTier || !(feeTier in FEE_TIERS)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Invalid feeTier. Available options: ${Object.keys(FEE_TIERS).join(
|
`Invalid feeTier. Available options: ${Object.keys(FEE_TIERS).join(
|
||||||
", "
|
", ",
|
||||||
)}`
|
)}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -790,7 +790,7 @@ export class SolanaCreateSingleSidedWhirlpoolTool extends Tool {
|
|||||||
otherTokenMint,
|
otherTokenMint,
|
||||||
initialPrice,
|
initialPrice,
|
||||||
maxPrice,
|
maxPrice,
|
||||||
feeTier
|
feeTier,
|
||||||
);
|
);
|
||||||
|
|
||||||
return JSON.stringify({
|
return JSON.stringify({
|
||||||
@@ -825,13 +825,13 @@ export class SolanaRaydiumCreateAmmV4 extends Tool {
|
|||||||
|
|
||||||
async _call(input: string): Promise<string> {
|
async _call(input: string): Promise<string> {
|
||||||
try {
|
try {
|
||||||
let inputFormat = JSON.parse(input);
|
const inputFormat = JSON.parse(input);
|
||||||
|
|
||||||
const tx = await this.solanaKit.raydiumCreateAmmV4(
|
const tx = await this.solanaKit.raydiumCreateAmmV4(
|
||||||
new PublicKey(inputFormat.marketId),
|
new PublicKey(inputFormat.marketId),
|
||||||
new BN(inputFormat.baseAmount),
|
new BN(inputFormat.baseAmount),
|
||||||
new BN(inputFormat.quoteAmount),
|
new BN(inputFormat.quoteAmount),
|
||||||
new BN(inputFormat.startTime)
|
new BN(inputFormat.startTime),
|
||||||
);
|
);
|
||||||
|
|
||||||
return JSON.stringify({
|
return JSON.stringify({
|
||||||
@@ -867,7 +867,7 @@ export class SolanaRaydiumCreateClmm extends Tool {
|
|||||||
|
|
||||||
async _call(input: string): Promise<string> {
|
async _call(input: string): Promise<string> {
|
||||||
try {
|
try {
|
||||||
let inputFormat = JSON.parse(input);
|
const inputFormat = JSON.parse(input);
|
||||||
|
|
||||||
const tx = await this.solanaKit.raydiumCreateClmm(
|
const tx = await this.solanaKit.raydiumCreateClmm(
|
||||||
new PublicKey(inputFormat.mint1),
|
new PublicKey(inputFormat.mint1),
|
||||||
@@ -876,7 +876,7 @@ export class SolanaRaydiumCreateClmm extends Tool {
|
|||||||
new PublicKey(inputFormat.configId),
|
new PublicKey(inputFormat.configId),
|
||||||
|
|
||||||
new Decimal(inputFormat.initialPrice),
|
new Decimal(inputFormat.initialPrice),
|
||||||
new BN(inputFormat.startTime)
|
new BN(inputFormat.startTime),
|
||||||
);
|
);
|
||||||
|
|
||||||
return JSON.stringify({
|
return JSON.stringify({
|
||||||
@@ -913,7 +913,7 @@ export class SolanaRaydiumCreateCpmm extends Tool {
|
|||||||
|
|
||||||
async _call(input: string): Promise<string> {
|
async _call(input: string): Promise<string> {
|
||||||
try {
|
try {
|
||||||
let inputFormat = JSON.parse(input);
|
const inputFormat = JSON.parse(input);
|
||||||
|
|
||||||
const tx = await this.solanaKit.raydiumCreateCpmm(
|
const tx = await this.solanaKit.raydiumCreateCpmm(
|
||||||
new PublicKey(inputFormat.mint1),
|
new PublicKey(inputFormat.mint1),
|
||||||
@@ -924,7 +924,7 @@ export class SolanaRaydiumCreateCpmm extends Tool {
|
|||||||
new BN(inputFormat.mintAAmount),
|
new BN(inputFormat.mintAAmount),
|
||||||
new BN(inputFormat.mintBAmount),
|
new BN(inputFormat.mintBAmount),
|
||||||
|
|
||||||
new BN(inputFormat.startTime)
|
new BN(inputFormat.startTime),
|
||||||
);
|
);
|
||||||
|
|
||||||
return JSON.stringify({
|
return JSON.stringify({
|
||||||
@@ -959,14 +959,14 @@ export class SolanaOpenbookCreateMarket extends Tool {
|
|||||||
|
|
||||||
async _call(input: string): Promise<string> {
|
async _call(input: string): Promise<string> {
|
||||||
try {
|
try {
|
||||||
let inputFormat = JSON.parse(input);
|
const inputFormat = JSON.parse(input);
|
||||||
|
|
||||||
const tx = await this.solanaKit.openbookCreateMarket(
|
const tx = await this.solanaKit.openbookCreateMarket(
|
||||||
new PublicKey(inputFormat.baseMint),
|
new PublicKey(inputFormat.baseMint),
|
||||||
new PublicKey(inputFormat.quoteMint),
|
new PublicKey(inputFormat.quoteMint),
|
||||||
|
|
||||||
inputFormat.lotSize,
|
inputFormat.lotSize,
|
||||||
inputFormat.tickSize
|
inputFormat.tickSize,
|
||||||
);
|
);
|
||||||
|
|
||||||
return JSON.stringify({
|
return JSON.stringify({
|
||||||
@@ -998,14 +998,14 @@ export class SolanaPythFetchPrice extends Tool {
|
|||||||
async _call(input: string): Promise<string> {
|
async _call(input: string): Promise<string> {
|
||||||
try {
|
try {
|
||||||
const price = await this.solanaKit.pythFetchPrice(input);
|
const price = await this.solanaKit.pythFetchPrice(input);
|
||||||
let response: PythFetchPriceResponse = {
|
const response: PythFetchPriceResponse = {
|
||||||
status: "success",
|
status: "success",
|
||||||
priceFeedID: input,
|
priceFeedID: input,
|
||||||
price: price,
|
price: price,
|
||||||
};
|
};
|
||||||
return JSON.stringify(response);
|
return JSON.stringify(response);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
let response: PythFetchPriceResponse = {
|
const response: PythFetchPriceResponse = {
|
||||||
status: "error",
|
status: "error",
|
||||||
priceFeedID: input,
|
priceFeedID: input,
|
||||||
message: error.message,
|
message: error.message,
|
||||||
@@ -1033,7 +1033,7 @@ export class SolanaResolveAllDomainsTool extends Tool {
|
|||||||
try {
|
try {
|
||||||
const owner = await this.solanaKit.resolveAllDomains(input);
|
const owner = await this.solanaKit.resolveAllDomains(input);
|
||||||
|
|
||||||
if(!owner) {
|
if (!owner) {
|
||||||
return JSON.stringify({
|
return JSON.stringify({
|
||||||
status: "error",
|
status: "error",
|
||||||
message: "Domain not found",
|
message: "Domain not found",
|
||||||
@@ -1056,7 +1056,6 @@ export class SolanaResolveAllDomainsTool extends Tool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export class SolanaGetOwnedDomains extends Tool {
|
export class SolanaGetOwnedDomains extends Tool {
|
||||||
name = "solana_get_owned_domains";
|
name = "solana_get_owned_domains";
|
||||||
description = `Get all domains owned by a specific wallet address.
|
description = `Get all domains owned by a specific wallet address.
|
||||||
@@ -1088,7 +1087,6 @@ export class SolanaGetOwnedDomains extends Tool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export class SolanaGetOwnedTldDomains extends Tool {
|
export class SolanaGetOwnedTldDomains extends Tool {
|
||||||
name = "solana_get_owned_tld_domains";
|
name = "solana_get_owned_tld_domains";
|
||||||
description = `Get all domains owned by the agent's wallet for a specific TLD.
|
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 {
|
export class SolanaGetAllTlds extends Tool {
|
||||||
name = "solana_get_all_tlds";
|
name = "solana_get_all_tlds";
|
||||||
description = `Get all active top-level domains (TLDs) in the AllDomains Name Service`;
|
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 {
|
export class SolanaGetMainDomain extends Tool {
|
||||||
name = "solana_get_main_domain";
|
name = "solana_get_main_domain";
|
||||||
description = `Get the main/favorite domain for a given wallet address.
|
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> {
|
async _call(input: string): Promise<string> {
|
||||||
try {
|
try {
|
||||||
const ownerPubkey = new PublicKey(input.trim());
|
const ownerPubkey = new PublicKey(input.trim());
|
||||||
const mainDomain = await this.solanaKit.getMainAllDomainsDomain(
|
const mainDomain =
|
||||||
ownerPubkey
|
await this.solanaKit.getMainAllDomainsDomain(ownerPubkey);
|
||||||
);
|
|
||||||
|
|
||||||
return JSON.stringify({
|
return JSON.stringify({
|
||||||
status: "success",
|
status: "success",
|
||||||
|
|||||||
@@ -157,8 +157,9 @@ export async function createOrcaSingleSidedWhirlpool(
|
|||||||
}
|
}
|
||||||
const mintAAccount = await fetcher.getMintInfo(mintA);
|
const mintAAccount = await fetcher.getMintInfo(mintA);
|
||||||
const mintBAccount = await fetcher.getMintInfo(mintB);
|
const mintBAccount = await fetcher.getMintInfo(mintB);
|
||||||
if (mintAAccount === null || mintBAccount === null)
|
if (mintAAccount === null || mintBAccount === null) {
|
||||||
throw Error("Mint account not found");
|
throw Error("Mint account not found");
|
||||||
|
}
|
||||||
const tickSpacing = FEE_TIERS[feeTier];
|
const tickSpacing = FEE_TIERS[feeTier];
|
||||||
const tickIndex = PriceMath.priceToTickIndex(
|
const tickIndex = PriceMath.priceToTickIndex(
|
||||||
initialPrice,
|
initialPrice,
|
||||||
@@ -273,8 +274,9 @@ export async function createOrcaSingleSidedWhirlpool(
|
|||||||
if (
|
if (
|
||||||
!TickUtil.checkTickInBounds(tickLowerInitializableIndex) ||
|
!TickUtil.checkTickInBounds(tickLowerInitializableIndex) ||
|
||||||
!TickUtil.checkTickInBounds(tickUpperInitializableIndex)
|
!TickUtil.checkTickInBounds(tickUpperInitializableIndex)
|
||||||
)
|
) {
|
||||||
throw Error("Prices out of bounds");
|
throw Error("Prices out of bounds");
|
||||||
|
}
|
||||||
const increasLiquidityQuoteParam: IncreaseLiquidityQuoteParam = {
|
const increasLiquidityQuoteParam: IncreaseLiquidityQuoteParam = {
|
||||||
inputTokenAmount: new BN(depositTokenAmount),
|
inputTokenAmount: new BN(depositTokenAmount),
|
||||||
inputTokenMint: depositTokenMint,
|
inputTokenMint: depositTokenMint,
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { Connection, PublicKey } from "@solana/web3.js";
|
|
||||||
import { SolanaAgentKit } from "../index";
|
import { SolanaAgentKit } from "../index";
|
||||||
import { getAllTld } from "@onsol/tldparser";
|
import { getAllTld } from "@onsol/tldparser";
|
||||||
|
|
||||||
@@ -8,11 +7,12 @@ import { getAllTld } from "@onsol/tldparser";
|
|||||||
* @returns Array of active TLD strings
|
* @returns Array of active TLD strings
|
||||||
*/
|
*/
|
||||||
export async function getAllDomainsTLDs(
|
export async function getAllDomainsTLDs(
|
||||||
agent: SolanaAgentKit
|
agent: SolanaAgentKit,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
): Promise<String[]> {
|
): Promise<String[]> {
|
||||||
try {
|
try {
|
||||||
let tlds = await getAllTld(agent.connection)
|
const tlds = await getAllTld(agent.connection);
|
||||||
return tlds.map((tld) => tld.tld)
|
return tlds.map((tld) => tld.tld);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
throw new Error(`Failed to fetch TLDs: ${error.message}`);
|
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
|
* @returns Array of all registered domain names with their TLDs
|
||||||
*/
|
*/
|
||||||
export async function getAllRegisteredAllDomains(
|
export async function getAllRegisteredAllDomains(
|
||||||
agent: SolanaAgentKit
|
agent: SolanaAgentKit,
|
||||||
): Promise<string[]> {
|
): Promise<string[]> {
|
||||||
try {
|
try {
|
||||||
// First get all TLDs
|
// First get all TLDs
|
||||||
@@ -20,7 +20,7 @@ export async function getAllRegisteredAllDomains(
|
|||||||
for (const tld of tlds) {
|
for (const tld of tlds) {
|
||||||
const domains = await getAllDomains(
|
const domains = await getAllDomains(
|
||||||
agent.connection,
|
agent.connection,
|
||||||
new PublicKey("namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX")
|
new PublicKey("namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX"),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add domains with TLD suffix
|
// Add domains with TLD suffix
|
||||||
|
|||||||
@@ -11,11 +11,12 @@ export async function get_balance(
|
|||||||
agent: SolanaAgentKit,
|
agent: SolanaAgentKit,
|
||||||
token_address?: PublicKey,
|
token_address?: PublicKey,
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
if (!token_address)
|
if (!token_address) {
|
||||||
return (
|
return (
|
||||||
(await agent.connection.getBalance(agent.wallet_address)) /
|
(await agent.connection.getBalance(agent.wallet_address)) /
|
||||||
LAMPORTS_PER_SOL
|
LAMPORTS_PER_SOL
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const token_account =
|
const token_account =
|
||||||
await agent.connection.getTokenAccountBalance(token_address);
|
await agent.connection.getTokenAccountBalance(token_address);
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { getFavoriteDomain as _getFavoriteDomain } from "@bonfida/spl-name-service";
|
import { getFavoriteDomain as _getFavoriteDomain } from "@bonfida/spl-name-service";
|
||||||
import { PublicKey } from "@solana/web3.js";
|
import { PublicKey } from "@solana/web3.js";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the user's main/favorite domain for a SolanaAgentKit instance
|
* Get the user's main/favorite domain for a SolanaAgentKit instance
|
||||||
* @param agent SolanaAgentKit instance
|
* @param agent SolanaAgentKit instance
|
||||||
@@ -10,15 +9,13 @@ import { PublicKey } from "@solana/web3.js";
|
|||||||
*/
|
*/
|
||||||
export async function getMainAllDomainsDomain(
|
export async function getMainAllDomainsDomain(
|
||||||
agent: any,
|
agent: any,
|
||||||
owner: PublicKey
|
owner: PublicKey,
|
||||||
): Promise<string | null> {
|
): Promise<string | null> {
|
||||||
let mainDomain = null;
|
let mainDomain = null;
|
||||||
try {
|
try {
|
||||||
mainDomain = await _getFavoriteDomain(agent.connection, owner);
|
mainDomain = await _getFavoriteDomain(agent.connection, owner);
|
||||||
return mainDomain.stale ? null : mainDomain.reverse;
|
return mainDomain.stale ? null : mainDomain.reverse;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log("No main/favorite domain found");
|
return null;
|
||||||
}
|
}
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { SolanaAgentKit } from "../agent";
|
import { SolanaAgentKit } from "../agent";
|
||||||
import { PublicKey } from "@solana/web3.js";
|
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
|
* 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(
|
export async function getOwnedAllDomains(
|
||||||
agent: SolanaAgentKit,
|
agent: SolanaAgentKit,
|
||||||
owner:PublicKey
|
owner: PublicKey,
|
||||||
): Promise<string[]> {
|
): Promise<string[]> {
|
||||||
try {
|
try {
|
||||||
let domains = await new TldParser(agent.connection).getParsedAllUserDomains(owner);
|
const domains = await new TldParser(
|
||||||
return domains.map((domain) => domain.domain)
|
agent.connection,
|
||||||
|
).getParsedAllUserDomains(owner);
|
||||||
|
return domains.map((domain) => domain.domain);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
throw new Error(`Failed to fetch owned domains: ${error.message}`);
|
throw new Error(`Failed to fetch owned domains: ${error.message}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,18 +8,14 @@ import { SolanaAgentKit } from "../agent";
|
|||||||
*/
|
*/
|
||||||
export async function getOwnedDomainsForTLD(
|
export async function getOwnedDomainsForTLD(
|
||||||
agent: SolanaAgentKit,
|
agent: SolanaAgentKit,
|
||||||
tld: string
|
tld: string,
|
||||||
): Promise<string[]> {
|
): Promise<string[]> {
|
||||||
try {
|
try {
|
||||||
let domains = await new TldParser(agent.connection)
|
const domains = await new TldParser(
|
||||||
.getParsedAllUserDomainsFromTld(
|
agent.connection,
|
||||||
agent.wallet_address,
|
).getParsedAllUserDomainsFromTld(agent.wallet_address, tld);
|
||||||
tld
|
return domains.map((domain) => domain.domain);
|
||||||
)
|
|
||||||
return domains.map((domain) => domain.domain)
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
throw new Error(`Failed to fetch domains for TLD: ${error.message}`);
|
throw new Error(`Failed to fetch domains for TLD: ${error.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ export async function getTokenDataByAddress(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getTokenAddressFromTicker(
|
export async function getTokenAddressFromTicker(
|
||||||
ticker: string
|
ticker: string,
|
||||||
): Promise<string | null> {
|
): Promise<string | null> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
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();
|
const data = await response.json();
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ export async function getTokenAddressFromTicker(
|
|||||||
|
|
||||||
solanaPairs = solanaPairs.filter(
|
solanaPairs = solanaPairs.filter(
|
||||||
(pair: any) =>
|
(pair: any) =>
|
||||||
pair.baseToken.symbol.toLowerCase() === ticker.toLowerCase()
|
pair.baseToken.symbol.toLowerCase() === ticker.toLowerCase(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Return the address of the highest FDV Solana pair
|
// Return the address of the highest FDV Solana pair
|
||||||
@@ -58,7 +58,7 @@ export async function getTokenAddressFromTicker(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getTokenDataByTicker(
|
export async function getTokenDataByTicker(
|
||||||
ticker: string
|
ticker: string,
|
||||||
): Promise<JupiterTokenData | undefined> {
|
): Promise<JupiterTokenData | undefined> {
|
||||||
const address = await getTokenAddressFromTicker(ticker);
|
const address = await getTokenAddressFromTicker(ticker);
|
||||||
if (!address) {
|
if (!address) {
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ export * from "./get_main_all_domains_domain";
|
|||||||
export * from "./get_owned_all_domains";
|
export * from "./get_owned_all_domains";
|
||||||
export * from "./resolve_domain";
|
export * from "./resolve_domain";
|
||||||
|
|
||||||
|
|
||||||
export * from "./get_all_domains_tlds";
|
export * from "./get_all_domains_tlds";
|
||||||
export * from "./get_all_registered_all_domains";
|
export * from "./get_all_registered_all_domains";
|
||||||
export * from "./get_owned_domains_for_tld";
|
export * from "./get_owned_domains_for_tld";
|
||||||
|
|||||||
@@ -21,9 +21,15 @@ async function uploadMetadata(
|
|||||||
|
|
||||||
formData.append("showName", "true");
|
formData.append("showName", "true");
|
||||||
|
|
||||||
if (options?.twitter) formData.append("twitter", options.twitter);
|
if (options?.twitter) {
|
||||||
if (options?.telegram) formData.append("telegram", options.telegram);
|
formData.append("twitter", options.twitter);
|
||||||
if (options?.website) formData.append("website", options.website);
|
}
|
||||||
|
if (options?.telegram) {
|
||||||
|
formData.append("telegram", options.telegram);
|
||||||
|
}
|
||||||
|
if (options?.website) {
|
||||||
|
formData.append("website", options.website);
|
||||||
|
}
|
||||||
|
|
||||||
const imageResponse = await fetch(imageUrl);
|
const imageResponse = await fetch(imageUrl);
|
||||||
const imageBlob = await imageResponse.blob();
|
const imageBlob = await imageResponse.blob();
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ export async function pythFetchPrice(priceFeedID: string): Promise<string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get price and exponent from price feed
|
// get price and exponent from price feed
|
||||||
let price = new BN(currentPrice[0].getPriceUnchecked().price);
|
const price = new BN(currentPrice[0].getPriceUnchecked().price);
|
||||||
let exponent = new BN(currentPrice[0].getPriceUnchecked().expo);
|
const exponent = new BN(currentPrice[0].getPriceUnchecked().expo);
|
||||||
|
|
||||||
// convert to scaled price
|
// 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();
|
return scaledPrice.toString();
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
|||||||
@@ -25,8 +25,9 @@ export async function raydiumCreateClmm(
|
|||||||
const [mintInfo1, mintInfo2] = await agent.connection.getMultipleAccountsInfo(
|
const [mintInfo1, mintInfo2] = await agent.connection.getMultipleAccountsInfo(
|
||||||
[mint1, mint2],
|
[mint1, mint2],
|
||||||
);
|
);
|
||||||
if (mintInfo1 === null || mintInfo2 === null)
|
if (mintInfo1 === null || mintInfo2 === null) {
|
||||||
throw Error("fetch mint info error");
|
throw Error("fetch mint info error");
|
||||||
|
}
|
||||||
|
|
||||||
const mintDecodeInfo1 = MintLayout.decode(mintInfo1.data);
|
const mintDecodeInfo1 = MintLayout.decode(mintInfo1.data);
|
||||||
const mintDecodeInfo2 = MintLayout.decode(mintInfo2.data);
|
const mintDecodeInfo2 = MintLayout.decode(mintInfo2.data);
|
||||||
@@ -59,7 +60,7 @@ export async function raydiumCreateClmm(
|
|||||||
// programId: DEVNET_PROGRAM_ID.CLMM,
|
// programId: DEVNET_PROGRAM_ID.CLMM,
|
||||||
mint1: mintFormatInfo1,
|
mint1: mintFormatInfo1,
|
||||||
mint2: mintFormatInfo2,
|
mint2: mintFormatInfo2,
|
||||||
// @ts-ignore
|
// @ts-expect-error sdk bug
|
||||||
ammConfig: { id: configId },
|
ammConfig: { id: configId },
|
||||||
initialPrice,
|
initialPrice,
|
||||||
startTime,
|
startTime,
|
||||||
|
|||||||
@@ -26,8 +26,9 @@ export async function raydiumCreateCpmm(
|
|||||||
const [mintInfoA, mintInfoB] = await agent.connection.getMultipleAccountsInfo(
|
const [mintInfoA, mintInfoB] = await agent.connection.getMultipleAccountsInfo(
|
||||||
[mintA, mintB],
|
[mintA, mintB],
|
||||||
);
|
);
|
||||||
if (mintInfoA === null || mintInfoB === null)
|
if (mintInfoA === null || mintInfoB === null) {
|
||||||
throw Error("fetch mint info error");
|
throw Error("fetch mint info error");
|
||||||
|
}
|
||||||
|
|
||||||
const mintDecodeInfoA = MintLayout.decode(mintInfoA.data);
|
const mintDecodeInfoA = MintLayout.decode(mintInfoA.data);
|
||||||
const mintDecodeInfoB = MintLayout.decode(mintInfoB.data);
|
const mintDecodeInfoB = MintLayout.decode(mintInfoB.data);
|
||||||
@@ -55,7 +56,7 @@ export async function raydiumCreateCpmm(
|
|||||||
extensions: {},
|
extensions: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
const { execute, extInfo } = await raydium.cpmm.createPool({
|
const { execute } = await raydium.cpmm.createPool({
|
||||||
programId: CREATE_CPMM_POOL_PROGRAM,
|
programId: CREATE_CPMM_POOL_PROGRAM,
|
||||||
poolFeeAccount: CREATE_CPMM_POOL_FEE_ACC,
|
poolFeeAccount: CREATE_CPMM_POOL_FEE_ACC,
|
||||||
mintA: mintFormatInfoA,
|
mintA: mintFormatInfoA,
|
||||||
@@ -63,7 +64,7 @@ export async function raydiumCreateCpmm(
|
|||||||
mintAAmount,
|
mintAAmount,
|
||||||
mintBAmount,
|
mintBAmount,
|
||||||
startTime,
|
startTime,
|
||||||
//@ts-ignore
|
//@ts-expect-error sdk bug
|
||||||
feeConfig: { id: configId.toString() },
|
feeConfig: { id: configId.toString() },
|
||||||
associatedOnly: false,
|
associatedOnly: false,
|
||||||
ownerInfo: {
|
ownerInfo: {
|
||||||
|
|||||||
@@ -10,20 +10,20 @@ import { PublicKey } from "@solana/web3.js";
|
|||||||
*/
|
*/
|
||||||
export async function resolveAllDomains(
|
export async function resolveAllDomains(
|
||||||
agent: SolanaAgentKit,
|
agent: SolanaAgentKit,
|
||||||
domain: string
|
domain: string,
|
||||||
): Promise<PublicKey | undefined> {
|
): Promise<PublicKey | undefined> {
|
||||||
try {
|
try {
|
||||||
console.log("domain", domain);
|
const tld = await new TldParser(agent.connection).getOwnerFromDomainTld(
|
||||||
let tld = await new TldParser(agent.connection).getOwnerFromDomainTld(
|
domain,
|
||||||
domain
|
|
||||||
);
|
);
|
||||||
console.log("tld", tld);
|
|
||||||
return tld;
|
return tld;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
// console.log("error", error.);
|
if (
|
||||||
|
error.message.includes(
|
||||||
if(error.message.includes("Cannot read properties of undefined (reading 'owner')")) {
|
"Cannot read properties of undefined (reading 'owner')",
|
||||||
return undefined
|
)
|
||||||
|
) {
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
throw new Error(`Domain resolution failed: ${error.message}`);
|
throw new Error(`Domain resolution failed: ${error.message}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import {
|
|||||||
CompressedTokenProgram,
|
CompressedTokenProgram,
|
||||||
createTokenPool,
|
createTokenPool,
|
||||||
} from "@lightprotocol/compressed-token";
|
} from "@lightprotocol/compressed-token";
|
||||||
import { Account, getOrCreateAssociatedTokenAccount } from "@solana/spl-token";
|
import { getOrCreateAssociatedTokenAccount } from "@solana/spl-token";
|
||||||
|
|
||||||
// arbitrary
|
// arbitrary
|
||||||
const MAX_AIRDROP_RECIPIENTS = 1000;
|
const MAX_AIRDROP_RECIPIENTS = 1000;
|
||||||
@@ -80,9 +80,8 @@ export async function sendCompressedAirdrop(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let sourceTokenAccount: Account;
|
|
||||||
try {
|
try {
|
||||||
sourceTokenAccount = await getOrCreateAssociatedTokenAccount(
|
await getOrCreateAssociatedTokenAccount(
|
||||||
agent.connection,
|
agent.connection,
|
||||||
agent.wallet,
|
agent.wallet,
|
||||||
mintAddress,
|
mintAddress,
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ export async function sendTx(
|
|||||||
}
|
}
|
||||||
|
|
||||||
tx.sign(agent.wallet, ...(otherKeypairs ?? []));
|
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({
|
await agent.connection.confirmTransaction({
|
||||||
signature: txid,
|
signature: txid,
|
||||||
blockhash: (await agent.connection.getLatestBlockhash()).blockhash,
|
blockhash: (await agent.connection.getLatestBlockhash()).blockhash,
|
||||||
|
|||||||
Reference in New Issue
Block a user