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

fix: do not throw when no env is found #29

Merged
merged 6 commits into from
Nov 21, 2024
Merged

fix: do not throw when no env is found #29

merged 6 commits into from
Nov 21, 2024

Conversation

sakulstra
Copy link
Contributor

@sakulstra sakulstra commented Nov 21, 2024

Throwing when no env is found is more problematic then I thought.

If we have a .env with public RPCs and we read it before invoking the action, we'll end up using public rpcs instead of our private ones, which is suboptimal.

If we invoke the action after invoking the action, the action will revert on fork prs, because no secrets are exposed there (neither alchemy key, nor RPC_).


Not reverting is the only option on the action level and even inside ts, seems more optimal to fall-trough.

@sakulstra
Copy link
Contributor Author

accidentally leaked env in first commit :/ revoked the key

@@ -29,19 +26,16 @@ import {

export const ChainId = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

goerlies are dead, but some we are using were missing

dist/action.js Show resolved Hide resolved
@@ -18,6 +18,7 @@
"dist/lib.js",
"dist/lib.mjs"
],
"bin": "./dist/cli.js",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

adding cli bin so you can emit the env etc

getRPCUrl,
} from "./lib";

Object.keys(process.env).map((key) => delete process.env[key]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i accidentally leaked the alchemy api key when updating the snapshots without noticing.
Running this before creating the snapshots, makes sure to cleanup the env.

@@ -1,11 +1,13 @@
import { networkMap } from "./alchemyIds";
import { ChainId } from "./chainIds";

type SupportedChainIds = (typeof ChainId)[keyof typeof ChainId] &
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a bit wrong.

SupportedChains was limited to "supported chains by alchemy", but it should be limited by supported chains by ChainId

@@ -24,38 +26,69 @@ export const getNetworkEnv = (chainId: SupportedChainIds) => {
return env;
};

export function getExplicitRPC(chainId: SupportedChainIds) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

added explicit getters that throw - if you want alchemy and you can't get it i guess that is reasonable.

export const getRPCUrl = (chainId: SupportedChainIds, alchemyKey?: string) => {
export const getRPCUrl = (
chainId: SupportedChainIds,
options?: GetRPCUrlOptions,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to object, so we can add quicknode & drpc without introducing a breaking change.

/**
* Return a RPC_URL for supported chains.
* If the RPC_URL environment variable is set, it will be used.
* Otherwise will construct the URL based on the chain ID and Alchemy API key.
*
* @notice This method acts as fall-through and will only revert if the ChainId is strictly not supported.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's just easier to use in practice as right now what we do is fetch & catch & call with undefined - so as tools like viem have an internal fallback. Also makes the action behavior more reasonable.

@sakulstra sakulstra merged commit dd8b6f8 into main Nov 21, 2024
1 check passed
@sakulstra sakulstra deleted the patch/dont-throw branch November 21, 2024 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants