@blockassetlabs/staking
TypeScript icon, indicating that this package has built-in type declarations

2.4.9 • Public • Published

Blockasset Labs Staking

This SDK helps developers get started with the on-chain staking tool provided by Blockasset Labs. It focuses its API on common use-cases to provide a smooth developer experience.

Addresses

Program addresses are the same on devnet, and mainnet-beta.

Get Started

Create Project

To setup a staking you need to have a Project first. If you don't have one, easiest way to create your own project is by using blockasset labs "Create Project" page.

Attribute Type Required Description
name String Yes Project name
authorities Array Yes List of authorities who have access to update project detail and create, update, or close project stakings.

If you are interested on creating project using package, check out "Create Staking using package" section

Create Staking

You can create Staking for you project by first go to your project page and then create staking page or simply go to this link: https://labs.blockasset.co/projects/<project-id>/create-staking

Attribute Type Required Description
Category String No Staking Category to be saved on chain
Prize Mint PublicKey Yes Mint address of the NFT that will be sent to the winner once the staking resolved
Token Mint PublicKey Yes Mint address of the token that will be used as payment for purchasing the tickets
Ticket Price BN Yes Price of each tickets in lamports
Max Tickets Number Yes Maximum number of tickets in each staking
Start BN Yes Staking start timestamp
End BN Yes Staking end timestamp
Max Tickets Per User Number Yes Maximum percentage of the entries that each wallet can obtain

If you are interested on creating staking using package, check out "Create Project using package" section

Participate in a Staking

Your users can participate in your staking by going to this address: https://labs.blockasset.co/projects/<stakinge-id>

Attribute Type Required Description
quantity Number Yes Number of entries that user wants to obtain

Installation

Installing the package using yarn:

yarn add @blockassetlabs/project @blockassetlabs/staking

You can also use npm instead, if you'd like:

npm install @blockassetlabs/project @blockassetlabs/staking

🔥 Pro Tip: Check out our implementations on "BlockassetLabs UI" repository.

Documentation

Fetch Project Info

import { getProject } from "@blockassetlabs/project";

const project = getProject(connection, projectId);

Fetch Stakings of a Project

import { getStakingsByProjectId } from "@blockassetlabs/staking";

const stakings = await getStakingsByProjectId(connection, projectId);

Fetch single Staking info

import { getStaking } from "@blockassetlabs/staking";

const stakings = await getStaking(connection, stakingId);

Fetch Tickets data for a single Staking

import { getTickets } from "@blockassetlabs/staking";

const stakings = await getTickets(connection, ticketId);

Create Staking

This transaction can only be called by one of the project authorities

import { createStaking } from "@blockassetlabs/staking";

const { signature, stakingId } = await createStaking(
  connection,
  wallet as Wallet,
  {
    // Project Id
    projectId: project.pubkey,

    // Mint address of staking prize NFT
    prizeMint: new PublicKey(formValues.prizeMint),

    // Mint address of the acceptable token for entrance fee
    // If not provided the payment will be based on sol
    tokenMint: formValues.tokenMint ?? new PublicKey(formValues.tokenMint),

    // Wallet address of treasury account for the entrance fees
    // No need to set any if the burn rate is 100
    treasury: formValues.tokenMint ?? new PublicKey(formValues.treasury),

    // Burn rate of the tokenMint
    // Can be between 1 to 100
    burnRate: formValues.burnRate ?? new PublicKey(formValues.burnRate),

    // Entrance fee for acquiring 1 staking entrance in natural amounts
    ticketFee: new BN(formValues.ticketFee),

    // Total tickets of a staking
    maxTickets: formValues.maxTickets,

    // Maximum percentage of the total tickets that each wallet can redeem
    // Default is 100
    maxTicketsPerWalletRate: formValues.maxTicketsPerWalletRate,

    // Start date timestamp
    start: new BN(formValues.start.getTime() / 1000),

    // End date timestamp
    end: new BN(formValues.end.getTime() / 1000),

    // Additional info
    category: formValues.category,
  },
);

Update Staking

This transaction can only be called by one of the project authorities

import { updateStaking } from "@blockassetlabs/staking";

