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

Nexus fix: OwnableValidator & OwnableExecutor integration + tests, + add missing features after viem refactor + fix issues & conflicts +++ #576

Merged
merged 18 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
6 changes: 3 additions & 3 deletions src/__contracts/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import type { Hex } from "viem"
export const addresses: Record<string, Hex> = {
Nexus: "0x776d63154D2aa9256D72C420416c930F3B735464",
K1Validator: "0xd98238BBAeA4f91683d250003799EAd31d7F5c55",
K1ValidatorFactory: "0x8025afaD10209b8bEF3A3C94684AaE4D309c9996",
Nexus: "0x2ecd86799137FA35De834Da03D876bcc363ec0c3",
VGabriel45 marked this conversation as resolved.
Show resolved Hide resolved
K1Validator: "0xBD654f9F8718840591A2964E2f0cA5b0bB743183",
K1ValidatorFactory: "0xB0D70f13903f3Eb5D378dD6A5aC4E755Fc13dC1b",
UniActionPolicy: "0x28120dC008C36d95DE5fa0603526f219c1Ba80f6"
} as const
export default addresses
22 changes: 15 additions & 7 deletions src/account/NexusSmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1039,9 +1039,17 @@ export class NexusSmartAccount extends BaseSmartContractAccount {
async sendUserOp({
signature,
...userOpWithoutSignature
}: Partial<UserOperationStruct>): Promise<UserOpResponse> {
const userOperation = await this.signUserOp(userOpWithoutSignature)
return await this.sendSignedUserOp(userOperation)
}: Partial<UserOperationStruct>, userOpSignature?: Hex): Promise<UserOpResponse> {
if (!userOpSignature) {
VGabriel45 marked this conversation as resolved.
Show resolved Hide resolved
const userOperation = await this.signUserOp(userOpWithoutSignature)
return await this.sendSignedUserOp(userOperation)
} else {
const userOperation = {
...userOpWithoutSignature,
signature: userOpSignature
} as UserOperationStruct
return await this.sendSignedUserOp(userOperation)
}
}

/**
Expand Down Expand Up @@ -1323,7 +1331,7 @@ export class NexusSmartAccount extends BaseSmartContractAccount {
: [manyOrOneTransactions],
buildUseropDto
)
const response = await this.sendUserOp(userOp)
const response = await this.sendUserOp(userOp, buildUseropDto?.signatureOverride)
this.setDeploymentState(response) // don't wait for this to finish...
return response
}
Expand Down Expand Up @@ -1711,7 +1719,7 @@ export class NexusSmartAccount extends BaseSmartContractAccount {
["address", "bytes"],
[
this.activeValidationModule.getAddress() ??
this.defaultValidationModule.getAddress(),
this.defaultValidationModule.getAddress(),
signature
]
)
Expand Down Expand Up @@ -1881,13 +1889,13 @@ export class NexusSmartAccount extends BaseSmartContractAccount {
| Awaited<ReturnType<typeof this.getInstalledExecutors>>,
module: Module
): Hex {
const index = installedModules.indexOf(getAddress(module.moduleAddress))
const index = installedModules[0].indexOf(getAddress(module.moduleAddress))
if (index === 0) {
return SENTINEL_ADDRESS
}
if (index > 0) {
// @ts-ignore: TODO: Gabi This looks wrong
VGabriel45 marked this conversation as resolved.
Show resolved Hide resolved
return installedModules[index - 1]
return installedModules[0][index - 1]
}
throw new Error(
`Module ${module.moduleAddress} not found in installed modules`
Expand Down
4 changes: 4 additions & 0 deletions src/account/utils/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ export const MOCK_MULTI_MODULE_ADDRESS =
"0x9C992f91E7Cd4697B81E137007f446E826b8378b"
export const MODULE_TYPE_MULTI = 0
export const eip1271MagicValue: Hex = "0x1626ba7e"

// Module addresses for base sepolia tests
export const OWNABLE_VALIDATOR_ADDRESS = "0xfb11d7ca9161F1DF508787BA45951225B6C0a681";
export const K1_VALIDATOR_ADDRESS = "0xBD654f9F8718840591A2964E2f0cA5b0bB743183";
23 changes: 12 additions & 11 deletions src/account/utils/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ export type NexusSmartAccountConfig = NexusSmartAccountConfigBaseProps &

export type NexusSmartAccountConfigConstructorProps =
NexusSmartAccountConfigBaseProps &
BaseSmartAccountConfig &
ResolvedBundlerProps &
ResolvedValidationProps &
ConfigurationAddresses
BaseSmartAccountConfig &
ResolvedBundlerProps &
ResolvedValidationProps &
ConfigurationAddresses

/**
* Represents options for building a user operation.
Expand All @@ -208,6 +208,7 @@ export type BuildUserOpOptions = {
dummyPndOverride?: BytesLike
useEmptyDeployCallData?: boolean
useExecutor?: boolean
signatureOverride?: Hex
VGabriel45 marked this conversation as resolved.
Show resolved Hide resolved
}

export type NonceOptions = {
Expand Down Expand Up @@ -442,13 +443,13 @@ export interface SmartAccountSigner<Inner = any> {
//#region UserOperationCallData
export type UserOperationCallData =
| {
/* the target of the call */
target: Address
/* the data passed to the target */
data: Hex
/* the amount of native token to send to the target (default: 0) */
value?: bigint
}
/* the target of the call */
target: Address
/* the data passed to the target */
data: Hex
/* the amount of native token to send to the target (default: 0) */
value?: bigint
}
| Hex
//#endregion UserOperationCallData

