diff --git a/account-kit/core/src/types.ts b/account-kit/core/src/types.ts index bf5b9fa17a..a98ed2c092 100644 --- a/account-kit/core/src/types.ts +++ b/account-kit/core/src/types.ts @@ -25,6 +25,8 @@ import type { RNSignerClient, } from "@account-kit/react-native-signer"; import type { Connection as SolanaWeb3Connection } from "@solana/web3.js"; +import type { PolicyToken } from "@account-kit/infra"; + export type SupportedAccountTypes = | "MultiOwnerLightAccount" | "LightAccount" @@ -73,6 +75,7 @@ export type Connection = { transport: AlchemyTransportConfig; chain: Chain; policyId?: string | string[]; + policyToken?: PolicyToken; }; type RpcConnectionConfig = @@ -90,6 +93,7 @@ type RpcConnectionConfig = // When providing multiple chains and no default transport, the signer connection is required signerConnection?: ConnectionConfig; policyId?: never; + policyToken?: never; } | { chain: Chain; @@ -103,12 +107,14 @@ type RpcConnectionConfig = // When providing multiple chains, then the signer connection is required signerConnection: ConnectionConfig; policyId?: never; + policyToken?: never; } | { transport: AlchemyTransport; chain: Chain; solana?: SolanaConnection; policyId?: string | string[]; + policyToken?: PolicyToken; signerConnection?: ConnectionConfig; chains?: never; }; diff --git a/account-kit/infra/src/actions/types.ts b/account-kit/infra/src/actions/types.ts index 7dba66abb8..698ae5fb5f 100644 --- a/account-kit/infra/src/actions/types.ts +++ b/account-kit/infra/src/actions/types.ts @@ -60,7 +60,7 @@ export type RequestGasAndPaymasterAndDataRequest = [ erc20Context?: { tokenAddress: Address; permit?: Hex; - maxTokenAmount?: BigInt; + maxTokenAmount?: number; }; dummySignature: Hex; userOperation: UserOperationRequest; diff --git a/account-kit/infra/src/client/smartAccountClient.ts b/account-kit/infra/src/client/smartAccountClient.ts index 23a15f4d7c..1e53a63358 100644 --- a/account-kit/infra/src/client/smartAccountClient.ts +++ b/account-kit/infra/src/client/smartAccountClient.ts @@ -12,7 +12,7 @@ import { type SmartContractAccountWithSigner, type UserOperationContext, } from "@aa-sdk/core"; -import { type Address, type Chain } from "viem"; +import { type Chain } from "viem"; import { alchemy, convertHeadersToObject, @@ -28,6 +28,7 @@ import { } from "./decorators/smartAccount.js"; import type { AlchemyRpcSchema } from "./types.js"; import { headersUpdate } from "../alchemyTrackerHeaders.js"; +import type { PolicyToken } from "../middleware/gasManager.js"; export function getSignerTypeHeader< TAccount extends SmartContractAccountWithSigner, @@ -48,13 +49,7 @@ export type AlchemySmartAccountClientConfig< account?: account; useSimulation?: boolean; policyId?: string | string[]; - policyToken?: { - address: Address; - maxTokenAmount: bigint; - approvalMode?: "NONE" | "PERMIT"; - erc20Name?: string; - version?: string; - }; + policyToken?: PolicyToken; } & Pick< SmartAccountClientConfig, | "customMiddleware" diff --git a/account-kit/infra/src/index.ts b/account-kit/infra/src/index.ts index 8468304a69..2866f199fd 100644 --- a/account-kit/infra/src/index.ts +++ b/account-kit/infra/src/index.ts @@ -68,6 +68,7 @@ export * from "./alchemyTrackerHeaders.js"; export { alchemyGasManagerMiddleware, alchemyGasAndPaymasterAndDataMiddleware, + type PolicyToken, } from "./middleware/gasManager.js"; export { alchemyUserOperationSimulator } from "./middleware/userOperationSimulator.js"; export type * from "./schema.js"; diff --git a/account-kit/infra/src/middleware/gasManager.ts b/account-kit/infra/src/middleware/gasManager.ts index c4337e3058..ae0c407ded 100644 --- a/account-kit/infra/src/middleware/gasManager.ts +++ b/account-kit/infra/src/middleware/gasManager.ts @@ -34,6 +34,7 @@ import type { AlchemySmartAccountClient } from "../client/smartAccountClient.js" import type { AlchemyTransport } from "../alchemyTransport.js"; import { alchemyFeeEstimator } from "./feeEstimator.js"; import type { RequestGasAndPaymasterAndDataRequest } from "../actions/types.js"; + import { PermitTypes, EIP7597Abis, @@ -47,10 +48,20 @@ type Context = { policyId: string | string[]; erc20Context?: { tokenAddress: Address; - maxTokenAmount?: BigInt; + maxTokenAmount?: number; permit?: Hex; }; }; + +export type PolicyToken = { + address: Address; + maxTokenAmount: number; + paymasterAddress?: Address; + approvalMode?: "NONE" | "PERMIT"; + erc20Name?: string; + version?: string; +}; + /** * Paymaster middleware factory that uses Alchemy's Gas Manager for sponsoring * transactions. Adheres to the ERC-7677 standardized communication protocol. @@ -127,15 +138,6 @@ interface AlchemyGasAndPaymasterAndDataMiddlewareParams { feeEstimatorOverride?: ClientMiddlewareFn; } -export type PolicyToken = { - address: Address; - maxTokenAmount: bigint; - paymasterAddress?: Address; - approvalMode?: "NONE" | "PERMIT"; - erc20Name?: string; - version?: string; -}; - /** * Paymaster middleware factory that uses Alchemy's Gas Manager for sponsoring * transactions. Uses Alchemy's custom `alchemy_requestGasAndPaymasterAndData` @@ -379,7 +381,7 @@ const generateSignedPermit = async ( account: TAccount, policyToken: { address: Address; - maxTokenAmount: bigint; + maxTokenAmount: number; paymasterAddress?: Address; approvalMode?: "NONE" | "PERMIT"; erc20Name?: string; @@ -423,8 +425,8 @@ const generateSignedPermit = async ( } const decimals = - 10n ** (decimalsResponse.data ? BigInt(decimalsResponse.data) : 18n); - const maxAmountToken = policyToken.maxTokenAmount * decimals; + 10 ** (decimalsResponse.data ? Number(decimalsResponse.data) : 18); + const maxRawAmountToken = BigInt(policyToken.maxTokenAmount * decimals); const nonce = BigInt(nonceResponse.data); const paymasterAddress = @@ -449,7 +451,7 @@ const generateSignedPermit = async ( message: { owner: account.address, spender: paymasterAddress, - value: maxAmountToken, + value: maxRawAmountToken, nonce: nonce, deadline, } satisfies PermitMessage, @@ -458,6 +460,6 @@ const generateSignedPermit = async ( const signedPermit = await account.signTypedData(typedPermitData); return encodeAbiParameters( [{ type: "uint256" }, { type: "uint256" }, { type: "bytes" }], - [maxAmountToken, deadline, signedPermit], + [maxRawAmountToken, deadline, signedPermit], ); }; diff --git a/docs/README.md b/docs/README.md index 1104725eec..4450ff8790 100644 --- a/docs/README.md +++ b/docs/README.md @@ -51,7 +51,7 @@ To add new images: SDK References are automatically generated from relevant projects within the monorepo via the `docs-gen` package. Both the markdown files and the sidebar structure in `docs/docs.yml` are generated and should **not** be edited manually. In the root, to generate references from code you can run: ```shell -yarn fern-gen +yarn fern:gen ``` ### Injected Code Snippets diff --git a/docs/specs/openrpc/_shared_wallets/components.yaml b/docs/specs/openrpc/_shared_wallets/components.yaml index 9efd1b1292..29d9d64d0c 100644 --- a/docs/specs/openrpc/_shared_wallets/components.yaml +++ b/docs/specs/openrpc/_shared_wallets/components.yaml @@ -390,7 +390,7 @@ components: description: "Erc20 contract address" maxTokenAmount: $ref: "#/components/schemas/positiveDecimal" - description: "Maximum allowed amount of value in USD" + description: "Maximum allowed amount of value in token" permit: $ref: "#/components/schemas/bytes" description: "A 7597 typed permit" diff --git a/examples/ui-demo/src/components/modals/Erc20/utils.ts b/examples/ui-demo/src/components/modals/Erc20/utils.ts index 58eed6d0a2..9427d9082d 100644 --- a/examples/ui-demo/src/components/modals/Erc20/utils.ts +++ b/examples/ui-demo/src/components/modals/Erc20/utils.ts @@ -13,7 +13,7 @@ const erc20Abi = parseAbi([ const nftAbi = parseAbi(["function mintTo(address to)"]); // Amount of USDC to approve for gas payment (e.g., 100 USDC, 100 * 10^6) -export const USDC_GAS_APPROVAL_AMOUNT = BigInt(100_000_000); +export const USDC_GAS_APPROVAL_AMOUNT = 100_000_000; const NFT_MINT_PRICE = BigInt(1_000_000); // 1 USDC for mint price (1 * 10^6) export async function getNftMintBatchUOs(accountAddress: Address) { @@ -21,7 +21,7 @@ export async function getNftMintBatchUOs(accountAddress: Address) { const approveGasSponsorshipCallData = encodeFunctionData({ abi: erc20Abi, functionName: "approve", - args: [ALCHEMY_PAYMASTER_ADDRESS, USDC_GAS_APPROVAL_AMOUNT], + args: [ALCHEMY_PAYMASTER_ADDRESS, BigInt(USDC_GAS_APPROVAL_AMOUNT)], }); // 2. Approve the NFT contract to spend USDC for the mint price diff --git a/examples/ui-demo/src/hooks/useModularAccountV2Client.ts b/examples/ui-demo/src/hooks/useModularAccountV2Client.ts index d9f2b749ba..edf5d76110 100644 --- a/examples/ui-demo/src/hooks/useModularAccountV2Client.ts +++ b/examples/ui-demo/src/hooks/useModularAccountV2Client.ts @@ -14,14 +14,6 @@ import { Chain, Hex, Address, PrivateKeyAccount } from "viem"; import { LocalAccountSigner } from "@aa-sdk/core"; import { privateKeyToAccount } from "viem/accounts"; -interface PolicyToken { - address: Address; - maxTokenAmount: bigint; - approvalMode?: "PERMIT" | "NONE"; - erc20Name?: string; - version?: string; -} - type Client = ModularAccountV2Client< AlchemySigner | LocalAccountSigner > & @@ -29,6 +21,14 @@ type Client = ModularAccountV2Client< ModularAccountV2> >; +interface PolicyToken { + address: Address; + maxTokenAmount: number; + approvalMode?: "PERMIT" | "NONE"; + erc20Name?: string; + version?: string; +} + // Hook that creates an MAv2 client that can be used for things that // @account-kit/react doesn't yet support, such as session keys. export const useModularAccountV2Client = ({