Skip to content

Commit

Permalink
fix: use try_function (#598)
Browse files Browse the repository at this point in the history
* fix: use try_function

* Fix: update node version in subgraph test flow

* fix: upgrade node version
  • Loading branch information
Rekard0 authored May 29, 2024
1 parent 973bef6 commit a543127
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/subgraph-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
uses: actions/setup-node@v3
with:
cache: 'yarn'
node-version: 16
node-version: 18
- name: Install dependencies
run: yarn install --pure-lockfile
- name: Build manifest
Expand All @@ -56,7 +56,7 @@ jobs:
uses: actions/setup-node@v3
with:
cache: 'yarn'
node-version: 16
node-version: 18
- name: Install dependencies
run: yarn
- name: Build contracts
Expand Down
23 changes: 16 additions & 7 deletions packages/subgraph/src/packages/token/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ export function getDelegation(
tokenAddress: Address
): string | null {
let contract = GovernanceERC20Contract.bind(tokenAddress);
let delegate = contract.delegates(user);
let delegate = contract.try_delegates(user);

return delegate === Address.fromString(ADDRESS_ZERO)
? null
: delegate.toHexString();
if (!delegate.reverted) {
return delegate.value === Address.fromString(ADDRESS_ZERO)
? null
: delegate.value.toHexString();
}
return null;
}

export function getDelegateeId(
Expand All @@ -36,10 +39,16 @@ export function getDelegateeId(
: null;
}

export function getVotingPower(user: Address, tokenAddress: Address): BigInt {
export function getVotingPower(
user: Address,
tokenAddress: Address
): BigInt | null {
let contract = GovernanceERC20Contract.bind(tokenAddress);
let votingPower = contract.getVotes(user);
return votingPower;
let votingPower = contract.try_getVotes(user);
if (!votingPower.reverted) {
return votingPower.value;
}
return null;
}

/**
Expand Down

0 comments on commit a543127

Please sign in to comment.