📘
ZenStake Docs
  • Overview
  • Getting Started
    • How to Set Up a Wallet
    • Funding Your Wallet
    • How to Stake
      • Claim and Unstake
      • Cooldown Period in ZenStake
  • ZenStake Ecosystem
    • Introduction to Zenstake
    • ZenStake Protocol
  • Fee Batch
  • $ZEN Token
    • Token Swap
  • Products
    • ZenStake Vaults
  • Staking Strategy
  • ZenStake Referral Program
  • Security
    • Risk Assessment Framework
  • Security Framework
  • For Developers
    • Fee Batch Mechanism
    • Token Swap Mechanism
    • Stablecoins Staking Strategy
  • Concentrated Liquidity Management (CLM) Strategy
  • Blue Chip Staking Strategy
  • Links
    • Website
    • Twitter
  • Telegram
Powered by GitBook
On this page
  • Key Features
  • How It Works
  • Technical Details
  1. For Developers

Token Swap Mechanism

The ZenStake Token Swap allows users to seamlessly exchange ZEN tokens for USDT within the same blockchain network. This feature provides a fast, secure, and fee-free swapping experience, making it an essential tool for managing ZEN holdings.

Key Features

  • Instant Swaps: Convert ZEN to USDT within seconds on the same blockchain.

  • Zero Fees: No swap fees or hidden costs.

  • Seamless Liquidity: Always accessible within supported ZenStake networks.

  • Multi-Chain Support: Available on Ethereum, Arbitrum, Polygon, BSC, and Optimism.

How It Works

  1. User Initiates Swap The user selects the amount of ZEN to swap and confirms the transaction.

    function swapZENtoUSDT(uint256 amount) external {  
        require(IERC20(ZEN).balanceOf(msg.sender) >= amount, "Insufficient ZEN balance");  
        IERC20(ZEN).transferFrom(msg.sender, address(this), amount);  
        uint256 usdtAmount = calculateSwapRate(amount);  
        IERC20(USDT).transfer(msg.sender, usdtAmount);  
    }  
  2. Swap Rate Calculation The swap rate is calculated based on the current market price using an oracle (e.g., Chainlink).

    function calculateSwapRate(uint256 zenAmount) internal view returns (uint256) {  
        uint256 zenPrice = getZENPrice(); // Fetch ZEN price from oracle  
        return (zenAmount * zenPrice) / 1e18; // Convert ZEN to USDT equivalent  
    }  
  3. Liquidity Provision The swap uses liquidity from ZenStake's dedicated pools, ensuring smooth transactions.

    function provideLiquidity(uint256 zenAmount, uint256 usdtAmount) external {  
        IERC20(ZEN).transferFrom(msg.sender, address(this), zenAmount);  
        IERC20(USDT).transferFrom(msg.sender, address(this), usdtAmount);  
        liquidityPool.addLiquidity(zenAmount, usdtAmount);  
    }  
  4. Multi-Chain Support The swap mechanism is deployed on multiple chains (Ethereum, Arbitrum, Polygon, BSC, Optimism) using the same interface.

    function isSupportedChain(uint256 chainId) external pure returns (bool) {  
        return (chainId == 1 || chainId == 42161 || chainId == 137 || chainId == 56 || chainId == 10);  
    }  

Technical Details

  • Gas Optimization: Swaps are designed to minimize gas costs by using efficient smart contract logic.

  • Security: Regular audits ensure the safety of the swap mechanism.

  • Oracle Integration: Chainlink oracles provide real-time price feeds for accurate swap rates.

PreviousFee Batch MechanismNextStablecoins Staking Strategy

Last updated 2 months ago