Skip to content

Commit

Permalink
Merge pull request #322 from pimlicolabs/fix-eip1193-provider
Browse files Browse the repository at this point in the history
Fix eip1193 provider
  • Loading branch information
plusminushalf authored Nov 4, 2024
2 parents 79728c4 + 53857bf commit 294505c
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 35 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-cats-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"permissionless": patch
---

Fixed ethereum provider by changing type of EIP1193Provider to EthereumProvider
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type {
Account,
Assign,
Chain,
EIP1193Provider,
OneOf,
Prettify,
Transport,
Expand Down Expand Up @@ -31,7 +30,7 @@ import {
} from "viem/account-abstraction"
import { signMessage } from "viem/actions"
import { getAccountNonce } from "../../actions/public/getAccountNonce"
import { toOwner } from "../../utils/toOwner"
import { type EthereumProvider, toOwner } from "../../utils/toOwner"
import { BiconomyAbi, FactoryAbi } from "./abi/BiconomySmartAccountAbi"

const BICONOMY_PROXY_CREATION_CODE =
Expand Down Expand Up @@ -95,7 +94,7 @@ export type ToBiconomySmartAccountParameters = Prettify<{
client: Client
owners: [
OneOf<
| EIP1193Provider
| EthereumProvider
| WalletClient<Transport, Chain | undefined, Account>
| LocalAccount
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type {
Account,
Assign,
Chain,
EIP1193Provider,
OneOf,
Transport,
WalletClient
Expand Down Expand Up @@ -32,7 +31,7 @@ import { signMessage as _signMessage, getChainId } from "viem/actions"
import { getAction } from "viem/utils"
import { getAccountNonce } from "../../actions/public/getAccountNonce"
import { getSenderAddress } from "../../actions/public/getSenderAddress"
import { toOwner } from "../../utils/toOwner"
import { type EthereumProvider, toOwner } from "../../utils/toOwner"
import { KernelInitAbi } from "./abi/KernelAccountAbi"
import { KernelV3InitAbi, KernelV3_1AccountAbi } from "./abi/KernelV3AccountAbi"
import { KernelV3MetaFactoryDeployWithFactoryAbi } from "./abi/KernelV3MetaFactoryAbi"
Expand Down Expand Up @@ -305,7 +304,7 @@ export type ToEcdsaKernelSmartAccountParameters<
client: Client
owners: [
OneOf<
| EIP1193Provider
| EthereumProvider
| WalletClient<Transport, Chain | undefined, Account>
| LocalAccount
>
Expand Down
5 changes: 2 additions & 3 deletions packages/permissionless/accounts/light/toLightSmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
type Assign,
type Chain,
type Client,
type EIP1193Provider,
type Hex,
type LocalAccount,
type OneOf,
Expand All @@ -29,7 +28,7 @@ import { getChainId, signMessage } from "viem/actions"
import { getAction } from "viem/utils"
import { getAccountNonce } from "../../actions/public/getAccountNonce"
import { getSenderAddress } from "../../actions/public/getSenderAddress"
import { toOwner } from "../../utils/toOwner"
import { type EthereumProvider, toOwner } from "../../utils/toOwner"

const getAccountInitCode = async (
owner: Address,
Expand Down Expand Up @@ -81,7 +80,7 @@ export type ToLightSmartAccountParameters<
version: entryPointVersion
}
owner: OneOf<
| EIP1193Provider
| EthereumProvider
| WalletClient<Transport, Chain | undefined, Account>
| LocalAccount
>
Expand Down
5 changes: 2 additions & 3 deletions packages/permissionless/accounts/nexus/toNexusSmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type {
Account,
Assign,
Chain,
EIP1193Provider,
OneOf,
Prettify,
Transport,
Expand Down Expand Up @@ -40,7 +39,7 @@ import { getChainId, readContract } from "viem/actions"
import { getAction } from "viem/utils"
import { getAccountNonce } from "../../actions/public/getAccountNonce"
import { encode7579Calls } from "../../utils"
import { toOwner } from "../../utils/toOwner"
import { type EthereumProvider, toOwner } from "../../utils/toOwner"

const wrapMessageHash = (
messageHash: Hex,
Expand Down Expand Up @@ -93,7 +92,7 @@ export type ToNexusSmartAccountParameters = Prettify<{
client: Client
owners: [
OneOf<
| EIP1193Provider
| EthereumProvider
| WalletClient<Transport, Chain | undefined, Account>
| LocalAccount
>
Expand Down
4 changes: 2 additions & 2 deletions packages/permissionless/accounts/safe/toSafeSmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
type Assign,
type Chain,
type Client,
type EIP1193Provider,
type Hex,
type LocalAccount,
type OneOf,
Expand Down Expand Up @@ -42,6 +41,7 @@ import { getAction } from "viem/utils"
import { getAccountNonce } from "../../actions/public/getAccountNonce"
import { isSmartAccountDeployed, toOwner } from "../../utils"
import { encode7579Calls } from "../../utils/encode7579Calls"
import type { EthereumProvider } from "../../utils/toOwner"

export type SafeVersion = "1.4.1"

Expand Down Expand Up @@ -940,7 +940,7 @@ export type ToSafeSmartAccountParameters<
client: Client
owners: [
OneOf<
| EIP1193Provider
| EthereumProvider
| WalletClient<Transport, Chain | undefined, Account>
| LocalAccount
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
type Assign,
type Chain,
type Client,
type EIP1193Provider,
type Hex,
type LocalAccount,
type OneOf,
Expand All @@ -26,7 +25,7 @@ import { getChainId, signMessage } from "viem/actions"
import { getAction } from "viem/utils"
import { getAccountNonce } from "../../actions/public/getAccountNonce"
import { getSenderAddress } from "../../actions/public/getSenderAddress"
import { toOwner } from "../../utils/toOwner"
import { type EthereumProvider, toOwner } from "../../utils/toOwner"

const getAccountInitCode = async (
owner: Address,
Expand Down Expand Up @@ -71,7 +70,7 @@ export type ToSimpleSmartAccountParameters<
> = {
client: Client
owner: OneOf<
| EIP1193Provider
| EthereumProvider
| WalletClient<Transport, Chain | undefined, Account>
| LocalAccount
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {
Assign,
Chain,
Client,
EIP1193Provider,
LocalAccount,
OneOf,
Transport,
Expand All @@ -25,7 +24,7 @@ import {
toSmartAccount
} from "viem/account-abstraction"
import { getAction, toHex } from "viem/utils"
import { toOwner } from "../../utils/toOwner"
import { type EthereumProvider, toOwner } from "../../utils/toOwner"
import { encodeCallData } from "./utils/encodeCallData"
import { getAccountAddress } from "./utils/getAccountAddress"
import { getFactoryData } from "./utils/getFactoryData"
Expand All @@ -49,7 +48,7 @@ export type ToThirdwebSmartAccountParameters<
> = {
client: Client
owner: OneOf<
| EIP1193Provider
| EthereumProvider
| WalletClient<Transport, Chain | undefined, Account>
| LocalAccount
>
Expand Down
5 changes: 2 additions & 3 deletions packages/permissionless/accounts/trust/toTrustSmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
type Assign,
type Chain,
type Client,
type EIP1193Provider,
type Hex,
type LocalAccount,
type OneOf,
Expand All @@ -27,7 +26,7 @@ import {
} from "viem/account-abstraction"
import { getAction } from "viem/utils"
import { getSenderAddress } from "../../actions/public/getSenderAddress"
import { toOwner } from "../../utils/toOwner"
import { type EthereumProvider, toOwner } from "../../utils/toOwner"
import { encodeCallData } from "./utils/encodeCallData"
import { getFactoryData } from "./utils/getFactoryData"

Expand Down Expand Up @@ -69,7 +68,7 @@ export const TRUST_ADDRESSES: {
export type ToTrustSmartAccountParameters = {
client: Client
owner: OneOf<
| EIP1193Provider
| EthereumProvider
| WalletClient<Transport, Chain | undefined, Account>
| LocalAccount
>
Expand Down
19 changes: 7 additions & 12 deletions packages/permissionless/utils/toOwner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import {
type Account,
type Address,
type Chain,
type EIP1193Provider,
type EIP1193RequestFn,
type EIP1474Methods,
type LocalAccount,
type OneOf,
type Transport,
Expand All @@ -17,12 +14,14 @@ import { toAccount } from "viem/accounts"
import { signTypedData } from "viem/actions"
import { getAction } from "viem/utils"

export async function toOwner({
export type EthereumProvider = { request(...args: any): Promise<any> }

export async function toOwner<provider extends EthereumProvider>({
owner,
address
}: {
owner: OneOf<
| EIP1193Provider
| provider
| WalletClient<Transport, Chain | undefined, Account>
| LocalAccount
>
Expand All @@ -39,15 +38,11 @@ export async function toOwner({
if ("request" in owner) {
if (!address) {
try {
;[address] = await (
owner.request as EIP1193RequestFn<EIP1474Methods>
)({
;[address] = await (owner as EthereumProvider).request({
method: "eth_requestAccounts"
})
} catch {
;[address] = await (
owner.request as EIP1193RequestFn<EIP1474Methods>
)({
;[address] = await (owner as EthereumProvider).request({
method: "eth_accounts"
})
}
Expand All @@ -58,7 +53,7 @@ export async function toOwner({
}
walletClient = createWalletClient({
account: address,
transport: custom(owner as EIP1193Provider)
transport: custom(owner as EthereumProvider)
})
}

Expand Down

0 comments on commit 294505c

Please sign in to comment.