Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Documentation Errors - Swap and Add Liquidity Atomically #144

Open
roigecode opened this issue Oct 8, 2022 · 0 comments
Open

Documentation Errors - Swap and Add Liquidity Atomically #144

roigecode opened this issue Oct 8, 2022 · 0 comments

Comments

@roigecode
Copy link

roigecode commented Oct 8, 2022

In the Swap and Add Liquidity Atomically documentation page https://docs.uniswap.org/sdk/guides/liquidity/swap-and-add there are two errors in the code provided when sending the transaction.

The example provided is:

import { SwapToRatioStatus } from "@uniswap/smart-order-router";

const V3_SWAP_ROUTER_ADDRESS = "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45";
const MY_ADDRESS = "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B";

if (routeToRatioResponse.status == SwapToRatioStatus.success) { // Error 1 - '.success' instead of '.SUCCESS'
  const route = routeToRatioResponse.result
  const transaction = {
    data: route.methodParameters.calldata,
    to: V3_SWAP_ROUTER_ADDRESS,
    value: BigNumber.from(route.methodParameters.value),
    from: MY_ADDRESS,
    gasPrice: BigNumber.from(route.gasPriceWei),
  };
) // Error 2 - Closing ')' instead of '}'

await web3Provider.sendTransaction(transaction);
// Possible Error - await out of 'if' scope, if it fails transaction is not defined

If one tries to run the code above (making the relevant changes such as the Address) it will not work.

The code should instead be:

import { SwapToRatioStatus } from "@uniswap/smart-order-router";

const V3_SWAP_ROUTER_ADDRESS = "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45";
const MY_ADDRESS = "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B";

if (routeToRatioResponse.status == SwapToRatioStatus.SUCCESS) { 
  const route = routeToRatioResponse.result
  const transaction = {
    data: route.methodParameters.calldata,
    to: V3_SWAP_ROUTER_ADDRESS,
    value: BigNumber.from(route.methodParameters.value),
    from: MY_ADDRESS,
    gasPrice: BigNumber.from(route.gasPriceWei),
  };
await web3Provider.sendTransaction(transaction);
}

As the SwapToRatioStatus enum does not have a property called success but instead SUCCESS:

// router.d.ts
export declare enum SwapToRatioStatus {
    SUCCESS = 1,
    NO_ROUTE_FOUND = 2,
    NO_SWAP_NEEDED = 3
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant