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

Bump uniswap sdk core to 4.09 and add correct base swap router address #481

Merged
merged 2 commits into from
Feb 20, 2024

Conversation

sismanis
Copy link
Contributor

The swap router address for base is different for other chains so the function needs to account for that. Also, @uniswap/sdk-core needs to be bumped to 4.0.9 where the WETH9 contract for Base was added otherwise any pools with WETH on base will not work in this SDK with the swap router.

  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
    This will fix bugs with using base with the smart order router. Currently does not work with the current version of the sdk and is fixed with these changes

  • What is the current behavior? (You can also link to an open issue here)
    The current behavior will throw an error when requesting a swap router quote on base

  • What is the new behavior (if this is a feature change)?
    The swap router will work correctly and quotes are able to be fetched using the SDK

  • Other information:

@sismanis sismanis requested a review from a team as a code owner January 29, 2024 23:53
@wminshew
Copy link

wminshew commented Feb 6, 2024

would be great to get this merged, currently using the smart-order-router on base results in a loss of funds since they're sent to an EOA the function call "succeeds"

@cgkol
Copy link
Contributor

cgkol commented Feb 6, 2024

hey all,

We are currently not supporting actively the swapRouter02 and are planning on deprecating it soon. Instead, we recommend using the UniversalRouter which should have everything configured as expected.

@wminshew
Copy link

wminshew commented Feb 7, 2024

hey all,

We are currently not supporting actively the swapRouter02 and are planning on deprecating it soon. Instead, we recommend using the UniversalRouter which should have everything configured as expected.

it looks like the address in the docs doesn't match the address being used in the universal-router-sdk either. I think the docs are wrong and the sdk is right, but would you confirm for me? Obviously a little extra nervous here given we've already lost funds with the last wrong address

@cgkol
Copy link
Contributor

cgkol commented Feb 8, 2024

@wminshew thank you for the flag. Before I give you a final confirmation, let me circle back to confirm the right addresses and will get back to you asap

@hensha256
Copy link
Contributor

hey @sismanis , thanks so much for bringing this to our attention. I've dug further and it looks like we're facing the same issue with Avalanche too. Would you mind adding a further conditional for avalanche too please in your PR?
You can see here that avalanche has this address

@hensha256
Copy link
Contributor

it looks like the address in the docs doesn't match the address being used in the universal-router-sdk either. I think the docs are wrong and the sdk is right, but would you confirm for me? Obviously a little extra nervous here given we've already lost funds with the last wrong address

Sure! The address for universal-router-sdk is different because we deployed a new one in the last couple of weeks to add Uniswap V2 support (it previously only had Uniswap V3 supported on Base.). We have not added that router to our interface yet, so we are still working with 0x198EF79F1F515F02dFE9e3115eD9fC07183f02fC which you can find in our docs and in old universal-router-sdk versions! If youre only using Uniswap V3 then the address 0x198... is still perfect to use, or if you want Uniswap V2 support too, you should use the address in the latest SDK version.

@hensha256
Copy link
Contributor

I've made this PR for sdk-core, I think we should merge that as a catch-all to make sure this never happens again. Then we can publish that and you can integrate it here. What do you think?

@jsy1218
Copy link
Member

jsy1218 commented Feb 9, 2024

Personally I prefer to separate support OPTIMISM_SEPOLIA from this PR. Previously there was a PR about supporting OPTIMISM_SEPOLIA.

@jsy1218 jsy1218 mentioned this pull request Feb 9, 2024
@sismanis
Copy link
Contributor Author

sismanis commented Feb 9, 2024

hey @sismanis , thanks so much for bringing this to our attention. I've dug further and it looks like we're facing the same issue with Avalanche too. Would you mind adding a further conditional for avalanche too please in your PR? You can see here that avalanche has this address

Hey @hensha256 just added Avalanche address as well. I'm assuming it's in the SDK-core like the Base one is as well. If not can hardcode it in, but probably better to add it into core directly and reference

@hensha256
Copy link
Contributor

Hey! The PR I talked about in this message has now been merged and published into sdk-core version 4.1.2. If you want to update to that version, you should be able to update the PR to just use that function without special casing :)

@hensha256
Copy link
Contributor

Would also be great if you could separate the sepolia stuff into another PR as @jsy1218 said!

@jsy1218
Copy link
Member

jsy1218 commented Feb 14, 2024

Would also be great if you could separate the sepolia stuff into another PR as @jsy1218 said!

