PixFun
  • 👋Welcome
  • Overview
    • 🚀Platform Product
      • 💻Data Analytics
      • 🤖Ai agents Creation
      • 🚀Exclusive launchpad
      • 🟢What are PixPoints?
      • 👑Pixel King
      • 💹Bonding Curve
      • 💡Our Mission
      • Staking
      • Revenue Model
      • Roadmap
  • 🥧Tokenomics
  • 👨‍💻Developer Docs
Powered by GitBook
On this page
  • Initializing the program
  • Making swaps
  • Reading the bonding curve
  • Swaping on Raydium

Developer Docs

PreviousTokenomics

Last updated 4 months ago

Learn how to create buy/ sell transactions for PixFun. The simplest way to interact with out Solana Program is by using the Anchor and .

Initializing the program

import { PixFun } from "@/contracts/pix_fun";
import idl from "@/contracts/pix_fun.json";
import { AnchorProvider, Program, Wallet } from "@coral-xyz/anchor";
import { bs58 } from "@coral-xyz/anchor/dist/cjs/utils/bytes";
import { Connection, Keypair } from "@solana/web3.js";
    
const connection = new Connection(process.env.RPC_URL!, "confirmed");
const wallet = new Wallet(Keypair.fromSecretKey(bs58.decode(process.env.PRIVATE_KEY!)));
const program = new Program(
  idl  as  PixFun,
  new  AnchorProvider(connection, wallet),
);

Making swaps

You can create either a fixedIn or fixedOut type swap. Both types are available within the same instruction, passing values for your desired type and 0 for the other.

  • You should specify wether you want to buy or to sell with the isBuy boolean.

  • For a fixedIn swap, you pass the input SOL (or token) amount as amountIn and the slippage adjusted value as minAmountOut. You leave amountOut and maxAmountIn as 0.

  • For a fixedOut swap, you pass the desired SOL (or token) amount as amountOut and the slippage adjusted value as maxAmountIn. You leave amountIn and minAmountOut as 0. The on-chain program will calculate your input value.

You can consider this code for a simplified view:

const amountIn = swapType === "fixedIn" ? amount : 0;
const minAmountOut = swapType === "fixedIn" ? slippageAmount : 0;

const amountOut = swapType === "fixedOut" ? amount : 0;
const maxAmountIn = swapType === "fixedOut" ? slippageAmount : 0;

const ix = await program.methods
      .swap(
        tradeType === "buy",
        amountIn,
        minAmountOut,
        amountOut,
        maxAmountIn,
      )
      .accounts({ mint: tokenAddress, user, program: program.programId })
      .instruction();

IMPORTANT: The program will take care of creating the Token Account, so you don't need to add a separate instruction for it.

Reading the bonding curve

const [poolAddress] = PublicKey.findProgramAddressSync(
    [Buffer.from("pool"), new PublicKey(tokenAddress).toBuffer()],
    new PublicKey(program.programId),
 );
const poolState = await program.account.poolState.fetch(poolAddress);

// Account fields:
const {
    virtualSolReserves,
    virtualTokenReserves,
    realTokenReserves,
    realSolReserves,
    tokenTotalSupply,
    complete,
  } = poolState;

Important: The bonding curve price, market cap and liquidity are calculated based on the virtual reserves above.

Swaping on Raydium

Once a token completes its bonding curve, it migrates to a pool, with its respective . The PixFun token is set as Base and SOL is set as Quote.

👨‍💻
IDL
Type
Raydium CPMM
SDK