From ed093f7fe070c91ae4026e892b2dbc5b24252299 Mon Sep 17 00:00:00 2001 From: Soil King <157099073+soilking@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:48:05 -0700 Subject: [PATCH] remove silo seeds --- .../subgraph-beanstalk/manifests/ethereum.yaml | 2 -- .../subgraph-beanstalk/manifests/no-apy.yaml | 2 -- projects/subgraph-beanstalk/schema.graphql | 18 ++++++++---------- .../subgraph-beanstalk/src/entities/Silo.ts | 1 - .../src/entities/snapshots/Silo.ts | 18 ++++++++---------- .../src/handlers/legacy/LegacySiloHandler.ts | 13 +------------ projects/subgraph-beanstalk/src/utils/Yield.ts | 4 ++-- .../src/utils/legacy/LegacySilo.ts | 17 ----------------- 8 files changed, 19 insertions(+), 56 deletions(-) diff --git a/projects/subgraph-beanstalk/manifests/ethereum.yaml b/projects/subgraph-beanstalk/manifests/ethereum.yaml index e5fb9a5d5..78ea4f233 100644 --- a/projects/subgraph-beanstalk/manifests/ethereum.yaml +++ b/projects/subgraph-beanstalk/manifests/ethereum.yaml @@ -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) diff --git a/projects/subgraph-beanstalk/manifests/no-apy.yaml b/projects/subgraph-beanstalk/manifests/no-apy.yaml index f37044ff3..1856526dc 100644 --- a/projects/subgraph-beanstalk/manifests/no-apy.yaml +++ b/projects/subgraph-beanstalk/manifests/no-apy.yaml @@ -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) diff --git a/projects/subgraph-beanstalk/schema.graphql b/projects/subgraph-beanstalk/schema.graphql index 77f6dd777..f9b763c02 100644 --- a/projects/subgraph-beanstalk/schema.graphql +++ b/projects/subgraph-beanstalk/schema.graphql @@ -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!]! } @@ -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! @@ -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" @@ -156,7 +156,7 @@ type SiloHourlySnapshot @entity { deltaDepositedBDV: BigInt! deltaStalk: BigInt! deltaPlantableStalk: BigInt! - deltaSeeds: BigInt! + deltaGrownStalkPerSeason: BigInt! deltaRoots: BigInt! deltaGerminatingStalk: BigInt! deltaBeanMints: BigInt! @@ -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" @@ -203,7 +201,7 @@ type SiloDailySnapshot @entity { deltaDepositedBDV: BigInt! deltaStalk: BigInt! deltaPlantableStalk: BigInt! - deltaSeeds: BigInt! + deltaGrownStalkPerSeason: BigInt! deltaRoots: BigInt! deltaGerminatingStalk: BigInt! deltaBeanMints: BigInt! diff --git a/projects/subgraph-beanstalk/src/entities/Silo.ts b/projects/subgraph-beanstalk/src/entities/Silo.ts index 4d64d0b45..af06a2194 100644 --- a/projects/subgraph-beanstalk/src/entities/Silo.ts +++ b/projects/subgraph-beanstalk/src/entities/Silo.ts @@ -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; diff --git a/projects/subgraph-beanstalk/src/entities/snapshots/Silo.ts b/projects/subgraph-beanstalk/src/entities/snapshots/Silo.ts index 5aa4f306c..42a38cc5d 100644 --- a/projects/subgraph-beanstalk/src/entities/snapshots/Silo.ts +++ b/projects/subgraph-beanstalk/src/entities/snapshots/Silo.ts @@ -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; @@ -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 @@ -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 @@ -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 @@ -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; @@ -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 @@ -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 @@ -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 @@ -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; @@ -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; diff --git a/projects/subgraph-beanstalk/src/handlers/legacy/LegacySiloHandler.ts b/projects/subgraph-beanstalk/src/handlers/legacy/LegacySiloHandler.ts index 22c86b562..fb865165e 100644 --- a/projects/subgraph-beanstalk/src/handlers/legacy/LegacySiloHandler.ts +++ b/projects/subgraph-beanstalk/src/handlers/legacy/LegacySiloHandler.ts @@ -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"; @@ -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 { diff --git a/projects/subgraph-beanstalk/src/utils/Yield.ts b/projects/subgraph-beanstalk/src/utils/Yield.ts index 321680816..a8b8fd672 100644 --- a/projects/subgraph-beanstalk/src/utils/Yield.ts +++ b/projects/subgraph-beanstalk/src/utils/Yield.ts @@ -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, @@ -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); } diff --git a/projects/subgraph-beanstalk/src/utils/legacy/LegacySilo.ts b/projects/subgraph-beanstalk/src/utils/legacy/LegacySilo.ts index 432c6840d..5f560b8dc 100644 --- a/projects/subgraph-beanstalk/src/utils/legacy/LegacySilo.ts +++ b/projects/subgraph-beanstalk/src/utils/legacy/LegacySilo.ts @@ -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 {