diff --git a/protocol/contracts/beanstalk/silo/EnrootFacet.sol b/protocol/contracts/beanstalk/silo/EnrootFacet.sol index 6ada40f374..cd33072f7f 100644 --- a/protocol/contracts/beanstalk/silo/EnrootFacet.sol +++ b/protocol/contracts/beanstalk/silo/EnrootFacet.sol @@ -220,7 +220,7 @@ contract EnrootFacet is ReentrancyGuard { amount, bdv, LibTokenSilo.Transfer.noEmitTransferSingle, - LibGerminate._getGerminationState(stem, enrootData.germStem.germinatingStem) + LibGerminate._getGerminationState(stem, enrootData.germStem) ); return bdv.mul(enrootData.stalkPerBdv).add( diff --git a/protocol/contracts/beanstalk/silo/SiloFacet/TokenSilo.sol b/protocol/contracts/beanstalk/silo/SiloFacet/TokenSilo.sol index 41a110c37d..dbcb9c4317 100644 --- a/protocol/contracts/beanstalk/silo/SiloFacet/TokenSilo.sol +++ b/protocol/contracts/beanstalk/silo/SiloFacet/TokenSilo.sol @@ -361,7 +361,7 @@ contract TokenSilo is Silo { for (uint256 i; i < stems.length; ++i) { LibGerminate.Germinate germ = LibGerminate._getGerminationState( stems[i], - germStem.germinatingStem + germStem ); uint256 crateBdv = LibTokenSilo.removeDepositFromAccount( sender, diff --git a/protocol/contracts/libraries/Silo/LibGerminate.sol b/protocol/contracts/libraries/Silo/LibGerminate.sol index 482df7950c..97e52187f5 100644 --- a/protocol/contracts/libraries/Silo/LibGerminate.sol +++ b/protocol/contracts/libraries/Silo/LibGerminate.sol @@ -171,7 +171,7 @@ library LibGerminate { function getGerminationState(address token, int96 stem) internal view returns (Germinate, int96) { // if the stem of the token is the stemTip, then it should be germinating. GermStem memory germStem = getGerminatingStem(token); - return (_getGerminationState(stem, germStem.germinatingStem), germStem.stemTip); + return (_getGerminationState(stem, germStem), germStem.stemTip); } /** @@ -230,19 +230,19 @@ library LibGerminate { */ function _getGerminationState( int96 stem, - int96 germinationStem + GermStem memory germData ) internal view returns (Germinate) { - if (stem < germinationStem) { + if (stem < germData.germinatingStem) { // if the stem of the deposit is lower than the germination stem, // then the deposit is not germinating. return Germinate.NOT_GERMINATING; } else { // return the gemination state based on whether the stem - // is equal to the germination stem or stemTip. - // if the stem is not equal to the germination stem, then it - // must equal the stemTip here. - if (stem == germinationStem) { + // is equal to the stemTip. + // if the stem is equal to the stem tip, it is in the inital stages of germination. + // if the stem is not equal to the stemTip, its in the germination process. + if (stem == germData.stemTip) { return isCurrentSeasonOdd() ? Germinate.ODD : Germinate.EVEN; } else { return isCurrentSeasonOdd() ? Germinate.EVEN : Germinate.ODD; diff --git a/protocol/contracts/libraries/Silo/LibSilo.sol b/protocol/contracts/libraries/Silo/LibSilo.sol index f861143af5..14801a9cef 100644 --- a/protocol/contracts/libraries/Silo/LibSilo.sol +++ b/protocol/contracts/libraries/Silo/LibSilo.sol @@ -159,7 +159,6 @@ library LibSilo { s.s.roots = s.s.roots.add(roots); s.a[account].roots = s.a[account].roots.add(roots); } else { - Account.FarmerGerminating storage farmerGerm; Storage.TotalGerminating storage totalGerm; @@ -170,14 +169,13 @@ library LibSilo { farmerGerm = s.a[account].evenGerminating; totalGerm = s.evenGerminating; } - + farmerGerm.stalk = farmerGerm.stalk.add(stalk.toUint112()); farmerGerm.roots = farmerGerm.roots.add(roots.toUint112()); totalGerm.stalk = totalGerm.stalk.add(stalk.toUint128()); totalGerm.roots = totalGerm.roots.add(roots.toUint128()); } - emit StalkBalanceChanged(account, int256(stalk), int256(roots)); } @@ -221,7 +219,7 @@ library LibSilo { farmerGerm = s.a[account].evenGerminating; totalGerm = s.evenGerminating; } - + farmerGerm.stalk = farmerGerm.stalk.sub(stalk.toUint112()); farmerGerm.roots = farmerGerm.roots.sub(roots.toUint112()); @@ -272,9 +270,9 @@ library LibSilo { * @dev assumes stalk is germinating. */ function transferGerminatingStalk( - address sender, - address recipient, - uint256 stalk, + address sender, + address recipient, + uint256 stalk, LibGerminate.Germinate GermState ) internal { AppStorage storage s = LibAppStorage.diamondStorage(); @@ -322,9 +320,7 @@ library LibSilo { } if (ar.oddStalkRemoved > 0) { - ar.oddStalkRemoved = ar.oddStalkRemoved.add( - ar.oddBdvRemoved.mul(stalkPerBDV) - ); + ar.oddStalkRemoved = ar.oddStalkRemoved.add(ar.oddBdvRemoved.mul(stalkPerBDV)); transferGerminatingStalk( sender, recipient, @@ -334,9 +330,7 @@ library LibSilo { } if (ar.evenStalkRemoved > 0) { - ar.evenStalkRemoved = ar.evenStalkRemoved.add( - ar.evenBdvRemoved.mul(stalkPerBDV) - ); + ar.evenStalkRemoved = ar.evenStalkRemoved.add(ar.evenBdvRemoved.mul(stalkPerBDV)); transferGerminatingStalk( sender, recipient, @@ -408,12 +402,8 @@ library LibSilo { if (_lastStem == _stemTip) { return; } - - mintStalk( - account, - _balanceOfGrownStalk(_lastStem, _stemTip, _bdv), - germ - ); + + mintStalk(account, _balanceOfGrownStalk(_lastStem, _stemTip, _bdv), germ); } // If this `account` has no BDV, skip to save gas. Still need to update lastStem @@ -583,7 +573,10 @@ library LibSilo { uint256[] memory removedDepositIDs = new uint256[](stems.length); LibGerminate.GermStem memory germStem = LibGerminate.getGerminatingStem(token); for (uint256 i; i < stems.length; ++i) { - LibGerminate.Germinate germState = LibGerminate._getGerminationState(stems[i], germStem.germinatingStem); + LibGerminate.Germinate germState = LibGerminate._getGerminationState( + stems[i], + germStem + ); uint256 crateBdv = LibTokenSilo.removeDepositFromAccount( account, token, @@ -598,8 +591,8 @@ library LibSilo { // if the deposit is germinating, decrement germinating values, // otherwise increment deposited values. // token is added to `ar.tokensRemoved` regardless of germination state. - - if (germState == LibGerminate.Germinate.NOT_GERMINATING) { + + if (germState == LibGerminate.Germinate.NOT_GERMINATING) { ar.bdvRemoved = ar.bdvRemoved.add(crateBdv); ar.stalkRemoved = ar.stalkRemoved.add(crateStalk); ar.tokensRemoved = ar.tokensRemoved.add(amounts[i]); @@ -632,7 +625,6 @@ library LibSilo { ); } - // "removing" deposits is equivalent to "burning" a batch of ERC1155 tokens. emit TransferBatch(msg.sender, account, address(0), removedDepositIDs, amounts); emit RemoveDeposits(account, token, stems, amounts, ar.tokensRemoved, bdvsRemoved); diff --git a/protocol/contracts/libraries/Silo/LibTokenSilo.sol b/protocol/contracts/libraries/Silo/LibTokenSilo.sol index e766e18d73..ef6508009b 100644 --- a/protocol/contracts/libraries/Silo/LibTokenSilo.sol +++ b/protocol/contracts/libraries/Silo/LibTokenSilo.sol @@ -581,7 +581,7 @@ library LibTokenSilo { LibGerminate.GermStem memory germStem = LibGerminate.getGerminatingStem(token); stem = germStem.stemTip.sub(toInt96(grownStalk.div(bdv))); _grownStalk = uint256(germStem.stemTip.sub(stem).mul(toInt96(bdv))); - germ = LibGerminate._getGerminationState(stem, germStem.germinatingStem); + germ = LibGerminate._getGerminationState(stem, germStem); } /**