GithubHelp home page GithubHelp logo

Comments (6)

AjayiMike avatar AjayiMike commented on July 30, 2024

For Context purpose, this is the full code:

import {
    UniswapPair,
    UniswapVersion,
    UniswapPairSettings,
    TradeDirection,
} from "simple-uniswap-sdk";
import { constants } from "ethers";

interface Params {
    fromTokenContractAddress: string;
    toTokenContractAddress: string;
    amount: string;
    provider: any;
}

export const findBestRoute = async (
    params: Params
): Promise<{ path: string[]; expectedOutput: string }> => {
    const {
        fromTokenContractAddress,
        toTokenContractAddress,
        amount,
        provider,
    } = params;

    const cloneUniswapContractDetails = {
        v2Override: {
            routerAddress: "0x145677FC4d9b8F19B5D56d1820c48e0443049a30",
            factoryAddress: "0xd590cC180601AEcD6eeADD9B7f2B7611519544f4",
            pairAddress: "0xd590cC180601AEcD6eeADD9B7f2B7611519544f4",
        },
    };

    const uniswapPair = new UniswapPair({
        fromTokenContractAddress,
        toTokenContractAddress,
        ethereumAddress: constants.AddressZero,
        ethereumProvider: provider,
        settings: new UniswapPairSettings({
            slippage: 0.001,
            deadlineMinutes: 20,
            disableMultihops: false,
            uniswapVersions: [UniswapVersion.v2],
            cloneUniswapContractDetails: cloneUniswapContractDetails,
            customNetwork: {
                nameNetwork: "Cronos Mainnet Beta",
                multicallContractAddress:
                    "0x5e954f5972EC6BFc7dECd75779F10d848230345F",
                nativeCurrency: {
                    name: "cro",
                    symbol: "CRO",
                },
                nativeWrappedTokenInfo: {
                    chainId: 25,
                    contractAddress:
                        "0x5C7F8A570d578ED84E63fdFA7b1eE72dEae1AE23",
                    decimals: 18,
                    symbol: "WCRO",
                    name: "Wrapped CRO",
                },
            },
        }),
    });

    try {
        const uniswapPairFactory = await uniswapPair.createFactory();
        const result = await uniswapPairFactory.findBestRoute(
            amount,
            TradeDirection.input
        );

        return {
            path: result.bestRouteQuote.routePathArray,
            expectedOutput:
                result.bestRouteQuote
                    .expectedConvertQuoteOrTokenAmountInMaxWithSlippage,
        };
    } catch (error) {
        console.log("error: ", error);
        throw error;
    }
};

The toTokenContractAddress: "0x7b8aD6d7560FAcd1959cfb4b4163D7d297c4bFc0"

I've used MUSD(0x97749c9B61F878a880DfE312d2594AE07AEd7656) and USDC(0xc21223249CA28397B4B6541dfFaEcC539BfF0c59) as the fromTokenContractAddress
No matter the input amount provided, I keep getting value between 4.3 to 4.9

the decentralized exchange whose contracts I'm using (mm.finance) gives me correct value so I don't know if there is something I'm doing wrongly

from simple-uniswap-sdk.

AjayiMike avatar AjayiMike commented on July 30, 2024

A loom video showing the error in action: loom
In the video, for every other coin, the minimum received is almost exactly what you get on the exchange's interface (mm.finance) except for the last coin CRP(0x7b8aD6d7560FAcd1959cfb4b4163D7d297c4bFc0), The minimum received is always 4.xxx no matter the input amount

from simple-uniswap-sdk.

AjayiMike avatar AjayiMike commented on July 30, 2024

The provider url of Cronos Mainnet Beta chain: https://rpc.nebkas.ro

from simple-uniswap-sdk.

joshstevens19 avatar joshstevens19 commented on July 30, 2024

Hey so we spoke over twitter but will explain again.. but this was due to no liquidity on main routes and it was always going to MMF token which the sdk did not know about, you need to add that base token and then the lib will route to it..

if you add (use one of the base tokens to map the MMF token)

baseTokens: {
    dai: {
        chainId: 25,
        contractAddress: '0x97749c9B61F878a880DfE312d2594AE07AEd7656',
         decimals: 18,
         symbol: 'MMF',
         name: 'MMF',
  }
}

aka like

image
in the custom network object it works

image

from simple-uniswap-sdk.

joshstevens19 avatar joshstevens19 commented on July 30, 2024

this is now fixed have confirmed my end!

from simple-uniswap-sdk.

AjayiMike avatar AjayiMike commented on July 30, 2024

Hey so we spoke over twitter but will explain again.. but this was due to no liquidity on main routes and it was always going to MMF token which the sdk did not know about, you need to add that base token and then the lib will route to it..

if you add (use one of the base tokens to map the MMF token)

baseTokens: {
    dai: {
        chainId: 25,
        contractAddress: '0x97749c9B61F878a880DfE312d2594AE07AEd7656',
         decimals: 18,
         symbol: 'MMF',
         name: 'MMF',
  }
}

aka like

image in the custom network object it works

image

Works like charm. Thank you very much

from simple-uniswap-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.