Skip to content

Instantly share code, notes, and snippets.

@yuyasugano
Created January 22, 2021 12:09
Show Gist options
  • Save yuyasugano/d043ff5b8ee114814b356d16b4fc28dd to your computer and use it in GitHub Desktop.
Save yuyasugano/d043ff5b8ee114814b356d16b4fc28dd to your computer and use it in GitHub Desktop.
Token swap Sell A for B at Uniswap
// 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