From 8ea8d9232d8be464aeb05222934d9877eb456876 Mon Sep 17 00:00:00 2001 From: Dhruv Chauhan Date: Tue, 5 Dec 2023 13:01:33 +0530 Subject: [PATCH] fix div by zero --- deployment/deployment.json | 2 +- .../config/templates/trader.joe.template.yaml | 2 ++ .../src/common/handlers/handleRewardV2.ts | 13 ++++++++----- .../src/common/handlers/handleRewardV3.ts | 13 ++++++++----- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/deployment/deployment.json b/deployment/deployment.json index 5547dbc812..bf202e8c4a 100644 --- a/deployment/deployment.json +++ b/deployment/deployment.json @@ -5330,7 +5330,7 @@ "status": "prod", "versions": { "schema": "1.3.2", - "subgraph": "1.2.1", + "subgraph": "1.3.0", "methodology": "1.0.0" }, "files": { diff --git a/subgraphs/uniswap-forks/protocols/trader-joe/config/templates/trader.joe.template.yaml b/subgraphs/uniswap-forks/protocols/trader-joe/config/templates/trader.joe.template.yaml index 748c81209b..e90295ea18 100644 --- a/subgraphs/uniswap-forks/protocols/trader-joe/config/templates/trader.joe.template.yaml +++ b/subgraphs/uniswap-forks/protocols/trader-joe/config/templates/trader.joe.template.yaml @@ -6,6 +6,8 @@ description: ... graft: base: {{subgraphId}} # Subgraph ID of base subgraph block: {{graftStartBlock}} # Block number +features: + - grafting {{/graftEnabled}} dataSources: - kind: ethereum diff --git a/subgraphs/uniswap-forks/protocols/trader-joe/src/common/handlers/handleRewardV2.ts b/subgraphs/uniswap-forks/protocols/trader-joe/src/common/handlers/handleRewardV2.ts index 5e275e9c30..409177feb8 100644 --- a/subgraphs/uniswap-forks/protocols/trader-joe/src/common/handlers/handleRewardV2.ts +++ b/subgraphs/uniswap-forks/protocols/trader-joe/src/common/handlers/handleRewardV2.ts @@ -18,6 +18,7 @@ import { import { convertTokenToDecimal, roundToWholeNumber, + safeDiv, } from "../../../../../src/common/utils/utils"; import { getPoolRewardsWithBonus } from "./handleRewarder"; @@ -46,11 +47,13 @@ export function updateMasterChef( // Calculate Reward Emission per second to a specific pool // Pools are allocated based on their fraction of the total allocation times the rewards emitted per second - const rewardAmountPerInterval = masterChefV2.adjustedRewardTokenRate - .times(masterChefV2Pool.poolAllocPoint) - .div(masterChefV2.totalAllocPoint); - const rewardAmountPerIntervalBigDecimal = BigDecimal.fromString( - rewardAmountPerInterval.toString() + const rewardAmountPerIntervalBigDecimal = safeDiv( + new BigDecimal( + masterChefV2.adjustedRewardTokenRate.times( + masterChefV2Pool.poolAllocPoint + ) + ), + new BigDecimal(masterChefV2.totalAllocPoint) ); // Based on the emissions rate for the pool, calculate the rewards per day for the pool. diff --git a/subgraphs/uniswap-forks/protocols/trader-joe/src/common/handlers/handleRewardV3.ts b/subgraphs/uniswap-forks/protocols/trader-joe/src/common/handlers/handleRewardV3.ts index 7b48e327fb..b8abef61e5 100644 --- a/subgraphs/uniswap-forks/protocols/trader-joe/src/common/handlers/handleRewardV3.ts +++ b/subgraphs/uniswap-forks/protocols/trader-joe/src/common/handlers/handleRewardV3.ts @@ -19,6 +19,7 @@ import { import { convertTokenToDecimal, roundToWholeNumber, + safeDiv, } from "../../../../../src/common/utils/utils"; import { getPoolRewardsWithBonus } from "./handleRewarder"; @@ -57,11 +58,13 @@ export function updateMasterChef( // Calculate Reward Emission per second to a specific pool // Pools are allocated based on their fraction of the total allocation times the rewards emitted per second - const rewardAmountPerInterval = masterChefV3.adjustedRewardTokenRate - .times(masterChefV3Pool.poolAllocPoint) - .div(masterChefV3.totalAllocPoint); - const rewardAmountPerIntervalBigDecimal = BigDecimal.fromString( - rewardAmountPerInterval.toString() + const rewardAmountPerIntervalBigDecimal = safeDiv( + new BigDecimal( + masterChefV3.adjustedRewardTokenRate.times( + masterChefV3Pool.poolAllocPoint + ) + ), + new BigDecimal(masterChefV3.totalAllocPoint) ); // Based on the emissions rate for the pool, calculate the rewards per day for the pool.