-
-
Notifications
You must be signed in to change notification settings - Fork 6
Olu/enable ppom on more networks #90
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
Open
segun
wants to merge
4
commits into
main
Choose a base branch
from
olu/send-ppom-on-more-networks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,7 +51,15 @@ const ALLOWED_PROVIDER_CALLS = [ | |
| 'trace_filter', | ||
| ]; | ||
|
|
||
| const ETHEREUM_CHAIN_ID = '0x1'; | ||
| export const SUPPORTED_CHAIN_IDS = [ | ||
| '0x1', // ethereum mainnet chain id | ||
| '0x38', // bnb chain id | ||
| '0x89', // polygon chain id | ||
| '0xa4b1', // arbitrum chain id | ||
| '0xa', // optimism chain id | ||
| '0xa86a', // avalanche chain id | ||
| '0xe708', // Linea chain id | ||
| ]; | ||
|
|
||
| /** | ||
| * @type PPOMFileVersion | ||
|
|
@@ -321,7 +329,7 @@ export class PPOMController extends BaseControllerV2< | |
| if (securityAlertsEnabled) { | ||
| this.#updateVersionInfo() | ||
| .then(async () => { | ||
| await this.#getNewFilesForChain(ETHEREUM_CHAIN_ID); | ||
| await this.#getNewFilesForChain(this.#chainId); | ||
| // start scheduled task to fetch data files | ||
| this.#checkScheduleFileDownloadForAllChains(); | ||
| }) | ||
|
|
@@ -361,7 +369,7 @@ export class PPOMController extends BaseControllerV2< | |
| throw Error('User has securityAlertsEnabled set to false'); | ||
| } | ||
| if (!this.#networkIsSupported(this.#chainId)) { | ||
| throw Error('Blockaid validation is available only on ethereum mainnet'); | ||
| throw Error('Blockaid validation is not available on selected network'); | ||
| } | ||
|
|
||
| await this.#reinitPPOMForNetworkIfRequired(); | ||
|
|
@@ -407,11 +415,10 @@ export class PPOMController extends BaseControllerV2< | |
| } | ||
|
|
||
| /* | ||
| * The function check if ethereum chainId is supported for validation | ||
| * Currently it checks for only Ethereum Mainnet but it will include more networks in future. | ||
| * The function check if chainId is supported for validation | ||
| */ | ||
| #networkIsSupported(chainId: string) { | ||
| return chainId === ETHEREUM_CHAIN_ID; | ||
| return SUPPORTED_CHAIN_IDS.includes(chainId); | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -494,7 +501,7 @@ export class PPOMController extends BaseControllerV2< | |
| this.#updateVersionInfo() | ||
| .then(async () => { | ||
| this.#checkScheduleFileDownloadForAllChains(); | ||
| await this.#getNewFilesForChain(ETHEREUM_CHAIN_ID); | ||
| await this.#getNewFilesForChain(this.#chainId); | ||
| }) | ||
| .catch((error: Error) => { | ||
| console.error(`Error in initialising: ${error.message}`); | ||
|
|
@@ -774,8 +781,9 @@ export class PPOMController extends BaseControllerV2< | |
| const currentTimestamp = new Date().getTime(); | ||
|
|
||
| const chainIds = Object.keys(this.state.chainStatus).filter( | ||
| (id) => id !== ETHEREUM_CHAIN_ID, | ||
| (id) => id !== this.#chainId, | ||
| ); | ||
|
|
||
| const oldChaninIds: any[] = chainIds.filter( | ||
| (chainId) => | ||
| (this.state.chainStatus[chainId] as any).lastVisited < | ||
|
|
@@ -843,8 +851,8 @@ export class PPOMController extends BaseControllerV2< | |
| if (isLastFileOfNetwork) { | ||
| // if this was last file for the chainId set dataFetched for chainId to true | ||
| await this.#setChainIdDataFetched(fileVersionInfo.chainId); | ||
| if (fileVersionInfo.chainId === ETHEREUM_CHAIN_ID) { | ||
| await this.#reinitPPOM(ETHEREUM_CHAIN_ID); | ||
| if (fileVersionInfo.chainId === this.#chainId) { | ||
| await this.#reinitPPOM(this.#chainId); | ||
| } | ||
| } | ||
| }) | ||
|
|
@@ -1000,9 +1008,10 @@ export class PPOMController extends BaseControllerV2< | |
| // thus it is added here to prevent validation from failing. | ||
| await this.#initialisePPOM(); | ||
| const { chainStatus } = this.state; | ||
| const versionInfo = | ||
| chainStatus[chainId]?.versionInfo ?? | ||
| this.state.versionInfo.filter(({ chainId: id }) => id === chainId); | ||
| const hasVersionInfo = chainStatus[chainId]?.versionInfo?.length; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed this part wasn't been called in tests because chainStatus[chainId]?.versionInfo is usually [] not undefined/null. So this check makes sure it works either it's undefined, null or [] |
||
| const versionInfo = hasVersionInfo | ||
| ? chainStatus[chainId]?.versionInfo | ||
| : this.state.versionInfo.filter(({ chainId: id }) => id === chainId); | ||
| if (!versionInfo?.length) { | ||
| this.#ppomInitError = `Aborting validation as no files are found for the network with chainId: ${chainId}`; | ||
| return undefined; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed to add one more because the condition in ppomController for this check to happen is > 5. It doesn't do the check if its <= 5