Skip to content

Commit

Permalink
chore: release 0.0.21 (#156)
Browse files Browse the repository at this point in the history
Co-authored-by: joepegler <[email protected]>
Co-authored-by: VGabriel45 <[email protected]>
Co-authored-by: VGabriel45 <[email protected]>
  • Loading branch information
4 people authored Dec 23, 2024
1 parent d6bcde9 commit 01b4d8b
Show file tree
Hide file tree
Showing 24 changed files with 1,037 additions and 110 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
env:
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
PIMLICO_API_KEY: ${{ secrets.PIMLICO_API_KEY }}
BUNDLER_URL: https://api.pimlico.io/v2/84532/rpc?apikey=pim_im13GpaqtMDSiJFhXMxcVn
PAYMASTER_URL: ${{ secrets.PAYMASTER_URL }}
BUNDLER_URL: ${{ secrets.BUNDLER_URL }}
VIRTUAL_BASE_SEPOLIA: ${{ secrets.VIRTUAL_BASE_SEPOLIA }}
CHAIN_ID: 84532
CI: true
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# @biconomy/sdk

## 0.0.20

### Patch Changes

- Counterfactual address helper export

## 0.0.18

### Patch Changes

- fix window.ethereum

## 0.0.17

### Patch Changes

- Add mock attestor only for testnets

## 0.0.16

### Patch Changes
Expand Down
35 changes: 13 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,12 @@ The Biconomy SDK is your all-in-one toolkit for building decentralized applicati

### Installation

1. **Add the package and install dependencies:**

1. **Add the package:**
```bash
bun add @biconomy/sdk viem @rhinestone/module-sdk
```

2. **Install dependencies:**

```bash
bun i
```

2. **Basic Usage:**
```typescript
import { createNexusClient } from "@biconomy/sdk";
import { http } from "viem";
Expand All @@ -48,35 +42,32 @@ const nexusClient = await createNexusClient({
bundlerTransport: http(bundlerUrl),
});

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

const { status, transactionHash } = await nexusClient.waitForTransactionReceipt({ hash });
```

3. Testing

To run the tests, ensure you have the following prerequisites installed:
### Testing

**Prerequisites:**
- Node.js v22 or higher
- [Bun](https://bun.sh/) package manager
- [Foundry](https://book.getfoundry.sh/getting-started/installation)

Install the dependencies:

**Setup:**
```bash
bun install --frozen-lockfile
```

### Run all tests

**Running Tests:**
```bash
# Run all tests
bun run test
```

### Run tests for a specific module

```bash
bun run test -t=smartSessions
# Run tests for a specific module
bun run test -t=smartSessions
```

For detailed information about the testing framework, network configurations, and debugging guidelines, please refer to our [Testing Documentation](./src/test/README.md).
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.16",
"version": "0.0.20",
"author": "Biconomy",
"repository": "github:bcnmy/sdk",
"main": "./dist/_cjs/index.js",
Expand Down
16 changes: 6 additions & 10 deletions src/sdk/account/toNexusAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import {
} from "viem/account-abstraction"

import {
BICONOMY_ATTESTER_ADDRESS,
ENTRY_POINT_ADDRESS,
MOCK_ATTESTER_ADDRESS,
RHINESTONE_ATTESTER_ADDRESS,
Expand Down Expand Up @@ -104,9 +103,9 @@ export type ToNexusSmartAccountParameters = {
k1ValidatorAddress?: Address
/** Optional account address override */
accountAddress?: Address
/** Attesters to add to the account */
/** Attester addresses to apply to the account */
attesters?: Address[]
/** Optional threshold for the account */
/** Optional attestors threshold for the account */
attesterThreshold?: number
} & Prettify<
Pick<
Expand Down Expand Up @@ -181,11 +180,7 @@ export const toNexusAccount = async (
k1ValidatorAddress = k1ValidatorAddress_,
key = "nexus account",
name = "Nexus Account",
attesters = [
RHINESTONE_ATTESTER_ADDRESS,
MOCK_ATTESTER_ADDRESS,
BICONOMY_ATTESTER_ADDRESS
],
attesters: attesters_ = [RHINESTONE_ATTESTER_ADDRESS],
attesterThreshold = 1
} = parameters

Expand Down Expand Up @@ -218,12 +213,13 @@ export const toNexusAccount = async (

// Review:
// Todo: attesters can be added here to do one time setup upon deployment.
chain?.testnet && attesters_.push(MOCK_ATTESTER_ADDRESS)
const factoryData = encodeFunctionData({
abi: parseAbi([
"function createAccount(address eoaOwner, uint256 index, address[] attesters, uint8 threshold) external returns (address)"
]),
functionName: "createAccount",
args: [signerAddress, index, attesters, attesterThreshold]
args: [signerAddress, index, attesters_, attesterThreshold]
})

/**
Expand Down Expand Up @@ -292,7 +288,7 @@ export const toNexusAccount = async (
}
],
functionName: "computeAccountAddress",
args: [signerAddress, index, [], 0]
args: [signerAddress, index, attesters_, attesterThreshold]
})) as Address

if (!addressEquals(addressFromFactory, zeroAddress)) {
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/account/utils/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const ADDRESS_ZERO = "0x0000000000000000000000000000000000000000"
export const MAGIC_BYTES =
"0x6492649264926492649264926492649264926492649264926492649264926492"
export const BICONOMY_TOKEN_PAYMASTER =
"0x00000f7365cA6C59A2C93719ad53d567ed49c14C"
"0x00000000301515A5410e0d768aF4f53c416edf19"
export const DEFAULT_BICONOMY_IMPLEMENTATION_ADDRESS =
"0x8EBDcA5ce92f9aBF1D1ab21de24068B2a2EaF808"
export const EIP1559_UNSUPPORTED_NETWORKS: Array<number> = [97, 56, 1442, 1101]
Expand Down
17 changes: 17 additions & 0 deletions src/sdk/account/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
encodeAbiParameters,
encodeFunctionData,
encodePacked,
erc20Abi,
hexToBytes,
keccak256,
parseAbi,
Expand All @@ -22,6 +23,7 @@ import {
toHex
} from "viem"
import {
BICONOMY_TOKEN_PAYMASTER,
MOCK_MULTI_MODULE_ADDRESS,
MODULE_ENABLE_MODE_TYPE_HASH,
NEXUS_DOMAIN_NAME,
Expand Down Expand Up @@ -391,3 +393,18 @@ export type EthersWallet = {
address: Address | string
provider: AnyData
}

export const getAllowance = async (
client: PublicClient,
accountAddress: Address,
tokenAddress: Address
): Promise<bigint> => {
const approval = await client.readContract({
address: tokenAddress,
abi: erc20Abi,
functionName: "allowance",
args: [accountAddress, BICONOMY_TOKEN_PAYMASTER]
})

return approval as bigint
}
80 changes: 80 additions & 0 deletions src/sdk/account/utils/getCounterFactualAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import type { Address } from "viem"
import type { PublicClient } from "viem"
import {
MOCK_ATTESTER_ADDRESS,
RHINESTONE_ATTESTER_ADDRESS,
k1ValidatorFactoryAddress
} from "../../constants"

/**
* Get the counterfactual address of a signer
*
* @param publicClient - The public client to use for the read contract
* @param signerAddress - The address of the signer
* @param index - The index of the account
* @param isTestnet - Whether the network is testnet
* @param attesters - The attesters to use
* @param threshold - The threshold of the attesters
* @param factoryAddress - The factory address to use
* @returns The counterfactual address
*
* @example
* ```ts
* const counterFactualAddress = await getCounterFactualAddress(publicClient, signerAddress)
* ```
*/
export const getCounterFactualAddress = async (
publicClient: PublicClient,
signerAddress: Address,
isTestnet = false,
index = 0n,
attesters = [RHINESTONE_ATTESTER_ADDRESS],
threshold = 1,
factoryAddress = k1ValidatorFactoryAddress
) => {
if (isTestnet) {
attesters.push(MOCK_ATTESTER_ADDRESS)
}

return await publicClient.readContract({
address: factoryAddress,
abi: [
{
inputs: [
{
internalType: "address",
name: "eoaOwner",
type: "address"
},
{
internalType: "uint256",
name: "index",
type: "uint256"
},
{
internalType: "address[]",
name: "attesters",
type: "address[]"
},
{
internalType: "uint8",
name: "threshold",
type: "uint8"
}
],
name: "computeAccountAddress",
outputs: [
{
internalType: "address payable",
name: "expectedAddress",
type: "address"
}
],
stateMutability: "view",
type: "function"
}
],
functionName: "computeAccountAddress",
args: [signerAddress, index, attesters, threshold]
})
}
1 change: 1 addition & 0 deletions src/sdk/account/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from "./Constants.js"
export * from "./getChain.js"
export * from "./Logger.js"
export * from "./toSigner.js"
export * from "./getCounterFactualAddress.js"
11 changes: 9 additions & 2 deletions src/sdk/account/utils/toSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export async function toSigner<
| WalletClient<Transport, Chain | undefined, Account>
| undefined = undefined

if ("request" in signer && signer?.type !== "walletClient") {
if ("request" in signer) {
if (!address) {
try {
;[address] = await (signer as EthereumProvider).request({
Expand All @@ -112,8 +112,15 @@ export async function toSigner<
walletClient = signer as WalletClient<Transport, Chain | undefined, Account>
}

const addressFromWalletClient =
walletClient?.account?.address ?? (await walletClient?.getAddresses())?.[0]

if (!addressFromWalletClient) {
throw new Error("address not found in wallet client")
}

return toAccount({
address: walletClient.account.address,
address: addressFromWalletClient,
async signMessage({ message }) {
return walletClient.signMessage({ message })
},
Expand Down
4 changes: 2 additions & 2 deletions src/sdk/clients/createBicoBundlerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
type SmartAccount,
createBundlerClient
} from "viem/account-abstraction"
import { biconomyPaymasterContext } from "./createBicoPaymasterClient"
import { biconomySponsoredPaymasterContext } from "./createBicoPaymasterClient"
import { type BicoActions, bicoBundlerActions } from "./decorators/bundler"
import type {
BicoRpcSchema,
Expand Down Expand Up @@ -105,7 +105,7 @@ export const createBicoBundlerClient = (
}

const defaultedPaymasterContext = parameters.paymaster
? parameters.paymasterContext ?? biconomyPaymasterContext
? parameters.paymasterContext ?? biconomySponsoredPaymasterContext
: undefined

const bundler_ = createBundlerClient({
Expand Down
Loading

0 comments on commit 01b4d8b

Please sign in to comment.