Skip to content

Commit

Permalink
Merge branch 'beta' into feat/dividends-support
Browse files Browse the repository at this point in the history
  • Loading branch information
monitz87 committed Dec 5, 2019
2 parents c0329fe + 269901b commit 3d279d7
Show file tree
Hide file tree
Showing 75 changed files with 3,258 additions and 1,223 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@polymathnetwork/sdk",
"version": "2.0.1-beta.65",
"version": "2.0.1-beta.67",
"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
12 changes: 6 additions & 6 deletions src/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
SecurityTokenReservationFactory,
Erc20TokenBalanceFactory,
InvestmentFactory,
CappedStoFactory,
UsdTieredStoFactory,
SimpleStoFactory,
TieredStoFactory,
DividendDistributionFactory,
CheckpointFactory,
Erc20DividendsManagerFactory,
Expand All @@ -24,8 +24,8 @@ export interface Factories {
securityTokenReservationFactory: SecurityTokenReservationFactory;
erc20TokenBalanceFactory: Erc20TokenBalanceFactory;
investmentFactory: InvestmentFactory;
cappedStoFactory: CappedStoFactory;
usdTieredStoFactory: UsdTieredStoFactory;
simpleStoFactory: SimpleStoFactory;
tieredStoFactory: TieredStoFactory;
dividendDistributionFactory: DividendDistributionFactory;
checkpointFactory: CheckpointFactory;
erc20DividendsManagerFactory: Erc20DividendsManagerFactory;
Expand Down Expand Up @@ -60,8 +60,8 @@ export class Context {
securityTokenReservationFactory: new SecurityTokenReservationFactory(this),
erc20TokenBalanceFactory: new Erc20TokenBalanceFactory(this),
investmentFactory: new InvestmentFactory(this),
cappedStoFactory: new CappedStoFactory(this),
usdTieredStoFactory: new UsdTieredStoFactory(this),
simpleStoFactory: new SimpleStoFactory(this),
tieredStoFactory: new TieredStoFactory(this),
dividendDistributionFactory: new DividendDistributionFactory(this),
checkpointFactory: new CheckpointFactory(this),
erc20DividendsManagerFactory: new Erc20DividendsManagerFactory(this),
Expand Down
71 changes: 71 additions & 0 deletions src/PolymathBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ import {
VestingEscrowWallet,
RestrictedPartialSaleTransferManager,
Perm,
isCappedSTO,
isCappedSTO_3_0_0,
isUSDTieredSTO,
isUSDTieredSTO_3_0_0,
isGeneralPermissionManager,
isGeneralPermissionManager_3_0_0,
isGeneralTransferManager,
isBlacklistTransferManager,
isLockUpTransferManager,
isCountTransferManager,
isManualApprovalTransferManager,
isPercentageTransferManager,
isVolumeRestrictionTransferManager,
isRestrictedPartialSaleTransferManager,
} from '@polymathnetwork/contract-wrappers';
import { range, flatten, includes } from 'lodash';
import P from 'bluebird';
Expand Down Expand Up @@ -244,6 +258,63 @@ export class PolymathBase extends PolymathAPI {
});
};

public getTreasuryWallet = async ({ module }: { module: Module }) => {
const stAddress = await module.securityToken();
const token = await this.tokenFactory.getSecurityTokenInstanceFromAddress(stAddress);
const defaultWallet = await token.getTreasuryWallet();

if (isCappedSTO(module)) {
if (isCappedSTO_3_0_0(module)) {
return defaultWallet;
}
}

if (isUSDTieredSTO(module)) {
if (isUSDTieredSTO_3_0_0(module)) {
const wallet = await module.treasuryWallet();
return wallet === '0x0000000000000000000000000000000000000000' ? defaultWallet : wallet;
}
}

if (isGeneralPermissionManager(module)) {
return defaultWallet;
}

if (isGeneralTransferManager(module)) {
return defaultWallet;
}

if (isBlacklistTransferManager(module)) {
return defaultWallet;
}

if (isLockUpTransferManager(module)) {
return defaultWallet;
}

if (isCountTransferManager(module)) {
return defaultWallet;
}

if (isManualApprovalTransferManager(module)) {
return defaultWallet;
}

if (isPercentageTransferManager(module)) {
return defaultWallet;
}

if (isVolumeRestrictionTransferManager(module)) {
return defaultWallet;
}

if (isRestrictedPartialSaleTransferManager(module)) {
return defaultWallet;
}

return module.getTreasuryWallet();
};

