Skip to content

Commit 2adfa13

Browse files
committed
fix: convert transaction parameters properly
1 parent 2c49af1 commit 2adfa13

9 files changed

Lines changed: 79 additions & 15 deletions

File tree

src/LowLevel/GeneralPermissionManager.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { TransactionObject } from 'web3/eth/types';
22
import { GeneralPermissionManagerAbi } from './abis/GeneralPermissionManagerAbi';
33
import { Contract } from './Contract';
44
import { Context } from './LowLevel';
5-
import { isAddress, getOptions } from './utils';
5+
import { isAddress, getOptions, fromAscii } from './utils';
66

77
import {
88
GenericContract,
@@ -51,7 +51,7 @@ export class GeneralPermissionManager extends Contract<GeneralPermissionManagerC
5151
message: `Delegate address is invalid: $delegate = ${delegate}`,
5252
});
5353

54-
const method = this.contract.methods.addDelegate(delegate, details);
54+
const method = this.contract.methods.addDelegate(delegate, fromAscii(details));
5555
const options = await getOptions(method, { from: this.context.account });
5656
return () => method.send(options);
5757
};
@@ -63,7 +63,12 @@ export class GeneralPermissionManager extends Contract<GeneralPermissionManagerC
6363
message: `Delegate address is invalid: $delegate = ${delegate}`,
6464
});
6565

66-
const method = this.contract.methods.changePermission(delegate, module, perm, isGranted);
66+
const method = this.contract.methods.changePermission(
67+
delegate,
68+
module,
69+
fromAscii(perm),
70+
isGranted
71+
);
6772
const options = await getOptions(method, { from: this.context.account });
6873
return () => method.send(options);
6974
};

src/LowLevel/SecurityToken.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class SecurityToken extends Contract<SecurityTokenContract> {
117117
return () => method.send(options);
118118
};
119119

