From 5e36e777bc0e427e146c6bdbde216875dd9e9281 Mon Sep 17 00:00:00 2001 From: Cesar Date: Fri, 10 Mar 2023 16:04:11 +0100 Subject: [PATCH 1/5] feat: add fetch nonce --- provider/implementations/js/polywrap.yaml | 3 +++ provider/implementations/js/src/index.ts | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/provider/implementations/js/polywrap.yaml b/provider/implementations/js/polywrap.yaml index 9e43388..b4f934c 100644 --- a/provider/implementations/js/polywrap.yaml +++ b/provider/implementations/js/polywrap.yaml @@ -5,3 +5,6 @@ project: source: module: ./src/index.ts schema: ./src/schema.graphql + import_abis: + - uri: wrap://ens/wraps.eth:ethereum-provider@1.1.0 + abi: ../../interface/src/schema.graphql \ No newline at end of file diff --git a/provider/implementations/js/src/index.ts b/provider/implementations/js/src/index.ts index 691d807..5c1b6a2 100644 --- a/provider/implementations/js/src/index.ts +++ b/provider/implementations/js/src/index.ts @@ -8,7 +8,8 @@ import { IProvider_Module_Args_address as Args_address, IProvider_Module_Args_chainId as Args_chainId, IProvider_Module_Args_waitForTransaction as Args_waitForTransaction, - IProvider_Connection as SchemaConnection + IProvider_Connection as SchemaConnection, + IProvider_Module_Args_nonce as Args_nonce, } from "./wrap"; import { PluginFactory, PluginPackage } from "@polywrap/plugin-js"; import { Connection } from "./Connection"; @@ -119,6 +120,15 @@ export class EthereumProviderPlugin extends Module { return network.chainId.toString(); } + public async nonce( + args: Args_nonce, + _client: CoreClient + ): Promise { + const connection = await this._getConnection(args.connection); + const nonce = await connection.getSigner().getTransactionCount(); + return nonce + } + private async _getConnection(connection?: SchemaConnection | null): Promise { return this._connections.getConnection(connection ?? this.env.connection); } From 3361c2b5c11d5de4b681fdf48c069787116c2d2c Mon Sep 17 00:00:00 2001 From: Cesar Date: Fri, 10 Mar 2023 16:09:21 +0100 Subject: [PATCH 2/5] chore: update interface & deploy hash --- provider/interface/deployment.json | 2 +- provider/interface/src/schema.graphql | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/provider/interface/deployment.json b/provider/interface/deployment.json index a524d92..8b9a4e0 100644 --- a/provider/interface/deployment.json +++ b/provider/interface/deployment.json @@ -6,7 +6,7 @@ "name": "ipfs_deploy", "id": "deploy.ipfs_deploy", "input": "wrap://fs/./build", - "result": "wrap://ipfs/QmXBQNWLpQcR95nequWFLHEcsTDP772QyVFnNuroyr2nzu" + "result": "wrap://ipfs/QmdhmhqS2hLHKnAtVjNFpRLMSouFgBfAQWLmG2pSAHWBVp" } ] } diff --git a/provider/interface/src/schema.graphql b/provider/interface/src/schema.graphql index 2684d17..8ddd3d3 100644 --- a/provider/interface/src/schema.graphql +++ b/provider/interface/src/schema.graphql @@ -40,4 +40,9 @@ type Module { Get the chain id of the signer's connection. Throws if signer is missing. """ chainId(connection: Connection): String! + + """ + Get the nonce of the signer's. Throws if signer is missing. + """ + nonce(connection: Connection): Int! } From 84c9ef0e1a9dbd28603c9198df0b4f1c6ed7e9e6 Mon Sep 17 00:00:00 2001 From: Cesar Date: Fri, 10 Mar 2023 19:06:53 +0100 Subject: [PATCH 3/5] feat: add is wallet method --- provider/implementations/js/src/index.ts | 23 ++++++++++++++++++++++- provider/interface/src/schema.graphql | 5 +++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/provider/implementations/js/src/index.ts b/provider/implementations/js/src/index.ts index 5c1b6a2..402dbbb 100644 --- a/provider/implementations/js/src/index.ts +++ b/provider/implementations/js/src/index.ts @@ -10,6 +10,7 @@ import { IProvider_Module_Args_waitForTransaction as Args_waitForTransaction, IProvider_Connection as SchemaConnection, IProvider_Module_Args_nonce as Args_nonce, + IProvider_Module_Args_isWallet as Args_isWallet, } from "./wrap"; import { PluginFactory, PluginPackage } from "@polywrap/plugin-js"; import { Connection } from "./Connection"; @@ -47,7 +48,7 @@ export class EthereumProviderPlugin extends Module { * Ethers-rs defines the type of EIP 1559 tx * as 0x02, but metamask expects it as 0x2, * hence, the need of this workaround. Related: - * https://github.com/foundry-rs/foundry/issues/3890. + * https://github.com/MetaMask/metamask-extension/issues/18076 * * We check if the parameters comes as array, if the error * contains 0x2 and if the type is 0x02, then we change it @@ -67,6 +68,26 @@ export class EthereumProviderPlugin extends Module { } } } + public async isWallet( + args: Args_isWallet, + _client: CoreClient + ): Promise { + const connection = await this._getConnection(args.connection); + /** + * This methods gives to the plugin the capability + * to check if the provider is a wallet (i.e metamask) + * or a given private key (with `new Wallet("0x..")`) + * this allows the wrapper to check if it needs to call + * sendTransaction or sendRawTransaction RPC method + * + * It checks if the provider has the `provider` attribute + * which is something that only the `Web3Provider` has + * but not the JsonRpcProvider: Check the following link for more info: + * https://github.com/ethers-io/ethers.js/blob/v5.7.0/packages/providers/src.ts/web3-provider.ts#L122 + */ + const provider = connection.getProvider(); + return "provider" in provider + } async waitForTransaction( args: Args_waitForTransaction, diff --git a/provider/interface/src/schema.graphql b/provider/interface/src/schema.graphql index 8ddd3d3..f1ce72c 100644 --- a/provider/interface/src/schema.graphql +++ b/provider/interface/src/schema.graphql @@ -45,4 +45,9 @@ type Module { Get the nonce of the signer's. Throws if signer is missing. """ nonce(connection: Connection): Int! + + """ + Check if signer is wallet-based. Throws if signer is missing. + """ + isWallet(connection: Connection): Boolean! } From e0a16415916d3531e699e68d0fb5bfb6b4386263 Mon Sep 17 00:00:00 2001 From: Cesar Date: Fri, 10 Mar 2023 19:08:09 +0100 Subject: [PATCH 4/5] chore: update version & deploy hash --- provider/implementations/js/package.json | 2 +- provider/interface/deployment.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/provider/implementations/js/package.json b/provider/implementations/js/package.json index 029d903..6564889 100644 --- a/provider/implementations/js/package.json +++ b/provider/implementations/js/package.json @@ -1,7 +1,7 @@ { "name": "@polywrap/ethereum-provider-js", "description": "Ethereum Provider JS Plugin", - "version": "0.2.4", + "version": "0.2.5", "license": "MIT", "main": "build/index.js", "files": [ diff --git a/provider/interface/deployment.json b/provider/interface/deployment.json index 8b9a4e0..441cbba 100644 --- a/provider/interface/deployment.json +++ b/provider/interface/deployment.json @@ -6,7 +6,7 @@ "name": "ipfs_deploy", "id": "deploy.ipfs_deploy", "input": "wrap://fs/./build", - "result": "wrap://ipfs/QmdhmhqS2hLHKnAtVjNFpRLMSouFgBfAQWLmG2pSAHWBVp" + "result": "wrap://ipfs/QmSDUiZjKhFj7iSv76MzneSwD7bSr55rptZvnki5sASSSy" } ] } From 6719f2d59de575bc2c4fef6708fdc467120e63b1 Mon Sep 17 00:00:00 2001 From: Cesar Date: Mon, 13 Mar 2023 18:50:12 +0100 Subject: [PATCH 5/5] chore: change is wallet to is web3 provider --- provider/implementations/js/src/index.ts | 7 ++++--- provider/interface/deployment.json | 2 +- provider/interface/src/schema.graphql | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/provider/implementations/js/src/index.ts b/provider/implementations/js/src/index.ts index 402dbbb..09b61d3 100644 --- a/provider/implementations/js/src/index.ts +++ b/provider/implementations/js/src/index.ts @@ -10,7 +10,7 @@ import { IProvider_Module_Args_waitForTransaction as Args_waitForTransaction, IProvider_Connection as SchemaConnection, IProvider_Module_Args_nonce as Args_nonce, - IProvider_Module_Args_isWallet as Args_isWallet, + IProvider_Module_Args_isWeb3Provider as Args_isWeb3Provider, } from "./wrap"; import { PluginFactory, PluginPackage } from "@polywrap/plugin-js"; import { Connection } from "./Connection"; @@ -68,8 +68,9 @@ export class EthereumProviderPlugin extends Module { } } } - public async isWallet( - args: Args_isWallet, + + public async isWeb3Provider( + args: Args_isWeb3Provider, _client: CoreClient ): Promise { const connection = await this._getConnection(args.connection); diff --git a/provider/interface/deployment.json b/provider/interface/deployment.json index 441cbba..0fafef6 100644 --- a/provider/interface/deployment.json +++ b/provider/interface/deployment.json @@ -6,7 +6,7 @@ "name": "ipfs_deploy", "id": "deploy.ipfs_deploy", "input": "wrap://fs/./build", - "result": "wrap://ipfs/QmSDUiZjKhFj7iSv76MzneSwD7bSr55rptZvnki5sASSSy" + "result": "wrap://ipfs/QmWP9Y1hoZNN6ccjdy6QiskKx3aJXYVrqmx5MCxQ72UML3" } ] } diff --git a/provider/interface/src/schema.graphql b/provider/interface/src/schema.graphql index f1ce72c..a582a0e 100644 --- a/provider/interface/src/schema.graphql +++ b/provider/interface/src/schema.graphql @@ -49,5 +49,5 @@ type Module { """ Check if signer is wallet-based. Throws if signer is missing. """ - isWallet(connection: Connection): Boolean! + isWeb3Provider(connection: Connection): Boolean! }