Skip to content

Commit

Permalink
Merge pull request #123 from traderjoe-xyz/fix-boring-helper
Browse files Browse the repository at this point in the history
fix BoringHelperV1 after MasterChef end of supply issue
  • Loading branch information
Mathieu-Be authored Nov 7, 2023
2 parents bdcdb6e + 6234508 commit 7009081
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
13 changes: 12 additions & 1 deletion contracts/boringcrypto/BoringHelperV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -878,4 +878,15 @@ 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;
}
}
}
34 changes: 34 additions & 0 deletions test/foundry/BoringHelperV1.t.sol
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 7009081

Please sign in to comment.