Skip to content

Commit

Permalink
Fix clm reward pool holders
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Aug 1, 2024
1 parent 6ce5a92 commit 4b534bf
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 18 deletions.
1 change: 1 addition & 0 deletions config/arbitrum.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"network": "arbitrum-one",
"indexerHintPrune": 20000000,
"shareTokenMintAddress": "0x0000000000000000000000000000000000000000",
"burnAddress": "0x000000000000000000000000000000000000dead",
"bindConfigAddress": "0x245d1c493342464ba568BCfb058C1069dFdc07B5",
"bindConfigBlock": 179921508,
"bindConfigEvent": "Initialized(uint8)",
Expand Down
1 change: 1 addition & 0 deletions config/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"network": "base",
"indexerHintPrune": 3000000,
"shareTokenMintAddress": "0x0000000000000000000000000000000000000000",
"burnAddress": "0x000000000000000000000000000000000000dead",
"bindConfigAddress": "0xbc4a342b0c057501e081484a2d24e576e854f823",
"bindConfigBlock": 12723637,
"bindConfigEvent": "ProxyCreated(address)",
Expand Down
1 change: 1 addition & 0 deletions config/bsc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"network": "bsc",
"indexerHintPrune": 2000000,
"shareTokenMintAddress": "0x0000000000000000000000000000000000000000",
"burnAddress": "0x000000000000000000000000000000000000dead",
"bindConfigAddress": "0xe596ec590de52c09c8d1c7a1294b32f957a7c94e",
"bindConfigBlock": 38435926,
"bindConfigEvent": "ProxyCreated(address)",
Expand Down
1 change: 1 addition & 0 deletions config/ethereum.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"network": "mainnet",
"indexerHintPrune": 400000,
"shareTokenMintAddress": "0x0000000000000000000000000000000000000000",
"burnAddress": "0x000000000000000000000000000000000000dead",
"bindConfigAddress": "0xC551dDCE8e5E657503Cd67A39713c06F2c0d2e97",
"bindConfigBlock": 19205553,
"bindConfigEvent": "ProxyCreated(address)",
Expand Down
1 change: 1 addition & 0 deletions config/kava.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"network": "kava",
"indexerHintPrune": 1000000,
"shareTokenMintAddress": "0x0000000000000000000000000000000000000000",
"burnAddress": "0x000000000000000000000000000000000000dead",
"bindConfigAddress": "0xCD9b038F012Ecd6b2739934426dDe3D4577e1d3C",
"bindConfigBlock": 3676191,
"bindConfigEvent": "ProxyCreated(address)",
Expand Down
1 change: 1 addition & 0 deletions config/linea.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"network": "linea",
"indexerHintPrune": 2000000,
"shareTokenMintAddress": "0x0000000000000000000000000000000000000000",
"burnAddress": "0x000000000000000000000000000000000000dead",
"bindConfigAddress": "0xD19ab62F83380908D65E344567378cF104cE46c2",
"bindConfigBlock": 3174336,
"bindConfigEvent": "ProxyCreated(address)",
Expand Down
1 change: 1 addition & 0 deletions config/manta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"network": "manta-pacific-mainnet",
"indexerHintPrune": 700000,
"shareTokenMintAddress": "0x0000000000000000000000000000000000000000",
"burnAddress": "0x000000000000000000000000000000000000dead",
"bindConfigAddress": "0x91BB303E972995EbE5f593BCddBb6F5Ef49Dbcbd",
"bindConfigBlock": 2501033,
"bindConfigEvent": "ProxyCreated(address)",
Expand Down
1 change: 1 addition & 0 deletions config/mode.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"network": "mode-mainnet",
"indexerHintPrune": 3000000,
"shareTokenMintAddress": "0x0000000000000000000000000000000000000000",
"burnAddress": "0x000000000000000000000000000000000000dead",
"bindConfigAddress": "0xBC4a342B0c057501E081484A2d24e576E854F823",
"bindConfigBlock": 8148382,
"bindConfigEvent": "ProxyCreated(address)",
Expand Down
1 change: 1 addition & 0 deletions config/optimism.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"network": "optimism",
"indexerHintPrune": 3000000,
"shareTokenMintAddress": "0x0000000000000000000000000000000000000000",
"burnAddress": "0x000000000000000000000000000000000000dead",
"bindConfigAddress": "0xA6D3769faC465FC0415e7E9F16dcdC96B83C240B",
"bindConfigBlock": 119276960,
"bindConfigEvent": "ProxyCreated(address)",
Expand Down
1 change: 1 addition & 0 deletions src/config.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ import { Address } from "@graphprotocol/graph-ts"

