diff --git a/contracts/boringcrypto/BoringHelperV1.sol b/contracts/boringcrypto/BoringHelperV1.sol index 4c7189e0..11eff44c 100644 --- a/contracts/boringcrypto/BoringHelperV1.sol +++ b/contracts/boringcrypto/BoringHelperV1.sol @@ -858,7 +858,7 @@ contract BoringHelperV1 is Ownable { for (uint256 i = 0; i < pids.length; i++) { (uint256 amount, ) = chef.userInfo(pids[i], who); pools[i].balance = amount; - (uint256 pendingJoe, , , ) = chef.pendingTokens(pids[i], who); + uint256 pendingJoe = _pendingTokens(pids[i], who); pools[i].pending = pendingJoe; (address lpToken, , , ) = chef.poolInfo(pids[i]); @@ -878,4 +878,16 @@ contract BoringHelperV1 is Ownable { } return pools; } + + + /// @notice Returns the user's pendingTokens for a specific pool of the MasterChef contract + /// @param pid The pool id + /// @param who The user's address + function _pendingTokens(uint256 pid, address who) internal view returns (uint256) { + try chef.pendingTokens(pid, who) returns (uint256 pendingJoe, address, string memory, uint256) { + return pendingJoe; + } catch { + return 0; + } + } } diff --git a/test/foundry/BoringHelperV1.t.sol b/test/foundry/BoringHelperV1.t.sol new file mode 100644 index 00000000..aad192ea --- /dev/null +++ b/test/foundry/BoringHelperV1.t.sol @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: MIT +pragma experimental ABIEncoderV2; +pragma solidity 0.6.12; + +import "forge-std/Test.sol"; + +import "contracts/boringcrypto/BoringHelperV1.sol"; + +contract testBoringHelperV1 is Test { + BoringHelperV1 constant boringHelper = BoringHelperV1(0x1dd4D86180EEe39ac4fB35ECa67CACF608Ab5741); + + function setUp() public { + vm.createSelectFork(vm.rpcUrl("avalanche"), 37292546); + } + + function test_PollPools() public { + uint256[] memory pids = new uint256[](1); + + vm.expectRevert("SafeMath: division by zero"); + boringHelper.pollPools(address(this), pids); + + BoringHelperV1 newBoringHelper = new BoringHelperV1( + boringHelper.chef(), + boringHelper.maker(), + boringHelper.joe(), + boringHelper.WAVAX(), + boringHelper.joeFactory(), + boringHelper.pangolinFactory(), + boringHelper.bar() + ); + + newBoringHelper.pollPools(address(this), pids); + } +}