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

Commit 2a6098c

Browse files
committed
fix: 🐛 add VEW event args and adapt it to new abi refactor
Add VEW EventArgs on types.ts and adapt the wrapper to the new ABI structure
2 parents 252546b + c7e5510 commit 2a6098c

31 files changed

+2623
-1762
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module.exports = {
2424
'jest/expect-expect': 'error',
2525
'jest/no-empty-title': 'warn',
2626
'jest/no-truthy-falsy': 'warn',
27+
'import/prefer-default-export': 'off',
2728
},
2829
settings: {
2930
'import/resolver': {

examples/lockUpTransferManager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { RedundantSubprovider, RPCSubprovider, Web3ProviderEngine } from '@0x/subproviders';
2+
import { BigNumber, LockUpTransferManagerEvents } from '@polymathnetwork/abi-wrappers';
23
import ModuleFactoryWrapper from '../src/contract_wrappers/modules/module_factory_wrapper';
34
import { ApiConstructorParams, PolymathAPI } from '../src/PolymathAPI';
45
import { ModuleName, ModuleType } from '../src';
5-
import { BigNumber, ModuleRegistryEvents, LockUpTransferManagerEvents } from '@polymathnetwork/abi-wrappers';
66

77
// This file acts as a valid sandbox for using a lockup restriction transfer manager module on an unlocked node (like ganache)
88
window.addEventListener('load', async () => {
@@ -27,7 +27,7 @@ window.addEventListener('load', async () => {
2727
const tokenName = prompt('Token Name', '');
2828

2929
// Double check available
30-
await polymathAPI.securityTokenRegistry.isTickerAvailable({
30+
await polymathAPI.securityTokenRegistry.tickerAvailable({
3131
ticker: ticker!,
3232
});
3333
// Get the ticker fee and approve the security token registry to spend
@@ -191,7 +191,7 @@ window.addEventListener('load', async () => {
191191
});
192192
// Example removing lockup from beneficiary 2 and removing lockup type
193193
await lockUpTM.removeLockUpFromUser({ userAddress: randomBeneficiary2, lockupName: thirdLockUpName });
194-
await lockUpTM.removeLockupType({lockupName: thirdLockUpName});
194+
await lockUpTM.removeLockupType({ lockupName: thirdLockUpName });
195195

196196
// Try to transfer 50, it is below lockup and will pass
197197
await tickerSecurityTokenInstance.transfer({ to: randomBeneficiary2, value: new BigNumber(50) });

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@polymathnetwork/contract-wrappers",
3-
"version": "2.0.0-beta.27",
3+
"version": "2.0.0-beta.30",
44
"description": "Smart TS wrappers for Polymath smart contracts",
55
"keywords": [
66
"polymath",
@@ -84,7 +84,7 @@
8484
"@0x/subproviders": "^4.1.1",
8585
"@0x/types": "^2.4.0",
8686
"@0x/typescript-typings": "^4.2.3",
87-
"@polymathnetwork/abi-wrappers": "3.0.0-beta.7",
87+
"@polymathnetwork/abi-wrappers": "3.0.0-beta.8",
8888
"@types/semver": "^6.0.1",
8989
"ethereumjs-blockstream": "6.0.0",
9090
"ethereumjs-util": "^6.1.0",

src/PolymathAPI.ts

Lines changed: 42 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,28 @@ import {
44
BigNumber,
55
providerUtils,
66
Provider,
7-
PolymathRegistry,
8-
ISecurityTokenRegistry,
9-
ISecurityToken,
10-
PolyToken,
11-
ModuleRegistry,
12-
CappedSTO,
13-
ModuleFactory,
14-
USDTieredSTO,
15-
FeatureRegistry,
16-
GeneralTransferManager,
17-
GeneralPermissionManager,
18-
ERC20DividendCheckpoint,
19-
ManualApprovalTransferManager,
20-
CountTransferManager,
21-
PercentageTransferManager,
22-
LockUpTransferManager,
23-
EtherDividendCheckpoint,
24-
VolumeRestrictionTransferManager,
25-
PolyTokenFaucet,
26-
Module,
27-
ERC20Detailed,
28-
VestingEscrowWallet,
7+
FeatureRegistryContract,
8+
ModuleRegistryContract,
9+
PolymathRegistryContract,
10+
ISecurityTokenRegistryContract,
11+
ModuleFactoryContract,
12+
ModuleContract,
13+
ERC20DividendCheckpointContract,
14+
EtherDividendCheckpointContract,
15+
GeneralPermissionManagerContract,
16+
CappedSTOContract,
17+
USDTieredSTOContract,
18+
CountTransferManagerContract,
19+
GeneralTransferManagerContract,
20+
ManualApprovalTransferManagerContract,
21+
PercentageTransferManagerContract,
22+
LockUpTransferManagerContract,
23+
ERC20DetailedContract,
24+
PolyTokenContract,
25+
PolyTokenFaucetContract,
26+
ISecurityTokenContract,
27+
VolumeRestrictionTMContract,
2928
} from '@polymathnetwork/abi-wrappers';
30-
import _ from 'lodash';
3129
import PolymathRegistryWrapper from './contract_wrappers/registries/polymath_registry_wrapper';
3230
import SecurityTokenRegistryWrapper from './contract_wrappers/registries/security_token_registry_wrapper';
3331
import PolyTokenWrapper from './contract_wrappers/tokens/poly_token_wrapper';
@@ -138,62 +136,33 @@ export class PolymathAPI {
138136

139137
const abiArray = [
140138
// Registries
141-
FeatureRegistry.abi,
142-
ModuleRegistry.abi.filter(
143-
a =>
144-
!(
145-
a.type === 'function' &&
146-
a.name === 'useModule' &&
147-
_.isEqual(a.inputs, [
148-
{
149-
name: '_moduleFactory',
150-
type: 'address',
151-
},
152-
])
153-
),
154-
),
155-
PolymathRegistry.abi,
156-
ISecurityTokenRegistry.abi.filter(
157-
a =>
158-
!(
159-
a.type === 'event' &&
160-
a.name === 'RegisterTicker' &&
161-
_.isEqual(a.inputs, [
162-
{ indexed: true, name: '_owner', type: 'address' },
163-
{ indexed: false, name: '_ticker', type: 'string' },
164-
{ indexed: false, name: '_name', type: 'string' },
165-
{ indexed: true, name: '_registrationDate', type: 'uint256' },
166-
{ indexed: true, name: '_expiryDate', type: 'uint256' },
167-
{ indexed: false, name: '_fromAdmin', type: 'bool' },
168-
{ indexed: false, name: '_registrationFee', type: 'uint256' },
169-
])
170-
),
171-
),
139+
FeatureRegistryContract.ABI(),
140+
ModuleRegistryContract.ABI(),
141+
PolymathRegistryContract.ABI(),
142+
ISecurityTokenRegistryContract.ABI(),
172143
// Modules
173-
ModuleFactory.abi,
174-
Module.abi,
144+
ModuleFactoryContract.ABI(),
145+
ModuleContract.ABI(),
175146
// Checkpoint
176-
ERC20DividendCheckpoint.abi,
177-
EtherDividendCheckpoint.abi,
147+
ERC20DividendCheckpointContract.ABI(),
148+
EtherDividendCheckpointContract.ABI(),
178149
// Permission
179-
GeneralPermissionManager.abi,
150+
GeneralPermissionManagerContract.ABI(),
180151
// STO
181-
CappedSTO.abi,
182-
USDTieredSTO.abi,
152+
CappedSTOContract.ABI(),
153+
USDTieredSTOContract.ABI(),
183154
// Transfer
184-
CountTransferManager.abi,
185-
GeneralTransferManager.abi,
186-
ManualApprovalTransferManager.abi,
187-
PercentageTransferManager.abi,
188-
LockUpTransferManager.abi,
189-
VolumeRestrictionTransferManager.abi,
155+
CountTransferManagerContract.ABI(),
156+
GeneralTransferManagerContract.ABI(),
157+
ManualApprovalTransferManagerContract.ABI(),
158+
PercentageTransferManagerContract.ABI(),
159+
LockUpTransferManagerContract.ABI(),
160+
VolumeRestrictionTMContract.ABI(),
190161
// Tokens
191-
ERC20Detailed.abi,
192-
PolyToken.abi,
193-
PolyTokenFaucet.abi,
194-
ISecurityToken.abi,
195-
// Wallet
196-
VestingEscrowWallet.abi,
162+
ERC20DetailedContract.ABI(),
163+
PolyTokenContract.ABI(),
164+
PolyTokenFaucetContract.ABI(),
165+
ISecurityTokenContract.ABI(),
197166
];
198167

199168
abiArray.forEach((abi): void => {

src/contract_wrappers/contract_wrapper.ts

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* eslint-disable no-underscore-dangle */
22
import { Block, BlockAndLogStreamer, Log } from 'ethereumjs-blockstream';
33
import _ from 'lodash';
4+
import { schemas } from '@0x/json-schemas';
45
import {
56
BaseContract,
67
Web3Wrapper,
78
marshaller,
8-
AbiDecoder,
99
intervalUtils,
1010
logUtils,
1111
BlockParamLiteral,
@@ -33,8 +33,6 @@ const SUBSCRIPTION_NOT_FOUND = 'SUBSCRIPTION_NOT_FOUND';
3333
const SUBSCRIPTION_ALREADY_PRESENT = 'SUBSCRIPTION_ALREADY_PRESENT';
3434

3535
export default abstract class ContractWrapper {
36-
public abstract abi: ContractAbi;
37-
3836
protected contract: Promise<BaseContract>;
3937

4038
protected web3Wrapper: Web3Wrapper;
@@ -43,6 +41,13 @@ export default abstract class ContractWrapper {
4341

4442
public abstract subscribeAsync: Subscribe | undefined;
4543

44+
/**
45+
* Returns the contract ABI
46+
*/
47+
public abi = async (): Promise<ContractAbi> => {
48+
return (await this.contract).abi;
49+
};
50+
4651
/**
4752
* Returns the contract address
4853
*/
@@ -64,12 +69,9 @@ export default abstract class ContractWrapper {
6469
*/
6570
public unsubscribeAll = (): void => {
6671
const filterTokens = _.keys(this._filterCallbacks);
67-
_.each(
68-
filterTokens,
69-
(filterToken): void => {
70-
this.unsubscribeInternal(filterToken);
71-
},
72-
);
72+
_.each(filterTokens, (filterToken): void => {
73+
this.unsubscribeInternal(filterToken);
74+
});
7375
};
7476

7577
private _blockAndLogStreamerIfExists: BlockAndLogStreamer<Block, Log> | undefined;
@@ -117,14 +119,14 @@ export default abstract class ContractWrapper {
117119
}
118120
}
119121

120-
protected subscribeInternal<ArgsType extends ContractEventArgs>(
122+
protected async subscribeInternal<ArgsType extends ContractEventArgs>(
121123
address: string,
122124
eventName: ContractEvents,
123125
indexFilterValues: IndexedFilterValues,
124-
abi: ContractAbi,
125126
callback: EventCallback<ArgsType>,
126127
isVerbose: boolean = false,
127-
): string {
128+
): Promise<string> {
129+
const { abi } = await this.contract;
128130
const filter = filterUtils.getFilter(address, eventName, indexFilterValues, abi);
129131
if (_.isUndefined(this._blockAndLogStreamerIfExists)) {
130132
this._startBlockAndLogStream(isVerbose);
@@ -138,11 +140,18 @@ export default abstract class ContractWrapper {
138140
protected async getLogsAsyncInternal<ArgsType extends ContractEventArgs>(
139141
address: string,
140142
eventName: ContractEvents,
141-
blockRange: BlockRange,
142-
indexFilterValues: IndexedFilterValues,
143-
abi: ContractAbi,
143+
blockRange?: BlockRange,
144+
indexFilterValues?: IndexedFilterValues,
144145
): Promise<LogWithDecodedArgs<ArgsType>[]> {
145-
const filter = filterUtils.getFilter(address, eventName, indexFilterValues, abi, blockRange);
146+
const { abi } = await this.contract;
147+
const _blockRange = blockRange || {
148+
fromBlock: BlockParamLiteral.Earliest,
149+
toBlock: BlockParamLiteral.Latest,
150+
};
151+
const _indexFilterValues = indexFilterValues || {};
152+
assert.doesConformToSchema('blockRange', _blockRange, schemas.blockRangeSchema);
153+
assert.doesConformToSchema('indexFilterValues', _indexFilterValues, schemas.indexFilterValuesSchema);
154+
const filter = filterUtils.getFilter(address, eventName, _indexFilterValues, abi, _blockRange);
146155
const logs = await this.web3Wrapper.getLogsAsync(filter);
147156
const logsWithDecodedArguments = _.map(logs, this.tryToDecodeLogOrNoopInternal.bind(this));
148157
return logsWithDecodedArguments as LogWithDecodedArgs<ArgsType>[];
@@ -151,26 +160,23 @@ export default abstract class ContractWrapper {
151160
protected tryToDecodeLogOrNoopInternal<ArgsType extends ContractEventArgs>(
152161
log: LogEntry,
153162
): LogWithDecodedArgs<ArgsType> | RawLog {
154-
const abiDecoder = new AbiDecoder([this.abi]);
163+
const { abiDecoder } = this.web3Wrapper;
155164
const logWithDecodedArgs = abiDecoder.tryToDecodeLogOrNoop(log);
156165
return logWithDecodedArgs;
157166
}
158167

159168
private _onLogStateChanged<ArgsType extends ContractEventArgs>(isRemoved: boolean, rawLog: Log): void {
160169
const log: LogEntry = marshaller.unmarshalLog(rawLog as RawLogEntry);
161-
_.forEach(
162-
this._filters,
163-
(filter: FilterObject, filterToken: string): void => {
164-
if (filterUtils.matchesFilter(log, filter)) {
165-
const decodedLog = this.tryToDecodeLogOrNoopInternal(log) as LogWithDecodedArgs<ArgsType>;
166-
const logEvent = {
167-
log: decodedLog,
168-
isRemoved,
169-
};
170-
this._filterCallbacks[filterToken](null, logEvent);
171-
}
172-
},
173-
);
170+
_.forEach(this._filters, (filter: FilterObject, filterToken: string): void => {
171+
if (filterUtils.matchesFilter(log, filter)) {
172+
const decodedLog = this.tryToDecodeLogOrNoopInternal(log) as LogWithDecodedArgs<ArgsType>;
173+
const logEvent = {
174+
log: decodedLog,
175+
isRemoved,
176+
};
177+
this._filterCallbacks[filterToken](null, logEvent);
178+
}
179+
});
174180
}
175181

176182
private _startBlockAndLogStream(isVerbose: boolean): void {

src/contract_wrappers/modules/checkpoint/erc20_dividend_checkpoint_wrapper.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ import {
1111
ERC20DividendCheckpointSetWithholdingFixedEventArgs,
1212
ERC20DetailedContract,
1313
BigNumber,
14-
ContractAbi,
1514
LogWithDecodedArgs,
16-
TxData,
1715
Web3Wrapper,
18-
ERC20DividendCheckpoint,
1916
} from '@polymathnetwork/abi-wrappers';
2017
import { schemas } from '@0x/json-schemas';
2118
import assert from '../../../utils/assert';
@@ -32,8 +29,6 @@ import {
3229
} from '../../../types';
3330
import { numberToBigNumber, dateToBigNumber, stringToBytes32, valueToWei } from '../../../utils/convert';
3431

35-
const EXCLUDED_ADDRESS_LIMIT = 150;
36-
3732
interface ERC20DividendDepositedSubscribeAsyncParams extends SubscribeAsyncParams {
3833
eventName: ERC20DividendCheckpointEvents.ERC20DividendDeposited;
3934
callback: EventCallback<ERC20DividendCheckpointERC20DividendDepositedEventArgs>;
@@ -160,8 +155,6 @@ interface CreateDividendWithCheckpointAndExclusionsParams extends CreateDividend
160155
* This class includes the functionality related to interacting with the ERC20DividendCheckpoint contract.
161156
*/
162157
export default class ERC20DividendCheckpointWrapper extends DividendCheckpointWrapper {
163-
public abi: ContractAbi = ERC20DividendCheckpoint.abi;
164-
165158
protected contract: Promise<ERC20DividendCheckpointContract>;
166159

167160
protected erc20DetailedContract = async (address: string): Promise<ERC20DetailedContract> => {
@@ -307,11 +300,10 @@ export default class ERC20DividendCheckpointWrapper extends DividendCheckpointWr
307300
assert.doesConformToSchema('indexFilterValues', params.indexFilterValues, schemas.indexFilterValuesSchema);
308301
assert.isFunction('callback', params.callback);
309302
const normalizedContractAddress = (await this.contract).address.toLowerCase();
310-
const subscriptionToken = this.subscribeInternal<ArgsType>(
303+
const subscriptionToken = await this.subscribeInternal<ArgsType>(
311304
normalizedContractAddress,
312305
params.eventName,
313306
params.indexFilterValues,
314-
ERC20DividendCheckpoint.abi,
315307
params.callback,
316308
params.isVerbose,
317309
);
@@ -328,15 +320,12 @@ export default class ERC20DividendCheckpointWrapper extends DividendCheckpointWr
328320
params: GetLogsAsyncParams,
329321
): Promise<LogWithDecodedArgs<ArgsType>[]> => {
330322
assert.doesBelongToStringEnum('eventName', params.eventName, ERC20DividendCheckpointEvents);
331-
assert.doesConformToSchema('blockRange', params.blockRange, schemas.blockRangeSchema);
332-
assert.doesConformToSchema('indexFilterValues', params.indexFilterValues, schemas.indexFilterValuesSchema);
333323
const normalizedContractAddress = (await this.contract).address.toLowerCase();
334324
const logs = await this.getLogsAsyncInternal<ArgsType>(
335325
normalizedContractAddress,
336326
params.eventName,
337327
params.blockRange,
338328
params.indexFilterValues,
339-
ERC20DividendCheckpoint.abi,
340329
);
341330
return logs;
342331
};

0 commit comments

Comments
 (0)