npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

bp-market-sdk

v1.0.1

Published

SDK for BP Market Solana Program

Readme

BP Market SDK

A TypeScript SDK for interacting with the BP Market Solana program.

Installation

npm install @bp-market/sdk

Usage

Initialize the SDK

import { BPMarketSDK } from '@bp-market/sdk';
import { Program, AnchorProvider } from '@coral-xyz/anchor';
import { Connection, PublicKey } from '@solana/web3.js';

// Initialize connection and provider
const connection = new Connection('https://api.devnet.solana.com');
const provider = new AnchorProvider(connection, wallet, {});

// Load the program
const program = new Program(idl, programId, provider);

// Create SDK instance
const sdk = new BPMarketSDK(program);

Owner Operations

// Initialize config with base token
const baseToken = new PublicKey('...');
const owner = wallet.publicKey;
await sdk.initialize(baseToken, owner);

// Update owner
const newOwner = new PublicKey('...');
await sdk.updateOwner(newOwner, owner);

// Lock/unlock users
await sdk.lockUser(userPublicKey, owner);
await sdk.unlockUser(userPublicKey, owner);

// Set fee accounts
await sdk.setAccount(AccountType.CojamFee, cojamAccount, owner);
await sdk.setAccount(AccountType.CharityFee, charityAccount, owner);
await sdk.setAccount(AccountType.Remain, remainAccount, owner);

Market Operations

// Publish a new market
const marketData = {
  marketKey: new BN(1),
  creator: creatorPublicKey,
  title: "Who will win the championship?",
  createFee: new BN(1000000),
  creatorFeePercentage: new BN(100), // 1%
  serviceFeePercentage: new BN(200), // 2%
  charityFeePercentage: new BN(50),  // 0.5%
  answerKeys: [new BN(1), new BN(2), new BN(3)]
};
await sdk.publishMarket(marketData, owner);

// Approve market
await sdk.approveMarket(marketKey, owner);

// Mark market as successful
await sdk.successMarket(marketKey, correctAnswerKey, owner);

// Adjourn market
await sdk.adjournMarket(marketKey, owner);

User Operations

// Place a bet
const marketKey = new BN(1);
const answerKey = new BN(2);
const amount = new BN(1000000000); // 1 token
const voter = wallet.publicKey;
await sdk.bet(marketKey, answerKey, amount, voter);

// Claim winnings
await sdk.receiveToken(marketKey, answerKey, voter);

// Calculate potential winnings
const winnings = await sdk.calculateWinnings(voter, marketKey, answerKey);

// Calculate available tokens to receive (works for both success and adjourn status)
const availableTokens = await sdk.availableReceiveTokens(marketKey, bettingPDA);
// Or using voter address directly
const availableTokensByUser = await sdk.availableReceiveTokensByUser(voter, marketKey, answerKey);

Query Operations

// Fetch accounts
const config = await sdk.fetchConfig();
const market = await sdk.fetchMarket(marketKey);
const answer = await sdk.fetchAnswer(marketKey);
const betting = await sdk.fetchBetting(voter, marketKey, answerKey);

// Get all config accounts at once
const accounts = await sdk.getAccounts();
// Returns: { owner, cojamFeeAccount, charityFeeAccount, remainAccount, baseToken }

// Get specific config information
const owner = await sdk.getOwner();
const baseToken = await sdk.getBaseToken();
const feeAccounts = await sdk.getFeeAccounts();
const lockedUsers = await sdk.getLockedUsers();

// Get market information
const marketInfo = await sdk.getMarketInfo(marketKey);
// Returns: { creator, title, status, totalTokens, remainTokens, rewardBaseTokens, correctAnswerKey, approveTime, successTime, adjournTime }

const marketFee = await sdk.getMarketFee(marketKey);
// Returns: { creatorFee, creatorFeePercentage, serviceFeePercentage, charityFeePercentage }

const marketFees = await sdk.getMarketFees(marketKey);
// Returns: { creatorFee, creatorFeePercentage, serviceFeePercentage, charityFeePercentage, totalFeePercentage }

// Get answer information
const answerInfo = await sdk.getAnswerInfo(marketKey, answerKey);
// Returns: { totalTokens, percentage }

const allAnswers = await sdk.getAllAnswersInfo(marketKey);
// Returns array of: { answerKey, totalTokens, percentage }

// Get user bet information
const userBetInfo = await sdk.getUserBetInfo(voter, marketKey, answerKey);
// Returns: { exists, tokens, createTime, potentialWinnings }

const userTotalBets = await sdk.getUserTotalBets(voter);
// Returns: { totalBets, totalTokensBet, markets: [{ marketKey, answerKey, tokens }] }

// Get all markets
const allMarkets = await sdk.getAllMarkets();

// Get markets by creator
const creatorMarkets = await sdk.getMarketsByCreator(creatorPublicKey);

// Get user bets
const userBets = await sdk.getUserBets(userPublicKey);

// Check if user is locked
const isLocked = await sdk.isUserLocked(userPublicKey);

// Get market status
const status = await sdk.getMarketStatus(marketKey);

Event Listeners

// Listen for bet placed events
const listenerId = sdk.addEventListener('betPlaced', (event, slot, signature) => {
  console.log('Bet placed:', event);
});

// Remove listener
await sdk.removeEventListener(listenerId);

Helper Methods

// Get PDAs
const configPDA = sdk.getConfigPDA();
const marketPDA = sdk.getMarketPDA(marketKey);
const answerPDA = sdk.getAnswerPDA(marketKey);
const bettingPDA = sdk.getBettingPDA(voter, marketKey, answerKey);

// Get vault token account
const vaultAccount = await sdk.getVaultTokenAccount(marketKey, mint);

Types

The SDK exports the following types:

  • ConfigAccount - Configuration account structure
  • MarketAccount - Market account structure
  • AnswerAccount - Answer account structure
  • BettingAccount - Betting account structure
  • MarketData - Market creation parameters
  • AccountType - Enum for account types (CojamFee, CharityFee, Remain)

License

MIT