Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Create discovery-types package #18

Merged
merged 7 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "l2beat-uif",
"name": "@l2beat/tools",
"license": "MIT",
"private": true,
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions packages/discovery-types/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: '../../.eslintrc.json',
}
2 changes: 2 additions & 0 deletions packages/discovery-types/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
7 changes: 7 additions & 0 deletions packages/discovery-types/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": false,
"singleQuote": true,
"printWidth": 80,
"bracketSpacing": true,
"trailingComma": "all"
}
7 changes: 7 additions & 0 deletions packages/discovery-types/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright © 2023 L2BEAT

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3 changes: 3 additions & 0 deletions packages/discovery-types/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# L2BEAT Discovery types

A set of Discovery types to be used together with @l2beat/discovery package.
35 changes: 35 additions & 0 deletions packages/discovery-types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@l2beat/discovery-types",
"description": "Common types for @l2beat/discovery.",
"version": "0.1.0",
"license": "MIT",
"repository": "https://github.com/l2beat/tools",
"bugs": {
"url": "https://github.com/l2beat/tools/issues"
},
"author": "Michał Sobieraj-Jakubiec <[email protected]>",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist",
"src",
"!**/*.test.*",
"!**/*.snapshot",
"!src/test",
"!dist/test"
],
"scripts": {
"clean": "rm -rf dist",
"build": "tsc",
"start": "node -r esbuild-register src/",
"format:fix": "prettier --write .",
"format": "prettier --check .",
"lint:fix": "yarn lint --fix",
"lint": "eslint --ext .ts,.tsx --max-warnings 0 src",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"zod": "^3.22.2"
},
"devDependencies": {}
}
31 changes: 31 additions & 0 deletions packages/discovery-types/src/Discovery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { EthereumAddress } from './EthereumAddress'
import { Hash256 } from './Hash256'
import { UpgradeabilityParameters } from './proxyDetails'

export interface DiscoveryOutput {
name: string
chain: string
blockNumber: number
contracts: ContractParameters[]
eoas: EthereumAddress[]
abis: Record<string, string[]>
configHash: Hash256
version: number
}

export interface ContractParameters {
name: string
derivedName?: string
unverified?: true
address: EthereumAddress
upgradeability: UpgradeabilityParameters
values?: Record<string, ContractValue>
errors?: Record<string, string>
}

export type ContractValue =
| string
| number
| boolean
| ContractValue[]
| { [key: string]: ContractValue | undefined }
3 changes: 3 additions & 0 deletions packages/discovery-types/src/EthereumAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface EthereumAddress extends String {
_EthereumAddressBrand: string
}
3 changes: 3 additions & 0 deletions packages/discovery-types/src/Hash256.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface Hash256 extends String {
_Hash256Brand: string
}
2 changes: 2 additions & 0 deletions packages/discovery-types/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './Discovery'
export * from './proxyDetails'
149 changes: 149 additions & 0 deletions packages/discovery-types/src/proxyDetails.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import { z } from 'zod'

import { EthereumAddress } from './EthereumAddress'

export interface ProxyDetails {
upgradeability: UpgradeabilityParameters
implementations: EthereumAddress[]
relatives: EthereumAddress[]
}

export type ManualProxyType = z.infer<typeof ManualProxyType>
export const ManualProxyType = z.enum([
'new Arbitrum proxy',
'call implementation proxy',
'zkSync Lite proxy',
'zkSpace proxy',
'Eternal Storage proxy',
'Polygon Extension proxy',
])

export type UpgradeabilityParameters =
| ImmutableUpgradeability
| GnosisSafeUpgradeability
| EIP1967ProxyUpgradeability
| PolygonProxyUpgradeability
| ZeppelinOSProxyUpgradeability
| StarkWareProxyUpgradeability
| StarkWareDiamondUpgradeability
| ArbitrumProxyUpgradeability
| NewArbitrumProxyUpgradeability
| ResolvedDelegateProxyUpgradeability
| EIP897ProxyUpgradeability
| CallImplementationProxyUpgradeability
| EIP2535ProxyUpgradeability
| ZkSyncLiteProxyUpgradeability
| EternalStorageProxyUpgradeability
| PolygonExtensionProxyUpgradeability
| ZkSpaceProxyUpgradeability