public getModuleAddressesByName = async (
{ symbol, moduleName }: GetModuleAddressesByNameParams,
opts?: GetModuleAddressesByNameOpts
Expand Down
17 changes: 10 additions & 7 deletions src/PostTransactionResolver.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { TransactionReceiptWithDecodedLogs } from '@polymathnetwork/contract-wrappers';

export class PostTransactionResolver<Value extends any> {
export class PostTransactionResolver<
Value extends any,
Receipt extends any = TransactionReceiptWithDecodedLogs
> {
public result?: Value;

private resolver: (
receipt: TransactionReceiptWithDecodedLogs
) => Promise<Value> | Promise<undefined>;
private resolver: (receipt: Receipt) => Promise<Value> | Promise<undefined>;

constructor(resolver?: (receipt: TransactionReceiptWithDecodedLogs) => Promise<Value>) {
constructor(resolver?: (receipt: Receipt) => Promise<Value>) {
if (!resolver) {
this.resolver = async () => undefined;
return;
Expand All @@ -16,13 +17,15 @@ export class PostTransactionResolver<Value extends any> {
this.resolver = resolver;
}

public async run(receipt: TransactionReceiptWithDecodedLogs) {
public async run(receipt: Receipt) {
const result = await this.resolver(receipt);

this.result = result;
}
}

export function isPostTransactionResolver<T = any>(val: any): val is PostTransactionResolver<T> {
export function isPostTransactionResolver<T = any, R = TransactionReceiptWithDecodedLogs>(
val: any
): val is PostTransactionResolver<T, R> {
return val instanceof PostTransactionResolver;
}
8 changes: 2 additions & 6 deletions src/browserUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ export async function getCurrentAddress() {
export function onAddressChange(cb: (newAddress: string, previousAddress?: string) => void) {
if (isUnsupported(window as ExtendedWindow)) {
// eslint-disable-next-line no-console
console.warn(
'"onAddressChange" Was called, but the current browser does not support Ethereum.'
);
console.warn('"onAddressChange" Was called, but the current browser does not support Ethereum');
return () => {};
}

Expand Down Expand Up @@ -206,9 +204,7 @@ export function onAddressChange(cb: (newAddress: string, previousAddress?: strin
export function onNetworkChange(cb: (newNetwork: number, previousNetwork?: number) => void) {
if (isUnsupported(window as ExtendedWindow)) {
// eslint-disable-next-line no-console
console.warn(
'"onNetworkChange" Was called, but the current browser does not support Ethereum.'
);
console.warn('"onNetworkChange" Was called, but the current browser does not support Ethereum');
return () => {};
}

Expand Down
64 changes: 0 additions & 64 deletions src/entities/CappedSto.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/entities/Checkpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class Checkpoint extends Entity<Params> {
if (!isUniqueIdentifiers(unserialized)) {
throw new PolymathError({
code: ErrorCode.InvalidUuid,
message: 'Wrong Checkpoint ID format.',
message: 'Wrong Checkpoint ID format',
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/entities/DividendDistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class DividendDistribution extends Entity<Params> {
if (!isUniqueIdentifiers(unserialized)) {
throw new PolymathError({
code: ErrorCode.InvalidUuid,
message: 'Wrong Dividend Distribution ID format.',
message: 'Wrong Dividend Distribution ID format',
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/entities/DividendsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export abstract class DividendsManager<P> extends Entity<P> {
if (!isUniqueIdentifiers(unserialized)) {
throw new PolymathError({
code: ErrorCode.InvalidUuid,
message: 'Wrong Dividends Manager ID format.',
message: 'Wrong Dividends Manager ID format',
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/entities/Erc20TokenBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class Erc20TokenBalance extends Entity<Params> {
if (!isUniqueIdentifiers(unserialized)) {
throw new PolymathError({
code: ErrorCode.InvalidUuid,
message: 'Wrong ERC20 Token Balance ID format.',
message: 'Wrong ERC20 Token Balance ID format',
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/entities/Investment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Investment extends Entity<Params> {
if (!isUniqueIdentifiers(unserialized)) {
throw new PolymathError({
code: ErrorCode.InvalidUuid,
message: 'Wrong Investment ID format.',
message: 'Wrong Investment ID format',
});
}

Expand Down
Loading

0 comments on commit 3d279d7

Please sign in to comment.