Skip to content

Commit

Permalink
refactor: add explicit address property
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Dec 5, 2024
1 parent de3a58d commit 76918c0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions subgraphs/isolated-pools/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ The Pool entity
type Pool @entity {
"Pool Address as id"
id: Bytes!
"Pool Comptroller address"
address: Bytes!
"Name of the pool"
name: String!
"Creator of the pool"
Expand Down Expand Up @@ -135,6 +137,8 @@ participated in, along with liquidation information.
type Account @entity {
"User address"
id: Bytes!
"User address"
address: Bytes!
"Pools the user is participating on"
pools: [AccountPool!]! @derivedFrom(field: "account")
"Count user has been liquidated"
Expand Down Expand Up @@ -238,6 +242,8 @@ An interface for rewards distributor that distribute rewards to isolated pools
type RewardsDistributor @entity {
"Address of the rewards distributor"
id: Bytes!
"Address of the rewards distributor"
address: Bytes!
"Address of the pool"
pool: Pool!
"Address of the reward token"
Expand Down
3 changes: 3 additions & 0 deletions subgraphs/isolated-pools/src/operations/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export function createPool(comptroller: Address): Pool {
const poolData = poolRegistryContract.getPoolByComptroller(comptroller);
const poolMetaData = poolRegistryContract.getVenusPoolMetadata(comptroller);

pool.address = comptroller;
pool.name = poolData.name;
pool.creator = poolData.creator;
pool.blockPosted = poolData.blockPosted;
Expand All @@ -75,6 +76,7 @@ export function createPool(comptroller: Address): Pool {

export function createAccount(accountAddress: Address): Account {
const account = new Account(accountAddress);
account.address = accountAddress;
account.countLiquidated = 0;
account.countLiquidator = 0;
account.hasBorrowed = false;
Expand Down Expand Up @@ -305,6 +307,7 @@ export const createRewardDistributor = (
const rewardToken = rewardDistributorContract.rewardToken();
const id = getRewardsDistributorId(rewardsDistributorAddress);
const rewardsDistributor = new RewardsDistributor(id);
rewardsDistributor.address = rewardsDistributorAddress;
rewardsDistributor.pool = comptrollerAddress;
rewardsDistributor.reward = rewardToken;
rewardsDistributor.save();
Expand Down
9 changes: 7 additions & 2 deletions subgraphs/venus/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ The Comptroller type has protocol level variables stored
type Comptroller @entity {
"ID is set to comptroller address"
id: Bytes!
"Comptroller Address"
address: Bytes!
"Address of price oracle the comptroller uses"
priceOracle: Bytes!
"Factor used to determine repayAmount for liquidating"
Expand All @@ -20,8 +22,9 @@ Market stores all high level variables for a vToken market
type Market @entity {
"VToken address"
id: Bytes!
"Vtoken Address"
address: Bytes!
"vToken decimal length"
#Fields that match Venus API
vTokenDecimals: Int!
"Name of the vToken"
name: String!
Expand Down Expand Up @@ -97,8 +100,10 @@ Account is an BNB address, with a list of all vToken markets the account has
participated in, along with liquidation information.
"""
type Account @entity {
"User BNB address"
"Account address"
id: Bytes!
"Account address"
address: Bytes!
"Array of VTokens user is in"
tokens: [MarketPosition!]! @derivedFrom(field: "account")
"Count user has been liquidated"
Expand Down
1 change: 1 addition & 0 deletions subgraphs/venus/src/mappings/comptroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { updateXvsSupplyState } from '../operations/updateXvsSupplyState';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function handleInitialization(block: ethereum.Block): void {
const comptroller = new Comptroller(comptrollerAddress);
comptroller.address = comptrollerAddress;
comptroller.priceOracle = nullAddress;
comptroller.closeFactorMantissa = zeroBigInt32;
comptroller.liquidationIncentive = zeroBigInt32;
Expand Down
2 changes: 2 additions & 0 deletions subgraphs/venus/src/operations/getOrCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function getOrCreateMarket(marketAddress: Address, event: ethereum.Event)
const vTokenContract = VToken.bind(marketAddress);
const comptrollerContract = Comptroller.bind(vTokenContract.comptroller());
market = new Market(marketAddress);
market.address = marketAddress;
market.isListed = true;
market.xvsBorrowStateBlock = event.block.number;
market.xvsSupplyStateBlock = event.block.number;
Expand Down Expand Up @@ -122,6 +123,7 @@ export function getOrCreateAccount(accountId: Bytes): Account {
let account = Account.load(accountId);
if (!account) {
account = new Account(accountId);
account.address = accountId;
account.countLiquidated = 0;
account.countLiquidator = 0;
account.hasBorrowed = false;
Expand Down

0 comments on commit 76918c0

Please sign in to comment.