Skip to content

Commit

Permalink
feat: release v0.0.16
Browse files Browse the repository at this point in the history
  • Loading branch information
joepegler committed Dec 9, 2024
1 parent 257ae3e commit 9ac54fc
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 19 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @biconomy/sdk

## 0.0.16

### Patch Changes

- Add mock attestor and option to include attestors during createAccount

## 0.0.15

### Patch Changes
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.15",
"version": "0.0.16",
"author": "Biconomy",
"repository": "github:bcnmy/sdk",
"main": "./dist/_cjs/index.js",
Expand Down
6 changes: 5 additions & 1 deletion src/sdk/account/toNexusAccount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ import {
type NexusClient,
createNexusClient
} from "../clients/createNexusClient"
import { k1ValidatorAddress } from "../constants"
import {
MAINNET_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS,
k1ValidatorAddress,
k1ValidatorFactoryAddress
} from "../constants"
import type { NexusAccount } from "./toNexusAccount"
import {
addressEquals,
Expand Down
16 changes: 14 additions & 2 deletions src/sdk/account/toNexusAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ import {
} from "viem/account-abstraction"

import {
BICONOMY_ATTESTER_ADDRESS,
ENTRY_POINT_ADDRESS,
MOCK_ATTESTER_ADDRESS,
RHINESTONE_ATTESTER_ADDRESS,
k1ValidatorAddress as k1ValidatorAddress_,
k1ValidatorFactoryAddress
Expand Down Expand Up @@ -102,6 +104,10 @@ export type ToNexusSmartAccountParameters = {
k1ValidatorAddress?: Address
/** Optional account address override */
accountAddress?: Address
/** Attesters to add to the account */
attesters?: Address[]
/** Optional threshold for the account */
attesterThreshold?: number
} & Prettify<
Pick<
ClientConfig<Transport, Chain, Account, RpcSchema>,
Expand Down Expand Up @@ -174,7 +180,13 @@ export const toNexusAccount = async (
factoryAddress = k1ValidatorFactoryAddress,
k1ValidatorAddress = k1ValidatorAddress_,
key = "nexus account",
name = "Nexus Account"
name = "Nexus Account",
attesters = [
RHINESTONE_ATTESTER_ADDRESS,
MOCK_ATTESTER_ADDRESS,
BICONOMY_ATTESTER_ADDRESS
],
attesterThreshold = 1
} = parameters

// @ts-ignore
Expand Down Expand Up @@ -211,7 +223,7 @@ export const toNexusAccount = async (
"function createAccount(address eoaOwner, uint256 index, address[] attesters, uint8 threshold) external returns (address)"
]),
functionName: "createAccount",
args: [signerAddress, index, [RHINESTONE_ATTESTER_ADDRESS], 1]
args: [signerAddress, index, attesters, attesterThreshold]
})

/**
Expand Down
16 changes: 14 additions & 2 deletions src/sdk/clients/createBundlerClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createBundlerClient } from "viem/account-abstraction"
import { privateKeyToAccount } from "viem/accounts"
import { baseSepolia } from "viem/chains"
import { beforeAll, describe, expect, test } from "vitest"
import { index } from "../../test/playground.test"
import { type NexusAccount, toNexusAccount } from "../account/toNexusAccount"
import { safeMultiplier } from "../account/utils"
import { MAINNET_ADDRESS_K1_VALIDATOR_ADDRESS } from "../constants"
Expand All @@ -14,7 +15,7 @@ import { smartAccountActions } from "./decorators/smartAccount"
const COMPETITORS = [
{
name: "Pimlico",
bundlerUrl: `https://api.pimlico.io/v2/${process.env.CHAIN_ID}/rpc?apikey=${process.env.PIMLICO_API_KEY}`
bundlerUrl: `https://api.pimlico.io/v2/84532/rpc?apikey=${process.env.PIMLICO_API_KEY}`
}
]

Expand All @@ -40,11 +41,22 @@ describe.each(COMPETITORS)(
transport: http(),
// You can omit this outside of a testing context
k1ValidatorAddress: MAINNET_ADDRESS_K1_VALIDATOR_ADDRESS,
factoryAddress: MAINNET_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
factoryAddress: MAINNET_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS,
index
})

nexusAccountAddress = await nexusAccount.getCounterFactualAddress()

const balance = await publicClient.getBalance({
address: nexusAccountAddress
})

if (balance === 0n) {
throw new Error(
`Insufficient balance at address: ${nexusAccountAddress}`
)
}

bundlerClient = createBundlerClient({
chain,
transport: http(bundlerUrl),
Expand Down
16 changes: 14 additions & 2 deletions src/sdk/clients/createNexusClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import type {
UserOperationRequest
} from "viem/account-abstraction"

import { type NexusAccount, toNexusAccount } from "../account/toNexusAccount"
import {
type NexusAccount,
type ToNexusSmartAccountParameters,
toNexusAccount
} from "../account/toNexusAccount"
import type { EthersWallet } from "../account/utils/Utils"
import type { EthereumProvider } from "../account/utils/toSigner"
import {
Expand Down Expand Up @@ -152,6 +156,10 @@ export type NexusClientConfig<
k1ValidatorAddress?: Address
/** Account address */
accountAddress?: Address
/** Attesters */
attesters?: ToNexusSmartAccountParameters["attesters"]
/** Threshold */
attesterThreshold?: ToNexusSmartAccountParameters["attesterThreshold"]
}
>

