Platform Module
The Platform Module serves as an intermediary layer between the Protocol and Marketplaces in the Cart.fun ecosystem. It enables organizations and entities to create and manage their own marketplace platforms with customized fee structures, treasury accounts, and multiple marketplaces.
Overview
The Platform Module provides a framework for creating and operating commerce platforms within the Cart.fun protocol. Organizations can establish their own commerce platforms with:
- Custom fee structures and revenue models
- Dedicated treasury accounts for fee collection
- Multiple marketplace deployments under a single platform
- Unified administration and management
- Bespoke branding and customization
Platforms require initialization under an active Protocol. Before creating a Platform, ensure the Protocol Module is properly initialized.
Account Structure
The Platform Module consists of several key account structures that store platform-specific data.
Platform Account
The Platform account is a Program Derived Address (PDA) that stores the platform configuration:
pub struct Platform {
pub admin: Pubkey, // 32 bytes - Platform administrator
pub fee_basis_points: u16, // 2 bytes - Platform fee percentage (in basis points, 100 = 1%)
pub treasury: Pubkey, // 32 bytes - Platform treasury account
pub protocol: Pubkey, // 32 bytes - Reference to the protocol account
pub is_active: bool, // 1 byte - Platform activation state
pub total_volume: u64, // 8 bytes - Total transaction volume processed
pub total_marketplaces: u64, // 8 bytes - Number of marketplaces under platform
pub bump: u8, // 1 byte - PDA bump seed
}
Platform Treasury
The Platform Treasury account is a PDA that manages platform fee collection and distribution:
pub struct Treasury {
pub authority: Pubkey, // 32 bytes - Platform PDA
pub balance: u64, // 8 bytes - Current SOL balance
pub total_collected: u64, // 8 bytes - Total fees collected
pub total_withdrawn: u64, // 8 bytes - Total amount withdrawn
pub bump: u8, // 1 byte - PDA bump seed
}
PDA Derivation
Platform-related PDAs are derived using the following seed structures:
- Name
Platform PDA- Type
- address
- Description
["platform", admin.toBuffer()]
- Name
Platform Treasury PDA- Type
- address
- Description
["platform_treasury", platform.toBuffer()]
This derivation scheme ensures that:
- Each platform is uniquely identified by its administrator
- Treasury accounts are tied to their respective platforms
- Account addresses can be deterministically derived when needed
Instructions
The Platform Module provides the following key instructions:
- Name
create_platform- Type
- instruction
- Description
Creates a new platform with the specified settings and administrator.
- Name
update_platform- Type
- instruction
- Description
Updates platform settings such as fees and activation status.
- Name
withdraw_from_treasury- Type
- instruction
- Description
Allows the platform administrator to withdraw funds from the platform treasury.
- Name
create_marketplace- Type
- instruction
- Description
Creates a new marketplace under the platform.
- Name
transfer_platform_ownership- Type
- instruction
- Description
Transfers platform administration rights to a new account.
- Name
close_platform- Type
- instruction
- Description
Closes a platform and all associated marketplaces.
Usage Examples
Creating a Platform
import { Connection, Keypair } from '@solana/web3.js'
import { CartProtocol, NetworkType } from '@cartdotfun/sdk'
async function createPlatform() {
const connection = new Connection(
'https://api.devnet.solana.com',
'confirmed',
)
const adminWallet = Keypair.fromSecretKey(/* your secret key */)
const cartProtocol = new CartProtocol({
connection,
wallet: adminWallet,
network: NetworkType.Devnet,
})
const { transaction, platformId } =
await cartProtocol.platform.createPlatform({
name: 'Digital Art Platform',
description: 'A platform for digital art and collectibles',
feeBasisPoints: 200, // 2% platform fee
})
const signature = await cartProtocol.sendAndConfirmTransaction(transaction)
console.log('Platform created:', signature)
console.log('Platform ID:', platformId)
return { platformId, signature }
}
Managing Platform Treasury
async function managePlatformTreasury(platformId) {
// Assuming cartProtocol is already initialized with admin wallet
// Check treasury balance
const treasuryBalance =
await cartProtocol.platform.getTreasuryBalance(platformId)
console.log('Treasury balance:', treasuryBalance)
// Withdraw from treasury
if (treasuryBalance > 0) {
const { transaction } = await cartProtocol.platform.withdrawFromTreasury({
platformId,
amount: treasuryBalance / 2, // Withdraw half the balance
destination: recipientPublicKey, // Where to send the funds
})
const signature = await cartProtocol.sendAndConfirmTransaction(transaction)
console.log('Withdrawal successful:', signature)
}
}
Creating Multiple Marketplaces
async function createMarketplaces(platformId) {
// Create first marketplace (Art)
const { transaction: tx1, marketplaceId: artMarketplaceId } =
await cartProtocol.marketplace.createMarketplace({
platformId,
name: 'Digital Art Marketplace',
description: 'Marketplace for digital art',
categories: ['art', 'digital', 'collectible'],
feeBasisPoints: 150, // 1.5% marketplace fee
})
await cartProtocol.sendAndConfirmTransaction(tx1)
// Create second marketplace (Music)
const { transaction: tx2, marketplaceId: musicMarketplaceId } =
await cartProtocol.marketplace.createMarketplace({
platformId,
name: 'Digital Music Marketplace',
description: 'Marketplace for music NFTs',
categories: ['music', 'audio', 'nft'],
feeBasisPoints: 150, // 1.5% marketplace fee
})
await cartProtocol.sendAndConfirmTransaction(tx2)
return { artMarketplaceId, musicMarketplaceId }
}
For more detailed information about the Platform Module, refer to the following resources: