Skip to content

Commit 15c2d35

Browse files
committed
feat: add whitelist specific code
1 parent ea78cca commit 15c2d35

File tree

8 files changed

+1042
-14
lines changed

8 files changed

+1042
-14
lines changed

src/LowLevel/GeneralPermissionManager.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ import { Contract } from './Contract';
44
import { Context } from './LowLevel';
55
import { isAddress, getOptions } from './utils';
66

7-
import { GenericContract } from './types';
8-
import { PolymathError } from '~/PolymathError';
9-
import { ErrorCodes } from '~/types';
7+
import {
8+
GenericContract,
9+
AddDelegateArgs,
10+
ChangePermissionArgs,
11+
GetAllDelegatesWithPermArgs,
12+
} from './types';
13+
import { PolymathError } from '../PolymathError';
14+
import { ErrorCodes } from '../types';
1015

1116
interface GeneralPermissionManagerContract extends GenericContract {
1217
methods: {
@@ -17,6 +22,8 @@ interface GeneralPermissionManagerContract extends GenericContract {
1722
perm: string,
1823
valid: boolean
1924
) => TransactionObject<void>;
25+
getAllDelegates: () => TransactionObject<string[]>;
26+
getAllDelegatesWithPerm: (module: string, perm: string) => TransactionObject<string[]>;
2027
};
2128
}
2229

@@ -29,7 +36,15 @@ export class GeneralPermissionManager extends Contract<GeneralPermissionManagerC
2936
});
3037
}
3138

32-
public addDelegate = async (delegate: string, details: string) => {
39+
public getAllDelegates = async () => {
40+
return await this.contract.methods.getAllDelegates().call();
41+
};
42+
43+
public getAllDelegatesWithPerm = async ({ module, perm }: GetAllDelegatesWithPermArgs) => {
44+
return await this.contract.methods.getAllDelegatesWithPerm(module, perm).call();
45+
};
46+
47+
public addDelegate = async ({ delegate, details }: AddDelegateArgs) => {
3348
if (!isAddress(delegate))
3449
throw new PolymathError({
3550
code: ErrorCodes.InvalidAddress,
@@ -41,19 +56,14 @@ export class GeneralPermissionManager extends Contract<GeneralPermissionManagerC
4156
return () => method.send(options);
4257
};
4358

44-
public changePermission = async (
45-
delegate: string,
46-
module: string,
47-
perm: string,
48-
valid: boolean
49-
) => {
59+
public changePermission = async ({ delegate, module, perm, enabled }: ChangePermissionArgs) => {
5060
if (!isAddress(delegate))
5161
throw new PolymathError({
5262
code: ErrorCodes.InvalidAddress,
5363
message: `Delegate address is invalid: $delegate = ${delegate}`,
5464
});
5565

56-
const method = this.contract.methods.changePermission(delegate, module, perm, valid);
66+
const method = this.contract.methods.changePermission(delegate, module, perm, enabled);
5767
const options = await getOptions(method, { from: this.context.account });
5868
return () => method.send(options);
5969
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { GeneralTransferManagerAbi } from './abis/GeneralTransferManagerAbi';
2+
import { Contract } from './Contract';
3+
import { Context } from './LowLevel';
4+
5+
import { GenericContract } from './types';
6+
7+
interface GeneralTransferManagerContract extends GenericContract {
8+
methods: {};
9+
}
10+
11+
export class GeneralTransferManager extends Contract<GeneralTransferManagerContract> {
12+
constructor({ address, context }: { address: string; context: Context }) {
13+
super({
14+
address,
15+
abi: GeneralTransferManagerAbi.abi,
16+
context,
17+
});
18+
}
19+
}

src/LowLevel/SecurityToken.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import { DividendCheckpointAbi } from './abis/DividendCheckpointAbi';
2222
import { Contract } from './Contract';
2323
import { CappedSto } from './CappedSto';
2424
import { UsdTieredSto } from './UsdTieredSto';
25+
import { GeneralPermissionManager } from './GeneralPermissionManager';
26+
import { GeneralTransferManager } from './GeneralTransferManager';
2527

2628
interface ModuleData {
2729
/**
@@ -133,6 +135,8 @@ export class SecurityToken extends Contract<SecurityTokenContract> {
133135
return () => method.send(options);
134136
};
135137

138+
// @TODO remon-nashid: add a generic getAttachedModule(moduleName) method. It should still return properly typed module objects.
139+
136140
public getErc20DividendModule = async () => {
137141
const address = await this.getFirstUnarchivedModuleAddress({
138142
name: 'ERC20DividendCheckpoint',
@@ -157,6 +161,30 @@ export class SecurityToken extends Contract<SecurityTokenContract> {
157161
return new EtherDividendCheckpoint({ address, context: this.context });
158162
}
159163

164+
public getGeneralPermissionManagerModule = async () => {
165+
const address = await this.getFirstUnarchivedModuleAddress({
166+
name: 'GeneralPermissionManager',
167+
});
168+
169+
if (!address) {
170+
return null;
171+
}
172+
173+
return new GeneralPermissionManager({ address, context: this.context });
174+
};
175+
176+
public getGeneralTransferManagerModule = async () => {
177+
const address = await this.getFirstUnarchivedModuleAddress({
178+
name: 'GeneralTransferManager',
179+
});
180+
181+
if (!address) {
182+
return null;
183+
}
184+
185+
return new GeneralTransferManager({ address, context: this.context });
186+
};
187+
160188
public async getCappedStoModules() {
161189
const addresses = await this.getUnarchivedModuleAddresses({
162190
name: 'CappedSTO',

0 commit comments

Comments
 (0)