Skip to content

Commit

Permalink
update all dependencies; add l1-avatar-execution first test
Browse files Browse the repository at this point in the history
  • Loading branch information
pscott committed Aug 16, 2024
1 parent 77aad71 commit 7374a6b
Show file tree
Hide file tree
Showing 7 changed files with 2,640 additions and 3,628 deletions.
2 changes: 1 addition & 1 deletion ethereum/src/mocks/MockStarknetMessaging.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ contract MockStarknetMessaging is StarknetMessaging {
bytes32 msgHash = keccak256(abi.encodePacked(fromAddress, toAddress, nonce, selector, payload.length, payload));

require(l1ToL2Messages()[msgHash] > 0, "INVALID_MESSAGE_TO_CONSUME");
l1ToL2Messages()[msgHash] = 0;
l1ToL2Messages()[msgHash] -= 1;
}
}
14 changes: 1 addition & 13 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,11 @@ dotenv.config();
import { task } from 'hardhat/config';
import { HardhatUserConfig } from 'hardhat/types';
import 'starknet';
import '@typechain/hardhat';
import '@nomicfoundation/hardhat-ethers';
import '@nomiclabs/hardhat-waffle';
import '@nomiclabs/hardhat-etherscan';
import '@nomicfoundation/hardhat-toolbox';
import '@nomicfoundation/hardhat-network-helpers';
import '@nomicfoundation/hardhat-foundry';
import '@openzeppelin/hardhat-upgrades';


task('accounts', 'Prints the list of accounts', async (args, hre) => {
const accounts = await hre.ethers.getSigners();

for (const account of accounts) {
console.log(await account.getAddress());
}
});

const config: HardhatUserConfig = {
solidity: {
compilers: [
Expand Down
30 changes: 16 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,48 @@
"test:l1-execution": "bash './scripts/l1-avatar-execution-test.sh'"
},
"devDependencies": {
"@gnosis.pm/safe-contracts": "^1.3.0",
"@gnosis.pm/zodiac": "^4.0.3",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.2",
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
"@nomicfoundation/hardhat-ethers": "^3.0.6",
"@nomicfoundation/hardhat-foundry": "^1.1.1",
"@nomicfoundation/hardhat-network-helpers": "^1.0.8",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@nomiclabs/hardhat-etherscan": "^3.1.7",
"@nomiclabs/hardhat-waffle": "^2.0.6",
"@nomicfoundation/hardhat-ignition": "^0.15.5",
"@nomicfoundation/hardhat-ignition-ethers": "^0.15.5",
"@nomicfoundation/hardhat-network-helpers": "^1.0.11",
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.0",
"@nomicfoundation/ignition-core": "^0.15.5",
"@openzeppelin/contracts": "^5.0.2",
"@openzeppelin/hardhat-upgrades": "^3.2.0",
"@safe-global/safe-contracts": "^1.4.1-build.0",
"@snapshot-labs/sx": "^0.1.0-beta.46",
"@typechain/ethers-v6": "^0.5.0",
"@typechain/hardhat": "^9.0.0",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
"@types/mocha": "^10.0.7",
"@types/node": "^20.4.5",
"@types/sinon-chai": "^3.2.9",
"@typescript-eslint/eslint-plugin": "^6.2.1",
"@typescript-eslint/parser": "^6.2.1",
"axios": "^1.5.0",
"chai": "^4.3.7",
"chai": "4",
"concurrently": "^7.0.0",
"dotenv": "^16.3.1",
"eslint": "^8.46.0",
"eslint-plugin-prettier": "^5.0.0",
"ethereum-waffle": "^4.0.10",
"ethers": "^6.13.2",
"fs": "^0.0.1-security",
"hardhat": "^2.17.2",
"hardhat-gas-reporter": "^1.0.9",
"hardhat-gas-reporter": "^1.0.8",
"json-format-cli": "^1.1.1",
"micro-starknet": "^0.2.3",
"prettier": "^3.0.0",
"solidity-coverage": "^0.8.12",
"starknet": "^6.11.0",
"ts-node": "^10.9.1",
"typechain": "^8.3.2",
"typescript": "^5.1.6",
"wait-on": "^7.0.1"
},
"dependencies": {
"ethers": "^6.13.2",
"starknet-devnet": "^0.1.1"
}
}
}
67 changes: 33 additions & 34 deletions tests/external/safeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */

import { Contract, utils, BigNumber, BigNumberish, Signer, PopulatedTransaction } from 'ethers';
import { Contract, BigNumberish, Signer, ethers, Typed } from 'ethers';
import { TypedDataSigner } from '@ethersproject/abstract-signer';
import { AddressZero } from '@ethersproject/constants';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';

export const EIP712_TYPES = {
Transaction: [
Expand Down Expand Up @@ -61,7 +60,7 @@ export const EIP712_SAFE_MESSAGE_TYPE = {

export interface MetaTransaction {
to: string;
value: string | number | BigNumber;
value: string | number | BigInt;
data: string;
operation: number;
}
Expand All @@ -81,8 +80,8 @@ export interface SafeSignature {
}

const encodeMetaTransaction = (tx: MetaTransaction): string => {
const data = utils.arrayify(tx.data);
const encoded = utils.solidityPack(
const data = ethers.getBytes(tx.data);
const encoded = ethers.solidityPacked(
['uint8', 'address', 'uint256', 'uint256', 'bytes'],
[tx.operation, tx.to, tx.value, data.length, data],
);
Expand All @@ -93,50 +92,50 @@ export const encodeMultiSend = (txs: MetaTransaction[]): string => {
return '0x' + txs.map((tx) => encodeMetaTransaction(tx)).join('');
};

export const buildMultiSendSafeTx = (
export const buildMultiSendSafeTx = async (
multiSend: Contract,
txs: MetaTransaction[],
nonce: number,
overrides?: Partial<SafeTransaction>,
): SafeTransaction => {
): Promise<SafeTransaction> => {
return buildContractCall(multiSend, 'multiSend', [encodeMultiSend(txs)], nonce, true, overrides);
};

export const calculateSafeDomainSeparator = (safe: Contract, chainId: BigNumberish): string => {
return utils._TypedDataEncoder.hashDomain({ verifyingContract: safe.address, chainId });
export const calculateSafeDomainSeparator = (safeAddress: string, chainId: BigNumberish): string => {
return ethers.TypedDataEncoder.hashDomain({ verifyingContract: safeAddress, chainId });
};

export const preimageSafeTransactionHash = (
safe: Contract,
safeAddress: string,
safeTx: SafeTransaction,
chainId: BigNumberish,
): string => {
return utils._TypedDataEncoder.encode(
{ verifyingContract: safe.address, chainId },
return ethers.TypedDataEncoder.encode(
{ verifyingContract: safeAddress, chainId },
EIP712_SAFE_TX_TYPE,
safeTx,
);
};

export const calculateSafeTransactionHash = (
safe: Contract,
safeAddress: string,
safeTx: SafeTransaction,
chainId: BigNumberish,
): string => {
return utils._TypedDataEncoder.hash(
{ verifyingContract: safe.address, chainId },
return ethers.TypedDataEncoder.hash(
{ verifyingContract: safeAddress, chainId },
EIP712_SAFE_TX_TYPE,
safeTx,
);
};

export const calculateSafeMessageHash = (
safe: Contract,
safeAddress: string,
message: string,
chainId: BigNumberish,
): string => {
return utils._TypedDataEncoder.hash(
{ verifyingContract: safe.address, chainId },
return ethers.TypedDataEncoder.hash(
{ verifyingContract: safeAddress, chainId },
EIP712_SAFE_MESSAGE_TYPE,
{
message,
Expand All @@ -153,7 +152,7 @@ export const safeApproveHash = async (
if (!skipOnChainApproval) {
if (!signer.provider) throw Error('Provider required for on-chain approval');
const chainId = (await signer.provider.getNetwork()).chainId;
const typedDataHash = utils.arrayify(calculateSafeTransactionHash(safe, safeTx, chainId));
const typedDataHash = ethers.getBytes(calculateSafeTransactionHash(await safe.getAddress(), safeTx, chainId));
const signerSafe = safe.connect(signer);
await signerSafe.approveHash(typedDataHash);
}
Expand All @@ -169,7 +168,7 @@ export const safeApproveHash = async (
};

export const safeSignTypedData = async (
signer: Signer & TypedDataSigner,
signer: Signer,
safe: Contract,
safeTx: SafeTransaction,
chainId?: BigNumberish,
Expand All @@ -179,16 +178,16 @@ export const safeSignTypedData = async (
const signerAddress = await signer.getAddress();
return {
signer: signerAddress,
data: await signer._signTypedData(
{ verifyingContract: safe.address, chainId: cid },
data: await signer.signTypedData(
{ verifyingContract: await safe.getAddress(), chainId: cid },
EIP712_SAFE_TX_TYPE,
safeTx,
),
};
};

export const signHash = async (signer: Signer, hash: string): Promise<SafeSignature> => {
const typedDataHash = utils.arrayify(hash);
const typedDataHash = ethers.getBytes(hash);
const signerAddress = await signer.getAddress();
return {
signer: signerAddress,
Expand All @@ -198,12 +197,12 @@ export const signHash = async (signer: Signer, hash: string): Promise<SafeSignat

export const safeSignMessage = async (
signer: Signer,
safe: Contract,
safeAddress: string,
safeTx: SafeTransaction,
chainId?: BigNumberish,
): Promise<SafeSignature> => {
const cid = chainId || (await signer.provider!.getNetwork()).chainId;
return signHash(signer, calculateSafeTransactionHash(safe, safeTx, cid));
return signHash(signer, calculateSafeTransactionHash(safeAddress, safeTx, cid));
};

export const buildSignatureBytes = (signatures: SafeSignature[]): string => {
Expand Down Expand Up @@ -252,9 +251,9 @@ export const populateExecuteTx = async (
safeTx: SafeTransaction,
signatures: SafeSignature[],
overrides?: any,
): Promise<PopulatedTransaction> => {
): Promise<ethers.ContractTransaction> => {
const signatureBytes = buildSignatureBytes(signatures);
return safe.populateTransaction.execTransaction(
return safe.execTransaction.populateTransaction(
safeTx.to,
safeTx.value,
safeTx.data,
Expand All @@ -269,19 +268,19 @@ export const populateExecuteTx = async (
);
};

export const buildContractCall = (
export const buildContractCall = async (
contract: Contract,
method: string,
params: any[],
nonce: number,
delegateCall?: boolean,
overrides?: Partial<SafeTransaction>,
): SafeTransaction => {
): Promise<SafeTransaction> => {
const data = contract.interface.encodeFunctionData(method, params);
return buildSafeTransaction(
Object.assign(
{
to: contract.address,
to: await contract.getAddress(),
data,
operation: delegateCall ? 1 : 0,
nonce,
Expand Down Expand Up @@ -317,7 +316,7 @@ export const buildContractCallVariable = (
export const executeTxWithSigners = async (
safe: Contract,
tx: SafeTransaction,
signers: SignerWithAddress[],
signers: Signer[],
overrides?: any,
) => {
const sigs = await Promise.all(signers.map((signer) => safeSignTypedData(signer, safe, tx)));
Expand All @@ -329,11 +328,11 @@ export const executeContractCallWithSigners = async (
contract: Contract,
method: string,
params: any[],
signers: SignerWithAddress[],
signers: Signer[],
delegateCall?: boolean,
overrides?: Partial<SafeTransaction>,
) => {
const tx = buildContractCall(
const tx = await buildContractCall(
contract,
method,
params,
Expand All @@ -346,7 +345,7 @@ export const executeContractCallWithSigners = async (

export const buildSafeTransaction = (template: {
to: string;
value?: BigNumber | number | string;
value?: BigInt | number | string;
data?: string;
operation?: number;
safeTxGas?: number | string;
Expand Down
Loading

0 comments on commit 7374a6b

Please sign in to comment.