Skip to content

Commit

Permalink
chore: import only ethers methods used + address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ42 committed Feb 29, 2024
1 parent 17bba8d commit d4fa3cb
Show file tree
Hide file tree
Showing 33 changed files with 314 additions and 316 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ forge-cache/
gas_benchmark.md

# Exclude build output folders
/common
/module
/contracts.ts
/**/contracts.ts
/devdocs
/userdocs

Expand Down
10 changes: 4 additions & 6 deletions dodoc/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ethers } from 'ethers';
import { keccak256, toUtf8Bytes } from 'ethers';
import { HelperContent } from 'squirrelly/dist/types/containers';

export const dodocConfig = {
Expand Down Expand Up @@ -331,9 +331,7 @@ const generateAdditionalMethodInfo = (contract: string, code: string) => {
) {
infoBlock +=
`- Function signature: \`${formatedCode}\`\n` +
`- Function selector: \`${ethers
.keccak256(ethers.toUtf8Bytes(formatedCode))
.substring(0, 10)}\``;
`- Function selector: \`${keccak256(toUtf8Bytes(formatedCode)).substring(0, 10)}\``;
}

return infoBlock;
Expand All @@ -350,7 +348,7 @@ const generateAdditionalEventInfo = (contract: string, code: string) => {
.toLowerCase()})\n` +
`- Solidity implementation: [\`${contract}.sol\`](${contractLink})\n` +
`- Event signature: \`${formatedCode}\`\n` +
`- Event topic hash: \`${ethers.keccak256(ethers.toUtf8Bytes(formatedCode))}\``
`- Event topic hash: \`${keccak256(toUtf8Bytes(formatedCode))}\``
);
};

Expand All @@ -365,7 +363,7 @@ const generateAdditionalErrorInfo = (contract: string, code: string) => {
.toLowerCase()})\n` +
`- Solidity implementation: [\`${contract}.sol\`](${contractLink})\n` +
`- Error signature: \`${formatedCode}\`\n` +
`- Error hash: \`${ethers.keccak256(ethers.toUtf8Bytes(formatedCode)).substring(0, 10)}\``
`- Error hash: \`${keccak256(toUtf8Bytes(formatedCode)).substring(0, 10)}\``
);
};

Expand Down
2 changes: 1 addition & 1 deletion packages/lsp0-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
2 changes: 1 addition & 1 deletion packages/lsp1-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
2 changes: 1 addition & 1 deletion packages/lsp10-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
2 changes: 1 addition & 1 deletion packages/lsp12-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
2 changes: 1 addition & 1 deletion packages/lsp14-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
2 changes: 1 addition & 1 deletion packages/lsp16-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
2 changes: 1 addition & 1 deletion packages/lsp17-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
2 changes: 1 addition & 1 deletion packages/lsp1delegate-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
2 changes: 1 addition & 1 deletion packages/lsp2-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
2 changes: 1 addition & 1 deletion packages/lsp20-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
2 changes: 1 addition & 1 deletion packages/lsp23-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
2 changes: 1 addition & 1 deletion packages/lsp25-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
2 changes: 1 addition & 1 deletion packages/lsp3-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
2 changes: 1 addition & 1 deletion packages/lsp4-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
2 changes: 1 addition & 1 deletion packages/lsp5-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
2 changes: 1 addition & 1 deletion packages/lsp6-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
2 changes: 1 addition & 1 deletion packages/lsp7-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
2 changes: 1 addition & 1 deletion packages/lsp8-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
2 changes: 1 addition & 1 deletion packages/lsp9-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
2 changes: 1 addition & 1 deletion packages/universalprofile-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
4 changes: 2 additions & 2 deletions scripts/ci/docs-generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs';
import path from 'path';
import { task } from 'hardhat/config';
import { TASK_COMPILE } from 'hardhat/builtin-tasks/task-names';
import { ethers } from 'ethers';
import { keccak256, toUtf8Bytes } from 'ethers';
import pluralize from 'pluralize';
import { mkdir, rm, stat, writeFile } from 'fs/promises';
import { CompilerOutputContract } from 'hardhat/types';
Expand Down Expand Up @@ -239,7 +239,7 @@ task('ts-gen', 'Generate NatSpec documentation automatically on compilation')
} = allMembers;

for (const [sig, member] of Object.entries(allMembers)) {
const hash = ethers.keccak256(ethers.toUtf8Bytes(sig));
const hash = keccak256(toUtf8Bytes(sig));
member.hash = member.type === 'event' ? hash : hash.slice(0, 10);
}

Expand Down
2 changes: 1 addition & 1 deletion template/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve } from 'path';
import '@nomicfoundation/hardhat-toolbox';

