Skip to content

Commit 4247bcd

Browse files
committed
Merge branch 'main' into feat/scopes
2 parents dee7c69 + 41626fc commit 4247bcd

38 files changed

Lines changed: 495 additions & 425 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"prettier": "^3.3.3",
5353
"turbo": "latest",
5454
"typescript": "5.0.4",
55-
"viem": "2.21.55",
55+
"viem": "^2.31.4",
5656
"webauthn-p256": "^0.0.10"
5757
},
5858
"packageManager": "yarn@4.2.2",

packages/delegation-toolkit/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@
139139
"tsconfig-paths": "^4.2.0",
140140
"tsup": "^8.5.0",
141141
"typescript": "5.0.4",
142-
"viem": "2.21.55",
142+
"viem": "2.31.4",
143143
"vitest": "^3.2.4"
144144
},
145145
"peerDependencies": {
146-
"viem": ">=2.18.2 <3.0.0"
146+
"viem": "^2.31.4"
147147
}
148148
}

packages/delegation-toolkit/src/experimental/erc7710RedeemDelegationAction.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,15 @@ export async function sendTransactionWithDelegationAction<
7979
],
8080
});
8181

82+
const {
83+
value: _value,
84+
permissionsContext: _permissionsContext,
85+
delegationManager: _delegationManager,
86+
...rest
87+
} = args;
88+
8289
const hash = await client.sendTransaction({
83-
...args,
90+
...rest,
8491
to: args.delegationManager,
8592
data: calldata,
8693
} as unknown as SendTransactionParameters);

packages/delegation-toolkit/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import type {
88
Account,
99
Address,
1010
Chain,
11-
Client,
1211
Hex,
1312
OneOf,
13+
PublicClient,
1414
Transport,
1515
WalletClient,
1616
} from 'viem';
@@ -143,7 +143,7 @@ export type DeployParams<TImplementation extends Implementation> = {
143143
export type ToMetaMaskSmartAccountParameters<
144144
TImplementation extends Implementation,
145145
> = {
146-
client: Client;
146+
client: PublicClient;
147147
implementation: TImplementation;
148148
signatory: SignatoryConfigByImplementation<TImplementation>;
149149
environment?: DeleGatorEnvironment;

packages/delegation-toolkit/test/experimental/erc7710RedeemDelegationAction.test.ts

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import type {
88
WalletClient,
99
} from 'viem';
1010
import {
11-
createClient,
1211
createPublicClient,
1312
createWalletClient,
1413
custom,
@@ -65,10 +64,7 @@ describe('erc7710RedeemDelegationAction', () => {
6564
});
6665

6766
metaMaskSmartAccount = await toMetaMaskSmartAccount({
68-
client: createClient({
69-
transport: custom({ request: async () => '0x' }),
70-
chain,
71-
}),
67+
client: publicClient,
7268
implementation: Implementation.MultiSig,
7369
signatory: [{ account: owner }],
7470
deployParams: [[owner.address], 1n],
@@ -318,15 +314,20 @@ describe('erc7710RedeemDelegationAction', () => {
318314
],
319315
});
320316

317+
const { delegationManager } = args;
318+
321319
const expectedArgs = {
322-
...args,
323-
to: args.delegationManager,
320+
account,
321+
chain,
322+
to: delegationManager,
323+
// value is not passed to sendTransaction
324324
data: redeemDelegationCallData,
325+
// permissionsContext and delegationManager are not passed to sendTransaction
325326
};
326327

327-
expect(sendTransaction.calledOnceWithExactly(expectedArgs)).to.equal(
328-
true,
329-
);
328+
expect(sendTransaction.calledOnce).to.equal(true);
329+
330+
expect(sendTransaction.firstCall.args[0]).to.deep.equal(expectedArgs);
330331
});
331332

332333
it('should throw an error when `to` is not provided', async () => {
@@ -345,5 +346,33 @@ describe('erc7710RedeemDelegationAction', () => {
345346
'`to` is required. `sendTransactionWithDelegation` cannot be used to deploy contracts.',
346347
);
347348
});
349+
350+
it('should not encode the specified `value`, `permissionsContext` and `delegationManager` into the resulting transaction', async () => {
351+
const extendedWalletClient = walletClient.extend(erc7710WalletActions());
352+
353+
const sendTransaction = stub(walletClient, 'sendTransaction');
354+
355+
const args: SendTransactionWithDelegationParameters = {
356+
account,
357+
chain,
358+
to: randomAddress(),
359+
value: 100n,
360+
data: randomBytes(128),
361+
permissionsContext: randomBytes(128),
362+
delegationManager: randomAddress(),
363+
};
364+
365+
await extendedWalletClient.sendTransactionWithDelegation(args);
366+
367+
expect(sendTransaction.calledOnce).to.equal(true);
368+
const sendTransactionArgs = sendTransaction.firstCall.args[0];
369+
expect(sendTransactionArgs.value).to.equal(undefined);
370+
expect((sendTransactionArgs as any).permissionsContext).to.equal(
371+
undefined,
372+
);
373+
expect((sendTransactionArgs as any).delegationManager).to.equal(
374+
undefined,
375+
);
376+
});
348377
});
349378
});

