Skip to content

Commit

Permalink
add support for entrypoint v0.7 in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
code-z2 committed Feb 27, 2024
1 parent ad157be commit 6c8b22a
Show file tree
Hide file tree
Showing 15 changed files with 292 additions and 163 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.9

* Add support for entrypoint v0.7 in parrallel.

## 0.0.8

* Add paymaster as a plugin
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ const String rpcUrl = 'http://localhost:8545';
const String bundlerUrl = 'http://localhost:3000/rpc';
chain = Chain(
ethRpcUrl: rpcUrl,
jsonRpcUrl: rpcUrl,
bundlerUrl: bundlerUrl,
entrypoint: Constants.entrypoint,
entrypoint: EntryPoint.v06,
accountFactory: Constants.accountFactory,
chainId: 1337,
explorer: "");
// using pre configured chain
chain = Chains.getChain(Network.localhost)
..ethRpcUrl = rpcUrl
..jsonRpcUrl = rpcUrl
..bundlerUrl = bundlerUrl;
```

Expand Down
4 changes: 2 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ Future<void> main() async {

// configure your chain
final Chain chain = Chain(
ethRpcUrl: rpcUrl,
jsonRpcUrl: rpcUrl,
bundlerUrl: bundlerUrl,
entrypoint: Constants.entrypointv06,
entrypoint: EntryPoint.v06,
accountFactory:
EthereumAddress.fromHex("0xCCaE5F64307D86346B83E55e7865f77906F9c7b4"),
chainId: 1337,
Expand Down
112 changes: 62 additions & 50 deletions lib/src/4337/chains.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ part of '../../variance.dart';
class Chain {
final int chainId;
final String explorer;
final EthereumAddress entrypoint;
final EntryPoint entrypoint;
EthereumAddress? accountFactory;
String? ethRpcUrl;
String? jsonRpcUrl;
String? bundlerUrl;
String? paymasterUrl;

Expand All @@ -14,13 +14,13 @@ class Chain {
required this.explorer,
required this.entrypoint,
this.accountFactory,
this.ethRpcUrl,
this.jsonRpcUrl,
this.bundlerUrl,
this.paymasterUrl});

/// asserts that [ethRpcUrl] and [bundlerUrl] is provided
/// asserts that [jsonRpcUrl] and [bundlerUrl] is provided
Chain validate() {
require(isURL(ethRpcUrl),
require(isURL(jsonRpcUrl),
"Chain Config Error: please provide a valid eth rpc url");
require(isURL(bundlerUrl),
"Chain Config Error: please provide a valid bundler url");
Expand All @@ -36,134 +36,134 @@ class Chains {
Network.ethereum: Chain(
chainId: 1,
explorer: "https://etherscan.io/",
ethRpcUrl: "https://rpc.ankr.com/eth",
entrypoint: Constants.entrypointv06,
jsonRpcUrl: "https://rpc.ankr.com/eth",
entrypoint: EntryPoint.v06,
),
Network.polygon: Chain(
chainId: 137,
explorer: "https://polygonscan.com/",
ethRpcUrl: "https://polygon-rpc.com/",
entrypoint: Constants.entrypointv06,
jsonRpcUrl: "https://polygon-rpc.com/",
entrypoint: EntryPoint.v06,
),
Network.optimism: Chain(
chainId: 10,
explorer: "https://explorer.optimism.io",
ethRpcUrl: "https://mainnet.optimism.io",
entrypoint: Constants.entrypointv06,
jsonRpcUrl: "https://mainnet.optimism.io",
entrypoint: EntryPoint.v06,
),
Network.base: Chain(
chainId: 8453,
explorer: "https://basescan.org",
ethRpcUrl: "https://mainnet.base.org",
entrypoint: Constants.entrypointv06,
jsonRpcUrl: "https://mainnet.base.org",
entrypoint: EntryPoint.v06,
),
Network.arbitrumOne: Chain(
chainId: 42161,
explorer: "https://arbiscan.io/",
ethRpcUrl: "https://arb1.arbitrum.io/rpc",
entrypoint: Constants.entrypointv06,
jsonRpcUrl: "https://arb1.arbitrum.io/rpc",
entrypoint: EntryPoint.v06,
),
Network.mantle: Chain(
chainId: 5000,
explorer: "https://explorer.mantle.xyz/",
ethRpcUrl: "https://rpc.mantle.xyz/",
entrypoint: Constants.entrypointv06,
jsonRpcUrl: "https://rpc.mantle.xyz/",
entrypoint: EntryPoint.v06,
),
Network.linea: Chain(
chainId: 59144,
explorer: "https://lineascan.build/",
ethRpcUrl: "https://rpc.linea.build",
entrypoint: Constants.entrypointv06),
jsonRpcUrl: "https://rpc.linea.build",
entrypoint: EntryPoint.v06),
Network.avalanche: Chain(
chainId: 43114,
explorer: "https://snowtrace.io/",
ethRpcUrl: "https://api.avax.network/ext/bc/C/rpc",
entrypoint: Constants.entrypointv06,
jsonRpcUrl: "https://api.avax.network/ext/bc/C/rpc",
entrypoint: EntryPoint.v06,
),
Network.gnosis: Chain(
chainId: 100,
explorer: "https://gnosisscan.io/",
ethRpcUrl: "https://rpc.ankr.com/gnosis",
entrypoint: Constants.entrypointv06,
jsonRpcUrl: "https://rpc.ankr.com/gnosis",
entrypoint: EntryPoint.v06,
),
Network.celo: Chain(
chainId: 42220,
explorer: "https://celoscan.io/",
ethRpcUrl: "https://forno.celo.org",
entrypoint: Constants.entrypointv06,
jsonRpcUrl: "https://forno.celo.org",
entrypoint: EntryPoint.v06,
),
Network.fantom: Chain(
chainId: 250,
explorer: "https://ftmscan.com/",
ethRpcUrl: "https://rpc.fantom.network",
entrypoint: Constants.entrypointv06,
jsonRpcUrl: "https://rpc.fantom.network",
entrypoint: EntryPoint.v06,
),
Network.opBnB: Chain(
chainId: 204,
explorer: "http://opbnbscan.com/",
ethRpcUrl: "https://opbnb-mainnet-rpc.bnbchain.org",
entrypoint: Constants.entrypointv06,
jsonRpcUrl: "https://opbnb-mainnet-rpc.bnbchain.org",
entrypoint: EntryPoint.v06,
),
Network.arbitrumNova: Chain(
chainId: 42170,
explorer: "https://nova.arbiscan.io/",
ethRpcUrl: "https://nova.arbitrum.io/rpc",
entrypoint: Constants.entrypointv06,
jsonRpcUrl: "https://nova.arbitrum.io/rpc",
entrypoint: EntryPoint.v06,
),
Network.polygonzkEvm: Chain(
chainId: 1101,
explorer: "https://zkevm.polygonscan.com/",
ethRpcUrl: "https://polygonzkevm-mainnet.g.alchemy.com/v2/demo",
entrypoint: Constants.entrypointv06,
jsonRpcUrl: "https://polygonzkevm-mainnet.g.alchemy.com/v2/demo",
entrypoint: EntryPoint.v06,
),
Network.scroll: Chain(
chainId: 534352,
explorer: "https://scrollscan.com/",
ethRpcUrl: "https://rpc.scroll.io/",
entrypoint: Constants.entrypointv06,
jsonRpcUrl: "https://rpc.scroll.io/",
entrypoint: EntryPoint.v06,
),
Network.mode: Chain(
chainId: 34443,
explorer: "https://explorer.mode.network/",
ethRpcUrl: "https://mainnet.mode.network/",
entrypoint: Constants.entrypointv06,
jsonRpcUrl: "https://mainnet.mode.network/",
entrypoint: EntryPoint.v06,
),
Network.sepolia: Chain(
chainId: 11155111,
explorer: "https://sepolia.etherscan.io/",
ethRpcUrl: "https://rpc.sepolia.org",
entrypoint: Constants.entrypointv06,
jsonRpcUrl: "https://rpc.sepolia.org",
entrypoint: EntryPoint.v06,
),
Network.mumbai: Chain(
chainId: 80001,
explorer: "https://mumbai.polygonscan.com/",
ethRpcUrl: "https://rpc-mumbai.maticvigil.com/",
entrypoint: Constants.entrypointv06,
jsonRpcUrl: "https://rpc-mumbai.maticvigil.com/",
entrypoint: EntryPoint.v06,
),
Network.baseTestent: Chain(
chainId: 84531,
explorer: "https://sepolia.basescan.org",
ethRpcUrl: "https://api-sepolia.basescan.org/api",
entrypoint: Constants.entrypointv06,
jsonRpcUrl: "https://api-sepolia.basescan.org/api",
entrypoint: EntryPoint.v06,
),
Network.fuji: Chain(
chainId: 43113,
explorer: "https://testnet.snowtrace.io/",
ethRpcUrl: "https://api.avax-test.network/ext/bc/C/rpc",
entrypoint: Constants.entrypointv06,
jsonRpcUrl: "https://api.avax-test.network/ext/bc/C/rpc",
entrypoint: EntryPoint.v06,
),
Network.katla: Chain(
chainId: 167008,
explorer: "https://explorer.katla.taiko.xyz/",
ethRpcUrl: "https://rpc.katla.taiko.xyz",
entrypoint: Constants.entrypointv06,
jsonRpcUrl: "https://rpc.katla.taiko.xyz",
entrypoint: EntryPoint.v06,
),
Network.localhost: Chain(
chainId: 1337,
explorer: "http://localhost:8545",
ethRpcUrl: "http://localhost:8545",
jsonRpcUrl: "http://localhost:8545",
bundlerUrl: "http://localhost:3000/rpc",
entrypoint: Constants.entrypointv06,
entrypoint: EntryPoint.v06,
)
};

Expand All @@ -177,14 +177,26 @@ class Chains {
class Constants {
static EthereumAddress entrypointv06 =
EthereumAddress.fromHex("0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789");
static EthereumAddress entrypoint =
static EthereumAddress entrypointv07 =
EthereumAddress.fromHex("0x0000000071727De22E5E9d8BAf0edAc6f37da032");
static EthereumAddress zeroAddress =
EthereumAddress.fromHex("0x0000000000000000000000000000000000000000");

Constants._();
}

enum EntryPoint {
v06(0.6, "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"),
v07(0.7, "0x0000000071727De22E5E9d8BAf0edAc6f37da032");

final double version;
final String hex;

const EntryPoint(this.version, this.hex);

EthereumAddress get address => EthereumAddress.fromHex(hex);
}

enum Network {
// mainnet
ethereum,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/4337/paymaster.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Paymaster {
}

Future<PaymasterResponse> sponsorUserOperation(Map<String, dynamic> userOp,
EthereumAddress entrypoint, Map<String, String>? context) async {
EntryPoint entrypoint, Map<String, String>? context) async {
final response = await _rpc.send<Map<String, dynamic>>(
'pm_sponsorUserOperation', [userOp, entrypoint.hex, context]);
return PaymasterResponse.fromMap(response);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/4337/providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BundlerProvider implements BundlerProviderBase {

@override
Future<UserOperationGas> estimateUserOperationGas(
Map<String, dynamic> userOp, EthereumAddress entrypoint) async {
Map<String, dynamic> userOp, EntryPoint entrypoint) async {
require(_initialized, "estimateUserOpGas: Wallet Provider not initialized");
final opGas = await _rpc.send<Map<String, dynamic>>(
'eth_estimateUserOperationGas', [userOp, entrypoint.hex]);
Expand All @@ -37,7 +37,7 @@ class BundlerProvider implements BundlerProviderBase {

@override
Future<UserOperationResponse> sendUserOperation(
Map<String, dynamic> userOp, EthereumAddress entrypoint) async {
Map<String, dynamic> userOp, EntryPoint entrypoint) async {
require(_initialized, "sendUserOp: Wallet Provider not initialized");
final opHash = await _rpc
.send<String>('eth_sendUserOperation', [userOp, entrypoint.hex]);
Expand Down
Loading

0 comments on commit 6c8b22a

Please sign in to comment.