Logo
Registry

swap

@example

• v1.0.0

Decentralized exchange protocol with automated market maker functionality

Token Swap Protocol

A decentralized exchange (DEX) protocol implementing automated market maker (AMM) functionality for token swapping. This protocol enables users to exchange different assets through liquidity pools managed by the DEX.

Features

  • Automated Market Making: Dynamic pricing based on pool state and asset ratios
  • Pool State Management: Maintains liquidity pool data with pair balances
  • Asset Flexibility: Supports swapping any asset types (AnyAsset)
  • Fee Integration: Automatic transaction fee handling
  • Change Management: Returns excess payment to buyers

How It Works

  1. Pool Setup: DEX maintains liquidity pools with two assets (pair_a, pair_b)
  2. Swap Request: Buyer specifies what they want (ask) and what they're offering (bid)
  3. Pool Update: Pool balances are adjusted based on the swap amounts
  4. Asset Exchange: Buyer receives the requested asset, pool gets the bid asset
  5. Change Return: Any excess payment is returned to the buyer

Transaction Structure

  • Inputs: Pool UTxO from DEX, payment from Buyer
  • Outputs: Updated pool state, assets to buyer
  • Redeemer: SwapParams containing ask and bid values

Parameters

  • ask: AnyAsset - The asset and amount the buyer wants to receive
  • bid: AnyAsset - The asset and amount the buyer is offering

Use Cases

  • Token Trading: Exchange different cryptocurrencies or tokens
  • Liquidity Provision: Enable trading pairs for various assets
  • DeFi Integration: Foundation for more complex financial protocols
  • Educational Examples: Learn AMM mechanics and pool management

This protocol demonstrates core DEX functionality and serves as a building block for decentralized trading systems.

swap

Published by

@example

Install

trix install example/swap

Publication datePublished 10 months ago
Back to all Protocols