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

@mirrorworld/library.wallet.new

v1.0.0-alpha.15

Published

game wallet SDK

Downloads

70

Readme

This SDK contains the client side methods for the Game Wallet Solana Program

Installation

🚨 Please make sure to add this NPM token in your .npmrc file: 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

yarn add @mirrorworld/library.wallet

Usage

Import the GameWalletLib instance into your client. It expects a connection and wallet instance. You can get these by using one of the Solana Wallet Adapters your application will use to connect to a Solana RPC.

These transactions require you to sign the transaction using your wallet. That means you need to have SOL. You can request SOL from the SolFaucet

import {
    GameWalletLib,
    GAME_WALLET_PROGRAM_ID
} from '@mirrorworld/library.wallet';

const connection = useConnection()

/** Make sure your wallet is initialized and connected to the browser before providing to GameWalletLib */
const wallet = useWallet()

/** GameWalletLib instance */
const gameWalletLib = new GameWalletLib(
    GAME_WALLET_PROGRAM_ID,
    connection,
    wallet
);

Demo

Example: You can see example project in this repo here:

Create Token Config

The Token Config PDA account is the main part of the Game Wallet Program which is created from the token mint account.

    const tokenDecimal = 9;
const isPaused = false;
const canDeposit = true;
const canWithdraw = true;
const canSpend = true;
const canDistribute = true;
const isWithdrawServiceFeeEnable = true;
const withdrawServiceFeePercentage = new BN(1);
const isSpendServiceFeeEnable = false;
const spendServiceFeePercentage = new BN(1);
const isDistributionServiceFeeEnable = false;
const distributionServiceFeePercentage = new BN(1);
const isMinWithdrawEnable = false;
const isMaxWithdrawEnable = false;
const minWithdraw = new BN((0.1 * LAMPORTS_PER_SOL));
const maxWithdraw = new BN((3.5 * LAMPORTS_PER_SOL));

let initializeTokenConfigTransaction = await gameWalletLib.createInitializeTokenConfigTransaction(tokenDecimal, isPaused, canDeposit, canWithdraw, canSpend, canDistribute,
    isWithdrawServiceFeeEnable, withdrawServiceFeePercentage, isSpendServiceFeeEnable, spendServiceFeePercentage, isDistributionServiceFeeEnable, distributionServiceFeePercentage,
    isMinWithdrawEnable, isMaxWithdrawEnable, minWithdraw, maxWithdraw,
    signingAuthorityWalletKeypair.publicKey, signingAuthorityWalletKeypair.publicKey, tokenMintAccount, incomeAccount);

gameWalletLib.signTransaction(initializeTokenConfigTransaction, signingAuthorityWalletSecretKey);

const initializeTokenConfigTransactionHash = await connection.sendRawTransaction(initializeTokenConfigTransaction.serialize());

console.log("initializeTokenConfigTransactionHash: ", initializeTokenConfigTransactionHash);

See example here

Deposit

The deposit method in the program create the user token config and deposit the amount in the deposit pool

let depositTransaction = await gameWalletLib.createDepositTransaction(amount, userWalletKeypair.publicKey, signingAuthorityWalletKeypair.publicKey,
    tokenMintAccount, userWalletKeypair.publicKey);

gameWalletLib.signTransaction(depositTransaction, signingAuthorityWalletSecretKey);
gameWalletLib.signTransaction(depositTransaction, userWalletSecretKey);

const depositTransactionHash = await connection.sendRawTransaction(depositTransaction.serialize());

console.log("depositTransactionHash: ", depositTransactionHash);

See example here

Withdraw

The Withdrawal method in the program is the created by the user they want to withdraw amount from the deposit pool

let withdrawTransaction = await gameWalletLib.createWithdrawTransaction(amount, userWalletKeypair.publicKey, signingAuthorityWalletKeypair.publicKey,
    tokenMintAccount, userWalletKeypair.publicKey, incomeAccount, userWalletKeypair.publicKey);

gameWalletLib.signTransaction(withdrawTransaction, signingAuthorityWalletSecretKey);
gameWalletLib.signTransaction(withdrawTransaction, userWalletSecretKey);

const withdrawTransactionHash = await connection.sendRawTransaction(withdrawTransaction.serialize());

console.log("withdrawTransactionHash: ", withdrawTransactionHash);

See example here

Withdraw Without User

The Withdrawal without user method in the program is the created by the user they want to withdraw amount from the deposit pool

let withdrawWithoutUserTransaction = await gameWalletLib.createWithdrawWithoutUserTransaction(amount, signingAuthorityWalletKeypair.publicKey, signingAuthorityWalletKeypair.publicKey,
    tokenMintAccount, userWalletKeypair.publicKey, incomeAccount, userWalletKeypair.publicKey);

gameWalletLib.signTransaction(withdrawWithoutUserTransaction, signingAuthorityWalletSecretKey);

