Comments (6)
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.
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.
The provider url of Cronos Mainnet Beta chain: https://rpc.nebkas.ro
from simple-uniswap-sdk.
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
in the custom network object it works
from simple-uniswap-sdk.
this is now fixed have confirmed my end!
from simple-uniswap-sdk.
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
Works like charm. Thank you very much
from simple-uniswap-sdk.
Related Issues (20)
- Polygon Main/Mumbai Contracts HOT 1
- Output trade fails on Uniswap V2 HOT 3
- Can't use with vite HOT 1
- Using this library to provide liquidity HOT 1
- Using this to swap erc-20 tokens, is there a need for providing approval before executing the swap? HOT 3
- How to use native currency on custom network HOT 4
- TokensFactoryPublic with customNetwork not working HOT 11
- How to compute Gas + Uniswap Fees needed for a trade? HOT 2
- Prices vary slightly
- Support for swapExactTokensForTokensSupportingFeeOnTransferTokens
- feat: AVALANCHE support HOT 13
- Invalid from or to address on custom chain? HOT 3
- License clarification HOT 3
- bug(avalanche): native token _ETH is not valid HOT 4
- feat: support multiple exchanges and search for best route
- Hello, is there any way to get the best route, for several pairs (possibly hundreds) in a single request to the node (multicall)?
- Hello, is there a way to get the best price for several pairs (possibly hundreds) in a single request to the node (multicall)?
- Price impact
- Invalid from or to contract tokens
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simple-uniswap-sdk.