Building on Aptos: A Guide for Solana Developers #2
Open Github Page
Fungible Assets on Aptos and Solana
Fungible Asset Launchpad Example
Tips for Building on Aptos
Aptos Developer Docs
Data Structures and Storage
Fungible Asset Storage
Similar to Solana, on Aptos each fungible asset is stored in its own Object (similar to Solana account). Each holder has at least one account to store the his or her balance of each fungible asset. On Solana it's called Token Account, on Aptos it's call Fungible Asset Store.
Define Your Own Data Structures
Since we want to support users to discover fungible assets created on the launchpad, we need to store the created fungible assets in a data structure. We call it Registry
.
On Solana it's a simple struct with a vector of token PubKeys. The struct is stored in its own account owned by the launchpad program.
use anchor_lang::prelude::*;#[account]#[derive(InitSpace)]pub struct Registry { #[max_len(10000)] // Reserve space for up to 10000 tokens pub tokens: Vec<Pubkey>,}#[derive(Accounts)]pub struct Initialize<'info> { #[account(mut)] pub payer: Signer<'info>, #[account(init, payer = payer, space = 10000)] pub registry: Account<'info, Registry>, pub system_program: Program<'info, System>,}pub fn handle_initialize(ctx: Context<Initialize>) -> Result<()> { let registry = &mut ctx.accounts.registry; registry.tokens = Vec::new(); Ok(())}
On Aptos, we also have a struct Registry
with a vector of addresses. The struct is stored as a resource directly in the object that launchpad contract deploys under.
struct Registry has key { fa_obj_addresses: vector<address>}// If you deploy the module under an object, sender is the object's signer// If you deploy the moduelr under your own account, sender is your account's signerfun init_module(sender: &signer) { move_to(sender, Registry { fa_obj_addresses: vector::empty<address>() });}