Skip to content

Commit

Permalink
Remove validatorAddres argument
Browse files Browse the repository at this point in the history
  • Loading branch information
cygaar committed Sep 22, 2024
1 parent 43e0d06 commit eb0fd86
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 119 deletions.
26 changes: 9 additions & 17 deletions packages/agw-client/src/actions/deployContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
type Account,
type Client,
type ContractConstructorArgs,
type Hex,
type PublicClient,
type Transport,
type WalletClient,
Expand Down Expand Up @@ -36,7 +35,6 @@ export function deployContract<
chainOverride,
allArgs
>,
validatorAddress: Hex,
): Promise<DeployContractReturnType> {
const { abi, args, bytecode, deploymentType, salt, ...request } =
parameters as DeployContractParameters;
Expand All @@ -54,19 +52,13 @@ export function deployContract<
if (!request.factoryDeps.includes(bytecode))
request.factoryDeps.push(bytecode);

return sendTransaction(
walletClient,
signerClient,
publicClient,
{
...request,
data,
to: CONTRACT_DEPLOYER_ADDRESS,
} as unknown as SendEip712TransactionParameters<
chain,
account,
chainOverride
>,
validatorAddress,
);
return sendTransaction(walletClient, signerClient, publicClient, {
...request,
data,
to: CONTRACT_DEPLOYER_ADDRESS,
} as unknown as SendEip712TransactionParameters<
chain,
account,
chainOverride
>);
}
9 changes: 3 additions & 6 deletions packages/agw-client/src/actions/sendTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import AccountFactoryAbi from '../abis/AccountFactory.js';
import {
BATCH_CALLER_ADDRESS,
SMART_ACCOUNT_FACTORY_ADDRESS,
VALIDATOR_ADDRESS,
} from '../constants.js';
import { type Call } from '../types/call.js';
import { getInitializerCalldata, isSmartAccountDeployed } from '../utils.js';
Expand All @@ -48,7 +49,6 @@ export async function sendTransactionBatch<
signerClient: WalletClient<Transport, ChainEIP712, Account>,
publicClient: PublicClient<Transport, ChainEIP712>,
parameters: SendTransactionBatchParameters<request>,
validatorAddress: Hex,
): Promise<SendTransactionReturnType> {
if (parameters.calls.length === 0) {
throw new Error('No calls provided');
Expand Down Expand Up @@ -110,7 +110,7 @@ export async function sendTransactionBatch<
// Create calldata for initializing the proxy account
const initializerCallData = getInitializerCalldata(
signerClient.account.address,
validatorAddress,
VALIDATOR_ADDRESS,
initialCall,
);
const addressBytes = toBytes(signerClient.account.address);
Expand Down Expand Up @@ -145,7 +145,6 @@ export async function sendTransactionBatch<
signerClient,
publicClient,
batchTransaction,
validatorAddress,
!isDeployed,
);
}
Expand All @@ -168,7 +167,6 @@ export async function sendTransaction<
chainOverride,
request
>,
validatorAddress: Hex,
): Promise<SendEip712TransactionReturnType> {
const isDeployed = await isSmartAccountDeployed(
publicClient,
Expand All @@ -185,7 +183,7 @@ export async function sendTransaction<
// Create calldata for initializing the proxy account
const initializerCallData = getInitializerCalldata(
signerClient.account.address,
validatorAddress,
VALIDATOR_ADDRESS,
initialCall,
);
const addressBytes = toBytes(signerClient.account.address);
Expand All @@ -207,7 +205,6 @@ export async function sendTransaction<
signerClient,
publicClient,
parameters,
validatorAddress,
!isDeployed,
);
}
3 changes: 0 additions & 3 deletions packages/agw-client/src/actions/sendTransactionInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
type Account,
type Chain,
type Client,
type Hex,
type PublicClient,
type SendTransactionRequest,
type Transport,
Expand Down Expand Up @@ -44,7 +43,6 @@ export async function sendTransactionInternal<
chainOverride,
request
>,
validatorAddress: Hex,
isInitialTransaction: boolean,
): Promise<SendEip712TransactionReturnType> {
const { chain = client.chain } = parameters;
Expand Down Expand Up @@ -86,7 +84,6 @@ export async function sendTransactionInternal<
...request,
chainId,
} as any,

