Skip to content

Commit

Permalink
Fix for germinating starting on the prior season upon certain converts
Browse files Browse the repository at this point in the history
  • Loading branch information
soilking committed Aug 16, 2024
1 parent 7a98b22 commit 17ee34b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
10 changes: 5 additions & 5 deletions projects/subgraph-beanstalk/manifests/ethereum.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,8 @@ dataSources:
- event: InternalBalanceChanged(indexed address,indexed address,int256)
handler: handleInternalBalanceChanged
file: ../src/handlers/FarmHandler.ts
# features:
# - grafting
# graft:
# base: QmRJCKP5nLjUNtR2ZZ9F62iBGiKLdkGPX7GzBZLgVfnz3c
# block: 15289930
features:
- grafting
graft:
base: QmUqT47H7o3gcZ2mHRJf2J5hpitWDYxsMmacGeuvo1wKU7
block: 19927630
4 changes: 2 additions & 2 deletions projects/subgraph-beanstalk/src/entities/Germinating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ export function getFarmerGerminatingBugOffset(account: Address, event: ethereum.
return ZERO_BI;
}

function germinationSeasonCategory(season: i32): string {
export function germinationSeasonCategory(season: i32): string {
return season % 2 == 0 ? "EVEN" : "ODD";
}

function germinationEnumCategory(enumValue: i32): string {
export function germinationEnumCategory(enumValue: i32): string {
return enumValue == 0 ? "ODD" : "EVEN";
}
13 changes: 11 additions & 2 deletions projects/subgraph-beanstalk/src/handlers/GaugeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
} from "../../generated/Beanstalk-ABIs/SeedGauge";
import {
deleteGerminating,
germinationEnumCategory,
germinationSeasonCategory,
getFarmerGerminatingBugOffset,
loadGerminating,
loadOrCreateGerminating,
Expand Down Expand Up @@ -72,8 +74,15 @@ export function handleFarmerGerminatingStalkBalanceChanged(event: FarmerGerminat
const currentSeason = getCurrentSeason(event.address);

if (event.params.deltaGerminatingStalk > ZERO_BI) {
// Germinating stalk is being added in the current season
let farmerGerminating = loadOrCreateGerminating(event.params.account, currentSeason, true);
// Germinating stalk is added. It is possible to begin germination in the prior season rather than the
// current season when converting. See ConvertFacet._depositTokensForConvert for more information.
// If the event's germinationState doesnt match with the current season, use the prior season.
const germinatingSeason =
germinationSeasonCategory(currentSeason) === germinationEnumCategory(event.params.germinationState)
? currentSeason
: currentSeason - 1;

let farmerGerminating = loadOrCreateGerminating(event.params.account, germinatingSeason, true);
farmerGerminating.stalk = farmerGerminating.stalk.plus(event.params.deltaGerminatingStalk);
farmerGerminating.save();
} else {
Expand Down

0 comments on commit 17ee34b

Please sign in to comment.