Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Autonomous-Finance/botega

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“Š Botega AMM

⚠️ ARCHIVED PROJECT

This project is archived and no longer maintained. It is provided as-is for educational and reference purposes. No support, updates, or bug fixes will be provided. It was originally developed by Autonomous Finance.

AO License Teal

Constant product AMM with factory-spawned liquidity pools on AO

Swap tokens, provide liquidity, earn LP rewards, and subscribe to real-time market events

Features β€’ Architecture β€’ Pool Actions β€’ Getting Started β€’ License


🌟 Features

πŸ”„ Constant Product Swaps

Uniswap-style x * y = K formula. Execute token swaps with slippage protection and expected minimum output guarantees.

🏭 Factory Pattern

Single factory spawns and manages all pool processes. Automatic pool registration, fee configuration, and Dexi integration.

πŸ’§ LP Token System

Mint LP tokens proportional to liquidity provided. Burn to withdraw your share of reserves plus accrued fees.

πŸ“‘ Real-Time Subscriptions

Subscribe to swap confirmations, liquidity events, and fee changes. Power autonomous agents with live market data.

πŸ’° Configurable Fees

Split fees between LPs (enters reserves) and protocol (transferred to collector). Support for fee discounts on whitelisted addresses.

🏷️ Tag Forwarding

All X-... tags forwarded through swap/provide/burn flows. Trigger timestamps on every output for downstream processing.

πŸ—οΈ Architecture

                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚   POOL CREATORS   β”‚
                         β”‚   ─────────────   β”‚
                         β”‚   Add-Pool        β”‚
                         β”‚   Token-A/B       β”‚
                         β”‚   Fee-Bps         β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                   β”‚
                                   β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         AMM FACTORY                             β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β€’ Validate token compatibility (aos 2.0)                       β”‚
β”‚  β€’ Spawn pool processes with configured fees                    β”‚
β”‚  β€’ Auto-register pools with Dexi aggregator                     β”‚
β”‚  β€’ Manage fee collectors & whitelists                           β”‚
β”‚  β€’ Relay confirmations/errors to users                          β”‚
β”‚  β€’ Batch patch AMM source code upgrades                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                        β”‚                        β”‚
         β”‚ Spawns                 β”‚ Registers              β”‚ Relays
         β–Ό                        β–Ό                        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   AMM POOL 1    β”‚      β”‚   AMM POOL 2    β”‚      β”‚   AMM POOL N    β”‚
β”‚   ──────────    β”‚      β”‚   ──────────    β”‚      β”‚   ──────────    β”‚
β”‚   AO/wUSDC      β”‚      β”‚   wAR/wUSDC     β”‚      β”‚   PI/wAR        β”‚
β”‚   25 bps        β”‚      β”‚   25 bps        β”‚      β”‚   25 bps        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                        β”‚                        β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                  β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         AMM POOL CORE                           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β€’ Constant product (x*y=K)     β€’ LP token mint/burn            β”‚
β”‚  β€’ Slippage protection          β€’ Fee collection (LP+Protocol)  β”‚
β”‚  β€’ Pending provide matching     β€’ Tag forwarding                β”‚
β”‚  β€’ Subscription notifications   β€’ State patching (HyperBee)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                  β”‚
                                  β”‚ Notifications & Transfers
                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                  β–Ό               β–Ό               β–Ό
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚     DEXI      β”‚ β”‚  SUBSCRIBERS  β”‚ β”‚   TRADERS     β”‚
          β”‚  ──────────   β”‚ β”‚  ──────────   β”‚ β”‚  ──────────   β”‚
          β”‚  Candles      β”‚ β”‚  β€’ Agents     β”‚ β”‚  β€’ Wallets    β”‚
          β”‚  Stats        β”‚ β”‚  β€’ Indexers   β”‚ β”‚  β€’ Bots       β”‚
          β”‚  Analytics    β”‚ β”‚  β€’ dApps      β”‚ β”‚  β€’ Arbitrage  β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

How It Works

  1. Pool Creation β€” Factory validates token compatibility, spawns pool process with configured fee tier
  2. Liquidity Provision β€” LPs transfer both tokens, receive LP tokens proportional to share of reserves
  3. Swapping β€” Traders transfer input token with X-Action: Swap, receive output based on constant product
  4. Fee Accrual β€” LP fees enter reserves (compounding), protocol fees transferred to collector
  5. Withdrawal β€” LPs burn pool tokens, receive proportional share of both reserves

