@memoo/memoo-sdk
v0.1.0
Published
An SDK for interacting with Memoo bonding curve programs on Solana
Downloads
16
Maintainers
Readme
Memoo SDK
An SDK for interacting with Memoo bonding curve programs on Solana.
Installation
npm install @memoo/memoo-sdk
# or
yarn add @memoo/memoo-sdkSetup
The SDK supports multiple ways to initialize. The built-in IDL is recommended for the simplest setup:
Option 1: Using Built-in IDL (Recommended - Simplest)
The SDK includes the IDL by default, so you don't need to import it manually:
import { MemooSDK } from '@memoo/memoo-sdk'
import { Connection, PublicKey, Keypair } from '@solana/web3.js'
import { Wallet } from '@coral-xyz/anchor'
// Initialize connection and wallet
const connection = new Connection('https://api.mainnet-beta.solana.com')
const wallet = Keypair.generate() // or use your wallet
// Create SDK instance - IDL is built-in, no need to import!
const sdk = new MemooSDK({
connection,
wallet: wallet as unknown as Wallet, // Wallet for AnchorProvider
programId: new PublicKey('YOUR_PROGRAM_ID'),
globalMemeConfigId: new PublicKey('YOUR_GLOBAL_MEME_CONFIG_ID'),
owner: wallet.publicKey,
defaultDecimals: 9,
metaDataPublicKey: new PublicKey(
'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'
),
defaultPriorityFee: 1000000
})Option 2: Using Custom IDL
If you need to use a custom IDL (e.g., for a different program version):
import { MemooSDK } from '@memoo/memoo-sdk'
import { Connection, PublicKey, Keypair } from '@solana/web3.js'
import { Wallet, Idl } from '@coral-xyz/anchor'
import IDL from './idl/memoo.json' // Your custom IDL file
// Initialize connection and wallet
const connection = new Connection('https://api.mainnet-beta.solana.com')
const wallet = Keypair.generate() // or use your wallet
// Create SDK instance with custom IDL
const sdk = new MemooSDK({
connection,
idl: IDL as Idl, // Your custom IDL definition
wallet: wallet as unknown as Wallet, // Wallet for AnchorProvider
programId: new PublicKey('YOUR_PROGRAM_ID'),
globalMemeConfigId: new PublicKey('YOUR_GLOBAL_MEME_CONFIG_ID'),
owner: wallet.publicKey,
defaultDecimals: 9,
defaultPriorityFee: 1000000
})Option 3: Using Program Instance
Alternatively, you can create the program yourself and pass it to the SDK:
import { MemooSDK } from '@memoo/memoo-sdk'
import { Connection, PublicKey, Keypair } from '@solana/web3.js'
import { Program, AnchorProvider, Idl } from '@coral-xyz/anchor'
import { IDL } from '@memoo/memoo-sdk' // Or import your own IDL
// Initialize connection and wallet
const connection = new Connection('https://api.mainnet-beta.solana.com')
const wallet = Keypair.generate() // or use your wallet
// Initialize Anchor provider and program
const provider = new AnchorProvider(connection, wallet, {})
const program = new Program(IDL as Idl, provider)
// Create SDK instance with program
const sdk = new MemooSDK({
connection,
program, // Pre-created program instance
programId: new PublicKey('YOUR_PROGRAM_ID'),
globalMemeConfigId: new PublicKey('YOUR_GLOBAL_MEME_CONFIG_ID'),
owner: wallet.publicKey,
defaultDecimals: 9,
metaDataPublicKey: new PublicKey(
'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'
),
defaultPriorityFee: 1000000
})Usage Examples
Register a Bonding Curve
const transaction = await sdk.registerBondingCurve({
memeId: new PublicKey('YOUR_MEME_ID'),
metadata: {
name: 'My Token',
symbol: 'MTK',
uri: 'https://example.com/metadata.json'
},
amount: '1.0', // Optional: initial buy amount
priorityFee: 0.001 // Optional priority fee in SOL
})
// Sign and send transaction
transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash
transaction.feePayer = wallet.publicKey
const signedTx = await wallet.signTransaction(transaction)
const txId = await connection.sendRawTransaction(signedTx.serialize())Buy Tokens
const transaction = await sdk.bondingCurveBuy({
memeId: 'YOUR_MEME_ID', // Can be string or PublicKey
amount: '0.5', // SOL amount to spend
priorityFee: 0.001 // Optional priority fee in SOL
})
transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash
transaction.feePayer = wallet.publicKey
const signedTx = await wallet.signTransaction(transaction)
const txId = await connection.sendRawTransaction(signedTx.serialize())Sell Tokens
const transaction = await sdk.bondingCurveSell({
memeId: 'YOUR_MEME_ID',
amount: '1000', // Token amount to sell
priorityFee: 0.001
})
transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash
transaction.feePayer = wallet.publicKey
const signedTx = await wallet.signTransaction(transaction)
const txId = await connection.sendRawTransaction(signedTx.serialize())Creator Claim
const transaction = await sdk.bondingCurveCreatorClaim({
memeId: 'YOUR_MEME_ID'
})
transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash
transaction.feePayer = wallet.publicKey
const signedTx = await wallet.signTransaction(transaction)
const txId = await connection.sendRawTransaction(signedTx.serialize())Airdrop Claim
const transaction = await sdk.bondingCurveAirdropClaim({
memeId: 'YOUR_MEME_ID',
encoded: messageBytes, // Uint8Array
signature: signatureBytes, // Uint8Array
signerPublicKey: signerPubKey, // PublicKey
addEd25519Instruction: true // Optional, default true
})
transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash
transaction.feePayer = wallet.publicKey
const signedTx = await wallet.signTransaction(transaction)
const txId = await connection.sendRawTransaction(signedTx.serialize())Yapper Claim
const transaction = await sdk.bondingCurveYapperClaim({
memeId: 'YOUR_MEME_ID',
encoded: messageBytes,
signature: signatureBytes,
signerPublicKey: signerPubKey,
addEd25519Instruction: true
})
transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash
transaction.feePayer = wallet.publicKey
const signedTx = await wallet.signTransaction(transaction)
const txId = await connection.sendRawTransaction(signedTx.serialize())Get Exchange Rate
const rate = await sdk.getExchangeRate({
memeId: 'YOUR_MEME_ID',
amount: '1.0',
from: 'SOL', // or "TOKEN"
type: 'Buy' // or "Sell"
})
console.log('Exchange rate:', rate)Fetch Bonding Curve Config
const config = await sdk.fetchBondingCurveConfig('YOUR_MEME_ID')
console.log('Total SOL:', config?.totalSol.toString())
console.log('Total Count:', config?.totalCount.toString())Fetch Global Config
const globalConfig = await sdk.fetchGlobalConfig()
console.log(
'Platform Fee Recipient:',
globalConfig?.platformFeeRecipient.toString()
)
console.log('Total Supply:', globalConfig?.totalSupply.toString())PDA Functions
The SDK provides helper functions for calculating PDAs:
import {
getPdaBondingCurveState,
getPdaGlobalBondingCurveConfig,
getPdaPoolSolAuthority,
getPdaBondingCurveMintAccountA,
getPdaBondingCurvePoolAuthorityA,
getPdaBondingCurveUserData,
getPdaBondingCurveMetadata
} from '@memoo/memoo-sdk'
const programId = new PublicKey('YOUR_PROGRAM_ID')
const memeId = new PublicKey('YOUR_MEME_ID')
const bondingCurveState = getPdaBondingCurveState(programId, memeId)
const globalConfig = getPdaGlobalBondingCurveConfig(
programId,
globalMemeConfigId
)
// ... etcNotes
- The SDK requires an Anchor program instance to be passed in the config
- All amounts should be provided as strings or numbers (will be converted internally)
- The
getExchangeRatemethod requires implementation of bonding curve calculation functions based on your specific formula (see TODO comments in code) - Priority fees are calculated automatically, but can be overridden
- All transactions need to be signed and sent manually (SDK only creates the transactions)
Development
# Install dependencies
yarn install
# Build
yarn build
# Watch mode
yarn watch
# Run tests
yarn testLicense
MIT