Expand Down
6 changes: 2 additions & 4 deletions src/bundler/Bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,8 @@ export class Bundler implements IBundler {
clearInterval(intervalId)
reject(
new Error(
`Exceeded maximum duration (${
maxDuration / 1000
} sec) waiting to get receipt for userOpHash ${
sendUserOperationResponse.result
`Exceeded maximum duration (${maxDuration / 1000
} sec) waiting to get receipt for userOpHash ${sendUserOperationResponse.result
}. Try getting the receipt manually using eth_getUserOperationReceipt rpc method on bundler`
)
)
Expand Down
6 changes: 5 additions & 1 deletion src/bundler/utils/HelperFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ function decodeErrorCode(errorCode: string) {
"0x40d3d1a40000000000000000000000004b8306128aed3d49a9d17b99bf8082d4e406fa1f":
"LinkedList_EntryAlreadyInList",
"0x40d3d1a4000000000000000000000000d98238bbaea4f91683d250003799ead31d7f5c55":
"Error: Custom error message about the K1Validator contract"
"Error: Custom error message about the K1Validator contract",
"0x8baa579f":
"Invalid Signature",
"0x1e6d14ea":
"Cannot Remove Owner (Number of owners needs to be bigger or equal to the threshold, consider setting a lower threshold)"
// Add more error codes and their corresponding human-readable messages here
}
const decodedError = errorMap[errorCode] || errorCode
Expand Down
4 changes: 2 additions & 2 deletions src/modules/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OwnableExecutorModule } from "./executors/OwnableExecutor.js"
import { K1ValidatorModule } from "./validators/K1ValidatorModule.js"
// import { OwnableValidator } from "./validators/OwnableValidator.js"
import { OwnableValidator } from "./validators/OwnableValidator.js"
import { ValidationModule } from "./validators/ValidationModule.js"

export * from "./utils/Types.js"
Expand All @@ -10,5 +10,5 @@ export * from "./interfaces/IValidationModule.js"

export const createOwnableExecutorModule = OwnableExecutorModule.create
export const createK1ValidatorModule = K1ValidatorModule.create
// export const createOwnableValidatorModule = OwnableValidator.create
export const createOwnableValidatorModule = OwnableValidator.create
export const createValidationModule = ValidationModule.create
8 changes: 3 additions & 5 deletions src/modules/utils/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
type ByteArray,
type Chain,
type Hex,
PrivateKeyAccount,
encodeAbiParameters,
isHex,
keccak256,
Expand Down Expand Up @@ -152,13 +153,10 @@ export const getUserOpHash = (
return keccak256(enc)
}

export const getRandomSigner = (): SignerData => {
export const getRandomSigner = (): PrivateKeyAccount => {
VGabriel45 marked this conversation as resolved.
Show resolved Hide resolved
const pkey = generatePrivateKey()
const account = privateKeyToAccount(pkey)
return {
pvKey: pkey,
pbKey: account.address
}
return account
}

export const parseChain = (chainInfo: ChainInfo): Chain => {
Expand Down
Loading