Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add approval process create API + example #275

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions examples/create-approval-process/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require('dotenv').config();

const { Defender } = require('@openzeppelin/defender-sdk');

async function main() {
const creds = { apiKey: process.env.API_KEY, apiSecret: process.env.API_SECRET };
const client = new Defender(creds);

const relayers = await client.relay.list();
let relayer = relayers.items.find((relayer) => relayer.network === 'sepolia');
if (!relayer) {
console.log('Relayer not found, creating one');
relayer = await client.relay.create({ name: 'My Testnet Relayer', network: 'sepolia', minBalance: 0 });
}

const approvalProcess = await client.approvalProcess.create({
name: 'My Approval Process 2',
network: 'sepolia',
via: relayer.address,
viaType: 'Relayer',
relayerId: relayer.relayerId,
});

console.log(approvalProcess);
}

if (require.main === module) {
main().catch(console.error);
}
15 changes: 15 additions & 0 deletions examples/create-approval-process/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@openzeppelin/defender-sdk-example-create-approval-process",
"version": "1.15.0",
"private": true,
"main": "index.js",
"author": "OpenZeppelin Defender <[email protected]>",
"license": "MIT",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"@openzeppelin/defender-sdk": "1.15.0",
"dotenv": "^16.3.1"
}
}
5 changes: 5 additions & 0 deletions packages/approval-process/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Defender SDK Approval Process client

The OpenZeppelin Defender provides a security operations (SecOps) platform for Ethereum with built-in best practices. Development teams implement Defender to ship faster and minimize security risks.

This library provides methods related to Approval Processes. See Examples for usage.
1 change: 1 addition & 0 deletions packages/approval-process/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../jest.config');
30 changes: 30 additions & 0 deletions packages/approval-process/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@openzeppelin/defender-sdk-approval-process-client",
"version": "1.15.0",
"description": "",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"scripts": {
"build": "rm -rf lib && tsc",
"test": "npm run test:unit",
"test:unit": "jest --verbose --passWithNoTests --forceExit",
"watch": "tsc -w"
},
"files": [
"lib",
"!*.test.js",
"!*.test.js.map",
"!*.test.d.ts",
"!*__mocks__"
],
"author": "OpenZeppelin Defender <[email protected]>",
"license": "MIT",
"dependencies": {
"@openzeppelin/defender-sdk-base-client": "^1.15.0",
"axios": "^1.6.7",
"lodash": "^4.17.21"
},
"publishConfig": {
"access": "public"
}
}
24 changes: 24 additions & 0 deletions packages/approval-process/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { BaseApiClient } from '@openzeppelin/defender-sdk-base-client';
import { CreateApprovalProcessRequest, CreateApprovalProcessResponse } from '../models/approval-process';

const PATH = '/approval-process';

export class ApprovalProcessClient extends BaseApiClient {
protected getPoolId(): string {
return process.env.DEFENDER_POOL_ID ?? 'us-west-2_94f3puJWv';
}

protected getPoolClientId(): string {
return process.env.DEFENDER_POOL_CLIENT_ID ?? '40e58hbc7pktmnp9i26hh5nsav';
}

protected getApiUrl(): string {
return process.env.DEFENDER_API_URL ?? 'https://defender-api.openzeppelin.com/v2/';
}

public async create(approvalProcess: CreateApprovalProcessRequest): Promise<CreateApprovalProcessResponse> {
return this.apiCall(async (api) => {
return await api.post(PATH, approvalProcess);
});
}
}
5 changes: 5 additions & 0 deletions packages/approval-process/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export { ApprovalProcessClient } from './api';
export { CreateApprovalProcessRequest, CreateApprovalProcessResponse } from './models/approval-process';

// eslint-disable-next-line @typescript-eslint/no-var-requires
export const VERSION = require('../package.json').version;
95 changes: 95 additions & 0 deletions packages/approval-process/src/models/approval-process.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { Network } from '@openzeppelin/defender-sdk-base-client';

export type ComponentType = ('deploy' | 'upgrade')[];

export interface Timelock {
address: string;
delay: string;
}
export interface FireblocksProposalParams {
apiKeyId: string;
vaultId: string;
assetId: string;
}

export type CreateApprovalProcessRequest =
| GenericApprovalProcessRequest
| MultisigApprovalProcessRequest
| RelayerApprovalProcessRequest
| RelayerGroupApprovalProcessRequest
| TimelockControllerApprovalProcessRequest
| FireblocksApprovalProcessRequest;

export interface BaseApprovalProcessRequest {
name: string;
/**
* When the approval process meant to be used in deployment environments
* it requires a component property to indicate the type of operation: 'deploy' or 'upgrade'
*/
component?: ComponentType;
network: Network;
/**
* Address of the approval process. It could be Contract, EOA, Relayer or any other kind of address.
*/
via: string;
stackResourceId?: string;
}

