Skip to content

Commit f3bab9d

Browse files
authored
Merge branch 'main' into add-amoy-support
2 parents cb42414 + 45f75f6 commit f3bab9d

File tree

40 files changed

+1791
-2596
lines changed

40 files changed

+1791
-2596
lines changed

README.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ resources:
7676
relayers:
7777
relayer-1:
7878
name: 'Test Relayer 1'
79-
network: 'goerli'
79+
network: 'sepolia'
8080
min-balance: 1000
8181
policy: ${self:resources.policies.policy-1}
8282
api-keys:
@@ -99,16 +99,14 @@ A list of properties that support direct referencing:
9999
- `action-trigger` may reference an `actionid` in Monitor
100100
- `action-condition` may reference an `actionId` in Monitor
101101
- `address-from-relayer` may reference a `relayerId` in Relayer
102-
- `notification-ids` may reference multiple `notificationId` in Category
103102
- `notify-config.channels` may reference multiple `notificationId` in Monitor
104-
- `notify-config.category` may reference a `categoryId` in Monitor
105103
- `contracts` may be used over `addresses` and reference multiple `contractId` in Monitor
106104
The following is an example of how a direct reference to a Defender contract and relayer can be used in monitor and action respectively:
107105

108106
```yaml
109107
...
110108
contracts:
111-
contract-1: 'goerli-0xd70d6A0480420b4C788AF91d0E1b0ca6141A9De8' # contractId of an existing resource in Defender
109+
contract-1: 'sepolia-0x62034459131329bE4349A9cc322B03c63806Aa11' # contractId of an existing resource in Defender
112110
relayers:
113111
relayer-2: 'bcb659c6-7e11-4d37-a15b-0fa9f3d3442c' # relayerId of an existing relayer in Defender
114112
actions:
@@ -124,7 +122,7 @@ monitors:
124122
block-example:
125123
name: 'Block Example'
126124
type: 'BLOCK'
127-
network: 'goerli'
125+
network: 'sepolia'
128126
risk-category: 'TECHNICAL'
129127
# optional - either contracts OR addresses should be defined
130128
contracts:
@@ -209,14 +207,6 @@ More information can be found on our documentation page [here](https://docs.open
209207

210208
## Caveats
211209

212-
Note that when setting up the notification configuration for a monitor, the `channels` property will always be prioritised over `category`. A notification category can only be associated to a monitor with no linked notification channels. This means that the `channels` property should be assigned the value `[]` in order to prioritise the `category` property.
213-
214-
```yaml
215-
notify-config:
216-
channels: [] # assign channels as empty list if you wish to use a category
217-
category: ${self:resources.categories.medium-severity} # optional
218-
```
219-
220210
Errors thrown during the `deploy` process, will not revert any prior changes. Common errors are:
221211

222212
- Not having set the API key and secret

examples/defender-test-project/serverless.yml

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ resources:
5757
- '0x0f06aB75c7DD497981b75CD82F6566e3a5CAd8f2'
5858
# optional
5959
eip1559-pricing: true
60-
private-transactions: true
60+
private-transactions: 'flashbots-fast'
6161

6262
secrets:
6363
# optional - global secrets are not affected by stackName changes
@@ -78,12 +78,12 @@ resources:
7878
abi: ${file(./abis/demoflash.json.abi)}
7979
# optional
8080
nat-spec: null
81-
contract-2: 'goerli-0xd70d6A0480420b4C788AF91d0E1b0ca6141A9De8'
81+
contract-2: 'sepolia-0x62034459131329bE4349A9cc322B03c63806Aa11'
8282

8383
relayers:
8484
relayer-1:
8585
name: 'Test Relayer 1'
86-
network: 'goerli'
86+
network: 'sepolia'
8787
min-balance: 1000
8888
# optional
8989
policy: ${self:resources.policies.policy-1}
@@ -121,30 +121,12 @@ resources:
121121
url: ${self:custom.config.notifications.slack}
122122
paused: false
123123

124-
categories:
125-
high-severity:
126-
name: High Severity
127-
# optional
128-
description: A default category to be assigned for high risk monitors.
129-
low-severity:
130-
name: Low Severity
131-
# optional
132-
description: A default category to be assigned for low risk monitors.
133-
medium-severity:
134-
name: Medium Severity
135-
# optional
136-
description: A default category to be assigned for medium risk monitors.
137-
# optional
138-
notification-ids:
139-
- ${self:resources.notifications.email-1}
140-
- ${self:resources.notifications.slack-1}
141-
142124
monitors:
143125
# unique resource name
144126
block-example:
145127
name: 'Block Example'
146128
type: 'BLOCK'
147-
network: 'goerli'
129+
network: 'sepolia'
148130
risk-category: 'TECHNICAL' # optional
149131
# optional - either contracts OR addresses should be defined
150132
contracts:
@@ -193,8 +175,7 @@ resources:
193175
notify-config:
194176
timeout: 0 # optional
195177
message: null # optional
196-
channels: [] # assign channels as empty list if you wish to use a category
197-
category: ${self:resources.categories.medium-severity} # optional (only used if channels is empty)
178+
channels: [] # optional
198179
# optional
199180
conditions:
200181
min-scanner-count: 1

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openzeppelin/defender-as-code",
3-
"version": "2.5.0",
3+
"version": "3.0.0",
44
"description": "Configure your Defender environment via code",
55
"main": "./lib/index.js",
66
"types": "./lib/index.d.ts",
@@ -70,7 +70,7 @@
7070
"typescript": "^4.9.5"
7171
},
7272
"dependencies": {
73-
"@openzeppelin/defender-sdk": "^1.10.0",
73+
"@openzeppelin/defender-sdk": "^1.13.1",
7474
"keccak256": "^1.0.6",
7575
"lodash": "^4.17.21",
7676
"prompt": "^1.3.0"

src/cmd/deploy.ts

Lines changed: 4 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
getEquivalentResourceByKey,
2121
getConsolidatedSecrets,
2222
validateTypesAndSanitise,
23-
constructNotificationCategory,
2423
validateAdditionalPermissionsOrThrow,
2524
getDeployClient,
2625
formatABI,
@@ -49,7 +48,6 @@ import {
4948
DefenderMonitorTrigger,
5049
DefenderMonitorFilterTrigger,
5150
DefenderBlockExplorerApiKey,
52-
DefenderCategory,
5351
DefenderFortaMonitorResponse,
5452
DefenderBlockMonitorResponse,
5553
Resources,
@@ -63,8 +61,6 @@ import {
6361
Actions,
6462
BlockExplorerApiKey,
6563
BlockExplorerApiKeys,
66-
Categories,
67-
Category,
6864
Contract,
6965
Contracts,
7066
DefenderID,
@@ -116,7 +112,6 @@ export default class DefenderDeploy {
116112
monitors: [],
117113
actions: [],
118114
notifications: [],
119-
categories: [],
120115
contracts: [],
121116
relayerApiKeys: [],
122117
secrets: [],
@@ -224,20 +219,6 @@ export default class DefenderDeploy {
224219
},
225220
);
226221

227-
// Notification Categories
228-
const categories: Categories = this.resources?.categories ?? {};
229-
const dCategories = await monitorClient.listNotificationCategories();
230-
const categoryDifference = _.differenceWith(
231-
dCategories,
232-
Object.entries(categories),
233-
(a: DefenderCategory, b: [string, Category | DefenderID]) => {
234-
if (isDefenderId(b[1])) {
235-
return a.categoryId === b[1];
236-
}
237-
return a.stackResourceId === getResourceID(getStackName(this.serverless), b[0]);
238-
},
239-
);
240-
241222
// Actions
242223
const actions: Actions = this.resources.actions ?? {};
243224
const actionClient = getActionClient(this.teamKey!);
@@ -282,7 +263,6 @@ export default class DefenderDeploy {
282263
difference.contracts = contractDifference;
283264
difference.monitors = monitorDifference;
284265
difference.notifications = notificationDifference;
285-
difference.categories = categoryDifference;
286266
difference.actions = actionDifference;
287267
difference.secrets = secretsDifference;
288268
difference.blockExplorerApiKeys = blockExplorerApiKeyDifference;
@@ -461,7 +441,7 @@ export default class DefenderDeploy {
461441
};
462442
},
463443
// on create
464-
async (contract: Contract, stackResourceId: string) => {
444+
async (contract: Contract, _stackResourceId: string) => {
465445
const importedContract = await client.addContract({
466446
name: contract.name,
467447
network: contract.network,
@@ -713,97 +693,12 @@ export default class DefenderDeploy {
713693
);
714694
}
715695

716-
private async deployCategories(output: DeployOutput<DefenderCategory>) {
717-
const categories: Categories = this.resources?.categories ?? {};
718-
const client = getMonitorClient(this.teamKey!);
719-
const notifications = await client.listNotificationChannels();
720-
const retrieveExisting = () => client.listNotificationCategories();
721-
722-
await this.wrapper<Category, DefenderCategory>(
723-
this.serverless,
724-
'Categories',
725-
removeDefenderIdReferences(categories),
726-
retrieveExisting,
727-
// on update
728-
async (category: Category, match: DefenderCategory) => {
729-
const matchStackResourceId =
730-
match.stackResourceId ?? getResourceID(getStackName(this.serverless), _.kebabCase(match.name));
731-
const newCategory = constructNotificationCategory(
732-
this.serverless,
733-
this.resources,
734-
category,
735-
matchStackResourceId,
736-
notifications,
737-
);
738-
739-
const mappedMatch = {
740-
name: match.name,
741-
description: match.description,
742-
notificationIds: match.notificationIds,
743-
stackResourceId: matchStackResourceId,
744-
};
745-
if (_.isEqual(validateTypesAndSanitise(newCategory), validateTypesAndSanitise(mappedMatch))) {
746-
return {
747-
name: matchStackResourceId,
748-
id: match.categoryId,
749-
success: false,
750-
response: match,
751-
notice: `Skipped ${matchStackResourceId} - no changes detected`,
752-
};
753-
}
754-
755-
const updatedCategory = await client.updateNotificationCategory(match.categoryId, {
756-
categoryId: match.categoryId,
757-
...newCategory,
758-
});
759-
760-
return {
761-
name: matchStackResourceId,
762-
id: updatedCategory.categoryId,
763-
success: true,
764-
response: updatedCategory,
765-
};
766-
},
767-
// on create
768-
async (_: Category, stackResourceId: string) => {
769-
return {
770-
name: stackResourceId,
771-
id: '',
772-
success: false,
773-
notice: 'Creating custom notification categories is not yet supported',
774-
};
775-
// const createdCategory = await client.createNotificationCategory(
776-
// constructNotificationCategory(this.serverless, category, stackResourceId, notifications),
777-
// );
778-
// return {
779-
// name: stackResourceId,
780-
// id: createdCategory.categoryId,
781-
// success: true,
782-
// response: createdCategory,
783-
// };
784-
},
785-
// on remove
786-
async (_: DefenderCategory[]) => {
787-
this.log.warn(`Deleting notification categories is not yet supported.`);
788-
// await Promise.all(categories.map(async (n) => await client.deleteNotificationCategory(n.categoryId)));
789-
},
790-
// overrideMatchDefinition
791-
// TODO: remove this when we allow creating new categories
792-
(a: DefenderCategory, b: Category) => {
793-
return a.name === b.name;
794-
},
795-
output,
796-
this.ssotDifference?.categories,
797-
);
798-
}
799-
800696
private async deployMonitors(output: DeployOutput<DefenderMonitor>) {
801697
try {
802698
const monitors: Monitors = this.resources?.monitors ?? {};
803699
const client = getMonitorClient(this.teamKey!);
804700
const actions = await getActionClient(this.teamKey!).list();
805701
const notifications = await client.listNotificationChannels();
806-
const categories = await client.listNotificationCategories();
807702

808703
// TODO: Add a new endpoint in defender-sdk which includes contract ABI and NatSpec
809704
const contracts = await getProposalClient(this.teamKey!).listContracts();
@@ -855,7 +750,6 @@ export default class DefenderDeploy {
855750
notifications,
856751
actions.items,
857752
blockwatchersForNetwork,
858-
categories,
859753
contracts,
860754
);
861755

@@ -881,9 +775,7 @@ export default class DefenderDeploy {
881775
notificationChannels: match.notifyConfig?.notifications.map(
882776
(n: DefenderNotificationReference) => n.notificationId,
883777
),
884-
notificationCategoryId: _.isEmpty(match.notifyConfig?.notifications)
885-
? match.notifyConfig?.notificationCategoryId
886-
: undefined,
778+
severityLevel: match.notifyConfig?.severityLevel,
887779
type: match.type,
888780
stackResourceId: match.stackResourceId,
889781
network: match.network,
@@ -950,7 +842,6 @@ export default class DefenderDeploy {
950842
notifications,
951843
actions.items,
952844
blockwatchersForNetwork,
953-
categories,
954845
contracts,
955846
),
956847
);
@@ -1244,7 +1135,7 @@ export default class DefenderDeploy {
12441135
async (forkedNetwork: ForkedNetworkRequest, stackResourceId: string) => {
12451136
const createdForkedNetwork = await client.createForkedNetwork({
12461137
name: forkedNetwork.name,
1247-
supportedNetwork: forkedNetwork['supported-network'],
1138+
supportedNetwork: forkedNetwork['supported-network'] as any, // cast to prevent typing errors in deploy when networks in SDK are not aligned,
12481139
rpcUrl: forkedNetwork['rpc-url'],
12491140
blockExplorerUrl: forkedNetwork['block-explorer-url'] ?? undefined,
12501141
apiKey: forkedNetwork['api-key'] ?? undefined,
@@ -1527,11 +1418,6 @@ export default class DefenderDeploy {
15271418
created: [],
15281419
updated: [],
15291420
};
1530-
const categories: DeployOutput<DefenderCategory> = {
1531-
removed: [],
1532-
created: [],
1533-
updated: [],
1534-
};
15351421
const secrets: DeployOutput<string> = {
15361422
removed: [],
15371423
created: [],
@@ -1574,7 +1460,6 @@ export default class DefenderDeploy {
15741460
contracts,
15751461
relayers,
15761462
notifications,
1577-
categories,
15781463
secrets,
15791464
blockExplorerApiKeys,
15801465
forkedNetworks,
@@ -1588,9 +1473,8 @@ export default class DefenderDeploy {
15881473
// Always deploy relayers before actions
15891474
await this.deployRelayers(stdOut.relayers);
15901475
await this.deployActions(stdOut.actions);
1591-
// Deploy notifications before monitors and categories
1476+
// Deploy notifications before monitors
15921477
await this.deployNotifications(stdOut.notifications);
1593-
await this.deployCategories(stdOut.categories);
15941478
await this.deployMonitors(stdOut.monitors);
15951479
await this.deployBlockExplorerApiKey(stdOut.blockExplorerApiKeys);
15961480

0 commit comments

Comments
 (0)