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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ls-arkade/payments

v0.1.17

Published

SDK for Liberty Square's Arkade

Downloads

5

Readme

Liberty Square Arkade: Payments

Install the Typescript package

yarn add @ls-arkade/payments

Setup the package in your app

Setup the program:

import { program, transactions } from "@ls-arkade/payments";

const { connection } = useConnection();
const wallet = useWallet();

const lsPaymentsProgram = program(connection, wallet);

Fetch config account

Each game has its own config onchain. See Notion's API doc for more info.

const configAccount = await lsPaymentsProgram.account.configAccount.fetch(
  new PublicKey(DEVNET_WHEEL_OF_FATE_CONFIG_ADDRESS)
);

Fetch pools

You can fetch each pool and display its total vault SOL amount.

import { pda, DAILY_POOL, MONTHLY_POOL, WEEKLY_POOL } from "@ls-arkade/payments";


const [dailyPoolPubkey] = pda.findPoolVault(configAccountKey.publicKey, DAILY_POOL);
const [weeklyPoolPubkey] = pda.findPoolVault(configAccountKey.publicKey, WEEKLY_POOL);
const [monthlyPoolPubkey] = pda.findPoolVault(configAccountKey.publicKey, MONTHLY_POOL);

Buy Paid Arkade SPL token with SOL:

The user can buy Arkade tokens from the UI.

Available options for one transaction:

  • Individual token(s): user can buy 1/2/3/4/5 tokens (0.045 SOL per)
  • Packs: user can buy one or two packs of 25 tokens in one tx (0.88 SOL per)

Each tx has a micro fee:

  • 0.0044 SOL for each individual ticket tx
  • 0.0088 SOL for each pack tx
const sourceTokenAccount = getAssociatedTokenAddressSync(
  configAccount.paymentTokenMint,
  wallet.publicKey!
);

if (!sourceTokenAccount) {
  throw new Error("You don't have enough tokens to start a game.")
}

// Ticket amount can be 1/2/3/4/5 for single tickets or 25/50 for packs
const ticketAmount = 1; 

const buySplTx = await transactions.buySpl(
  new PublicKey(DEVNET_WHEEL_OF_FATE_CONFIG_ADDRESS),
  sourceTokenAccount,
  ticketAmount,
  // new PublicKey("FkgPYryuNgmJepPRDHoFhMo9bAZVSR7D2GQnCjd2AJQ8") // one of the valid NFT held by current player (or undefined)
);

await lsPaymentsProgram.provider.sendAndConfirm(buySplTx, [], { skipPreflight: true });

Buy Free Arkade SPL token with Karbon:

The user can buy Arkade tokens from the UI.

Available options for one transaction:

  • Individual token(s): user can buy 1/2/3/4/5 tokens (0.045 SOL per)
  • Packs: user can buy one or two packs of 25 tokens in one tx (0.88 SOL per)

Each tx has a micro fee:

  • 0.0044 SOL for each individual ticket tx
  • 0.0088 SOL for each pack tx
import { KARBON_TOKEN } from "@ls-arkade/payments";

const sourceTokenAccount = getAssociatedTokenAddressSync(
  KARBON_TOKEN,
  wallet.publicKey!
);

if (!sourceTokenAccount) {
  throw new Error("You don't have enough tokens to start a game.")
}

// Ticket amount can be 1/2/3/4/5 for single tickets or 25/50 for packs
const ticketAmount = 1; 

const buySplTx = await transactions.buySpl(
  new PublicKey(DEVNET_WHEEL_OF_FATE_CONFIG_ADDRESS),
  sourceTokenAccount,
  ticketAmount,
  provider.publicKey,
  undefined, // new PublicKey("FkgPYryuNgmJepPRDHoFhMo9bAZVSR7D2GQnCjd2AJQ8") // one of the valid NFT held by current player (or undefined)
  KARBON_TOKEN
);

await lsPaymentsProgram.provider.sendAndConfirm(buySplTx, [], { skipPreflight: true });

Start a game:

This methods can be passed an NFT mint belonging to the tx signer.

If the user owns:

  • a squirrel: the cost is 1 token
  • a "the hallowed": the cost is 2 tokens
  • none of the above: the cost is 3 tokens

Final cost is calculated onchain.

const sourceTokenAccount = getAssociatedTokenAddressSync(
  configAccount.paymentTokenMint,
  wallet.publicKey!
);

const sourceTokenAccountInfo = await connection.getAccountInfo(sourceTokenAccount);

if (!sourceTokenAccountInfo) {
  const createATATx = new Transaction().add(createAssociatedTokenAccountInstruction(
    wallet.publicKey!,
    sourceTokenAccount,
    wallet.publicKey!,
    configAccount.paymentTokenMint
  ));
  await lsPaymentsProgram.provider.sendAndConfirm!(createATATx);
}

const handlePaymentTxn = await transactions.handlePayment(
  new PublicKey(DEVNET_WHEEL_OF_FATE_CONFIG_ADDRESS),
  sourceTokenAccount
  wallet.publicKey!,
  // new PublicKey("FkgPYryuNgmJepPRDHoFhMo9bAZVSR7D2GQnCjd2AJQ8") // one of the valid NFT held by current player (or undefined)
);

await lsPayments.provider.sendAndConfirm!(handlePaymentTxn, [], { skipPreflight: true });

Start a free game:

This methods can be passed an NFT mint belonging to the tx signer.

If the user owns:

  • a squirrel: the cost is 1 token
  • a "the hallowed": the cost is 2 tokens
  • none of the above: the cost is 3 tokens

Final cost is calculated onchain.

import { ARKADE_FREE_PLAY } from "@ls-arkade/payments";

const sourceTokenAccount = getAssociatedTokenAddressSync(
  ARKADE_FREE_PLAY,
  wallet.publicKey!
);

const sourceTokenAccountInfo = await connection.getAccountInfo(sourceTokenAccount);

if (!sourceTokenAccountInfo) {
  const createATATx = new Transaction().add(createAssociatedTokenAccountInstruction(
    wallet.publicKey!,
    sourceTokenAccount,
    wallet.publicKey!,
    ARKADE_FREE_PLAY
  ));
  await lsPaymentsProgram.provider.sendAndConfirm!(createATATx);
}

const handlePaymentTxn = await transactions.handlePayment(
  new PublicKey(DEVNET_WHEEL_OF_FATE_CONFIG_ADDRESS),
  sourceTokenAccount
  wallet.publicKey!,
  undefined, // new PublicKey("FkgPYryuNgmJepPRDHoFhMo9bAZVSR7D2GQnCjd2AJQ8") // one of the valid NFT held by current player
  ARKADE_FREE_PLAY
);

await lsPayments.provider.sendAndConfirm!(handlePaymentTxn, [], { skipPreflight: true });