Yield Farms

Reaper deals a lot with Master Chef contracts, so ways to easily deploy and manage a lot of them is important

Deploying your Master Chef

Create and deploy a MasterChef contract with a single function. Input the administrator address and emissions per second, and instead of putting the starting timestamp simply input the delay until emissions begin in seconds and the proper timestamp will be created for you.

reaper.deployMasterChef(adminAddress: string, emissions:bigNumber, delay:uint-seconds) => (contract:object)

Adding a new farm

Add farms to your Master Chef contract using the addFarm function. Pass in the address of your target Chef contract along with the supported token and number of allocation points. You can put a sleep after deployment to make sure the contract is finished constructing before your next call.

reaper.addFarm(masterchefAddress: string, tokenAddress: string, allocation: uint) => (transactionReceipt:object)

Depositing into your farms

After you add farms to your Master Chef, you can approve and deposit in one function with depositToFarm. Pass in the MasterChef address, the Pool ID, and the amount you're depositing.

reaper.depositToFarm(chefAddress: string, pid: uint, amount: uint) => transactionReceipt:object

In the below example, I deploy a test token, mint it to my wallet, then deploy my Master Chef, add a farm, and deposit into it

Retrieving User Info

You can view your account information struct with getUserInfo.

reaper.getUserInfo(chefAddress: string, pid: uint, userAddress: string) => (userInfo:object)

In the example below, I create a test token and mint it, then deploy my Master Chef, add a farm, deposit into it, and check on my position.

Inserting pauses with sleep() after complex transactions will ensure all your contract interactions have finished execution before you try to interact with them.

Using .toString() makes it easy to to read bigNumber return values in the console

  const testToken = await reaper.deployTestToken("Reaper.Farm", "R3PR", reaper.BigGas);

  await reaper.mintTestToken(testToken.address, self, await reaper.parseToken(100000));

  let chef = await reaper.deployMasterChef(self, ethers.utils.parseEther("0.01"), 3, reaper.BigGas);

  await reaper.addFarm(chef.address, testToken.address, 500, reaper.BigGas);

  await reaper.depositToFarm(chef.address, 0, await reaper.parseToken(500));
  let userInfo = await reaper.getUserInfo(chef.address, 0, self);

    "amount": userInfo.amount.toString(),
    "rewardDebt": userInfo.rewardDebt.toString()
> { amount: '500000000000000000000', rewardDebt: '0' }

See how many farms you've started

Read the length of your Master Chef contract's poolInfo array with getPoolLength.

reaper.getPoolLength(chefAddress) => (uint)

Retrieving farm information

Use getPoolInfo to return the PoolInfo struct for whatever Pool ID you pass in.

reaper.getPoolInfo(chefAddress:string, pid:uint) => (poolInfo:object)

  let poolInfo = await reaper.getPoolInfo(chef.address, 0);
    "lpToken": poolInfo.lpToken,
    "allocPoint": poolInfo.allocPoint.toString(),
    "lastRewardTime": poolInfo.lastRewardTime.toString(),
    "accCommPerShare": poolInfo.accCommPerShare.toString()
    lpToken: '0xE7411d7F74ea6ff4cF2658eb42232d34aEe9987D',
    allocPoint: '500',
    lastRewardTime: '1627374989',
    accCommPerShare: '0'

Last updated