Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor codebase #574

Merged
merged 31 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a1fff6d
chore: fix nexus import (#567)
joepegler Sep 3, 2024
896c455
Merge branch 'feat/nexus' into refactor/codebase
joepegler Sep 6, 2024
b4e78d6
chore: refactor continued
joepegler Sep 11, 2024
96a840b
chore: add timers
joepegler Sep 12, 2024
3d093c9
chore: backmerge nexus
joepegler Sep 16, 2024
3aa9a9d
chore: refactor signer -> holder
joepegler Sep 17, 2024
d5c3c83
chore: add relevant exports
joepegler Sep 18, 2024
9a3ac57
chore: packages -> src
joepegler Sep 19, 2024
759e1d8
chore: tsdoc - createNexusAccount
joepegler Sep 19, 2024
453a58f
chore: tsdoc - createNexusClient
joepegler Sep 19, 2024
ba9897c
chore: tsdoc - accountId
joepegler Sep 19, 2024
140f9dc
chore: tsdoc - getActiveHook
joepegler Sep 19, 2024
f1e6985
chore: tsdoc - getFallbackBySelector
joepegler Sep 19, 2024
d6603ad
chore: tsdoc - getInstalledExecutors
joepegler Sep 19, 2024
d0ad76d
chore: tsdoc - getInstalledValidators
joepegler Sep 19, 2024
a5493d1
chore: tsdoc - installModule
joepegler Sep 19, 2024
e5dc236
chore: tsdoc - installModules
joepegler Sep 19, 2024
21e3abd
chore: tsdoc - isModuleInstalled
joepegler Sep 19, 2024
69cad12
chore: tsdoc - supportsExecutionMode
joepegler Sep 19, 2024
48e8db6
chore: tsdoc - supportsMode
joepegler Sep 19, 2024
6bb3bb2
chore: tsdoc - uninstallFallback
joepegler Sep 19, 2024
2b9fe68
chore: tsdoc - uninstallModule
joepegler Sep 19, 2024
1cffbc2
chore: tsdoc - uninstallModules
joepegler Sep 19, 2024
b8c47f3
chore: tsdoc - sendTransaction
joepegler Sep 19, 2024
b78b12c
chore: tsdoc - signMessage
joepegler Sep 19, 2024
20d27b5
chore: tsdoc - signTypedData
joepegler Sep 19, 2024
fc3957e
chore: tsdoc - writeContract
joepegler Sep 19, 2024
427ce0e
chore: tsdoc - bicoBundlerClient
joepegler Sep 19, 2024
d0ae8c5
chore: tsdoc - ignore helpers
joepegler Sep 19, 2024
947bd35
chore: fix size limit
joepegler Sep 19, 2024
a6f911e
fix: remove executor module
joepegler Sep 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
with:
json-summary-path: ./coverage/coverage-summary.json
json-final-path: "./coverage/coverage-final.json"
vite-config-path: ./tests/vitest.config.ts
vite-config-path: ./test/vitest.config.ts
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Upload coverage reports to Codecov
Expand Down
8 changes: 4 additions & 4 deletions .size-limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
},
{
"name": "bundler (tree-shaking)",
"path": "./dist/_esm/bundler/index.js",
"path": "./dist/_esm/clients/createBicoBundlerClient.js",
"limit": "15 kB",
"import": "{ createBundler }",
"import": "{ createBicoBundlerClient }",
"ignore": ["node:fs", "fs"]
},
{
"name": "paymaster (tree-shaking)",
"path": "./dist/_esm/paymaster/index.js",
"path": "./dist/_esm/clients/createBicoPaymasterClient.js",
"limit": "15 kB",
"import": "{ toPaymaster }",
"import": "{ createBicoPaymasterClient }",
"ignore": ["node:fs", "fs"]
}
]
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Particle Auth Fix
- E2E tests for session validation modules ([4ad7ea7](https://github.com/bcnmy/biconomy-client-sdk/pull/401/commits/4ad7ea7f8eb6a28854dcce83834b2b7ff9ad3287))
- Added [TSDoc](https://bcnmy.github.io/biconomy-client-sdk) ([638dae](https://github.com/bcnmy/biconomy-client-sdk/pull/401/commits/638daee0ed6924f67c5151a2d0e5a02d32e4bf23))
- Make txs more typesafe and default with valueOrData ([b1e5b5e](https://github.com/bcnmy/biconomy-client-sdk/pull/401/commits/b1e5b5e02ab3a7fb99faa1d45b55e3cbe8d6bc93))
- Added createSmartAccountClient alias ([232472](https://github.com/bcnmy/biconomy-client-sdk/pull/401/commits/232472c788bed0619cf6295ade076b6ec3a9e0f8))
- Added createNexusClient alias ([232472](https://github.com/bcnmy/biconomy-client-sdk/pull/401/commits/232472c788bed0619cf6295ade076b6ec3a9e0f8))
- Improve dx of using paymster to build userOps ([bb54888](https://github.com/bcnmy/biconomy-client-sdk/pull/401/commits/bb548884e76a94a20329e49b18994503de9e3888))
- Add ethers v6 signer support ([9727fd](https://github.com/bcnmy/biconomy-client-sdk/pull/401/commits/9727fd51e47d62904399d17d48f5c9d6b9e591e5))
- Improved dx of using gas payments with erc20 ([741806](https://github.com/bcnmy/biconomy-client-sdk/pull/401/commits/741806da68457eba262e1a49be77fcc24360ba36))
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ bun i
```

```typescript
import { createSmartAccountClient } from "@biconomy/account";
import { createNexusClient } from "@biconomy/account";

const smartAccount = await createSmartAccountClient({
const smartAccount = await createNexusClient({
signer: viemWalletOrEthersSigner,
bundlerUrl: "", // From dashboard.biconomy.io
paymasterUrl: "", // From dashboard.biconomy.io
Expand Down
Binary file modified bun.lockb
Binary file not shown.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
"dev": "bun link && concurrently \"bun run esm:watch\" \"bun run cjs:watch\" \"bun run esm:watch:aliases\" \"bun run cjs:watch:aliases\"",
"build": "bun run clean && bun run build:cjs && bun run build:esm && bun run build:types",
"clean": "rimraf ./dist/_esm ./dist/_cjs ./dist/_types ./dist/tsconfig",
"test": "vitest -c ./tests/vitest.config.ts",
"test": "vitest -c ./src/test/vitest.config.ts",
"test:watch": "bun run test dev",
"playground": "RUN_PLAYGROUND=true vitest -c ./tests/vitest.config.ts -t=playground",
"playground": "RUN_PLAYGROUND=true vitest -c ./src/test/vitest.config.ts -t=playground",
"playground:watch": "RUN_PLAYGROUND=true bun run test -t=playground --watch",
"size": "size-limit",
"docs": "typedoc --tsconfig ./tsconfig/tsconfig.esm.json",
Expand Down Expand Up @@ -107,12 +107,13 @@
"tsc-alias": "^1.8.8",
"tslib": "^2.6.3",
"typedoc": "^0.25.9",
"viem": "2.21.6",
"vitest": "^1.3.1",
"yargs": "^17.7.2"
},
"peerDependencies": {
"typescript": "^5",
"viem": "^2"
"viem": "^2.20.0"
},
"commitlint": {
"extends": [
Expand Down
12 changes: 6 additions & 6 deletions scripts/fetch:deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const getDeployments = async () => {

const tsAbiPath = isForCore
? `${__dirname}/../src/__contracts/abi/${name}Abi.ts`
: `${__dirname}/../tests/src/__contracts/abi/${name}Abi.ts`
: `${__dirname}/../test/__contracts/abi/${name}Abi.ts`

fs.writeFileSync(tsAbiPath, tsAbiContent)

Expand All @@ -63,7 +63,7 @@ export const getDeployments = async () => {
}

// Write ABI index file...
const abiIndexContent = `export * from "./UniActionPolicyAbi"\nexport * from "./EntryPointABI"\n${coreFiles
const abiIndexContent = `export * from "./EIP1271Abi"\nexport * from "./UniActionPolicyAbi"\nexport * from "./EntryPointABI"\n${coreFiles
.map((file) => `export * from "./${file}Abi"`)
.join("\n")}`

Expand All @@ -76,15 +76,15 @@ export const getDeployments = async () => {
const abiIndexPath = `${__dirname}/../src/__contracts/abi/index.ts`
fs.writeFileSync(abiIndexPath, abiIndexContent)

const testAbiIndexPath = `${__dirname}/../tests/src/__contracts/abi/index.ts`
const testAbiIndexPath = `${__dirname}/../test/__contracts/abi/index.ts`
fs.writeFileSync(testAbiIndexPath, testAbiIndexContent)

// Write addresses to src folder
const writeAddressesPath = `${__dirname}/../src/__contracts/addresses.ts`
const writeAddressesPathTest = `${__dirname}/../tests/src/__contracts/mockAddresses.ts`
const writeAddressesPathTest = `${__dirname}/../test/__contracts/mockAddresses.ts`

const addressesContent = `// The contents of this folder is auto-generated. Please do not edit as your changes are likely to be overwritten\n
import type { Hex } from "viem"\nexport const addresses: Record<string, Hex> = ${JSON.stringify(
export const addresses = ${JSON.stringify(
Object.keys(deployedContracts)
.filter((key) => coreFiles.includes(key))
.reduce((acc, key) => {
Expand All @@ -96,7 +96,7 @@ export const getDeployments = async () => {
)} as const;\nexport default addresses\n`

const testAddressesContent = `// The contents of this folder is auto-generated. Please do not edit as your changes are likely to be overwritten\n
import type { Hex } from "viem"\nexport const mockAddresses: Record<string, Hex> = ${JSON.stringify(
export const mockAddresses = ${JSON.stringify(
Object.keys(deployedContracts)
.filter((key) => testFiles.includes(key))
.reduce((acc, key) => {
Expand Down
56 changes: 28 additions & 28 deletions scripts/send:userOp.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { http, createWalletClient, parseEther } from "viem"
import { http, type PublicClient, parseEther } from "viem"
import { privateKeyToAccount } from "viem/accounts"
import {
createK1ValidatorModule,
createSmartAccountClient,
getChain
} from "../src"
import { getChain } from "../src/sdk/account/utils/getChain"
import { createNexusClient } from "../src/sdk/clients/createNexusClient"

const k1ValidatorAddress = "0x663E709f60477f07885230E213b8149a7027239B"
const factoryAddress = "0x887Ca6FaFD62737D0E79A2b8Da41f0B15A864778"
Expand Down Expand Up @@ -51,37 +48,40 @@ const account = privateKeyToAccount(`0x${privateKey}`)
const accountTwo = privateKeyToAccount(`0x${privateKeyTwo}`)
const recipient = accountTwo.address

const [walletClient] = [
createWalletClient({
account,
chain,
transport: http()
})
]

const smartAccount = await createSmartAccountClient({
const nexusClient = await createNexusClient({
holder: account,
chain,
signer: walletClient,
bundlerUrl,
transport: http(),
bundlerTransport: http(bundlerUrl),
k1ValidatorAddress,
factoryAddress
})

const sendUserOperation = async () => {
const transaction = {
to: recipient, // NFT address
data: "0x",
value: parseEther("0.0001")
}
const main = async () => {
console.log(
"Your smart account will be deployed at address, make sure it has some funds to pay for user ops: ",
await smartAccount.getAddress()
await nexusClient.account.getAddress()
)

const response = await smartAccount.sendTransaction([transaction])
const hash = await nexusClient.sendTransaction({
calls: [
{
to: recipient,
value: parseEther("0.0001")
}
]
})

const receipt = await response.wait()
console.log("Receipt: ", receipt)
const receipt = await (
nexusClient.account.client as PublicClient
).waitForTransactionReceipt({ hash })
}

sendUserOperation()
main()
.then(() => {
process.exit(0)
})
.catch((error) => {
console.error(error)
process.exitCode = 1
})
147 changes: 147 additions & 0 deletions scripts/viem:bundler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import { config } from "dotenv"
import { http, type PublicClient, createPublicClient } from "viem"
import { privateKeyToAccount } from "viem/accounts"
import { toNexusAccount } from "../src/sdk/account/toNexusAccount"
import { getChain } from "../src/sdk/account/utils/getChain"
import { createBicoBundlerClient } from "../src/sdk/clients/createBicoBundlerClient"

config()

const k1ValidatorAddress = "0x663E709f60477f07885230E213b8149a7027239B"
const factoryAddress = "0x887Ca6FaFD62737D0E79A2b8Da41f0B15A864778"

const GAS_ESTIMATE = 1.25

const safeMultiplier = (bI: bigint, multiplier: number): bigint =>
BigInt(Math.round(Number(bI) * multiplier))

export const getEnvVars = () => {
return {
bundlerUrl: process.env.BUNDLER_URL || "",
privateKey: process.env.E2E_PRIVATE_KEY_ONE || "",
privateKeyTwo: process.env.E2E_PRIVATE_KEY_TWO || "",
paymasterUrl: process.env.PAYMASTER_URL || "",
chainId: process.env.CHAIN_ID || "0"
}
}

export const getConfig = () => {
const {
paymasterUrl,
bundlerUrl,
chainId: chainIdFromEnv,
privateKey,
privateKeyTwo
} = getEnvVars()

const chainId = Number.parseInt(chainIdFromEnv)

const chain = getChain(chainId)

return {
chain,
chainId,
paymasterUrl,
bundlerUrl,
privateKey,
privateKeyTwo
}
}

const { chain, privateKey, privateKeyTwo, bundlerUrl } = getConfig()

if ([chain, privateKey, privateKeyTwo, bundlerUrl].every(Boolean) !== true)
throw new Error("Missing env vars")

const account = privateKeyToAccount(`0x${privateKey}`)
const accountTwo = privateKeyToAccount(`0x${privateKeyTwo}`)
const recipient = accountTwo.address

const publicClient = createPublicClient({
chain,
transport: http()
})

const main = async () => {
const nexusAccount = await toNexusAccount({
holder: account,
chain,
transport: http(),
k1ValidatorAddress,
factoryAddress
})

const bicoBundler = createBicoBundlerClient({
bundlerUrl,
account: nexusAccount,
userOperation: {
estimateFeesPerGas: async (parameters) => {
const feeData = await (
parameters?.account?.client as PublicClient
)?.estimateFeesPerGas?.()
const gas = {
maxFeePerGas: safeMultiplier(feeData.maxFeePerGas, GAS_ESTIMATE),
maxPriorityFeePerGas: safeMultiplier(
feeData.maxPriorityFeePerGas,
GAS_ESTIMATE
)
}
return gas
}
}
})

const usesAltoBundler = process.env.BUNDLER_URL?.includes("pimlico")
console.time("read methods")
const results = await Promise.allSettled([
bicoBundler.getChainId(),
bicoBundler.getSupportedEntryPoints(),
bicoBundler.prepareUserOperation({
sender: account.address,
nonce: 0n,
data: "0x",
signature: "0x",
verificationGasLimit: 1n,
preVerificationGas: 1n,
callData: "0x",
callGasLimit: 1n,
maxFeePerGas: 1n,
maxPriorityFeePerGas: 1n,
account: nexusAccount
})
])
console.timeEnd("read methods")

const successCount = results.filter((result) => result.status === "fulfilled")
console.log(
`running the ${usesAltoBundler ? "Alto" : "Bico"} bundler with ${
successCount.length
} successful calls`
)

console.time("write methods")
const hash = await bicoBundler.sendUserOperation({
calls: [
{
to: account.address,
value: 1n
}
],
account: nexusAccount
})
const userOpReceipt = await bicoBundler.waitForUserOperationReceipt({ hash })
const { transactionHash } = await publicClient.waitForTransactionReceipt({
hash: userOpReceipt.receipt.transactionHash
})
console.timeEnd("write methods")
console.log({ transactionHash })
}

main()
.then(() => {
process.exit(0)
})
.catch((error) => {
console.error(error)
process.exitCode = 1
})
Loading