Skip to content
This repository has been archived by the owner on Jul 6, 2022. It is now read-only.

Commit

Permalink
Merge 26b9989 into eb4333c
Browse files Browse the repository at this point in the history
  • Loading branch information
shuffledex committed Oct 7, 2019
2 parents eb4333c + 26b9989 commit 904d97c
Show file tree
Hide file tree
Showing 12 changed files with 1,437 additions and 21 deletions.
38 changes: 38 additions & 0 deletions examples/advancedPLCRVoting.ts
@@ -0,0 +1,38 @@
import { AdvancedPLCRVotingCheckpointEvents_3_1_0, BigNumber, ethersUtils } from '@polymathnetwork/abi-wrappers';
import _ from 'lodash';
import { PolymathAPI, ModuleName } from '../src';
import { moduleInstancesLookup } from './modules';

/**
* This method adds a AdvancedPLCRVotingCheckpoint module and uses it. Requires that a valid security token has already been generated.
* @param polymathAPI The polymathAPI instance.
* @param ticker Ticker symbol.
*/

// Example under construction
export const advancedPLCRVotingCheckpoint = async (polymathAPI: PolymathAPI, ticker: string) => {
const advancedPLCRVoting = (await moduleInstancesLookup(polymathAPI, {
ticker,
moduleName: ModuleName.AdvancedPLCRVotingCheckpoint,
}))[0];

const logs = await advancedPLCRVoting.getLogsAsync({
eventName: AdvancedPLCRVotingCheckpointEvents_3_1_0.VoteCommit,
indexFilterValues: { _voter: '0x84c3f9d07466a65c3a1dd1eab059dec560a11f0c' },
});

const args = _.map(logs, (e: any) => {
return e.args;
});

const onlyBallot: any = _.filter(args, (e: any) => {
return e._ballotId.toNumber() === 2;
});

const secretHash = onlyBallot[0]._secretHash;
const hash = ethersUtils.solidityKeccak256(['uint256', 'uint256'], ['1000000000000000000', '12345678']);

console.log(secretHash, hash);

advancedPLCRVoting.unsubscribeAll();
};
50 changes: 44 additions & 6 deletions examples/modules.ts
@@ -1,4 +1,5 @@
import { BigNumber } from '@polymathnetwork/abi-wrappers';
import P from 'bluebird';
import {
BlacklistTransferManager,
CappedSTO,
Expand All @@ -18,8 +19,8 @@ import {
USDTieredSTO,
VestingEscrowWallet,
VolumeRestrictionTransferManager,
AdvancedPLCRVotingCheckpoint,
} from '../src';
import P from 'bluebird';
import { PolymathError } from '../src/PolymathError';
import {
CappedSTOData,
Expand All @@ -29,6 +30,7 @@ import {
RestrictedPartialSaleTransferManagerData,
USDTieredSTOData,
VestingEscrowWalletData,
AdvancedPLCRVotingCheckpointData,
} from '../src/contract_wrappers/tokens/security_token_wrapper/common';
import { ModuleFactory } from '../src/contract_wrappers/modules/module_factory_wrapper';

Expand All @@ -51,7 +53,8 @@ export interface AddingModuleOpts {
| DividendCheckpointData
| CappedSTOData
| USDTieredSTOData
| VestingEscrowWalletData;
| VestingEscrowWalletData
| AdvancedPLCRVotingCheckpointData;
}

interface GetAttachedGeneralPermissionManagersParams extends GetAttachedModulesParams {
Expand Down Expand Up @@ -110,6 +113,10 @@ interface GetAttachedEtherDividendCheckpointsParams extends GetAttachedModulesPa
moduleName: ModuleName.EtherDividendCheckpoint;
}

interface GetAttachedAdvancedPLCRVotingCheckpointsParams extends GetAttachedModulesParams {
moduleName: ModuleName.AdvancedPLCRVotingCheckpoint;
}

interface GetAttachedModules {
(params: GetAttachedGeneralPermissionManagersParams, opts?: GetAttachedModulesOpts): Promise<
GeneralPermissionManager[]
Expand Down Expand Up @@ -141,6 +148,9 @@ interface GetAttachedModules {
(params: GetAttachedEtherDividendCheckpointsParams, opts?: GetAttachedModulesOpts): Promise<
EtherDividendCheckpoint[]
>;
(params: GetAttachedAdvancedPLCRVotingCheckpointsParams, opts?: GetAttachedModulesOpts): Promise<
AdvancedPLCRVotingCheckpoint
>;
}

/**
Expand All @@ -157,9 +167,7 @@ export const addModule = async (
opts: AddingModuleOpts,
) => {
// Create a Security Token Instance
const tickerSecurityTokenInstance = await polymathAPI.tokenFactory.getSecurityTokenInstanceFromTicker(
ticker ? ticker : '',
);
const tickerSecurityTokenInstance = await polymathAPI.tokenFactory.getSecurityTokenInstanceFromTicker(ticker || '');

const moduleTypes = {
[ModuleName.CappedSTO]: ModuleType.STO,
Expand All @@ -176,6 +184,7 @@ export const addModule = async (
[ModuleName.EtherDividendCheckpoint]: ModuleType.Dividends,
[ModuleName.GeneralPermissionManager]: ModuleType.PermissionManager,
[ModuleName.VestingEscrowWallet]: ModuleType.Wallet,
[ModuleName.AdvancedPLCRVotingCheckpoint]: ModuleType.Dividends,
};

async function getRequiredPolyTokenBalanceOnSecurityToken(setupCost: BigNumber) {
Expand Down Expand Up @@ -457,6 +466,25 @@ export const addModule = async (
break;
}

case ModuleName.AdvancedPLCRVotingCheckpoint: {
const address = await getFactoryAddress(
polymathAPI,
moduleTypes[ModuleName.AdvancedPLCRVotingCheckpoint],
ModuleName.AdvancedPLCRVotingCheckpoint,
);
const factory = await polymathAPI.moduleFactory.getModuleFactory(address);
const setupCost = await factory.setupCostInPoly();
await getRequiredPolyTokenBalanceOnSecurityToken(setupCost);
await tickerSecurityTokenInstance.addModule({
moduleName: ModuleName.AdvancedPLCRVotingCheckpoint,
address,
maxCost: setupCost,
budget: setupCost,
archived: opts.archived,
});
break;
}

default: {
throw new PolymathError({
code: ErrorCode.NotFound,
Expand Down Expand Up @@ -510,7 +538,7 @@ export const moduleInstancesLookup = async (
): Promise<any[]> => {
// Create a Security Token Instance

const securityToken = await polymathAPI.tokenFactory.getSecurityTokenInstanceFromTicker(ticker ? ticker : '');
const securityToken = await polymathAPI.tokenFactory.getSecurityTokenInstanceFromTicker(ticker || '');
// Get Module Addresses
const moduleAddresses = await securityToken.getModulesByName({ moduleName });

Expand Down Expand Up @@ -670,6 +698,16 @@ export const moduleInstancesLookup = async (
return wrappedModules;
}

case ModuleName.AdvancedPLCRVotingCheckpoint: {
wrappedModules = await P.map(filteredModuleAddresses, (moduleAddress: any) =>
polymathAPI.moduleFactory.getModuleInstance({
address: moduleAddress,
name: moduleName,
}),
);
return wrappedModules;
}

default: {
throw new PolymathError({
code: ErrorCode.NotFound,
Expand Down
7 changes: 7 additions & 0 deletions src/PolymathAPI.ts
Expand Up @@ -33,6 +33,7 @@ import {
GeneralTransferManagerContract_3_1_0,
RestrictedPartialSaleTMContract_3_1_0,
VestingEscrowWalletContract_3_1_0,
AdvancedPLCRVotingCheckpointContract_3_1_0,
} from '@polymathnetwork/abi-wrappers';
import PolymathRegistryWrapper from './contract_wrappers/registries/polymath_registry_wrapper';
import SecurityTokenRegistryWrapper from './contract_wrappers/registries/security_token_registry_wrapper';
Expand Down Expand Up @@ -189,8 +190,14 @@ export class PolymathAPI {
RestrictedPartialSaleTMContract_3_1_0.ABI(),
// Wallet
VestingEscrowWalletContract_3_1_0.ABI(),
// Checkpoint
AdvancedPLCRVotingCheckpointContract_3_1_0.ABI(),
];

abiArray.forEach((abi): void => {
this.web3Wrapper.abiDecoder.addABI(abi);
});

this.contractFactory = new ContractFactory(this.web3Wrapper, abiArray, params.polymathRegistryAddress);

this.polymathRegistry = new PolymathRegistryWrapper(
Expand Down

0 comments on commit 904d97c

Please sign in to comment.