From 2702eae19a413c688276e25ef83563ba486cc9a9 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Mon, 12 Aug 2024 23:01:28 -0700 Subject: [PATCH] Handle edge cases for non-Safe smart contracts Older multi-signatures used `required()` instead of `getThreshold()`. Also handled non-multi-sig smart contracts with early exit. --- index.html | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 084351f..73c9528 100644 --- a/index.html +++ b/index.html @@ -194,13 +194,31 @@ }, 'safe' ] + }, + { + jsonrpc: '2.0', + id: 'required', + method: 'eth_call', + params: [ + { + to: safe, + data: '0xdc8452cd' // required() + }, + 'safe' + ] } ]) }).then(r => r.json()); - const { owners, threshold } = response.reduce((a, c) => ({ ...a, [c.id]: c.result }), {}); + const { owners, threshold, required } = response.reduce((a, c) => ({ ...a, [c.id]: c.result }), {}); + if (owners === undefined) { // Smart contract reverted + return { + owners: [safe], + threshold: -1 // Sentinel value for non Safe smart contract + } + } return { owners: [...owners.replace('0x', '').substring(128).matchAll(/.{64}/g)].map(o => `0x${o[0].substring(24)}`), - threshold: parseInt(threshold) + threshold: Number.isNaN(parseInt(threshold)) ? parseInt(required) : parseInt(threshold) } } @@ -210,6 +228,10 @@ root.insertAdjacentHTML('beforeend', `
  • ${safe}
  • `); return; } + else if (threshold === -1) { + root.insertAdjacentHTML('beforeend', `
  • ${safe} (Unknown smart contract)
  • `); + return; + } root.insertAdjacentHTML('beforeend', `
  • ${safe} (${threshold}-of-${owners.length})
  • `); const newRoot = document.createElement('ul'); root.querySelector('li:last-child').insertAdjacentElement('beforeend', newRoot); -- 2.47.3