Token Swap

Fungily Token Swap is an on-chain token exchange protocol built on an Automated Market Maker (AMM) model. It enables seamless, secure, and gas-optimized token swaps with real-time price discovery and capital-efficient liquidity provisioning.

🧠 What Is Fungily Token Swap?

Fungily Token Swap is the core infrastructure for swapping:

  • Fungily-native tokens (from presales or mintpads)

  • Any ERC-20 compatible tokens supported by the protocol

It is *non-custodial, *permissionless, and supports high-efficiency trading by relying on an AMM-powered liquidity poolremoving the need for centralized order books or third-party intermediaries.

⚙️ How It Works

At the heart of Fungily Token Swap is a concentrated liquidity AMM mechanism.

Instead of distributing liquidity across the entire price curve, liquidity providers (LPs) can allocate capital within specific price ranges. This creates:

  • Lower slippage for trades

  • Higher capital efficiency

  • Customizable liquidity provisioning for LPs

📈 The AMM Formula

Fungily swap modifies the traditional constant product formula from:

math x * y = k

to a more granular, price-driven mechanism using square root price ticks.

✅ Key Formulas

Formula for Constant Product AMM:

Where:

  • xx = amount of Token A in the liquidity pool

  • yy = amount of Token B in the liquidity pool

  • kk = constant product

Token Swap Formula:

For token swaps, where a user swaps an input amount of Token A for Token B:

Where:

  • xinputx_{\text{input}} = amount of Token A the user wants to swap

  • youtputy_{\text{output}} = amount of Token B the user will receive

To solve for the amount of Token B the user receives:

Final Token B Output:

To find the actual amount of Token B the user will receive:

Where:

  • Δy\Delta y = amount of Token B the user receives.

Slippage Formula:

To account for fees (e.g., 2% fee):

Example:

After the user inputs 100 Token A:

Now, calculate the new amount of Token B:

Finally, the amount of Token B the user receives:

Full Example in Markdown:

This allows the protocol to simulate a concentrated order book, while still functioning as a decentralized AMM.

💡 Key Features

Feature
Description

Concentrated Liquidity

LPs can choose price ranges to allocate capital more efficiently

On-Chain Pricing

No external price feeds prices adjust according to trades and liquidity

Range Orders

LPs can simulate limit orders by providing liquidity at specific ranges

Gas Optimization

Efficient tick-based design improves gas usage per trade


🧮 Price Execution & Slippage

  • All swaps follow bonding curve mechanics

  • Swaps that consume liquidity across multiple price ticks experience progressive slippage

  • The pool enforces price protection and validates minimum output constraints (amountOutMin)

🔐 Security and Integrity

  • Immutable pool contracts prevent malicious upgrades

  • Permissionless architecture: anyone can add liquidity or initiate swaps

  • Slippage tolerance and deadline options protect users from MEV and frontrunning

📈 Example Use Case

Swapping 100 USDC to FGLY (Fungily token):

  1. Call swapExactTokensForTokens with:

    • amountIn = 100e6

    • path = [USDC, FGLY]

    • amountOutMin = estimated - slippage

  2. Contract calculates output based on current tick, liquidity range, and fee tier

  3. Output tokens are transferred to msg.sender

🔗 Integration & Extensibility

  • Compatible with wallet dApps, dashboards, and on-chain trading bots

  • Can be combined with Fungily Presale and Mintpad to bootstrap post-launch liquidity

  • Future support for:

    • Multi-hop routing

    • Limit orders

    • Liquidity mining programs

Last updated