Skip to content

Commit

Permalink
chore: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
joepegler committed Jan 16, 2025
1 parent 8320f38 commit 52a3cce
Show file tree
Hide file tree
Showing 35 changed files with 141 additions and 87 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @biconomy/sdk

## 0.0.29

### Patch Changes

- AbstractJS rebrand
- meeNode support
- useTestBundler

## 0.0.28

### Patch Changes
Expand Down
40 changes: 25 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,31 @@ bun add @biconomy/sdk viem @rhinestone/module-sdk

2. **Basic Usage:**
```typescript
import { createSmartAccountClient } from "@biconomy/sdk";
import { http } from "viem";

const nexusClient = await createSmartAccountClient({
signer: account,
chain,
transport: http(),
bundlerTransport: http(bundlerUrl),
});

const hash = await nexusClient.sendTransaction({
calls: [{ to: "0x...", value: 1 }]
});

const { status, transactionHash } = await nexusClient.waitForTransactionReceipt({ hash });
import { toMultichainNexusAccount, mcUSDC } from "@biconomy/sdk";
import { base, optimism } from "viem/chains";
import { privateKeyToAccount } from "viem/accounts";

const eoaAccount = privateKeyToAccount(`0x${process.env.PRIVATE_KEY}`)
const mcNexus = await toMultichainNexusAccount({
chains: [base, optimism],
signer: eoaAccount
})
const meeClient = createMeeClient({ account: mcNexus })

const quote = await meeClient.getQuote({
instructions: [{
calls: [{ to: "0x...", value: 1 }],
chainId: base.id
}],
feeToken: {
address: mcUSDC.addressOn(base.id), // Token used to pay for the transaction
chainId: base.id // Chain where the payment will be processed
}
})

// Execute the quote and get back a transaction hash
// This sends the transaction to the network
const { hash } = await meeClient.executeQuote({ quote })
```

