Skip to content
This repository was archived by the owner on Jul 6, 2022. It is now read-only.

Commit 7377aa9

Browse files
author
Victor Wiebe
committed
feat: 🎸 comments improvements for generalPermissionManager
1 parent e6c8883 commit 7377aa9

File tree

1 file changed

+90
-6
lines changed

1 file changed

+90
-6
lines changed

‎src/contract_wrappers/modules/permission_manager/general_permission_manager_wrapper.ts‎

Lines changed: 90 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,46 +58,84 @@ interface GetGeneralPermissionManagerLogsAsyncParams extends GetLogs {
5858
(params: GetAddDelegateLogsAsyncParams): Promise<LogWithDecodedArgs<GeneralPermissionManagerAddDelegateEventArgs>[]>;
5959
}
6060

61+
/**
62+
* @param delegate Ethereum address of the delegate
63+
* @param module Ethereum contract address of the module
64+
* @param perm Permission flag
65+
*/
6166
interface PermParams {
6267
module: string;
6368
delegate: string;
6469
permission: Perm;
6570
}
6671

72+
/**
73+
* @param delegateIndex Index of the delegate
74+
*/
6775
interface DelegateIndexParams {
6876
delegateIndex: number;
6977
}
7078

79+
/**
80+
* @param delegate the address of potential delegate
81+
*/
7182
interface DelegateParams {
7283
delegate: string;
7384
}
7485

86+
/**
87+
* @param module Ethereum contract address of the module
88+
* @param perm Permission flag
89+
*/
7590
interface GetAllDelegatesWithPermParams {
7691
module: string;
7792
perm: Perm;
7893
}
7994

95+
/**
96+
* @param delegate Ethereum address of the delegate
97+
* @param types Array of types
98+
*/
8099
interface GetAllModulesAndPermsFromTypesParams {
81100
delegate: string;
82101
types: number[];
83102
}
84103

104+
/**
105+
* @param delegate Ethereum address of the delegate
106+
*/
85107
interface DelegateTxParams extends TxParams {
86108
delegate: string;
87109
}
88110

111+
/**
112+
* @param delegate Ethereum address of the delegate
113+
* @param details Details about the delegate i.e `Belongs to financial firm`
114+
*/
89115
interface AddDelegateParams extends TxParams {
90116
delegate: string;
91117
details: string;
92118
}
93119

120+
/**
121+
* @param delegate Ethereum address of the delegate
122+
* @param module Ethereum contract address of the module
123+
* @param perm Permission flag
124+
* @param valid Bool flag use to switch on/off the permission
125+
*/
94126
interface ChangePermissionParams extends TxParams {
95127
delegate: string;
96128
module: string;
97129
perm: Perm;
98130
valid: boolean;
99131
}
100132

