From 798e573c782c6950c4a4f2d0b0dbd2311ea5d14e Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 15 Feb 2023 11:17:01 +0100 Subject: [PATCH] add Sepolia and Goerli provider --- apps/remix-ide/src/app.js | 6 ++++ .../app/providers/goerli-vm-fork-provider.tsx | 29 +++++++++++++++++++ .../providers/sepolia-vm-fork-provider.tsx | 29 +++++++++++++++++++ apps/remix-ide/src/app/udapp/run-tab.js | 2 ++ libs/remix-simulator/src/genesis.ts | 7 ++++- 5 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 apps/remix-ide/src/app/providers/goerli-vm-fork-provider.tsx create mode 100644 apps/remix-ide/src/app/providers/sepolia-vm-fork-provider.tsx diff --git a/apps/remix-ide/src/app.js b/apps/remix-ide/src/app.js index 403de27733..635d377246 100644 --- a/apps/remix-ide/src/app.js +++ b/apps/remix-ide/src/app.js @@ -29,6 +29,8 @@ import { NotificationPlugin } from './app/plugins/notification' import { Blockchain } from './blockchain/blockchain.js' import { BerlinVMProvider, LondonVMProvider } from './app/providers/vm-provider' import { MainnetForkVMProvider } from './app/providers/mainnet-vm-fork-provider' +import { SepoliaForkVMProvider } from './app/providers/sepolia-vm-fork-provider' +import { GoerliForkVMProvider } from './app/providers/goerli-vm-fork-provider' import { CustomForkVMProvider } from './app/providers/custom-vm-fork-provider' import { HardhatProvider } from './app/providers/hardhat-provider' import { GanacheProvider } from './app/providers/ganache-provider' @@ -207,6 +209,8 @@ class AppComponent { const web3Provider = new Web3ProviderModule(blockchain) const vmProviderCustomFork = new CustomForkVMProvider(blockchain) const vmProviderMainnetFork = new MainnetForkVMProvider(blockchain) + const vmProviderSepoliaFork = new SepoliaForkVMProvider(blockchain) + const vmProviderGoerliFork = new GoerliForkVMProvider(blockchain) const vmProviderBerlin = new BerlinVMProvider(blockchain) const vmProviderLondon = new LondonVMProvider(blockchain) const hardhatProvider = new HardhatProvider(blockchain) @@ -277,6 +281,8 @@ class AppComponent { storagePlugin, vmProviderBerlin, vmProviderLondon, + vmProviderSepoliaFork, + vmProviderGoerliFork, vmProviderMainnetFork, vmProviderCustomFork, hardhatProvider, diff --git a/apps/remix-ide/src/app/providers/goerli-vm-fork-provider.tsx b/apps/remix-ide/src/app/providers/goerli-vm-fork-provider.tsx new file mode 100644 index 0000000000..8de9aa832a --- /dev/null +++ b/apps/remix-ide/src/app/providers/goerli-vm-fork-provider.tsx @@ -0,0 +1,29 @@ +import * as packageJson from '../../../../../package.json' +import { BasicVMProvider } from './vm-provider' + +export class GoerliForkVMProvider extends BasicVMProvider { + nodeUrl: string + blockNumber: number | 'latest' + constructor (blockchain) { + super({ + name: 'vm-goerli-fork', + displayName: 'Goerli fork - Remix VM (London)', + kind: 'provider', + description: 'Remix VM (London)', + methods: ['sendAsync', 'init'], + version: packageJson.version + }, blockchain) + this.blockchain = blockchain + this.fork = 'merge' + this.nodeUrl = 'https://remix-sepolia.ethdevops.io' + this.blockNumber = 'latest' + } + + async init () { + return { + 'fork': this.fork, + 'nodeUrl': this.nodeUrl, + 'blockNumber': this.blockNumber + } + } +} diff --git a/apps/remix-ide/src/app/providers/sepolia-vm-fork-provider.tsx b/apps/remix-ide/src/app/providers/sepolia-vm-fork-provider.tsx new file mode 100644 index 0000000000..9f3fa374ae --- /dev/null +++ b/apps/remix-ide/src/app/providers/sepolia-vm-fork-provider.tsx @@ -0,0 +1,29 @@ +import * as packageJson from '../../../../../package.json' +import { BasicVMProvider } from './vm-provider' + +export class SepoliaForkVMProvider extends BasicVMProvider { + nodeUrl: string + blockNumber: number | 'latest' + constructor (blockchain) { + super({ + name: 'vm-sepolia-fork', + displayName: 'Sepolia fork - Remix VM (London)', + kind: 'provider', + description: 'Remix VM (London)', + methods: ['sendAsync', 'init'], + version: packageJson.version + }, blockchain) + this.blockchain = blockchain + this.fork = 'merge' + this.nodeUrl = 'https://remix-sepolia.ethdevops.io' + this.blockNumber = 'latest' + } + + async init () { + return { + 'fork': this.fork, + 'nodeUrl': this.nodeUrl, + 'blockNumber': this.blockNumber + } + } +} diff --git a/apps/remix-ide/src/app/udapp/run-tab.js b/apps/remix-ide/src/app/udapp/run-tab.js index 869e600170..00a49c4308 100644 --- a/apps/remix-ide/src/app/udapp/run-tab.js +++ b/apps/remix-ide/src/app/udapp/run-tab.js @@ -136,6 +136,8 @@ export class RunTab extends ViewPlugin { await addProvider('vm-london', 'Remix VM (London)', false, true, 'london', 'settingsVMLondonMode', titleVM) await addProvider('vm-berlin', 'Remix VM (Berlin)', false, true, 'berlin', 'settingsVMBerlinMode', titleVM) await addProvider('vm-mainnet-fork', 'Remix VM - Mainnet fork', false, true, 'london', 'settingsVMMainnetMode', titleVM) + await addProvider('vm-sepolia-fork', 'Remix VM - Sepolia fork', false, true, '', 'settingsVMSepoliaMode', titleVM) + await addProvider('vm-goerli-fork', 'Remix VM - Goerli fork', false, true, '', 'settingsVMGoerliMode', titleVM) await addProvider('vm-custom-fork', 'Remix VM - Custom fork', false, true, '', 'settingsVMCustomMode', titleVM) // external provider diff --git a/libs/remix-simulator/src/genesis.ts b/libs/remix-simulator/src/genesis.ts index e62e4e4432..a17ea904c2 100644 --- a/libs/remix-simulator/src/genesis.ts +++ b/libs/remix-simulator/src/genesis.ts @@ -1,13 +1,18 @@ import { Block } from '@ethereumjs/block' +import { ConsensusType } from '@ethereumjs/common' export function generateBlock (vmContext) { + const common = vmContext.vmObject().common + + const difficulty = common.consensusType() === ConsensusType.ProofOfStake ? 0 : 69762765929000 + return new Promise((resolve, reject) => { const block: Block = Block.fromBlockData({ header: { timestamp: (new Date().getTime() / 1000 | 0), number: 0, coinbase: '0x0e9281e9c6a0808672eaba6bd1220e144c9bb07a', - difficulty: 69762765929000, + difficulty, gasLimit: 8000000 } }, { common: vmContext.vmObject().common })