Skip to content

Commit

Permalink
Merge branch 'feat/nexus' of https://github.com/bcnmy/biconomy-client…
Browse files Browse the repository at this point in the history
…-sdk into nexus_fix/ownableValidator
  • Loading branch information
VGabriel45 committed Sep 20, 2024
2 parents 546a8de + f548ab4 commit f97a5ef
Show file tree
Hide file tree
Showing 137 changed files with 5,230 additions and 7,230 deletions.
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

0 comments on commit f97a5ef

Please sign in to comment.