Check warning on line 86 in packages/agw-client/src/actions/sendTransactionInternal.ts

View workflow job for this annotation

GitHub Actions / publish

Unexpected any. Specify a different type
validatorAddress,
isInitialTransaction,
);

Expand Down
5 changes: 2 additions & 3 deletions packages/agw-client/src/actions/signTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
BaseError,
type Client,
encodeAbiParameters,
type Hex,
parseAbiParameters,
type Transport,
type WalletClient,
Expand All @@ -17,6 +16,7 @@ import {
type SignEip712TransactionReturnType,
} from 'viem/zksync';

import { VALIDATOR_ADDRESS } from '../constants.js';
import {
assertEip712Request,
type AssertEip712RequestParameters,
Expand All @@ -33,7 +33,6 @@ export async function signTransaction<
client: Client<Transport, ChainEIP712, Account>,
signerClient: WalletClient<Transport, ChainEIP712, Account>,
args: SignEip712TransactionParameters<chain, account, chainOverride>,
validatorAddress: Hex,
useSignerAddress = false,
): Promise<SignEip712TransactionReturnType> {
const {
Expand Down Expand Up @@ -95,7 +94,7 @@ export async function signTransaction<
// Match the expect signature format of the AGW smart account
signature = encodeAbiParameters(
parseAbiParameters(['bytes', 'address', 'bytes[]']),
[rawSignature, validatorAddress, []],
[rawSignature, VALIDATOR_ADDRESS, []],
);
}

Expand Down
20 changes: 6 additions & 14 deletions packages/agw-client/src/actions/writeContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
type ContractFunctionName,
encodeFunctionData,
type EncodeFunctionDataParameters,
type Hex,
type PublicClient,
type Transport,
type WalletClient,
Expand Down Expand Up @@ -43,7 +42,6 @@ export async function writeContract<
account,
chainOverride
>,
validatorAddress: Hex,
): Promise<WriteContractReturnType> {
const {
abi,
Expand All @@ -68,18 +66,12 @@ export async function writeContract<
} as EncodeFunctionDataParameters);

try {
return await sendTransaction(
client,
signerClient,
publicClient,
{
data: `${data}${dataSuffix ? dataSuffix.replace('0x', '') : ''}`,
to: address,
account,
...request,
},
validatorAddress,
);
return await sendTransaction(client, signerClient, publicClient, {
data: `${data}${dataSuffix ? dataSuffix.replace('0x', '') : ''}`,
to: address,
account,
...request,
});
} catch (error) {
throw getContractError(error as BaseError, {
abi,
Expand Down
30 changes: 3 additions & 27 deletions packages/agw-client/src/walletActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
} from './actions/sendTransaction.js';
import { signTransaction } from './actions/signTransaction.js';
import { writeContract } from './actions/writeContract.js';
import { VALIDATOR_ADDRESS } from './constants.js';

export type AbstractWalletActions<
chain extends ChainEIP712 | undefined = ChainEIP712 | undefined,
Expand All @@ -45,7 +44,6 @@ export function globalWalletActions<
signerClient: WalletClient<Transport, ChainEIP712, Account>,
publicClient: PublicClient<Transport, ChainEIP712>,
) {
const validatorAddress = VALIDATOR_ADDRESS;
return (
client: Client<Transport, ChainEIP712, Account>,
): AbstractWalletActions<Chain, Account> => ({
Expand All @@ -55,44 +53,23 @@ export function globalWalletActions<
signerClient,
publicClient,
args as SendEip712TransactionParameters<chain, account>,
validatorAddress,
),
sendTransactionBatch: (args) =>
sendTransactionBatch(
client,
signerClient,
publicClient,
args,
validatorAddress,
),
sendTransactionBatch(client, signerClient, publicClient, args),
signTransaction: (args) =>
signTransaction(
client,
signerClient,
args as SignEip712TransactionParameters<chain, account>,
validatorAddress,
),
deployContract: (args) =>
deployContract(
client,
signerClient,
publicClient,
args,
validatorAddress,
),
deployContract(client, signerClient, publicClient, args),
writeContract: (args) =>
writeContract(
Object.assign(client, {
sendTransaction: (
args: SendEip712TransactionParameters<chain, account>,
) =>
sendTransaction(
client,
signerClient,
publicClient,
args,
validatorAddress,
),
) => sendTransaction(client, signerClient, publicClient, args),
}),
signerClient,
publicClient,
Expand All @@ -103,7 +80,6 @@ export function globalWalletActions<
ChainEIP712,
Account
>,
validatorAddress,
),
});
}
4 changes: 0 additions & 4 deletions packages/agw-client/test/src/actions/deployContract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ test('create2 with factoryDeps', async () => {
deploymentType: 'create2',
salt: MOCK_SALT,
},
address.validatorAddress,
);