export interface GenericApprovalProcessRequest extends BaseApprovalProcessRequest {
viaType: 'EOA' | 'Contract' | 'Unknown' | 'ERC20' | 'Governor';
}

export interface MultisigApprovalProcessRequest extends BaseApprovalProcessRequest {
viaType: 'Multisig' | 'Gnosis Safe' | 'Safe' | 'Gnosis Multisig';
multisigSender: string;
}

export interface RelayerApprovalProcessRequest extends BaseApprovalProcessRequest {
viaType: 'Relayer';
relayerId: string;
}

export interface RelayerGroupApprovalProcessRequest extends BaseApprovalProcessRequest {
viaType: 'Relayer Group';
relayerGroupId: string;
}

export interface TimelockControllerApprovalProcessRequest extends BaseApprovalProcessRequest {
viaType: 'Timelock Controller';
timelock: Timelock;
}

export interface FireblocksApprovalProcessRequest extends BaseApprovalProcessRequest {
viaType: 'Fireblocks';
fireblocks: FireblocksProposalParams;
}

export interface CreateApprovalProcessResponse {
approvalProcessId: string;
createdAt: string;
name: string;
component?: ComponentType;
network?: Network;
via?: string;
viaType?:
| 'EOA'
| 'Contract'
| 'Multisig'
| 'Gnosis Safe'
| 'Safe'
| 'Gnosis Multisig'
| 'Relayer'
shahnami marked this conversation as resolved.
Show resolved Hide resolved
| 'Relayer Group'
| 'Unknown'
| 'Relayer Group'
| 'Timelock Controller'
| 'ERC20'
| 'Governor'
| 'Fireblocks';
timelock?: Timelock;
multisigSender?: string;
fireblocks?: FireblocksProposalParams;
relayerId?: string;
shahnami marked this conversation as resolved.
Show resolved Hide resolved
relayerGroupId?: string;
stackResourceId?: string;
}
11 changes: 11 additions & 0 deletions packages/approval-process/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "code-style/tsconfig.json",
"compilerOptions": {
"declaration": true,
"outDir": "./lib",
"skipLibCheck": true,
"sourceMap": false
},
"include": ["./src"],
"exclude": ["**/*.test.ts", "**/__mocks__/*"]
}
3 changes: 2 additions & 1 deletion packages/defender-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"@openzeppelin/defender-sdk-network-client": "^1.15.0",
"@openzeppelin/defender-sdk-account-client": "^1.15.0",
"@openzeppelin/defender-sdk-key-value-store-client": "^1.15.0",
"@openzeppelin/defender-sdk-relay-group-client": "^1.15.0"
"@openzeppelin/defender-sdk-relay-group-client": "^1.15.0",
"@openzeppelin/defender-sdk-approval-process-client": "^1.15.0"
},
"publishConfig": {
"access": "public"
Expand Down
6 changes: 5 additions & 1 deletion packages/defender-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { DeployClient } from '@openzeppelin/defender-sdk-deploy-client';
import { NotificationChannelClient } from '@openzeppelin/defender-sdk-notification-channel-client';
import { NetworkClient } from '@openzeppelin/defender-sdk-network-client';
import { AccountClient } from '@openzeppelin/defender-sdk-account-client';
import { ApprovalProcessClient } from '@openzeppelin/defender-sdk-approval-process-client';
import { RelayGroupClient } from '@openzeppelin/defender-sdk-relay-group-client';
import { KeyValueStoreClient, LocalKeyValueStoreCreateParams } from '@openzeppelin/defender-sdk-key-value-store-client';

import { Newable, ClientParams } from './types';
import { ActionRelayerParams, Relayer as RelaySignerClient } from '@openzeppelin/defender-sdk-relay-signer-client';
import { ListNetworkRequestOptions } from '@openzeppelin/defender-sdk-network-client/lib/models/networks';
Expand Down Expand Up @@ -105,6 +105,10 @@ export class Defender {
});
}

get approvalProcess() {
return getClient(ApprovalProcessClient, { apiKey: this.apiKey, apiSecret: this.apiSecret });
}

get monitor() {
return getClient(MonitorClient, {
apiKey: this.apiKey,
Expand Down
1 change: 1 addition & 0 deletions packages/deploy/src/models/approval-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface ApprovalProcessResponse {
| 'Gnosis Multisig'
| 'Relayer'
| 'Unknown'
| 'Relayer Group'
| 'Timelock Controller'
| 'ERC20'
| 'Governor'
Expand Down
28 changes: 26 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.