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

@streamflow/distributor

v7.0.0-alpha.5

Published

JavaScript SDK to interact with Streamflow Airdrop protocol.

Downloads

642

Readme

JS SDK to interact with Streamflow Airdrop.

This package allows you to create, claim, clawback a Token Distributor.

Token Distributor essentially that allows you to Airdrop tokens to multiple (thousands or even millions) of recipients with constant fees for the Sender. Recipient will pay gas fees when claiming tokens.

You can also use getClaims and getDistributors to fetch active claims and distributors respectively.


Installation

npm i -s @streamflow/common @streamflow/distributor

or

yarn add @streamflow/common @streamflow/distributor

Documentation

API Documentation available here: docs site →

Import SDK

Most common imports:

import { ICluster } from "@streamflow/common";
import { SolanaDistributorClient } from "@streamflow/distributor/solana";

Check the SDK for other types and utility functions.

Create DistributorClient instance

Solana

const client = new SolanaDistributorClient({
  clusterUrl: "https://api.mainnet-beta.solana.com",
  cluster: ICluster.Mainnet,
});

Create an Airdrop (Distributor account)

const now = Math.floor(Date.now() / 1000);

const solanaParams = {
    invoker: wallet, // SignerWalletAdapter or Keypair of Sender account
    isNative: // [optional] [WILL CREATE A wSOL Airdrop] Needed only if you need to Airdrop Solana native token
};

const res = await client.create(
  {
    mint: "Gssm3vfi8s65R31SBdmQRq6cKeYojGgup7whkw4VCiQj", // mint
    version: now, // version of the Airdrop, version will be used to generate unique address of the Distributor Account
    root: [
      54, 218, 49, 68, 131, 214, 250, 113, 37, 143, 167, 73, 17, 54, 233, 26, 141, 93, 28, 186, 137, 211, 251, 205,
      240, 192, 134, 208, 108, 246, 0, 191,
    ], // Merkle root
    maxNumNodes: 4, // Number of recipients
    maxTotalClaim: "4000000000", // Total amount to distribute
    unlockPeriod: 1, // Unlock period in seconds
    startVestingTs: 0, // Timestamp when Airdrop starts
    endVestingTs: now + 3600 * 24 * 7, // Timestamp when Airdrop ends
    clawbackStartTs: now + 5, // Timestamp after which Airdrop can be clawed back to the Sender address
    claimsClosable: false, // Whether individual Claims can be closed by the Sender
  },
  solanaParams,
);

Claim an Airdrop

const solanaParams = {
    invoker: recipient, // SignerWalletAdapter or Keypair of Recipient account
};

const claimRes = await client.claim(
  {
    id: res.metadataId, // address of the Distributor Account
    proof: [
      [
        36, 11, 128, 61, 125, 228, 9, 50, 112, 51, 54, 201, 213, 81, 228, 216, 62, 191, 68, 63, 59, 125, 163, 77, 44,
        88, 170, 65, 139, 25, 147, 145,
      ],
      [
        53, 101, 204, 14, 202, 64, 98, 238, 49, 6, 119, 208, 98, 195, 150, 81, 191, 55, 46, 103, 91, 245, 121, 195,
        43, 104, 75, 183, 12, 38, 37, 153,
      ],
    ], // Merkle Proof used to verify claim
    amountUnlocked: "0", // Total amount unlocked for a Recipient
    amountLocked: "1000000000", // Total amount locked for a Recipient
  },
  solanaParams,
);

Clawback an Airdrop

Returns all funds to the original Sender.

  • only Sender can clawback funds before Airdrop has ended;
  • anyone can clawback funds a day after Airdrop has ended - funds will still go to the original Sender;
const solanaParams = {
    invoker: sender, // SignerWalletAdapter or Keypair of Invoker account
};
const clawbackRes = await client.clawback({ id: res.metadataId }, solanaParams);

Handling errors

GenericStreamClient wraps all errors when making on-chain calls with ContractError error class:

  • this class inherits original traceback
  • error may optionally contain contractErrorCode property that can be further mapped to a specific Contract error
  • for createMultiple method errors are wrapped individually for every recipient address
  • please check documentation for enums AnchorErrorCode and ContractErrorCode at solana/types.ts to see short description for each error

Additional notes

Streamflow Distributor protocol program IDs

| Solana | | | ------- | -------------------------------------------- | | Devet | MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N | | Mainnet | |