Middle Staking Docs
  • 👋Welcome
    • Presentation
    • Stake Unstake Rewards
    • Deposit
      • Deposit fees
  • 🪙MID TOKEN
    • Distribution
    • Staking rewards
    • Buy & Sell
    • Use cases
  • 📔CONTRACTS
    • Staking Contract
      • Details
      • Functions
    • Swap contract
      • Details
      • Liquidity
      • Swap
    • NFT/SFT Staking Contract
      • Details
  • Liquidity & swap
Powered by GitBook
On this page
  1. CONTRACTS
  2. Swap contract

Swap

Swap functions use the liquidity available to trade one token with another

    #[payable("*")]
    #[endpoint(swap)]
    fn swap(
        &self, 
        first_token: TokenIdentifier,  
        second_token: TokenIdentifier, 
        opt_min_out: OptionalValue<BigUint>,
    )

first_token will always be MID token and second_token indicate what liquidity to use.

Payment token can be first or second token.

opt_min_out (slippage) : is an optionnal value where user can indicate the minimum amount of token he want to receive. We will use this to set the slippage tolerance

    #[payable("*")]
    #[endpoint(dualSwap)]
    fn dual_swap(
        &self, 
        first_token: TokenIdentifier,  
        second_token: TokenIdentifier, 
        opt_min_out: OptionalValue<BigUint>,
    )

first token and second token must be in the "swaped_tokens" list

PreviousLiquidityNextNFT/SFT Staking Contract

Last updated 1 year ago

📔