Skip to content

Commit

Permalink
refactor: account for isTimeBased reverting
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Dec 13, 2024
1 parent 4bdb63f commit 5256d28
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions subgraphs/isolated-pools/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ type RewardsDistributor @entity {
rewardTokenAddress: Bytes!
"Distribution rate for suppliers"
marketRewards: [MarketReward!]! @derivedFrom(field:"rewardsDistributor")
"Depending on the Chain, the rewards distributor is time based or block based"
isTimeBased: Boolean!
}

Expand Down
5 changes: 4 additions & 1 deletion subgraphs/isolated-pools/src/operations/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
getRewardsDistributorId,
getTransactionEventId,
} from '../utilities/ids';
import valueOrFalseIfReverted from '../utilities/valueOrFalseIfReverted';

export function createPool(comptroller: Address): Pool {
const pool = new Pool(getPoolId(comptroller));
Expand Down Expand Up @@ -311,7 +312,9 @@ export function createRewardDistributor(
rewardsDistributor.address = rewardsDistributorAddress;
rewardsDistributor.pool = comptrollerAddress;
rewardsDistributor.rewardTokenAddress = rewardToken;
rewardsDistributor.isTimeBased = rewardDistributorContract.isTimeBased();
rewardsDistributor.isTimeBased = valueOrFalseIfReverted(
rewardDistributorContract.try_isTimeBased(),
);
rewardsDistributor.save();

// we get the current speeds for all known markets at this point in time
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ethereum } from '@graphprotocol/graph-ts';

// checks if a call reverted, in case it is we return -1 to indicate the wanted value is not available
function valueOrFalseIfReverted(callResult: ethereum.CallResult<boolean>): boolean {
return callResult.reverted ? false : callResult.value;
}

export default valueOrFalseIfReverted;

0 comments on commit 5256d28

Please sign in to comment.