### Testing
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@biconomy/sdk",
"version": "0.0.28",
"version": "0.0.29",
"author": "Biconomy",
"repository": "github:bcnmy/sdk",
"main": "./dist/_cjs/index.js",
Expand Down
4 changes: 2 additions & 2 deletions src/sdk/account/decorators/build.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Instruction } from "../../clients/decorators/mee/getQuote"
import type { BaseMultichainSmartAccount } from "../toMultiChainNexusAccount"
import {
type BuildDefaultInstructionsParams,
type BuildDefaultParams,
buildDefaultInstructions
} from "./instructions/buildDefaultInstructions"
import {
Expand All @@ -26,7 +26,7 @@ export type BaseInstructionsParams = {
*/
export type BuildDefaultInstruction = {
type: "default"
data: BuildDefaultInstructionsParams
data: BuildDefaultParams
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,11 @@ export type BuildDefaultParams = {
instructions: Instruction[] | Instruction
}

/**
* Parameters for building base instructions
* @property currentInstructions - Optional array of {@link Instruction} existing instructions to append to
* @property instructions - Single {@link Instruction} or array of instructions to add
*/
export type BuildDefaultInstructionsParams = BaseInstructionsParams &
BuildDefaultParams

/**
* Builds a base set of instructions by combining existing instructions with new ones
*
* @param baseParams - {@link BaseInstructionsParams} Base configuration
* @param baseParams.currentInstructions - Optional array of existing instructions (defaults to empty array)
* @param params - {@link BuildDefaultInstructionsParams} Instructions configuration
* @param params.instructions - Single instruction or array of instructions to append
*
* @param params - {@link BuildDefaultParams} Instructions configuration
* @returns Promise resolving to an array of {@link Instruction}
*
* @example
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/account/decorators/instructions/buildIntent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Chain, erc20Abi } from "viem"
import type { Chain } from "viem"
import type { Instruction } from "../../../clients/decorators/mee"
import type { BaseMultichainSmartAccount } from "../../toMultiChainNexusAccount"
import type { MultichainToken } from "../../utils/Types"
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/account/toMultiChainNexusAccount.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { http, type Chain, type erc20Abi } from "viem"
import { http, type Chain } from "viem"
import type { Instruction } from "../clients/decorators/mee/getQuote"
import {
MEE_VALIDATOR_ADDRESS,
Expand Down
12 changes: 8 additions & 4 deletions src/sdk/account/toNexusAccount.addresses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ describe("nexus.account.addresses", async () => {
transport: http(),
bundlerTransport: http(bundlerUrl),
validatorAddress: TEST_ADDRESS_K1_VALIDATOR_ADDRESS,
factoryAddress: TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
factoryAddress: TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS,
useTestBundler: true
})

nexusAccount = nexusClient.account
Expand Down Expand Up @@ -139,14 +140,16 @@ describe("nexus.account.addresses", async () => {
signer: eoaAccount,
chain: base,
transport: http(),
bundlerTransport: http(bundlerUrl)
bundlerTransport: http(bundlerUrl),
useTestBundler: true
})

const testnetClient = await createSmartAccountClient({
signer: eoaAccount,
chain: baseSepolia,
transport: http(),
bundlerTransport: http(bundlerUrl)
bundlerTransport: http(bundlerUrl),
useTestBundler: true
})

const testnetAddress = await testnetClient.account.getAddress()
Expand All @@ -164,7 +167,8 @@ describe("nexus.account.addresses", async () => {
transport: http(),
validatorAddress: MEE_VALIDATOR_ADDRESS,
factoryAddress: NEXUS_ACCOUNT_FACTORY,
attesters: [TEMP_MEE_ATTESTER_ADDR]
attesters: [TEMP_MEE_ATTESTER_ADDR],
useTestBundler: true
})

const meeAddress = await meeAccount.getAddress()
Expand Down
3 changes: 2 additions & 1 deletion src/sdk/account/toNexusAccount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ describe("nexus.account", async () => {
transport: http(),
bundlerTransport: http(bundlerUrl),
validatorAddress: TEST_ADDRESS_K1_VALIDATOR_ADDRESS,
factoryAddress: TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
factoryAddress: TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS,
useTestBundler: true
})

nexusAccount = nexusClient.account
Expand Down
9 changes: 7 additions & 2 deletions src/sdk/account/toNexusAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ export type ToNexusSmartAccountParameters = {
bootStrapAddress?: Address
/** Optional registry address */
registryAddress?: Address
/** Optional use test bundler */
useTestBundler?: boolean
} & Prettify<
Pick<
ClientConfig<Transport, Chain, Account, RpcSchema>,
Expand Down Expand Up @@ -160,6 +162,7 @@ export type NexusSmartAccountImplementation = SmartAccountImplementation<
signer: Signer
publicClient: PublicClient
walletClient: WalletClient
useTestBundler: boolean
}
>

Expand Down Expand Up @@ -196,7 +199,8 @@ export const toNexusAccount = async (
attesters: attesters_ = [RHINESTONE_ATTESTER_ADDRESS],
attesterThreshold = 1,
bootStrapAddress = NEXUS_BOOTSTRAP_ADDRESS,
registryAddress = REGISTRY_ADDRESS
registryAddress = REGISTRY_ADDRESS,
useTestBundler = false
} = parameters

const useMeeAccount = addressEquals(validatorAddress, MEE_VALIDATOR_ADDRESS)
Expand Down Expand Up @@ -600,7 +604,8 @@ export const toNexusAccount = async (
signer,
walletClient,
publicClient,
attesters: attesters_
attesters: attesters_,
useTestBundler
}
})
}
2 changes: 1 addition & 1 deletion src/sdk/account/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export * from "./Constants.js"
export * from "./getChain.js"
export * from "./Logger.js"
export * from "./toSigner.js"
export * from "../decorators/getNexusAddress.js"
export * from "../decorators"
export * from "./toFeeToken.js"
export * from "./getMultichainContract.js"
export * from "./explorer.js"
Expand Down
3 changes: 2 additions & 1 deletion src/sdk/clients/createBicoBundlerClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ describe("bico.bundler", async () => {
chain,
transport: http(),
validatorAddress: TEST_ADDRESS_K1_VALIDATOR_ADDRESS,
factoryAddress: TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
factoryAddress: TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS,
useTestBundler: true
})

bicoBundler = createBicoBundlerClient({ bundlerUrl, account: nexusAccount })
Expand Down
2 changes: 0 additions & 2 deletions src/sdk/clients/createBicoPaymasterClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ describe.skip("bico.paymaster", async () => {
bundlerTransport: http(bundlerUrl)
})

console.log(nexusClient.account.address, "nexusClient.account.address")

const initialBalance = await publicClient.getBalance({
address: nexusAccountAddress
})
Expand Down
11 changes: 7 additions & 4 deletions src/sdk/clients/createBundlerClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ const COMPETITORS = [
{
name: "Pimlico",
chain: baseSepolia,
bundlerUrl: `https://api.pimlico.io/v2/${baseSepolia.id}/rpc?apikey=${process.env.PIMLICO_API_KEY}`
bundlerUrl: `https://api.pimlico.io/v2/${baseSepolia.id}/rpc?apikey=${process.env.PIMLICO_API_KEY}`,
useTestBundler: true
},
{
name: "Biconomy",
bundlerUrl: `https://bundler.biconomy.io/api/v3/${baseSepolia.id}/nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44`,
chain: baseSepolia
chain: baseSepolia,
useTestBundler: false
}
]

