mirror of
https://github.com/getwax/wax.git
synced 2026-01-09 15:18:02 -05:00
Move deterministic deployer to its own package, update imports, use in inpage demo
This commit is contained in:
1
packages/demos/inpage/lib-ts/deterministic-deployer
Symbolic link
1
packages/demos/inpage/lib-ts/deterministic-deployer
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../deterministic-deployer/src
|
||||
@@ -28,9 +28,6 @@ import {
|
||||
SimpleAccountFactory,
|
||||
SimpleAccountFactory__factory,
|
||||
} from '../hardhat/typechain-types';
|
||||
import SafeSingletonFactory, {
|
||||
SafeSingletonFactoryViewer,
|
||||
} from './SafeSingletonFactory';
|
||||
import ReusablePopup from './ReusablePopup';
|
||||
import AdminPopup, { AdminPurpose } from './AdminPopup';
|
||||
import waxPrivate from './waxPrivate';
|
||||
@@ -47,6 +44,9 @@ import SafeCompressionAccountWrapper from './accounts/SafeCompressionAccountWrap
|
||||
import { hexLen } from './helpers/encodeUtils';
|
||||
import JsonRpcError from './JsonRpcError';
|
||||
import measureCalldataGas from './measureCalldataGas';
|
||||
import DeterministicDeployer, {
|
||||
DeterministicDeploymentViewer,
|
||||
} from '../lib-ts/deterministic-deployer/DeterministicDeployer';
|
||||
|
||||
type Config = {
|
||||
logRequests?: boolean;
|
||||
@@ -185,7 +185,10 @@ export default class WaxInPage {
|
||||
await this.ethereum.request({ method: 'eth_chainId' }),
|
||||
);
|
||||
|
||||
const viewer = new SafeSingletonFactoryViewer(this.ethersProvider, chainId);
|
||||
const viewer = new DeterministicDeploymentViewer(
|
||||
this.ethersProvider,
|
||||
chainId,
|
||||
);
|
||||
|
||||
const assumedEntryPoint = viewer.connectAssume(EntryPoint__factory, []);
|
||||
|
||||
@@ -234,7 +237,7 @@ export default class WaxInPage {
|
||||
|
||||
const wallet = await this.requestAdminAccount('deploy-contracts');
|
||||
|
||||
const factory = await SafeSingletonFactory.init(wallet);
|
||||
const factory = await DeterministicDeployer.init(wallet);
|
||||
|
||||
const entryPoint = await factory.connectOrDeploy(EntryPoint__factory, []);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
import EthereumRpc from '../EthereumRpc';
|
||||
import IAccount from './IAccount';
|
||||
import WaxInPage from '..';
|
||||
import { SafeCompressionFactory } from '../../hardhat/typechain-types/lib/packages/plugins/src/SafeCompressionFactory';
|
||||
import { SafeCompressionFactory } from '../../hardhat/typechain-types/lib/plugins/src/safe/SafeCompressionFactory';
|
||||
import receiptOf from '../helpers/receiptOf';
|
||||
import {
|
||||
encodeBitStack,
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
import EthereumRpc from '../EthereumRpc';
|
||||
import IAccount from './IAccount';
|
||||
import WaxInPage from '..';
|
||||
import { SafeECDSAFactory } from '../../hardhat/typechain-types/lib/packages/plugins/src/SafeECDSAFactory';
|
||||
import { SafeECDSAFactory } from '../../hardhat/typechain-types/lib/plugins/src/safe/SafeECDSAFactory';
|
||||
import receiptOf from '../helpers/receiptOf';
|
||||
import { executeContractCallWithSigners } from './execution';
|
||||
import assert from '../helpers/assert';
|
||||
|
||||
127
packages/deterministic-deployer/.eslintrc.cjs
Normal file
127
packages/deterministic-deployer/.eslintrc.cjs
Normal file
@@ -0,0 +1,127 @@
|
||||
/* eslint-env node */
|
||||
|
||||
module.exports = {
|
||||
root: true,
|
||||
env: { browser: true, es2020: true, mocha: true },
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:@typescript-eslint/recommended-requiring-type-checking',
|
||||
'plugin:react-hooks/recommended',
|
||||
'airbnb',
|
||||
],
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
ecmaVersion: 'latest',
|
||||
sourceType: 'module',
|
||||
project: true,
|
||||
tsconfigRootDir: __dirname,
|
||||
},
|
||||
plugins: ['react-refresh', 'prettier', '@typescript-eslint', 'import'],
|
||||
rules: {
|
||||
'react-refresh/only-export-components': [
|
||||
'error',
|
||||
{ allowConstantExport: true },
|
||||
],
|
||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||
'prettier/prettier': [
|
||||
'error',
|
||||
{
|
||||
bracketSpacing: true,
|
||||
bracketSameLine: false,
|
||||
printWidth: 80,
|
||||
semi: true,
|
||||
singleQuote: true,
|
||||
tabWidth: 2,
|
||||
trailingComma: 'all',
|
||||
useTabs: false,
|
||||
proseWrap: 'always',
|
||||
},
|
||||
],
|
||||
'no-unused-vars': 'off',
|
||||
'@typescript-eslint/no-unused-vars': [
|
||||
'error',
|
||||
{
|
||||
varsIgnorePattern: '^_',
|
||||
argsIgnorePattern: '^_',
|
||||
destructuredArrayIgnorePattern: '^_',
|
||||
caughtErrorsIgnorePattern: '^_',
|
||||
},
|
||||
],
|
||||
'import/extensions': 'off',
|
||||
'import/no-unresolved': 'off',
|
||||
'import/no-extraneous-dependencies': [
|
||||
'error',
|
||||
{
|
||||
devDependencies: [
|
||||
'demo/**/*.ts',
|
||||
'demo/**/*.tsx',
|
||||
'scripts/**/*.ts',
|
||||
'vite.config.ts',
|
||||
'hardhat/**/*.ts',
|
||||
'tests/**/*.*',
|
||||
],
|
||||
},
|
||||
],
|
||||
'react/react-in-jsx-scope': 'off',
|
||||
'react/jsx-filename-extension': 'off',
|
||||
'react/jsx-indent': 'off',
|
||||
'react/jsx-one-expression-per-line': 'off',
|
||||
'import/no-absolute-path': 'off',
|
||||
'no-useless-constructor': 'off',
|
||||
'@typescript-eslint/no-useless-constructor': 'error',
|
||||
'no-empty-function': 'off',
|
||||
'react/function-component-definition': [
|
||||
'error',
|
||||
{
|
||||
namedComponents: 'arrow-function',
|
||||
unnamedComponents: 'arrow-function',
|
||||
},
|
||||
],
|
||||
'react/require-default-props': 'off',
|
||||
'react/jsx-props-no-spreading': 'off',
|
||||
'object-curly-newline': 'off',
|
||||
'no-return-await': 'off',
|
||||
'max-classes-per-file': 'off',
|
||||
'lines-between-class-members': [
|
||||
'error',
|
||||
'always',
|
||||
{
|
||||
exceptAfterSingleLine: true,
|
||||
},
|
||||
],
|
||||
'no-use-before-define': 'off',
|
||||
'no-redeclare': 'off',
|
||||
'brace-style': 'off',
|
||||
'no-restricted-syntax': 'off',
|
||||
'operator-linebreak': 'off',
|
||||
|
||||
// Found false positive with these. Maybe the typescript used for linting is
|
||||
// out of date.
|
||||
'@typescript-eslint/no-unsafe-call': 'off',
|
||||
'@typescript-eslint/no-unsafe-member-access': 'off',
|
||||
|
||||
'no-shadow': 'off',
|
||||
'@typescript-eslint/no-shadow': 'error',
|
||||
|
||||
camelcase: [
|
||||
'error',
|
||||
{
|
||||
allow: ['^[a-zA-Z0-9]+__factory$', '^eth_[a-zA-Z]+$'],
|
||||
},
|
||||
],
|
||||
|
||||
'implicit-arrow-linebreak': 'off',
|
||||
'function-paren-newline': 'off',
|
||||
'react/jsx-wrap-multilines': 'off',
|
||||
'no-void': 'off',
|
||||
'react/jsx-curly-newline': 'off',
|
||||
'no-await-in-loop': 'off',
|
||||
'no-continue': 'off',
|
||||
'no-constant-condition': 'off',
|
||||
'no-underscore-dangle': 'off',
|
||||
'consistent-return': 'off',
|
||||
'no-plusplus': 'off',
|
||||
'no-bitwise': 'off',
|
||||
},
|
||||
};
|
||||
12
packages/deterministic-deployer/package.json
Normal file
12
packages/deterministic-deployer/package.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "deterministic-deployer",
|
||||
"version": "0.0.0",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ethers": "^6.11.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.4.3"
|
||||
}
|
||||
}
|
||||
@@ -111,14 +111,20 @@ export default class DeterministicDeployer {
|
||||
throw new Error("Missing details for deploying deployer contract");
|
||||
}
|
||||
|
||||
// Fund the eoa account for the presigned transaction
|
||||
await (
|
||||
await signer.sendTransaction({
|
||||
...overrides,
|
||||
to: deployment.signerAddress,
|
||||
value: BigInt(deployment.gasPrice) * BigInt(deployment.gasLimit),
|
||||
})
|
||||
).wait();
|
||||
const requiredBalance = BigInt(deployment.gasPrice) * BigInt(deployment.gasLimit);
|
||||
const currentBalance = await provider.getBalance(deployment.signerAddress);
|
||||
const balanceDeficit = requiredBalance - currentBalance;
|
||||
|
||||
if (balanceDeficit > 0n) {
|
||||
// Fund the eoa account for the presigned transaction
|
||||
await (
|
||||
await signer.sendTransaction({
|
||||
...overrides,
|
||||
to: deployment.signerAddress,
|
||||
value: BigInt(deployment.gasPrice) * BigInt(deployment.gasLimit),
|
||||
})
|
||||
).wait();
|
||||
}
|
||||
|
||||
await (await provider.broadcastTransaction(deployment.transaction)).wait();
|
||||
|
||||
12
packages/deterministic-deployer/src/assert.ts
Normal file
12
packages/deterministic-deployer/src/assert.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export default function assert(
|
||||
condition: unknown,
|
||||
msg = "Assertion failed",
|
||||
): asserts condition {
|
||||
if (!condition) {
|
||||
throw new AssertionError(msg);
|
||||
}
|
||||
}
|
||||
|
||||
class AssertionError extends Error {
|
||||
name = "AssertionError";
|
||||
}
|
||||
20
packages/deterministic-deployer/tsconfig.json
Normal file
20
packages/deterministic-deployer/tsconfig.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": false,
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"include": ["*.*", "./**/*"]
|
||||
}
|
||||
58
packages/deterministic-deployer/yarn.lock
Normal file
58
packages/deterministic-deployer/yarn.lock
Normal file
@@ -0,0 +1,58 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@adraffy/ens-normalize@1.10.1":
|
||||
version "1.10.1"
|
||||
resolved "https://registry.yarnpkg.com/@adraffy/ens-normalize/-/ens-normalize-1.10.1.tgz#63430d04bd8c5e74f8d7d049338f1cd9d4f02069"
|
||||
integrity sha512-96Z2IP3mYmF1Xg2cDm8f1gWGf/HUVedQ3FMifV4kG/PQ4yEP51xDtRAEfhVNt5f/uzpNkZHwWQuUcu6D6K+Ekw==
|
||||
|
||||
"@noble/curves@1.2.0":
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.2.0.tgz#92d7e12e4e49b23105a2555c6984d41733d65c35"
|
||||
integrity sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==
|
||||
dependencies:
|
||||
"@noble/hashes" "1.3.2"
|
||||
|
||||
"@noble/hashes@1.3.2":
|
||||
version "1.3.2"
|
||||
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39"
|
||||
integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==
|
||||
|
||||
"@types/node@18.15.13":
|
||||
version "18.15.13"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.15.13.tgz#f64277c341150c979e42b00e4ac289290c9df469"
|
||||
integrity sha512-N+0kuo9KgrUQ1Sn/ifDXsvg0TTleP7rIy4zOBGECxAljqvqfqpTfzx0Q1NUedOixRMBfe2Whhb056a42cWs26Q==
|
||||
|
||||
aes-js@4.0.0-beta.5:
|
||||
version "4.0.0-beta.5"
|
||||
resolved "https://registry.yarnpkg.com/aes-js/-/aes-js-4.0.0-beta.5.tgz#8d2452c52adedebc3a3e28465d858c11ca315873"
|
||||
integrity sha512-G965FqalsNyrPqgEGON7nIx1e/OVENSgiEIzyC63haUMuvNnwIgIjMs52hlTCKhkBny7A2ORNlfY9Zu+jmGk1Q==
|
||||
|
||||
ethers@^6.11.1:
|
||||
version "6.11.1"
|
||||
resolved "https://registry.yarnpkg.com/ethers/-/ethers-6.11.1.tgz#96aae00b627c2e35f9b0a4d65c7ab658259ee6af"
|
||||
integrity sha512-mxTAE6wqJQAbp5QAe/+o+rXOID7Nw91OZXvgpjDa1r4fAbq2Nu314oEZSbjoRLacuCzs7kUC3clEvkCQowffGg==
|
||||
dependencies:
|
||||
"@adraffy/ens-normalize" "1.10.1"
|
||||
"@noble/curves" "1.2.0"
|
||||
"@noble/hashes" "1.3.2"
|
||||
"@types/node" "18.15.13"
|
||||
aes-js "4.0.0-beta.5"
|
||||
tslib "2.4.0"
|
||||
ws "8.5.0"
|
||||
|
||||
tslib@2.4.0:
|
||||
version "2.4.0"
|
||||
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.0.tgz#7cecaa7f073ce680a05847aa77be941098f36dc3"
|
||||
integrity sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==
|
||||
|
||||
typescript@^5.4.3:
|
||||
version "5.4.3"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.3.tgz#5c6fedd4c87bee01cd7a528a30145521f8e0feff"
|
||||
integrity sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg==
|
||||
|
||||
ws@8.5.0:
|
||||
version "8.5.0"
|
||||
resolved "https://registry.yarnpkg.com/ws/-/ws-8.5.0.tgz#bfb4be96600757fe5382de12c670dab984a1ed4f"
|
||||
integrity sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==
|
||||
1
packages/plugins/lib-ts/deterministic-deployer
Symbolic link
1
packages/plugins/lib-ts/deterministic-deployer
Symbolic link
@@ -0,0 +1 @@
|
||||
../../deterministic-deployer/src
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ethers } from "ethers";
|
||||
import DeterministicDeployer from "../test/e2e/utils/DeterministicDeployer";
|
||||
import DeterministicDeployer from "../lib-ts/deterministic-deployer/DeterministicDeployer";
|
||||
import {
|
||||
SimulateTxAccessor__factory,
|
||||
SafeProxyFactory__factory,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { expect } from "chai";
|
||||
import { JsonRpcProvider, NonceManager, Signer, ethers } from "ethers";
|
||||
import DeterministicDeployer from "../test/e2e/utils/DeterministicDeployer";
|
||||
import DeterministicDeployer from "../lib-ts/deterministic-deployer/DeterministicDeployer";
|
||||
import { createAndSendUserOpWithEcdsaSig } from "../test/e2e/utils/createUserOp";
|
||||
import { executeContractCallWithSigners } from "../test/e2e/utils/execution";
|
||||
import receiptOf from "../test/e2e/utils/receiptOf";
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
createUserOperation,
|
||||
} from "./utils/createUserOp";
|
||||
import { getSigners } from "./utils/getSigners";
|
||||
import DeterministicDeployer from "./utils/DeterministicDeployer";
|
||||
import DeterministicDeployer from "../../lib-ts/deterministic-deployer/DeterministicDeployer";
|
||||
import getBlsUserOpHash from "./utils/getBlsUserOpHash";
|
||||
import appendKeyToInitCode from "./utils/appendKeyToInitCode";
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
} from "ethers";
|
||||
|
||||
import { executeContractCallWithSigners } from "./utils/execution";
|
||||
import DeterministicDeployer from "./utils/DeterministicDeployer";
|
||||
import DeterministicDeployer from "../../lib-ts/deterministic-deployer/DeterministicDeployer";
|
||||
import {
|
||||
Safe,
|
||||
SafeECDSAFactory__factory,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { expect } from "chai";
|
||||
import { JsonRpcProvider, NonceManager, Signer, ethers } from "ethers";
|
||||
|
||||
import { executeContractCallWithSigners } from "./utils/execution";
|
||||
import DeterministicDeployer from "./utils/DeterministicDeployer";
|
||||
import DeterministicDeployer from "../../lib-ts/deterministic-deployer/DeterministicDeployer";
|
||||
import {
|
||||
MockDKIMRegsitry,
|
||||
MockDKIMRegsitry__factory,
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
SafeProxyFactory__factory,
|
||||
Safe__factory,
|
||||
} from "../../../typechain-types";
|
||||
import DeterministicDeployer from "./DeterministicDeployer";
|
||||
import DeterministicDeployer from "../../../lib-ts/deterministic-deployer/DeterministicDeployer";
|
||||
import receiptOf from "./receiptOf";
|
||||
import makeDevFaster from "./makeDevFaster";
|
||||
import { getSigners } from "./getSigners";
|
||||
|
||||
Reference in New Issue
Block a user