Skip to content

Commit

Permalink
add smart account
Browse files Browse the repository at this point in the history
  • Loading branch information
superwunc committed May 29, 2024
1 parent d346419 commit 2a9d09d
Show file tree
Hide file tree
Showing 53 changed files with 6,575 additions and 2 deletions.
105 changes: 105 additions & 0 deletions src/accounts/biconomy/abi/BiconomySmartAccountAbi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* The exeuctor abi, used to execute transactions on the Biconomy Modular Smart Account
*/
export const BiconomyExecuteAbi = [
{
inputs: [
{
internalType: "address",
name: "dest",
type: "address"
},
{
internalType: "uint256",
name: "value",
type: "uint256"
},
{
internalType: "bytes",
name: "func",
type: "bytes"
}
],
name: "execute_ncC",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address[]",
name: "dest",
type: "address[]"
},
{
internalType: "uint256[]",
name: "value",
type: "uint256[]"
},
{
internalType: "bytes[]",
name: "func",
type: "bytes[]"
}
],
name: "executeBatch_y6U",
outputs: [],
stateMutability: "nonpayable",
type: "function"
}
] as const

/**
* The init abi, used to initialise Biconomy Modular Smart Account / setup default ECDSA module
*/
export const BiconomyInitAbi = [
{
inputs: [
{
internalType: "address",
name: "handler",
type: "address"
},
{
internalType: "address",
name: "moduleSetupContract",
type: "address"
},
{
internalType: "bytes",
name: "moduleSetupData",
type: "bytes"
}
],
name: "init",
outputs: [
{
internalType: "address",
name: "",
type: "address"
}
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "eoaOwner",
type: "address"
}
],
name: "initForSmartAccount",
outputs: [
{
internalType: "address",
name: "",
type: "address"
}
],
stateMutability: "nonpayable",
type: "function"
}
]
44 changes: 44 additions & 0 deletions src/accounts/biconomy/privateKeyToBiconomySmartAccount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { type Chain, type Client, type Hex, type Transport } from "viem"
import { privateKeyToAccount } from "viem/accounts"
import type { ENTRYPOINT_ADDRESS_V06_TYPE, Prettify } from "../../types"
import {
type BiconomySmartAccount,
type SignerToBiconomySmartAccountParameters,
signerToBiconomySmartAccount
} from "./signerToBiconomySmartAccount"

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

/**
* @description Creates a Biconomy Smart Account from a private key.
*
* @returns A Private Key Biconomy Smart Account using ECDSA as default validation module.
*/
export async function privateKeyToBiconomySmartAccount<
entryPoint extends ENTRYPOINT_ADDRESS_V06_TYPE,
TTransport extends Transport = Transport,
TChain extends Chain | undefined = Chain | undefined
>(
client: Client<TTransport, TChain, undefined>,
{
privateKey,
...rest
}: PrivateKeyToBiconomySmartAccountParameters<entryPoint>
): Promise<BiconomySmartAccount<entryPoint, TTransport, TChain>> {
const privateKeyAccount = privateKeyToAccount(privateKey)
return signerToBiconomySmartAccount<
entryPoint,
TTransport,
TChain,
"privateKey"
>(client, {
signer: privateKeyAccount,
...rest
})
}
Loading

0 comments on commit 2a9d09d

Please sign in to comment.