@sismanis I already merged OP Sepolia support. You should be able to separate just by merging from main branch.

@sismanis
Copy link
Contributor Author

@jsy1218 sounds good will do that today

@sismanis
Copy link
Contributor Author

@jsy1218 I can't update to sdk-core version 4.1.2 without adding arbitrum-sepolia support, and I need 4.1.2 to get the new swap router addresses exported from sdk-core. Do you want me to do that in a separate PR or do it here as well.

@jsy1218
Copy link
Member

jsy1218 commented Feb 15, 2024

@jsy1218 I can't update to sdk-core version 4.1.2 without adding arbitrum-sepolia support, and I need 4.1.2 to get the new swap router addresses exported from sdk-core. Do you want me to do that in a separate PR or do it here as well.

Sorry for the trouble, but would love to support arb-sepolia in a separate PR.

@jsy1218
Copy link
Member

jsy1218 commented Feb 15, 2024

@sismanis FYI I created the Arb-Sepolia PR. This PR has been hanging for a bit, and continuous user fund loss is a real risk. If possible, I'd like to lend a help and deploy to routing-api Thursday during EST business hours.

@sismanis
Copy link
Contributor Author

@sismanis FYI I created the Arb-Sepolia PR. This PR has been hanging for a bit, and continuous user fund loss is a real risk. If possible, I'd like to lend a help and deploy to routing-api Thursday during EST business hours.

Let me know when the arb PR is merged and I can rebase off of main and finalize the changes. Sure, I'm available pretty much any time today

@jsy1218
Copy link
Member

jsy1218 commented Feb 15, 2024

@sismanis FYI I created the Arb-Sepolia PR. This PR has been hanging for a bit, and continuous user fund loss is a real risk. If possible, I'd like to lend a help and deploy to routing-api Thursday during EST business hours.

Let me know when the arb PR is merged and I can rebase off of main and finalize the changes. Sure, I'm available pretty much any time today

@sismanis just merged :)

package.json Outdated Show resolved Hide resolved
@sismanis
Copy link
Contributor Author

Will reopen in a sec, just found it easier to reset to main and reimplement cause I had a lot of similar/conflicting changes with the sepolia stuff

@sismanis sismanis reopened this Feb 15, 2024
@sismanis
Copy link
Contributor Author

Should be good to go now @jsy1218. I noticed some conlficting keys in a test case with the new sepolia chains. Can fix that real quick in this PR if you want too

Screenshot 2024-02-15 at 12 02 01 PM

@jsy1218
Copy link
Member

jsy1218 commented Feb 15, 2024

Should be good to go now @jsy1218. I noticed some conlficting keys in a test case with the new sepolia chains. Can fix that real quick in this PR if you want too

Screenshot 2024-02-15 at 12 02 01 PM

That's fine, you can leave as is. I think the duplicate key is fine, since other PR can have all the tests pass #493.

@jsy1218
Copy link
Member

jsy1218 commented Feb 15, 2024

Integration Tests will fail, if the branch is forked from SOR. This is because a bunch of secrets used in https://github.com/Uniswap/smart-order-router/blob/main/.github/workflows/tests.yml require creating new repository secrets:

  •       JSON_RPC_PROVIDER: ${{ secrets.JSON_RPC_PROVIDER }}
    
  •       JSON_RPC_PROVIDER_GORLI: ${{ secrets.JSON_RPC_PROVIDER_GORLI }}
    
  •       JSON_RPC_PROVIDER_OPTIMISM: ${{ secrets.JSON_RPC_PROVIDER_OPTIMISM }}
    
  •       JSON_RPC_PROVIDER_OPTIMISM_GOERLI: ${{ secrets.JSON_RPC_PROVIDER_OPTIMISM_GOERLI }}
    
  •       JSON_RPC_PROVIDER_ARBITRUM_ONE: ${{ secrets.JSON_RPC_PROVIDER_ARBITRUM_ONE }}
    
  •       JSON_RPC_PROVIDER_ARBITRUM_GOERLI: ${{ secrets.JSON_RPC_PROVIDER_ARBITRUM_GOERLI }}
    
  •       JSON_RPC_PROVIDER_POLYGON: ${{ secrets.JSON_RPC_PROVIDER_POLYGON }}
    
  •       JSON_RPC_PROVIDER_POLYGON_MUMBAI: ${{ secrets.JSON_RPC_PROVIDER_POLYGON_MUMBAI }}
    
  •       JSON_RPC_PROVIDER_CELO: ${{ secrets.JSON_RPC_PROVIDER_CELO }}
    
  •       JSON_RPC_PROVIDER_CELO_ALFAJORES: ${{ secrets.JSON_RPC_PROVIDER_CELO_ALFAJORES }}
    
  •       JSON_RPC_PROVIDER_BNB: ${{ secrets.JSON_RPC_PROVIDER_BNB }}
    
  •       JSON_RPC_PROVIDER_AVALANCHE: ${{ secrets.JSON_RPC_PROVIDER_AVALANCHE }}
    
  •       JSON_RPC_PROVIDER_BASE: ${{ secrets.JSON_RPC_PROVIDER_BASE }}
    
  •       TENDERLY_BASE_URL: ${{ secrets.TENDERLY_BASE_URL }}
    
  •       TENDERLY_USER: ${{ secrets.TENDERLY_USER }}
    
  •       TENDERLY_PROJECT: ${{ secrets.TENDERLY_PROJECT }}
    
  •       TENDERLY_ACCESS_KEY: ${{ secrets.TENDERLY_ACCESS_KEY }}
    