const withdrawWithoutUserTransactionHash = await connection.sendRawTransaction(withdrawWithoutUserTransaction.serialize());

console.log("withdrawWithoutUserTransactionHash: ", withdrawWithoutUserTransactionHash);

See example here

Spend

The spend method in the program is for when user spend amount from his deposit pool

    let spendTransaction = await gameWalletLib.createSpendTransaction(amount, userWalletKeypair.publicKey, signingAuthorityWalletKeypair.publicKey,
    tokenMintAccount, userWalletKeypair.publicKey, incomeAccount);

gameWalletLib.signTransaction(spendTransaction, signingAuthorityWalletSecretKey);
gameWalletLib.signTransaction(spendTransaction, userWalletSecretKey);

const spendTransactionHash = await connection.sendRawTransaction(spendTransaction.serialize());

console.log("spendTransactionHash: ", spendTransactionHash);

See example here

Spend Without User

The spend without user method in the program is for when user spend amount from his deposit pool and user don't need to sign the transaction

        let spendWithoutUserTransaction = await gameWalletLib.createSpendWithoutUserTransaction(amount, signingAuthorityWalletKeypair.publicKey, signingAuthorityWalletKeypair.publicKey,
    tokenMintAccount, userWalletKeypair.publicKey, incomeAccount);

gameWalletLib.signTransaction(spendWithoutUserTransaction, signingAuthorityWalletSecretKey);

const spendWithoutUserTransactionHash = await connection.sendRawTransaction(spendWithoutUserTransaction.serialize());

console.log("spendWithoutUserTransactionHash: ", spendWithoutUserTransactionHash);

See example here

Added Deposit Supply

The add deposit supply method in the program is for add the supply in the deposit pool

let addDepositSupplyTransaction = await gameWalletLib.createAddDepositSupplyTransaction(amount, signingAuthorityWalletKeypair.publicKey, signingAuthorityWalletKeypair.publicKey,
    tokenMintAccount, signingAuthorityWalletKeypair.publicKey);

gameWalletLib.signTransaction(addDepositSupplyTransaction, signingAuthorityWalletSecretKey);

const addDepositSupplyTransactionHash = await connection.sendRawTransaction(addDepositSupplyTransaction.serialize(), {skipPreflight: false});

console.log("addDepositSupplyTransactionHash: ", addDepositSupplyTransactionHash);

See example here

Added Distribution Supply

The add distribution supply method in the program is for add the supply in the distribution pool

let addDistributeSupplyTransaction = await gameWalletLib.createAddDistributeSupplyTransaction(amount, signingAuthorityWalletKeypair.publicKey, signingAuthorityWalletKeypair.publicKey,
    tokenMintAccount, signingAuthorityWalletKeypair.publicKey);

gameWalletLib.signTransaction(addDistributeSupplyTransaction, signingAuthorityWalletSecretKey);

const addDistributeSupplyTransactionHash = await connection.sendRawTransaction(addDistributeSupplyTransaction.serialize());

console.log("addDistributeSupplyTransactionHash: ", addDistributeSupplyTransactionHash);

See example here

Distribution

The distribution method in the program is for when user eran new token then those token will be added to the user deposit pool from the distribution pool

let createDistributeTransaction = await gameWalletLib.createDistributeTransaction(amount, userWalletKeypair.publicKey, signingAuthorityWalletKeypair.publicKey,
    tokenMintAccount, userWalletKeypair.publicKey, incomeAccount);

gameWalletLib.signTransaction(createDistributeTransaction, signingAuthorityWalletSecretKey);
gameWalletLib.signTransaction(createDistributeTransaction, userWalletSecretKey);

const createDistributeTransactionHash = await connection.sendRawTransaction(createDistributeTransaction.serialize());

console.log("createDistributeTransactionHash: ", createDistributeTransactionHash);

See example here

Distribution Without User

The distribution without user method in the program is for when user eran new token then those token will be added to the user deposit pool from the distribution pool and user not need to sign the transaction

    let distributeWithoutUserTransaction = await gameWalletLib.createDistributeWithoutUserTransaction(amount, signingAuthorityWalletKeypair.publicKey, signingAuthorityWalletKeypair.publicKey,
    tokenMintAccount, userWalletKeypair.publicKey, incomeAccount);

gameWalletLib.signTransaction(distributeWithoutUserTransaction, signingAuthorityWalletSecretKey);

const distributeWithoutUserTransactionHash = await connection.sendRawTransaction(distributeWithoutUserTransaction.serialize());

console.log("distributeWithoutUserTransactionHash: ", distributeWithoutUserTransactionHash);

See example here

Accounts

| Name | Description | |:-------------------------------:|:--------------------------------------------:| | Token Config | Program config for the token pda account | | User Token Config | User config related to the token pda account | | Deposit Pool | Deposit Pool pda account | | Deposit Pool Token Account | Deposit Pool pda token account | | Distribution Pool | Distribution Pool pda account | | Distribution Pool Token Account | Distribution Pool pda token account |