Skip to content

Commit 2c4546d

Browse files
authored
Merge pull request #630 from PolymathNetwork/bug/refreshed-tokens
Read refreshed tokens events
2 parents e0f83bb + 1c0d629 commit 2c4546d

3 files changed

Lines changed: 31 additions & 19 deletions

File tree

packages/polymath-js/src/contracts/SecurityTokenRegistry.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import type {
2424

2525
const NEW_SECURITY_TOKEN_EVENT = 'NewSecurityToken';
2626
const REGISTER_TICKER_EVENT = 'RegisterTicker';
27+
const REFRESHED_SECURITY_TOKEN_EVENT = 'SecurityTokenRefreshed';
2728

2829
class SecurityTokenRegistry extends Contract {
2930
constructor(artifact: any, address: string) {
@@ -190,25 +191,28 @@ class SecurityTokenRegistry extends Contract {
190191
token.owner = await contract.owner();
191192

192193
// get token issuing tx hash
194+
const eventOpts = {
195+
filter: { _securityTokenAddress: token.address },
196+
fromBlock: 0,
197+
toBlock: 'latest',
198+
};
199+
193200
let events = await this._contractWS.getPastEvents(
194201
NEW_SECURITY_TOKEN_EVENT,
195-
{
196-
filter: { _securityTokenAddress: token.address },
197-
fromBlock: 0,
198-
toBlock: 'latest',
199-
}
202+
eventOpts
203+
);
204+
const events3 = await this._contractWS.getPastEvents(
205+
REFRESHED_SECURITY_TOKEN_EVENT,
206+
eventOpts
200207
);
201208
if (semver.eq(this.version, LATEST_PROTOCOL_VERSION)) {
202209
const str2 = new SecurityTokenRegistry(artifact2, this.address);
203210
const events2 = await str2._contractWS.getPastEvents(
204211
NEW_SECURITY_TOKEN_EVENT,
205-
{
206-
filter: { _securityTokenAddress: token.address },
207-
fromBlock: 0,
208-
toBlock: 'latest',
209-
}
212+
eventOpts
210213
);
211-
events = [...events, ...events2];
214+
215+
events = [...events, ...events2, ...events3];
212216
}
213217
token.txHash = events[0].transactionHash;
214218
token.timestamp = await this._getBlockDate(events[0].blockNumber);

packages/polymath-offchain/src/startup/__tests__/setupWeb3.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ const contractMock = jest.fn().mockImplementation(() => {
112112
RegisterTicker: registerTickerListenerMock,
113113
ModuleAdded: moduleAddedListenerMock,
114114
NewSecurityToken: newSecurityTokenListenerMock,
115+
SecurityTokenRefreshed: newSecurityTokenListenerMock,
115116
},
116117
getPastEvents: getPastEventsMock,
117118
methods: {

packages/polymath-offchain/src/startup/setupWeb3.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import logger from 'winston';
1111
import Web3 from 'web3';
1212
import { User } from '../models';
1313
import PolymathRegistryArtifact from '@polymathnetwork/polymath-scripts/fixtures/contracts/PolymathRegistry.json';
14-
import SecurityTokenRegistryArtifact from '@polymathnetwork/polymath-scripts/fixtures/contracts/ISecurityTokenRegistry.json';
14+
import SecurityTokenRegistryArtifact from '@polymathnetwork/polymath-scripts/fixtures/contracts/SecurityTokenRegistry.json';
1515
import SecurityTokenArtifact from '@polymathnetwork/polymath-scripts/fixtures/contracts/ISecurityToken.json';
1616
import CappedSTOArtifact from '@polymathnetwork/polymath-scripts/fixtures/contracts/CappedSTO.json';
1717
import STOModuleFactoryArtifacts from '@polymathnetwork/polymath-scripts/fixtures/contracts/ModuleFactory.json';
@@ -512,6 +512,10 @@ export const addTokenCreateListener = async (networkId: string) => {
512512
newSecurityTokenHandler(contract, networkId, error, result)
513513
);
514514

515+
contract.events.SecurityTokenRefreshed({}, (error, result) =>
516+
newSecurityTokenHandler(contract, networkId, error, result)
517+
);
518+
515519
logger.info(
516520
`[SETUP] Listening for Security Token deployments in ${NETWORKS[
517521
networkId
@@ -526,14 +530,17 @@ export const addTokenCreateListener = async (networkId: string) => {
526530
export const addSTOListeners = async (networkId: string) => {
527531
const contract = await getSTRContract(networkId);
528532
try {
529-
const previousTokenEvents = await contract.getPastEvents(
530-
'NewSecurityToken',
531-
{
532-
fromBlock: 0,
533-
toBlock: 'latest',
534-
}
535-
);
533+
let newSTs = await contract.getPastEvents('NewSecurityToken', {
534+
fromBlock: 0,
535+
toBlock: 'latest',
536+
});
537+
538+
let refreshedSTs = await contract.getPastEvents('SecurityTokenRefreshed', {
539+
fromBlock: 0,
540+
toBlock: 'latest',
541+
});
536542

543+
const previousTokenEvents = [...newSTs, ...refreshedSTs];
537544
for (let event of previousTokenEvents) {
538545
const {
539546
returnValues: { _securityTokenAddress, _ticker },

0 commit comments

Comments
 (0)