Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: ss enable mode #152

Merged
merged 31 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0449f36
chore: add test and multi account
joepegler Nov 30, 2024
abc7e95
chore: abstractions
joepegler Dec 2, 2024
63ec4af
chore: remove unnecessary code
joepegler Dec 2, 2024
2028d5a
chore: fix unit tests
joepegler Dec 2, 2024
7cee6ca
chore: omit failing dan tests
joepegler Dec 2, 2024
b60fabb
chore: remove dan
joepegler Dec 2, 2024
83d6269
chore: add missing imports
joepegler Dec 2, 2024
effc16b
chore: test fix
joepegler Dec 7, 2024
32f9846
chore: meeService
joepegler Dec 7, 2024
7420df9
chore: get account params
joepegler Dec 9, 2024
0dd2016
chore: testnetParams
joepegler Dec 9, 2024
42df35f
chore: ss enable mode
joepegler Dec 19, 2024
311e899
chore: fix string
joepegler Dec 19, 2024
aa5983f
chore: merge left behind mee work
joepegler Dec 19, 2024
acc77b9
chore: fix nonce
joepegler Dec 19, 2024
a26231b
chore: add module address to nonce
joepegler Dec 20, 2024
0f1f19f
chore: cont
joepegler Dec 20, 2024
9fe0818
chore: pack user operation
joepegler Dec 20, 2024
477bb1d
feat: add safeSender
joepegler Dec 20, 2024
fa5f293
chore: continued
joepegler Dec 20, 2024
cc59f52
chore: improved debugging tools
joepegler Dec 20, 2024
5228ebe
feat: clean logs
joepegler Dec 20, 2024
6b4e4c0
chore: version & changelog update (#157)
VGabriel45 Dec 23, 2024
8503e5a
chore: backmerge
joepegler Dec 28, 2024
186e759
chore: fix tests and build
joepegler Dec 30, 2024
346c6e3
chore: continued
joepegler Dec 30, 2024
12c4b6f
Merge remote-tracking branch 'origin/develop' into feat/ss_enable_mode
joepegler Dec 30, 2024
0e83bc4
chore: skip failing paymaster tests
joepegler Dec 30, 2024
3fe6115
chore: continued migration
joepegler Dec 31, 2024
9c0759d
chore: smart sessions migration
joepegler Dec 31, 2024
a0304d2
chore: introduce deferred terminology
joepegler Dec 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
PRIVATE_KEY=
CHAIN_ID=84532
ALT_CHAIN_ID=11155111
RPC_URL=
BUNDLER_URL=
BICONOMY_SDK_DEBUG=false
RUN_PLAYGROUND=false
PAYMASTER_URL=
PIMLICO_API_KEY=
PIMLICO_API_KEY=
TENDERLY_API_KEY=
TENDERLY_ACCOUNT_SLUG=
TENDERLY_PROJECT_SLUG=
VIRTUAL_BASE_SEPOLIA=
1 change: 1 addition & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ jobs:
BUNDLER_URL: ${{ secrets.BUNDLER_URL }}
VIRTUAL_BASE_SEPOLIA: ${{ secrets.VIRTUAL_BASE_SEPOLIA }}
CHAIN_ID: 84532
ALT_CHAIN_ID: 11155420
CI: true
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.22

### Patch Changes

- Smart sessions enable mode

## 0.0.21

### Patch Changes
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ bun add @biconomy/sdk viem @rhinestone/module-sdk

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

const nexusClient = await createNexusClient({
const nexusClient = await createSmartAccountClient({
signer: account,
chain,
transport: http(),
Expand All @@ -52,9 +52,10 @@ const { status, transactionHash } = await nexusClient.waitForTransactionReceipt(
### Testing

**Prerequisites:**
- Node.js v22 or higher
- [Node.js](https://nodejs.org/en/download/package-manager) *(v22 or higher)*
- [Bun](https://bun.sh/) package manager
- [Foundry](https://book.getfoundry.sh/getting-started/installation)
- [Yarn](https://www.npmjs.com/package/yarn) *(must be 1.1.x, not 3.x)*. This is necessary because the nexus contracts repo relies on yarn.

**Setup:**
```bash
Expand Down
Binary file modified bun.lockb
Binary file not shown.
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@biconomy/sdk",
"version": "0.0.21",
"version": "0.0.22",
"author": "Biconomy",
"repository": "github:bcnmy/sdk",
"main": "./dist/_cjs/index.js",
Expand Down Expand Up @@ -38,12 +38,12 @@
"viem": "2.21.6",
"vitest": "^1.3.1",
"yargs": "^17.7.2",
"@rhinestone/module-sdk": "^0.1.28"
"@rhinestone/module-sdk": "0.1.28"
},
"peerDependencies": {
"typescript": "^5",
"viem": "^2.20.0",
"@rhinestone/module-sdk": "^0.1.28"
"@rhinestone/module-sdk": "0.1.28"
},
"exports": {
".": {
Expand Down Expand Up @@ -126,8 +126,5 @@
},
"type": "module",
"types": "./dist/_types/index.d.ts",
"typings": "./dist/_types/index.d.ts",
"dependencies": {
"@silencelaboratories/walletprovider-sdk": "^0.3.0"
}
"typings": "./dist/_types/index.d.ts"
}
32 changes: 25 additions & 7 deletions src/sdk/account/toNexusAccount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
createWalletClient,
domainSeparator,
encodeAbiParameters,
encodeFunctionData,
encodePacked,
getContract,
hashMessage,
Expand All @@ -27,6 +28,7 @@ import {
} from "viem"
import type { UserOperation } from "viem/account-abstraction"
import { afterAll, beforeAll, describe, expect, test } from "vitest"
import { CounterAbi } from "../../test/__contracts/abi/CounterAbi"
import { MockSignatureValidatorAbi } from "../../test/__contracts/abi/MockSignatureValidatorAbi"
import { TokenWithPermitAbi } from "../../test/__contracts/abi/TokenWithPermitAbi"
import { testAddresses } from "../../test/callDatas"
Expand All @@ -40,13 +42,12 @@ import {
import type { MasterClient, NetworkConfig } from "../../test/testUtils"
import {
type NexusClient,
createNexusClient
} from "../clients/createNexusClient"
createSmartAccountClient
} from "../clients/createSmartAccountClient"
import {
BICONOMY_ATTESTER_ADDRESS,
MAINNET_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS,
k1ValidatorAddress,
k1ValidatorFactoryAddress
k1ValidatorAddress
} from "../constants"
import type { NexusAccount } from "./toNexusAccount"
import {
Expand Down Expand Up @@ -90,7 +91,7 @@ describe("nexus.account", async () => {
transport: http()
})

nexusClient = await createNexusClient({
nexusClient = await createSmartAccountClient({
signer: eoaAccount,
chain,
transport: http(),
Expand All @@ -106,7 +107,7 @@ describe("nexus.account", async () => {
})

test("should override account address", async () => {
const newNexusClient = await createNexusClient({
const newNexusClient = await createSmartAccountClient({
chain,
transport: http(),
bundlerTransport: http(bundlerUrl),
Expand Down Expand Up @@ -221,7 +222,7 @@ describe("nexus.account", async () => {
calls: [{ to: userTwo.address, value: 1n }]
})

const userOpHash = await nexusClient.account.getUserOpHash(userOperation)
const userOpHash = nexusClient.account.getUserOpHash(userOperation)

const isValid = await mockSigVerifierContract.read.verify([
userOpHash,
Expand Down Expand Up @@ -600,4 +601,21 @@ describe("nexus.account", async () => {
expect(BICONOMY_ATTESTER_ADDRESS).toBe(biconomyAttesterAddress)
}
)

testnetTest(
"should debug user operation and generate tenderly link",
async ({ config: { chain } }) => {
await nexusClient.debugUserOperation({
calls: [
{
to: testAddresses.Counter,
data: encodeFunctionData({
abi: CounterAbi,
functionName: "incrementNumber"
})
}
]
})
}
)
})
67 changes: 20 additions & 47 deletions src/sdk/account/toNexusAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
} from "../constants"
// Constants
import { EntrypointAbi } from "../constants/abi"
import { getCounterFactualAddress as getCounterFactualAddress_ } from "./utils/getCounterFactualAddress"

// Modules
import { toK1Validator } from "../modules/k1Validator/toK1Validator"
Expand Down Expand Up @@ -144,6 +145,8 @@ export type NexusSmartAccountImplementation = SmartAccountImplementation<
getModule: () => Module
factoryData: Hex
factoryAddress: Address
k1ValidatorAddress: Address
attesters: Address[]
signer: Signer
publicClient: PublicClient
walletClient: WalletClient
Expand Down Expand Up @@ -249,47 +252,15 @@ export const toNexusAccount = async (
}
}

const addressFromFactory = (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_, attesterThreshold]
})) as Address
const addressFromFactory = await getCounterFactualAddress_(
publicClient,
signerAddress,
false,
index,
attesters_,
attesterThreshold,
factoryAddress
)

if (!addressEquals(addressFromFactory, zeroAddress)) {
_accountAddress = addressFromFactory
Expand Down Expand Up @@ -324,14 +295,13 @@ export const toNexusAccount = async (
* @param userOp - The user operation
* @returns The hash of the user operation
*/
const getUserOpHash = (userOp: UserOperation): Hex => {
return getUserOperationHash({
const getUserOpHash = (userOp: UserOperation): Hex =>
getUserOperationHash({
chainId: chain.id,
entryPointAddress: entryPoint07Address,
entryPointVersion: "0.7",
userOperation: userOp
})
}

/**
* @description Encodes a batch of calls for execution
Expand Down Expand Up @@ -397,12 +367,13 @@ export const toNexusAccount = async (

/**
* @description Gets the nonce for the account
* @param args - Optional arguments for getting the nonce
* @param parameters - Optional parameters for getting the nonce
* @returns The nonce
*/
const getNonce = async (parameters?: {
key?: bigint
validationMode?: "0x00" | "0x01"
moduleAddress?: Address
}): Promise<bigint> => {
try {
const TIMESTAMP_ADJUSTMENT = 16777215n
Expand All @@ -411,7 +382,7 @@ export const toNexusAccount = async (
const key: string = concat([
toHex(defaultedKey, { size: 3 }),
defaultedValidationMode,
module.address as Hex
parameters?.moduleAddress ?? (module.address as Hex)
])

const accountAddress = await getCounterFactualAddress()
Expand Down Expand Up @@ -599,9 +570,11 @@ export const toNexusAccount = async (
getModule: () => module,
factoryData,
factoryAddress,
k1ValidatorAddress,
signer,
walletClient,
publicClient
publicClient,
attesters: attesters_
}
})
}
2 changes: 1 addition & 1 deletion src/sdk/account/utils/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const MOCK_MULTI_MODULE_ADDRESS =
export const MODULE_TYPE_MULTI = 0

export const NEXUS_DOMAIN_NAME = "nexus"
export const NEXUS_DOMAIN_VERSION = "1.0.0"
export const NEXUS_DOMAIN_VERSION = "1.0.1"
export const NEXUS_DOMAIN_TYPEHASH =
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"

Expand Down
1 change: 0 additions & 1 deletion src/sdk/account/utils/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export type UserOpReceipt = {
logs: Log[]
}

export type Service = "Bundler" | "Paymaster"
export type BigNumberish = Hex | number | bigint
export type BytesLike = Uint8Array | Hex | string

Expand Down
Loading
Loading