β οΈ ARCHIVED PROJECTThis 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.
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
|
Uniswap-style |
Single factory spawns and manages all pool processes. Automatic pool registration, fee configuration, and Dexi integration. |
|
Mint LP tokens proportional to liquidity provided. Burn to withdraw your share of reserves plus accrued fees. |
Subscribe to swap confirmations, liquidity events, and fee changes. Power autonomous agents with live market data. |
|
Split fees between LPs (enters reserves) and protocol (transferred to collector). Support for fee discounts on whitelisted addresses. |
All |
βββββββββββββββββββββ
β 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 β
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
- Pool Creation β Factory validates token compatibility, spawns pool process with configured fee tier
- Liquidity Provision β LPs transfer both tokens, receive LP tokens proportional to share of reserves
- Swapping β Traders transfer input token with
X-Action: Swap, receive output based on constant product - Fee Accrual β LP fees enter reserves (compounding), protocol fees transferred to collector
- Withdrawal β LPs burn pool tokens, receive proportional share of both reserves
ββββββββββββ ββββββββββββ ββββββββββββ
β 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' β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββ 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' β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
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 |
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
})
| 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 | 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 |
-- 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
})
-- 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"
})
ao.send({
Target = POOL,
Action = "Burn",
Quantity = "500000000000" -- LP tokens to burn
})
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)
})
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 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)
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
- Lua 5.3+
- LuaRocks 3.11+
- Node.js 18+
- Teal (cyan)
- aoform (AO deployment)
# 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
The build process produces:
build/factory.luaβ Factory process codebuild/amm.luaβ Standalone AMM (for testing)build/amm_as_template.luaβ AMM template embedded in factory
# Run all tests
npm test
# Run pool tests only
npm run test-pool
# Run factory tests only
npm run test-factory
| 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 |
| 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 |
All X-... tags are forwarded through AMM operations (swap, provide, burn) to enable downstream tracking and automation.
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
All outgoing messages include Trigger-Timestamp for event ordering and latency tracking.
| 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 |
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
This project is licensed under the MIT License - see the LICENSE file for details.