Skip to content

Commit

Permalink
Merge pull request #108 from pimlicolabs/feat/wagmi-simple-account
Browse files Browse the repository at this point in the history
Add all account connectors in wagmi & export account types in permissionless
  • Loading branch information
plusminushalf authored Feb 1, 2024
2 parents 12ac5b0 + 532bf2e commit 33dce19
Show file tree
Hide file tree
Showing 22 changed files with 546 additions and 222 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-bobcats-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"permissionless": patch
---

Added account parameters types
5 changes: 5 additions & 0 deletions .changeset/fuzzy-ghosts-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@permissionless/wagmi": patch
---

Added account-specific connectors
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"lint:fix": "bun run lint --apply",
"test": "vitest dev -c ./packages/permissionless-test/vitest.config.ts",
"test:ci": "CI=true vitest -c ./packages/permissionless-test/vitest.config.ts --coverage",
"run:demo": "bun run --cwd packages/wagmi-demo dev",
"wagmi-demo": "bun run --cwd packages/wagmi-demo dev",
"build:wagmi:cjs": "tsc --project ./tsconfig/tsconfig.wagmi.cjs.json && tsc-alias -p ./tsconfig/tsconfig.wagmi.cjs.json && printf '{\"type\":\"commonjs\"}' > ./packages/wagmi/_cjs/package.json",
"build:wagmi:esm": "tsc --project ./tsconfig/tsconfig.wagmi.esm.json && tsc-alias -p ./tsconfig/tsconfig.wagmi.esm.json && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./packages/wagmi/_esm/package.json",
"build:wagmi:types": "tsc --project ./tsconfig/tsconfig.wagmi.types.json && tsc-alias -p ./tsconfig/tsconfig.wagmi.types.json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import {
type Address,
type Chain,
type Client,
type Hex,
type Transport
} from "viem"
import { type Chain, type Client, type Hex, type Transport } from "viem"
import { privateKeyToAccount } from "viem/accounts"
import type { Prettify } from "../../types"
import {
type BiconomySmartAccount,
type SignerToBiconomySmartAccountParameters,
signerToBiconomySmartAccount
} from "./signerToBiconomySmartAccount"

export type PrivateKeyToBiconomySmartAccountParameters = Prettify<
{
privateKey: Hex
} & Omit<SignerToBiconomySmartAccountParameters, "signer">
>

