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

subgraph-beanstalk2.4.0 + add standardized Version entity to all subgraphs #1025

Merged
merged 63 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
96f06f8
remove unnecessary entities
soilking Aug 6, 2024
e5938b7
consolidate utils
soilking Aug 6, 2024
0a0ad01
refactor add/remove deposit
soilking Aug 7, 2024
49a0003
generalized silo snapshot
soilking Aug 7, 2024
8aa55b1
refactor snapshot usages
soilking Aug 7, 2024
a9eaa79
test fixes
soilking Aug 7, 2024
c460e28
recursive seed update
soilking Aug 7, 2024
5dae947
recursive stalk update
soilking Aug 7, 2024
743b143
recursive deposit update
soilking Aug 7, 2024
3bd5024
legacy stem conversion
soilking Aug 7, 2024
04a3c46
silo deposit tests
soilking Aug 8, 2024
330dc48
hourly snapshot tests
soilking Aug 8, 2024
57a4787
generalized silo asset snapshot
soilking Aug 8, 2024
52d5d8a
silo asset snapshot refactor
soilking Aug 8, 2024
35223cc
refactor other snapshots
soilking Aug 8, 2024
41ce4b1
fix stalk mismatch from plantable/germinating
soilking Aug 9, 2024
df29c40
bump version
soilking Aug 9, 2024
1ce10ca
runtime fixes
soilking Aug 9, 2024
16aa8b4
remove unnecessary event
soilking Aug 9, 2024
ff9dd9c
major file restructure
soilking Aug 11, 2024
90ddc8e
rewrite manifest
soilking Aug 12, 2024
1d0e9fe
dont calculate cached yield
soilking Aug 12, 2024
fbacbec
dynamically set protocol assets
soilking Aug 12, 2024
f44a50e
fix for FarmerGerminatingStalkBalanceChanged when germinating didnt c…
soilking Aug 12, 2024
4c0a13b
fix comparison
soilking Aug 12, 2024
8478325
adjust params
soilking Aug 13, 2024
2c0dcd4
increment spec version
soilking Aug 13, 2024
a1ceff6
schema for unripe
soilking Aug 13, 2024
1ae2ce6
handle replanted sunrise
soilking Aug 13, 2024
91405d2
fix type
soilking Aug 13, 2024
5c322ed
comments in manifest
soilking Aug 13, 2024
1bf963d
update abi reference
soilking Aug 13, 2024
500a8cf
add missing abi
soilking Aug 13, 2024
9711e0e
unripe token loader and changeunderlying
soilking Aug 13, 2024
6149dd3
unripe snapshots
soilking Aug 14, 2024
e36576b
Merge branch 'feat/sk/sg-beanstalk-refactor' into feat/sk/sg-unripe
soilking Aug 14, 2024
038aeb9
add bdv to whitelist hourly/daily
soilking Aug 14, 2024
c42e627
add token decimals
soilking Aug 14, 2024
850c778
hourly unripe stats
soilking Aug 14, 2024
fc5e2aa
chop stats upon chop
soilking Aug 14, 2024
39d34d8
add convert handler
soilking Aug 14, 2024
f5e6175
add price abi
soilking Aug 14, 2024
669de1b
delta bdv
soilking Aug 14, 2024
6ef9f68
updated chop entity
soilking Aug 14, 2024
c957136
chop converts
soilking Aug 14, 2024
00fce72
Merge branch 'feat/sk/sg-beanstalk-refactor' into feat/sk/sg-unripe
soilking Aug 14, 2024
a05a565
_version entity
soilking Aug 14, 2024
c694232
update apy cache to use blockHandler init
soilking Aug 14, 2024
f9aad96
remove ineffective underscore
soilking Aug 14, 2024
2c75128
add version entity to all subgraphs
soilking Aug 14, 2024
37cc738
upgrade manifest specVersion
soilking Aug 14, 2024
bd197a8
update apiVersion and deploy ci
soilking Aug 14, 2024
94e2c36
Merge branch 'master' into subgraph-beanstalk2.4.0
soilking Aug 15, 2024
0578439
fix import of wrong file
soilking Aug 15, 2024
7923ab5
null check for bdv of unripe tokens prior to replant
soilking Aug 15, 2024
c96592c
fix comparison
soilking Aug 15, 2024
a2a71fc
change abi for pre-replant sunrise
soilking Aug 15, 2024
82c5e49
fix nullable issues
soilking Aug 15, 2024
7a98b22
FarmerGerminatingStalkBalanceChanged adjust for event bug
soilking Aug 15, 2024
17ee34b
Fix for germinating starting on the prior season upon certain converts
soilking Aug 16, 2024
510aa88
remove graft
soilking Aug 17, 2024
8fdc420
Merge branch 'master' into subgraph-beanstalk2.4.0
soilking Aug 17, 2024
e395207
handle bean supply exploit correction
soilking Aug 17, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/deploy.subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
exit 1
fi
# Check if the subgraph is a valid selection
if [[ "${{ github.event.inputs.subgraph }}" != "beanstalk" && "${{ github.event.inputs.subgraph }}" != "bean" && "${{ github.event.inputs.subgraph }}" != "basin" && "${{ github.event.inputs.subgraph }}" != "beanft" ]]; then
if [[ ! "${{ github.event.inputs.subgraph }}" =~ ^(beanstalk|bean|basin|beanft) ]]; then
echo "Error: Subgraph must be one of 'beanstalk', 'bean', 'basin', 'beanft'."
exit 1
fi
Expand Down
20 changes: 11 additions & 9 deletions projects/subgraph-basin/manifests/codegen-abis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# the only important part is in the `abis` and `templates` sections.
# - For abis, its only the list of abis that is relevant. The name of the dataSource is also visible.
# - For templates, it is only the name of the template that is relevant.
specVersion: 0.0.4
specVersion: 0.0.9
schema:
file: ../schema.graphql
dataSources:
Expand Down Expand Up @@ -33,10 +33,11 @@ dataSources:
file: ../../subgraph-core/abis/CurvePrice.json
- name: BeanstalkPrice
file: ../../subgraph-core/abis/BeanstalkPrice.json
eventHandlers:
- event: BoreWell(address,address,address[],(address,bytes),(address,bytes)[],bytes)
handler: handleBoreWell
file: ../src/templates/AquiferHandler.ts
blockHandlers:
- handler: handleInitVersion
filter:
kind: once
file: ../src/utils/Init.ts
templates:
- kind: ethereum/contract
name: Well
Expand All @@ -52,7 +53,8 @@ templates:
abis:
- name: Well
file: ../../subgraph-core/abis/Well.json
eventHandlers:
- event: Sync(uint256[],uint256,address)
handler: handleSync
file: ../src/WellHandler.ts
blockHandlers:
- handler: handleInitVersion
filter:
kind: once
file: ../src/utils/Init.ts
27 changes: 26 additions & 1 deletion projects/subgraph-basin/manifests/ethereum.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
specVersion: 0.0.4
specVersion: 0.0.9
schema:
file: ../schema.graphql
dataSources:
###
# INITIALIZATION
###
- kind: ethereum/contract
name: Version
network: mainnet
source:
address: "0xBA51AAAA95aeEFc1292515b36D86C51dC7877773"
abi: Aquifer
startBlock: 17977922
endBlock: 17977922
mapping:
kind: ethereum/events
apiVersion: 0.0.7
language: wasm/assemblyscript
entities:
- Version
abis:
- name: Aquifer
file: ../../subgraph-core/abis/Aquifer.json
blockHandlers:
- handler: handleInitVersion
filter:
kind: once
file: ../src/utils/Init.ts
- kind: ethereum/contract
name: Aquifer
network: mainnet
Expand Down
12 changes: 12 additions & 0 deletions projects/subgraph-basin/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ enum SwapEvent {
SHIFT
}

