UNPKG

goosefx-amm-sdk

Version:

SDK for the GooseFx AMM

175 lines (171 loc) 5.99 kB
import { PublicKey, EpochInfo } from '@solana/web3.js'; import { ConfigInfo, PoolInfo, PoolKeys } from './api/type.js'; import { TxVersion } from './common/txTool/txType.js'; import BN from 'bn.js'; import { C as ComputeBudgetConfig, G as GetTransferAmountFee } from './type-4a262146.js'; import { Percent } from './module/percent.js'; import { Gamma } from './gfx/idl/gamma.type.js'; import Decimal from 'decimal.js'; import { IdlAccounts, IdlTypes } from '@coral-xyz/anchor'; declare enum RoundDirection { Floor = 0, Ceiling = 1 } type SwapWithoutFeesResult = { sourceAmountSwapped: BN; destinationAmountSwapped: BN; }; type TradingTokenResult = { tokenAmount0: BN; tokenAmount1: BN; }; type SwapResult = { newSwapSourceAmount: BN; newSwapDestinationAmount: BN; sourceAmountSwapped: BN; destinationAmountSwapped: BN; tradeFee: BN; }; declare class CurveCalculator { static validate_supply(tokenAmount0: BN, tokenAmount1: BN): void; static swapBaseIn(sourceAmount: BN, swapSourceAmount: BN, swapDestinationAmount: BN, tradeFeeRate: BN, observationState: CpmmObservationState, poolVolatilityFactor: BN, isInvokedWithSignedSegmenter?: boolean): SwapResult; static swapBaseOut(destinationAmount: BN, swapSourceAmount: BN, swapDestinationAmount: BN, tradeFeeRate: BN, observationState: CpmmObservationState, poolVolatilityFactor: BN, isInvokedWithSignedSegmenter?: boolean): SwapResult; } interface MintInfo { address: string; decimals: number; programId: string; } interface CreateCpmmPoolParam<T> { programId: PublicKey; poolFeeAccount: PublicKey; mintA: MintInfo; mintB: MintInfo; mintAAmount: BN; mintBAmount: BN; startTime: BN; maxTradeFeeRate: BN; volatilityFactor: BN; feeConfig: ConfigInfo; associatedOnly: boolean; checkCreateATAOwner?: boolean; ownerInfo: { feePayer?: PublicKey; useSOLBalance?: boolean; }; computeBudgetConfig?: ComputeBudgetConfig; txVersion?: T; } interface CreateCpmmPoolAddress { poolId: PublicKey; configId: PublicKey; authority: PublicKey; lpMint: PublicKey; vaultA: PublicKey; vaultB: PublicKey; observationId: PublicKey; mintA: MintInfo; mintB: MintInfo; programId: PublicKey; poolFeeAccount: PublicKey; feeConfig: ConfigInfo; } interface AddCpmmLiquidityParams<T = TxVersion.LEGACY> { poolInfo: PoolInfo; poolKeys?: PoolKeys; payer?: PublicKey; inputAmount: BN; baseSpecified: boolean; slippage: Percent; config?: { bypassAssociatedCheck?: boolean; checkCreateATAOwner?: boolean; }; computeBudgetConfig?: ComputeBudgetConfig; txVersion?: T; computeResult?: { inputAmountFee: GetTransferAmountFee; anotherAmount: GetTransferAmountFee; maxAnotherAmount: GetTransferAmountFee; liquidity: BN; }; partner?: PublicKey; } interface WithdrawCpmmLiquidityParams<T = TxVersion.LEGACY> { poolInfo: PoolInfo; poolKeys?: PoolKeys; payer?: PublicKey; lpAmount: BN; slippage: Percent; computeBudgetConfig?: ComputeBudgetConfig; txVersion?: T; } interface CpmmSwapWithOracleParams<T = TxVersion.LEGACY> { poolInfo: PoolInfo; poolKeys?: PoolKeys; payer?: PublicKey; zeroForOne: boolean; slippage?: number; swapResult: Pick<SwapResult, "sourceAmountSwapped" | "destinationAmountSwapped">; config?: { bypassAssociatedCheck?: boolean; checkCreateATAOwner?: boolean; associatedOnly?: boolean; }; computeBudgetConfig?: ComputeBudgetConfig; txVersion?: T; wrapSol?: boolean; dflowSegmenterOptions?: { registeredSegmenter: PublicKey; registeredRegistry: PublicKey; } | null; referralAccounts?: { referralAccount: PublicKey; referralTokenAccountWithInputMint: PublicKey; } | null; } interface CpmmSwapParams<T = TxVersion.LEGACY> extends CpmmSwapWithOracleParams<T> { baseIn?: boolean; } interface ComputePairAmountParams { poolInfo: PoolInfo; baseReserve: BN; quoteReserve: BN; amount: string | Decimal; slippage: Percent; epochInfo: EpochInfo; baseSpecified?: boolean; } type CpmmObservationState = IdlAccounts<Gamma>["observationState"]; type CpmmConfig = IdlAccounts<Gamma>["ammConfig"]; type CpmmPool = IdlAccounts<Gamma>["poolState"]; type CpmmPoolPartners = IdlAccounts<Gamma>["poolPartnerInfos"]; type CpmmRewardInfo = IdlAccounts<Gamma>["rewardInfo"]; type CpmmUserLiquidityAccount = IdlAccounts<Gamma>["userPoolLiquidity"]; type CpmmUserRewardInfo = IdlAccounts<Gamma>["userRewardInfo"]; type CpmmObservation = IdlTypes<Gamma>["observation"]; type UserLiquidityAccount = IdlAccounts<Gamma>["userPoolLiquidity"]; declare enum CpmmCoder { CPMM_POOL = "poolState", CPMM_POOL_PARTNERS = "poolPartnerInfos" } type CpmmRpcData = CpmmPool & { baseReserve: BN; quoteReserve: BN; vaultAAmount: BN; vaultBAmount: BN; configInfo?: CpmmConfig; partnerInfo: CpmmPoolPartners; observationAccount: CpmmObservationState; poolPrice: Decimal; programId: PublicKey; }; type CpmmComputeData = { id: PublicKey; version: 7; configInfo: CpmmConfig; mintA: MintInfo; mintB: MintInfo; authority: PublicKey; } & Omit<CpmmRpcData, "configInfo" | "mintA" | "mintB">; export { AddCpmmLiquidityParams as A, CreateCpmmPoolParam as C, RoundDirection as R, SwapWithoutFeesResult as S, TradingTokenResult as T, UserLiquidityAccount as U, WithdrawCpmmLiquidityParams as W, CreateCpmmPoolAddress as a, CpmmSwapWithOracleParams as b, CpmmSwapParams as c, ComputePairAmountParams as d, CpmmObservationState as e, CpmmConfig as f, CpmmPool as g, CpmmPoolPartners as h, CpmmRewardInfo as i, CpmmUserLiquidityAccount as j, CpmmUserRewardInfo as k, CpmmObservation as l, CpmmCoder as m, CpmmRpcData as n, CpmmComputeData as o, SwapResult as p, CurveCalculator as q };