Skip to content

Commit

Permalink
fix: init offchain service (#1533)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReflectiveChimp authored Aug 12, 2024
1 parent 99a3109 commit 70b87a8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/api/offchain-rewards/providers/merkl/MerklProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { isUnixBetween } from '../../../../utils/date';
import { getJson } from '../../../../utils/http';

const providerId = 'merkl' as const;
const throwIfNoData: boolean = false; // whether to throw if "{}" is returned
const supportedChains = new Set<AppChain>([
'ethereum',
'polygon',
Expand Down Expand Up @@ -162,10 +163,21 @@ export class MerklProvider implements IOffchainRewardProvider {
providerId
);
}

if (Object.keys(data).length === 0) {
if (throwIfNoData) {
throw new ProviderApiError(
`fetchCampaignsForChain(${chainId}): no data returned`,
providerId
);
}
return {};
}

const dataForChain = data[numericChainId];
if (!dataForChain) {
throw new ProviderApiError(
`fetchCampaignsForChain(${chainId}): no data returned`,
`fetchCampaignsForChain(${chainId}): no data for chain returned`,
providerId
);
}
Expand Down
12 changes: 11 additions & 1 deletion src/api/stats/getChainTvl.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { get } from 'lodash';
import { ChainId } from '../../../packages/address-book/src/address-book';
const BigNumber = require('bignumber.js');
import { fetchPrice } from '../../utils/fetchPrice';
Expand Down Expand Up @@ -101,6 +100,9 @@ const setVaultsTvl = async (vaults, balances, chainId, tvls) => {
};

const getVaultBalances = async (chainId, vaults) => {
if (!vaults) {
throw new Error(`getVaultBalances: undefined vaults passed for ${chainId}`);
}
const calls = vaults.map(vault => {
const contract = fetchContract(vault.earnedTokenAddress, BeefyVaultV6Abi, chainId);
return contract.read.balance();
Expand All @@ -110,6 +112,10 @@ const getVaultBalances = async (chainId, vaults) => {
};

const getGovVaultBalances = async (chainId, govPools) => {
if (!govPools) {
throw new Error(`getGovVaultBalances: undefined govPools passed for ${chainId}`);
}

const calls = govPools.map(vault => {
const tokenContract = fetchContract(vault.tokenAddress, ERC20Abi, chainId);
return tokenContract.read.balanceOf([vault.earnContractAddress]);
Expand All @@ -120,6 +126,10 @@ const getGovVaultBalances = async (chainId, govPools) => {
};

const getCowVaultBalances = async (chainId, cowVaults) => {
if (!cowVaults) {
throw new Error(`getCowVaultBalances: undefined cowVaults passed for ${chainId}`);
}

const calls = cowVaults.map(vault => {
const tokenContract = fetchContract(vault.earnContractAddress, ERC20Abi, chainId);
return tokenContract.read.totalSupply();
Expand Down
2 changes: 2 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { initZapSwapService } from './api/zap/swap';
import { initValidatorPerformanceService } from './api/validators/validators';
import { initArticlesService } from './api/articles/fetchArticlesData';
import { initCowcentratedService } from './api/cowcentrated';
import { initOffchainRewardsService } from './api/offchain-rewards';

const Koa = require('koa');
const helmet = require('koa-helmet');
Expand Down Expand Up @@ -65,6 +66,7 @@ const start = async () => {
initArticlesService();
initZapSwapService();
initCowcentratedService();
initOffchainRewardsService();

app.listen(port);
console.log(`> beefy-api running! (:${port})`);
Expand Down

0 comments on commit 70b87a8

Please sign in to comment.