Skip to content

Commit

Permalink
remove silo seeds
Browse files Browse the repository at this point in the history
  • Loading branch information
soilking committed Sep 24, 2024
1 parent 29a3d57 commit ed093f7
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 56 deletions.
2 changes: 0 additions & 2 deletions projects/subgraph-beanstalk/manifests/ethereum.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,6 @@ dataSources:
- name: SeedGauge
file: ../../subgraph-core/abis/Beanstalk/Beanstalk-BIP45.json
eventHandlers:
- event: SeedsBalanceChanged(indexed address,int256)
handler: handleSeedsBalanceChanged
- event: RemoveWithdrawal(indexed address,indexed address,uint32,uint256)
handler: handleRemoveWithdrawal
- event: RemoveWithdrawals(indexed address,indexed address,uint32[],uint256)
Expand Down
2 changes: 0 additions & 2 deletions projects/subgraph-beanstalk/manifests/no-apy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ dataSources:
- name: SeedGauge
file: ../../subgraph-core/abis/Beanstalk/Beanstalk-BIP45.json
eventHandlers:
- event: SeedsBalanceChanged(indexed address,int256)
handler: handleSeedsBalanceChanged
- event: WhitelistToken(indexed address,bytes4,uint32,uint256,bytes4,bytes4,uint128,uint64)
handler: handleWhitelistToken_v4
- event: RemoveWithdrawal(indexed address,indexed address,uint32,uint256)
Expand Down
18 changes: 8 additions & 10 deletions projects/subgraph-beanstalk/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type Beanstalk @entity {
lastSeason: Int!
"Array of the addresses for all active farmers in the silo"
activeFarmers: [Bytes!]!
"Array of the addresses for all farmers that had silo transfers and need stalk/seeds/roots updated"
"Array of the addresses for all farmers that had silo transfers and need stalk/roots updated"
farmersToUpdate: [Bytes!]!
}

