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

Fetch multisig threshold in the proxy detector #166

Merged
merged 4 commits into from
Mar 28, 2024
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
6 changes: 6 additions & 0 deletions packages/discovery-types/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @l2beat/discovery-types

## 0.8.1

### Patch Changes

- Compute multisig threshold in the proxy detector

## 0.8.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/discovery-types/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@l2beat/discovery-types",
"description": "Common types for @l2beat/discovery.",
"version": "0.8.0",
"version": "0.8.1",
mateuszradomski marked this conversation as resolved.
Show resolved Hide resolved
"license": "MIT",
"repository": "https://github.com/l2beat/tools",
"bugs": {
Expand Down
1 change: 1 addition & 0 deletions packages/discovery-types/src/proxyDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface GnosisSafeUpgradeability {
type: 'gnosis safe'
masterCopy: EthereumAddress
modules: EthereumAddress[]
threshold: string
}

export interface GnosisSafeZodiacModuleUpgradeability {
Expand Down
8 changes: 8 additions & 0 deletions packages/discovery/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @l2beat/discovery

## 0.46.6

### Patch Changes

- Compute multisig threshold in the proxy detector
- Updated dependencies
- @l2beat/[email protected]

## 0.46.5

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/discovery/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@l2beat/discovery",
"description": "L2Beat discovery - engine & tooling utilized for keeping an eye on L2s",
"version": "0.46.5",
"version": "0.46.6",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"bin": {
Expand All @@ -20,7 +20,7 @@
},
"dependencies": {
"@l2beat/backend-tools": "^0.5.1",
"@l2beat/discovery-types": "^0.8.0",
"@l2beat/discovery-types": "^0.8.1",
"@solidity-parser/parser": "^0.18.0",
"chalk": "^4.1.2",
"deep-diff": "^1.0.2",
Expand Down
41 changes: 41 additions & 0 deletions packages/discovery/src/discovery/proxies/auto/GnosisSafe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,36 @@ async function getMasterCopy(
}
}

async function getOwnersCount(
provider: DiscoveryProvider,
address: EthereumAddress,
blockNumber: number,
): Promise<number | undefined> {
const owners = await getCallResult<string[]>(
provider,
address,
'function getOwners() view returns (address[])',
[],
blockNumber,
)

return owners?.length
}

async function getThreshold(
provider: DiscoveryProvider,
address: EthereumAddress,
blockNumber: number,
): Promise<number | undefined> {
return await getCallResult<number>(
provider,
address,
'function getThreshold() view returns (uint256)',
[],
blockNumber,
)
}

export async function detectGnosisSafe(
provider: DiscoveryProvider,
address: EthereumAddress,
Expand All @@ -41,13 +71,24 @@ export async function detectGnosisSafe(
const modules = await getModules(provider, address, blockNumber)
assert(modules, 'Could not find modules for GnosisSafe')

const ownerCount = await getOwnersCount(provider, address, blockNumber)
const threshold = await getThreshold(provider, address, blockNumber)
assert(ownerCount !== undefined, 'Cannot retrieve owner count')
assert(threshold !== undefined, 'Cannot retrieve threshold')

const thresholdString = `${threshold} of ${ownerCount} (${(
(threshold / ownerCount) *
100
).toFixed()}%)`

return {
implementations: [masterCopy],
relatives: modules,
upgradeability: {
type: 'gnosis safe',
masterCopy,
modules,
threshold: thresholdString,
},
}
}
Loading