Skip to content

Commit

Permalink
fix compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
soilking committed Sep 26, 2024
1 parent 57f719a commit 234d46c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
3 changes: 2 additions & 1 deletion projects/subgraph-basin/src/handlers/BeanstalkHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Sunrise } from "../../generated/Basin-ABIs/Beanstalk";
import { loadOrCreateAquifer } from "../entities/Aquifer";
import { checkForSnapshot } from "../utils/Well";
import { getAquifer } from "../../../subgraph-core/constants/RuntimeConstants";
import { toAddress } from "../../../subgraph-core/utils/Bytes";

export function handleSunrise(event: Sunrise): void {
// Right now this is a manual list of aquifers that are checked for deployments and wells updated
Expand All @@ -12,6 +13,6 @@ export function handleSunrise(event: Sunrise): void {
let aquifer = loadOrCreateAquifer(getAquifer(v()));

for (let i = 0; i < aquifer.wells.length; i++) {
checkForSnapshot(Address.fromBytes(aquifer.wells[i]), event.block);
checkForSnapshot(toAddress(aquifer.wells[i]), event.block);
}
}
9 changes: 5 additions & 4 deletions projects/subgraph-basin/src/handlers/WellHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
recordSyncEvent
} from "../entities/events/Liquidity";
import { recordShiftEvent, recordSwapEvent } from "../entities/events/Swap";
import { toAddress } from "../../../subgraph-core/utils/Bytes";