/**
* @description Creates a Biconomy Smart Account from a private key.
*
Expand All @@ -21,20 +23,11 @@ export async function privateKeyToBiconomySmartAccount<
TChain extends Chain | undefined = Chain | undefined
>(
client: Client<TTransport, TChain, undefined>,
{
privateKey,
entryPoint,
index = 0n
}: {
privateKey: Hex
entryPoint: Address
index?: bigint
}
{ privateKey, ...rest }: PrivateKeyToBiconomySmartAccountParameters
): Promise<BiconomySmartAccount<TTransport, TChain>> {
const privateKeyAccount = privateKeyToAccount(privateKey)
return signerToBiconomySmartAccount(client, {
signer: privateKeyAccount,
entryPoint,
index
...rest
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import { toAccount } from "viem/accounts"
import { getChainId, signMessage, signTypedData } from "viem/actions"
import { getAccountNonce } from "../../actions/public/getAccountNonce"
import type { Prettify } from "../../types"
import { getUserOperationHash } from "../../utils/getUserOperationHash"
import { isSmartAccountDeployed } from "../../utils/isSmartAccountDeployed"
import {
Expand Down Expand Up @@ -184,6 +185,20 @@ const getAccountAddress = async ({
})
}

export type SignerToBiconomySmartAccountParameters<
TSource extends string = "custom",
TAddress extends Address = Address
> = Prettify<{
signer: SmartAccountSigner<TSource, TAddress>
entryPoint: Address
address?: Address
index?: bigint
factoryAddress?: Address
accountLogicAddress?: Address
fallbackHandlerAddress?: Address
ecdsaModuleAddress?: Address
}>

/**
* Build a Biconomy modular smart account from a private key, that use the ECDSA signer behind the scene
* @param client
Expand All @@ -210,16 +225,7 @@ export async function signerToBiconomySmartAccount<
accountLogicAddress = BICONOMY_ADDRESSES.ACCOUNT_V2_0_LOGIC,
fallbackHandlerAddress = BICONOMY_ADDRESSES.DEFAULT_FALLBACK_HANDLER_ADDRESS,
ecdsaModuleAddress = BICONOMY_ADDRESSES.ECDSA_OWNERSHIP_REGISTRY_MODULE
}: {
signer: SmartAccountSigner<TSource, TAddress>
entryPoint: Address
address?: Address
index?: bigint
factoryAddress?: Address
accountLogicAddress?: Address
fallbackHandlerAddress?: Address
ecdsaModuleAddress?: Address
}
}: SignerToBiconomySmartAccountParameters<TSource, TAddress>
): Promise<BiconomySmartAccount<TTransport, TChain>> {
// Get the private key related account
const viemSigner: LocalAccount = {
Expand Down
32 changes: 26 additions & 6 deletions packages/permissionless/accounts/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
import { privateKeyToSimpleSmartAccount } from "./privateKeyToSimpleSmartAccount"
import {
type PrivateKeyToSimpleSmartAccountParameters,
privateKeyToSimpleSmartAccount
} from "./simple/privateKeyToSimpleSmartAccount"

import {
type SignerToSimpleSmartAccountParameters,
type SimpleSmartAccount,
signerToSimpleSmartAccount
} from "./signerToSimpleSmartAccount"
} from "./simple/signerToSimpleSmartAccount"

import { privateKeyToSafeSmartAccount } from "./privateKeyToSafeSmartAccount"
import {
type PrivateKeyToSafeSmartAccountParameters,
privateKeyToSafeSmartAccount
} from "./safe/privateKeyToSafeSmartAccount"

import {
type SafeSmartAccount,
type SafeVersion,
type SignerToSafeSmartAccountParameters,
signerToSafeSmartAccount
} from "./signerToSafeSmartAccount"
} from "./safe/signerToSafeSmartAccount"

import {
type KernelEcdsaSmartAccount,
type SignerToEcdsaKernelSmartAccountParameters,
signerToEcdsaKernelSmartAccount
} from "./kernel/signerToEcdsaKernelSmartAccount"

import {
type BiconomySmartAccount,
type SignerToBiconomySmartAccountParameters,
signerToBiconomySmartAccount
} from "./biconomy/signerToBiconomySmartAccount"

import { privateKeyToBiconomySmartAccount } from "./biconomy/privateKeyToBiconomySmartAccount"
import {
type PrivateKeyToBiconomySmartAccountParameters,
privateKeyToBiconomySmartAccount
} from "./biconomy/privateKeyToBiconomySmartAccount"

import {
SignTransactionNotSupportedBySmartAccount,
Expand All @@ -46,5 +59,12 @@ export {
type KernelEcdsaSmartAccount,
signerToEcdsaKernelSmartAccount,
type BiconomySmartAccount,
signerToBiconomySmartAccount
signerToBiconomySmartAccount,
type SignerToSimpleSmartAccountParameters,
type SignerToSafeSmartAccountParameters,
type PrivateKeyToSimpleSmartAccountParameters,
type PrivateKeyToSafeSmartAccountParameters,
type SignerToEcdsaKernelSmartAccountParameters,
type SignerToBiconomySmartAccountParameters,
type PrivateKeyToBiconomySmartAccountParameters
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from "viem/actions"
import { getAccountNonce } from "../../actions/public/getAccountNonce"
import { getSenderAddress } from "../../actions/public/getSenderAddress"
import type { Prettify } from "../../types"
import { getUserOperationHash } from "../../utils/getUserOperationHash"
import { isSmartAccountDeployed } from "../../utils/isSmartAccountDeployed"
import type { SmartAccount } from "../types"
Expand Down Expand Up @@ -199,6 +200,19 @@ const getAccountAddress = async <
})
}

export type SignerToEcdsaKernelSmartAccountParameters<
TSource extends string = "custom",
TAddress extends Address = Address
> = Prettify<{
signer: SmartAccountSigner<TSource, TAddress>
entryPoint: Address
address?: Address
index?: bigint
factoryAddress?: Address
accountLogicAddress?: Address
ecdsaValidatorAddress?: Address
deployedAccountAddress?: Address
}>
/**
* Build a kernel smart account from a private key, that use the ECDSA signer behind the scene
* @param client
Expand Down Expand Up @@ -226,16 +240,7 @@ export async function signerToEcdsaKernelSmartAccount<
accountLogicAddress = KERNEL_ADDRESSES.ACCOUNT_V2_2_LOGIC,
ecdsaValidatorAddress = KERNEL_ADDRESSES.ECDSA_VALIDATOR,
deployedAccountAddress
}: {
signer: SmartAccountSigner<TSource, TAddress>
entryPoint: Address
address?: Address
index?: bigint
factoryAddress?: Address
accountLogicAddress?: Address
ecdsaValidatorAddress?: Address
deployedAccountAddress?: Address
}
}: SignerToEcdsaKernelSmartAccountParameters<TSource, TAddress>
): Promise<KernelEcdsaSmartAccount<TTransport, TChain>> {
// Get the private key related account
const viemSigner: LocalAccount = {
Expand Down
73 changes: 0 additions & 73 deletions packages/permissionless/accounts/privateKeyToSafeSmartAccount.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { type Chain, type Client, type Hex, type Transport } from "viem"
import { privateKeyToAccount } from "viem/accounts"
import type { Prettify } from "../../types"
import {
type SafeSmartAccount,
type SignerToSafeSmartAccountParameters,
signerToSafeSmartAccount
} from "./signerToSafeSmartAccount"

export type PrivateKeyToSafeSmartAccountParameters = Prettify<
{
privateKey: Hex
} & Omit<SignerToSafeSmartAccountParameters, "signer">
>

/**
* @description Creates an Simple Account from a private key.
*
* @returns A Private Key Simple Account.
*/
export async function privateKeyToSafeSmartAccount<
TTransport extends Transport = Transport,
TChain extends Chain | undefined = Chain | undefined
>(
client: Client<TTransport, TChain, undefined>,
{ privateKey, ...rest }: PrivateKeyToSafeSmartAccountParameters
): Promise<SafeSmartAccount<TTransport, TChain>> {
const privateKeyAccount = privateKeyToAccount(privateKey)

return signerToSafeSmartAccount(client, {
signer: privateKeyAccount,
...rest
})
}
Loading

0 comments on commit 33dce19

Please sign in to comment.