]> git.ardis.lu - safe-owners/commitdiff
Handle edge cases for non-Safe smart contracts
authorArdis Lu <ardisglu@gmail.com>
Tue, 13 Aug 2024 06:01:28 +0000 (23:01 -0700)
committerArdis Lu <ardisglu@gmail.com>
Tue, 13 Aug 2024 06:01:28 +0000 (23:01 -0700)
Older multi-signatures used `required()` instead of `getThreshold()`. Also handled non-multi-sig smart contracts with early exit.

index.html

index 084351f750d45b194ac739fbe385b33eb9e915d1..73c952883cd5dc3bfc7867525366de23ec01766c 100644 (file)
               },
               '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)
       }
     }
 
         root.insertAdjacentHTML('beforeend', `<li>${safe}</li>`);
         return;
       }
+      else if (threshold === -1) {
+        root.insertAdjacentHTML('beforeend', `<li>${safe} (Unknown smart contract)</li>`);
+        return;
+      }
       root.insertAdjacentHTML('beforeend', `<li>${safe} (${threshold}-of-${owners.length})</li>`);
       const newRoot = document.createElement('ul');
       root.querySelector('li:last-child').insertAdjacentElement('beforeend', newRoot);
This page took 0.037515 seconds and 4 git commands to generate.