From 6fd3ec4b13a8e729e977a81d1da5c58009e2a8dc Mon Sep 17 00:00:00 2001 From: harsh9200 Date: Fri, 28 Jun 2024 23:10:37 +0530 Subject: [PATCH 1/4] Fix bug --- .../templates/balancer.v2.template.yaml | 2 +- .../balancer-forks/src/common/constants.ts | 167 ++++++++++++++++++ .../balancer-forks/src/common/initializers.ts | 2 +- subgraphs/balancer-forks/src/common/types.ts | 12 +- subgraphs/balancer-forks/src/common/utils.ts | 12 +- .../balancer-forks/src/modules/Rewards.ts | 2 +- 6 files changed, 191 insertions(+), 6 deletions(-) create mode 100644 subgraphs/balancer-forks/src/common/constants.ts diff --git a/subgraphs/balancer-forks/protocols/balancer-v2/config/templates/balancer.v2.template.yaml b/subgraphs/balancer-forks/protocols/balancer-v2/config/templates/balancer.v2.template.yaml index 69796a5c51..7726cdb37f 100644 --- a/subgraphs/balancer-forks/protocols/balancer-v2/config/templates/balancer.v2.template.yaml +++ b/subgraphs/balancer-forks/protocols/balancer-v2/config/templates/balancer.v2.template.yaml @@ -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 diff --git a/subgraphs/balancer-forks/src/common/constants.ts b/subgraphs/balancer-forks/src/common/constants.ts new file mode 100644 index 0000000000..ca4e4f4828 --- /dev/null +++ b/subgraphs/balancer-forks/src/common/constants.ts @@ -0,0 +1,167 @@ +import { Address, BigDecimal, BigInt } from "@graphprotocol/graph-ts"; + +//////////////////////// +///// Schema Enums ///// +//////////////////////// + +// The network names corresponding to the Network enum in the schema. +// They also correspond to the ones in `dataSource.network()` after converting to lower case. +// See below for a complete list: +// https://thegraph.com/docs/en/hosted-service/what-is-hosted-service/#supported-networks-on-the-hosted-service +export namespace Network { + export const ARBITRUM_ONE = "ARBITRUM_ONE"; + export const ARWEAVE_MAINNET = "ARWEAVE_MAINNET"; + export const AVALANCHE = "AVALANCHE"; + export const BOBA = "BOBA"; + export const AURORA = "AURORA"; + export const BSC = "BSC"; // aka BNB Chain + export const CELO = "CELO"; + export const COSMOS = "COSMOS"; + export const CRONOS = "CRONOS"; + export const MAINNET = "MAINNET"; // Ethereum mainnet + export const FANTOM = "FANTOM"; + export const FUSE = "FUSE"; + export const HARMONY = "HARMONY"; + export const JUNO = "JUNO"; + export const MOONBEAM = "MOONBEAM"; + export const MOONRIVER = "MOONRIVER"; + export const NEAR_MAINNET = "NEAR_MAINNET"; + export const OPTIMISM = "OPTIMISM"; + export const OSMOSIS = "OSMOSIS"; + export const MATIC = "MATIC"; // aka Polygon + export const XDAI = "XDAI"; // aka Gnosis Chain +} + +export namespace ProtocolType { + export const EXCHANGE = "EXCHANGE"; + export const LENDING = "LENDING"; + export const YIELD = "YIELD"; + export const BRIDGE = "BRIDGE"; + export const GENERIC = "GENERIC"; +} + +export namespace LiquidityPoolFeeType { + export const FIXED_TRADING_FEE = "FIXED_TRADING_FEE"; + export const TIERED_TRADING_FEE = "TIERED_TRADING_FEE"; + export const DYNAMIC_TRADING_FEE = "DYNAMIC_TRADING_FEE"; + export const FIXED_LP_FEE = "FIXED_LP_FEE"; + export const DYNAMIC_LP_FEE = "DYNAMIC_LP_FEE"; + export const FIXED_PROTOCOL_FEE = "FIXED_PROTOCOL_FEE"; + export const DYNAMIC_PROTOCOL_FEE = "DYNAMIC_PROTOCOL_FEE"; +} + +export namespace RewardTokenType { + export const DEPOSIT = "DEPOSIT"; + export const BORROW = "BORROW"; +} + +export namespace LendingType { + export const CDP = "CDP"; + export const POOLED = "POOLED"; +} + +export namespace RiskType { + export const GLOBAL = "GLOBAL"; + export const ISOLATED = "ISOLATED"; +} + +export namespace InterestRateType { + export const STABLE = "STABLE"; + export const VARIABLE = "VARIABLE"; + export const FIXED_TERM = "FIXED_TERM"; +} + +export namespace InterestRateSide { + export const LENDER = "LENDER"; + export const BORROWER = "BORROWER"; +} + +export namespace UsageType { + export const DEPOSIT = "DEPOSIT"; + export const WITHDRAW = "WITHDRAW"; + export const SWAP = "SWAP"; +} + +export namespace RewardIntervalType { + export const BLOCK = "BLOCK"; + export const TIMESTAMP = "TIMESTAMP"; +} + +export namespace NULL { + export const TYPE_STRING = "0x0000000000000000000000000000000000000000"; + export const TYPE_ADDRESS = Address.fromString(TYPE_STRING); +} + +export namespace Protocol { + export const NAME = "Balancer v2"; + export const SLUG = "balancer-v2"; + export const NETWORK = Network.MAINNET; +} + +export namespace MasterChef { + export const MINICHEF = "MINICHEF"; + export const MASTERCHEF = "MASTERCHEF"; + export const MASTERCHEFV2 = "MASTERCHEFV2"; + export const MASTERCHEFV3 = "MASTERCHEFV3"; +} + +export const SECONDS_PER_HOUR = 60 * 60; +export const SECONDS_PER_DAY = 60 * 60 * 24; +export const MAX_BPS = BigInt.fromI32(10000); +export const DEFAULT_DECIMALS = BigInt.fromI32(18); + +export const INT_ZERO = 0 as i32; +export const INT_ONE = 1 as i32; + +export const BIGINT_NEG_ONE = BigInt.fromI32(-1); +export const BIGINT_ZERO = BigInt.fromI32(0); +export const BIGINT_ONE = BigInt.fromI32(1); +export const BIGINT_TEN = BigInt.fromI32(10); +export const BIGINT_HUNDRED = BigInt.fromI32(100); +export const BIGINT_NEGATIVE_ONE = BigInt.fromString("-1"); + +export const BIGDECIMAL_ZERO = new BigDecimal(BIGINT_ZERO); +export const BIGDECIMAL_ONE = new BigDecimal(BIGINT_ONE); +export const BIGDECIMAL_TEN = new BigDecimal(BIGINT_TEN); +export const BIGDECIMAL_HUNDRED = BigDecimal.fromString("100"); +export const BIGDECIMAL_NEGATIVE_ONE = BigDecimal.fromString("-1"); +export const BIGDECIMAL_POINT_FOUR = BigDecimal.fromString("0.4"); + +export const DEFAULT_DECIMALS_DENOMINATOR = BigDecimal.fromString("1000000000000000000"); +export const FEE_DENOMINATOR = DEFAULT_DECIMALS_DENOMINATOR; + +export const USDC_DECIMALS = 6; +export const USDC_DENOMINATOR = BigDecimal.fromString("1000000"); + +export const PRICE_CACHING_BLOCKS = BigInt.fromI32(7000); + +///////////////////////////////////// +///// Protocol/Network Specific ///// +///////////////////////////////////// + +export const VAULT_ADDRESS = Address.fromString( + "0xBA12222222228d8Ba445958a75a0704d566BF2C8" +); +export const PROTOCOL_FEES_COLLECTOR_ADDRESS = Address.fromString( + "0xce88686553686DA562CE7Cea497CE749DA109f9F" +); +export const PROTOCOL_TOKEN_ADDRESS = Address.fromString( + "0xba100000625a3754423978a60c9317c58a424e3D" +); +export const GAUGE_CONTROLLER_ADDRESS = Address.fromString( + "0xC128468b7Ce63eA702C1f104D55A2566b13D3ABD" +); +export const AAVE_BOOSTED_POOL_ADDRESS = Address.fromString( + "0x7b50775383d3d6f0215a8f290f2c9e2eebbeceb2" +); +export const BLACKLISTED_PHANTOM_POOLS: Address[] = [ + Address.fromString("0x2bbf681cc4eb09218bee85ea2a5d3d13fa40fc0c"), // Balancer Aave Boosted Pool (USDT) OLD + Address.fromString("0x804cdb9116a10bb78768d3252355a1b18067bf8f"), // Balancer Aave Boosted Pool (DAI) OLD + Address.fromString("0x9210f1204b5a24742eba12f710636d76240df3d0"), // Balancer Aave Boosted Pool (USDC) OLD + Address.fromString("0x2f4eb100552ef93840d5adc30560e5513dfffacb"), // Balancer Aave Boosted Pool (USDT) + Address.fromString("0xae37d54ae477268b9997d4161b96b8200755935c"), // Balancer Aave Boosted Pool (DAI) + Address.fromString("0x82698aecc9e28e9bb27608bd52cf57f704bd1b83"), // Balancer Aave Boosted Pool (USDC) +]; + +export const INFLATION_INTERVAL = "TIMESTAMP"; +export const STARTING_INFLATION_RATE = BigDecimal.fromString((0.23974867724).toString()).times(DEFAULT_DECIMALS_DENOMINATOR); diff --git a/subgraphs/balancer-forks/src/common/initializers.ts b/subgraphs/balancer-forks/src/common/initializers.ts index 327e887004..701f453187 100644 --- a/subgraphs/balancer-forks/src/common/initializers.ts +++ b/subgraphs/balancer-forks/src/common/initializers.ts @@ -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( diff --git a/subgraphs/balancer-forks/src/common/types.ts b/subgraphs/balancer-forks/src/common/types.ts index 6ef73fe404..a1621441f1 100644 --- a/subgraphs/balancer-forks/src/common/types.ts +++ b/subgraphs/balancer-forks/src/common/types.ts @@ -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; } @@ -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()); } diff --git a/subgraphs/balancer-forks/src/common/utils.ts b/subgraphs/balancer-forks/src/common/utils.ts index 792252d63e..e5f4121763 100644 --- a/subgraphs/balancer-forks/src/common/utils.ts +++ b/subgraphs/balancer-forks/src/common/utils.ts @@ -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() ); @@ -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; @@ -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]; diff --git a/subgraphs/balancer-forks/src/modules/Rewards.ts b/subgraphs/balancer-forks/src/modules/Rewards.ts index 6dfdaa67e3..a37c3eb759 100644 --- a/subgraphs/balancer-forks/src/modules/Rewards.ts +++ b/subgraphs/balancer-forks/src/modules/Rewards.ts @@ -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 { From 0b43ef17ed7854d1d7da8960b80832895aa49587 Mon Sep 17 00:00:00 2001 From: harsh9200 Date: Fri, 28 Jun 2024 23:19:25 +0530 Subject: [PATCH 2/4] increment subgraph version --- deployment/deployment.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/deployment.json b/deployment/deployment.json index db36e1b38a..994ac88ca4 100644 --- a/deployment/deployment.json +++ b/deployment/deployment.json @@ -1150,7 +1150,7 @@ "status": "prod", "versions": { "schema": "1.3.0", - "subgraph": "1.1.4", + "subgraph": "1.1.5", "methodology": "1.0.0" }, "files": { From 3b0f86c172b612278e886fd5210199dbfd55bf2b Mon Sep 17 00:00:00 2001 From: harsh9200 Date: Fri, 28 Jun 2024 23:28:20 +0530 Subject: [PATCH 3/4] increment subgraph version to 1.2.0 --- deployment/deployment.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/deployment.json b/deployment/deployment.json index 994ac88ca4..ae553dd67e 100644 --- a/deployment/deployment.json +++ b/deployment/deployment.json @@ -1150,7 +1150,7 @@ "status": "prod", "versions": { "schema": "1.3.0", - "subgraph": "1.1.5", + "subgraph": "1.2.0", "methodology": "1.0.0" }, "files": { From abe5925865d26b315012aff128820d7fef866fa4 Mon Sep 17 00:00:00 2001 From: harsh9200 Date: Fri, 28 Jun 2024 23:47:53 +0530 Subject: [PATCH 4/4] Remove constants.ts file --- .../balancer-forks/src/common/constants.ts | 167 ------------------ 1 file changed, 167 deletions(-) delete mode 100644 subgraphs/balancer-forks/src/common/constants.ts diff --git a/subgraphs/balancer-forks/src/common/constants.ts b/subgraphs/balancer-forks/src/common/constants.ts deleted file mode 100644 index ca4e4f4828..0000000000 --- a/subgraphs/balancer-forks/src/common/constants.ts +++ /dev/null @@ -1,167 +0,0 @@ -import { Address, BigDecimal, BigInt } from "@graphprotocol/graph-ts"; - -//////////////////////// -///// Schema Enums ///// -//////////////////////// - -// The network names corresponding to the Network enum in the schema. -// They also correspond to the ones in `dataSource.network()` after converting to lower case. -// See below for a complete list: -// https://thegraph.com/docs/en/hosted-service/what-is-hosted-service/#supported-networks-on-the-hosted-service -export namespace Network { - export const ARBITRUM_ONE = "ARBITRUM_ONE"; - export const ARWEAVE_MAINNET = "ARWEAVE_MAINNET"; - export const AVALANCHE = "AVALANCHE"; - export const BOBA = "BOBA"; - export const AURORA = "AURORA"; - export const BSC = "BSC"; // aka BNB Chain - export const CELO = "CELO"; - export const COSMOS = "COSMOS"; - export const CRONOS = "CRONOS"; - export const MAINNET = "MAINNET"; // Ethereum mainnet - export const FANTOM = "FANTOM"; - export const FUSE = "FUSE"; - export const HARMONY = "HARMONY"; - export const JUNO = "JUNO"; - export const MOONBEAM = "MOONBEAM"; - export const MOONRIVER = "MOONRIVER"; - export const NEAR_MAINNET = "NEAR_MAINNET"; - export const OPTIMISM = "OPTIMISM"; - export const OSMOSIS = "OSMOSIS"; - export const MATIC = "MATIC"; // aka Polygon - export const XDAI = "XDAI"; // aka Gnosis Chain -} - -export namespace ProtocolType { - export const EXCHANGE = "EXCHANGE"; - export const LENDING = "LENDING"; - export const YIELD = "YIELD"; - export const BRIDGE = "BRIDGE"; - export const GENERIC = "GENERIC"; -} - -export namespace LiquidityPoolFeeType { - export const FIXED_TRADING_FEE = "FIXED_TRADING_FEE"; - export const TIERED_TRADING_FEE = "TIERED_TRADING_FEE"; - export const DYNAMIC_TRADING_FEE = "DYNAMIC_TRADING_FEE"; - export const FIXED_LP_FEE = "FIXED_LP_FEE"; - export const DYNAMIC_LP_FEE = "DYNAMIC_LP_FEE"; - export const FIXED_PROTOCOL_FEE = "FIXED_PROTOCOL_FEE"; - export const DYNAMIC_PROTOCOL_FEE = "DYNAMIC_PROTOCOL_FEE"; -} - -export namespace RewardTokenType { - export const DEPOSIT = "DEPOSIT"; - export const BORROW = "BORROW"; -} - -export namespace LendingType { - export const CDP = "CDP"; - export const POOLED = "POOLED"; -} - -export namespace RiskType { - export const GLOBAL = "GLOBAL"; - export const ISOLATED = "ISOLATED"; -} - -export namespace InterestRateType { - export const STABLE = "STABLE"; - export const VARIABLE = "VARIABLE"; - export const FIXED_TERM = "FIXED_TERM"; -} - -export namespace InterestRateSide { - export const LENDER = "LENDER"; - export const BORROWER = "BORROWER"; -} - -export namespace UsageType { - export const DEPOSIT = "DEPOSIT"; - export const WITHDRAW = "WITHDRAW"; - export const SWAP = "SWAP"; -} - -export namespace RewardIntervalType { - export const BLOCK = "BLOCK"; - export const TIMESTAMP = "TIMESTAMP"; -} - -export namespace NULL { - export const TYPE_STRING = "0x0000000000000000000000000000000000000000"; - export const TYPE_ADDRESS = Address.fromString(TYPE_STRING); -} - -export namespace Protocol { - export const NAME = "Balancer v2"; - export const SLUG = "balancer-v2"; - export const NETWORK = Network.MAINNET; -} - -export namespace MasterChef { - export const MINICHEF = "MINICHEF"; - export const MASTERCHEF = "MASTERCHEF"; - export const MASTERCHEFV2 = "MASTERCHEFV2"; - export const MASTERCHEFV3 = "MASTERCHEFV3"; -} - -export const SECONDS_PER_HOUR = 60 * 60; -export const SECONDS_PER_DAY = 60 * 60 * 24; -export const MAX_BPS = BigInt.fromI32(10000); -export const DEFAULT_DECIMALS = BigInt.fromI32(18); - -export const INT_ZERO = 0 as i32; -export const INT_ONE = 1 as i32; - -export const BIGINT_NEG_ONE = BigInt.fromI32(-1); -export const BIGINT_ZERO = BigInt.fromI32(0); -export const BIGINT_ONE = BigInt.fromI32(1); -export const BIGINT_TEN = BigInt.fromI32(10); -export const BIGINT_HUNDRED = BigInt.fromI32(100); -export const BIGINT_NEGATIVE_ONE = BigInt.fromString("-1"); - -export const BIGDECIMAL_ZERO = new BigDecimal(BIGINT_ZERO); -export const BIGDECIMAL_ONE = new BigDecimal(BIGINT_ONE); -export const BIGDECIMAL_TEN = new BigDecimal(BIGINT_TEN); -export const BIGDECIMAL_HUNDRED = BigDecimal.fromString("100"); -export const BIGDECIMAL_NEGATIVE_ONE = BigDecimal.fromString("-1"); -export const BIGDECIMAL_POINT_FOUR = BigDecimal.fromString("0.4"); - -export const DEFAULT_DECIMALS_DENOMINATOR = BigDecimal.fromString("1000000000000000000"); -export const FEE_DENOMINATOR = DEFAULT_DECIMALS_DENOMINATOR; - -export const USDC_DECIMALS = 6; -export const USDC_DENOMINATOR = BigDecimal.fromString("1000000"); - -export const PRICE_CACHING_BLOCKS = BigInt.fromI32(7000); - -///////////////////////////////////// -///// Protocol/Network Specific ///// -///////////////////////////////////// - -export const VAULT_ADDRESS = Address.fromString( - "0xBA12222222228d8Ba445958a75a0704d566BF2C8" -); -export const PROTOCOL_FEES_COLLECTOR_ADDRESS = Address.fromString( - "0xce88686553686DA562CE7Cea497CE749DA109f9F" -); -export const PROTOCOL_TOKEN_ADDRESS = Address.fromString( - "0xba100000625a3754423978a60c9317c58a424e3D" -); -export const GAUGE_CONTROLLER_ADDRESS = Address.fromString( - "0xC128468b7Ce63eA702C1f104D55A2566b13D3ABD" -); -export const AAVE_BOOSTED_POOL_ADDRESS = Address.fromString( - "0x7b50775383d3d6f0215a8f290f2c9e2eebbeceb2" -); -export const BLACKLISTED_PHANTOM_POOLS: Address[] = [ - Address.fromString("0x2bbf681cc4eb09218bee85ea2a5d3d13fa40fc0c"), // Balancer Aave Boosted Pool (USDT) OLD - Address.fromString("0x804cdb9116a10bb78768d3252355a1b18067bf8f"), // Balancer Aave Boosted Pool (DAI) OLD - Address.fromString("0x9210f1204b5a24742eba12f710636d76240df3d0"), // Balancer Aave Boosted Pool (USDC) OLD - Address.fromString("0x2f4eb100552ef93840d5adc30560e5513dfffacb"), // Balancer Aave Boosted Pool (USDT) - Address.fromString("0xae37d54ae477268b9997d4161b96b8200755935c"), // Balancer Aave Boosted Pool (DAI) - Address.fromString("0x82698aecc9e28e9bb27608bd52cf57f704bd1b83"), // Balancer Aave Boosted Pool (USDC) -]; - -export const INFLATION_INTERVAL = "TIMESTAMP"; -export const STARTING_INFLATION_RATE = BigDecimal.fromString((0.23974867724).toString()).times(DEFAULT_DECIMALS_DENOMINATOR);