Documentation Errors - Swap and Add Liquidity Atomically
Opened this issue · 0 comments
roigecode commented
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
}