Uniswap / v2-sdk

🛠 An SDK for building applications on top of Uniswap V2
https://uniswap.org/docs/v2/SDK/getting-started
MIT License
428 stars 1.09k forks source link

Custom `FACTORY_ADDRESS` and `INIT_CODE_HASH` #130

Closed vladikopl01 closed 1 year ago

vladikopl01 commented 1 year ago

Is there any way to pass custom FACTORY_ADDRESS and INIT_CODE_HASH to SDK to work with different forks of UniswapV2 dexes? Or the way how to overwrite them for each dex?

Florian-S-A-W commented 1 year ago

Hi @vladikopl01

The SDK does not allow passing in a custom FACTORY_ADDRESS or INIT_CODE_HASH. Looking at the code, it seems that both are only used to compute the address of pairs: https://github.com/Uniswap/v2-sdk/blob/main/src/entities/pair.ts#L10

I have seen a couple of Uniswap forks that just forked the SDK and replaced the hard-coded values in constants. If you don't want to have duplicate code in your project you could fork this repository and amend the getAddress function in the Pair class. Passing the factory address and init code hash there: https://github.com/Uniswap/v2-sdk/blob/main/src/entities/pair.ts#L30 and in the compute function: https://github.com/Uniswap/v2-sdk/blob/main/src/entities/pair.ts#L10 should do the trick.

I guess the values are hard coded to make the sdk easier to use. After all it's primarily meant to be used for Uniswap and not forks.