Expand Down Expand Up @@ -189,6 +197,8 @@ export async function createNexusClient(
bundlerTransport,
transport,
accountAddress,
attesters,
attesterThreshold,
...bundlerConfig
} = parameters

Expand All @@ -202,7 +212,9 @@ export async function createNexusClient(
index,
module,
factoryAddress,
k1ValidatorAddress
k1ValidatorAddress,
attesters,
attesterThreshold
})

const bundler_ = createBicoBundlerClient({
Expand Down
11 changes: 4 additions & 7 deletions src/sdk/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,27 @@ export const TIMEFRAME_POLICY_ADDRESS: Hex =
export const NEXUS_BOOTSTRAP_ADDRESS: Hex =
"0x00000008c901d8871b6F6942De0B5D9cCf3873d3"

export const TEST_ADDRESS_NEXUS_IMPLEMENTATION_ADDRESS: Hex =
"0xB3F84591e997Fc6fe9Cd3b89603Dad28E0445CE0"
export const TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS: Hex =
"0x704C800D313c6B184228B5b733bBd6BC3EA9832c"
export const TEST_ADDRESS_K1_VALIDATOR_ADDRESS: Hex =
"0xCfa6175DDC2eF918e527b2972D9AB8B149f151b7"

export const MAINNET_ADDRESS_NEXUS_IMPLEMENTATION_ADDRESS: Hex =
"0x000000F5b753Fdd20C5CA2D7c1210b3Ab1EA5903"
export const MAINNET_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS: Hex =
"0x00000024115AA990F0bAE0B6b0D5B8F68b684cd6"
export const MAINNET_ADDRESS_K1_VALIDATOR_ADDRESS: Hex =
"0x0000002D6DB27c52E3C11c1Cf24072004AC75cBa"

export const nexusImplementationAddress: Hex = isTesting()
? TEST_ADDRESS_NEXUS_IMPLEMENTATION_ADDRESS
: MAINNET_ADDRESS_NEXUS_IMPLEMENTATION_ADDRESS
export const k1ValidatorFactoryAddress: Hex = isTesting()
? TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
: MAINNET_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS

export const k1ValidatorAddress: Hex = isTesting()
? TEST_ADDRESS_K1_VALIDATOR_ADDRESS
: MAINNET_ADDRESS_K1_VALIDATOR_ADDRESS

export const BICONOMY_ATTESTER_ADDRESS: Hex =
"0xDE8FD2dBcC0CA847d11599AF5964fe2AEa153699"

// Rhinestone constants
export {
SMART_SESSIONS_ADDRESS,
Expand Down
61 changes: 57 additions & 4 deletions src/test/playground.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
type NexusClient,
createNexusClient
} from "../sdk/clients/createNexusClient"
import { MAINNET_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS } from "../sdk/constants"
import type {
CreateSessionDataParams,
SessionData
Expand All @@ -36,6 +37,8 @@ import {
getTestParamsForTestnet
} from "./testUtils"

export const index = 6n

describe.skipIf(!playgroundTrue())("playground", () => {
let network: NetworkConfig
// Required for "PUBLIC_TESTNET" networks
Expand All @@ -52,8 +55,6 @@ describe.skipIf(!playgroundTrue())("playground", () => {
let nexusClient: NexusClient
let nexusAccountAddress: Address

const index = 6n

beforeAll(async () => {
network = await toNetwork("PUBLIC_TESTNET")

Expand Down Expand Up @@ -98,6 +99,59 @@ describe.skipIf(!playgroundTrue())("playground", () => {
console.log({ nexusAccountAddress })
})

test("should verify BICONOMY_ATTESTER_ADDRESS", async () => {
const BICONOMY_ATTESTER_ADDRESS = (await publicClient.readContract({
address: MAINNET_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS,
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: [
"0x129443cA2a9Dec2020808a2868b38dDA457eaCC7",
0n,
["0x000000333034E9f539ce08819E12c1b8Cb29084d"],
1
]
})) as Address

expect(BICONOMY_ATTESTER_ADDRESS).toBe(
"0xDE8FD2dBcC0CA847d11599AF5964fe2AEa153699"
)
})

test("should check balances and top up relevant addresses", async () => {
const [ownerBalance, smartAccountBalance] = await Promise.all([
publicClient.getBalance({
Expand Down Expand Up @@ -162,8 +216,7 @@ describe.skipIf(!playgroundTrue())("playground", () => {
expect(balanceAfter - balanceBefore).toBe(1n)
})

// Skipped because on base sepolia the attestations for smart sessions have not been created yet
test.skip("should test creating and using a session", async () => {
test("should test creating and using a session", async () => {
const sessionsModule = toSmartSessionsValidator({
account: nexusClient.account,
signer: eoaAccount
Expand Down

0 comments on commit 9ac54fc

Please sign in to comment.