-
Notifications
You must be signed in to change notification settings - Fork 24
Feat / Add Uniswap to gateway #12
Conversation
…into feat/uniswap_gateway
src/services/uniswap.js
Outdated
| const tokenAmountIn = new uni.TokenAmount(tIn, amountIn) | ||
| const result = uni.Router.swapCallParameters( | ||
| uni.Trade.exactIn(route, tokenAmountIn), | ||
| { ttl: 50, recipient: wallet.address, allowedSlippage: new uni.Percent('1', '100') } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be better values for the ttl (time to live) and the "allowedSlippage"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ttl:Uniswap defines this as "how long the swap is valid until it expires, in seconds." I think we should make ttl an constant equal to 0 that is specified in uniswap.js.
allowedSlippage: I think we should make this a constant equal to 0 in uniswap.js as well. Since we set slippage buffer through the Hummingbot client, I don't think we need to add more slippage buffer here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There shouldn't be problem with setting allowedSloppage to 0.
However, I believe there would be a problem with setting ttl to 0. I believe the swap wouldn't be executed. I'd test to confirm this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry that was a typo - for ttl I think a value like 60 seconds would be a good initial value.
fengtality
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See requested changes - let's discuss the price one during 1:1 tmrw
src/services/uniswap.js
Outdated
| const tokenAmountIn = new uni.TokenAmount(tIn, amountIn) | ||
| const result = uni.Router.swapCallParameters( | ||
| uni.Trade.exactIn(route, tokenAmountIn), | ||
| { ttl: 50, recipient: wallet.address, allowedSlippage: new uni.Percent('1', '100') } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ttl:Uniswap defines this as "how long the swap is valid until it expires, in seconds." I think we should make ttl an constant equal to 0 that is specified in uniswap.js.
allowedSlippage: I think we should make this a constant equal to 0 in uniswap.js as well. Since we set slippage buffer through the Hummingbot client, I don't think we need to add more slippage buffer here.
src/services/uniswap.js
Outdated
| // network defaults to KOVAN | ||
| const providerUrl = process.env.ETHEREUM_RPC_URL | ||
| this.network = process.env.ETHEREUM_CHAIN | ||
| this.chainID = uni.ChainId.KOVAN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line isn't needed since it's defined below
src/services/uniswap.js
Outdated
| var tOut = await uni.Fetcher.fetchTokenData(this.chainID, tokenOut) | ||
|
|
||
| try { | ||
| pair = await uni.Fetcher.fetchPairData(tIn, tOut) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent 2 spaces
src/services/uniswap.js
Outdated
| route = new uni.Route([pair], tIn, tOut) | ||
| } | ||
| catch(err){ | ||
| console.log('Trying alternative/indirect route.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar to above, indent 2 spaces
fengtality
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
buy doesn't work and throws an Operation Error - problems seems to reside in the swapExactOut` function
|
I added a commit which:
Smaller traders would use a small maxSwaps number because they care more about gas costs, while larger traders would use a high maxSwaps because they want the best price and don't care about gas as much. We should factor this calculation into the client profitability calculation as well: |
|
Sorry @vic-en for trampling all over your PR... I should have created a separate branch for the last 2 commits. I don't think they affected the Uniswap part of the code, but feel free to roll them back if you want. I think the |
I figured it. I'd push a commit to address that. |
No description provided.