Skip to content

Commit

Permalink
Merge branch 'beta' into test/modify-dividends-default-exclusion-list
Browse files Browse the repository at this point in the history
  • Loading branch information
monitz87 committed Jan 6, 2020
2 parents f1eefe1 + 21cd2e4 commit d4faf6b
Show file tree
Hide file tree
Showing 84 changed files with 1,042 additions and 444 deletions.
4 changes: 2 additions & 2 deletions .eslintrc
Expand Up @@ -64,8 +64,8 @@
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true,
"ArrowFunctionExpression": false,
"FunctionExpression": false
"ArrowFunctionExpression": true,
"FunctionExpression": true
}
}
],
Expand Down
4 changes: 1 addition & 3 deletions commitlint.config.js
@@ -1,5 +1,3 @@
module.exports = {
extends: [
'@commitlint/config-conventional'
],
extends: ['@commitlint/config-conventional'],
};
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@polymathnetwork/sdk",
"version": "2.0.1-beta.84",
"version": "2.0.1-beta.86",
"description": "A Javascript SDK for interacting with the Polymath network for the browser and Node.js",
"bugs": {
"url": "https://github.com/PolymathNetwork/polymath-sdk/issues"
Expand Down
2 changes: 1 addition & 1 deletion release.config.js
Expand Up @@ -9,7 +9,7 @@ module.exports = {
prerelease: true,
},
],
/**
/*
* In this order the **prepare** step of @semantic-release/npm will run first
* followed by @semantic-release/git:
* - Update the package.json version and create the npm package tarball
Expand Down
81 changes: 45 additions & 36 deletions src/Polymath.ts
Expand Up @@ -11,7 +11,7 @@ import { union, compact } from 'lodash';
import { Context } from './Context';
import { getInjectedProvider } from './browserUtils';
import { ErrorCode, TransactionSpeed } from './types';
import { Erc20TokenBalance, SecurityToken, Wallet } from './entities';
import { SecurityToken, Wallet } from './entities';
import { ReserveSecurityToken } from './procedures';
import { PolymathError } from './PolymathError';
import { PolymathBase } from './PolymathBase';
Expand Down Expand Up @@ -56,6 +56,35 @@ interface GetSecurityToken {
(params: string): Promise<SecurityToken>;
}

const calculateGasPrice = (speed: TransactionSpeed, basePrice: BigNumber) => {
let result = basePrice;
switch (speed) {
case TransactionSpeed.Slow: {
break;
}
case TransactionSpeed.Medium: {
result = basePrice.multipliedBy(2);
break;
}
case TransactionSpeed.Fast: {
result = basePrice.multipliedBy(3);
break;
}
case TransactionSpeed.Fastest: {
result = basePrice.multipliedBy(5);
break;
}
default: {
throw new PolymathError({
code: ErrorCode.FatalError,
message: 'Invalid transaction speed parameter',
});
}
}

return result;
};

export class Polymath {
public isUnsupported: boolean = false;

Expand Down Expand Up @@ -228,15 +257,20 @@ export class Polymath {
return typeof a.address === 'string';
};

const {
context: {
contractWrappers: { tokenFactory },
factories,
},
} = this;

// fetch by UUID
if (typeof args === 'string') {
uid = args;
} else if (isAddressArgs(args)) {
const { address } = args;
try {
const securityToken = await this.context.contractWrappers.tokenFactory.getSecurityTokenInstanceFromAddress(
address
);
const securityToken = await tokenFactory.getSecurityTokenInstanceFromAddress(address);

const symbol = await securityToken.symbol();
uid = SecurityToken.generateId({ symbol });
Expand All @@ -250,7 +284,7 @@ export class Polymath {
uid = SecurityToken.generateId(args);
}

return this.context.factories.securityTokenFactory.fetch(uid);
return factories.securityTokenFactory.fetch(uid);
};

/**
Expand All @@ -271,7 +305,8 @@ export class Polymath {
*/
public isValidErc20 = async (args: { address: string }) => {
const { address } = args;
const erc20Token = await this.context.contractWrappers.tokenFactory.getERC20TokenInstanceFromAddress(
const { context } = this;
const erc20Token = await context.contractWrappers.tokenFactory.getERC20TokenInstanceFromAddress(
address
);
await erc20Token.isValidContract();
Expand All @@ -294,7 +329,10 @@ export class Polymath {
* @returns version string (i.e. 3.0.0)
*/
public getLatestProtocolVersion = async () => {
const version = await this.context.contractWrappers.securityTokenRegistry.getLatestProtocolVersion();
const {
context: { contractWrappers },
} = this;
const version = await contractWrappers.securityTokenRegistry.getLatestProtocolVersion();

return version.map(vNum => vNum.toNumber()).join('.');
};
Expand Down Expand Up @@ -415,32 +453,3 @@ export class Polymath {
return calculateGasPrice(speed, networkGasPrice);
};
}

const calculateGasPrice = (speed: TransactionSpeed, basePrice: BigNumber) => {
let result = basePrice;
switch (speed) {
case TransactionSpeed.Slow: {
break;
}
case TransactionSpeed.Medium: {
result = basePrice.multipliedBy(2);
break;
}
case TransactionSpeed.Fast: {
result = basePrice.multipliedBy(3);
break;
}
case TransactionSpeed.Fastest: {
result = basePrice.multipliedBy(5);
break;
}
default: {
throw new PolymathError({
code: ErrorCode.FatalError,
message: 'Invalid transaction speed parameter',
});
}
}

return result;
};
29 changes: 22 additions & 7 deletions src/PolymathBase.ts
Expand Up @@ -31,12 +31,13 @@ import {
isPercentageTransferManager,
isVolumeRestrictionTransferManager,
isRestrictedPartialSaleTransferManager,
EtherDividendCheckpoint,
} from '@polymathnetwork/contract-wrappers';
import { range, flatten } from 'lodash';
import P from 'bluebird';
import semver from 'semver';
import { PolymathError } from './PolymathError';
import { ErrorCode, Module, SecurityTokenRole } from './types';
import { ErrorCode, SecurityTokenRole } from './types';
import { ZERO_ADDRESS } from './utils/constants';

interface GetModuleAddressesByNameParams {
Expand Down Expand Up @@ -197,6 +198,22 @@ export interface BaseDividend {
shareholders: DividendShareholderStatus[];
}

export type Module =
| GeneralPermissionManager
| GeneralTransferManager
| BlacklistTransferManager
| LockUpTransferManager
| CountTransferManager
| ManualApprovalTransferManager
| PercentageTransferManager
| VolumeRestrictionTransferManager
| RestrictedPartialSaleTransferManager
| CappedSTO
| USDTieredSTO
| ERC20DividendCheckpoint
| EtherDividendCheckpoint
| VestingEscrowWallet;

export class PolymathBase extends PolymathAPI {
public getModuleFactoryAddress = async ({
moduleName,
Expand Down Expand Up @@ -229,7 +246,7 @@ export class PolymathBase extends PolymathAPI {
let latestVersion = '0.0.0';

// Get latest version of the module factory
for (const moduleAddress of availableModules) {
await P.each(availableModules, async moduleAddress => {
const moduleFactory = await this.moduleFactory.getModuleFactory(moduleAddress);
const name = await moduleFactory.name();

Expand All @@ -240,10 +257,10 @@ export class PolymathBase extends PolymathAPI {
address = moduleAddress;
}
}
}
});

if (address !== null) {
return address;
return address as string;
}

throw new PolymathError({
Expand Down Expand Up @@ -568,13 +585,11 @@ export class PolymathBase extends PolymathAPI {
dividendIndex: number;
dividendsModule: ERC20DividendCheckpoint;
}): Promise<BaseDividend> => {
let symbol: string;

const tokenAddress = await dividendsModule.dividendTokens({ dividendIndex });

const token = await this.tokenFactory.getERC20TokenInstanceFromAddress(tokenAddress);

symbol = await token.symbol();
const symbol = await token.symbol();

const dividend = await dividendsModule.dividends({ dividendIndex });

Expand Down
9 changes: 3 additions & 6 deletions src/entities/PolyTransaction.ts
@@ -1,10 +1,7 @@
import { mapValues, isPlainObject, pickBy } from 'lodash';
import { EventEmitter } from 'events';
import v4 from 'uuid/v4';
import {
TransactionReceiptWithDecodedLogs,
PolyResponse,
} from '@polymathnetwork/contract-wrappers';
import { TransactionReceiptWithDecodedLogs } from '@polymathnetwork/contract-wrappers';
import { PostTransactionResolver, isPostTransactionResolver } from '../PostTransactionResolver';
import {
TransactionSpec,
Expand Down Expand Up @@ -109,7 +106,7 @@ export class PolyTransaction<Args = any, Values extends any[] = any[]> extends E
txHash,
receipt,
error,
/**
/*
* NOTE @monitz87: we intentionally expose the args as any for the end user
* until we figure out how to type this properly
*/
Expand Down Expand Up @@ -251,5 +248,5 @@ export class PolyTransaction<Args = any, Values extends any[] = any[]> extends E
}) as T;
}

public _refresh(_params: Partial<void>) {}
public _refresh() {}
}
19 changes: 17 additions & 2 deletions src/entities/SecurityToken/Controller.ts
Expand Up @@ -5,6 +5,7 @@ import {
SetController,
ControllerRedeem,
DisableController,
SignDisableControllerAck,
} from '../../procedures';

export class Controller extends SubModule {
Expand All @@ -21,9 +22,10 @@ export class Controller extends SubModule {

/**
* Permanently disable controller functionality
* @param signature optional signed data. If not passed, signing will be requested on the spot
*
* @param signature optional signed data. If not passed, signing will be requested when the transaction queue is run. The data can be generated beforehand by the token owner calling `signDisableAck`
*/
public disableController = async (args?: { signature?: string }) => {
public disable = async (args?: { signature?: string }) => {
const { symbol } = this.securityToken;
const procedure = new DisableController({ ...args, symbol }, this.context);
return procedure.prepare();
Expand Down Expand Up @@ -79,4 +81,17 @@ export class Controller extends SubModule {

return procedure.prepare();
};

/**
* Generate a signature string that can be used to permanently disable the Security Token's controller functionality
*
* Note that only the owner's signature is valid for this operation
*/
public signDisableAck = async () => {
const { symbol } = this.securityToken;

const procedure = new SignDisableControllerAck({ symbol }, this.context);

return procedure.prepare();
};
}
16 changes: 10 additions & 6 deletions src/entities/SecurityToken/Documents.ts
Expand Up @@ -52,9 +52,11 @@ export class Documents extends SubModule {
let securityTokenInstance;

try {
securityTokenInstance = await contractWrappers.tokenFactory.getSecurityTokenInstanceFromTicker(
symbol
);
// prettier-ignore
securityTokenInstance =
await contractWrappers.tokenFactory.getSecurityTokenInstanceFromTicker(
symbol
);
} catch (err) {
throw new PolymathError({
code: ErrorCode.FetcherValidationError,
Expand All @@ -79,9 +81,11 @@ export class Documents extends SubModule {
let securityTokenInstance;

try {
securityTokenInstance = await contractWrappers.tokenFactory.getSecurityTokenInstanceFromTicker(
symbol
);
// prettier-ignore
securityTokenInstance =
await contractWrappers.tokenFactory.getSecurityTokenInstanceFromTicker(
symbol
);
} catch (err) {
throw new PolymathError({
code: ErrorCode.FetcherValidationError,
Expand Down

0 comments on commit d4faf6b

Please sign in to comment.