The goal of this subgraph is to index historical data for the exact fees earned by each staked user in each vault.
The basic calculation for fees earned is poolShare * allocPoint * fee
where poolShare
is the user’s % ownership of the staked pool (stakedTokens / totalSupplyOfStakedTokens
) and allocPoint
is the % fee split given to the fee receiver i.e. Inventory (20%) or Liquidity (80%). The fee
is generated whenever the vault has a Mint, Redeem or Swap transaction. The fee is then split and transferred to the Inventory and Liquidity receivers.
The Inventory and Liquidity receivers can be set in the subgraph’s config. However it would be desirable to find a way to future proof against future receivers being added.
Summary
Index the exact amount of fee received for every staked individual when a fee receipt is created via mint/redeem/swap.
eventHandlers:
- event: NewVault(indexed uint256,address,address)
handler: handleNewVault - // Creates New Vault Entity
eventHandlers:
- event: FeesReceived(uint256,uint256)
handler: handleFeesReceived
- event: Deposit(uint256,uint256,uint256,uint256,address)
handler: handleDeposit
- event: Withdraw(uint256,uint256,uint256,address)
handler: handleWithdraw
- event: XTokenCreated(uint256,address,address)
handler: handleXTokenCreated
eventHandlers:
- event: FeesReceived(uint256,uint256)
handler: handleFeesReceived
- event: PoolUpdated(uint256,address)
handler: handlePoolUpdated
- event: PoolCreated(uint256,address)
handler: handleCreated
TokenX & TokenXWeth
eventHandlers:
- event: Transfer(address,address,uint256)
handler: handleTransfer
type User @entity {
id: ID!
poolShares: [PoolShare!] @derivedFrom(field: "user")
earnings: [Earning!] @derivedFrom(field: "user")
}
type Vault @entity {
id: ID! # VaultID
vaultId: BigInt!
address: Bytes!
assetAddress: Bytes!
xTokenAddress: Bytes!
xTokenWethAddress: Bytes!
inventoryStakedTotal: BigInt!
liquidityStakedTotal: BigInt!
shares: [String!]! ##PoolShareID
ticker: String # i.e. PUNK
}
type VaultAddressLookup @entity {
id: ID! #Address
vault: Vault!
}
type PoolShare @entity {
id: ID!
vault: Vault!
user: User!
inventoryShare: BigDecimal!
liquidityShare: BigDecimal!
}
type Earning @entity {
id: ID!
feeReceipt: FeeReceipt!
vault: Vault!
isInventory: Boolean!
user: User!
amount: BigDecimal
}
type UserVaultFeeAggregate @entity {
id: ID! # UserID - Vault - Inventory/LP
isInventory: Boolean!
user: User!
vault: Vault!
aggregatedVaultFees: BigDecimal!
}
type FeeReceipt @entity {
id: ID!
timestamp: BigInt!
isInventory: Boolean!
vault: Vault!
amount: BigDecimal!
feeDistribution: [Earning!] @derivedFrom(field: "feeReceipt")
}
type Token @entity {
id: ID!
vault: Vault!
isUsed: Boolean!
isInventory: Boolean!
}
Coming soon
Made with 💚 by Graphrica 🌍