const signature = await updateStaking(connection, wallet as Wallet, {
  // Staking Id
  stakingId: activeStaking.pubkey,

  // Project Id
  projectId: project.pubkey,

  // Mint address of staking prize NFT
  prizeMint: new PublicKey(formValues.prizeMint),

  // Mint address of the acceptable token for entrance fee
  // If not provided the payment will be based on sol
  tokenMint: formValues.tokenMint ?? new PublicKey(formValues.tokenMint),

  // Wallet address of treasury account for the entrance fees
  // No need to set any if the burn rate is 100
  treasury: formValues.tokenMint ?? new PublicKey(formValues.treasury),

  // Burn rate of the tokenMint
  // Can be between 1 to 100
  burnRate: formValues.burnRate ?? new PublicKey(formValues.burnRate),

  // Entrance fee for acquiring 1 staking entrance in natural amounts
  ticketFee: new BN(formValues.ticketFee),

  // Total tickets of a staking
  maxTickets: formValues.maxTickets,

  // Maximum percentage of the total tickets that each wallet can redeem
  // Default is 100
  maxTicketsPerWalletRate: formValues.maxTicketsPerWalletRate,

  // Start date timestamp
  start: new BN(formValues.start.getTime() / 1000),

  // End date timestamp
  end: new BN(formValues.end.getTime() / 1000),

  // Additional info
  category: formValues.category,
});

Buy Tickets

This is a public transaction and can only be called by anyone

import { redeemTickets } from "@blockassetlabs/staking";

const signature = await redeemTickets(connection, wallet as Wallet, {
  // Number of tickets
  quantity,

  // Staking id
  stakingId: activeStaking.pubkey,
});

Resolve Staking

Resolving the staking is an on-chain weighted random selection

This is a public transaction, so anybody can resolve the staking

import { resolveStaking } from "@blockassetlabs/staking";

const signature = await resolveStaking(
  new Transaction(),
  connection,
  wallet as Wallet,
  {
    // Staking id
    stakingId: activeStaking.pubkey,
  },
);

Claim Prize

Only the staking winner can call call this transaction to claim its prize

import { claimPrize } from "@blockassetlabs/staking";

const signature = await claimPrize(connection, wallet as Wallet, {
  // Staking id
  stakingId: activeStaking.pubkey,
});

Close Staking

It's possible to recover the funds used to pay rent for the data stored on-chain by closing the Staking.

  • If the prize is not claimed yet this action will transfer back the prize to the caller account.
  • This action is not recoverable and permanently remove the access to the staking.

This transaction can only be called by one of the project authorities

import { closeStaking } from "@blockassetlabs/staking";

const signature = await closeStaking(connection, wallet as Wallet, {
  // Staking id
  stakingId: activeStaking.pubkey,
});

Create Project

This is a public transaction, so anybody can create a new project

import { withInitProject } from "@blockassetlabs/project";

const [transaction, projectId] = await withInitProject(
  new Transaction(),
  connection,
  wallet as Wallet,
  {
    authorities: [wallet.publicKey],
    name: formValues.name,
  },
);
await executeTransaction(connection, wallet as Wallet, transaction, {
  silent: false,
  signers: [],
});

Update Project

This transaction can only be called by one of the project authorities

import { withUpdateProject } from "@blockassetlabs/project";

const transaction = await withUpdateProject(
  new Transaction(),
  connection,
  wallet as Wallet,
  {
    projectId: projectId,
    authorities: [wallet.publicKey],
    name: formValues.name,
  },
);
await executeTransaction(connection, wallet as Wallet, transaction, {
  silent: false,
  signers: [],
});

Close Project

It's possible to recover the funds used to pay rent for the data stored on-chain by closing the Project.

  • Although closing a project will not affect any of its stakings, it's highly recommended to close its stakings first because once the project closed, you will no longer have access to its stakings to modify or close.
  • This action is not recoverable and permanently remove the access to the project.

This transaction can only be called by one of the project authorities

import { withUpdateProject } from "@blockassetlabs/project";

const transaction = await withCloseProject(
  new Transaction(),
  connection,
  wallet as Wallet,
  {
    projectId: projectId,
  },
);
await executeTransaction(connection, wallet as Wallet, transaction, {
  silent: false,
  signers: [],
});

Questions & Support

If you are developing using Blockasset contracts and libraries, feel free to reach out for support on Discord. We will work with you or your team to answer questions, provide development support and discuss new feature requests.

For issues please, file a GitHub issue.

https://discord.gg/blockasset

License

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.4.981latest

Version History

VersionDownloads (Last 7 Days)Published
2.4.981
2.4.80
2.4.70
2.4.60
2.4.50
2.4.40
2.4.30
2.4.21
2.4.10
2.4.00
2.3.50
2.3.40
2.3.30
2.3.20
2.3.10
2.3.00

Package Sidebar

Install

npm i @blockassetlabs/staking

Weekly Downloads

82

Version

2.4.9

License

MIT

Unpacked Size

1.44 MB

Total Files

92

Last publish

Collaborators

  • nikhil_blockasset
  • sorooshblockasset