Guide To Emergency Withdraw Your LP in A Yield Farm

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

11/24/21, 9:24 AM Guide to Emergency Withdraw your LP in a yield farm | by Stakingbits | Stakingbits | Nov, 2021 | Medium

Open in app

Follow 2.3K Followers

Guide to Emergency Withdraw your LP in a


yield farm
Stakingbits 9 hours ago · 5 min read

Imagine you’re yield farming on a degen yield farm with 60,000% APY and suddenly
the UI goes down, what do you do? Maybe you’d want to withdraw your funds, but you
can’t because the website is down!

https://medium.com/stakingbits/guide-to-emergency-withdraw-your-lp-in-a-yield-farm-7104873a7e71 1/7
11/24/21, 9:24 AM Guide to Emergency Withdraw your LP in a yield farm | by Stakingbits | Stakingbits | Nov, 2021 | Medium

In this guide, we’ll show you how you can emergency withdraw your funds from the
yield farm by interacting directly with the smart contracts.

Most yield farming projects have a typical MasterChef contract which acts as the brain
and control centre of a yield farming platform; it typically wields much power and has
the ability to pull all users’ funds from the platform.

In order to emergency withdraw, you’d need to first start with identifying this
important piece of smart contract which your funds are controlled by.

Step 1: Locate the MasterChef contract for the farm


The first step is to identify the MasterChef contract for the platform — the details are
usually found in the documentation of the yield farm.

Let’s take for example PancakeSwap, if we head over to their docs;

We can find the link to the MasterChef contract, and clicking on it brings us to the
smart contract on BSCscan.

https://medium.com/stakingbits/guide-to-emergency-withdraw-your-lp-in-a-yield-farm-7104873a7e71 2/7
11/24/21, 9:24 AM Guide to Emergency Withdraw your LP in a yield farm | by Stakingbits | Stakingbits | Nov, 2021 | Medium

Most other farms should have a similar MasterChef contract, regardless whether the
farm is on BSC, Polygon, Fantom or Avalanche.

In another example, let’s take a look at CronaSwap — a DEX on Cronos. The link to the
MasterChef on Cronos Explorer is located here.

Step 2: Locate the pool ID (pid) of the pool you were farming in
The second step is to find the pid of the liquidity pool you were farming in.

Each pool deployed by the MasterChef is associated with a pid, which is then used to
identify the pool and perform actions within the MasterChef contract such as
harvesting rewards.

To locate the pid, look for the transaction in which you’ve deposited your LP
tokens in the MasterChef contract on the block explorer.

Scroll down on the block explorer until you find Input Data.

Click on Decode Input Data.

This will decode the data and show you the pid of the pool that you’ve deposited in.

https://medium.com/stakingbits/guide-to-emergency-withdraw-your-lp-in-a-yield-farm-7104873a7e71 3/7
11/24/21, 9:24 AM Guide to Emergency Withdraw your LP in a yield farm | by Stakingbits | Stakingbits | Nov, 2021 | Medium

Take note of this integer, in this case the pid is 263.

Step 3: Call the Emergency Withdraw function on the MasterChef


contract
Head back to the MasterChef contract on your respective blockchain.

Let’s use PancakeSwap again for example (MasterChef link).

Click on Write Contract, then Connect to Web3 and authenticate with Metamask.

Once connected to your wallet, head down to the emergencyWithdraw function.

https://medium.com/stakingbits/guide-to-emergency-withdraw-your-lp-in-a-yield-farm-7104873a7e71 4/7
11/24/21, 9:24 AM Guide to Emergency Withdraw your LP in a yield farm | by Stakingbits | Stakingbits | Nov, 2021 | Medium

Enter the pid for the pool to exit, then click Write.

Sign the transaction on Metamask to call Emergency Withdraw directly on the


contract. This allows you to withdraw your funds from the contract even though the UI
is down.

Note that if the funds have been already drained by an exploit or hacker, calling emergency
withdraw would not return any funds to your wallet.

A note about preventing rug pulls with timelocks


Since the MasterChef is an extremely powerful piece of smart contract, it is crucial that
you understand what power the developers hold when it comes to managing your
funds deposited onto the platform.

In many cases, many funds have been stolen by a rug-pull.

A timelock is usually used in an attempt to mitigate the risk of a rug-pull, which is a


piece of code that locks the smart contract code execution for the duration of the
timelock, preventing it from being executed immediately.

https://medium.com/stakingbits/guide-to-emergency-withdraw-your-lp-in-a-yield-farm-7104873a7e71 5/7
11/24/21, 9:24 AM Guide to Emergency Withdraw your LP in a yield farm | by Stakingbits | Stakingbits | Nov, 2021 | Medium

This means users can monitor the timelock smart contract for suspicious activities, and
withdraw their funds if needed.

The timelock is usually set as the owner of the MasterChef contract. For example,
PancakeSwap’s MasterChef has the address
0xA1f482Dc58145Ba2210bC21878Ca34000E2e8fE4 set as the owner, which points to
the timelock smart contract.

By having the timelock in place, and verified publicly, every transaction that takes
place needs to be first queued before it can be executed.

You can view the timelock delay (in seconds) by reading the timelock contract and
scrolling to view the delay function. 21700 seconds represents a timelock of 6 hours.

How to spot a potential rug pull in DeFi


“Got rugged?”
medium.com

https://medium.com/stakingbits/guide-to-emergency-withdraw-your-lp-in-a-yield-farm-7104873a7e71 6/7
11/24/21, 9:24 AM Guide to Emergency Withdraw your LP in a yield farm | by Stakingbits | Stakingbits | Nov, 2021 | Medium

Subscribe to our newsletter so that you don’t miss our latest updates!

Sign up for The Wild Forest


By Stakingbits

The Wild Forest is the fastest growing DeFi newsletter with content summaries, guides, monthly
roundups and more. We help our 1000+ subscribers navigate DeFi's wild forest and you don't want to
miss. Take a look.

Emails will be sent to leefeng91@gmail.com.


Get this newsletter Not you?

Yield Farming Emergency Withdraw Defi

About Write Help Legal

Get the Medium app

https://medium.com/stakingbits/guide-to-emergency-withdraw-your-lp-in-a-yield-farm-7104873a7e71 7/7

You might also like