Skip to content

Commit

Permalink
merge: subgraph: resolve merge conflicts for b3 (#993)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brean0 authored Aug 6, 2024
2 parents aa3db35 + 18ad3d7 commit e92b919
Show file tree
Hide file tree
Showing 34 changed files with 1,256 additions and 2,278 deletions.
527 changes: 0 additions & 527 deletions projects/subgraph-basin/tests/Well.test.ts

This file was deleted.

26 changes: 0 additions & 26 deletions projects/subgraph-basin/tests/helpers/Functions.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,3 @@
<<<<<<< HEAD
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts";
import { createMockedFunction } from "matchstick-as";
import { BEAN_3CRV, BEAN_ERC20, BEAN_WETH_CP2_WELL, CRV3_TOKEN, WETH } from "../../../subgraph-core/utils/Constants";
import { BEAN_USD_PRICE, WELL } from "./Constants";
import { setMockCurvePrice, setMockWellPrice } from "../../../subgraph-core/tests/event-mocking/Price";

export function createContractCallMocks(): void {
setMockCurvePrice({
contract: BEAN_3CRV,
tokens: [BEAN_ERC20, CRV3_TOKEN],
balances: [BigInt.fromString("14306013160240"), BigInt.fromString("12306817594155799426763734")],
price: BEAN_USD_PRICE,
liquidity: BigInt.fromString("26025239751318"),
deltaB: BigInt.fromString("-866349934591"),
lpUsd: BigInt.fromString("969328"),
lpBdv: BigInt.fromString("1032515")
});

setMockWellPrice({
contract: BEAN_WETH_CP2_WELL,
tokens: [BEAN_ERC20, WETH],
balances: [BigInt.fromString("2000000000"), BigInt.fromString("1500000000000000000")],
price: BEAN_USD_PRICE,
=======
import { BigDecimal, BigInt, ethereum } from "@graphprotocol/graph-ts";
import { createMockedFunction } from "matchstick-as/assembly/index";
import { BEAN_3CRV, BEAN_ERC20, BEAN_WETH_CP2_WELL, CRV3_TOKEN, WETH } from "../../../subgraph-core/utils/Constants";
Expand Down Expand Up @@ -56,7 +31,6 @@ export function createContractCallMocks(priceMultiple: BigDecimal = ONE_BD): voi
tokens: [BEAN_ERC20, WETH],
balances: [BigInt.fromString("2000000000"), BigInt.fromString("1500000000000000000")],
price: price,
>>>>>>> master
liquidity: BigInt.fromString("26025239751318"),
deltaB: BigInt.fromString("-866349934591"),
lpUsd: BigInt.fromString("969328"),
Expand Down
4 changes: 0 additions & 4 deletions projects/subgraph-bean/src/BeanstalkHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import { MetapoolOracle, WellOracle } from "../generated/TWAPOracles/BIP37";
import { DeltaBPriceLiquidity } from "./utils/price/Types";
import { setRawWellReserves, setTwaLast } from "./utils/price/TwaOracle";
import { decodeCumulativeWellReserves, setWellTwa } from "./utils/price/WellPrice";
<<<<<<< HEAD
import { BeanstalkPrice_try_price, getPoolPrice } from "./utils/price/BeanstalkPrice";
=======
>>>>>>> master
import { beanstalkPrice_updatePoolPrices } from "./BlockHandler";

export function handleSunrise(event: Sunrise): void {
Expand Down
24 changes: 1 addition & 23 deletions projects/subgraph-bean/src/utils/Bean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,7 @@ export function loadBean(token: string): Bean {
return bean as Bean;
}

<<<<<<< HEAD
export function loadOrCreateBeanHourlySnapshot(
token: string,
timestamp: BigInt,
season: i32
): BeanHourlySnapshot {
=======
export function loadOrCreateBeanHourlySnapshot(token: string, timestamp: BigInt, season: i32): BeanHourlySnapshot {
>>>>>>> master
let id = token + "-" + season.toString();
let snapshot = BeanHourlySnapshot.load(id);
if (snapshot == null) {
Expand Down Expand Up @@ -195,9 +187,7 @@ 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 < BigInt.fromString("15278082") ? BEAN_ERC20_V1.toHexString() : BEAN_ERC20.toHexString();
}

export function updateBeanSupplyPegPercent(blockNumber: BigInt): void {
Expand Down Expand Up @@ -261,19 +251,7 @@ export function updateBeanAfterPoolSwap(
}

updateBeanSupplyPegPercent(blockNumber);
<<<<<<< HEAD
updateBeanValues(
BEAN_ERC20.toHexString(),
timestamp,
beanPrice,
ZERO_BI,
volumeBean,
volumeUSD,
deltaLiquidityUSD
);
=======
updateBeanValues(BEAN_ERC20.toHexString(), timestamp, beanPrice, ZERO_BI, volumeBean, volumeUSD, deltaLiquidityUSD);
>>>>>>> master
checkBeanCross(BEAN_ERC20.toHexString(), timestamp, blockNumber, oldBeanPrice, beanPrice);
}
}
Expand Down
3 changes: 0 additions & 3 deletions projects/subgraph-bean/src/utils/Pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import { emptyBigIntArray, ZERO_BD, ZERO_BI } from "../../../subgraph-core/utils
import { getBeanTokenAddress, loadBean, updateInstDeltaB } from "./Bean";
import { checkPoolCross } from "./Cross";
import { DeltaBAndPrice } from "./price/Types";
<<<<<<< HEAD
=======
import { getTokensForPool } from "../constants/PooledTokens";
import { loadOrCreateToken } from "./Token";
>>>>>>> master

export function loadOrCreatePool(poolAddress: string, blockNumber: BigInt): Pool {
let pool = Pool.load(poolAddress);
Expand Down
4 changes: 0 additions & 4 deletions projects/subgraph-bean/src/utils/Token.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<<<<<<< HEAD
import { BigDecimal, BigInt } from "@graphprotocol/graph-ts";
=======
import { BigDecimal } from "@graphprotocol/graph-ts";
>>>>>>> master
import { Token } from "../../generated/schema";
import { ZERO_BD } from "../../../subgraph-core/utils/Decimals";
import { getTokenInfo } from "../constants/PooledTokens";
Expand Down
16 changes: 0 additions & 16 deletions projects/subgraph-bean/tests/Cross.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import { mockBlock } from "../../subgraph-core/tests/event-mocking/Block";
import { mockPreReplantETHPrice, simpleMockPrice } from "../../subgraph-core/tests/event-mocking/Price";

import { BEAN_3CRV_V1, BEAN_ERC20, BEAN_ERC20_V1, BEAN_WETH_CP2_WELL, BEAN_WETH_V1 } from "../../subgraph-core/utils/Constants";
<<<<<<< HEAD
import { BD_10, ONE_BD, ONE_BI, toDecimal, ZERO_BD, ZERO_BI } from "../../subgraph-core/utils/Decimals";
=======
import { BD_10, BigDecimal_round, ONE_BD, ONE_BI, toDecimal, ZERO_BD, ZERO_BI } from "../../subgraph-core/utils/Decimals";
>>>>>>> master

import { loadBean } from "../src/utils/Bean";
import { getPreReplantPriceETH, constantProductPrice, uniswapV2Reserves } from "../src/utils/price/UniswapPrice";
Expand Down Expand Up @@ -79,13 +75,8 @@ describe("Peg Crosses", () => {
const reserves = uniswapV2Reserves(BEAN_WETH_V1);
const ethPriceNow = getPreReplantPriceETH();
const newPrice = constantProductPrice(toDecimal(reserves[1]), toDecimal(reserves[0], 18), ethPriceNow);
<<<<<<< HEAD
log.info("expected | actual {} | {}", [beanPrice.toString(), newPrice.truncate(4).toString()]);
assert.assertTrue(beanPrice.equals(newPrice));
=======
// log.info("expected | actual {} | {}", [beanPrice.toString(), newPrice.truncate(4).toString()]);
assert.assertTrue(beanPrice.equals(newPrice.truncate(4)));
>>>>>>> master

const beanPrice2 = BigDecimal.fromString("0.7652");
const liquidity2 = BigDecimal.fromString("1234567");
Expand All @@ -95,17 +86,10 @@ describe("Peg Crosses", () => {
const ethPriceNow2 = getPreReplantPriceETH();
const newPrice2 = constantProductPrice(toDecimal(reserves2[1]), toDecimal(reserves2[0], 18), ethPriceNow2);
const newLiquidity2 = toDecimal(reserves2[0], 18).times(ethPriceNow2).times(BigDecimal.fromString("2"));
<<<<<<< HEAD
log.info("expected | actual {} | {}", [beanPrice2.toString(), newPrice2.truncate(4).toString()]);
assert.assertTrue(beanPrice2.equals(newPrice2));
log.info("expected | actual {} | {}", [liquidity2.truncate(0).toString(), newLiquidity2.truncate(0).toString()]);
// assert.assertTrue(liquidity2.truncate(0).equals(newLiquidity2.truncate(0)));
=======
// log.info("expected | actual {} | {}", [beanPrice2.toString(), newPrice2.truncate(4).toString()]);
assert.assertTrue(beanPrice2.equals(newPrice2.truncate(4)));
// log.info("expected | actual {} | {}", [liquidity2.truncate(2).toString(), newLiquidity2.truncate(2).toString()]);
assert.assertTrue(BigDecimal_round(liquidity2).equals(BigDecimal_round(newLiquidity2)));
>>>>>>> master
});

test("UniswapV2/Bean cross above", () => {
Expand Down
9 changes: 0 additions & 9 deletions projects/subgraph-beanstalk/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ enum EmaWindow {
ROLLING_30_DAY
}

enum EmaWindow {
ROLLING_24_HOUR
ROLLING_7_DAY
ROLLING_30_DAY
}

type Beanstalk @entity {
" Smart contract address of the protocol's main contract (Factory, Registry, etc) "
id: ID!
Expand Down Expand Up @@ -1767,15 +1761,12 @@ type DewhitelistToken implements SiloEvent @entity(immutable: true) {
type Germinating @entity {
"Address-(EVEN|ODD)"
id: ID!
<<<<<<< HEAD
=======
"Address of the token or account which is germinating"
address: String!
"EVEN or ODD"
type: String!
"True when the address is a farmer account"
isFarmer: Boolean!
>>>>>>> master
"The season in which the germination started"
season: Int!
"Germinating stalk. This only applies to farmer/Beanstalk address"
Expand Down
61 changes: 1 addition & 60 deletions projects/subgraph-beanstalk/src/FieldHandler.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
import { Address, BigInt, log } from "@graphprotocol/graph-ts";
import {
Harvest,
PlotTransfer,
Sow,
SupplyDecrease,
SupplyIncrease,
SupplyNeutral,
WeatherChange
} from "../generated/Field/Beanstalk";
import { Harvest, PlotTransfer, Sow, SupplyDecrease, SupplyIncrease, SupplyNeutral, WeatherChange } from "../generated/Field/Beanstalk";
import { Harvest as HarvestEntity } from "../generated/schema";
import { BEANSTALK, BEANSTALK_FARMS } from "../../subgraph-core/utils/Constants";
<<<<<<< HEAD
import { ZERO_BI } from "../../subgraph-core/utils/Decimals";
=======
import { BI_10, ZERO_BI } from "../../subgraph-core/utils/Decimals";
>>>>>>> master
import { loadFarmer } from "./utils/Farmer";
import { handleRateChange, loadField, loadFieldDaily, loadFieldHourly } from "./utils/Field";
import { loadPlot } from "./utils/Plot";
import { savePodTransfer } from "./utils/PodTransfer";
import { getCurrentSeason, getHarvestableIndex, loadSeason } from "./utils/Season";
import { loadBeanstalk } from "./utils/Beanstalk";
<<<<<<< HEAD
=======
import { expirePodListingIfExists } from "./utils/PodListing";
>>>>>>> master

export function handleWeatherChange(event: WeatherChange): void {
handleRateChange(event.address, event.block, event.params.season, event.params.caseId, event.params.change);
Expand Down Expand Up @@ -297,11 +282,7 @@ export function handlePlotTransfer(event: PlotTransfer): void {
}
};

<<<<<<< HEAD
let transferredHarvestable = calcHarvestable(event.params.id, event.params.pods, season.harvestableIndex);
=======
let transferredHarvestable = calcHarvestable(event.params.id, event.params.pods, currentHarvestable);
>>>>>>> master

// log.debug("\nPodTransfer: ===================\n", []);
// log.debug("\nPodTransfer: Transfer Season - {}\n", [field.season.toString()]);
Expand Down Expand Up @@ -350,11 +331,7 @@ export function handlePlotTransfer(event: PlotTransfer): void {
sourcePlot.updatedAt = event.block.timestamp;
sourcePlot.updatedAtBlock = event.block.number;
sourcePlot.pods = event.params.pods;
<<<<<<< HEAD
sourcePlot.harvestablePods = calcHarvestable(sourcePlot.index, sourcePlot.pods, season.harvestableIndex);
=======
sourcePlot.harvestablePods = calcHarvestable(sourcePlot.index, sourcePlot.pods, currentHarvestable);
>>>>>>> master
sourcePlot.save();

remainderPlot.farmer = event.params.from.toHexString();
Expand All @@ -365,12 +342,7 @@ export function handlePlotTransfer(event: PlotTransfer): void {
remainderPlot.updatedAtBlock = event.block.number;
remainderPlot.index = remainderIndex;
remainderPlot.pods = sourceEndIndex.minus(transferEndIndex);
<<<<<<< HEAD
remainderPlot.harvestablePods = calcHarvestable(remainderPlot.index, remainderPlot.pods, season.harvestableIndex);
remainderPlot.temperature = sourcePlot.temperature;
=======
remainderPlot.harvestablePods = calcHarvestable(remainderPlot.index, remainderPlot.pods, currentHarvestable);
>>>>>>> master
remainderPlot.save();

// log.debug("\nPodTransfer: sourceIndex == transferIndex\n", []);
Expand All @@ -386,11 +358,7 @@ export function handlePlotTransfer(event: PlotTransfer): void {
sourcePlot.updatedAt = event.block.timestamp;
sourcePlot.updatedAtBlock = event.block.number;
sourcePlot.pods = sourcePlot.pods.minus(event.params.pods);
<<<<<<< HEAD
sourcePlot.harvestablePods = calcHarvestable(sourcePlot.index, sourcePlot.pods, season.harvestableIndex);
=======
sourcePlot.harvestablePods = calcHarvestable(sourcePlot.index, sourcePlot.pods, currentHarvestable);
>>>>>>> master
sourcePlot.save();

const isMarket = toPlot.source == "MARKET" && toPlot.sourceHash == event.transaction.hash.toHexString();
Expand All @@ -407,12 +375,7 @@ export function handlePlotTransfer(event: PlotTransfer): void {
toPlot.updatedAtBlock = event.block.number;
toPlot.index = event.params.id;
toPlot.pods = event.params.pods;
<<<<<<< HEAD
toPlot.harvestablePods = calcHarvestable(toPlot.index, toPlot.pods, season.harvestableIndex);
toPlot.temperature = sourcePlot.temperature;
=======
toPlot.harvestablePods = calcHarvestable(toPlot.index, toPlot.pods, currentHarvestable);
>>>>>>> master
toPlot.save();

// log.debug("\nPodTransfer: sourceEndIndex == transferEndIndex\n", []);
Expand All @@ -429,11 +392,7 @@ export function handlePlotTransfer(event: PlotTransfer): void {
sourcePlot.updatedAt = event.block.timestamp;
sourcePlot.updatedAtBlock = event.block.number;
sourcePlot.pods = event.params.id.minus(sourcePlot.index);
<<<<<<< HEAD
sourcePlot.harvestablePods = calcHarvestable(sourcePlot.index, sourcePlot.pods, season.harvestableIndex);
=======
sourcePlot.harvestablePods = calcHarvestable(sourcePlot.index, sourcePlot.pods, currentHarvestable);
>>>>>>> master
sourcePlot.save();

const isMarket = toPlot.source == "MARKET" && toPlot.sourceHash == event.transaction.hash.toHexString();
Expand All @@ -450,12 +409,7 @@ export function handlePlotTransfer(event: PlotTransfer): void {
toPlot.updatedAtBlock = event.block.number;
toPlot.index = event.params.id;
toPlot.pods = event.params.pods;
<<<<<<< HEAD
toPlot.harvestablePods = calcHarvestable(toPlot.index, toPlot.pods, season.harvestableIndex);
toPlot.temperature = sourcePlot.temperature;
=======
toPlot.harvestablePods = calcHarvestable(toPlot.index, toPlot.pods, currentHarvestable);
>>>>>>> master
toPlot.save();

remainderPlot.farmer = event.params.from.toHexString();
Expand All @@ -468,13 +422,8 @@ export function handlePlotTransfer(event: PlotTransfer): void {
remainderPlot.updatedAtBlock = event.block.number;
remainderPlot.index = remainderIndex;
remainderPlot.pods = sourceEndIndex.minus(transferEndIndex);
<<<<<<< HEAD
remainderPlot.harvestablePods = calcHarvestable(remainderPlot.index, remainderPlot.pods, season.harvestableIndex);
remainderPlot.temperature = sourcePlot.temperature;
=======
remainderPlot.harvestablePods = calcHarvestable(remainderPlot.index, remainderPlot.pods, currentHarvestable);
remainderPlot.beansPerPod = sourcePlot.beansPerPod;
>>>>>>> master
remainderPlot.save();

// log.debug("\nPodTransfer: split source twice\n", []);
Expand All @@ -491,11 +440,7 @@ export function handlePlotTransfer(event: PlotTransfer): void {
if (transferredHarvestable != ZERO_BI) {
updateFieldTotals(
event.params.from,
<<<<<<< HEAD
beanstalk.lastSeason,
=======
currentSeason,
>>>>>>> master
ZERO_BI,
ZERO_BI,
ZERO_BI,
Expand All @@ -507,11 +452,7 @@ export function handlePlotTransfer(event: PlotTransfer): void {
);
updateFieldTotals(
event.params.to,
<<<<<<< HEAD
beanstalk.lastSeason,
=======
currentSeason,
>>>>>>> master
ZERO_BI,
ZERO_BI,
ZERO_BI,
Expand Down
12 changes: 0 additions & 12 deletions projects/subgraph-beanstalk/src/GaugeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ export function handleFarmerGerminatingStalkBalanceChanged(event: FarmerGerminat

if (event.params.deltaGerminatingStalk > ZERO_BI) {
// Germinating stalk is being added in the current season
<<<<<<< HEAD
let farmerGerminating = loadOrCreateGerminating(event.params.account, currentSeason);
=======
let farmerGerminating = loadOrCreateGerminating(event.params.account, currentSeason, true);
>>>>>>> master
farmerGerminating.stalk = farmerGerminating.stalk.plus(event.params.deltaGerminatingStalk);
farmerGerminating.save();
} else {
Expand Down Expand Up @@ -132,11 +128,7 @@ export function handleTotalGerminatingBalanceChanged(event: TotalGerminatingBala
return;
}

<<<<<<< HEAD
let tokenGerminating = loadOrCreateGerminating(event.params.token, event.params.germinationSeason.toU32());
=======
let tokenGerminating = loadOrCreateGerminating(event.params.token, event.params.germinationSeason.toU32(), false);
>>>>>>> master
tokenGerminating.season = event.params.germinationSeason.toU32();
tokenGerminating.tokenAmount = tokenGerminating.tokenAmount.plus(event.params.deltaAmount);
tokenGerminating.bdv = tokenGerminating.bdv.plus(event.params.deltaBdv);
Expand All @@ -153,11 +145,7 @@ export function handleTotalGerminatingStalkChanged(event: TotalGerminatingStalkC
return;
}

<<<<<<< HEAD
let siloGerminating = loadOrCreateGerminating(event.address, event.params.germinationSeason.toU32());
=======
let siloGerminating = loadOrCreateGerminating(event.address, event.params.germinationSeason.toU32(), false);
>>>>>>> master
siloGerminating.season = event.params.germinationSeason.toU32();
siloGerminating.stalk = siloGerminating.stalk.plus(event.params.deltaGerminatingStalk);
// Don't delete this entity as the overall silo germinating stalk entity is likely to be recreated frequently.
Expand Down
Loading

0 comments on commit e92b919

Please sign in to comment.