πŸ”„ Pool Actions

Swap Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Trader  │────────▢│  Token   │────────▢│   Pool   β”‚
β”‚          β”‚ Transferβ”‚ Process  β”‚Credit-  β”‚          β”‚
β”‚          β”‚         β”‚          β”‚Notice   β”‚          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                β”‚
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
     β”‚
     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  1. Validate slippage & reserves                   β”‚
β”‚  2. Calculate output (constant product)            β”‚
β”‚  3. Deduct LP fee (enters reserves)                β”‚
β”‚  4. Deduct protocol fee (sent to collector)        β”‚
β”‚  5. Transfer output tokens to trader               β”‚
β”‚  6. Notify subscribers on 'order-confirmation'     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Provide Liquidity Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    Transfer Token A    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    LP    │───────────────────────▢│   Pool   β”‚
β”‚          β”‚                        β”‚          β”‚
β”‚          β”‚    Transfer Token B    β”‚  Pending β”‚
β”‚          │───────────────────────▢│  Provide β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                          β”‚
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
     β”‚
     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  1. Match pending provide for sender               β”‚
β”‚  2. Adjust quantities within slippage tolerance    β”‚
β”‚  3. Calculate LP tokens to mint (√(A*B) or ratio)  β”‚
β”‚  4. Add tokens to reserves                         β”‚
β”‚  5. Mint LP tokens to provider                     β”‚
β”‚  6. Refund excess tokens if adjusted               β”‚
β”‚  7. Notify subscribers on 'liquidity-add-remove'   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‘ Subscription Topics

All Botega AMMs offer a real-time subscription service powered by DEXI tokens.

Topic Description Payload
order-confirmation Emitted after every successful swap Order ID, tokens, quantities, fees, reserves
liquidity-add-remove Emitted on provide/burn Reserves delta, pool token changes
fee-change Emitted when swap fees are updated New total fee percentage

Subscribe to an AMM

AMM = '<pool-process-id>'
DEXI_TOKEN = '<dexi-token-process>'

-- 1. Register as subscriber
ao.send({
  Target = AMM,
  Action = 'Register-Subscriber',
  Topics = json.encode({'order-confirmation', 'liquidity-add-remove'})
})

-- 2. Pay for subscription
ao.send({
  Target = DEXI_TOKEN,
  Action = 'Transfer',
  Recipient = AMM,
  Quantity = '<payment-amount>',
  ["X-Subscriber-Process-Id"] = ao.id
})

πŸ“‹ Handler Reference

Query Handlers

Action Description Response Tags
Get-Pair Token addresses in the pair Token-A, Token-B
Get-Reserves Current reserve balances <Token-A>, <Token-B>
Get-K Current K constant K
Get-Price Price quote for swap Price, Expected-Output
Get-Swap-Output Detailed swap simulation Output, Fee, Price-Impact
Get-Fee-Percentage LP and protocol fee rates Fee-Percentage, LP-Fee, Protocol-Fee
Balance LP token balance for address Balance, Ticker
Balances All LP token balances Data (JSON)
Total-Supply Total LP tokens minted Total-Supply

Action Handlers

Action Description Tags Required
Swap Execute token swap X-Action: Swap, X-Expected-Min-Output
Provide Add liquidity X-Action: Provide, X-Slippage-Tolerance
Burn Remove liquidity Quantity
Cancel Cancel pending provide β€”
Transfer Transfer LP tokens Recipient, Quantity

πŸ”„ Usage Examples

Execute a Swap

-- Transfer input token with swap parameters
ao.send({
  Target = INPUT_TOKEN,
  Action = "Transfer",
  Recipient = POOL,
  Quantity = "1000000000000",  -- Amount to swap
  ["X-Action"] = "Swap",
  ["X-Expected-Min-Output"] = "950000000000"  -- Minimum acceptable output
})

Provide Liquidity

-- Transfer first token
ao.send({
  Target = TOKEN_A,
  Action = "Transfer",
  Recipient = POOL,
  Quantity = "1000000000000",
  ["X-Action"] = "Provide",
  ["X-Slippage-Tolerance"] = "1"  -- 1% slippage tolerance
})

