A-DEX
  • About Us
    • Intro
    • Audits
    • Roadmap
    • Brand
    • Services
    • Contacts
  • Products
    • Swap
    • Analytics
    • Signals
  • Oracle
  • Tutorials
    • Swap
      • How to login?
      • How to swap?
      • How to add liquidity?
      • How to remove liquidity?
      • How to get pools info?
  • Developers
    • Smart Contracts
      • Swap
        • Tables
        • Actions
        • Examples
          • How to open liquidity account?
          • How to close liquidity account?
          • How to add liquidity?
          • How to remove liquidity?
          • How to swap by market price?
          • How to swap tokens with min out required amount?
          • How to cross-swap tokens by market price?
          • How to cross-swap tokens with min out required amount?
    • SDK
    • API
Powered by GitBook
On this page

Was this helpful?

  1. Developers
  2. Smart Contracts
  3. Swap
  4. Examples

How to add liquidity?

Before adding liquidity make sure to open a liquidity token account related to the pool code

import {
  SwapActionGenerator,
  SwapTransactionGenerator,
} from "@a-dex/a-dex-sdk";
import { ExtendedAsset, Name, Sym, Asset, ExtendedSymbol } from "eos-common";

const actionsGen = new SwapActionGenerator("swap.adex");
const trxGen = new SwapTransactionGenerator(
  [
    {
      actor: "trader.adex",
      permission: "active",
    },
  ],
  actionsGen
);

const trx = await trxGen.addLiquidity(
  new Name("trader.adex"),
  new Sym("LPA", 0),
  0,
  new ExtendedAsset(new Asset("1.0000 EOS"), new Name("eosio.token")),
  new ExtendedAsset(new Asset("4.0000 USDT"), new Name("tethertether"))
);
cleos -u https://eos.greymass.com push transaction '{
  "delay_sec": 0,
  "max_cpu_usage_ms": 0,
  "actions": [
    {
      "account": "eosio.token",
      "name": "transfer",
      "data": {
        "from": "trader.adex",
        "to": "swap.adex",
        "quantity": "1.0000 EOS",
        "memo": "deposit:1"
      },
      "authorization": [
        {
          "actor": "trader.adex",
          "permission": "active"
        }
      ]
    },
    {
      "account": "tethertether",
      "name": "transfer",
      "data": {
        "from": "trader.adex",
        "to": "swap.adex",
        "quantity": "4.0000 USDT",
        "memo": "deposit:1"
      },
      "authorization": [
        {
          "actor": "trader.adex",
          "permission": "active"
        }
      ]
    }
  ]
}'
const result = await api.transact({
    actions: [
    {
      account: 'eosio.token',
      name: 'transfer',
      authorization: [{
        actor: 'trader.adex',
        permission: 'active',
      }],
      data: {
        from: 'trader.adex',
        to: 'swap.adex',
        quantity: '1.0000 EOS',
        memo: 'deposit:1'
      },
    },
    {
      account: 'tethertether',
      name: 'transfer',
      authorization: [{
        actor: 'trader.adex',
        permission: 'active',
      }],
      data: {
        from: 'trader.adex',
        to: 'swap.adex',
        quantity: '4.0000 USDT',
        memo: 'deposit:1'
      }
    }]
  }, {
    blocksBehind: 3,
    expireSeconds: 30,
  });

PreviousHow to close liquidity account?NextHow to remove liquidity?

Last updated 2 years ago

Was this helpful?