9
9
RegisterTickerArgs ,
10
10
GenerateSecurityTokenArgs ,
11
11
GetSecurityTokenArgs ,
12
+ GetTickerDetailsArgs ,
13
+ IsTickerAvailableArgs ,
14
+ TickerDetails ,
12
15
} from './types' ;
13
16
import { fromWei } from './utils' ;
14
17
@@ -19,6 +22,9 @@ interface SecurityTokenRegistryContract extends GenericContract {
19
22
ticker : string ,
20
23
tokenName : string
21
24
) : TransactionObject < void > ;
25
+ getTickerDetails (
26
+ ticker : string
27
+ ) : TransactionObject < { [ key : string ] : string } > ;
22
28
getTickerRegistrationFee ( ) : TransactionObject < string > ;
23
29
getSecurityTokenLaunchFee ( ) : TransactionObject < string > ;
24
30
getSecurityTokenAddress ( ticker : string ) : TransactionObject < string > ;
@@ -49,6 +55,68 @@ export class SecurityTokenRegistry extends Contract<
49
55
. send ( { from : this . context . account } ) ;
50
56
} ;
51
57
58
+ public getTickerDetails = async ( { ticker } : GetTickerDetailsArgs ) => {
59
+ const keysMap : { [ key : string ] : string } = {
60
+ '0' : 'owner' ,
61
+ '1' : 'registrationDate' ,
62
+ '2' : 'expiryDate' ,
63
+ '3' : 'name' ,
64
+ '4' : 'status' ,
65
+ } ;
66
+
67
+ const details = await this . contract . methods
68
+ . getTickerDetails ( ticker )
69
+ . call ( { from : this . context . account } ) ;
70
+
71
+ // Convert the object returned by SecurityTokenRegistry.getTickerDetails to a TickerDetails object.
72
+ try {
73
+ const initialValue = < TickerDetails > {
74
+ owner : '0x0000000000000000000000000000000000000000' ,
75
+ registrationDate : 0 ,
76
+ expiryDate : 0 ,
77
+ name : '' ,
78
+ status : false ,
79
+ } ;
80
+ const labeledDetails : TickerDetails = Object . keys ( details ) . reduce (
81
+ ( acc , cur : string ) => {
82
+ let val : string | number = details [ cur ] ;
83
+ // Parse unix timestamps.
84
+ if ( cur === '1' || cur === '2' ) {
85
+ val = parseInt ( val ) ;
86
+ }
87
+ const newKey : string = keysMap [ cur ] ;
88
+ acc [ newKey ] = val ;
89
+ return acc ;
90
+ } ,
91
+ initialValue
92
+ ) ;
93
+
94
+ return labeledDetails ;
95
+ } catch ( error ) {
96
+ throw new Error ( 'Unexpected ticker details data.' ) ;
97
+ }
98
+ } ;
99
+
100
+ /**
101
+ * While lacking a public, smart contract function to check for ticker availability, this function attempts to
102
+ * immitate the internal function SecurityTokenRegistry._tickerAvailable()
103
+ * @see https://github.com/PolymathNetwork/polymath-core/blob/aa635df01588f733ce95bc13fe319c7d3c858a24/contracts/SecurityTokenRegistry.sol#L318
104
+ */
105
+ public isTickerAvailable = async ( {
106
+ ticker,
107
+ } : IsTickerAvailableArgs ) : Promise < boolean > => {
108
+ const details = await this . getTickerDetails ( { ticker } ) ;
109
+
110
+ if ( details . owner !== '0x0000000000000000000000000000000000000000' ) {
111
+ if ( Date . now ( ) > details . expiryDate * 1000 && ! details . status ) {
112
+ return true ;
113
+ }
114
+ return false ;
115
+ }
116
+
117
+ return true ;
118
+ } ;
119
+
52
120
public generateSecurityToken = async ( {
53
121
tokenName,
54
122
ticker,
0 commit comments