Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use stalk per BDV for vAPYs #719

Merged
merged 14 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 42 additions & 22 deletions projects/subgraph-beanstalk/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ type Silo @entity {
plantableStalk: BigInt!
"Current seeds balance"
seeds: BigInt!
"Current average grown stalk per bdv per season"
grownStalkPerBdvPerSeason: BigInt!
"Current roots balance"
roots: BigInt!
"Cumulative total for bean mints sent to the silo"
Expand Down Expand Up @@ -141,6 +143,8 @@ type SiloHourlySnapshot @entity {
plantableStalk: BigInt!
"Point in time current seeds balance"
seeds: BigInt!
"Point in time average grown stalk per bdv per season"
grownStalkPerBdvPerSeason: BigInt!
"Point in time current roots balance"
roots: BigInt!
"Point in time cumulative total for bean mints sent to the silo"
Expand Down Expand Up @@ -182,6 +186,8 @@ type SiloDailySnapshot @entity {
plantableStalk: BigInt!
"Point in time current seeds balance"
seeds: BigInt!
"Point in time average grown stalk per bdv per season"
grownStalkPerBdvPerSeason: BigInt!
"Point in time current roots balance"
roots: BigInt!
"Point in time cumulative total for bean mints sent to the silo"
Expand Down Expand Up @@ -298,32 +304,46 @@ type SiloYield @entity {
u: Int!
"Bean EMA for season"
beansPerSeasonEMA: BigDecimal!
"Bean APY for 0 seeds per BDV"
zeroSeedBeanAPY: BigDecimal!
"Bean APY for 2 seeds per BDV"
twoSeedBeanAPY: BigDecimal!
"Stalk APY for 2 seeds per BDV"
twoSeedStalkAPY: BigDecimal!
"Bean APY for 3 seeds per BDV"
threeSeedBeanAPY: BigDecimal!
"Stalk APY for 3 seeds per BDV"
threeSeedStalkAPY: BigDecimal!
"Bean APY for 3.25 seeds per BDV"
threePointTwoFiveSeedBeanAPY: BigDecimal!
"Stalk APY for 3.25 seeds per BDV"
threePointTwoFiveSeedStalkAPY: BigDecimal!
"Bean APY for 4 seeds per BDV"
fourSeedBeanAPY: BigDecimal!
"Stalk APY for 4 seeds per BDV"
fourSeedStalkAPY: BigDecimal!
"Bean APY for 4.5 seeds per BDV"
fourPointFiveSeedBeanAPY: BigDecimal!
"Stalk APY for 4.5 seeds per BDV"
fourPointFiveSeedStalkAPY: BigDecimal!
"Current whitelisted silo tokens"
whitelistedTokens: [String!]!
"Current Bean (0) and Stalk (1) APY for each token."
tokenAPYS: [TokenYield!]! @derivedFrom(field: "siloYield")
"Unix timestamp of update"
createdAt: BigInt!
}

type TokenYield @entity {
"Token address - season"
id: Bytes!
"Token being calculated"
token: Bytes!
"Season for APY calculation"
season: Int!
"Related silo yield entity"
siloYield: SiloYield!
"Bean APY for season"
beanAPY: BigDecimal!
"Stalk APY for season"
stalkAPY: BigDecimal!
"Unix timestamp of update"
createdAt: BigInt!
}

type WhitelistTokenSetting @entity {
" Contract address for the whitelisted token "
id: Bytes!
" Encoded BDV selector "
selector: Bytes!
"Represents how much Stalk one BDV of the underlying deposited token grows each season."
stalkEarnedPerSeason: BigInt!
"The stalk per BDV that the silo grants in exchange for depositing this token."
stalkIssuedPerBdv: BigInt!
"The last season in which the stalkEarnedPerSeason for this token was updated."
milestoneSeason: Int!
"Last timestamp entity was updated"
updatedAt: BigInt!
}

type Field @entity {
" Contract address for this field or farmer "
id: ID!
Expand Down
15 changes: 15 additions & 0 deletions projects/subgraph-beanstalk/src/DiamondHandler.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
import { Address, BigDecimal, BigInt } from "@graphprotocol/graph-ts";
import { ZERO_BI } from "../../subgraph-core/utils/Decimals";
import { DiamondCut } from "../generated/Diamond/Beanstalk";
import { loadBeanstalk } from "./utils/Beanstalk";
import { TOKEN_YIELD_14_000 } from "./utils/HistoricYield";
import { loadTokenYield } from "./utils/SiloEntities";

export function handleDiamondCut(event: DiamondCut): void {
let beanstalk = loadBeanstalk(event.address);

// Load the historical vAPY figures in bulk at start
if (beanstalk.lastUpgrade == ZERO_BI) {
for (let i = 0; i < TOKEN_YIELD_14_000.length; i++) {
let tokenYield = loadTokenYield(Address.fromString(TOKEN_YIELD_14_000[i][0]), <i32>parseInt(TOKEN_YIELD_14_000[i][1]));
tokenYield.beanAPY = BigDecimal.fromString(TOKEN_YIELD_14_000[i][2]);
tokenYield.stalkAPY = BigDecimal.fromString(TOKEN_YIELD_14_000[i][3]);
tokenYield.createdAt = BigInt.fromString(TOKEN_YIELD_14_000[i][4]);
tokenYield.save();
}
}

beanstalk.lastUpgrade = event.block.timestamp;
beanstalk.save();
}
2 changes: 1 addition & 1 deletion projects/subgraph-beanstalk/src/FarmHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Address, BigInt } from "@graphprotocol/graph-ts";
import { InternalBalanceChanged } from "../generated/Farm/Beanstalk";
import { loadBeanstalk } from "./utils/Beanstalk";
import { BEANSTALK } from "../../subgraph-core/utils/Constants";
import { loadSiloAsset, loadSiloAssetDailySnapshot, loadSiloAssetHourlySnapshot } from "./utils/SiloAsset";
import { loadSiloAsset, loadSiloAssetDailySnapshot, loadSiloAssetHourlySnapshot } from "./utils/SiloEntities";
import { loadFarmer } from "./utils/Farmer";

export function handleInternalBalanceChanged(event: InternalBalanceChanged): void {
Expand Down
9 changes: 7 additions & 2 deletions projects/subgraph-beanstalk/src/SeasonHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ import { loadField, loadFieldDaily, loadFieldHourly } from "./utils/Field";
import { expirePodListing, loadPodListing } from "./utils/PodListing";
import { loadPodMarketplace, loadPodMarketplaceDailySnapshot, loadPodMarketplaceHourlySnapshot } from "./utils/PodMarketplace";
import { loadSeason } from "./utils/Season";
import { loadSilo, loadSiloDailySnapshot, loadSiloHourlySnapshot } from "./utils/Silo";
import { addDepositToSiloAsset, updateStalkWithCalls } from "./SiloHandler";
import { updateBeanEMA } from "./YieldHandler";
import { loadSiloAssetDailySnapshot, loadSiloAssetHourlySnapshot } from "./utils/SiloAsset";
import {
loadSilo,
loadSiloDailySnapshot,
loadSiloHourlySnapshot,
loadSiloAssetDailySnapshot,
loadSiloAssetHourlySnapshot
} from "./utils/SiloEntities";
import { BeanstalkPrice } from "../generated/Season-Replanted/BeanstalkPrice";

export function handleSunrise(event: Sunrise): void {
Expand Down
Loading
Loading