Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom route methods && uniswap v3 multi hop #45

Merged
merged 20 commits into from
Aug 4, 2022

Conversation

liu-zhipeng
Copy link
Contributor

@liu-zhipeng liu-zhipeng commented Jun 28, 2022

  • support custom router abi (For Pangolin and Trader Joe swap on avalanche)
  • support custom router method names
  • support uniswap v3 multihop
  • fix some issues
  • Unit tests
  • readme

@liu-zhipeng liu-zhipeng marked this pull request as ready for review June 29, 2022 15:05
@liu-zhipeng
Copy link
Contributor Author

Hi. I am so excited to contribute to such a great project. I found some small problems while using uniswap sdk. For example, some uniswap forked dexs like pangolin swap changed router functions. especially ETH to AVAX. So i added some changes for developers to use custom router abi and router methods. Also I added some code to support uniswap v3 multihop. I would like you to review my changes if you have time. Thank you again for a great sdk!

@joshstevens19
Copy link
Owner

Hey @liu-zhipeng firstly thanks so much for this!! Help from others is needed and this looks incredible already.

Only scanned on phone but 1 thing which popped out any new things or featured you added to this please add to the readme doc, for example you done some liquidity work and now supporting multihop adding to the docs is the last part missing I think!

I will review this tomorrow be great to review with the docs update as well thanks a lot hope this will be your first of many PRs 💪

@liu-zhipeng
Copy link
Contributor Author

liu-zhipeng commented Jun 29, 2022

Hey @liu-zhipeng firstly thanks so much for this!! Help from others is needed and this looks incredible already.

Only scanned on phone but 1 thing which popped out any new things or featured you added to this please add to the readme doc, for example you done some liquidity work and now supporting multihop adding to the docs is the last part missing I think!

I will review this tomorrow be great to review with the docs update as well thanks a lot hope this will be your first of many PRs 💪

Yep. i will do! Also i am going to add unit tests for new features as well.

@liu-zhipeng liu-zhipeng reopened this Jun 29, 2022
.gitignore Outdated Show resolved Hide resolved
README.md Outdated
// For multihop swap
// Sequence of Fees
// ex: USDC>USDT>WETH>WBTC => [(USDC-USDT fee), (USDT-WETH fee), (WETH-WBTC fee)]
liquidityProviderFee: string[];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't seem correct here as in v2 it would still be string

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in v2 liquidityProviderFee should be array in this version

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liu-zhipeng am i correct?

