Skip to content

Commit

Permalink
Support internal/external transfer mode on claim plenty
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaman1337 committed May 18, 2024
1 parent 7bddb9d commit f4b3608
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
6 changes: 4 additions & 2 deletions protocol/contracts/beanstalk/silo/SiloFacet/Silo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import {LibBytes} from "contracts/libraries/LibBytes.sol";
import {C} from "contracts/C.sol";
import {IWell} from "contracts/interfaces/basin/IWell.sol";
import {LibTokenApprove} from "contracts/libraries/Token/LibTokenApprove.sol";

This comment has been minimized.

Copy link
@Brean0

Brean0 May 18, 2024

Contributor

LibTokenApprove not needed here :)

This comment has been minimized.

Copy link
@pizzaman1337

pizzaman1337 May 19, 2024

Author Contributor

Removed here: 1c52d73

import "contracts/libraries/Token/LibTransfer.sol";

/**
* @title Silo
Expand Down Expand Up @@ -140,12 +142,12 @@ contract Silo is ReentrancyGuard {
* if `s.a[account].sop.plenty == 0`. This would emit a ClaimPlenty event
* with an amount of 0.
*/
function _claimPlenty(address account, address well) internal {
function _claimPlenty(address account, address well, LibTransfer.To toMode) internal {
uint256 plenty = s.a[account].sop[well].plenty;
if (plenty > 0) {
IERC20[] memory tokens = IWell(well).tokens();
IERC20 sopToken = tokens[0] != C.bean() ? tokens[0] : tokens[1];
sopToken.safeTransfer(account, plenty);
LibTransfer.sendToken(sopToken, plenty, LibTractor._user(), toMode);
s.a[account].sop[well].plenty = 0;

emit ClaimPlenty(account, address(sopToken), plenty);
Expand Down
8 changes: 4 additions & 4 deletions protocol/contracts/beanstalk/silo/SiloFacet/SiloFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,14 @@ contract SiloFacet is Invariable, TokenSilo {
/**
* @notice Claim rewards from a Flood (Was Season of Plenty)
*/
function claimPlenty(address well) external payable {
_claimPlenty(LibTractor._user(), well);
function claimPlenty(address well, LibTransfer.To toMode) external payable {
_claimPlenty(LibTractor._user(), well, toMode);
}

function claimAllPlenty() external payable {
function claimAllPlenty(LibTransfer.To toMode) external payable {
address[] memory tokens = LibWhitelistedTokens.getWhitelistedWellLpTokens();
for (uint i; i < tokens.length; i++) {
_claimPlenty(LibTractor._user(), tokens[i]);
_claimPlenty(LibTractor._user(), tokens[i], toMode);
}
}
}
15 changes: 14 additions & 1 deletion protocol/contracts/interfaces/IMockFBeanstalk.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ pragma solidity ^0.8.20;
pragma abicoder v2;

interface IMockFBeanstalk {
// Is this the proper location for enums?
enum From {
EXTERNAL,
INTERNAL,
EXTERNAL_INTERNAL,
INTERNAL_TOLERANT
}
enum To {
EXTERNAL,
INTERNAL
}

struct AccountSeasonOfPlenty {
uint32 lastRain;
uint32 lastSop;
Expand Down Expand Up @@ -519,7 +531,8 @@ interface IMockFBeanstalk {

function claimOwnership() external;

function claimPlenty(address well) external payable;
function claimPlenty(address well, To toMode) external payable;
function claimAllPlenty(To toMode) external payable;

function convert(
bytes memory convertData,
Expand Down
7 changes: 4 additions & 3 deletions protocol/test/foundry/sun/Flood.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity >=0.6.0 <0.9.0;
pragma abicoder v2;

import {TestHelper, C} from "test/foundry/utils/TestHelper.sol";
import {TestHelper, C, LibTransfer} from "test/foundry/utils/TestHelper.sol";
import {IWell, IERC20, Call} from "contracts/interfaces/basin/IWell.sol";
import {MockPump} from "contracts/mocks/well/MockPump.sol";
import {MockSeasonFacet, Weather} from "contracts/mocks/mockFacets/MockSeasonFacet.sol";
Expand All @@ -11,6 +11,7 @@ import {MockFieldFacet} from "contracts/mocks/mockFacets/MockFieldFacet.sol";
import {Storage} from "contracts/libraries/LibAppStorage.sol";
import {SeasonGettersFacet} from "contracts/beanstalk/sun/SeasonFacet/SeasonGettersFacet.sol";
import {SiloGettersFacet} from "contracts/beanstalk/silo/SiloFacet/SiloGettersFacet.sol";
import {IMockFBeanstalk} from "contracts/interfaces/IMockFBeanstalk.sol";
import {console} from "forge-std/console.sol";

/**
Expand Down Expand Up @@ -187,7 +188,7 @@ contract FloodTest is TestHelper {
// claims user plenty
bs.mow(users[2], C.BEAN);
vm.prank(users[2]);
bs.claimPlenty(sopWell);
bs.claimPlenty(sopWell, IMockFBeanstalk.To.EXTERNAL);
assertEq(bs.balanceOfPlenty(users[2], sopWell), 0);
assertEq(IERC20(C.WETH).balanceOf(users[2]), userCalcPlenty);
}
Expand Down Expand Up @@ -321,7 +322,7 @@ contract FloodTest is TestHelper {
// claims user plenty
bs.mow(users[2], sopWell);
vm.prank(users[2]);
bs.claimPlenty(sopWell);
bs.claimPlenty(sopWell, IMockFBeanstalk.To.EXTERNAL);
assertEq(bs.balanceOfPlenty(users[2], sopWell), 0);
assertEq(IERC20(C.WETH).balanceOf(users[2]), 25595575914848452999);
}
Expand Down

0 comments on commit f4b3608

Please sign in to comment.