export interface ImmutableUpgradeability {
type: 'immutable'
}

export interface GnosisSafeUpgradeability {
type: 'gnosis safe'
masterCopy: EthereumAddress
}

export interface EIP1967ProxyUpgradeability {
type: 'EIP1967 proxy'
admin: EthereumAddress
implementation: EthereumAddress
}

export interface PolygonProxyUpgradeability {
type: 'Polygon proxy'
admin: EthereumAddress
implementation: EthereumAddress
}

export interface ZeppelinOSProxyUpgradeability {
type: 'ZeppelinOS proxy'
admin?: EthereumAddress
owner?: EthereumAddress
implementation: EthereumAddress
}

export interface StarkWareProxyUpgradeability {
type: 'StarkWare proxy'
implementation: EthereumAddress
callImplementation?: EthereumAddress
upgradeDelay: number
isFinal: boolean
useConstantDelay?: boolean
proxyGovernance?: EthereumAddress[]
}

export interface StarkWareDiamondUpgradeability {
type: 'StarkWare diamond'
implementation: EthereumAddress
upgradeDelay: number
isFinal: boolean
facets: Record<string, EthereumAddress>
proxyGovernance?: EthereumAddress[]
}

export interface ArbitrumProxyUpgradeability {
type: 'Arbitrum proxy'
admin: EthereumAddress
adminImplementation: EthereumAddress
userImplementation: EthereumAddress
}

export interface NewArbitrumProxyUpgradeability {
type: 'new Arbitrum proxy'
admin: EthereumAddress
implementation: EthereumAddress
adminImplementation: EthereumAddress
userImplementation: EthereumAddress
}

export interface ResolvedDelegateProxyUpgradeability {
type: 'resolved delegate proxy'
addressManager: EthereumAddress
implementationName: string
implementation: EthereumAddress
}

export interface EIP897ProxyUpgradeability {
type: 'EIP897 proxy'
isUpgradable: boolean
implementation: EthereumAddress
}

export interface CallImplementationProxyUpgradeability {
type: 'call implementation proxy'
implementation: EthereumAddress
}

export interface EIP2535ProxyUpgradeability {
type: 'EIP2535 diamond proxy'
facets: EthereumAddress[]
}

export interface ZkSyncLiteProxyUpgradeability {
type: 'zkSync Lite proxy'
admin: EthereumAddress
implementation: EthereumAddress
additional: EthereumAddress
}

export interface EternalStorageProxyUpgradeability {
type: 'Eternal Storage proxy'
admin: EthereumAddress
implementation: EthereumAddress
}

export interface PolygonExtensionProxyUpgradeability {
type: 'Polygon Extension proxy'
admin: EthereumAddress
implementation: EthereumAddress
extension: EthereumAddress
}
export interface ZkSpaceProxyUpgradeability {
type: 'zkSpace proxy'
admin: EthereumAddress
implementation: EthereumAddress
additional: EthereumAddress[]
}
8 changes: 8 additions & 0 deletions packages/discovery-types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"incremental": true
},
"include": ["src"]
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3564,3 +3564,8 @@ yocto-queue@^0.1.0:
version "0.1.0"
resolved "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz"
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==

zod@^3.22.2:
version "3.22.2"
resolved "https://registry.yarnpkg.com/zod/-/zod-3.22.2.tgz#3add8c682b7077c05ac6f979fea6998b573e157b"
integrity sha512-wvWkphh5WQsJbVk1tbx1l1Ly4yg+XecD+Mq280uBGt9wa5BKSWf4Mhp6GmrkPixhMxmabYY7RbzlwVP32pbGCg==