// additional hardhat plugins
// import 'hardhat-packager';
import 'hardhat-packager';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';

Expand Down
30 changes: 18 additions & 12 deletions tests/LSP17Extensions/helpers/UserOp.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { getBytes, dataSlice, keccak256, BytesLike } from 'ethers';
import {
getBytes,
dataSlice,
keccak256,
BytesLike,
toBigInt,
toBeHex,
hexlify,
toNumber,
} from 'ethers';
import { Wallet } from 'ethers';
import { AddressZero, callDataCost } from './utils';
import { ecsign, toRpcSig, keccak256 as keccak256_buffer } from 'ethereumjs-util';
import { Create2Factory } from './Create2Factory';
import { EntryPoint } from '@account-abstraction/contracts';
import { ethers } from 'ethers';
import { AbiCoder } from 'ethers';
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers';
import * as typ from './solidityTypes';
import { ethers as hreEther } from 'hardhat';
Expand All @@ -26,7 +35,7 @@ export interface UserOperation {
export function packUserOp(op: UserOperation, forSignature = true): string {
if (forSignature) {
// Encoding the UserOperation object fields into a single string for signature
return ethers.AbiCoder.defaultAbiCoder().encode(
return AbiCoder.defaultAbiCoder().encode(
[
'address',
'uint256',
Expand Down Expand Up @@ -54,7 +63,7 @@ export function packUserOp(op: UserOperation, forSignature = true): string {
);
} else {
// Encoding the UserOperation object fields into a single string including the signature
return ethers.AbiCoder.defaultAbiCoder().encode(
return AbiCoder.defaultAbiCoder().encode(
[
'address',
'uint256',
Expand Down Expand Up @@ -88,7 +97,7 @@ export function packUserOp(op: UserOperation, forSignature = true): string {
export function getUserOpHash(op: UserOperation, entryPoint: string, chainId: number): string {
const userOpHash = keccak256(packUserOp(op, true));
// Encoding the UserOperation hash, entryPoint address, and chainId for final hash computation
const enc = ethers.AbiCoder.defaultAbiCoder().encode(
const enc = AbiCoder.defaultAbiCoder().encode(
['bytes32', 'address', 'uint256'],
[userOpHash, entryPoint, chainId],
);
Expand Down Expand Up @@ -189,14 +198,13 @@ export async function fillUserOp(
data: initCallData,
gasLimit: 10e6,
});
op1.verificationGasLimit =
ethers.toBigInt(DefaultsForUserOp.verificationGasLimit) + initEstimate;
op1.verificationGasLimit = toBigInt(DefaultsForUserOp.verificationGasLimit) + initEstimate;
}
}
if (op1.nonce == null) {
if (provider == null) throw new Error('must have entryPoint to autofill nonce');

const signerKeyAsUint192 = ethers.toBeHex(ethers.toBigInt(signer.address));
const signerKeyAsUint192 = toBeHex(toBigInt(signer.address));

try {
op1.nonce = await entryPoint.getNonce(op1.sender, signerKeyAsUint192);
Expand All @@ -209,7 +217,7 @@ export async function fillUserOp(
const gasEtimated = await provider.estimateGas({
from: entryPoint?.target,
to: op1.sender,
data: ethers.hexlify(op1.callData as BytesLike),
data: hexlify(op1.callData as BytesLike),
});

op1.callGasLimit = gasEtimated;
Expand Down Expand Up @@ -242,9 +250,7 @@ export async function fillAndSign(
const op2 = await fillUserOp(op, signer, entryPoint);

const chainId = await provider.getNetwork().then((net) => net.chainId);
const message = getBytes(
getUserOpHash(op2, entryPoint.target as string, ethers.toNumber(chainId)),
);
const message = getBytes(getUserOpHash(op2, entryPoint.target as string, toNumber(chainId)));

return {
...op2,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { ethers } from 'hardhat';
import { parseEther } from 'ethers';
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers';

// types
Expand Down Expand Up @@ -159,7 +159,7 @@ export const shouldBehaveLikeLSP1 = (buildContext: () => Promise<LSP1TestContext
});

describe('when calling the `universalReceiver(...)` function while sending native tokens', () => {
const valueSent = ethers.parseEther('3');
const valueSent = parseEther('3');

before(async () => {
context = await buildContext();
Expand Down Expand Up @@ -193,7 +193,7 @@ export const shouldBehaveLikeLSP1 = (buildContext: () => Promise<LSP1TestContext
before(async () => {
await context.accounts[0].sendTransaction({
to: lsp1CheckerAddress,
value: ethers.parseEther('50'),
value: parseEther('50'),
});
});

Expand Down
Loading

0 comments on commit d4fa3cb

Please sign in to comment.