133+
/**
134+
* @param delegate Ethereum address of the delegate
135+
* @param modules Multiple module matching the multiple perms, needs to be same length
136+
* @param perms Multiple permission flag needs to be changed
137+
* @param valids Bool array consist the flag to switch on/off the permission
138+
*/
101139
interface ChangePermissionMultiParams extends TxParams {
102140
delegate: string;
103141
modules: string[];
@@ -134,22 +172,35 @@ export default class GeneralPermissionManagerWrapper extends ModuleWrapper {
134172
this.contract = contract;
135173
}
136174

175+
/**
176+
* Mapping used to hold the permissions on the modules provided to delegate
177+
*/
137178
public perms = async (params: PermParams) => {
138179
assert.isETHAddressHex('module', params.module);
139180
assert.isETHAddressHex('delegate', params.delegate);
140181
return (await this.contract).perms.callAsync(params.module, params.delegate, stringToBytes32(params.permission));
141182
};
142183

143-
public allDelegates = async (params: DelegateIndexParams) => {
184+
/**
185+
* Array to track all delegates
186+
*/
187+
public allDelegates = async (params: DelegateIndexParams): Promise<string> => {
144188
return (await this.contract).allDelegates.callAsync(numberToBigNumber(params.delegateIndex));
145189
};
146190

147-
public delegateDetails = async (params: DelegateParams) => {
191+
/**
192+
* Mapping to hold the delegate details
193+
*/
194+
public delegateDetails = async (params: DelegateParams): Promise<string> => {
148195
assert.isETHAddressHex('delegate', params.delegate);
149196
return (await this.contract).delegateDetails.callAsync(params.delegate);
150197
};
151198

152-
public checkPermission = async (params: PermParams) => {
199+
/**
200+
* Used to check the permission on delegate corresponds to module contract address
201+
* @return bool if permission is valid
202+
*/
203+
public checkPermission = async (params: PermParams): Promise<boolean> => {
153204
assert.isETHAddressHex('delegate', params.delegate);
154205
assert.isETHAddressHex('module', params.module);
155206
return (await this.contract).checkPermission.callAsync(
@@ -159,6 +210,11 @@ export default class GeneralPermissionManagerWrapper extends ModuleWrapper {
159210
);
160211
};
161212

213+
/**
214+
* Used to add a delegate
215+
* @param delegate Ethereum address of the delegate
216+
* @param details Details about the delegate i.e `Belongs to financial firm`
217+
*/
162218
public addDelegate = async (params: AddDelegateParams) => {
163219
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
164220
assert.isNonZeroETHAddressHex('delegate', params.delegate);
@@ -172,6 +228,9 @@ export default class GeneralPermissionManagerWrapper extends ModuleWrapper {
172228
);
173229
};
174230

231+
/**
232+
* Used to delete a delegate
233+
*/
175234
public deleteDelegate = async (params: DelegateTxParams) => {
176235
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
177236
assert.isNonZeroETHAddressHex('delegate', params.delegate);
@@ -183,11 +242,18 @@ export default class GeneralPermissionManagerWrapper extends ModuleWrapper {
183242
);
184243
};
185244

186-
public checkDelegate = async (params: DelegateParams) => {
245+
/**
246+
* Used to check if an address is a delegate or not
247+
* @return boolean if address is delegate
248+
*/
249+
public checkDelegate = async (params: DelegateParams): Promise<boolean> => {
187250
assert.isNonZeroETHAddressHex('delegate', params.delegate);
188251
return (await this.contract).checkDelegate.callAsync(params.delegate);
189252
};
190253

254+
/**
255+
* Used to provide/change the permission to the delegate corresponds to the module contract
256+
*/
191257
public changePermission = async (params: ChangePermissionParams) => {
192258
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
193259
assert.isNonZeroETHAddressHex('delegate', params.delegate);
@@ -202,6 +268,9 @@ export default class GeneralPermissionManagerWrapper extends ModuleWrapper {
202268
);
203269
};
204270

271+
/**
272+
* Used to change one or more permissions for a single delegate at once
273+
*/
205274
public changePermissionMulti = async (params: ChangePermissionMultiParams) => {
206275
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
207276
assert.isNonZeroETHAddressHex('delegate', params.delegate);
@@ -219,12 +288,23 @@ export default class GeneralPermissionManagerWrapper extends ModuleWrapper {
219288
);
220289
};
221290

222-
public getAllDelegatesWithPerm = async (params: GetAllDelegatesWithPermParams) => {
291+
/**
292+
* Used to return all delegates with a given permission and module
293+
* @return delegates address array
294+
*/
295+
public getAllDelegatesWithPerm = async (params: GetAllDelegatesWithPermParams): Promise<string[]> => {
223296
assert.isETHAddressHex('module', params.module);
224297
return (await this.contract).getAllDelegatesWithPerm.callAsync(params.module, stringToBytes32(params.perm));
225298
};
226299

227-
public getAllModulesAndPermsFromTypes = async (params: GetAllModulesAndPermsFromTypesParams) => {
300+
/**
301+
* Used to return all permission of a single or multiple module
302+
* @return address[] the address array of Modules this delegate has permission
303+
* @return bytes32[] the permission array of the corresponding Modules
304+
*/
305+
public getAllModulesAndPermsFromTypes = async (
306+
params: GetAllModulesAndPermsFromTypesParams,
307+
): Promise<PermissionsPerModule[]> => {
228308
assert.isETHAddressHex('delegate', params.delegate);
229309
const result = await (await this.contract).getAllModulesAndPermsFromTypes.callAsync(params.delegate, params.types);
230310
// [module1, module1, module2, module3, module3], [perm1, perm2, perm1, perm2, perm3]
@@ -243,6 +323,10 @@ export default class GeneralPermissionManagerWrapper extends ModuleWrapper {
243323
return typedResult;
244324
};
245325

326+
/**
327+
* Used to get all delegates
328+
* @return delegate addresses array
329+
*/
246330
public getAllDelegates = async () => {
247331
return (await this.contract).getAllDelegates.callAsync();
248332
};

0 commit comments

Comments
 (0)