pancake_swap_sdk 0.0.7 copy "pancake_swap_sdk: ^0.0.7" to clipboard
pancake_swap_sdk: ^0.0.7 copied to clipboard

A package is a project forked from two prominent web libraries, pancake swap sdk and uniswap swap sdk.

flutter_pancake_swap_sdk #

Table of Contents #

  1. Introduction
  2. Installation
  3. Usage
  4. Documentation
  5. Examples
  6. Support

Introduction #

flutter_pancake_swap_sdk is a Flutter project forked from two prominent web libraries, pancakeswap/sdk and Uniswap SDK v3 Overview. This project aims to adapt these web libraries for mobile platforms, providing users with the functionality of the PancakeSwap and Uniswap platforms.

Installation #

With Flutter:

flutter pub add pancake_swap_sdk

This will add a line like this to your package's pubspec.yaml

dependencies:
  pancake_swap_sdk

Usage #

The SDK includes several key features such as token declaration and price estimation. Here's a brief overview:

Token Declaration #

  • For native tokens: Token.WETH[ChainId]!
  • For creating a token instance: Token(chainId, address, decimal)

LP Pair Tokens #

  • To get LP pair tokens: Pair.getAddress(token1, token2)

Price Estimation #

  • To estimate prices: Trade.bestTradeExactIn(TokenAmount(tokenFrom, value.amountSwapFrom(decimalFrom)), tokenTo, maxHops)

Documentation #

Forked from the PancakeSwap SDK.

For more detailed information, refer to the Uniswap SDK v3 Documentation.

You can refer to the Uniswap SDK documentation uniswap.org.

Examples #

Trade? getTrade({
  required List<EthereumAddress> addressSwap,
  required int decimalFrom,
  required int decimalTo,
  required double value,
}) {
  Trade? bestTradeSoFar;
  Token tokenFrom =
  TokenSDK.Token(_buildConfig.chainId, addressSwap[0], decimalFrom);
  Token tokenTo =
  TokenSDK.Token(_buildConfig.chainId, addressSwap[1], decimalTo);

  if (addressSwap[0]
      .hex
      .toLowerCase()
      .contains(_buildConfig.bnbContractAddress.toLowerCase())) {
    tokenFrom = TokenSDK.Token.WETH[ChainId.MAINNET.value]!;
  }

  if (addressSwap[1]
      .hex
      .toLowerCase()
      .contains(_buildConfig.bnbContractAddress.toLowerCase())) {
    tokenTo = TokenSDK.Token.WETH[ChainId.MAINNET.value]!;
  }

  for (int i = 1; i <= maxHops; i++) {
    var bestTrade = Trade.bestTradeExactIn(
      listPair,
      TokenAmount(tokenFrom, value.amountSwapFrom(decimalFrom)),
      tokenTo,
      maxHops: i,
    );
    if (bestTrade.isNotEmpty) {
      final currentTrade = bestTrade[0];
      final valueBool = isTradeBetter(
        bestTradeSoFar,
        currentTrade,
        minimumDelt: betterTradeLessHopsThreshold,
      );
      if (valueBool) {
        bestTradeSoFar = currentTrade;
      }
    }
  }
  tradeInfor = bestTradeSoFar;

  return tradeInfor;
}

Future<List<Pair>> getListPair(Token tokenA, Token tokenB) async {
  List<Pair> listPair = [];
  final listPairA = getPairTokenABaseToken(tokenA);
  final listPairB = getPairTokenBBaseToken(tokenB);
  try {
    final listStablePair = getStableLPPair(tokenA, tokenB);
    listPair = await _contractMultiCallRepository
        .getListPairFromSDK(addressLpToken: [
      ...listStablePair,
      ...listPairA,
      ...listPairB,
    ]);
  } catch (e) {
    Log.info('error get pair swap', e.toString());
  }

  return listPair;
}

Support #

Support this project by donating on buymeacoffee.com.

If you encounter any issues or have questions related to this project, feel free to reach out for support. You can send an email to enertran98@gmail.com, and we will do our best to assist you promptly.

Please provide a detailed description of the issue, including any error messages or screenshots that can help us understand the problem better. This will enable us to provide more effective assistance.

Thank you for your support and cooperation.

7
likes
120
pub points
27%
popularity

Publisher

unverified uploader

A package is a project forked from two prominent web libraries, pancake swap sdk and uniswap swap sdk.

Repository (GitLab)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

big_dart, convert, dart_numerics, decimal, ethereum_addresses, flutter, intl, web3dart

More

Packages that depend on pancake_swap_sdk