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

fix(#patch); Balancer v2 Mainnet; Fix index out of range error #2574

Merged
merged 4 commits into from
Jun 28, 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
2 changes: 1 addition & 1 deletion deployment/deployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@
"status": "prod",
"versions": {
"schema": "1.3.0",
"subgraph": "1.1.4",
"subgraph": "1.2.0",
"methodology": "1.0.0"
},
"files": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ dataSources:
handler: handleNewGauge
- event: RewardsOnlyGaugeCreated(indexed address,indexed address,address)
handler: handleRewardsOnlyGaugeCreated
file: ./src/mappings/GaugeControllerMappings.ts
file: ./src/mappings/gaugeControllerMappings.ts
{{#usesBalancerTokenAdmin}}
- kind: ethereum/contract
name: BalancerTokenAdmin
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/balancer-forks/src/common/initializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ export function getOrCreateLiquidityPool(
);
pool._poolId = poolId.toHexString();

const inputTokensInfo = utils.getPoolTokensInfo(poolId);
const inputTokensInfo = utils.getPoolTokensInfo(poolAddress, poolId);
pool.inputTokens = inputTokensInfo.getInputTokens;
pool.inputTokenBalances = inputTokensInfo.getBalances;
pool.inputTokenWeights = utils.getPoolTokenWeights(
Expand Down
12 changes: 11 additions & 1 deletion subgraphs/balancer-forks/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,16 @@ export class PoolFeesType {
}

export class PoolTokensType {
private _poolAddress: Address;
private _tokens: Address[];
private _balances: BigInt[];

constructor(tokens: Address[] = [], balances: BigInt[] = []) {
constructor(
poolAddress: Address = constants.NULL.TYPE_ADDRESS,
tokens: Address[] = [],
balances: BigInt[] = []
) {
this._poolAddress = poolAddress;
this._tokens = tokens;
this._balances = balances;
}
Expand All @@ -78,6 +84,10 @@ export class PoolTokensType {
const inputTokens: string[] = [];

for (let idx = 0; idx < this._tokens.length; idx++) {
if (this._tokens.at(idx) == this._poolAddress) {
continue;
}

inputTokens.push(this._tokens.at(idx).toHexString());
}

Expand Down
12 changes: 10 additions & 2 deletions subgraphs/balancer-forks/src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ export function getTokenDecimals(tokenAddr: Address): BigDecimal {
return constants.BIGINT_TEN.pow(decimals.toI32() as u8).toBigDecimal();
}

export function getPoolTokensInfo(poolId: Bytes): PoolTokensType {
export function getPoolTokensInfo(
poolAddress: Address,
poolId: Bytes
): PoolTokensType {
const vaultContract = VaultContract.bind(constants.VAULT_ADDRESS);

const poolTokens = vaultContract.try_getPoolTokens(poolId);
if (poolTokens.reverted) return new PoolTokensType();

return new PoolTokensType(
poolAddress,
poolTokens.value.getTokens(),
poolTokens.value.getBalances()
);
Expand Down Expand Up @@ -99,7 +103,7 @@ export function getPoolInputTokenBalances(
poolId: Bytes
): BigInt[] {
const poolContract = WeightedPoolContract.bind(poolAddress);
const poolTokensInfo = getPoolTokensInfo(poolId);
const poolTokensInfo = getPoolTokensInfo(poolAddress, poolId);

const poolBalances = poolTokensInfo.getBalances;

Expand Down Expand Up @@ -229,6 +233,10 @@ export function getPoolTVL(
): BigDecimal {
let totalValueLockedUSD = constants.BIGDECIMAL_ZERO;

if (inputTokens.length != inputTokenBalances.length) {
return totalValueLockedUSD;
}

for (let idx = 0; idx < inputTokens.length; idx++) {
const inputTokenBalance = inputTokenBalances[idx];

Expand Down
2 changes: 1 addition & 1 deletion subgraphs/balancer-forks/src/modules/Rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as constants from "../common/constants";
import { RewardsInfoType } from "../common/types";
import { getRewardsPerDay } from "../common/rewards";
import { log, BigInt, Address, ethereum } from "@graphprotocol/graph-ts";
import { Gauge as LiquidityGaugeContract } from "../../generated/templates/gauge/Gauge";
import { Gauge as LiquidityGaugeContract } from "../../generated/templates/Gauge/Gauge";
import { GaugeController as GaugeControllereContract } from "../../generated/GaugeController/GaugeController";

export function getRewardsData(gaugeAddress: Address): RewardsInfoType {
Expand Down
Loading