Skip to content

Allow ETH and WETH work side by side - BREAKING CHANGE!

Compare
Choose a tag to compare
@joshstevens19 joshstevens19 released this 07 Jul 13:55
· 55 commits to master since this release
9053803

The old approach assumed everything was native eth but you had to pass in weth contract address. This also meant you could not do a ETH > WETH swap and you also got all WETH context back all the time. This change now makes it very clear when your using ETH and when your using WETH. From the interface point of view not much has changed you now can use the native eth using:

import { UniswapPair, ChainId, UniswapVersion, ETH } from 'simple-uniswap-sdk';

const uniswapPair = new UniswapPair({
  // the contract address of the token you want to convert FROM
  fromTokenContractAddress: ETH.MAINNET().contractAddress,
  // the contract address of the token you want to convert TO
  toTokenContractAddress: '0x1985365e9f78359a9B6AD760e32412f4a445E862',
  // the ethereum address of the user using this part of the dApp
  ethereumAddress: '0xB1E6079212888f0bE0cf55874B2EB9d7a5e02cD9',
  ethereumProvider: YOUR_WEB3_ETHERS_OR_CUSTOM_ETHEREUM_PROVIDER,
  settings: new UniswapPairSettings({
    // if not supplied it will use `0.005` which is 0.5%
    // please pass it in as a full number decimal so 0.7%
    // would be 0.007
    slippage: 0.005,
    // if not supplied it will use 20 a deadline minutes
    deadlineMinutes: 20,
    // if not supplied it will try to use multihops
    // if this is true it will require swaps to direct
    // pairs
    disableMultihops: false,
    // for example if you only wanted to turn on quotes for v3 and not v3
    // you can only support the v3 enum same works if you only want v2 quotes
    // if you do not supply anything it query both v2 and v3
    uniswapVersions: [UniswapVersion.v2, UniswapVersion.v3],
  }),
});

// now to create the factory you just do
const uniswapPairFactory = await uniswapPair.createFactory();

WETH class has been renamed to WETHContract so people who upgrade get compile-time errors to alert them they need to change their approach. WETH can be used using WETHContract.MAINNET().contractAddress.

Also we have removed the flag useWETHAsERC20Route on the settings as this approach felt wrong and hidden away. We have also added toBalance on the TradeContext interface response now.

Thanks!