# This same entity schema is intended for use across the subgraphs
type Version @entity {
"= 'subgraph'"
id: ID!
"= 'beanstalk'"
subgraphName: String!
"Verison number of the subgraph"
versionNumber: String!
"Which blockchain is being indexed, i.e. 'ethereum', 'arbitrum', etc."
chain: String!
}

type Token @entity {
" Smart contract address of the token "
id: Bytes!
Expand Down
24 changes: 24 additions & 0 deletions projects/subgraph-basin/src/utils/Init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { BigInt, ethereum } from "@graphprotocol/graph-ts";
import { Version } from "../../generated/schema";

export function handleInitVersion(block: ethereum.Block): void {
const versionEntity = new Version("subgraph");
versionEntity.versionNumber = "2.2.2";
versionEntity.subgraphName = subgraphNameForBlockNumber(block.number);
versionEntity.chain = chainForBlockNumber(block.number);
versionEntity.save();
}

function subgraphNameForBlockNumber(blockNumber: BigInt): string {
if (blockNumber == BigInt.fromU32(17977922)) {
return "basin";
}
throw new Error("Unable to initialize subgraph name for this block number");
}

function chainForBlockNumber(blockNumber: BigInt): string {
if (blockNumber == BigInt.fromU32(17977922)) {
return "ethereum";
}
throw new Error("Unable to initialize chain for this block number");
}
11 changes: 6 additions & 5 deletions projects/subgraph-bean/manifests/codegen-abis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# the only important part is in the `abis` and `templates` sections.
# - For abis, its only the list of abis that is relevant. The name of the dataSource is also visible.
# - For templates, it is only the name of the template that is relevant.
specVersion: 0.0.4
specVersion: 0.0.9
schema:
file: ../schema.graphql
dataSources:
Expand Down Expand Up @@ -43,7 +43,8 @@ dataSources:
file: ../../subgraph-core/abis/CurvePrice.json
- name: CalculationsCurve
file: ../../subgraph-core/abis/CalculationsCurve.json
eventHandlers:
- event: Transfer(indexed address,indexed address,uint256)
handler: handleTransfer
file: ../src/BeanHandler.ts
blockHandlers:
- handler: handleInitVersion
filter:
kind: once
file: ../src/utils/Init.ts
27 changes: 26 additions & 1 deletion projects/subgraph-bean/manifests/ethereum.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
specVersion: 0.0.4
specVersion: 0.0.9
schema:
file: ../schema.graphql
dataSources:
###
# INITIALIZATION
###
- kind: ethereum/contract
name: Version
network: mainnet
source:
address: "0xC1E088fC1323b20BCBee9bd1B9fC9546db5624C5"
abi: Beanstalk
startBlock: 12974075
endBlock: 12974075
mapping:
kind: ethereum/events
apiVersion: 0.0.7
language: wasm/assemblyscript
entities:
- Version
abis:
- name: Beanstalk
file: ../../subgraph-core/abis/Beanstalk/Beanstalk-Replanted.json
blockHandlers:
- handler: handleInitVersion
filter:
kind: once
file: ../src/utils/Init.ts
- kind: ethereum/contract
name: BeanV1
network: mainnet
Expand Down
12 changes: 12 additions & 0 deletions projects/subgraph-bean/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# This same entity schema is intended for use across the subgraphs
type Version @entity {
"= 'subgraph'"
id: ID!
"= 'beanstalk'"
subgraphName: String!
"Verison number of the subgraph"
versionNumber: String!
"Which blockchain is being indexed, i.e. 'ethereum', 'arbitrum', etc."
chain: String!
}

type Token @entity {
"Smart contract address of the token"
id: ID!
Expand Down
14 changes: 11 additions & 3 deletions projects/subgraph-bean/src/utils/Bean.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { BigDecimal, BigInt } from "@graphprotocol/graph-ts";
import { Bean, BeanDailySnapshot, BeanHourlySnapshot, Pool } from "../../generated/schema";
import { BEAN_ERC20_V1, BEAN_ERC20, BEAN_WETH_V1, BEAN_3CRV_V1, BEAN_LUSD_V1, BEANSTALK } from "../../../subgraph-core/utils/Constants";
import {
BEAN_ERC20_V1,
BEAN_ERC20,
BEAN_WETH_V1,
BEAN_3CRV_V1,
BEAN_LUSD_V1,
BEANSTALK,
NEW_BEAN_TOKEN_BLOCK
} from "../../../subgraph-core/utils/Constants";
import { dayFromTimestamp, hourFromTimestamp } from "../../../subgraph-core/utils/Dates";
import { ONE_BD, toDecimal, ZERO_BD, ZERO_BI } from "../../../subgraph-core/utils/Decimals";
import { checkBeanCross, getV1Crosses } from "./Cross";
Expand Down Expand Up @@ -178,11 +186,11 @@ export function calcLiquidityWeightedBeanPrice(token: string): BigDecimal {
}

export function getBeanTokenAddress(blockNumber: BigInt): string {
return blockNumber < BigInt.fromString("15278082") ? BEAN_ERC20_V1.toHexString() : BEAN_ERC20.toHexString();
return blockNumber < NEW_BEAN_TOKEN_BLOCK ? BEAN_ERC20_V1.toHexString() : BEAN_ERC20.toHexString();
}

export function updateBeanSupplyPegPercent(blockNumber: BigInt): void {
if (blockNumber < BigInt.fromString("15278082")) {
if (blockNumber < NEW_BEAN_TOKEN_BLOCK) {
let bean = loadBean(BEAN_ERC20_V1.toHexString());
let lpSupply = ZERO_BD;

Expand Down
24 changes: 24 additions & 0 deletions projects/subgraph-bean/src/utils/Init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { BigInt, ethereum } from "@graphprotocol/graph-ts";
import { Version } from "../../generated/schema";

export function handleInitVersion(block: ethereum.Block): void {
const versionEntity = new Version("subgraph");
versionEntity.versionNumber = "2.3.1";
versionEntity.subgraphName = subgraphNameForBlockNumber(block.number);
versionEntity.chain = chainForBlockNumber(block.number);
versionEntity.save();
}

function subgraphNameForBlockNumber(blockNumber: BigInt): string {
if (blockNumber == BigInt.fromU32(12974075)) {
return "bean";
}
throw new Error("Unable to initialize subgraph name for this block number");
}

function chainForBlockNumber(blockNumber: BigInt): string {
if (blockNumber == BigInt.fromU32(12974075)) {
return "ethereum";
}
throw new Error("Unable to initialize chain for this block number");
}
4 changes: 2 additions & 2 deletions projects/subgraph-bean/src/utils/LockedBeans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
BEANSTALK,
GAUGE_BIP45_BLOCK,
UNRIPE_BEAN,
UNRIPE_BEAN_3CRV
UNRIPE_LP
} from "../../../subgraph-core/utils/Constants";
import { SeedGauge } from "../../generated/Bean-ABIs/SeedGauge";
import { ONE_BI, ZERO_BD, ZERO_BI } from "../../../subgraph-core/utils/Decimals";
Expand Down Expand Up @@ -46,7 +46,7 @@ export function calcLockedBeans(blockNumber: BigInt): BigInt {

const recapPaidPercent = new BigDecimal(recapPercentResult.value).div(BigDecimal.fromString("1000000"));
const lockedBeansUrBean = LibLockedUnderlying_getLockedUnderlying(UNRIPE_BEAN, recapPaidPercent);
const lockedUnripeLp = LibLockedUnderlying_getLockedUnderlying(UNRIPE_BEAN_3CRV, recapPaidPercent);
const lockedUnripeLp = LibLockedUnderlying_getLockedUnderlying(UNRIPE_LP, recapPaidPercent);
const underlyingLpPool = getUnderlyingUnripe(blockNumber);

const poolBeanReserves = loadOrCreatePool(underlyingLpPool.toHexString(), blockNumber).reserves[0];
Expand Down
8 changes: 4 additions & 4 deletions projects/subgraph-bean/tests/l2sr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
BEAN_WETH_UNRIPE_MIGRATION_BLOCK,
GAUGE_BIP45_BLOCK,
UNRIPE_BEAN,
UNRIPE_BEAN_3CRV
UNRIPE_LP
} from "../../subgraph-core/utils/Constants";
import { BI_10, ONE_BI, ZERO_BI } from "../../subgraph-core/utils/Decimals";
import {
Expand Down Expand Up @@ -46,10 +46,10 @@ describe("L2SR", () => {
test("Calculation - block 19736119", () => {
mockSeedGaugeLockedBeansReverts(mockReserves, mockReservesTime);
mockERC20TokenSupply(UNRIPE_BEAN, BigInt.fromString("109291429462926"));
mockERC20TokenSupply(UNRIPE_BEAN_3CRV, BigInt.fromString("88784724593495"));
mockERC20TokenSupply(UNRIPE_LP, BigInt.fromString("88784724593495"));
const recapPaidPercent = BigDecimal.fromString("0.045288");
const lockedUnderlyingBean = LibLockedUnderlying_getPercentLockedUnderlying(UNRIPE_BEAN, recapPaidPercent);
const lockedUnderlyingLp = LibLockedUnderlying_getPercentLockedUnderlying(UNRIPE_BEAN_3CRV, recapPaidPercent);
const lockedUnderlyingLp = LibLockedUnderlying_getPercentLockedUnderlying(UNRIPE_LP, recapPaidPercent);

assert.assertTrue(lockedUnderlyingBean.equals(BigDecimal.fromString("0.6620572696973799")));
assert.assertTrue(lockedUnderlyingLp.equals(BigDecimal.fromString("0.6620572696973799")));
Expand All @@ -60,7 +60,7 @@ describe("L2SR", () => {

mockGetRecapPaidPercent(BigDecimal.fromString("0.045288"));
mockGetTotalUnderlying(UNRIPE_BEAN, BigInt.fromString("24584183207621"));
mockGetTotalUnderlying(UNRIPE_BEAN_3CRV, BigInt.fromString("246676046856767267392929"));
mockGetTotalUnderlying(UNRIPE_LP, BigInt.fromString("246676046856767267392929"));
mockERC20TokenSupply(BEAN_WETH_CP2_WELL, BigInt.fromString("256164804872196346760208"));

const lockedBeans = calcLockedBeans(BEAN_WETH_UNRIPE_MIGRATION_BLOCK);
Expand Down
11 changes: 6 additions & 5 deletions projects/subgraph-beanft/manifests/codegen-abis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# the only important part is in the `abis` and `templates` sections.
# - For abis, its only the list of abis that is relevant. The name of the dataSource is also visible.
# - For templates, it is only the name of the template that is relevant.
specVersion: 0.0.5
specVersion: 0.0.9
schema:
file: ../schema.graphql
dataSources:
Expand All @@ -30,7 +30,8 @@ dataSources:
file: ../abis/barnraise.json
- name: basin
file: ../abis/basin.json
eventHandlers:
- event: Transfer(indexed address,indexed address,indexed uint256)
handler: handleTransferGenesis
file: ../src/mappings.ts
blockHandlers:
- handler: handleInitVersion
filter:
kind: once
file: ../src/utils/Init.ts
27 changes: 26 additions & 1 deletion projects/subgraph-beanft/manifests/ethereum.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
specVersion: 0.0.5
specVersion: 0.0.9
schema:
file: ../schema.graphql
dataSources:
###
# INITIALIZATION
###
- kind: ethereum/contract
name: Version
network: mainnet
source:
address: "0xa755A670Aaf1FeCeF2bea56115E65e03F7722A79"
abi: genesis
startBlock: 13323594
endBlock: 13323594
mapping:
kind: ethereum/events
apiVersion: 0.0.7
language: wasm/assemblyscript
entities:
- Version
abis:
- name: genesis
file: ../abis/genesis.json
blockHandlers:
- handler: handleInitVersion
filter:
kind: once
file: ../src/utils/Init.ts
- kind: ethereum
name: genesis
network: mainnet
Expand Down
16 changes: 14 additions & 2 deletions projects/subgraph-beanft/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
# This same entity schema is intended for use across the subgraphs
type Version @entity {
"= 'subgraph'"
id: ID!
"= 'beanstalk'"
subgraphName: String!
"Verison number of the subgraph"
versionNumber: String!
"Which blockchain is being indexed, i.e. 'ethereum', 'arbitrum', etc."
chain: String!
}

type BeaNFTUser @entity {
id: ID!
barnRaise: [Int!]
genesis: [Int!]
winter: [Int!]
basin: [Int!]
},
}
type CollectionData @entity {
id: ID!
minted: [Int!]
}
}
Loading
Loading