joshstevens19 / simple-uniswap-sdk

Uniswap SDK which handles the routes automatically for you, changes in trade quotes reactive subscriptions, exposure to formatted easy to understand information, bringing back the best trade quotes automatically, generating transactions for you and much more.
MIT License
188 stars 94 forks source link

Trade by specifying TO token amount #4

Closed DimitarNestorov closed 3 years ago

DimitarNestorov commented 3 years ago

Currently the trade function only supports specifying the FROM token amount.

joshstevens19 commented 3 years ago

Hey, thanks for raising this! This is something I will get round to supporting soon but it's a bit further down the list at the moment.. once supported il comment back on here with the version number.

joshstevens19 commented 3 years ago

Hey this has now been added to the sdk. You can get quotes from input and output directions. You use the same interface to execute the quote but we have an optional parameter now which allows you to pass in a different direction.

/**
   * Generate trade - this will return amount but you still need to send the transaction
   * if you want it to be executed on the blockchain
   * @param amount The amount you want to swap formatted. Aka if you want to swap 1 AAVE you pass in 1
   * @param direction The direction you want to get the quote from
   */
async trade(amount: string, direction: TradeDirection = TradeDirection.input): Promise<TradeContext>

This will generate all the same stuff it did before but it have properties like maximumSent defined instead of minAmountConvertQuote. The transaction would all of been built for you as a different output direction takes you down a different contract call. So all in all it should be very easy to quote both ways now without any changes to the interface!

Package has been deployed in 2.3.0 :+1:

Let me know if you bump into any issues! Closing as it should be resolved.