Expand Down Expand Up @@ -101,9 +101,11 @@ type Silo @entity {
stalk: BigInt!
"Current plantable stalk for bean seigniorage not yet claimed"
plantableStalk: BigInt!
"Current seeds balance"
seeds: BigInt!
"Current grown stalk per season"
"""
Current grown stalk per season.
NOTE: This value is currently not accurate for pre-gauge queries (BIP-45).
A correct implementation would recalculate this value when a whitelisted token's seed amount is changed.
"""
grownStalkPerSeason: BigInt!
"Current roots balance"
roots: BigInt!
Expand Down Expand Up @@ -138,8 +140,6 @@ type SiloHourlySnapshot @entity {
stalk: BigInt!
"Point in time current plantable stalk for bean seigniorage not yet claimed"
plantableStalk: BigInt!
"Point in time current seeds balance"
seeds: BigInt!
"Point in time grown stalk per season"
grownStalkPerSeason: BigInt!
"Point in time current roots balance"
Expand All @@ -156,7 +156,7 @@ type SiloHourlySnapshot @entity {
deltaDepositedBDV: BigInt!
deltaStalk: BigInt!
deltaPlantableStalk: BigInt!
deltaSeeds: BigInt!
deltaGrownStalkPerSeason: BigInt!
deltaRoots: BigInt!
deltaGerminatingStalk: BigInt!
deltaBeanMints: BigInt!
Expand Down Expand Up @@ -185,8 +185,6 @@ type SiloDailySnapshot @entity {
stalk: BigInt!
"Point in time current plantable stalk for bean seigniorage not yet claimed"
plantableStalk: BigInt!
"Point in time current seeds balance"
seeds: BigInt!
"Point in time grown stalk per season"
grownStalkPerSeason: BigInt!
"Point in time current roots balance"
Expand All @@ -203,7 +201,7 @@ type SiloDailySnapshot @entity {
deltaDepositedBDV: BigInt!
deltaStalk: BigInt!
deltaPlantableStalk: BigInt!
deltaSeeds: BigInt!
deltaGrownStalkPerSeason: BigInt!
deltaRoots: BigInt!
deltaGerminatingStalk: BigInt!
deltaBeanMints: BigInt!
Expand Down
1 change: 0 additions & 1 deletion projects/subgraph-beanstalk/src/entities/Silo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export function loadSilo(account: Address): Silo {
silo.depositedBDV = ZERO_BI;
silo.stalk = ZERO_BI;
silo.plantableStalk = ZERO_BI;
silo.seeds = ZERO_BI;
silo.grownStalkPerSeason = ZERO_BI;
silo.roots = ZERO_BI;
silo.germinatingStalk = ZERO_BI;
Expand Down
18 changes: 8 additions & 10 deletions projects/subgraph-beanstalk/src/entities/snapshots/Silo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export function takeSiloSnapshots(silo: Silo, block: ethereum.Block): void {
hourly.depositedBDV = silo.depositedBDV;
hourly.stalk = silo.stalk;
hourly.plantableStalk = silo.plantableStalk;
hourly.seeds = silo.seeds;
hourly.grownStalkPerSeason = silo.grownStalkPerSeason;
hourly.roots = silo.roots;
hourly.germinatingStalk = silo.germinatingStalk;
Expand All @@ -43,7 +42,7 @@ export function takeSiloSnapshots(silo: Silo, block: ethereum.Block): void {
hourly.deltaDepositedBDV = hourly.depositedBDV.minus(baseHourly.depositedBDV);
hourly.deltaStalk = hourly.stalk.minus(baseHourly.stalk);
hourly.deltaPlantableStalk = hourly.plantableStalk.minus(baseHourly.plantableStalk);
hourly.deltaSeeds = hourly.seeds.minus(baseHourly.seeds);
hourly.deltaGrownStalkPerSeason = hourly.grownStalkPerSeason.minus(baseHourly.grownStalkPerSeason);
hourly.deltaRoots = hourly.roots.minus(baseHourly.roots);
hourly.deltaGerminatingStalk = hourly.germinatingStalk.minus(baseHourly.germinatingStalk);
// NOTE: missing beanToMaxLpGpPerBdvRatio
Expand All @@ -54,7 +53,7 @@ export function takeSiloSnapshots(silo: Silo, block: ethereum.Block): void {
hourly.deltaDepositedBDV = hourly.deltaDepositedBDV.plus(baseHourly.deltaDepositedBDV);
hourly.deltaStalk = hourly.deltaStalk.plus(baseHourly.deltaStalk);
hourly.deltaPlantableStalk = hourly.deltaPlantableStalk.plus(baseHourly.deltaPlantableStalk);
hourly.deltaSeeds = hourly.deltaSeeds.plus(baseHourly.deltaSeeds);
hourly.deltaGrownStalkPerSeason = hourly.deltaGrownStalkPerSeason.plus(baseHourly.deltaGrownStalkPerSeason);
hourly.deltaRoots = hourly.deltaRoots.plus(baseHourly.deltaRoots);
hourly.deltaGerminatingStalk = hourly.deltaGerminatingStalk.plus(baseHourly.deltaGerminatingStalk);
// NOTE: missing beanToMaxLpGpPerBdvRatio
Expand All @@ -67,7 +66,7 @@ export function takeSiloSnapshots(silo: Silo, block: ethereum.Block): void {
hourly.deltaDepositedBDV = hourly.depositedBDV;
hourly.deltaStalk = hourly.stalk;
hourly.deltaPlantableStalk = hourly.plantableStalk;
hourly.deltaSeeds = hourly.seeds;
hourly.deltaGrownStalkPerSeason = hourly.grownStalkPerSeason;
hourly.deltaRoots = hourly.roots;
hourly.deltaGerminatingStalk = hourly.germinatingStalk;
// NOTE: missing beanToMaxLpGpPerBdvRatio
Expand All @@ -86,7 +85,6 @@ export function takeSiloSnapshots(silo: Silo, block: ethereum.Block): void {
daily.depositedBDV = silo.depositedBDV;
daily.stalk = silo.stalk;
daily.plantableStalk = silo.plantableStalk;
daily.seeds = silo.seeds;
daily.grownStalkPerSeason = silo.grownStalkPerSeason;
daily.roots = silo.roots;
daily.germinatingStalk = silo.germinatingStalk;
Expand All @@ -97,7 +95,7 @@ export function takeSiloSnapshots(silo: Silo, block: ethereum.Block): void {
daily.deltaDepositedBDV = daily.depositedBDV.minus(baseDaily.depositedBDV);
daily.deltaStalk = daily.stalk.minus(baseDaily.stalk);
daily.deltaPlantableStalk = daily.plantableStalk.minus(baseDaily.plantableStalk);
daily.deltaSeeds = daily.seeds.minus(baseDaily.seeds);
daily.deltaGrownStalkPerSeason = daily.grownStalkPerSeason.minus(baseDaily.grownStalkPerSeason);
daily.deltaRoots = daily.roots.minus(baseDaily.roots);
daily.deltaGerminatingStalk = daily.germinatingStalk.minus(baseDaily.germinatingStalk);
// NOTE: missing beanToMaxLpGpPerBdvRatio
Expand All @@ -108,7 +106,7 @@ export function takeSiloSnapshots(silo: Silo, block: ethereum.Block): void {
daily.deltaDepositedBDV = daily.deltaDepositedBDV.plus(baseDaily.deltaDepositedBDV);
daily.deltaStalk = daily.deltaStalk.plus(baseDaily.deltaStalk);
daily.deltaPlantableStalk = daily.deltaPlantableStalk.plus(baseDaily.deltaPlantableStalk);
daily.deltaSeeds = daily.deltaSeeds.plus(baseDaily.deltaSeeds);
daily.deltaGrownStalkPerSeason = daily.deltaGrownStalkPerSeason.plus(baseDaily.deltaGrownStalkPerSeason);
daily.deltaRoots = daily.deltaRoots.plus(baseDaily.deltaRoots);
daily.deltaGerminatingStalk = daily.deltaGerminatingStalk.plus(baseDaily.deltaGerminatingStalk);
// NOTE: missing beanToMaxLpGpPerBdvRatio
Expand All @@ -119,7 +117,7 @@ export function takeSiloSnapshots(silo: Silo, block: ethereum.Block): void {
daily.deltaDepositedBDV = daily.depositedBDV;
daily.deltaStalk = daily.stalk;
daily.deltaPlantableStalk = daily.plantableStalk;
daily.deltaSeeds = daily.seeds;
daily.deltaGrownStalkPerSeason = daily.grownStalkPerSeason;
daily.deltaRoots = daily.roots;
daily.deltaGerminatingStalk = daily.germinatingStalk;
// NOTE: missing beanToMaxLpGpPerBdvRatio
Expand All @@ -143,7 +141,7 @@ export function clearSiloDeltas(silo: Silo, block: ethereum.Block): void {
hourly.deltaDepositedBDV = ZERO_BI;
hourly.deltaStalk = ZERO_BI;
hourly.deltaPlantableStalk = ZERO_BI;
hourly.deltaSeeds = ZERO_BI;
hourly.deltaGrownStalkPerSeason = ZERO_BI;
hourly.deltaRoots = ZERO_BI;
hourly.deltaGerminatingStalk = ZERO_BI;
hourly.deltaBeanMints = ZERO_BI;
Expand All @@ -154,7 +152,7 @@ export function clearSiloDeltas(silo: Silo, block: ethereum.Block): void {
daily.deltaDepositedBDV = ZERO_BI;
daily.deltaStalk = ZERO_BI;
daily.deltaPlantableStalk = ZERO_BI;
daily.deltaSeeds = ZERO_BI;
daily.deltaGrownStalkPerSeason = ZERO_BI;
daily.deltaRoots = ZERO_BI;
daily.deltaGerminatingStalk = ZERO_BI;
daily.deltaBeanMints = ZERO_BI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { addDeposits, addWithdrawToSiloAsset, removeDeposits } from "../../utils
import { takeWhitelistTokenSettingSnapshots } from "../../entities/snapshots/WhitelistTokenSetting";
import { WhitelistToken as WhitelistToken_v3 } from "../../../generated/Beanstalk-ABIs/SiloV3";
import { RemoveWithdrawal, RemoveWithdrawals, SeedsBalanceChanged, WhitelistToken } from "../../../generated/Beanstalk-ABIs/SeedGauge";
import { updateClaimedWithdraw, updateSeedsBalances } from "../../utils/legacy/LegacySilo";
import { updateClaimedWithdraw } from "../../utils/legacy/LegacySilo";
import { Bytes4_emptySelector } from "../../../../subgraph-core/utils/Bytes";
import { initLegacyUnripe } from "../../utils/legacy/LegacyWhitelist";

Expand Down Expand Up @@ -152,17 +152,6 @@ export function handleWhitelistToken_v4(event: WhitelistToken): void {
siloSettings.save();
}

// Replanted -> Reseed
// Legacy feature since silo v3, but the event was still present until the reseed //
export function handleSeedsBalanceChanged(event: SeedsBalanceChanged): void {
// Exclude BIP-24 emission of missed past events
if (event.transaction.hash.toHexString() == "0xa89638aeb0d6c4afb4f367ea7a806a4c8b3b2a6eeac773e8cc4eda10bfa804fc") {
return;
}

updateSeedsBalances(event.address, event.params.account, event.params.delta, event.block);
}

/// Withdrawal is a legacy feature from replant, but these events were still present until the reseed ///
// Replanted -> Reseed
export function handleRemoveWithdrawal(event: RemoveWithdrawal): void {
Expand Down
4 changes: 2 additions & 2 deletions projects/subgraph-beanstalk/src/utils/Yield.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Address, BigDecimal, BigInt, log } from "@graphprotocol/graph-ts";
import { toDecimal, ZERO_BD, ZERO_BI } from "../../../subgraph-core/utils/Decimals";
import { BI_10, toDecimal, ZERO_BD, ZERO_BI } from "../../../subgraph-core/utils/Decimals";
import {
loadSilo,
loadSiloAsset,
Expand Down Expand Up @@ -124,7 +124,7 @@ export function updateSiloVAPYs(protocol: Address, timestamp: BigInt, window: i3
toDecimal(whitelistSettings[i].stalkEarnedPerSeason),
toDecimal(beanGrownStalk),
silo.stalk,
silo.seeds
silo.grownStalkPerSeason
);
apys.push(tokenAPY);
}
Expand Down
17 changes: 0 additions & 17 deletions projects/subgraph-beanstalk/src/utils/legacy/LegacySilo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,11 @@ export function updateStalkWithCalls(protocol: Address, block: ethereum.Block):
block,
false
);
updateSeedsBalances(protocol, account, beanstalk_call.balanceOfSeeds(account).minus(silo.seeds), block, false);
}
beanstalk.farmersToUpdate = [];
beanstalk.save();
}

export function updateSeedsBalances(
protocol: Address,
account: Address,
seeds: BigInt,
block: ethereum.Block,
recurs: boolean = true
): void {
if (recurs && account != protocol) {
updateSeedsBalances(protocol, protocol, seeds, block);
}
let silo = loadSilo(account);
silo.seeds = silo.seeds.plus(seeds);
takeSiloSnapshots(silo, block);
silo.save();
}

const STEM_START_SEASON = 14210;

export function stemFromSeason(season: i32, token: Address): BigInt {
Expand Down

0 comments on commit ed093f7

Please sign in to comment.