README.md Outdated
@@ -437,7 +447,7 @@ export interface TradeContext {
// aka 0.05% = 0.0005
// 0.3% = 0.003
// 1% = 0.01
liquidityProviderFeePercent: number;
liquidityProviderFeePercent: number[];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't seem correct here as in v2 it would still be string

README.md Outdated
@@ -464,7 +474,7 @@ export interface TradeContext {
routeText: string;
routePathArray: string[];
uniswapVersion: UniswapVersion;
liquidityProviderFee: number;
liquidityProviderFee: number[];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't seem correct here as in v2 it would still be string

README.md Outdated
liquidityProviderFee: '0.030000000000000000',
liquidityProviderFeePercent: 0.003,
liquidityProviderFee: ['0.030000000000000000','0.050000000000000000','0.030000000000000000'],
liquidityProviderFeePercent: [0.003, 0.005, 0.003],
Copy link
Owner

@joshstevens19 joshstevens19 Jun 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from my memory the liquidity provider fee percent on this level is just 1 percent and if you got many routes with different providers fees it would create repeated objects with the single fee. Then order by the best.

liquidityProviderFee: string;
liquidityProviderFeePercent: number;
liquidityProviderFee: string[];
liquidityProviderFeePercent: number[];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again arrays here v2 wont be an array

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above breaking change in the trade context ..

@@ -333,14 +333,13 @@ export class UniswapPairFactory {
? null
: bestRouteQuote.expectedConvertQuoteOrTokenAmountInMaxWithSlippage,
expectedConvertQuote: bestRouteQuote.expectedConvertQuote,
liquidityProviderFee:
liquidityProviderFee: bestRouteQuote.liquidityProviderFee.map((f) =>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

breaking changes for v2.. if many liquidity provider fees the expected convert quote will be different depending on that no? would not expect a loop here i dont think...

@@ -404,14 +403,13 @@ export class UniswapPairFactory {
? null
: bestRouteQuote.expectedConvertQuoteOrTokenAmountInMaxWithSlippage,
expectedConvertQuote: bestRouteQuote.expectedConvertQuote,
liquidityProviderFee:
liquidityProviderFee: bestRouteQuote.liquidityProviderFee.map((f) =>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@@ -470,14 +468,13 @@ export class UniswapPairFactory {
? null
: bestRouteQuote.expectedConvertQuoteOrTokenAmountInMaxWithSlippage,
expectedConvertQuote: bestRouteQuote.expectedConvertQuote,
liquidityProviderFee:
liquidityProviderFee: bestRouteQuote.liquidityProviderFee.map((f) =>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

src/factories/router/models/token-routes.ts Show resolved Hide resolved
@mburger81
Copy link

@joshstevens19 @liu-zhipeng
when do you think you can find a solution for the changes requested and release this?

@liu-zhipeng
Copy link
Contributor Author

@joshstevens19 @liu-zhipeng when do you think you can find a solution for the changes requested and release this?

Once @joshstevens19 confirms this, we can release this, cus all features are working properly now.

@mburger81
Copy link

So you resolved the backward compatibility? There was a problem about in some points your returned now an array []

could you maybe release in meantime your version on npm?

@liu-zhipeng
Copy link
Contributor Author

liu-zhipeng commented Jul 11, 2022

That is no problem at all to return liquidityProviderFee as array. If there are some issues on the apps which are using old version. they MUST update to support uniswap v3. Because each uniswap V3 pairs have 3 different fee tiers.
I am waiting for @joshstevens19 's reivew yet.

@joshstevens19
Copy link
Owner

No PR is good sorry been away I’m going to get to this soon!

@mburger81
Copy link

@liu-zhipeng why did you close this unmerged?

@joshstevens19 joshstevens19 reopened this Jul 27, 2022
@ghost
Copy link

ghost commented Aug 1, 2022

when will you release this? @liu-zhipeng

@mburger81
Copy link

@helios8090 the problem is, @liu-zhipeng can not do the merge and the release
@joshstevens19 sorry dude but its really annoying :(

@liu-zhipeng
Copy link
Contributor Author

@helios8090 the problem is, @liu-zhipeng can not do the merge and the release @joshstevens19 sorry dude but its really annoying :(

I have no permission to merge.

@mburger81
Copy link

@liu-zhipeng I know, for that reason I asked you to fork, merge and release your own repository, just temporally until @joshstevens19 will merge it

we are trying to make webcomponents for the community using simple-uniswap to deliver a well working, free, fast, working everywhere solution
but we are stuck on waiting this merge since e 5 weeks

@joshstevens19
Copy link
Owner

Guys super sorry I’ve been away and it’s super hard for me to see these sometimes. The main problem with the PR is it’s a breaking interface change to the liquidity interface which means if we release it everyones integration will break who use to think that was a string. I’m going to set a note for tomorrow AM before I do anything else to do another PR review on this. I did do a PR review but the things I asked still is missing. We can’t do breaking changes in the interface we can ofc add a new field and depreciate the old one for v1 and v2 use only but if you could make it so v2 interface is NONE breaking then I’m happy to get this in asap @liu-zhipeng

@joshstevens19
Copy link
Owner

Remind me set.. tomorrow AM 9:45 BST! will do another review of it and highlight the main issues. Sorry for the delay!

@mburger81
Copy link

Yeah that was what I'm saying, there is this breaking change you already told us
for that reason I was wondering why you wrote later, anything is fine, because it isn't

I Just ask you to maybe integrate this changes also on the swap ui you provide

THX a lot!

@joshstevens19
Copy link
Owner

Well it is - you just expose the field in a new property in the interface and write docs around it why, it’s a very easy fix in this PR!

@@ -8,7 +8,7 @@ export interface CurrentTradeContext {
quoteDirection: TradeDirection;
fromToken: Token;
toToken: Token;
liquidityProviderFee: string;
liquidityProviderFee: string[];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This here! This needs to be a new field if it has to be an array so it doesn’t do a breaking change to the interface

liquidityProviderFee: string;
liquidityProviderFeePercent: number;
liquidityProviderFee: string[];
liquidityProviderFeePercent: number[];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above breaking change in the trade context ..

@mburger81
Copy link

@liu-zhipeng nice!

@joshstevens19
Copy link
Owner

this looks better @liu-zhipeng can you just update the readme docs to show the new field and explain it so people understand?

@liu-zhipeng
Copy link
Contributor Author

liu-zhipeng commented Aug 2, 2022

I have already updated readme.

@liu-zhipeng
Copy link
Contributor Author

7a178a7

Copy link
Owner

@joshstevens19 joshstevens19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to run 1 manual test later if good will merge and deploy.. thanks for doing this and sorry it ended up taking longer then we wanted. @liu-zhipeng your a legend!

@liu-zhipeng
Copy link
Contributor Author

Thank you for your approval. @joshstevens19 And I am super happy if my work can be helpful for others.

@joshstevens19
Copy link
Owner

joshstevens19 commented Aug 3, 2022

@liu-zhipeng so done manually tests everything works well, just one thing I spotted is when on a v2 trade the liquidityProviderFeesV3 is populated it should be an empty array [] could you do that then we can merge and deploy!

image

@liu-zhipeng
Copy link
Contributor Author

@liu-zhipeng so done manually tests everything works well, just one thing I spotted is when on a v2 trade the liquidityProviderFeesV3 is populated it should be an empty array [] could you do that then we can merge and deploy!

image

I thought that was more consistent. anyway updated finally!

@joshstevens19 joshstevens19 merged commit 75b9f9c into joshstevens19:master Aug 4, 2022
@joshstevens19
Copy link
Owner

amazing! Will deploy tomorrow @liu-zhipeng thanks again

@liu-zhipeng
Copy link
Contributor Author

Awesome!

@joshstevens19
Copy link
Owner

https://github.com/joshstevens19/simple-uniswap-sdk/releases/tag/3.7.0 - its now deployed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants