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

@agreewe/solana-blockchain-contracts

v0.1.5

Published

Interface to the Fanout wallet Solana Blockchain contract

Downloads

40

Readme

Introduction

This package is derived from the Rust program found in programs/SolSplitter via a script using Solita.

How to use

The interface for functions from the rust programs are found in /packages/sdk/generated. These files should NOT have to be touched unless necessary. The interactions with these functions can be found in packages/sdk/index.ts.

The general idea of the functions found in index.ts is as follows:

  1. Call functions to generated instructions
  2. Signing of instructions/transaction
  3. Send to Solana blockchain

Initializing a Fanout Wallet

const connection = new Connection("devnet", "confirmed");
let fanoutSdk: FanoutClient;

authorityWallet = useWallet() // wallet instance

fanoutSdk = new FanoutClient(
  connection,
  new NodeWallet(new Account(authorityWallet.secretKey))
);

const init = await fanoutSdk.initializeFanout({
  totalShares: 100,
  name: `Test${Date.now()}`,
  membershipModel: MembershipModel.Wallet,
  phaseLimits: []
  
});

Adding Members

For adding members, a sample usecase is as follows. Input parameters for function can be found in index.ts

const member = new Keypair()
const {membershipAccount} = await fanoutSdk.addMemberWallet({
    fanout: init.fanout,
    fanoutNativeAccount: init.nativeAccount,
    membershipKey: member.publicKey,
    shares: [50]
});

Distribution

To distribute all, call the distributeAll function as shown below.

await fanoutSdk.distributeAll(
    {
        fanout: init.fanout,
        payer: signer
    }
)

Transfer Shares

To transfer shares from one member wallet to another, call the transferShares function as shown below.

await fanoutSdk.transferShares({
    fromMember: member0Wallet.publicKey,
    toMember: member1Wallet.publicKey,
    fanout: builtFanout.fanout,
    shares: [40,40,30]
});

Quick start

Install the package from npm:

yarn add @agreewe/solana-blockchain-contracts

This is how you'd setup

import { Keypair, LAMPORTS_PER_SOL} from "@solana/web3.js";
import * as anchor from "@project-serum/anchor"
import {NodeWallet} from "@project-serum/common";
import {
    Fanout,
    FanoutClient,
    FanoutMembershipVoucher,
} from "@agreewe/solana-blockchain-contracts";


const connection = new anchor.web3.Connection("devnet", "confirmed");
const authorityWallet = Keypair.generate();

await connection.requestAirdrop(authorityWallet.publicKey, LAMPORTS_PER_SOL * 2);

const fanoutSdk = new FanoutClient(
    connection,
    new NodeWallet(new Account(authorityWallet.secretKey))
);

const phaseLimits = [100, 200];

// Initialize the Wallet
const {fanout} = await fanoutSdk.initializeFanout({
    totalShares: 100,
    name: `Your Globally Unique Wallet Name`,
    membershipModel: MembershipModel.Wallet,
    phaseLimits: phaseLimits,
});

// fanout is your fanout config address
// nativeAccount is your account address

// Retrieve the On-chain  Wallet
const fanoutAccount = await fanoutSdk.fetch<Fanout>(
    fanout,
    Fanout
);

console.log(fanoutAccount); // Shows you all the parameters in your wallet

// This is your Wallet Address
let AccountKey = fanoutAccount.accountKey // this is the same thing as nativeAccount above

// Add members

const member1 = new Keypair();
const {membershipAccount1} = await fanoutSdk.addMemberWallet({
    fanout: init.fanout,
    fanoutNativeAccount: init.nativeAccount,
    membershipKey: member1.publicKey,
    shares: 10
});

//Repeat for all members until sum(shares) == totalShares from initialization
...

// Send some Sol to the Wallet so you can distribute
await connection.requestAirdrop(AccountKey, 2);

// Generate the distribution instructions
let distMember1 = await fanoutSdk.distributeWalletMemberInstructions(
    {
        distributeForMint: false,
        member: member1.wallet.publicKey,
        fanout: fanout,
        payer: authorityWallet.publicKey, // This can be changed to whoever sends the tx
    },
);

// Send the distribution instructions
const tx = await fanoutSdk.sendInstructions(
    [...distMember1.instructions],
    [authorityWallet],
    authorityWallet.publicKey
);
if (!!tx.RpcResponseAndContext.value.err) {
    const txdetails = await connection.getConfirmedTransaction(tx.TransactionSignature);
    console.log(txdetails, tx.RpcResponseAndContext.value.err);
}

// Member1 Should have 0.2 more sol in their wallet