export const NETWORK_NAME = "{{network}}"
export const SHARE_TOKEN_MINT_ADDRESS = Address.fromString("{{shareTokenMintAddress}}")
export const BURN_ADDRESS = Address.fromString("{{burnAddress}}")
43 changes: 25 additions & 18 deletions src/vault-interaction.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Address, log, ethereum } from "@graphprotocol/graph-ts"
import { Address, log, ethereum, BigInt, Bytes } from "@graphprotocol/graph-ts"
import { Transfer as TransferEvent, IERC20 as IERC20Contract } from "../generated/templates/BeefyVaultV7/IERC20"
import { getBeefyStrategy, getBeefyVault, isVaultInitialized } from "./entity/vault"
import { ZERO_BD, ZERO_BI, tokenAmountToDecimal } from "./utils/decimal"
import { getTokenAndInitIfNeeded } from "./entity/token"
import { SHARE_TOKEN_MINT_ADDRESS } from "./config"
import { getChainVaults, isBoostAddress } from "./vault-config-asm"
import { SHARE_TOKEN_MINT_ADDRESS, BURN_ADDRESS } from "./config"
import { getChainVaults, isBoostAddress, isRewardPoolAddress } from "./vault-config-asm"
import { getInvestor } from "./entity/investor"
import { getInvestorPosition } from "./entity/position"
import { BeefyVault, Investor } from "../generated/schema"
Expand All @@ -14,59 +14,66 @@ import { getClockTick } from "./entity/clock"
import { HOUR } from "./utils/time"
import { TokenBalance } from "./platform/common"
import { Multicall3Params, multicall } from "./utils/multicall"
import { getBeefyRewardPool } from "./entity/reward-pool"

export function handleRewardPoolTransfer(event: TransferEvent): void {
// a transfer of a reward pool token is equivalent to a transfer of the vault token
// from the investor's perspective
handleVaultTransfer(event)
const rewardPool = getBeefyRewardPool(event.address)
const vault = getBeefyVault(rewardPool.vault)
_handleTransfer(event.block, vault, event.params.from, event.params.to, event.params.value, event.transaction.hash)
}

export function handleVaultTransfer(event: TransferEvent): void {
const vault = getBeefyVault(event.address)
_handleTransfer(event.block, vault, event.params.from, event.params.to, event.params.value, event.transaction.hash)
}

function _handleTransfer(block: ethereum.Block, vault: BeefyVault, from: Address, to: Address, value: BigInt, transactionHash: Bytes): void {
// transfer to self
if (event.params.from.equals(event.params.to)) {
log.warning("handleVaultTransfer: transfer to self {}", [event.transaction.hash.toHexString()])
if (from.equals(to)) {
log.warning("handleVaultTransfer: transfer to self {}", [transactionHash.toHexString()])
return
}

/// value is zero
if (event.params.value.equals(ZERO_BI)) {
log.warning("handleVaultTransfer: zero value transfer {}", [event.transaction.hash.toHexString()])
if (value.equals(ZERO_BI)) {
log.warning("handleVaultTransfer: zero value transfer {}", [transactionHash.toHexString()])
return
}

// ignore transfers from/to boosts
if (isBoostAddress(event.params.from)) {
log.warning("handleVaultTransfer: transfer from boost {}", [event.params.from.toHexString()])
if (isBoostAddress(from)) {
log.warning("handleVaultTransfer: transfer from boost {}", [from.toHexString()])
return
}
if (isBoostAddress(event.params.to)) {
log.warning("handleVaultTransfer: transfer to boost {}", [event.params.to.toHexString()])
if (isBoostAddress(to)) {
log.warning("handleVaultTransfer: transfer to boost {}", [to.toHexString()])
return
}

let vault = getBeefyVault(event.address)
if (!isVaultInitialized(vault)) {
log.warning("handleVaultTransfer: vault is not initialized {}", [vault.id.toHexString()])
return
}

updateVaultData(vault)

if (!event.params.from.equals(SHARE_TOKEN_MINT_ADDRESS)) {
const investorAddress = event.params.from
if (!from.equals(SHARE_TOKEN_MINT_ADDRESS) && !from.equals(BURN_ADDRESS) && !isRewardPoolAddress(from)) {
const investorAddress = from
const investor = getInvestor(investorAddress)
investor.save()
updateInvestorVaultData(vault, investor)
}

if (!event.params.to.equals(SHARE_TOKEN_MINT_ADDRESS)) {
const investorAddress = event.params.to
if (!to.equals(SHARE_TOKEN_MINT_ADDRESS) && !to.equals(BURN_ADDRESS) && !isRewardPoolAddress(to)) {
const investorAddress = to
const investor = getInvestor(investorAddress)
investor.save()
updateInvestorVaultData(vault, investor)
}

updateVaultBreakDown(event.block, vault)
updateVaultBreakDown(block, vault)
}

export function handleStrategyHarvest(event: ethereum.Event): void {
Expand Down

0 comments on commit 4b534bf

Please sign in to comment.