-- Transfer second token
ao.send({
  Target = TOKEN_B,
  Action = "Transfer",
  Recipient = POOL,
  Quantity = "2000000000000",
  ["X-Action"] = "Provide",
  ["X-Slippage-Tolerance"] = "1"
})

Burn LP Tokens

ao.send({
  Target = POOL,
  Action = "Burn",
  Quantity = "500000000000"  -- LP tokens to burn
})

Create a Pool (via Factory)

ao.send({
  Target = FACTORY,
  Action = "Add-Pool",
  ["Token-A"] = "<token-a-process-id>",
  ["Token-B"] = "<token-b-process-id>",
  ["Fee-Bps"] = "25"  -- 0.25% fee (25 basis points)
})

πŸ’Έ Fee Mechanism

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    INCOMING SWAP                        β”‚
β”‚                    ─────────────                        β”‚
β”‚                   1,000,000 tokens                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β–Ό               β–Ό               β–Ό
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚  LP Fee     β”‚ β”‚ Protocol    β”‚ β”‚ Net Input   β”‚
   β”‚  ────────   β”‚ β”‚ Fee         β”‚ β”‚ ─────────   β”‚
   β”‚  0.20%      β”‚ β”‚ ────────    β”‚ β”‚ 99.75%      β”‚
   β”‚  (2,000)    β”‚ β”‚ 0.05%       β”‚ β”‚ (997,500)   β”‚
   β”‚             β”‚ β”‚ (500)       β”‚ β”‚             β”‚
   β”‚  β†’ Reserves β”‚ β”‚ β†’ Collector β”‚ β”‚ β†’ Swap Calc β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • LP Fee enters reserves β†’ automatically compounds for liquidity providers
  • Protocol Fee transferred to collector contract β†’ does not affect K
  • Fee Discounts available for whitelisted addresses (portfolio agents)

πŸ“ Project Structure

bark-amm/
β”œβ”€β”€ πŸ“‚ src/
β”‚   β”œβ”€β”€ πŸ“‚ amm/                    # AMM pool logic
β”‚   β”‚   β”œβ”€β”€ main.tl                # Entry point, handler registration
β”‚   β”‚   β”œβ”€β”€ amm-handlers.tl        # Handler implementations
β”‚   β”‚   β”œβ”€β”€ state.tl               # State management
β”‚   β”‚   β”œβ”€β”€ πŸ“‚ pool/               # Core pool operations
β”‚   β”‚   β”‚   β”œβ”€β”€ pool.tl            # Reserves, K, price calculations
β”‚   β”‚   β”‚   β”œβ”€β”€ swap.tl            # Swap execution
β”‚   β”‚   β”‚   β”œβ”€β”€ provide.tl         # Liquidity provision
β”‚   β”‚   β”‚   β”œβ”€β”€ burn.tl            # LP token burning
β”‚   β”‚   β”‚   β”œβ”€β”€ cancel.tl          # Cancel pending provides
β”‚   β”‚   β”‚   β”œβ”€β”€ refund.tl          # Error refunds
β”‚   β”‚   β”‚   └── globals.tl         # Global type definitions
β”‚   β”‚   └── πŸ“‚ token/              # LP token operations
β”‚   β”‚       β”œβ”€β”€ token.tl           # Token initialization
β”‚   β”‚       β”œβ”€β”€ balance.tl         # Balance queries
β”‚   β”‚       β”œβ”€β”€ transfer.tl        # LP transfers
β”‚   β”‚       └── credit_notice.tl   # Incoming transfer handling
β”‚   β”œβ”€β”€ πŸ“‚ factory/                # Pool factory
β”‚   β”‚   β”œβ”€β”€ factory.tl             # Factory handlers & pool spawning
β”‚   β”‚   β”œβ”€β”€ factory_lib.tl         # Factory utilities
β”‚   β”‚   └── globals.tl             # Factory globals
β”‚   β”œβ”€β”€ πŸ“‚ utils/                  # Shared utilities
β”‚   β”‚   β”œβ”€β”€ assertions.tl          # Input validation
β”‚   β”‚   β”œβ”€β”€ bintmath.tl            # Big integer math
β”‚   β”‚   β”œβ”€β”€ forward-tags.tl        # Tag forwarding
β”‚   β”‚   β”œβ”€β”€ patterns.tl            # Handler patterns
β”‚   β”‚   β”œβ”€β”€ responses.tl           # Response helpers
β”‚   β”‚   └── tl-bint.tl             # Bint wrapper
β”‚   └── πŸ“‚ typedefs/               # Type definitions
β”‚       β”œβ”€β”€ ao.d.tl                # AO types
β”‚       └── json.d.tl              # JSON types
β”œβ”€β”€ πŸ“‚ packages/
β”‚   └── πŸ“‚ subscriptions/          # Subscription module
β”‚       └── subscribable.lua       # Real-time notifications
β”œβ”€β”€ πŸ“‚ build/                      # Compiled Lua output
β”‚   β”œβ”€β”€ factory.lua                # Deployed factory code
β”‚   β”œβ”€β”€ amm.lua                    # Standalone AMM (testing)
β”‚   └── amm_as_template.lua        # AMM template for spawning
β”œβ”€β”€ πŸ“‚ test/                       # Test suites
β”‚   β”œβ”€β”€ swap_test_pool.lua         # Swap tests
β”‚   β”œβ”€β”€ provide_burn_test_pool.lua # Provide/burn tests
β”‚   └── integration_test_*.lua     # Integration tests
β”œβ”€β”€ πŸ“‚ scripts/                    # Build & deploy scripts
β”‚   β”œβ”€β”€ build.sh                   # Compile Teal to Lua
β”‚   └── deploy.sh                  # Deploy to AO
β”œβ”€β”€ processes.dev.yaml             # Dev deployment config
β”œβ”€β”€ processes.prod.yaml            # Production deployment config
└── tlconfig.lua                   # Teal compiler config

