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 07acd5f
Show file tree
Hide file tree
Showing 36 changed files with 183 additions and 90 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
43 changes: 43 additions & 0 deletions src/sdk/account/utils/toAcrossPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import type {
BridgingUserOpParams
} from "../decorators/buildBridgeInstructions"

/**
* Response type for Across bridge relay fee information
* @interface AcrossRelayFeeResponse
*/
export interface AcrossRelayFeeResponse {
totalRelayFee: {
pct: string
Expand All @@ -37,6 +41,10 @@ export interface AcrossRelayFeeResponse {
exclusivityDeadline: string
}

/**
* Parameters for fetching suggested fees from Across bridge
* @interface AcrossSuggestedFeesParams
*/
type AcrossSuggestedFeesParams = {
inputToken: Address
outputToken: Address
Expand All @@ -48,6 +56,16 @@ type AcrossSuggestedFeesParams = {
// Create HTTP client instance
const acrossClient = createHttpClient("https://app.across.to/api")

/**
* Fetches suggested fees from Across bridge API
* @param {AcrossSuggestedFeesParams} params - Parameters for fee calculation
* @param {Address} params.inputToken - Source token address
* @param {Address} params.outputToken - Destination token address
* @param {number} params.originChainId - Source chain ID
* @param {number} params.destinationChainId - Destination chain ID
* @param {bigint} params.amount - Amount to bridge
* @returns {Promise<AcrossRelayFeeResponse>} Suggested fees and related information
*/
const acrossGetSuggestedFees = async ({
inputToken,
outputToken,
Expand All @@ -67,6 +85,17 @@ const acrossGetSuggestedFees = async ({
}
})

/**
* Encodes a bridging operation for the Across protocol into a user operation
* @param {BridgingUserOpParams} params - Parameters for the bridge operation
* @param {bigint} params.bridgingAmount - Amount to bridge
* @param {Chain} params.fromChain - Source chain information
* @param {Account} params.account - User's account information
* @param {Chain} params.toChain - Destination chain information
* @param {TokenMapping} params.tokenMapping - Token address mapping across chains
* @returns {Promise<BridgingPluginResult>} Encoded user operation and bridging details
* @throws {Error} When depositor or recipient address cannot be found
*/
export const acrossEncodeBridgingUserOp = async (
params: BridgingUserOpParams
): Promise<BridgingPluginResult> => {
Expand Down Expand Up @@ -143,6 +172,20 @@ export const acrossEncodeBridgingUserOp = async (
}
}

/**
* Creates an Across bridging plugin instance
* @returns {BridgingPlugin} Plugin instance implementing the Across bridge protocol
*
* @example
* const acrossPlugin = toAcrossPlugin()
* const bridgeResult = await acrossPlugin.encodeBridgeUserOp({
* bridgingAmount: 1000000n,
* fromChain: sourceChain,
* toChain: destChain,
* account: userAccount,
* tokenMapping: tokens
* })
*/
export const toAcrossPlugin = (): BridgingPlugin => ({
encodeBridgeUserOp: async (params) => {
return await acrossEncodeBridgingUserOp(params)
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
Loading

0 comments on commit 07acd5f

Please sign in to comment.