describe.each(COMPETITORS)(
"nexus.interoperability with $name",
async ({ bundlerUrl, chain }) => {
async ({ bundlerUrl, chain, useTestBundler }) => {
const account = privateKeyToAccount(`0x${process.env.PRIVATE_KEY as Hex}`)

const publicClient = createPublicClient({
Expand All @@ -45,7 +47,8 @@ describe.each(COMPETITORS)(
transport: http(),
// You can omit this outside of a testing context
validatorAddress: MAINNET_ADDRESS_K1_VALIDATOR_ADDRESS,
factoryAddress: MAINNET_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
factoryAddress: MAINNET_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS,
useTestBundler
})

nexusAccountAddress = await nexusAccount.getCounterFactualAddress()
Expand Down
1 change: 1 addition & 0 deletions src/sdk/clients/createHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const createHttpClient = (url: Url): HttpClient => {
})

if (!result.ok) {
console.log({ result })
throw new Error(result.statusText)
}

Expand Down
9 changes: 6 additions & 3 deletions src/sdk/clients/createNexusSessionClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ describe("nexus.session.client", async () => {
signer: eoaAccount,
chain,
transport: http(),
bundlerTransport: http(bundlerUrl)
bundlerTransport: http(bundlerUrl),
useTestBundler: true
})
nexusAccountAddress = await nexusClient.account.getCounterFactualAddress()

Expand Down Expand Up @@ -181,7 +182,8 @@ describe("nexus.session.client", async () => {
accountAddress: nexusClient.account.address,
signer: sessionKeyAccount,
transport: http(),
bundlerTransport: http(bundlerUrl)
bundlerTransport: http(bundlerUrl),
useTestBundler: true
})

const usePermissionsModule = toSmartSessionsValidator({
Expand Down Expand Up @@ -238,7 +240,8 @@ describe("nexus.session.client", async () => {
accountAddress: nexusClient.account.address,
signer: sessionKeyAccount,
transport: http(),
bundlerTransport: http(bundlerUrl)
bundlerTransport: http(bundlerUrl),
useTestBundler: true
})

const useSmartSessionNexusClient = smartSessionNexusClient.extend(
Expand Down
12 changes: 8 additions & 4 deletions src/sdk/clients/createSmartAccountClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ describe("nexus.client", async () => {
transport: http(),
bundlerTransport: http(bundlerUrl),
validatorAddress: TEST_ADDRESS_K1_VALIDATOR_ADDRESS,
factoryAddress: TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
factoryAddress: TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS,
useTestBundler: true
})
nexusAccountAddress = await nexusClient.account.getCounterFactualAddress()
})
Expand Down Expand Up @@ -277,7 +278,8 @@ describe("nexus.client", async () => {
transport: http(),
bundlerTransport: http(bundlerUrl),
validatorAddress: TEST_ADDRESS_K1_VALIDATOR_ADDRESS,
factoryAddress: TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
factoryAddress: TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS,
useTestBundler: true
})

const ethersNexusClient = await createSmartAccountClient({
Expand All @@ -286,7 +288,8 @@ describe("nexus.client", async () => {
transport: http(),
bundlerTransport: http(bundlerUrl),
validatorAddress: TEST_ADDRESS_K1_VALIDATOR_ADDRESS,
factoryAddress: TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
factoryAddress: TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS,
useTestBundler: true
})

const sig1 = await viemNexusClient.signMessage({ message: "123" })
Expand All @@ -303,7 +306,8 @@ describe("nexus.client", async () => {
transport: http(),
bundlerTransport: http(bundlerUrl),
validatorAddress: TEST_ADDRESS_K1_VALIDATOR_ADDRESS,
factoryAddress: TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
factoryAddress: TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS,
useTestBundler: true
})

const hash = await ethersNexusClient.sendUserOperation({
Expand Down
6 changes: 5 additions & 1 deletion src/sdk/clients/createSmartAccountClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ export type SmartAccountClientConfig<
bootStrapAddress?: Address
/** Registry address */
registryAddress?: Address
/** Use test bundler */
useTestBundler?: boolean
}
>

Expand Down Expand Up @@ -217,6 +219,7 @@ export async function createSmartAccountClient(
paymasterContext,
attesters,
attesterThreshold,
useTestBundler = false,
...bundlerConfig
} = parameters

Expand All @@ -234,7 +237,8 @@ export async function createSmartAccountClient(
factoryAddress,
validatorAddress,
attesters,
attesterThreshold
attesterThreshold,
useTestBundler
}))

const bundler_ = createBicoBundlerClient({
Expand Down
9 changes: 6 additions & 3 deletions src/sdk/clients/decorators/bundler/getGasFeeValues.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Account, Chain, Client, Hex, Transport } from "viem"
import type { NexusAccount } from "../../../account/toNexusAccount"

export type BicoRpcSchema = [
{
Expand Down Expand Up @@ -69,10 +70,12 @@ export const getGasFeeValues = async (
.toLowerCase()
.includes("biconomy")

const usePimlico = !!(client?.account as NexusAccount)?.useTestBundler

const gasPrice = await client.request({
method: isABiconomyBundler
? "biconomy_getGasFeeValues"
: "pimlico_getUserOperationGasPrice",
method: usePimlico
? "pimlico_getUserOperationGasPrice"
: "biconomy_getGasFeeValues",
params: []
})

Expand Down
Loading

0 comments on commit 52a3cce

Please sign in to comment.