Skip to content

Commit 44f0d64

Browse files
authored
Merge pull request #50 from OpenZeppelin/main
Release to Wizard
2 parents 95e0c42 + ec19031 commit 44f0d64

File tree

21 files changed

+1903
-1330
lines changed

21 files changed

+1903
-1330
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ node_modules
66
.netlify
77
/.svelte-kit
88
/build
9+
src/lib/generated
910

1011
# OS
1112
.DS_Store
@@ -20,3 +21,5 @@ Thumbs.db
2021
# Vite
2122
vite.config.js.timestamp-*
2223
vite.config.ts.timestamp-*
24+
25+
/.vscode/

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ Url: http://localhost:5173 # or live version https://defeder-remix-deploy.netlif
3434
Type of connection: Iframe
3535
Location in Remix: Side Panel
3636
```
37-
5. You should see the plugin added to the sidebar (new icon with ? symbol).
37+
5. You should see the plugin added to the sidebar (new icon with ? symbol).
38+
(Note: If accessing Remix through Brave browser, you might have to turn down Shields configuration for this website on the right of the search bar.)
3839

3940
## Testing in Contracts Wizard
4041

package.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
"version": "0.0.1",
44
"type": "module",
55
"scripts": {
6-
"dev": "vite dev",
7-
"build": "vite build",
8-
"preview": "vite preview",
9-
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
10-
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
6+
"prepare": "node scripts/prepare.js",
7+
"dev": "pnpm prepare && vite dev",
8+
"build": "pnpm prepare && vite build",
9+
"preview": "pnpm prepare && vite preview",
10+
"check": "pnpm prepare && svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
11+
"check:watch": "pnpm prepare && svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
1112
},
1213
"devDependencies": {
1314
"@sveltejs/adapter-auto": "^3.0.0",
@@ -30,6 +31,8 @@
3031
"@sveltejs/adapter-netlify": "^4.3.6",
3132
"bootstrap": "^5.3.3",
3233
"ethers": "^6.13.4",
33-
"solc": "^0.8.28"
34+
"solc": "^0.8.28",
35+
"file-saver": "^2.0.5",
36+
"superchain-registry": "github:ethereum-optimism/superchain-registry"
3437
}
3538
}

pnpm-lock.yaml

Lines changed: 1372 additions & 1089 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/prepare.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env node
2+
3+
import { existsSync, mkdirSync, copyFileSync, writeFileSync } from 'fs';
4+
import { createRequire } from 'module';
5+
6+
const GENERATED_DIR = 'src/lib/generated';
7+
8+
async function main() {
9+
createDirs(GENERATED_DIR);
10+
11+
copySuperchainRegistry();
12+
copySolcVersion();
13+
}
14+
15+
main().catch(e => {
16+
console.error(e);
17+
process.exit(1);
18+
});
19+
20+
function createDirs(dir) {
21+
if (!existsSync(dir)) {
22+
mkdirSync(dir, { recursive: true });
23+
}
24+
}
25+
26+
function copySuperchainRegistry() {
27+
copyFileSync('node_modules/superchain-registry/chainList.json', `${GENERATED_DIR}/superchainRegistryChainList.json`);
28+
}
29+
30+
function copySolcVersion() {
31+
const { version } = createRequire(import.meta.url)('solc/package.json');
32+
writeFileSync(`${GENERATED_DIR}/solcVersion.json`, JSON.stringify({ version }, null, 2));
33+
}

src/lib/models/approval-process.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { TenantNetworkResponse } from "./network";
2+
import type { GlobalState } from "./ui";
23

34
/**
45
* Generic approval process model
@@ -17,12 +18,19 @@ export type ApprovalProcess = {
1718
stackResourceId?: string;
1819
}
1920

21+
export type ApprovalProcessToCreate = {
22+
viaType: ApprovalProcessType;
23+
via?: string;
24+
relayerId?: string;
25+
network?: string;
26+
}
27+
2028
export type ComponentType = ('deploy' | 'upgrade')[];
2129

2230
/**
2331
* Supported approval process creation types
2432
*/
25-
export const approvalProcessTypes = ['EOA', 'Safe', 'Relayer'];
33+
export const approvalProcessTypes = ['EOA', 'Safe', 'Relayer'] as const;
2634
export type ApprovalProcessType = typeof approvalProcessTypes[number];
2735

2836

@@ -31,11 +39,23 @@ export type ApprovalProcessType = typeof approvalProcessTypes[number];
3139
* https://github.com/OpenZeppelin/defender-sdk/blob/main/packages/approval-process/src/models/approval-process.ts
3240
*/
3341
export interface CreateApprovalProcessRequest {
34-
viaType: 'EOA' | 'Relayer' | 'Safe';
42+
viaType: ApprovalProcessType;
3543
name: string;
3644
component?: ComponentType;
3745
network: string;
3846
via: string;
3947
multisigSender?: string;
4048
relayerId?: string;
4149
}
50+
51+
52+
export function approvalProcessByNetworkAndComponent(network: GlobalState["form"]["network"]) {
53+
return (ap: ApprovalProcess) => {
54+
const networkName =
55+
typeof network === "string"
56+
? network
57+
: network?.name;
58+
59+
return ap.network === networkName && ap.component?.includes("deploy");
60+
}
61+
}

src/lib/models/network.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const productionNetworks = new Set([
3333
'moonriver',
3434
'optimism',
3535
'scroll',
36+
'unichain',
3637
'xdai',
3738
'zksync'
3839
]);
@@ -92,6 +93,7 @@ export const chainIds: { [key in string]: number } = {
9293
'scroll-sepolia': 534351,
9394
'sepolia': 11155111,
9495
'sokol': 77,
96+
'unichain': 130,
9597
'unichain-sepolia': 1301,
9698
'x-dfk-avax-chain': 53935,
9799
'x-dfk-avax-chain-test': 335,
@@ -147,6 +149,7 @@ export const chainDisplayNames: { [key in string]: string } = {
147149
'scroll-sepolia': 'Scroll Sepolia',
148150
'sepolia': 'Sepolia',
149151
'sokol': 'Sokol',
152+
'unichain': 'Unichain',
150153
'unichain-sepolia': 'Unichain Sepolia',
151154
'x-dfk-avax-chain': 'Avalanche X-DFK',
152155
'x-dfk-avax-chain-test': 'Avalanche X-DFK Testnet',

src/lib/models/ui.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import type { CompilationFileSources, CompilationResult, SourceWithTarget } from "@remixproject/plugin-api";
22
import type { Relayer } from "./relayer";
33
import type { ApiKeyCapability, Credentials } from "./auth";
4-
import type { ApprovalProcess } from "./approval-process";
4+
import type { ApprovalProcess, ApprovalProcessToCreate } from "./approval-process";
55
import type { TenantNetworkResponse } from "./network";
66

7-
export type DropdownItem = {
7+
export type DropdownItem<TValue = any> = {
88
label: string;
9-
value: any;
9+
value: TValue;
1010
group?: string;
1111
}
1212

13+
type HTMLInputExtendedElement<TId = string, TValue = string, TName = string> = HTMLInputElement & { id: TId, name: TName, value: TValue, checked: boolean}
14+
export type HTMLInputElementEvent<TId = string, TValue = string, TName = string> = Event & { currentTarget: HTMLInputExtendedElement<TId, TValue, TName> }
15+
1316
export type GlobalState = {
1417
authenticated: boolean;
1518
error?: string;
@@ -25,23 +28,37 @@ export type GlobalState = {
2528
version?: string,
2629
data?: CompilationResult | null,
2730
enforceDeterministicReason?: string,
31+
groupNetworksBy?: 'superchain',
2832
}
2933
form: {
3034
network?: string | TenantNetworkResponse;
3135
approvalProcessSelected?: ApprovalProcess;
32-
approvalProcessToCreate?: {
33-
viaType: 'EOA' | 'Safe' | 'Relayer';
34-
via?: string;
35-
relayerId?: string;
36-
network?: string;
36+
approvalProcessToCreate?: ApprovalProcessToCreate;
37+
approvalType?: SelectedApprovalProcessType;
38+
constructorArguments: {
39+
values: Record<string, string | number | boolean>,
40+
required: string[],
3741
}
38-
approvalType?: 'existing' | 'new' | 'injected';
42+
deterministic: {
43+
isSelected: boolean;
44+
isEnforced: boolean;
45+
salt?: string
46+
};
3947
completed?: boolean;
40-
};
48+
},
49+
clearDeploymentStatus?: () => void;
4150
};
4251

4352
export type APIResponse<T> = {
4453
success: boolean;
4554
error?: string;
4655
data?: T;
47-
}
56+
}
57+
58+
const selectedApprovalProcessTypes = ['existing', 'new', 'injected'] as const;
59+
export type SelectedApprovalProcessType = typeof selectedApprovalProcessTypes[number];
60+
61+
export const isSelectedApprovalProcessType = (selectedApprovalProcessType: string): selectedApprovalProcessType is SelectedApprovalProcessType => {
62+
const expectedTypes: string[] = [...selectedApprovalProcessTypes];
63+
return expectedTypes.includes(selectedApprovalProcessType);
64+
};

src/lib/remix/components/Deploy.svelte

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { onDestroy } from "svelte";
33
44
// Lib
5-
import { addAPToDropdown, clearErrorBanner, globalState, setDeploymentCompleted, setErrorBanner } from "$lib/state/state.svelte";
5+
import { updateSelectedApprovalProcessWithExisting, clearErrorBanner, globalState, setDeploymentCompleted, setErrorBanner } from "$lib/state/state.svelte";
66
import { log, logError, logSuccess, logWarning } from "$lib/remix/logger";
77
import { deployContract, switchToNetwork } from "$lib/ethereum";
88
import { API } from "$lib/api";
@@ -16,7 +16,7 @@
1616
import { getNetworkLiteral, isProductionNetwork, type TenantNetworkResponse } from "$lib/models/network";
1717
import type { ApprovalProcess, CreateApprovalProcessRequest} from "$lib/models/approval-process";
1818
import type { DeployContractRequest, UpdateDeploymentRequest } from "$lib/models/deploy";
19-
import type { APIResponse } from "$lib/models/ui";
19+
import type { APIResponse, HTMLInputElementEvent } from "$lib/models/ui";
2020
2121
// Components
2222
import Button from "./shared/Button.svelte";
@@ -150,7 +150,7 @@
150150
logWarning("Warning: The created Deployment Environment has Deploy Approval Process configuration only, the Block Explorer API Key and Upgrade Approval Process are not set");
151151
if (!result.data) return;
152152
153-
addAPToDropdown(result.data.approvalProcess)
153+
updateSelectedApprovalProcessWithExisting(result.data.approvalProcess)
154154
return result.data.approvalProcess;
155155
}
156156
@@ -333,14 +333,13 @@
333333
deploying = false;
334334
}
335335
336-
function handleInputChange(event: Event) {
337-
const target = event.target as HTMLInputElement;
338-
inputsWithValue[target.name] = target.value;
336+
function handleInputChange(event: HTMLInputElementEvent) {
337+
const { name, value } = event.currentTarget;
338+
inputsWithValue[name] = value;
339339
}
340340
341-
function handleSaltChanged(event: Event) {
342-
const target = event.target as HTMLInputElement;
343-
salt = target.value;
341+
function handleSaltChanged(event: HTMLInputElementEvent) {
342+
salt = event.currentTarget.value;
344343
}
345344
346345
onDestroy(() => {

0 commit comments

Comments
 (0)