Skip to content

Commit

Permalink
Remove classic vault unrelated to clm
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Jul 18, 2024
1 parent e7d5aab commit c4e1446
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/classic/entity/classic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ export function getClassic(vaultAddress: Bytes): Classic {
return classic
}

export function removeClassicAndDependencies(classic: Classic): void {
removeClassicVault(classic.vault)
removeClassicStrategy(classic.strategy)

const id = classic.id
store.remove("Classic", id.toHexString())
}

export function getClassicVault(vaultAddress: Bytes): ClassicVault {
let vault = ClassicVault.load(vaultAddress)
if (!vault) {
Expand All @@ -66,6 +74,11 @@ export function getClassicVault(vaultAddress: Bytes): ClassicVault {
return vault
}

export function removeClassicVault(vaultAddress: Bytes): void {
const id = vaultAddress
store.remove("ClassicVault", id.toHexString())
}

export function getClassicStrategy(strategyAddress: Bytes): ClassicStrategy {
let strategy = ClassicStrategy.load(strategyAddress)
if (!strategy) {
Expand All @@ -78,6 +91,11 @@ export function getClassicStrategy(strategyAddress: Bytes): ClassicStrategy {
return strategy
}

export function removeClassicStrategy(strategyAddress: Bytes): void {
const id = strategyAddress
store.remove("ClassicStrategy", id.toHexString())
}

export function getClassicBoost(boostAddress: Bytes): ClassicBoost {
let boost = ClassicBoost.load(boostAddress)
if (!boost) {
Expand Down
15 changes: 14 additions & 1 deletion src/classic/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ import {
ClassicStrategy as ClassicStrategyTemplate,
ClassicBoost as ClassicBoostTemplate,
} from "../../generated/templates"
import { getClassic, getClassicBoost, getClassicStrategy, getClassicVault } from "./entity/classic"
import {
getClassic,
getClassicBoost,
getClassicStrategy,
getClassicVault,
removeClassicAndDependencies,
} from "./entity/classic"
import { Classic } from "../../generated/schema"
import { getTransaction } from "../common/entity/transaction"
import { fetchAndSaveTokenData } from "../common/utils/token"
import { PRODUCT_LIFECYCLE_PAUSED, PRODUCT_LIFECYCLE_RUNNING } from "../common/entity/lifecycle"
import { ADDRESS_ZERO } from "../common/utils/address"
import { isClmRewardPool } from "../clm/entity/clm"

export function handleClassicVaultOrStrategyCreated(event: VaultOrStrategyCreated): void {
const address = event.params.proxy
Expand Down Expand Up @@ -144,6 +151,12 @@ function fetchInitialClassicDataAndSave(classic: Classic): void {
}
const underlyingTokenAddress = underlyingTokenAddressRes.value

if (!isClmRewardPool(underlyingTokenAddress)) {
log.error("Underlying token address is not related to clm: {}", [underlyingTokenAddress.toHexString()])
removeClassicAndDependencies(classic)
return
}

const vaultSharesToken = fetchAndSaveTokenData(vaultAddress)
const underlyingToken = fetchAndSaveTokenData(underlyingTokenAddress)

Expand Down

0 comments on commit c4e1446

Please sign in to comment.