Skip to content

Commit

Permalink
fetch all vaults and filter on funded
Browse files Browse the repository at this point in the history
  • Loading branch information
sosaucily committed May 3, 2024
1 parent cc6d563 commit 21e683b
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/app/hooks/use-ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,21 @@ 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 numFetched = 0;
let fundedVaults: RawVault[] = [];
let fetchedVaults: RawVault[] = [];
do {
fetchedVaults = await dlcManagerContract.getAllDLCs(numFetched, numFetched + numToFetch);
fundedVaults = fundedVaults.concat(
fetchedVaults.filter(vault => vault.status == FUNDED_STATUS)
);
numFetched += numToFetch;
} while (fetchedVaults.length == numToFetch);
return fundedVaults;
} catch (error) {
throw new EthereumError(`Could not fetch Funded Vaults: ${error}`);
}
Expand Down

0 comments on commit 21e683b

Please sign in to comment.