Skip to content

Commit

Permalink
subgraph-beanstalk2.4.0 + add standardized Version entity to all subg…
Browse files Browse the repository at this point in the history
…raphs (#1025)
  • Loading branch information
soilking authored Aug 19, 2024
2 parents 6af75da + e395207 commit ea50d3a
Show file tree
Hide file tree
Showing 140 changed files with 6,593 additions and 5,487 deletions.
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

0 comments on commit ea50d3a

Please sign in to comment.