mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-16 07:36:45 +00:00
fix: Parse float number to BN error
This commit is contained in:
@@ -350,6 +350,7 @@ export class SolanaAgentKit {
|
||||
activationPoint: BN | null,
|
||||
hasAlphaVault: boolean,
|
||||
activationType: number,
|
||||
computeUnitMicroLamports: number = 100000,
|
||||
): Promise<string> {
|
||||
return createMeteoraDynamicAMMPool(
|
||||
this,
|
||||
@@ -364,6 +365,7 @@ export class SolanaAgentKit {
|
||||
activationType,
|
||||
padding: new Array(90).fill(0),
|
||||
},
|
||||
computeUnitMicroLamports,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ export const DEFAULT_OPTIONS = {
|
||||
LEVERAGE_BPS: 50000, // 10000 = x1, 50000 = x5, 100000 = x10, 1000000 = x100
|
||||
} as const;
|
||||
|
||||
export const METEORA_DYNAMIC_FEE_DENOMINATOR = new BN(100000);
|
||||
export const METEORA_DYNAMIC_FEE_DENOMINATOR = 100000;
|
||||
|
||||
/**
|
||||
* Jupiter API URL
|
||||
|
||||
@@ -1320,10 +1320,11 @@ export class SolanaMeteoraCreateDynamicPool extends Tool {
|
||||
- tokenBMint: string, token B mint (required).
|
||||
- tokenAAmount: number, token A amount including decimals, e.g., 1000000000 (required).
|
||||
- tokenBAmount: number, token B amount including decimals, e.g., 1000000000 (required).
|
||||
- tradeFee: number, trade fee in percentage, e.g., 0.5 (required).
|
||||
- tradeFeeNumerator: number, trade fee numerator, e.g., 2500 for 2.5% (required).
|
||||
- activationType: number, pool start trading time indicator, 0 is slot and 1 is timestamp, default is 1 for timestamp (optional).
|
||||
- activationPoint: number, pool start trading slot / timestamp, default is null means pool can start trading immediately (optional).
|
||||
- hasAlphaVault: boolean, whether the pool supports alpha vault, default is false (optional).
|
||||
- computeUnitMicroLamports: number, the priority fee in micro-lamports unit, default is 100000 (optional).
|
||||
`;
|
||||
|
||||
constructor(private solanaKit: SolanaAgentKit) {
|
||||
@@ -1337,10 +1338,11 @@ export class SolanaMeteoraCreateDynamicPool extends Tool {
|
||||
tokenBMint: string;
|
||||
tokenAAmount: number;
|
||||
tokenBAmount: number;
|
||||
tradeFee: number;
|
||||
tradeFeeNumerator: number;
|
||||
activationType?: number;
|
||||
activationPoint?: number;
|
||||
hasAlphaVault?: boolean;
|
||||
computeUnitMicroLamports?: number;
|
||||
}
|
||||
const inputFormat: CreateMeteoraDynamicAmmPoolInput = JSON.parse(input);
|
||||
|
||||
@@ -1350,14 +1352,17 @@ export class SolanaMeteoraCreateDynamicPool extends Tool {
|
||||
const tokenBMint = new PublicKey(inputFormat.tokenBMint);
|
||||
const tokenAAmount = new BN(inputFormat.tokenAAmount.toString());
|
||||
const tokenBAmount = new BN(inputFormat.tokenBAmount.toString());
|
||||
const tradeFeeNumerator = new BN(inputFormat.tradeFee.toString())
|
||||
.mul(METEORA_DYNAMIC_FEE_DENOMINATOR)
|
||||
.toNumber();
|
||||
|
||||
const tradeFeeNumerator = new BN(
|
||||
inputFormat.tradeFeeNumerator.toString(),
|
||||
).toNumber();
|
||||
const activationType = inputFormat.activationType ?? 1;
|
||||
const activationPoint = inputFormat.activationPoint
|
||||
? new BN(inputFormat.activationPoint)
|
||||
: null;
|
||||
const hasAlphaVault = inputFormat.hasAlphaVault ?? false;
|
||||
const computeUnitMicroLamports =
|
||||
inputFormat.computeUnitMicroLamports ?? 100000;
|
||||
|
||||
const txId = await this.solanaKit.meteoraCreateDynamicPool(
|
||||
tokenAMint,
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import AmmImpl from "@mercurial-finance/dynamic-amm-sdk";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import BN from "bn.js";
|
||||
import { PublicKey, sendAndConfirmTransaction } from "@solana/web3.js";
|
||||
import {
|
||||
ComputeBudgetProgram,
|
||||
PublicKey,
|
||||
sendAndConfirmTransaction,
|
||||
} from "@solana/web3.js";
|
||||
import { CustomizableParams } from "@mercurial-finance/dynamic-amm-sdk/dist/cjs/src/amm/types";
|
||||
|
||||
/**
|
||||
@@ -26,6 +30,7 @@ export async function createMeteoraDynamicAMMPool(
|
||||
tokenAAmount: BN,
|
||||
tokenBAmount: BN,
|
||||
customizableParams: CustomizableParams,
|
||||
computeUnitMicroLamports: number,
|
||||
): Promise<string> {
|
||||
const initPoolTx =
|
||||
await AmmImpl.createCustomizablePermissionlessConstantProductPool(
|
||||
@@ -38,6 +43,12 @@ export async function createMeteoraDynamicAMMPool(
|
||||
customizableParams,
|
||||
);
|
||||
|
||||
initPoolTx.add(
|
||||
ComputeBudgetProgram.setComputeUnitPrice({
|
||||
microLamports: computeUnitMicroLamports,
|
||||
}),
|
||||
);
|
||||
|
||||
const initPoolTxHash = await sendAndConfirmTransaction(
|
||||
agent.connection,
|
||||
initPoolTx,
|
||||
|
||||
Reference in New Issue
Block a user