From 6ca9e229a2ad33337c6dca2e5df2ea4390b0be2d Mon Sep 17 00:00:00 2001 From: Mateusz Radomski Date: Thu, 28 Mar 2024 09:36:17 +0100 Subject: [PATCH 1/4] Fetch multisig threshold in the proxy detector --- packages/discovery-types/src/proxyDetails.ts | 1 + .../src/discovery/proxies/auto/GnosisSafe.ts | 38 +++++++++++++++++++ packages/discovery/src/utils/UnixTime.ts | 24 ++++++------ 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/packages/discovery-types/src/proxyDetails.ts b/packages/discovery-types/src/proxyDetails.ts index a8cf9737..f132b178 100644 --- a/packages/discovery-types/src/proxyDetails.ts +++ b/packages/discovery-types/src/proxyDetails.ts @@ -51,6 +51,7 @@ export interface GnosisSafeUpgradeability { type: 'gnosis safe' masterCopy: EthereumAddress modules: EthereumAddress[] + threshold: string } export interface GnosisSafeZodiacModuleUpgradeability { diff --git a/packages/discovery/src/discovery/proxies/auto/GnosisSafe.ts b/packages/discovery/src/discovery/proxies/auto/GnosisSafe.ts index c094c1c9..f7d9d72f 100644 --- a/packages/discovery/src/discovery/proxies/auto/GnosisSafe.ts +++ b/packages/discovery/src/discovery/proxies/auto/GnosisSafe.ts @@ -28,6 +28,36 @@ async function getMasterCopy( } } +async function getOwnersCount( + provider: DiscoveryProvider, + address: EthereumAddress, + blockNumber: number, +): Promise { + const owners = await getCallResult( + provider, + address, + 'function getOwners() view returns (address[])', + [], + blockNumber, + ) + + return owners?.length +} + +async function getThreshold( + provider: DiscoveryProvider, + address: EthereumAddress, + blockNumber: number, +): Promise { + return await getCallResult( + provider, + address, + 'function getThreshold() view returns (uint256)', + [], + blockNumber, + ) +} + export async function detectGnosisSafe( provider: DiscoveryProvider, address: EthereumAddress, @@ -41,6 +71,13 @@ 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) + let thresholdString = 'Cannot retrieve threshold' + if (ownerCount !== undefined && threshold !== undefined) { + thresholdString = `${threshold} of ${ownerCount} (${((threshold / ownerCount) * 100).toFixed()}%)` + } + return { implementations: [masterCopy], relatives: modules, @@ -48,6 +85,7 @@ export async function detectGnosisSafe( type: 'gnosis safe', masterCopy, modules, + threshold: thresholdString, }, } } diff --git a/packages/discovery/src/utils/UnixTime.ts b/packages/discovery/src/utils/UnixTime.ts index 0e447d2a..8bd4deca 100644 --- a/packages/discovery/src/utils/UnixTime.ts +++ b/packages/discovery/src/utils/UnixTime.ts @@ -36,8 +36,8 @@ export class UnixTime { period === 'day' ? UnixTime.DAY : period === 'hour' - ? UnixTime.HOUR - : UnixTime.MINUTE + ? UnixTime.HOUR + : UnixTime.MINUTE return new UnixTime(this.timestamp - (this.timestamp % modulus)) } @@ -46,8 +46,8 @@ export class UnixTime { period === 'day' ? UnixTime.DAY : period === 'hour' - ? UnixTime.HOUR - : UnixTime.MINUTE + ? UnixTime.HOUR + : UnixTime.MINUTE const remaining = modulus - (this.timestamp % modulus) return new UnixTime(this.timestamp + remaining) } @@ -57,10 +57,10 @@ export class UnixTime { period === 'day' ? UnixTime.DAY : period === 'hour' - ? UnixTime.HOUR - : period === 'minute' - ? UnixTime.MINUTE - : UnixTime.SIX_HOURS + ? UnixTime.HOUR + : period === 'minute' + ? UnixTime.MINUTE + : UnixTime.SIX_HOURS const isFull = this.timestamp % modulus ? false : true return isFull } @@ -76,10 +76,10 @@ export class UnixTime { period === 'days' ? UnixTime.DAY : period === 'hours' - ? UnixTime.HOUR - : period === 'minutes' - ? UnixTime.MINUTE - : 1 + ? UnixTime.HOUR + : period === 'minutes' + ? UnixTime.MINUTE + : 1 return new UnixTime(this.timestamp + value * unit) } From 909f0d23ab7102f90bb4bc18bff324fd2c1681d6 Mon Sep 17 00:00:00 2001 From: Mateusz Radomski Date: Thu, 28 Mar 2024 09:38:52 +0100 Subject: [PATCH 2/4] Changeset --- packages/discovery-types/CHANGELOG.md | 6 ++++++ packages/discovery-types/package.json | 2 +- packages/discovery/CHANGELOG.md | 8 ++++++++ packages/discovery/package.json | 4 ++-- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/discovery-types/CHANGELOG.md b/packages/discovery-types/CHANGELOG.md index d3c5bce2..359409be 100644 --- a/packages/discovery-types/CHANGELOG.md +++ b/packages/discovery-types/CHANGELOG.md @@ -1,5 +1,11 @@ # @l2beat/discovery-types +## 0.8.1 + +### Patch Changes + +- Compute multisig threshold in the proxy detector + ## 0.8.0 ### Minor Changes diff --git a/packages/discovery-types/package.json b/packages/discovery-types/package.json index f49e5ec5..f088399e 100644 --- a/packages/discovery-types/package.json +++ b/packages/discovery-types/package.json @@ -1,7 +1,7 @@ { "name": "@l2beat/discovery-types", "description": "Common types for @l2beat/discovery.", - "version": "0.8.0", + "version": "0.8.1", "license": "MIT", "repository": "https://github.com/l2beat/tools", "bugs": { diff --git a/packages/discovery/CHANGELOG.md b/packages/discovery/CHANGELOG.md index 715a46bf..c13fc92e 100644 --- a/packages/discovery/CHANGELOG.md +++ b/packages/discovery/CHANGELOG.md @@ -1,5 +1,13 @@ # @l2beat/discovery +## 0.46.6 + +### Patch Changes + +- Compute multisig threshold in the proxy detector +- Updated dependencies + - @l2beat/discovery-types@0.8.1 + ## 0.46.5 ### Patch Changes diff --git a/packages/discovery/package.json b/packages/discovery/package.json index 7369ee19..74b40218 100644 --- a/packages/discovery/package.json +++ b/packages/discovery/package.json @@ -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": { @@ -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", From 9cef830e602e9031fe708f6d0b25c5a0fee02f01 Mon Sep 17 00:00:00 2001 From: Mateusz Radomski Date: Thu, 28 Mar 2024 09:41:11 +0100 Subject: [PATCH 3/4] Reformat fix, probably because new version of Prettier --- .../src/discovery/proxies/auto/GnosisSafe.ts | 5 +++- packages/discovery/src/utils/UnixTime.ts | 24 +++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/discovery/src/discovery/proxies/auto/GnosisSafe.ts b/packages/discovery/src/discovery/proxies/auto/GnosisSafe.ts index f7d9d72f..aef8d9b8 100644 --- a/packages/discovery/src/discovery/proxies/auto/GnosisSafe.ts +++ b/packages/discovery/src/discovery/proxies/auto/GnosisSafe.ts @@ -75,7 +75,10 @@ export async function detectGnosisSafe( const threshold = await getThreshold(provider, address, blockNumber) let thresholdString = 'Cannot retrieve threshold' if (ownerCount !== undefined && threshold !== undefined) { - thresholdString = `${threshold} of ${ownerCount} (${((threshold / ownerCount) * 100).toFixed()}%)` + thresholdString = `${threshold} of ${ownerCount} (${( + (threshold / ownerCount) * + 100 + ).toFixed()}%)` } return { diff --git a/packages/discovery/src/utils/UnixTime.ts b/packages/discovery/src/utils/UnixTime.ts index 8bd4deca..0e447d2a 100644 --- a/packages/discovery/src/utils/UnixTime.ts +++ b/packages/discovery/src/utils/UnixTime.ts @@ -36,8 +36,8 @@ export class UnixTime { period === 'day' ? UnixTime.DAY : period === 'hour' - ? UnixTime.HOUR - : UnixTime.MINUTE + ? UnixTime.HOUR + : UnixTime.MINUTE return new UnixTime(this.timestamp - (this.timestamp % modulus)) } @@ -46,8 +46,8 @@ export class UnixTime { period === 'day' ? UnixTime.DAY : period === 'hour' - ? UnixTime.HOUR - : UnixTime.MINUTE + ? UnixTime.HOUR + : UnixTime.MINUTE const remaining = modulus - (this.timestamp % modulus) return new UnixTime(this.timestamp + remaining) } @@ -57,10 +57,10 @@ export class UnixTime { period === 'day' ? UnixTime.DAY : period === 'hour' - ? UnixTime.HOUR - : period === 'minute' - ? UnixTime.MINUTE - : UnixTime.SIX_HOURS + ? UnixTime.HOUR + : period === 'minute' + ? UnixTime.MINUTE + : UnixTime.SIX_HOURS const isFull = this.timestamp % modulus ? false : true return isFull } @@ -76,10 +76,10 @@ export class UnixTime { period === 'days' ? UnixTime.DAY : period === 'hours' - ? UnixTime.HOUR - : period === 'minutes' - ? UnixTime.MINUTE - : 1 + ? UnixTime.HOUR + : period === 'minutes' + ? UnixTime.MINUTE + : 1 return new UnixTime(this.timestamp + value * unit) } From cfe8f6dcec4005e34ef46663c0d27d8fe51a36f9 Mon Sep 17 00:00:00 2001 From: Mateusz Radomski Date: Thu, 28 Mar 2024 11:14:36 +0100 Subject: [PATCH 4/4] Assert success of fetching --- .../src/discovery/proxies/auto/GnosisSafe.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/discovery/src/discovery/proxies/auto/GnosisSafe.ts b/packages/discovery/src/discovery/proxies/auto/GnosisSafe.ts index aef8d9b8..5d813a97 100644 --- a/packages/discovery/src/discovery/proxies/auto/GnosisSafe.ts +++ b/packages/discovery/src/discovery/proxies/auto/GnosisSafe.ts @@ -73,13 +73,13 @@ export async function detectGnosisSafe( const ownerCount = await getOwnersCount(provider, address, blockNumber) const threshold = await getThreshold(provider, address, blockNumber) - let thresholdString = 'Cannot retrieve threshold' - if (ownerCount !== undefined && threshold !== undefined) { - thresholdString = `${threshold} of ${ownerCount} (${( - (threshold / ownerCount) * - 100 - ).toFixed()}%)` - } + 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],