Skip to content

Commit

Permalink
Merge pull request #103 from PolymathNetwork/fix/permission-bugs
Browse files Browse the repository at this point in the history
Fix/permission bugs
  • Loading branch information
monitz87 committed Oct 28, 2019
2 parents 2d72f1e + e94a1c9 commit fbf508e
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 158 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@0x/subproviders": "^3.0.2",
"@babel/polyfill": "^7.0.0",
"@babel/runtime": "^7.2.0",
"@polymathnetwork/contract-wrappers": "3.0.0-beta.47",
"@polymathnetwork/contract-wrappers": "3.0.0-beta.52",
"@types/sinon": "^7.5.0",
"bluebird": "^3.5.5",
"ethereum-address": "^0.0.4",
Expand Down
7 changes: 4 additions & 3 deletions src/entities/SecurityToken/Permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ export class Permissions extends SubModule {
*
* @param delegateAddress wallet address of the delegate
* @param role role to assign
* @param description description of the delegate (defaults to empty string, is ignored if the delegate already exists)
* @param description description of the delegate (is ignored if the delegate already exists)
*/
public assignRole = async (args: {
delegateAddress: string;
role: SecurityTokenRole;
description?: string;
description: string;
}) => {
const { symbol } = this.securityToken;

Expand Down Expand Up @@ -126,6 +126,7 @@ export class Permissions extends SubModule {
{
symbol,
assign: false,
description: '', // this is not used when revoking
...args,
},
this.context
Expand Down Expand Up @@ -256,7 +257,7 @@ export class Permissions extends SubModule {
});
};

private rolesPerFeature = {
public rolesPerFeature = {
[Feature.Permissions]: [SecurityTokenRole.PermissionsAdministrator],
[Feature.Shareholders]: [SecurityTokenRole.ShareholdersAdministrator],
[Feature.Erc20Dividends]: [
Expand Down
4 changes: 2 additions & 2 deletions src/entities/factories/CappedStoFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
BlockParamLiteral,
conversionUtils,
FULL_DECIMALS,
CappedSTOEvents_3_0_0,
CappedSTOEvents,
} from '@polymathnetwork/contract-wrappers';
import { Factory } from './Factory';
import { Context } from '../../Context';
Expand All @@ -26,7 +26,7 @@ export class CappedStoFactory extends Factory<CappedSto, Params, UniqueIdentifie
});

const tokenPurchases = await module.getLogsAsync({
eventName: CappedSTOEvents_3_0_0.TokenPurchase,
eventName: CappedSTOEvents.TokenPurchase,
blockRange: {
fromBlock: BlockParamLiteral.Earliest,
toBlock: BlockParamLiteral.Latest,
Expand Down
8 changes: 4 additions & 4 deletions src/entities/factories/InvestmentFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
BlockParamLiteral,
conversionUtils,
FULL_DECIMALS,
CappedSTOEvents_3_0_0,
USDTieredSTOEvents_3_0_0,
CappedSTOEvents,
USDTieredSTOEvents,
} from '@polymathnetwork/contract-wrappers';
import { Factory } from './Factory';
import { Context } from '../../Context';
Expand All @@ -30,7 +30,7 @@ export class InvestmentFactory extends Factory<Investment, Params, UniqueIdentif
});

const tokenPurchases = await module.getLogsAsync({
eventName: CappedSTOEvents_3_0_0.TokenPurchase,
eventName: CappedSTOEvents.TokenPurchase,
blockRange: {
fromBlock: BlockParamLiteral.Earliest,
toBlock: BlockParamLiteral.Latest,
Expand Down Expand Up @@ -64,7 +64,7 @@ export class InvestmentFactory extends Factory<Investment, Params, UniqueIdentif
});

const tokenPurchases = await module.getLogsAsync({
eventName: USDTieredSTOEvents_3_0_0.TokenPurchase,
eventName: USDTieredSTOEvents.TokenPurchase,
blockRange: {
fromBlock: BlockParamLiteral.Earliest,
toBlock: BlockParamLiteral.Latest,
Expand Down
4 changes: 2 additions & 2 deletions src/entities/factories/UsdTieredStoFactory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
ModuleName,
USDTieredSTOEvents_3_0_0,
USDTieredSTOEvents,
BlockParamLiteral,
conversionUtils,
FULL_DECIMALS,
Expand All @@ -27,7 +27,7 @@ export class UsdTieredStoFactory extends Factory<UsdTieredSto, Params, UniqueIde
});

const tokenPurchases = await module.getLogsAsync({
eventName: USDTieredSTOEvents_3_0_0.TokenPurchase,
eventName: USDTieredSTOEvents.TokenPurchase,
blockRange: {
fromBlock: BlockParamLiteral.Earliest,
toBlock: BlockParamLiteral.Latest,
Expand Down
11 changes: 7 additions & 4 deletions src/procedures/AssignSecurityTokenRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class AssignSecurityTokenRole extends Procedure<AssignSecurityTokenRolePr
public type = ProcedureType.AssignSecurityTokenRole;

public async prepareTransactions() {
const { symbol, role, assign, description = '', delegateAddress } = this.args;
const { symbol, role, assign, description, delegateAddress } = this.args;
const { contractWrappers } = this.context;
const delegate = conversionUtils.checksumAddress(delegateAddress);

Expand Down Expand Up @@ -63,7 +63,8 @@ export class AssignSecurityTokenRole extends Procedure<AssignSecurityTokenRolePr
))[0];

const delegates = await permissionModule.getAllDelegates();
const exists = delegates.filter(element => element === delegate).length > 0;
const exists =
delegates.filter(element => element.toUpperCase() === delegate.toUpperCase()).length > 0;

/**
* In the following block we attempt to:
Expand All @@ -76,7 +77,9 @@ export class AssignSecurityTokenRole extends Procedure<AssignSecurityTokenRolePr
perm,
});

const permitted = !!permittedDelegates.find(element => element === delegate);
const permitted = !!permittedDelegates.find(
element => element.toUpperCase() === delegate.toUpperCase()
);

// Upcoming permission equals existing one
if (permitted === assign) {
Expand All @@ -90,7 +93,7 @@ export class AssignSecurityTokenRole extends Procedure<AssignSecurityTokenRolePr
} else {
// Delegate not found. Add them here
await this.addTransaction(permissionModule.addDelegate, {
tag: PolyTransactionTag.ChangePermission,
tag: PolyTransactionTag.AddDelegate,
})({ delegate, details: description });
}

Expand Down
4 changes: 2 additions & 2 deletions src/procedures/CreateCheckpoint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SecurityTokenEvents_3_0_0 } from '@polymathnetwork/contract-wrappers';
import { SecurityTokenEvents } from '@polymathnetwork/contract-wrappers';
import { Procedure } from './Procedure';
import {
CreateCheckpointProcedureArgs,
Expand Down Expand Up @@ -38,7 +38,7 @@ export class CreateCheckpoint extends Procedure<CreateCheckpointProcedureArgs, C

const [event] = findEvents({
logs,
eventName: SecurityTokenEvents_3_0_0.CheckpointCreated,
eventName: SecurityTokenEvents.CheckpointCreated,
});
if (event) {
const { args: eventArgs } = event;
Expand Down
4 changes: 2 additions & 2 deletions src/procedures/CreateErc20DividendDistribution.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
ModuleName,
ERC20DividendCheckpointEvents_3_0_0,
ERC20DividendCheckpointEvents,
BigNumber,
} from '@polymathnetwork/contract-wrappers';
import { Procedure } from './Procedure';
Expand Down Expand Up @@ -75,7 +75,7 @@ export class CreateErc20DividendDistribution extends Procedure<
const { logs } = receipt;

const [event] = findEvents({
eventName: ERC20DividendCheckpointEvents_3_0_0.ERC20DividendDeposited,
eventName: ERC20DividendCheckpointEvents.ERC20DividendDeposited,
logs,
});

Expand Down
4 changes: 2 additions & 2 deletions src/procedures/CreateEtherDividendDistribution.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
ModuleName,
EtherDividendCheckpointEvents_3_0_0,
EtherDividendCheckpointEvents,
BigNumber,
} from '@polymathnetwork/contract-wrappers';
import { Procedure } from './Procedure';
Expand Down Expand Up @@ -67,7 +67,7 @@ export class CreateEtherDividendDistribution extends Procedure<
const { logs } = receipt;

const [event] = findEvents({
eventName: EtherDividendCheckpointEvents_3_0_0.EtherDividendDeposited,
eventName: EtherDividendCheckpointEvents.EtherDividendDeposited,
logs,
});

Expand Down
4 changes: 2 additions & 2 deletions src/procedures/LaunchCappedSto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
ModuleName,
BigNumber,
CappedSTOFundRaiseType,
SecurityTokenEvents_3_0_0,
SecurityTokenEvents,
} from '@polymathnetwork/contract-wrappers';
import { Procedure } from './Procedure';
import {
Expand Down Expand Up @@ -103,7 +103,7 @@ export class LaunchCappedSto extends Procedure<LaunchCappedStoProcedureArgs, Cap
const { logs } = receipt;

const [event] = findEvents({
eventName: SecurityTokenEvents_3_0_0.ModuleAdded,
eventName: SecurityTokenEvents.ModuleAdded,
logs,
});

Expand Down
4 changes: 2 additions & 2 deletions src/procedures/LaunchUsdTieredSto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
ModuleName,
BigNumber,
FundRaiseType,
SecurityTokenEvents_3_0_0,
SecurityTokenEvents,
} from '@polymathnetwork/contract-wrappers';
import { Procedure } from './Procedure';
import {
Expand Down Expand Up @@ -129,7 +129,7 @@ export class LaunchUsdTieredSto extends Procedure<LaunchUsdTieredStoProcedureArg
const { logs } = receipt;

const [event] = findEvents({
eventName: SecurityTokenEvents_3_0_0.ModuleAdded,
eventName: SecurityTokenEvents.ModuleAdded,
logs,
});

Expand Down
3 changes: 2 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export enum PolyTransactionTag {
WithdrawTaxWithholdings = 'WithdrawTaxWithholdings',
PushDividendPayment = 'PushDividendPayment',
SetDividendsWallet = 'SetDividendsWallet',
AddDelegate = 'AddDelegate',
ChangePermission = 'ChangePermission',
ControllerTransfer = 'ControllerTransfer',
PauseSto = 'PauseSto',
Expand Down Expand Up @@ -325,7 +326,7 @@ export interface AssignSecurityTokenRoleProcedureArgs {
delegateAddress: string;
role: SecurityTokenRole;
assign: boolean;
description?: string;
description: string;
}

export interface AssignStoRoleProcedureArgs {
Expand Down

0 comments on commit fbf508e

Please sign in to comment.