πŸš€ Getting Started

Prerequisites

  • Lua 5.3+
  • LuaRocks 3.11+
  • Node.js 18+
  • Teal (cyan)
  • aoform (AO deployment)

Installation

# Install Lua dependencies
luarocks install --local cyan
luarocks install --local amalg
luarocks install --local busted

# Clone the repository
git clone https://github.com/Autonomous-Finance/bark-amm.git
cd bark-amm

# Install Node dependencies
npm install

# Build the project
npm run build

# Deploy to AO (dev)
npm run deploy-dev

Build Output

The build process produces:

  • build/factory.lua β€” Factory process code
  • build/amm.lua β€” Standalone AMM (for testing)
  • build/amm_as_template.lua β€” AMM template embedded in factory

Running Tests

# Run all tests
npm test

# Run pool tests only
npm run test-pool

# Run factory tests only
npm run test-factory

βš™οΈ Configuration

Factory Process Tags

Tag Description
Operator Authorized operator address
Dexi-Token Payment token for subscriptions
Dexi Dexi aggregator process for auto-registration
HB-Cache-Process HyperBee cache for state sync

Pool Process Tags

Tag Description
Token-A First token in the pair
Token-B Second token in the pair
Fee-Bps Fee in basis points (default: 25 = 0.25%)
AMM-Factory Parent factory process
Dexi-Token Payment token for subscriptions

🏷️ Tag Forwarding

All X-... tags are forwarded through AMM operations (swap, provide, burn) to enable downstream tracking and automation.

Reserved Tags (Not Forwarded)

X-Action                    # AMM action type
X-Slippage-Tolerance        # Provide slippage
X-Expected-Min-Output       # Swap minimum output
X-Token-A, X-Token-B        # Token identifiers
X-Reserves-Token-A/B        # Reserve snapshots
X-Error                     # Error details
X-Refund-Reason             # Refund context

Trigger Timestamps

All outgoing messages include Trigger-Timestamp for event ordering and latency tracking.

πŸ› οΈ Tech Stack

Technology Purpose
Teal Typed Lua for compile-time safety
Lua Runtime process logic
AO Decentralized compute on Arweave
aoform Deployment management
amalg Lua module bundling
bint Arbitrary precision integers

⚠️ Disclaimer

This software is provided "as is" without warranty of any kind. Use at your own risk. The authors are not responsible for any financial losses incurred through the use of this software.

This is experimental DeFi infrastructure. Always:

  • Test integrations thoroughly before production use
  • Understand slippage and impermanent loss risks
  • Review the code before providing significant liquidity

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors