Skip to content

Commit

Permalink
feat: add mav2 signer (#1203)
Browse files Browse the repository at this point in the history
- [ ] Did you add new tests and confirm existing tests pass? (`yarn test`)
- [ ] Did you update relevant docs? (docs are found in the `site` folder, and guidelines for updating/adding docs can be found in the [contribution guide](https://github.com/alchemyplatform/aa-sdk/blob/main/CONTRIBUTING.md))
- [ ] Do your commits follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) standard?
- [ ] Does your PR title also follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) standard?
- [ ] If you have a breaking change, is it [correctly reflected in your commit message](https://www.conventionalcommits.org/en/v1.0.0/#examples)? (e.g. `feat!: breaking change`)
- [ ] Did you run lint (`yarn lint:check`) and fix any issues? (`yarn lint:write`)
- [ ] Did you follow the [contribution guidelines](https://github.com/alchemyplatform/aa-sdk/blob/main/CONTRIBUTING.md)?

<!-- start pr-codex -->

---

This PR introduces a new module for single signer validation in the `account-kit` smart contracts. It adds functionality for packing signatures and validating user operations, along with defining the ABI for the single signer validation module and related contracts.

- Added `PackSignatureParams` type and `packSignature` utility in `utils.ts`.
- Created `SingleSignerValidationModule` with metadata and encoding functions in `single-signer-validation/module.ts`.
- Implemented `singleSignerMessageSigner` function in `single-signer-validation/signer.ts` for signing operations.
- Defined the ABI for `singleSignerValidation` in `abis/singleSignerValidation.ts`.
- Added ABI for `MAV2Factory` and `smaV2` in their respective files.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->

feat: add all mav2 contract addrs, abis (#1207)

- [x] Did you add new tests and confirm existing tests pass? (`yarn test`)
- [ ] Did you update relevant docs? (docs are found in the `site` folder, and guidelines for updating/adding docs can be found in the [contribution guide](https://github.com/alchemyplatform/aa-sdk/blob/main/CONTRIBUTING.md))
- [ ] Do your commits follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) standard?
- [ ] Does your PR title also follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) standard?
- [ ] If you have a breaking change, is it [correctly reflected in your commit message](https://www.conventionalcommits.org/en/v1.0.0/#examples)? (e.g. `feat!: breaking change`)
- [ ] Did you run lint (`yarn lint:check`) and fix any issues? (`yarn lint:write`)
- [ ] Did you follow the [contribution guidelines](https://github.com/alchemyplatform/aa-sdk/blob/main/CONTRIBUTING.md)?

<!-- start pr-codex -->

---

This PR focuses on renaming and restructuring various ABI exports and imports in the `account-kit/smart-contracts` project, enhancing clarity and organization in the codebase.

- Renamed `MAV2FactoryAbi` to `accountFactoryAbi` in `accountFactoryAbi.ts`.
- Renamed `smaV2Abi` to `semiModularAccountBytecodeAbi` in `semiModularAccountBytecodeAbi.ts`.
- Renamed `singleSignerValidationAbi` to `singleSignerValidationModuleAbi` in `singleSignerValidationModule.ts`.
- Updated import statement in `module.ts` for `singleSignerValidationModuleAbi`.
- Added new `addresses` export with various module addresses in `utils.ts`.
- Introduced `paymasterGuardModuleAbi` in `paymasterGuardModule.ts`.
- Added `timeRangeModuleAbi` in `timeRangeModule.ts`.
- Added `webauthnValidationModuleAbi` in `webauthnValidation.ts`.
- Added `nativeTokenLimitModuleAbi` in `nativeTokenLimitModule.ts`.
- Added `allowlistModuleAbi` in `allowlistModule.ts`.
- Introduced `modularAccountAbi` in `modularAccountAbi.ts`.
- Introduced `semiModularAccountStorageAbi` in `semiModularAccountStorageAbi.ts`.

> The following files were skipped due to too many changes: `account-kit/smart-contracts/src/ma-v2/abis/semiModularAccountStorageAbi.ts`

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->

feat: add scaffold for ma v2

chore: lint

feat: add scaffold for ma v2

feat: add all mav2 contract addrs, abis (#1207)

- [x] Did you add new tests and confirm existing tests pass? (`yarn test`)
- [ ] Did you update relevant docs? (docs are found in the `site` folder, and guidelines for updating/adding docs can be found in the [contribution guide](https://github.com/alchemyplatform/aa-sdk/blob/main/CONTRIBUTING.md))
- [ ] Do your commits follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) standard?
- [ ] Does your PR title also follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) standard?
- [ ] If you have a breaking change, is it [correctly reflected in your commit message](https://www.conventionalcommits.org/en/v1.0.0/#examples)? (e.g. `feat!: breaking change`)
- [ ] Did you run lint (`yarn lint:check`) and fix any issues? (`yarn lint:write`)
- [ ] Did you follow the [contribution guidelines](https://github.com/alchemyplatform/aa-sdk/blob/main/CONTRIBUTING.md)?

<!-- start pr-codex -->

---

This PR introduces several new smart contract ABIs and address constants for a modular account system, enhancing functionality for various modules, including validation and execution.

- Added `addresses` constant with various module addresses in `addresses.ts`.
- Introduced ABIs for `paymasterGuardModule`, `timeRangeModule`, `webauthnValidation`, `nativeTokenLimitModule`, `allowlistModule`, and `maV2`.
- Each ABI includes functions, events, and errors relevant to their respective modules.

> The following files were skipped due to too many changes: `account-kit/smart-contracts/src/ma-v2/abis/smaStorage.ts`

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->

feat: add mav2 account

feat: add entity id nonce logic

feat: x

feat: a

feat: x
  • Loading branch information
linnall authored and howydev committed Dec 14, 2024
1 parent 1c007cb commit 72a46ce
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions account-kit/smart-contracts/src/ma-v2/account/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import {
concatHex,
encodeFunctionData,
getContract,
type Address,
type Chain,
type Hex,
Expand Down Expand Up @@ -49,6 +50,8 @@ export type CreateSMAV2AccountParams<
initialOwner?: Address;
accountAddress?: Address;
entryPoint?: EntryPointDef<TEntryPointVersion, Chain>;
isGlobalValidation?: boolean;
entityId?: bigint;
};

export async function createSMAV2Account<
Expand All @@ -71,8 +74,14 @@ export async function createSMAV2Account(
initialOwner,
accountAddress,
entryPoint = getEntryPoint(chain, { version: "0.7.0" }),
isGlobalValidation = true,
entityId = 0n,
} = config;

if (entityId >= 2n ** 32n) {
throw new Error("Entity ID must be less than uint32.max");
}

const client = createBundlerClient({
transport,
chain,
Expand Down Expand Up @@ -120,8 +129,36 @@ export async function createSMAV2Account(
),
});

// TODO: add deferred action flag
const getAccountNonce = async (nonceKey?: bigint): Promise<bigint> => {
// uint32 entityId + (bytes1 options) makes a uint40
const nonceKeySuffix: bigint =
entityId * 256n + (isGlobalValidation ? 1n : 0n);

if (nonceKey) {
// comparing the end 40 bytes to suffix
if (nonceKey % 2n ** 40n !== nonceKeySuffix) {
throw new Error("Invalid nonceKey");
}
} else {
nonceKey = nonceKeySuffix;
}

const entryPointContract = getContract({
address: entryPoint.address,
abi: entryPoint.abi,
client,
});

return entryPointContract.read.getNonce([
accountAddress,
nonceKey,
]) as Promise<bigint>;
};

return {
...baseAccount,
getAccountNonce,
getSigner: () => signer,
};
}

0 comments on commit 72a46ce

Please sign in to comment.