Skip to content

Commit

Permalink
Merge pull request #103 from VenusProtocol/refactor/get-pool-by-compt…
Browse files Browse the repository at this point in the history
…roller

refactor: remove try from getPoolByComptroller
  • Loading branch information
coreyar authored Aug 9, 2023
2 parents e309ae9 + aaf2f26 commit 802ebbd
Showing 1 changed file with 21 additions and 31 deletions.
52 changes: 21 additions & 31 deletions subgraphs/isolated-pools/src/operations/create.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, BigInt, log } from '@graphprotocol/graph-ts';
import { Address, BigInt } from '@graphprotocol/graph-ts';

import { PoolLens as PoolLensContract } from '../../generated/PoolRegistry/PoolLens';
import {
Expand Down Expand Up @@ -50,36 +50,26 @@ export function createPool(comptroller: Address): Pool {
const pool = new Pool(getPoolId(comptroller));
// Fill in pool from pool lens
const poolLensContract = PoolLensContract.bind(poolLensAddress);
const getPoolByComptrollerResult = poolLensContract.try_getPoolByComptroller(
poolRegistryAddress,
comptroller,
);

if (getPoolByComptrollerResult.reverted) {
log.error('Unable to fetch pool info for {} with lens {}', [
comptroller.toHexString(),
poolLensAddress.toHexString(),
]);
} else {
const poolDataFromLens = getPoolByComptrollerResult.value;
pool.name = poolDataFromLens.name;
pool.creator = poolDataFromLens.creator;
pool.blockPosted = poolDataFromLens.blockPosted;
pool.timestampPosted = poolDataFromLens.timestampPosted;
pool.category = poolDataFromLens.category;
pool.logoUrl = poolDataFromLens.logoURL;
pool.description = poolDataFromLens.description;
pool.priceOracleAddress = poolDataFromLens.priceOracle;
pool.closeFactorMantissa = poolDataFromLens.closeFactor
? poolDataFromLens.closeFactor
: new BigInt(0);
pool.minLiquidatableCollateralMantissa = poolDataFromLens.minLiquidatableCollateral;
pool.liquidationIncentiveMantissa = poolDataFromLens.liquidationIncentive
? poolDataFromLens.liquidationIncentive
: new BigInt(0);
// Note: we don't index vTokens here because when a pool is created it has no markets
pool.save();
}
const poolDataFromLens = poolLensContract.getPoolByComptroller(poolRegistryAddress, comptroller);

pool.name = poolDataFromLens.name;
pool.creator = poolDataFromLens.creator;
pool.blockPosted = poolDataFromLens.blockPosted;
pool.timestampPosted = poolDataFromLens.timestampPosted;
pool.category = poolDataFromLens.category;
pool.logoUrl = poolDataFromLens.logoURL;
pool.description = poolDataFromLens.description;
pool.priceOracleAddress = poolDataFromLens.priceOracle;
pool.closeFactorMantissa = poolDataFromLens.closeFactor
? poolDataFromLens.closeFactor
: new BigInt(0);
pool.minLiquidatableCollateralMantissa = poolDataFromLens.minLiquidatableCollateral;
pool.liquidationIncentiveMantissa = poolDataFromLens.liquidationIncentive
? poolDataFromLens.liquidationIncentive
: new BigInt(0);
// Note: we don't index vTokens here because when a pool is created it has no markets
pool.save();

return pool;
}

Expand Down

0 comments on commit 802ebbd

Please sign in to comment.