export function handleAddLiquidity(event: AddLiquidity): void {
let well = loadWell(event.address);
Expand All @@ -33,7 +34,7 @@ export function handleAddLiquidity(event: AddLiquidity): void {

updateWellVolumesAfterLiquidity(
event.address,
well.tokens.map<Address>((b) => Address.fromBytes(b)),
well.tokens.map<Address>((b) => toAddress(b)),
event.params.tokenAmountsIn,
event.params.lpAmountOut,
event.block
Expand All @@ -59,7 +60,7 @@ export function handleSync(event: Sync): void {

updateWellVolumesAfterLiquidity(
event.address,
well.tokens.map<Address>((b) => Address.fromBytes(b)),
well.tokens.map<Address>((b) => toAddress(b)),
deltaReserves,
event.params.lpAmountOut,
event.block
Expand Down Expand Up @@ -89,7 +90,7 @@ export function handleRemoveLiquidity(event: RemoveLiquidity): void {

updateWellVolumesAfterLiquidity(
event.address,
well.tokens.map<Address>((b) => Address.fromBytes(b)),
well.tokens.map<Address>((b) => toAddress(b)),
event.params.tokenAmountsOut,
event.params.lpAmountIn.neg(),
event.block
Expand Down Expand Up @@ -168,7 +169,7 @@ export function handleShift(event: Shift): void {
let well = loadWell(event.address);

let fromTokenIndex = well.tokens.indexOf(event.params.toToken) == 0 ? 1 : 0;
let fromToken = Address.fromBytes(well.tokens[fromTokenIndex]);
let fromToken = toAddress(well.tokens[fromTokenIndex]);

let deltaReserves = deltaBigIntArray(event.params.reserves, well.reserves);
let amountIn = deltaReserves[fromTokenIndex];
Expand Down
4 changes: 2 additions & 2 deletions projects/subgraph-basin/src/utils/Volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function updateWellVolumesAfterLiquidity(
block: ethereum.Block
): void {
let well = loadWell(wellAddress);
const wellTokens = well.tokens.map<Address>((t) => Address.fromBytes(t));
const wellTokens = well.tokens.map<Address>((t) => toAddress(t));

// Determines which tokens were bough/sold and how much
const tradeAmount = calcLiquidityVolume(well, padTokenAmounts(wellTokens, tokens, amounts), deltaLpSupply);
Expand Down Expand Up @@ -99,7 +99,7 @@ function updateVolumeStats(well: Well, deltaTradeVolumeReserves: BigInt[], delta
let totalTradeUSD = ZERO_BD;
let totalTransferUSD = ZERO_BD;
for (let i = 0; i < deltaTradeVolumeReserves.length; ++i) {
const tokenInfo = loadToken(Address.fromBytes(well.tokens[i]));
const tokenInfo = loadToken(toAddress(well.tokens[i]));
let usdTradeAmount = ZERO_BD;
if (deltaTradeVolumeReserves[i] > ZERO_BI) {
tradeVolumeReserves[i] = tradeVolumeReserves[i].plus(deltaTradeVolumeReserves[i]);
Expand Down
12 changes: 6 additions & 6 deletions projects/subgraph-basin/src/utils/Well.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { calcRates } from "./legacy/CP2";
export function getCalculatedReserveUSDValues(tokens: Bytes[], reserves: BigInt[]): BigDecimal[] {
let results = emptyBigDecimalArray(tokens.length);
for (let i = 0; i < tokens.length; i++) {
let token = loadToken(Address.fromBytes(tokens[i]));
let token = loadToken(toAddress(tokens[i]));
results[i] = toDecimal(reserves[i], token.decimals).times(token.lastPriceUSD);
}
return results;
Expand All @@ -37,7 +37,7 @@ export function updateWellTokenUSDPrices(wellAddress: Address, blockNumber: BigI
if (i == beanIndex) {
continue;
}
let tokenAddress = Address.fromBytes(well.tokens[i]);
let tokenAddress = toAddress(well.tokens[i]);
if (well.reserves[i].gt(ZERO_BI)) {
updateTokenUSD(tokenAddress, blockNumber, currentBeans.div(toDecimal(well.reserves[i], getTokenDecimals(tokenAddress))));
}
Expand All @@ -62,13 +62,13 @@ export function getTokenPrices(well: Well): BigInt[] {
// Stable2 does not require transforming rates. Otherwise, the rates are given with this precision:
// quoteToken + 18 - baseToken
if (!isStable2WellFn(v(), wellFnAddress)) {
const decimalsToRemove = [18 - getTokenDecimals(well.tokens[1]), 18 - getTokenDecimals(well.tokens[0])];
rates[0] = rates[0].div(BI_10.pow(decimalsToRemove[0]));
rates[1] = rates[1].div(BI_10.pow(decimalsToRemove[1]));
const decimalsToRemove = [18 - getTokenDecimals(toAddress(well.tokens[1])), 18 - getTokenDecimals(toAddress(well.tokens[0]))];
rates[0] = rates[0].div(BI_10.pow(<u8>decimalsToRemove[0]));
rates[1] = rates[1].div(BI_10.pow(<u8>decimalsToRemove[1]));
}
} else {
// In practice only the original constant product well does not support calcRate
rates = calcRates(well.reserves, [getTokenDecimals(well.tokens[0]), getTokenDecimals(well.tokens[1])]);
rates = calcRates(well.reserves, [getTokenDecimals(toAddress(well.tokens[0])), getTokenDecimals(toAddress(well.tokens[1]))]);
}
return rates;
}
Expand Down
5 changes: 4 additions & 1 deletion projects/subgraph-basin/src/utils/legacy/CP2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export function calcRates(reserves: BigInt[], tokenDecimals: u32[]): BigInt[] {
return [ZERO_BI, ZERO_BI];
}

return [reserves[1].times(BI_10.pow(tokenDecimals[0])).div(reserves[0]), reserves[0].times(BI_10.pow(tokenDecimals[1])).div(reserves[1])];
return [
reserves[1].times(BI_10.pow(<u8>tokenDecimals[0])).div(reserves[0]),
reserves[0].times(BI_10.pow(<u8>tokenDecimals[1])).div(reserves[1])
];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion projects/subgraph-basin/tests/helpers/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const WITHDRAW_ENTITY_TYPE = "Withdraw";
export const WELL = Address.fromString("0x90767D012E17F8d1D2f7a257ECB951db703D7b3D");
export const AQUIFER = Address.fromString("0xF6a8aD553b265405526030c2102fda2bDcdDC177");
export const IMPLEMENTATION = Address.fromString("0x09120eAED8e4cD86D85a616680151DAA653880F2");
export const WELL_FUNCTION = Address.fromString("0x3E661784267F128e5f706De17Fac1Fc1c9d56f30");
export const WELL_FUNCTION = Address.fromString("0xBA510C20FD2c52E4cb0d23CFC3cCD092F9165a6E");
export const PUMP = Address.fromString("0x6732128F9cc0c4344b2d4DC6285BCd516b7E59E6");
export const WELL_DATA = Bytes.empty();

Expand Down

0 comments on commit 234d46c

Please sign in to comment.