Liquidswap Docs
GithubDappPontem Network
Liquidswap V0 Docs
Liquidswap V0 Docs
  • Introduction
    • Security Audits
    • Bounty Program
    • Developer Links
  • Protocol Overview
  • Smart Contracts
    • Generics
    • LP Coins
    • Routers
    • Scripts
    • Advanced Topics
    • 💥V0.5 Update
  • Integration
    • Test Coins
    • Let's Swap
    • Create Pool
    • Add Liquidity
    • Burn Liquidity
    • Basic Oracle
    • Flashloans
    • Unit Testing
  • Staking / Harvest
    • Overview
    • Smart Contracts
    • Integration Examples
    • DApp
    • Create your own farming pool
  • SDKs
  • Liquidswap Widget
  • Liquidswap DApp
    • Bridge
    • Testnet
  • Coins Registry
Powered by GitBook
On this page
  1. Integration

Let's Swap

PreviousTest CoinsNextCreate Pool

Last updated 2 years ago

Always practice solid risk management rules when experimenting with swaps: use the correct slippage values and trusted currency pairs, double-check the numbers before confirming, and compare external price sources.

Throughout this guide, we will use and try to swap Aptos coins to test BTC.

Let's create a new module and import the router into it:

As you try to compile the code above, you will get a warning; don't worry, it's fine.

Now let's add the dependencies we will need for this experiment, as well as a basic entry function that we can call in a transaction later:

Let's withdraw 1000 Aptos coins from an account and see how many BTC we can get in exchange:

The provided code above wouldn't still compile as we can't drop Aptos coins; at the same time, it already shows how much BTC we can get back for 1000 Aptos coins because of get_amount_out function.

Now let's indeed do a swap and finally deposit the swapped coins on our account:

Everything worked out well; using swap_exact_coin_for_coin, we have swapped Aptos coins for BTC.

This looks simple, but what if someone decided to front-run us? Let's add some basic slippage checks for the minimum amount of BTC we want to receive (afterwards we can remove get_amount_out).

An important note regarding decentralized AMM securities and user transactions:

  • Always use safety checks.

  • Never swap tokens without a slippage value provided offline.

All done. In the same way, you can try another function: router::swap_coin_for_exact_coin (see docs).

Use external price feeds or oracles (even the can be a good option).

Basic Oracle
Basic module
Router
Router