Skip to content

Latest commit

 

History

History
111 lines (90 loc) · 2.75 KB

File metadata and controls

111 lines (90 loc) · 2.75 KB

Scale AMM Documentation

Instructions

set_platform_base_token(base_token: Pubkey)

Updates the global platform base token restriction. Only the program upgrade authority may call this.

Accounts

  • authority (signer): upgrade authority
  • config (PDA): platform config
  • system_program
  • program_data (upgradeable loader data)

set_platform_fee(fee_bps: u16)

Updates the platform-wide fee in basis points. Only the program upgrade authority may call this.

Accounts

  • authority (signer): upgrade authority
  • config (PDA): platform config

set_fee_beneficiary(beneficiary: Pubkey)

Updates the platform fee beneficiary. Only the program upgrade authority may call this.

Accounts

  • authority (signer): upgrade authority
  • config (PDA): platform config

create(params: CreateParams)

Creates a new pool for mint_a/mint_b with virtual liquidity and custom fees. Requires funding initial_token_b_reserves only.

Accounts

  • payer (signer)
  • owner (signer)
  • token_wallet_authority (signer)
  • mint_a, mint_b
  • token_wallet_b (token account)
  • pool (PDA)
  • vault_a, vault_b (PDAs)
  • token_program_a, token_program_b
  • system_program, rent
  • config (platform config)

buy(params: SwapParams)

Swaps token A for token B (user buys token B). Fees are charged in token A.

sell(params: SwapParams)

Swaps token B for token A (user sells token B). Fees are charged in token A.

quote_buy / quote_sell

Return deterministic swap results without moving tokens.

Account Layouts

PlatformConfig

  • authority: Pubkey
  • fee_beneficiary: Pubkey
  • base_token: Pubkey
  • platform_fee_bps: u16
  • bump: u8

Pool

  • enabled: bool
  • owner: Pubkey
  • mint_a: Pubkey
  • mint_b: Pubkey
  • token_a_reserves: u128
  • token_b_reserves: u128
  • shift: u128
  • fee_beneficiary_count: u8
  • fee_beneficiaries: [FeeBeneficiary; 5]
  • bump: u8

FeeBeneficiary

  • wallet: Pubkey
  • share_bps: u16

PDA Derivations

  • pool: PDA("pool", owner, mint_a, mint_b)
  • vault_a: PDA(pool, mint_a)
  • vault_b: PDA(pool, mint_b)
  • config: PDA("config")

Usage Examples

Create a pool

await program.methods
  .create({
    shift: new anchor.BN(1_000_000),
    initialTokenBReserves: 100_000,
    feeBeneficiaries: [
      { wallet: beneficiaryOne, shareBps: 200 },
      { wallet: beneficiaryTwo, shareBps: 300 },
    ],
  })
  .accounts({ /* ... */ })
  .rpc();

Swap (buy)

await program.methods
  .buy({ amount: 10_000, limit: 1 })
  .accounts({ /* ... */ })
  .rpc();

Virtual Liquidity

shift adds virtual liquidity to token A reserves. Pricing uses token_a_reserves + shift as the effective reserve, allowing pools to launch without initial token A deposits.