mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-19 07:36:46 +00:00
add create market func and update description
This commit is contained in:
@@ -1,25 +1,26 @@
|
||||
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import bs58 from "bs58";
|
||||
import Decimal from "decimal.js";
|
||||
import { DEFAULT_OPTIONS } from "../constants";
|
||||
import {
|
||||
request_faucet_funds,
|
||||
deploy_token,
|
||||
deploy_collection,
|
||||
deploy_token,
|
||||
get_balance,
|
||||
mintCollectionNFT,
|
||||
transfer,
|
||||
trade,
|
||||
registerDomain,
|
||||
getTPS,
|
||||
launchPumpFunToken,
|
||||
lendAsset,
|
||||
getTPS,
|
||||
mintCollectionNFT,
|
||||
openbookCreateMarket,
|
||||
raydiumCreateAmmV4,
|
||||
raydiumCreateClmm,
|
||||
raydiumCreateCpmm,
|
||||
registerDomain,
|
||||
request_faucet_funds,
|
||||
trade,
|
||||
transfer,
|
||||
} from "../tools";
|
||||
import { CollectionOptions, PumpFunTokenOptions } from "../types";
|
||||
import { DEFAULT_OPTIONS } from "../constants";
|
||||
import BN from "bn.js";
|
||||
import Decimal from "decimal.js";
|
||||
|
||||
/**
|
||||
* Main class for interacting with Solana blockchain
|
||||
@@ -183,4 +184,21 @@ export class SolanaAgentKit {
|
||||
startTime,
|
||||
)
|
||||
}
|
||||
|
||||
async openbookCreateMarket(
|
||||
baseMint: PublicKey,
|
||||
quoteMint: PublicKey,
|
||||
|
||||
lotSize: number = 1,
|
||||
tickSize: number = 0.01,
|
||||
) {
|
||||
return openbookCreateMarket(
|
||||
this,
|
||||
baseMint,
|
||||
quoteMint,
|
||||
|
||||
lotSize,
|
||||
tickSize,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -572,7 +572,7 @@ export class SolanaTPSCalculatorTool extends Tool {
|
||||
|
||||
export class SolanaRaydiumCreateAmmV4 extends Tool {
|
||||
name = "raydium_create_ammV4";
|
||||
description = `create raydium amm v4 pool
|
||||
description = `Raydium's Legacy AMM that requiers an OpenBook marketID
|
||||
|
||||
Inputs (input is a json string):
|
||||
marketId: string (required)
|
||||
@@ -613,12 +613,12 @@ export class SolanaRaydiumCreateAmmV4 extends Tool {
|
||||
|
||||
export class SolanaRaydiumCreateClmm extends Tool {
|
||||
name = "raydium_create_clmm";
|
||||
description = `create raydium clmm pool
|
||||
description = `Concentrated liquidity market maker, custom liquidity ranges, increased capital efficiency
|
||||
|
||||
Inputs (input is a json string):
|
||||
mint1: string (required)
|
||||
mint2: string (required)
|
||||
configId: string (required)
|
||||
configId: string (required) stores pool info, id, index, protocolFeeRate, tradeFeeRate, tickSpacing, fundFeeRate
|
||||
initialPrice: number, eg: 123.12 (required)
|
||||
startTime: number(seconds), eg: now number or zero (required)
|
||||
`;
|
||||
@@ -658,12 +658,12 @@ export class SolanaRaydiumCreateClmm extends Tool {
|
||||
|
||||
export class SolanaRaydiumCreateCpmm extends Tool {
|
||||
name = "raydium_create_cpmm";
|
||||
description = `create raydium cpmm pool
|
||||
description = `Raydium's newest CPMM, does not require marketID, supports Token 2022 standard
|
||||
|
||||
Inputs (input is a json string):
|
||||
mint1: string (required)
|
||||
mint2: string (required)
|
||||
configId: string (required)
|
||||
configId: string (required), stores pool info, index, protocolFeeRate, tradeFeeRate, fundFeeRate, createPoolFee
|
||||
mintAAmount: number(int), eg: 1111 (required)
|
||||
mintBAmount: number(int), eg: 2222 (required)
|
||||
startTime: number(seconds), eg: now number or zero (required)
|
||||
@@ -704,6 +704,48 @@ export class SolanaRaydiumCreateCpmm extends Tool {
|
||||
}
|
||||
}
|
||||
|
||||
export class SolanaOpenbookCreateMarket extends Tool {
|
||||
name = "solana_openbook_create_market";
|
||||
description = `Openbook marketId, required for ammv4
|
||||
|
||||
Inputs (input is a json string):
|
||||
baseMint: string (required)
|
||||
quoteMint: string (required)
|
||||
lotSize: number (required)
|
||||
tickSize: number (required)
|
||||
`;
|
||||
|
||||
constructor(private solanaKit: SolanaAgentKit) {
|
||||
super();
|
||||
}
|
||||
|
||||
async _call(input: string): Promise<string> {
|
||||
try {
|
||||
let inputFormat = JSON.parse(input)
|
||||
|
||||
const tx = await this.solanaKit.openbookCreateMarket(
|
||||
new PublicKey(inputFormat.baseMint),
|
||||
new PublicKey(inputFormat.quoteMint),
|
||||
|
||||
inputFormat.lotSize,
|
||||
inputFormat.tickSize,
|
||||
);
|
||||
|
||||
return JSON.stringify({
|
||||
status: "success",
|
||||
message: "Create openbook market successfully",
|
||||
transaction: tx,
|
||||
});
|
||||
} catch (error: any) {
|
||||
return JSON.stringify({
|
||||
status: "error",
|
||||
message: error.message,
|
||||
code: error.code || "UNKNOWN_ERROR",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function createSolanaTools(solanaKit: SolanaAgentKit) {
|
||||
return [
|
||||
new SolanaBalanceTool(solanaKit),
|
||||
@@ -722,5 +764,6 @@ export function createSolanaTools(solanaKit: SolanaAgentKit) {
|
||||
new SolanaRaydiumCreateAmmV4(solanaKit),
|
||||
new SolanaRaydiumCreateClmm(solanaKit),
|
||||
new SolanaRaydiumCreateCpmm(solanaKit),
|
||||
new SolanaOpenbookCreateMarket(solanaKit),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -12,3 +12,4 @@ export * from "./get_tps";
|
||||
export * from "./raydium_create_ammV4";
|
||||
export * from "./raydium_create_clmm";
|
||||
export * from "./raydium_create_cpmm";
|
||||
export * from "./openbook_create_market";
|
||||
52
src/tools/openbook_create_market.ts
Normal file
52
src/tools/openbook_create_market.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { OPEN_BOOK_PROGRAM, Raydium, TxVersion } from "@raydium-io/raydium-sdk-v2";
|
||||
import { MintLayout, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
|
||||
export async function openbookCreateMarket(
|
||||
agent: SolanaAgentKit,
|
||||
|
||||
baseMint: PublicKey,
|
||||
quoteMint: PublicKey,
|
||||
|
||||
lotSize: number = 1,
|
||||
tickSize: number = 0.01,
|
||||
): Promise<string[]> {
|
||||
|
||||
const raydium = await Raydium.load({
|
||||
owner: agent.wallet,
|
||||
connection: agent.connection,
|
||||
})
|
||||
|
||||
const baseMintInfo = await agent.connection.getAccountInfo(baseMint)
|
||||
const quoteMintInfo = await agent.connection.getAccountInfo(quoteMint)
|
||||
|
||||
if (
|
||||
baseMintInfo?.owner.toString() !== TOKEN_PROGRAM_ID.toBase58() ||
|
||||
quoteMintInfo?.owner.toString() !== TOKEN_PROGRAM_ID.toBase58()
|
||||
) {
|
||||
throw new Error(
|
||||
'openbook market only support TOKEN_PROGRAM_ID mints, if you want to create pool with token-2022, please create raydium cpmm pool instead'
|
||||
)
|
||||
}
|
||||
|
||||
const { execute } = await raydium.marketV2.create({
|
||||
baseInfo: {
|
||||
mint: baseMint,
|
||||
decimals: MintLayout.decode(baseMintInfo.data).decimals,
|
||||
},
|
||||
quoteInfo: {
|
||||
mint: quoteMint,
|
||||
decimals: MintLayout.decode(quoteMintInfo.data).decimals,
|
||||
},
|
||||
lotSize,
|
||||
tickSize,
|
||||
dexProgramId: OPEN_BOOK_PROGRAM,
|
||||
|
||||
txVersion: TxVersion.V0,
|
||||
})
|
||||
|
||||
const { txIds } = await execute({ sequentially: true, })
|
||||
|
||||
return txIds
|
||||
}
|
||||
Reference in New Issue
Block a user