๐ง gamba-core-v2
Gamba Core package with a provider for the Anchor program + utilities
npm install gamba-core-v2
๐ ๏ธ GambaProviders
GambaProvider
A provider class with methods to interact with the Gamba program.
-
Props:
gambaProgram
:anchor.Program<Gamba>
anchorProvider
:anchor.AnchorProvider
wallet
:GambaProviderWallet
-
Methods:
constructor(connection: Connection, wallet: GambaProviderWallet, opts?: ConfirmOptions)
: Initializes theGambaProvider
.static fromAnchorProvider(provider: anchor.AnchorProvider)
: Returns aGambaProvider
from ananchor.AnchorProvider
.get user
: Returns the current user'sPublicKey
.createPool(underlyingTokenMint: PublicKey, authority: PublicKey, slot: number)
: Creates a pool.depositToPool(pool: PublicKey, underlyingTokenMint: PublicKey, amount: bigint | number)
: Deposits to the pool.withdrawFromPool(pool: PublicKey, underlyingTokenMint: PublicKey, amount: bigint | number)
: Withdraws from the pool.mintBonusTokens(pool: PublicKey, underlyingTokenMint: PublicKey, amount: bigint | number)
: Mints bonus tokens.createPlayer()
: Creates an associated player account.closePlayer()
: Closes the associated player account.play(...)
: Plays a game with specified parameters.
const gambaProvider = new GambaProvider(connection, wallet);
gambaProvider.createPlayer();
๐ Transaction Utilities
parseGambaTransaction
Parses a transaction to retrieve Gamba events.
-
Parameters:
transaction: ParsedTransactionWithMeta
: A parsed transaction with metadata.
-
Returns:
GambaTransaction<"GameSettled"> | GambaTransaction<"PoolChange">[]
: List of parsed transactions.
const parsedEvents = parseGambaTransaction(transactionWithMeta);
fetchGambaTransactionsFromSignatures
Fetches recent Gamba events using transaction signatures.
-
Parameters:
connection: Connection
: A Solana connection instance.signatures: string[]
: Array of transaction signatures.
-
Returns:
Promise<(GambaTransaction<"GameSettled"> | GambaTransaction<"PoolChange">)[]>
: A promise resolving to a list of transactions.
const gambaTransactions = await fetchGambaTransactionsFromSignatures(connection, signatures);
fetchGambaTransactions
Fetches recent Gamba events based on an address.
-
Parameters:
connection: Connection
: A Solana connection instance.address: PublicKey
: Address to fetch transactions from.options: SignaturesForAddressOptions
: Signature query options.
-
Returns:
Promise<(GambaTransaction<"GameSettled"> | GambaTransaction<"PoolChange">)[]>
: A promise resolving to a list of transactions.
const recentGambaTransactions = await fetchGambaTransactions(connection, address, options);
๐งฉ Decoding Helpers
๐ฎ Game Logic
getGameHash
Computes a game hash from an RNG seed, client seed, and nonce.
-
Parameters:
rngSeed: string
: RNG seed value.clientSeed: string
: Client seed value.nonce: number
: Nonce value.
-
Returns:
Promise<string>
: A promise resolving to the game hash.
const gameHash = await getGameHash(rngSeed, clientSeed, nonce);
getResultNumber
Extracts a numeric result based on an RNG seed, client seed, and nonce.
-
Parameters:
rngSeed: string
: RNG seed value.clientSeed: string
: Client seed value.nonce: number
: Nonce value.
-
Returns:
Promise<number>
: A promise resolving to a numeric result.
const resultNumber = await getResultNumber(rngSeed, clientSeed, nonce);
getNextResult
Fetches the next game result based on a previous nonce.
-
Parameters:
connection: Connection
: A Solana connection instance.user: PublicKey
: User's public key.prevNonce: number
: The previous nonce value.
-
Returns:
Promise<GameResult>
: A promise resolving to the next game result.
const nextResult = await getNextResult(connection, user, prevNonce);
๐ Constants
๐บ๏ธ Seed Address Generators
getPoolAddress
Derives the pool address from a mint and authority.
-
Parameters:
underlyingMint: PublicKey
: Mint address of the underlying token.authority?: PublicKey
: Optional authority for the pool.
-
Returns:
PublicKey
: The derived pool address.
const underlyingMint = new PublicKey("So11111111111111111111111111111111111111112");
const authority = new PublicKey("5tJXJGZh7bCSqP8kgYi4P1R9W4GmA5mZAn5xZZ2CGN4P");
const poolAddress = getPoolAddress(underlyingMint, authority);
getPlayerAddress
Retrieves the player address for an owner.
-
Parameters:
owner: PublicKey
: Public key of the player owner.
-
Returns:
PublicKey
: The derived player address.
const playerOwner = new PublicKey("7Hj9wFkf4HhrFhUVGRi75mNY4PttytVgAhRRUNtBeJRx");
const playerAddress = getPlayerAddress(playerOwner);
getPoolUnderlyingTokenAccountAddress
Fetches the underlying token account address for a pool.
-
Parameters:
pool: PublicKey
: Public key of the pool.
-
Returns:
PublicKey
: The underlying token account address.
const pool = new PublicKey("7Hj9wFkf4HhrFhUVGRi75mNY4PttytVgAhRRUNtBeJRx");
const poolUnderlyingAccountAddress = getPoolUnderlyingTokenAccountAddress(pool);
getPoolJackpotTokenAccountAddress
Retrieves the jackpot account address for a pool.
-
Parameters:
pool: PublicKey
: Public key of the pool.
-
Returns:
PublicKey
: The jackpot account address.
const pool = new PublicKey("7Hj9wFkf4HhrFhUVGRi75mNY4PttytVgAhRRUNtBeJRx");
const poolJackpotAccountAddress = getPoolJackpotTokenAccountAddress(pool);
getPoolBonusUnderlyingTokenAccountAddress
Returns the address of the pool's bonus underlying token account.
-
Parameters:
pool: PublicKey
: Public key of the pool.
-
Returns:
PublicKey
: Address of the bonus underlying token account.
const pool = new PublicKey("7Hj9wFkf4HhrFhUVGRi75mNY4PttytVgAhRRUNtBeJRx");
const poolBonusUnderlyingTokenAccountAddress = getPoolBonusUnderlyingTokenAccountAddress(pool);
getUserUnderlyingAta
Fetches a user's associated token account for an underlying mint.
-
Parameters:
user: PublicKey
: Public key of the user.underlyingTokenMint: PublicKey
: Mint address of the underlying token.
-
Returns:
PublicKey
: User's associated token account address.
const user = new PublicKey("7Hj9wFkf4HhrFhUVGRi75mNY4PttytVgAhRRUNtBeJRx");
const underlyingTokenMint = new PublicKey("So11111111111111111111111111111111111111112");
const userUnderlyingAta = getUserUnderlyingAta(user, underlyingTokenMint);
getPlayerUnderlyingAta
Retrieves a player's underlying token account.
-
Parameters:
user: PublicKey
: Public key of the player.underlyingTokenMint: PublicKey
: Mint address of the underlying token.
-
Returns:
PublicKey
: Player's underlying token account address.
const user = new PublicKey("7Hj9wFkf4HhrFhUVGRi75mNY4PttytVgAhRRUNtBeJRx");
const underlyingTokenMint = new PublicKey("So11111111111111111111111111111111111111112");
const playerUnderlyingAta = getPlayerUnderlyingAta(user, underlyingTokenMint);
getUserBonusAtaForPool
Gets the bonus account for a user in a pool.
-
Parameters:
user: PublicKey
: Public key of the user.pool: PublicKey
: Public key of the pool.
-
Returns:
PublicKey
: User's bonus account address for the pool.
const user = new PublicKey("7Hj9wFkf4HhrFhUVGRi75mNY4PttytVgAhRRUNtBeJRx");
const pool = new PublicKey("So11111111111111111111111111111111111111112");
const userBonusAta = getUserBonusAtaForPool(user, pool);
getUserLpAtaForPool
Retrieves the user's liquidity pool token account.
-
Parameters:
user: PublicKey
: Public key of the user.pool: PublicKey
: Public key of the pool.
-
Returns:
PublicKey
: User's liquidity pool account address for the pool.
const user = new PublicKey("7Hj9wFkf4HhrFhUVGRi75mNY4PttytVgAhRRUNtBeJRx");
const pool = new PublicKey("So11111111111111111111111111111111111111112");
const userLpAta = getUserLpAtaForPool(user, pool);
getPlayerBonusAtaForPool
Fetches a player's bonus token account for a pool.
-
Parameters:
user: PublicKey
: Public key of the player.pool: PublicKey
: Public key of the pool.
-
Returns:
PublicKey
: Player's bonus token account address for the pool.
const user = new PublicKey("7Hj9wFkf4HhrFhUVGRi75mNY4PttytVgAhRRUNtBeJRx");
const pool = new PublicKey("So11111111111111111111111111111111111111112");
const playerBonusAta = getPlayerBonusAtaForPool(user, pool);
๐ Utilities
wrapSol
Creates instructions to wrap SOL to native tokens.
-
Parameters:
from: PublicKey
: The source public key.amount: bigint | number
: The amount to wrap.create: boolean
: Indicates whether to create a new account.
-
Returns:
Promise<_solana_web3_js.TransactionInstruction[]>
: A promise resolving to an array of transaction instructions.
const basisPointsValue = basisPoints(percent);
unwrapSol
Generates an instruction to unwrap SOL back to its native form.
-
Parameters:
from: PublicKey
: The source public key.
-
Returns:
Promise<_solana_web3_js.TransactionInstruction>
: A promise resolving to the transaction instruction.
const from = new PublicKey("7Hj9wFkf4HhrFhUVGRi75mNY4PttytVgAhRRUNtBeJRx");
const amount = BigInt(1000000); // 1 SOL
const create = true;
const instructions = await wrapSol(from, amount, create);
isNativeMint
Checks if a given public key matches the native mint.
-
Parameters:
pubkey: PublicKey
: The public key to check.
-
Returns:
boolean
:true
if the key matches the native mint, otherwisefalse
.
const pubkey = new PublicKey("So11111111111111111111111111111111111111112");
const isNative = isNativeMint(pubkey);