Created
January 22, 2021 12:09
-
-
Save yuyasugano/d043ff5b8ee114814b356d16b4fc28dd to your computer and use it in GitHub Desktop.
Token swap Sell A for B at Uniswap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Sell A for B at Uniswap | |
const uAtoB = await uFetcher.fetchPairData( | |
tokenFetchers[i][1], | |
tokenFetchers[i][0] | |
); | |
const route1 = await new uRoute([uAtoB], tokenFetchers[i][0]); | |
const trade1 = await new uTrade( | |
route1, | |
new uTokenAmount(tokenFetchers[i][0], amount0), | |
uTradeType.EXACT_INPUT | |
); | |
const rate1 = await trade1.executionPrice.toSignificant(6); | |
console.log(`Putting ${unit0} ${tokenPairs[i][0]} into Uniswap pool`); | |
console.log(`Sell ${tokenPairs[i][0]} for ${tokenPairs[i][1]} at Uniswap: ${rate1 * unit0}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment