Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provider errors #858

Merged
merged 4 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions modules/delegates/helpers/formatDelegationHistoryChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ export const formatDelegationHistoryChart = (

const years = differenceInCalendarYears(Date.now(), new Date(lockEvents[0].blockTimestamp));

const end =
years * 365 +
formatIsoDateConversion((new Date()).toISOString());
const end = years * 365 + formatIsoDateConversion(new Date().toISOString());

const output: MKRWeightHisory[] = [];

Expand Down
4 changes: 2 additions & 2 deletions modules/executive/api/fetchExecutiveVoteTally.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export async function fetchExecutiveVoteTally(chief: Chief): Promise<any | null>
}
});

// We need to split the voters array into chunks of 1000 addresses because our
// We need to split the voters array into chunks because our
// Alchemy key doesn't support batch requests larger than 1000 queries each
const chunkSize = 1000;
const chunkSize = 900;
const voterChunks = Array.from({ length: Math.ceil(voters.length / chunkSize) }, (_, i) =>
voters.slice(i * chunkSize, i * chunkSize + chunkSize)
);
Expand Down
12 changes: 6 additions & 6 deletions modules/polling/components/PollWinningOptionBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ export default function PollWinningOptionBox({
isDefault = true;
}

// Winner will be null if the winning conditions are not met, but we want to display the leading option too
const leadingOption = typeof tally.winner === 'number' ? tally.winner : tally.results[0].optionId;
const leadingOptionName = `${
typeof tally.winner === 'number' ? tally.winningOptionName : tally.results[0].optionName
//don't show "& n more" if isDefault since there's only ever 1 default option
}${!isDefault && numberOfLeadingOptions > 1 ? ` & ${numberOfLeadingOptions - 1} more` : ''}`;
// Winner will be null if the winning conditions are not met, but we want to display the leading option too
const leadingOption = typeof tally.winner === 'number' ? tally.winner : tally.results[0].optionId;
const leadingOptionName = `${
typeof tally.winner === 'number' ? tally.winningOptionName : tally.results[0].optionName
//don't show "& n more" if isDefault since there's only ever 1 default option
}${!isDefault && numberOfLeadingOptions > 1 ? ` & ${numberOfLeadingOptions - 1} more` : ''}`;

return (
<Flex sx={{ py: 2, justifyContent: 'center' }}>
Expand Down
26 changes: 25 additions & 1 deletion modules/tags/constants/poll-tags-mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -1042,5 +1042,29 @@
"1064": ["high-impact", "risk-parameter", "spark"],
"1065": ["high-impact", "spark"],
"1066": ["medium-impact", "spark"],
"1067": ["high-impact", "risk-parameter", "spark"]
"1067": ["high-impact", "risk-parameter", "spark"],
"1068": ["high-impact", "risk-parameter", "spark"],
"1069": ["high-impact", "spark"],
"1070": ["high-impact", "oracle", "spark"],
"1071": ["medium-impact", "risk-parameter", "auctions"],
"1072": ["high-impact", "ratification", "mips", "endgame"],
"1073": ["high-impact", "ratification", "mips", "endgame"],
"1074": ["high-impact", "ratification", "mips", "endgame"],
"1075": ["high-impact", "ratification", "mips", "endgame"],
"1076": ["high-impact", "risk-parameter", "spark"],
"1077": ["medium-impact", "risk-parameter"],
"1078": ["medium-impact", "risk-parameter"],
"1080": ["high-impact", "risk-parameter", "spark"],
"1081": ["high-impact", "risk-parameter", "spark"],
"1082": ["high-impact", "risk-parameter", "spark"],
"1083": ["high-impact", "risk-parameter"],
"1084": ["high-impact", "risk-parameter", "endgame", "d3m", "spark"],
"1085": ["high-impact", "risk-parameter", "endgame", "spark"],
"1086": ["medium-impact", "misc-governance", "endgame"],
"1087": ["high-impact", "ratification", "mips"],
"1088": ["high-impact", "mips"],
"1089": ["high-impact", "risk-parameter"],
"1090": ["high-impact", "spark"],
"1091": ["high-impact", "spark"],
"1092": ["high-impact", "spark"]
}
2 changes: 1 addition & 1 deletion modules/web3/helpers/getContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const getContracts = (

// If our account or network changes, recreate the contracts SDK
if (changeAccount || changeNetwork || !contracts || (needsSigner && !hasSigner(contracts))) {
const providerToUse = provider ?? getDefaultProvider(rpcUrl);
const providerToUse = provider ?? getDefaultProvider(network);

const signerOrProvider = needsSigner
? (providerToUse as providers.Web3Provider).getSigner(account)
Expand Down
27 changes: 15 additions & 12 deletions modules/web3/helpers/getDefaultProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ import { ethers, providers } from 'ethers';
ethers.utils.Logger.setLogLevel(ethers.utils.Logger.levels.ERROR);

export const getDefaultProvider = (
network: SupportedNetworks | string | undefined,
optionsOverrides?: Record<string, string>
): providers.BaseProvider => {
const options = {
infura: config.INFURA_KEY,
alchemy: config.ALCHEMY_KEY,
pocket: config.POCKET_KEY,
etherscan: config.ETHERSCAN_KEY,
...(optionsOverrides || {})
network: SupportedNetworks | string | undefined
): providers.FallbackProvider => {
const infuraProvider = new ethers.providers.InfuraProvider(network, config.INFURA_KEY);
const alchemyProvider = new ethers.providers.AlchemyProvider(network, config.ALCHEMY_KEY);
const pocketProvider = new ethers.providers.PocketProvider(network, config.POCKET_KEY);
const etherscanProvider = new ethers.providers.EtherscanProvider(network, config.ETHERSCAN_KEY);

const provider = new ethers.providers.FallbackProvider([
{ provider: infuraProvider, priority: 2 },
{ provider: alchemyProvider, priority: 1 },
{ provider: pocketProvider, priority: 3 },
{ provider: etherscanProvider, priority: 3 }
], 1); //Quorum of 1
Comment on lines +23 to +28

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, so this will always try alchemy first, and if it is successful then we're good, right?


return provider;
};

return ethers.getDefaultProvider(network, options);
};
4 changes: 3 additions & 1 deletion modules/web3/helpers/getEthersContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { getRPCFromChainID } from './getRPC';
import { chainIdToNetworkName } from './chain';
import { SupportedChainId } from '../constants/chainID';
import { Contract, ethers, providers } from 'ethers';
import { DEFAULT_NETWORK } from '../constants/networks';
Expand All @@ -21,8 +22,9 @@ export const getEthersContracts = <T extends Contract>(
readOnly?: boolean
): T => {
const rcpUrl = getRPCFromChainID(chainId ?? DEFAULT_NETWORK.chainId);
const network = chainIdToNetworkName(chainId ?? DEFAULT_NETWORK.chainId);

const providerToUse = readOnly ? new providers.JsonRpcBatchProvider(rcpUrl) : getDefaultProvider(rcpUrl);
const providerToUse = readOnly ? new providers.JsonRpcBatchProvider(rcpUrl) : getDefaultProvider(network);

const signerOrProvider =
account && provider
Expand Down
Loading