expect(transactionHash).toBe('0xmockedTransactionHash');
Expand All @@ -98,7 +97,6 @@ test('create2 with factoryDeps', async () => {
factoryDeps: [contractBytecode],
to: CONTRACT_DEPLOYER_ADDRESS,
},
address.validatorAddress,
);
});

Expand All @@ -124,7 +122,6 @@ test('create2 with no chain and no account', async () => {
deploymentType: 'create2',
salt: MOCK_SALT,
},
address.validatorAddress,
);

expect(transactionHash).toBe('0xmockedTransactionHash');
Expand All @@ -140,6 +137,5 @@ test('create2 with no chain and no account', async () => {
factoryDeps: [contractBytecode],
to: CONTRACT_DEPLOYER_ADDRESS,
},
address.validatorAddress,
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import {
BATCH_CALLER_ADDRESS,
SMART_ACCOUNT_FACTORY_ADDRESS,
VALIDATOR_ADDRESS,
} from '../../../../src/constants.js';
import {
getInitializerCalldata,
Expand Down Expand Up @@ -123,7 +124,6 @@ describe('sendTransaction', () => {
account: baseClient.account,
chain: anvilAbstractTestnet.chain as ChainEIP712,
} as any,
address.validatorAddress,
);

if (shouldCallEncodeFunctionData) {
Expand All @@ -150,7 +150,6 @@ describe('sendTransaction', () => {
account: baseClient.account,
chain: anvilAbstractTestnet.chain as ChainEIP712,
}),
address.validatorAddress,
!isDeployed,
);
expect(transactionHash).toBe('0xmockedTransactionHash');
Expand Down Expand Up @@ -243,7 +242,6 @@ describe('sendTransactionBatch', () => {
paymaster: '0x5407B5040dec3D339A9247f3654E59EEccbb6391',
paymasterInput: '0xabc',
} as any,
address.validatorAddress,
);

expect(encodeFunctionData).toHaveBeenCalledTimes(
Expand All @@ -262,7 +260,7 @@ describe('sendTransactionBatch', () => {
// Verify that getInitializerCalldata is called with the correct arguments
expect(getInitializerCalldata).toHaveBeenCalledWith(
address.signerAddress,
address.validatorAddress,
VALIDATOR_ADDRESS,
{
target: BATCH_CALLER_ADDRESS,
allowFailure: false,
Expand Down Expand Up @@ -300,7 +298,6 @@ describe('sendTransactionBatch', () => {
paymasterInput: '0xabc',
value: BigInt(1000),
}),
address.validatorAddress,
!isDeployed,
);
expect(transactionHash).toBe('0xmockedTransactionHash');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ describe('sendTransactionInternal', () => {
account: baseClient.account,
chain: anvilAbstractTestnet.chain as ChainEIP712,
} as any,
address.validatorAddress,
isInitialTransaction,
);

Expand All @@ -132,7 +131,6 @@ describe('sendTransactionInternal', () => {
paymasterInput: '0x',
chainId: abstractTestnet.id,
}),
address.validatorAddress,
isInitialTransaction,
);

Expand Down Expand Up @@ -163,7 +161,6 @@ test('sendTransactionInternal with mismatched chain', async () => {
account: baseClient.account,
chain: invalidChain,
} as any,
address.validatorAddress,
false,
),
).rejects.toThrowError('Current Chain ID: 11124');
Expand Down
Loading

0 comments on commit eb0fd86

Please sign in to comment.