The changes seems ok to me, and I'm ok merging it first, and see the main branch can have all the tests pass.

@jsy1218
Copy link
Member

jsy1218 commented Feb 15, 2024

Integration Tests will fail, if the branch is forked from SOR. This is because a bunch of secrets used in https://github.com/Uniswap/smart-order-router/blob/main/.github/workflows/tests.yml require creating new repository secrets:

  •       JSON_RPC_PROVIDER: ${{ secrets.JSON_RPC_PROVIDER }}
    
  •       JSON_RPC_PROVIDER_GORLI: ${{ secrets.JSON_RPC_PROVIDER_GORLI }}
    
  •       JSON_RPC_PROVIDER_OPTIMISM: ${{ secrets.JSON_RPC_PROVIDER_OPTIMISM }}
    
  •       JSON_RPC_PROVIDER_OPTIMISM_GOERLI: ${{ secrets.JSON_RPC_PROVIDER_OPTIMISM_GOERLI }}
    
  •       JSON_RPC_PROVIDER_ARBITRUM_ONE: ${{ secrets.JSON_RPC_PROVIDER_ARBITRUM_ONE }}
    
  •       JSON_RPC_PROVIDER_ARBITRUM_GOERLI: ${{ secrets.JSON_RPC_PROVIDER_ARBITRUM_GOERLI }}
    
  •       JSON_RPC_PROVIDER_POLYGON: ${{ secrets.JSON_RPC_PROVIDER_POLYGON }}
    
  •       JSON_RPC_PROVIDER_POLYGON_MUMBAI: ${{ secrets.JSON_RPC_PROVIDER_POLYGON_MUMBAI }}
    
  •       JSON_RPC_PROVIDER_CELO: ${{ secrets.JSON_RPC_PROVIDER_CELO }}
    
  •       JSON_RPC_PROVIDER_CELO_ALFAJORES: ${{ secrets.JSON_RPC_PROVIDER_CELO_ALFAJORES }}
    
  •       JSON_RPC_PROVIDER_BNB: ${{ secrets.JSON_RPC_PROVIDER_BNB }}
    
  •       JSON_RPC_PROVIDER_AVALANCHE: ${{ secrets.JSON_RPC_PROVIDER_AVALANCHE }}
    
  •       JSON_RPC_PROVIDER_BASE: ${{ secrets.JSON_RPC_PROVIDER_BASE }}
    
  •       TENDERLY_BASE_URL: ${{ secrets.TENDERLY_BASE_URL }}
    
  •       TENDERLY_USER: ${{ secrets.TENDERLY_USER }}
    
  •       TENDERLY_PROJECT: ${{ secrets.TENDERLY_PROJECT }}
    
  •       TENDERLY_ACCESS_KEY: ${{ secrets.TENDERLY_ACCESS_KEY }}
    

The changes seems ok to me, and I'm ok merging it first, and see the main branch can have all the tests pass.

I noticed that Tests / Unit Tests (pull_request) failed, which is set to be required for the branch protection rule, and block this PR from merging. For it to pass, it requires setting JSON_RPC_PROVIDER to your forked repo https://github.com/L1-Advisors/smart-order-router/tree/fix-base-swap-router. Do you have a JSON PRC ready? A free API key from Infura should do, i.e. https://mainnet.infura.io/v3/{API_KEY}

