@fractalshq/token2022-wrapper
v0.1.5
Published
Utilities and instruction builders for wrapping Token-2022 mints into SPL Token mints via the Token2022 Wrapper program.
Readme
@fractalshq/token2022-wrapper
Utilities and instruction builders for wrapping Token-2022 mints into SPL Token mints via the Token2022 Wrapper program.
Install
npm install @fractalshq/token2022-wrapper bn.js @solana/web3.js @solana/spl-tokenBuild locally (isolate from repo):
cd packages/token2022-wrapper
rm -rf node_modules
npm i
npm run buildUsage
Default Program (XNET Wrapper)
import { Connection, PublicKey, Transaction } from '@solana/web3.js';
import { buildWrap2022ToSplIx, getWrapperTokenMint } from '@fractalshq/token2022-wrapper';
const connection = new Connection('https://api.mainnet-beta.solana.com');
const token2022Mint = new PublicKey('...');
const owner = new PublicKey('...');
const { preIxs, ixs, wrapperMint } = await buildWrap2022ToSplIx({
connection,
token2022Mint,
owner,
amount: 1_000_000, // base units per token2022 decimals
createAtaIfMissing: true,
});
const tx = new Transaction();
(preIxs ?? []).forEach(ix => tx.add(ix));
ixs.forEach(ix => tx.add(ix));
console.log('Wrapper SPL mint:', wrapperMint.toBase58());Custom Wrapping Contract
import { Connection, PublicKey, Transaction } from '@solana/web3.js';
import { buildWrap2022ToSplIx, getWrapperTokenMint } from '@fractalshq/token2022-wrapper';
const connection = new Connection('https://api.mainnet-beta.solana.com');
const token2022Mint = new PublicKey('...');
const owner = new PublicKey('...');
// Use a custom Token2022 wrapper program
const customProgramId = new PublicKey('YourCustomWrapperProgramIdHere');
const { preIxs, ixs, wrapperMint } = await buildWrap2022ToSplIx({
connection,
token2022Mint,
owner,
amount: 1_000_000, // base units per token2022 decimals
createAtaIfMissing: true,
programId: customProgramId, // Specify custom program ID
});
const tx = new Transaction();
(preIxs ?? []).forEach(ix => tx.add(ix));
ixs.forEach(ix => tx.add(ix));
console.log('Custom wrapper SPL mint:', wrapperMint.toBase58());Important Notes
Wrapper Contract Deployment
When using custom wrapping contracts (by specifying a programId), you are responsible for deploying and managing your own Token2022 Wrapper program. This library only provides the instruction builders and utilities to interact with any deployed Token2022 Wrapper program.
- The default XNET Wrapper program (
22WrapbNKwPSy3HcGQTTJpgv43tszbZdTEfBEWmGYX2V) is maintained and available for use - For custom deployments, ensure your wrapper program implements the same instruction interface and PDA derivation logic
- All PDAs (wrapper mint, reserve authority, token accounts) are derived deterministically based on the program ID
Exports
buildWrap2022ToSplIx(params)- Main wrapper function (accepts optionalprogramId)createInitializeWrapperTokenInstruction(...)- Initialize wrapper (accepts optionalprogramId)createDepositAndMintWrapperTokensInstruction(...)- Deposit and mint wrapper tokens (accepts optionalprogramId)createWithdrawAndBurnWrapperTokensInstruction(...)- Withdraw and burn wrapper tokens (accepts optionalprogramId)- PDA helpers (
getWrapperTokenMint,getReserveAuthority,getReserveAuthorityTokenAccount) - accept optionalprogramId - Constants and utilities
License
MIT
