Skip to content

Commit

Permalink
refactor: maintain pattern of one utility per file
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Jan 29, 2024
1 parent 84788c3 commit 43cbffa
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 36 deletions.
8 changes: 4 additions & 4 deletions subgraphs/venus/src/operations/getOrCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import { BEP20 } from '../../generated/templates/VToken/BEP20';
import { VToken } from '../../generated/templates/VToken/VToken';
import { zeroBigInt32 } from '../constants';
import { comptrollerAddress, nullAddress } from '../constants/addresses';
import { exponentToBigInt } from '../utilities/exponentToBigInt';
import { getUnderlyingPrice } from '../utilities/getUnderlyingPrice';
import { getAccountVTokenId, getAccountVTokenTransactionId } from '../utilities/ids';
import {
valueOrNotAvailableAddressIfReverted,
valueOrNotAvailableIntIfReverted,
} from '../utilities/valueOrNotAvailableIfReverted';
} from '../utilities';
import { exponentToBigInt } from '../utilities/exponentToBigInt';
import { getUnderlyingPrice } from '../utilities/getUnderlyingPrice';
import { getAccountVTokenId, getAccountVTokenTransactionId } from '../utilities/ids';
import { getMarket } from './get';

export function getOrCreateComptroller(): Comptroller {
Expand Down
6 changes: 2 additions & 4 deletions subgraphs/venus/src/utilities/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export { getTokenPriceCents } from './getTokenPriceCents';
export { exponentToBigDecimal } from './exponentToBigDecimal';
export { getUnderlyingPrice } from './getUnderlyingPrice';
export {
valueOrNotAvailableIntIfReverted,
valueOrNotAvailableAddressIfReverted,
} from './valueOrNotAvailableIfReverted';
export { valueOrNotAvailableAddressIfReverted } from './valueOrNotAvailableAddressIfReverted';
export { valueOrNotAvailableIntIfReverted } from './valueOrNotAvailableIntIfReverted';
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Address, ethereum, log } from '@graphprotocol/graph-ts';

import { nullAddress } from '../constants/addresses';

// checks if a call reverted, in case it is we return 0x000.. to indicate the wanted value is not available
export function valueOrNotAvailableAddressIfReverted(
callResult: ethereum.CallResult<Address>,
callName: string,
): Address {
if (callResult.reverted) {
log.error('***CALL FAILED*** : {} reverted', [callName]);
return nullAddress;
}
return callResult.value;
}
28 changes: 0 additions & 28 deletions subgraphs/venus/src/utilities/valueOrNotAvailableIfReverted.ts

This file was deleted.

18 changes: 18 additions & 0 deletions subgraphs/venus/src/utilities/valueOrNotAvailableIntIfReverted.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { BigInt, ethereum, log } from '@graphprotocol/graph-ts';

import { NOT_AVAILABLE_BIG_INT } from '../constants';

// checks if a call reverted, in case it is we return -1 to indicate the wanted value is not available
// checks if a call reverted, in case it is we return -1 to indicate the wanted value is not available
export function valueOrNotAvailableIntIfReverted(
callResult: ethereum.CallResult<BigInt>,
callName: string,
): BigInt {
if (callResult.reverted) {
log.error('***CALL FAILED*** : {} reverted', [callName]);
return NOT_AVAILABLE_BIG_INT;
}
return callResult.value;
}

export default valueOrNotAvailableIntIfReverted;

0 comments on commit 43cbffa

Please sign in to comment.