@sismanis
Copy link
Contributor Author

Integration Tests will fail, if the branch is forked from SOR. This is because a bunch of secrets used in https://github.com/Uniswap/smart-order-router/blob/main/.github/workflows/tests.yml require creating new repository secrets:

  •       JSON_RPC_PROVIDER: ${{ secrets.JSON_RPC_PROVIDER }}
    
  •       JSON_RPC_PROVIDER_GORLI: ${{ secrets.JSON_RPC_PROVIDER_GORLI }}
    
  •       JSON_RPC_PROVIDER_OPTIMISM: ${{ secrets.JSON_RPC_PROVIDER_OPTIMISM }}
    
  •       JSON_RPC_PROVIDER_OPTIMISM_GOERLI: ${{ secrets.JSON_RPC_PROVIDER_OPTIMISM_GOERLI }}
    
  •       JSON_RPC_PROVIDER_ARBITRUM_ONE: ${{ secrets.JSON_RPC_PROVIDER_ARBITRUM_ONE }}
    
  •       JSON_RPC_PROVIDER_ARBITRUM_GOERLI: ${{ secrets.JSON_RPC_PROVIDER_ARBITRUM_GOERLI }}
    
  •       JSON_RPC_PROVIDER_POLYGON: ${{ secrets.JSON_RPC_PROVIDER_POLYGON }}
    
  •       JSON_RPC_PROVIDER_POLYGON_MUMBAI: ${{ secrets.JSON_RPC_PROVIDER_POLYGON_MUMBAI }}
    
  •       JSON_RPC_PROVIDER_CELO: ${{ secrets.JSON_RPC_PROVIDER_CELO }}
    
  •       JSON_RPC_PROVIDER_CELO_ALFAJORES: ${{ secrets.JSON_RPC_PROVIDER_CELO_ALFAJORES }}
    
  •       JSON_RPC_PROVIDER_BNB: ${{ secrets.JSON_RPC_PROVIDER_BNB }}
    
  •       JSON_RPC_PROVIDER_AVALANCHE: ${{ secrets.JSON_RPC_PROVIDER_AVALANCHE }}
    
  •       JSON_RPC_PROVIDER_BASE: ${{ secrets.JSON_RPC_PROVIDER_BASE }}
    
  •       TENDERLY_BASE_URL: ${{ secrets.TENDERLY_BASE_URL }}
    
  •       TENDERLY_USER: ${{ secrets.TENDERLY_USER }}
    
  •       TENDERLY_PROJECT: ${{ secrets.TENDERLY_PROJECT }}
    
  •       TENDERLY_ACCESS_KEY: ${{ secrets.TENDERLY_ACCESS_KEY }}
    

The changes seems ok to me, and I'm ok merging it first, and see the main branch can have all the tests pass.

I noticed that Tests / Unit Tests (pull_request) failed, which is required, and block the merge. For it to pass, it requires setting JSON_RPC_PROVIDER to your forked repo https://github.com/L1-Advisors/smart-order-router/tree/fix-base-swap-router. Do you have a JSON PRC ready? A free API key from Infura should do, i.e. https://mainnet.infura.io/v3/{API_KEY}

Yeah no problem I have one ready. Will set that now

@sismanis
Copy link
Contributor Author

Alright @jsy1218 just added JSON_RPC_PROVIDER to my repo secrets. Should be good to go

@jsy1218
Copy link
Member

jsy1218 commented Feb 15, 2024

Alright @jsy1218 just added JSON_RPC_PROVIDER to my repo secrets. Should be good to go

Weird, I manually retried unit test, and the latest run shows that JSON_RPC_PROVIDER is still empty:

Screenshot 2024-02-16 at 2 29 10 AM

Did you add as Repository Secrets?

Screenshot 2024-02-16 at 2 31 22 AM

@sismanis
Copy link
Contributor Author

Alright @jsy1218 just added JSON_RPC_PROVIDER to my repo secrets. Should be good to go

Weird, I manually retried unit test, and the latest run shows that JSON_RPC_PROVIDER is still empty:

Screenshot 2024-02-16 at 2 29 10 AM Did you add as Repository Secrets? Screenshot 2024-02-16 at 2 31 22 AM

Yep, that's where I added it. Very weird.
Screenshot 2024-02-15 at 12 33 13 PM

@sismanis
Copy link
Contributor Author

@jsy1218 just updated it again and double checked it was there idk if I messed something up the first time

@jsy1218
Copy link
Member

