@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 |