This guide shows how you can set up Defender to automatically add a contract to the Admin dashboard whenever a factory creates it.
This automation is achieved through the following relationship between Defender components:
- A Sentinel watches for every successful Event emitted by the contract that creates a clone. If detected, it triggers an Autotask to run and passes along information about the transaction
- The Autotask makes use of the Admin API to add the address of the newly created contract to Admin dashboard
In this case, the contract ABI can be pre-supplied since clone contracts will have identical ABIs. Alternatively, you may be able to dynamically retrieve the ABI from a verified contract at a given address using Etherscan’s API.
To programmatically add a contract to the Admin dashboard, the defender-admin-client API requires credentials in the form of an API key and secret.
You can use an existing API key or create one to be used solely for this purpose.
To create a new key, open the hamburger menu at the top right and select Team API Keys. Generate a new key and secret with at least the ability to create Admin proposals. Copy and save these in a secure location.
You can use Defender’s handy Secrets vault to securely store the Admin API key and secret created in the previous step.
Select Autotask from the left and then Secrets. Give the API key and secret a name and paste in the respective string.
From the Autotask dashboard at the right select Create Autotask.
Name the Autotask and select Webhook.
Paste in the Autotask code and hit Create.
Now the Autotask is ready to be triggered by a Sentinel.
Note that manually triggering this Autotask will be flagged as an error, since the Autotask relies on data supplied by the actual firing of the Sentinel (such as the address of the newly deployed clone contract address).
This Sentinel will watch for an event emitted by the contract signaling that a new clone has been created.
Select Sentinel from the left, then Create Sentinel.
Leave the Sentinel Type as Contract.
Give it a name, such as "New Clone Event Detected"
Select the appropriate network.
If the factory contract is already loaded into the Admin dashboard, select the name of the contract from the Addresses dropdown. Otherwise, paste the contract address and ABI.
Leave the confirmation blocks at 1 for rapid detection or specify a higher block number for additional thoroughness.
Now comes the time to select the conditions that will trigger the Sentinel. Either function calls or event emissions can be monitored.
Select the event name for clone creation and leave the field blank to catch all emitted clone creation events. Select Next.
Under Execute an Autotask, Select the Autotask name created in the previous step.
As with any account action, the triggering of this Sentinel will be recorded in the Defender Logging. If you'd like, you can select a way of receiving notification when this Sentinel gets triggered. Simply select your choice from the Create New Notification.
To test from the UI, select the factory contract from the Admin dashboard, navigate to New Proposal -> Admin action, and select the contract creation function along with an execution strategy that will work based on the contract's permissions.
Then on the next screen, verify the information and select Approve and Execute and pay the gas.
Head over to Logging to verify the status of the Admin proposal, the firing of the Sentinel, the execution of the Autotask, and finally the contract being added to the Admin dashboard.
Navigate to Admin to see the new contract along with the others in the dashboard.