0.1.63 • Published 4 months ago

meme-police-sdk v0.1.63

Weekly downloads
-
License
-
Repository
-
Last release
4 months ago

Mastermind SDK

A TypeScript SDK for interacting with the Mastermind Solana program. This SDK provides a comprehensive interface for trading and managing bonding curves on Solana.

Installation

npm install meme-police-sdk

Usage

Initializing the Client

import { MastermindClient, Config } from 'meme-police-sdk/dist/index';
import { AnchorProvider } from '@coral-xyz/anchor';

// Initialize with default config (devnet)
const client = new MastermindClient(provider);

// Or specify a cluster
const config = new Config('mainnet');
const client = new MastermindClient(provider, 'mainnet', config);

Configuration

The SDK supports the following networks:

  • mainnet
  • devnet
  • localnet

Key Features

  1. Trading Operations

    • Execute buy/sell trades with exact input or output amounts
    • Support for slippage protection
    • Automatic fee calculation
  2. Bonding Curve Management

    • Create and manage bonding curves
    • Query curve states and reserves
    • Track virtual and real token/SOL reserves
  3. Account Management

    • Query global state
    • Manage authority and permissions
    • Handle token vaults and associated accounts

Examples

Execute a Trade

const tradeParams = {
  tradeType: TradeType.EXACT_IN,
  tradeDirection: TradeDirection.BUY,
  amountToTrade: new BN(1000000000), // 1 SOL
  slippage: 0.01, // 1%
  mint: tokenMintPublicKey,
};

const [tradeInfo, error] = await client.getTrade(tradeParams);
if (error) {
  console.error('Trade error:', error);
  return;
}

console.log('Trade details:', {
  inputAmount: tradeInfo.inputAmount.toString(),
  outputAmount: tradeInfo.minmaxOutputAmount.toString(),
  price: tradeInfo.price.toString(),
  fee: tradeInfo.fee.toString(),
});

Query Bonding Curve State

const [bondingCurvePda] = client.getBondingCurveAccounts(mintPublicKey);
const curveState = await client.deserializeCurve(bondingCurvePda.publicKey);

console.log('Curve state:', {
  realTokenReserve: curveState.realTokenReserve.toString(),
  realSolReserve: curveState.realSolReserve.toString(),
  virtualTokenReserve: curveState.virtualTokenReserve.toString(),
  virtualSolReserve: curveState.virtualSolReserve.toString(),
});

Error Handling

The SDK provides custom error types for common scenarios:

  • MastermindRpcError: RPC-related errors with transaction IDs
  • PermissionError: Authorization-related errors
  • SlippageError: Trade slippage validation errors
  • TradeError: General trading-related errors

License

MIT License

Copyright (c) 2024 Meme Police

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0.1.63

4 months ago

0.1.62

4 months ago

0.1.61

4 months ago

0.1.58

4 months ago

0.1.57

4 months ago

0.1.55

4 months ago

0.1.54

4 months ago

0.1.53

4 months ago

0.1.51

4 months ago

0.1.49

4 months ago

0.1.44

5 months ago

0.1.43

5 months ago

0.1.42

5 months ago

0.1.40

5 months ago

0.1.39

5 months ago

0.1.38

6 months ago

0.1.37

6 months ago

0.1.36

6 months ago

0.1.34

6 months ago

0.1.33

6 months ago

0.1.31

6 months ago

0.1.30

6 months ago

0.1.29

6 months ago

0.1.28

6 months ago

0.1.27

6 months ago

0.1.26

6 months ago

0.1.25

6 months ago

0.1.23

6 months ago

0.1.22

7 months ago

0.1.21

7 months ago

0.1.20

7 months ago

0.1.19

7 months ago

0.1.18

7 months ago

0.1.16

7 months ago

0.1.15

7 months ago

0.1.14

7 months ago

0.1.13

7 months ago

0.1.9

7 months ago

0.1.8

7 months ago

0.1.7

7 months ago

0.1.3

7 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.1.0

7 months ago