pancake_swap_sdk

Last updated:

0 purchases

pancake_swap_sdk Image
pancake_swap_sdk Images
Add to Cart

Description:

pancake swap sdk

flutter_pancake_swap_sdk #
Table of Contents #

Introduction
Installation
Usage
Documentation
Examples
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
copied to clipboard
This will add a line like this to your package's pubspec.yaml
dependencies:
pancake_swap_sdk
copied to clipboard
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;
}
copied to clipboard
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 [email protected], 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.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.