jsy1218 commented Feb 15, 2024

@jsy1218 just updated it again and double checked it was there idk if I messed something up the first time

Manully retryed again. It fails again, and I can't quite tell why. I think I will create a PR within Uniswap SOR, so as to ship this fix asap.

@sismanis
Copy link
Contributor Author

@jsy1218 just updated it again and double checked it was there idk if I messed something up the first time

Manully retryed again. It fails again, and I can't quite tell why. I think I will create a PR within Uniswap SOR, so as to ship this fix asap.

That's a shame I was hoping to get some contribution credit to the repo. Would it work if I created the PR within this repo and not from a fork? I can handle it if that's the case

@jsy1218
Copy link
Member

jsy1218 commented Feb 15, 2024

@jsy1218 just updated it again and double checked it was there idk if I messed something up the first time

Manully retryed again. It fails again, and I can't quite tell why. I think I will create a PR within Uniswap SOR, so as to ship this fix asap.

That's a shame I was hoping to get some contribution credit to the repo. Would it work if I created the PR within this repo and not from a fork? I can handle it if that's the case

Well.. Only Uniswap Labs employees can be added to the Uniswap org, in order to create the PR within https://github.com/Uniswap repos.

Can you disable all tests in token-properties-provider.test.ts and token-fee-fetcher.test.ts? That's probably gonna make unit test pass as well. I think I will follow up by putting token-properties-provider.test.ts and token-fee-fetcher.test.ts out of the unit test suite. I tested locally, disable all tests in token-properties-provider.test.ts and token-fee-fetcher.test.ts can make unit test pass.

This way you can still get contribution credit, meanwhile the repo can be better structured to serve future community contributions as well.

@sismanis
Copy link
Contributor Author

@jsy1218 just updated it again and double checked it was there idk if I messed something up the first time

Manully retryed again. It fails again, and I can't quite tell why. I think I will create a PR within Uniswap SOR, so as to ship this fix asap.

That's a shame I was hoping to get some contribution credit to the repo. Would it work if I created the PR within this repo and not from a fork? I can handle it if that's the case

Well.. Only Uniswap Labs employees can be added to the Uniswap org, in order to create the PR within https://github.com/Uniswap repos.

Can you disable all tests in token-properties-provider.test.ts and token-fee-fetcher.test.ts? That's probably gonna make unit test pass as well. I think I will follow up by putting token-properties-provider.test.ts and token-fee-fetcher.test.ts out of the unit test suite. I tested locally, disable all tests in token-properties-provider.test.ts and token-fee-fetcher.test.ts can make unit test pass.

This way you can still get contribution credit, meanwhile the repo can be better structured to serve future community contributions as well.

Yep, I will do that right now. Thanks so much.

@sismanis
Copy link
Contributor Author

@jsy1218 just FYI I skipped the tests in those files. Not 100% sure if I did it correctly.

@jsy1218
Copy link
Member

jsy1218 commented Feb 16, 2024

@jsy1218 just FYI I skipped the tests in those files. Not 100% sure if I did it correctly.

@sismanis I think you can merge

@sismanis
Copy link
Contributor Author

@jsy1218 just FYI I skipped the tests in those files. Not 100% sure if I did it correctly.

@sismanis I think you can merge

I can't merge, says only those with write access can merge to this repository

@jsy1218
Copy link
Member

jsy1218 commented Feb 18, 2024

@jsy1218 just FYI I skipped the tests in those files. Not 100% sure if I did it correctly.

@sismanis I think you can merge

I can't merge, says only those with write access can merge to this repository

Ok, I can help merge next Tuesday EST time. Monday is a company holiday.

@jsy1218 jsy1218 merged commit a9f037a into Uniswap:main Feb 20, 2024
8 of 23 checks passed
mikeki added a commit that referenced this pull request Feb 22, 2024
mikeki added a commit that referenced this pull request Feb 22, 2024
* Bump V2-SDK to 4.2.0

* 3.24.1

* 3.24.2

* fix test

* update dependencies

* Revert "Bump uniswap sdk core to 4.09 and add correct base swap router address (#481)"

This reverts commit a9f037a.

* increase gas deviation
@jsy1218
Copy link
Member

jsy1218 commented Feb 23, 2024

@sismanis FYI, this PR was reverted due to regression. I haven't had the time to figure out what's wrong with the PR yet. How much user fund loss risk are we talking about here?

Update - the regression might be explained here Uniswap/sdk-core#120

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.

5 participants