From 666c04754113c10e540e55d347e754d35db5b117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Pr=C3=A9vost?= <998369+prevostc@users.noreply.github.com> Date: Mon, 15 Jul 2024 14:30:16 +0200 Subject: [PATCH] Cleanup RPs --- src/classic/entity/classic.ts | 7 ++++++- src/clm/entity/clm.ts | 7 ++++++- src/reward-pool/lifecycle.ts | 12 ++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/classic/entity/classic.ts b/src/classic/entity/classic.ts index 945e028..cfcce94 100644 --- a/src/classic/entity/classic.ts +++ b/src/classic/entity/classic.ts @@ -1,4 +1,4 @@ -import { BigInt, Bytes } from "@graphprotocol/graph-ts" +import { BigInt, Bytes, store } from "@graphprotocol/graph-ts" import { Classic, ClassicVault, @@ -95,6 +95,11 @@ export function isClassicRewardPool(rewardPoolAddress: Bytes): boolean { return ClassicRewardPool.load(rewardPoolAddress) != null } +export function removeClassicRewardPool(rewardPoolAddress: Bytes): void { + const id = rewardPoolAddress + store.remove("ClassicRewardPool", id.toHexString()) +} + export function getClassicRewardPool(rewardPoolAddress: Bytes): ClassicRewardPool { let rewardPool = ClassicRewardPool.load(rewardPoolAddress) if (!rewardPool) { diff --git a/src/clm/entity/clm.ts b/src/clm/entity/clm.ts index 35fbf8a..d76b098 100644 --- a/src/clm/entity/clm.ts +++ b/src/clm/entity/clm.ts @@ -1,4 +1,4 @@ -import { BigInt, Bytes } from "@graphprotocol/graph-ts" +import { BigInt, Bytes, store } from "@graphprotocol/graph-ts" import { ClmRewardPool, ClmStrategy, ClmManager, ClmSnapshot, CLM } from "../../../generated/schema" import { ADDRESS_ZERO } from "../../common/utils/address" import { ZERO_BI } from "../../common/utils/decimal" @@ -90,6 +90,11 @@ export function isClmRewardPool(rewardPoolAddress: Bytes): boolean { return ClmRewardPool.load(rewardPoolAddress) != null } +export function removeClmRewardPool(rewardPoolAddress: Bytes): void { + const id = rewardPoolAddress + store.remove("ClmRewardPool", id.toHexString()) +} + export function getClmRewardPool(rewardPoolAddress: Bytes): ClmRewardPool { let rewardPool = ClmRewardPool.load(rewardPoolAddress) if (!rewardPool) { diff --git a/src/reward-pool/lifecycle.ts b/src/reward-pool/lifecycle.ts index 47ba82e..c2bf14b 100644 --- a/src/reward-pool/lifecycle.ts +++ b/src/reward-pool/lifecycle.ts @@ -14,8 +14,14 @@ import { import { getTransaction } from "../common/entity/transaction" import { fetchAndSaveTokenData } from "../common/utils/token" import { ZERO_BI } from "../common/utils/decimal" -import { getCLM, getClmRewardPool, isClmManagerAddress, isClmRewardPool } from "../clm/entity/clm" -import { getClassic, getClassicRewardPool, isClassicRewardPool, isClassicVaultAddress } from "../classic/entity/classic" +import { getCLM, getClmRewardPool, isClmManagerAddress, isClmRewardPool, removeClmRewardPool } from "../clm/entity/clm" +import { + getClassic, + getClassicRewardPool, + isClassicRewardPool, + isClassicVaultAddress, + removeClassicRewardPool, +} from "../classic/entity/classic" import { getNullToken } from "../common/entity/token" export function handleRewardPoolCreated(event: RewardPoolCreatedEvent): void { @@ -70,6 +76,7 @@ export function handleRewardPoolInitialized(event: RewardPoolInitialized): void clm.rewardPoolsTotalSupply = rewardPoolsTotalSupply clm.save() + removeClassicRewardPool(rewardPoolAddress) ClmRewardPoolTemplate.create(rewardPoolAddress) log.info("handleRewardPoolInitialized: Reward pool {} initialized for CLM {} on block {}", [ @@ -97,6 +104,7 @@ export function handleRewardPoolInitialized(event: RewardPoolInitialized): void classic.rewardPoolsTotalSupply = rewardPoolsTotalSupply classic.save() + removeClmRewardPool(rewardPoolAddress) ClassicRewardPoolTemplate.create(rewardPoolAddress) log.info("handleRewardPoolInitialized: Reward pool {} initialized for Classic {} on block {}", [