Skip to content

Commit

Permalink
fetch all vaults and filter on funded (#93)
Browse files Browse the repository at this point in the history
* feat: fetch all vaults and filter on funded

* feat: cleanup function
  • Loading branch information
sosaucily authored May 3, 2024
1 parent cc6d563 commit 7d0758e
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/app/hooks/use-ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,23 @@ export function useEthereum(): UseEthereumReturnType {
}

async function getAllFundedVaults(ethereumNetwork: EthereumNetwork): Promise<RawVault[]> {
const FUNDED_STATUS = 1;
try {
const dlcManagerContract = await getDefaultProvider(ethereumNetwork, 'DLCManager');
const vaults: RawVault[] = await dlcManagerContract.getFundedDLCs(0, 10000);
const filteredVaults = vaults.filter(
vault => vault.uuid != '0x0000000000000000000000000000000000000000000000000000000000000000'
);
return filteredVaults;
const numToFetch = 50;
let totalFetched = 0;
const fundedVaults: RawVault[] = [];
// eslint-disable-next-line no-constant-condition
while (true) {
const fetchedVaults: RawVault[] = await dlcManagerContract.getAllDLCs(
totalFetched,
totalFetched + numToFetch
);
fundedVaults.push(...fetchedVaults.filter(vault => vault.status === FUNDED_STATUS));
totalFetched += numToFetch;
if (fetchedVaults.length !== numToFetch) break;
}
return fundedVaults;
} catch (error) {
throw new EthereumError(`Could not fetch Funded Vaults: ${error}`);
}
Expand Down

0 comments on commit 7d0758e

Please sign in to comment.