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

Commit 37b5a3e

Browse files
committed
feat: 🎸 use 3.0 methods to check for ticker availability
removed obsolete STR internal methods (that weren't working properly) and fixed the signature of `getSecurityTokenAddress` BREAKING CHANGE: rename Security Token Registry wrapper's `isTickerAvailable` to `tickerAvailable`, `getSecurityTokenAddress` now receives `{ ticker: string }` instead of just `string`
1 parent a3836d5 commit 37b5a3e

File tree

3 files changed

+16
-28
lines changed

3 files changed

+16
-28
lines changed

‎examples/addInvestorToWhitelist.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

‎examples/cappedSTO.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ window.addEventListener('load', async () => {
2828
const tokenName = prompt('Token Name', '');
2929

3030
// Double check available
31-
await polymathAPI.securityTokenRegistry.isTickerAvailable({
31+
await polymathAPI.securityTokenRegistry.tickerAvailable({
3232
ticker: ticker!,
3333
});
3434
// Get the ticker fee and approve the security token registry to spend

‎src/contract_wrappers/registries/security_token_registry_wrapper.ts‎

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ export default class SecurityTokenRegistryWrapper extends ContractWrapper {
588588
});
589589
assert.assert(tickerDetails.status, 'Not deployed');
590590
const isFrozen = await (await this.securityTokenContract(
591-
await this.getSecurityTokenAddress(params.ticker),
591+
await this.getSecurityTokenAddress({ ticker: params.ticker }),
592592
)).transfersFrozen.callAsync();
593593
assert.assert(isFrozen, 'Transfers not frozen');
594594
return (await this.contract).refreshSecurityToken.sendTransactionAsync(
@@ -724,7 +724,7 @@ export default class SecurityTokenRegistryWrapper extends ContractWrapper {
724724
assert.assert(params.registrationDate.getTime() > new Date(0).getTime(), 'Bad registration date');
725725
assert.isNonZeroETHAddressHex('owner', params.owner);
726726
if (params.status) {
727-
const address = await this.getSecurityTokenAddress(params.ticker);
727+
const address = await this.getSecurityTokenAddress({ ticker: params.ticker });
728728
assert.isNonZeroETHAddressHex('address', address);
729729
}
730730
return (await this.contract).modifyExistingTicker.sendTransactionAsync(
@@ -799,7 +799,7 @@ export default class SecurityTokenRegistryWrapper extends ContractWrapper {
799799
assert.assert(functionsUtils.checksumAddressComparision(address, tickerDetails.owner), 'Not authorised');
800800
if (tickerDetails.status) {
801801
const securityTokenOwner = await (await this.securityTokenContract(
802-
await this.getSecurityTokenAddress(params.ticker),
802+
await this.getSecurityTokenAddress({ ticker: params.ticker }),
803803
)).owner.callAsync();
804804
assert.assert(securityTokenOwner === params.newOwner, 'New owner does not match token owner');
805805
}
@@ -855,30 +855,28 @@ export default class SecurityTokenRegistryWrapper extends ContractWrapper {
855855
};
856856

857857
/**
858-
* Returns the security token address by ticker symbol
859-
* @param ticker is the ticker of the security token
858+
* Returns the security token address by ticker symbol
860859
* @return address string
861860
*/
862-
public getSecurityTokenAddress = async (ticker: string) => {
863-
return (await this.contract).getSecurityTokenAddress.callAsync(ticker);
864-
};
861+
public getSecurityTokenAddress = async (params: TickerParams) => {
862+
return (await this.contract).getSecurityTokenAddress.callAsync(params.ticker);
863+
};
865864

866865
/**
867866
* Gets ticker availability
868867
* @return boolean
869868
*/
870-
public isTickerAvailable = async (params: TickerParams) => {
871-
const result = await this.getTickerDetailsInternal(params.ticker);
872-
return this.isTickerAvailableInternal(result.registrationDate, result.expiryDate, result.status);
873-
};
869+
public tickerAvailable = async (params: TickerParams) => {
870+
return (await this.contract).tickerAvailable.callAsync(params.ticker);
871+
}
874872

875873
/**
876874
* Knows if the ticker was registered by the user
877875
* @return boolean
878876
*/
879877
public isTickerRegisteredByCurrentIssuer = async (params: TickerParams) => {
880878
const result = await this.getTickerDetailsInternal(params.ticker);
881-
if (this.isTickerAvailableInternal(result.registrationDate, result.expiryDate, result.status)) {
879+
if (await this.tickerAvailable({ ticker: params.ticker })) {
882880
return false;
883881
}
884882
return result.owner === (await this.getDefaultFromAddress());
@@ -906,7 +904,7 @@ export default class SecurityTokenRegistryWrapper extends ContractWrapper {
906904
);
907905
assert.isETHAddressHex('owner', params.owner);
908906
if (params.status) {
909-
const address = await this.getSecurityTokenAddress(params.ticker);
907+
const address = await this.getSecurityTokenAddress({ ticker: params.ticker });
910908
assert.isNonZeroETHAddressHex('address', address);
911909
}
912910
return (await this.contract).modifyTicker.sendTransactionAsync(
@@ -1220,16 +1218,6 @@ export default class SecurityTokenRegistryWrapper extends ContractWrapper {
12201218
return logs;
12211219
};
12221220

1223-
private isTickerAvailableInternal = (registrationDate: Date, expiryDate: Date, isDeployed: boolean) => {
1224-
if (registrationDate.getTime() === new Date(0).getTime()) {
1225-
return true;
1226-
}
1227-
if (!isDeployed && expiryDate.getTime() > Date.now()) {
1228-
return true;
1229-
}
1230-
return false;
1231-
};
1232-
12331221
private getTickerDetailsInternal = async (ticker: string) => {
12341222
const result = await (await this.contract).getTickerDetails.callAsync(ticker);
12351223
const typedResult: TickerDetails = {
@@ -1267,7 +1255,7 @@ export default class SecurityTokenRegistryWrapper extends ContractWrapper {
12671255
assert.isETHAddressHex('owner', owner);
12681256
assert.assert(ticker.length > 0 && ticker.length <= 10, 'Bad ticker, must be 1 to 10 characters');
12691257
assert.assert(
1270-
await this.isTickerAvailable({
1258+
await this.tickerAvailable({
12711259
ticker,
12721260
}),
12731261
'Ticker is not available',
@@ -1289,7 +1277,7 @@ export default class SecurityTokenRegistryWrapper extends ContractWrapper {
12891277
assert.isNonZeroETHAddressHex('securityToken', securityToken);
12901278
assert.isNonZeroETHAddressHex(
12911279
'Security token not registered for ticker',
1292-
await this.getSecurityTokenAddress(ticker),
1280+
await this.getSecurityTokenAddress({ ticker }),
12931281
);
12941282
};
12951283
}

0 commit comments

Comments
 (0)