120-
public addPermissionModule = async () => {
120+
public addGeneralPermissionManager = async () => {
121121
const factoryAddress = await this.context.moduleRegistry.getModuleFactoryAddress({
122122
moduleName: 'GeneralPermissionManager',
123123
moduleType: ModuleTypes.Permission,

src/LowLevel/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ export function toAscii(value: string) {
6262
return utils.toAscii(value).replace(/\u0000/g, '');
6363
}
6464

65+
export function fromAscii(value: string) {
66+
return utils.fromAscii(value);
67+
}
68+
69+
export function toChecksumAddress(value: string) {
70+
return utils.toChecksumAddress(value);
71+
}
72+
6573
export function isAddress(value: string) {
6674
return utils.isAddress(value);
6775
}

src/Polymath.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { DividendsModule } from './entities/DividendsModule';
4747
import { StoModule } from './entities/StoModule';
4848
import { PolymathError } from './PolymathError';
4949
import { ChangeDelegatePermission } from './procedures/ChangeDelegatePermission';
50+
import { EnableGeneralPermissionManager } from './procedures/EnablePermissionModule';
5051

5152
// TODO @RafaelVidaurre: Type this correctly. It should return a contextualized
5253
// version of T
@@ -211,6 +212,22 @@ export class Polymath {
211212
return await procedure.prepare();
212213
};
213214

215+
/**
216+
* Enable General Permission Manager module
217+
*
218+
* @param securityTokenId token uuid
219+
*/
220+
public enablePermissionsModule = async (args: { securityTokenId: string }) => {
221+
const { symbol } = this.SecurityToken.unserialize(args.securityTokenId);
222+
const procedure = new EnableGeneralPermissionManager(
223+
{
224+
symbol,
225+
},
226+
this.context
227+
);
228+
return await procedure.prepare();
229+
};
230+
214231
/**
215232
* Create investor supply checkpoint at the current date
216233
*/

src/procedures/ChangeDelegatePermission.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import {
88
ModulePermissions,
99
} from '../types';
1010
import { PolymathError } from '../PolymathError';
11+
import { toChecksumAddress } from '../LowLevel/utils';
1112

1213
export class ChangeDelegatePermission extends Procedure<ChangeDelegatePermissionArgs> {
1314
public type = ProcedureTypes.ChangeDelegatePermission;
1415

1516
public async prepareTransactions() {
16-
const { symbol, delegate, op, isGranted, details } = this.args;
17+
const { symbol, op, isGranted, details } = this.args;
18+
const delegate = toChecksumAddress(this.args.delegate);
1719
const { securityTokenRegistry } = this.context;
1820
let module: string;
1921
let perm: string;
@@ -53,6 +55,7 @@ export class ChangeDelegatePermission extends Procedure<ChangeDelegatePermission
5355
});
5456

5557
const delegates = await permissionModule.getAllDelegates();
58+
console.log(delegates);
5659
const exists = delegates.filter(element => element === delegate).length > 0;
5760

5861
// In the following block we attempt to:
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Procedure } from './Procedure';
2+
import {
3+
ProcedureTypes,
4+
PolyTransactionTags,
5+
EnableGeneralPermissionManagerProcedureArgs,
6+
} from '../types';
7+
8+
export class EnableGeneralPermissionManager extends Procedure<
9+
EnableGeneralPermissionManagerProcedureArgs
10+
> {
11+
public type = ProcedureTypes.EnableGeneralPermissionManager;
12+
13+
public async prepareTransactions() {
14+
const { symbol } = this.args;
15+
const { securityTokenRegistry } = this.context;
16+
17+
const securityToken = await securityTokenRegistry.getSecurityToken({
18+
ticker: symbol,
19+
});
20+
21+
await this.addTransaction(securityToken.addGeneralPermissionManager, {
22+
tag: PolyTransactionTags.EnableGeneralPermissionManager,
23+
})();
24+
}
25+
}
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import { Procedure } from './Procedure';
2-
import { ProcedureTypes, PolyTransactionTags, EnablePermissionModuleProcedureArgs } from '../types';
2+
import {
3+
ProcedureTypes,
4+
PolyTransactionTags,
5+
EnableGeneralPermissionManagerProcedureArgs,
6+
} from '../types';
37

4-
export class EnablePermissionModule extends Procedure<EnablePermissionModuleProcedureArgs> {
5-
public type = ProcedureTypes.EnablePermissionModule;
8+
export class EnableGeneralPermissionManager extends Procedure<
9+
EnableGeneralPermissionManagerProcedureArgs
10+
> {
11+
public type = ProcedureTypes.EnableGeneralPermissionManager;
612

713
public async prepareTransactions() {
814
const { symbol } = this.args;
@@ -12,8 +18,8 @@ export class EnablePermissionModule extends Procedure<EnablePermissionModuleProc
1218
ticker: symbol,
1319
});
1420

15-
await this.addTransaction(securityToken.addPermissionModule, {
16-
tag: PolyTransactionTags.EnablePermissionModule,
21+
await this.addTransaction(securityToken.addGeneralPermissionManager, {
22+
tag: PolyTransactionTags.EnableGeneralPermissionManager,
1723
})();
1824
}
1925
}

src/types/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export enum ProcedureTypes {
104104
Approve = 'Approve',
105105
CreateCheckpoint = 'CreateCheckpoint',
106106
EnableDividendModules = 'EnableDividendModules',
107-
EnablePermissionModule = 'EnablePermissionModule',
107+
EnableGeneralPermissionManager = 'EnableGeneralPermissionManager',
108108
CreateErc20DividendDistribution = 'CreateErc20DividendDistribution',
109109
CreateEtherDividendDistribution = 'CreateEtherDividendDistribution',
110110
CreateSecurityToken = 'CreateSecurityToken',
@@ -129,7 +129,7 @@ export enum PolyTransactionTags {
129129
SetErc20TaxWithholding = 'SetErc20TaxWithholding',
130130
SetEtherTaxWithholding = 'SetEtherTaxWithholding',
131131
EnableDividends = 'EnableDividends',
132-
EnablePermissionModule = 'EnablePermissionModule',
132+
EnableGeneralPermissionManager = 'EnableGeneralPermissionManager',
133133
ReclaimDividendFunds = 'ReclaimDividendFunds',
134134
WithdrawTaxWithholdings = 'WithdrawTaxWithholdings',
135135
PushDividendPayment = 'PushDividendPayment',
@@ -215,7 +215,7 @@ export interface EnableDividendModulesProcedureArgs {
215215
types?: DividendModuleTypes[];
216216
}
217217

218-
export interface EnablePermissionModuleProcedureArgs {
218+
export interface EnableGeneralPermissionManagerProcedureArgs {
219219
symbol: string;
220220
}
221221

@@ -253,7 +253,7 @@ export interface SetDividendsWalletProcedureArgs {
253253
export interface ChangeDelegatePermissionArgs {
254254
symbol: string;
255255
delegate: string;
256-
op: string;
256+
op: ModuleOperations;
257257
isGranted: boolean;
258258
details?: string;
259259
}

src/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import stringify from 'json-stable-stringify';
12
import { isAddress } from '../LowLevel/utils';
23
import { Pojo } from '../types';
3-
import stringify from 'json-stable-stringify';
44

55
export const delay = async (amount: number) => {
66
return new Promise(resolve => {

0 commit comments

Comments
 (0)