packages/delegation-toolkit/test/toMetaMaskSmartAccount.test.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { Account, Client } from 'viem';
1+
import type { Account, PublicClient } from 'viem';
22
import {
3-
createClient,
3+
createPublicClient,
44
custom,
55
hashTypedData,
66
isAddress,
@@ -19,7 +19,7 @@ import type { DeleGatorEnvironment, MetaMaskSmartAccount } from '../src/types';
1919
import { SIGNABLE_USER_OP_TYPED_DATA } from '../src/userOp';
2020

2121
describe('MetaMaskSmartAccount', () => {
22-
let client: Client;
22+
let publicClient: PublicClient;
2323
let alice: Account;
2424
let bob: Account;
2525
let environment: DeleGatorEnvironment;
@@ -28,7 +28,8 @@ describe('MetaMaskSmartAccount', () => {
2828
const transport = custom({
2929
request: async () => '0x',
3030
});
31-
client = createClient({ transport, chain });
31+
publicClient = createPublicClient({ transport, chain });
32+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
3233

3334
environment = {
3435
SimpleFactory: randomAddress(),
@@ -48,7 +49,7 @@ describe('MetaMaskSmartAccount', () => {
4849
// note derivation of the correctness of counterfactual account data is validated in counterfactualAccountData.test.ts
4950
it('creates a MetaMaskSmartAccount for Hybrid implementation', async () => {
5051
const smartAccount = await toMetaMaskSmartAccount({
51-
client,
52+
client: publicClient,
5253
implementation: Implementation.Hybrid,
5354
deployParams: [alice.address, [], [], []],
5455
deploySalt: '0x0',
@@ -65,7 +66,7 @@ describe('MetaMaskSmartAccount', () => {
6566

6667
it('creates a MetaMaskSmartAccount for MultiSig implementation', async () => {
6768
const smartAccount = await toMetaMaskSmartAccount({
68-
client,
69+
client: publicClient,
6970
implementation: Implementation.MultiSig,
7071
deployParams: [[alice.address, bob.address], 2n],
7172
deploySalt: '0x0',
@@ -82,7 +83,7 @@ describe('MetaMaskSmartAccount', () => {
8283

8384
it('creates a MetaMaskSmartAccount for Stateless7702 implementation with existing address', async () => {
8485
const smartAccount = await toMetaMaskSmartAccount({
85-
client,
86+
client: publicClient,
8687
implementation: Implementation.Stateless7702,
8788
address: alice.address,
8889
signatory: { account: alice },
@@ -102,7 +103,7 @@ describe('MetaMaskSmartAccount', () => {
102103
it('throws error when creating Stateless7702 without address (counterfactual not supported)', async () => {
103104
await expect(
104105
toMetaMaskSmartAccount({
105-
client,
106+
client: publicClient,
106107
implementation: Implementation.Stateless7702,
107108
signatory: { account: alice },
108109
environment,
@@ -115,7 +116,7 @@ describe('MetaMaskSmartAccount', () => {
115116
it('throws an error for unsupported implementation', async () => {
116117
await expect(
117118
toMetaMaskSmartAccount({
118-
client,
119+
client: publicClient,
119120
implementation: 99 as any as Implementation,
120121
deployParams: [alice.address, [], [], []],
121122
deploySalt: '0x0',
@@ -128,7 +129,7 @@ describe('MetaMaskSmartAccount', () => {
128129
it('has a default for MetaMaskSmartAccount generic TImplementation parameter', async () => {
129130
// MetaMaskSmartAccount requires a generic parameter, and defaults to `Implementation` which covers all implementations
130131
const smartAccount: MetaMaskSmartAccount = await toMetaMaskSmartAccount({
131-
client,
132+
client: publicClient,
132133
implementation: Implementation.MultiSig,
133134
deployParams: [[alice.address, bob.address], 2n],
134135
deploySalt: '0x0',
@@ -142,7 +143,7 @@ describe('MetaMaskSmartAccount', () => {
142143
describe('signUserOperation()', () => {
143144
it('signs a user operation for MultiSig implementation', async () => {
144145
const smartAccount = await toMetaMaskSmartAccount({
145-
client,
146+
client: publicClient,
146147
implementation: Implementation.MultiSig,
147148
deployParams: [[alice.address, bob.address], 2n],
148149
deploySalt: '0x0',
@@ -188,7 +189,7 @@ describe('MetaMaskSmartAccount', () => {
188189

189190
it('signs a user operation for Hybrid implementation', async () => {
190191
const smartAccount = await toMetaMaskSmartAccount({
191-
client,
192+
client: publicClient,
192193
implementation: Implementation.Hybrid,
193194
deployParams: [alice.address, [], [], []],
194195
deploySalt: '0x0',
@@ -234,7 +235,7 @@ describe('MetaMaskSmartAccount', () => {
234235

235236
it('signs a user operation for Stateless7702 implementation', async () => {
236237
const smartAccount = await toMetaMaskSmartAccount({
237-
client,
238+
client: publicClient,
238239
implementation: Implementation.Stateless7702,
239240
address: alice.address,
240241
signatory: { account: alice },

packages/delegation-toolkit/test/utils.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import { bytesToHex, getAddress } from 'viem';
2-
import type {
3-
Chain,
4-
Hex,
5-
WalletClient,
6-
PublicClient,
7-
Account,
8-
Client,
9-
} from 'viem';
2+
import type { Chain, Hex, WalletClient, PublicClient, Account } from 'viem';
103
import {
114
generatePrivateKey,
125
privateKeyToAccount,
@@ -48,7 +41,7 @@ export const randomBytes = (byteLength: number): Hex => {
4841

4942
export const counterfactualAccountConfig: ToMetaMaskSmartAccountParameters<Implementation.Hybrid> =
5043
{
51-
client: {} as Client,
44+
client: {} as PublicClient,
5245
implementation: Implementation.Hybrid,
5346
deployParams: [
5447
OWNER_ACCOUNT.address,
@@ -62,7 +55,7 @@ export const counterfactualAccountConfig: ToMetaMaskSmartAccountParameters<Imple
6255

6356
export const multiSigAccountConfig: ToMetaMaskSmartAccountParameters<Implementation.MultiSig> =
6457
{
65-
client: {} as Client,
58+
client: {} as PublicClient,
6659
implementation: Implementation.MultiSig,
6760
deployParams: [[OWNER_ACCOUNT.address], 1n],
6861
deploySalt: SALT,
@@ -71,7 +64,7 @@ export const multiSigAccountConfig: ToMetaMaskSmartAccountParameters<Implementat
7164

7265
export const deployedAccountConfig: ToMetaMaskSmartAccountParameters<Implementation.Hybrid> =
7366
{
74-
client: {} as Client,
67+
client: {} as PublicClient,
7568
implementation: Implementation.Hybrid,
7669
address: DEPLOYED_ADDRESS,
7770
signatory: { account: OWNER_ACCOUNT },

packages/delegator-e2e/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
"teardown": "docker compose down"
2222
},
2323
"peerDependencies": {
24-
"viem": ">=2.18.2 <3.0.0"
24+
"viem": "^2.31.4"
2525
}
2626
}

packages/delegator-e2e/test/caveats/allowedCalldata.test.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,29 @@ import {
1414
encodePermissionContexts,
1515
} from '@metamask/delegation-toolkit/utils';
1616
import {
17-
transport,
1817
gasPrice,
1918
sponsoredBundlerClient,
2019
deploySmartAccount,
2120
deployCounter,
2221
CounterContract,
2322
randomBytes,
23+
publicClient,
24+
stringToUnprefixedHex,
2425
} from '../utils/helpers';
25-
import {
26-
createClient,
27-
encodeFunctionData,
28-
Hex,
29-
hexToBigInt,
30-
slice,
31-
} from 'viem';
26+
import { encodeFunctionData, Hex, hexToBigInt, slice } from 'viem';
3227
import { expectUserOperationToSucceed } from '../utils/assertions';
3328
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
34-
import { chain } from '../../src/config';
3529

36-
let aliceSmartAccount: MetaMaskSmartAccount<Implementation.Hybrid>;
37-
let bobSmartAccount: MetaMaskSmartAccount<Implementation.Hybrid>;
30+
let aliceSmartAccount: MetaMaskSmartAccount;
31+
let bobSmartAccount: MetaMaskSmartAccount;
3832
let aliceCounter: CounterContract;
3933

4034
beforeEach(async () => {
41-
const client = createClient({ transport, chain });
4235
const alice = privateKeyToAccount(generatePrivateKey());
4336
const bob = privateKeyToAccount(generatePrivateKey());
4437

4538
aliceSmartAccount = await toMetaMaskSmartAccount({
46-
client,
39+
client: publicClient,
4740
implementation: Implementation.Hybrid,
4841
deployParams: [alice.address, [], [], []],
4942
deploySalt: '0x1',
@@ -53,7 +46,7 @@ beforeEach(async () => {
5346
await deploySmartAccount(aliceSmartAccount);
5447

5548
bobSmartAccount = await toMetaMaskSmartAccount({
56-
client,
49+
client: publicClient,
5750
implementation: Implementation.Hybrid,
5851
deployParams: [bob.address, [], [], []],
5952
deploySalt: '0x1',
@@ -268,7 +261,7 @@ const runTest_expectFailure = async (
268261
],
269262
...gasPrice,
270263
}),
271-
).rejects.toThrow(expectedError);
264+
).rejects.toThrow(stringToUnprefixedHex(expectedError));
272265

273266
const counterAfter = await aliceCounter.read.count?.();
274267
expect(counterAfter, 'Expected count to remain 0n').toEqual(0n);

0 commit comments

Comments
 (0)