Skip to content

Commit 308eae4

Browse files
committed
fix: return protocol version correctly
also throw an error in the TransferErc20 procedure if the provided token address corresponds to a Security Token. The error message directs the user to the proper transfer functions in the security token entity
1 parent ffdda6d commit 308eae4

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/Polymath.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import P from 'bluebird';
99
import { Context } from './Context';
1010
import { getInjectedProvider } from './browserUtils';
1111
import { ErrorCode } from './types';
12-
import { Erc20TokenBalance, SecurityToken, SecurityTokenReservation } from './entities';
12+
import { Erc20TokenBalance, SecurityToken } from './entities';
1313
import { ReserveSecurityToken } from './procedures';
1414
import { PolymathError } from './PolymathError';
1515
import { PolymathBase } from './PolymathBase';
@@ -222,6 +222,17 @@ export class Polymath {
222222
return this.context.factories.securityTokenFactory.fetch(uid);
223223
};
224224

225+
/**
226+
* Check if a token symbol (ticker) is available for reservation
227+
*
228+
* @param symbol security token symbol for which to check availability
229+
*/
230+
public isSymbolAvailable = async (args: { symbol: string }) => {
231+
const { symbol } = args;
232+
233+
return this.context.contractWrappers.securityTokenRegistry.tickerAvailable({ ticker: symbol });
234+
};
235+
225236
/**
226237
* Check if a token follows the ERC20 standard
227238
*
@@ -263,9 +274,13 @@ export class Polymath {
263274

264275
/**
265276
* Get the current version of the Polymath Protocol
277+
*
278+
* @returns version string (i.e. 3.0.0)
266279
*/
267280
public getLatestProtocolVersion = async () => {
268-
await this.context.contractWrappers.securityTokenRegistry.getLatestProtocolVersion();
281+
const version = await this.context.contractWrappers.securityTokenRegistry.getLatestProtocolVersion();
282+
283+
return version.map(vNum => vNum.toNumber()).join('.');
269284
};
270285

271286
/**

src/procedures/TransferErc20.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,23 @@ export class TransferErc20 extends Procedure<TransferErc20ProcedureArgs> {
1616

1717
const ownerAddress = await currentWallet.address();
1818

19-
const { polyToken } = contractWrappers;
19+
const { polyToken, securityTokenRegistry } = contractWrappers;
2020

2121
let token;
2222

2323
if (tokenAddress) {
24+
const isSecurityToken = await securityTokenRegistry.isSecurityToken({
25+
securityTokenAddress: tokenAddress,
26+
});
27+
28+
if (isSecurityToken) {
29+
throw new PolymathError({
30+
code: ErrorCode.ProcedureValidationError,
31+
message:
32+
"This address belongs to a Security Token. To transfer Security Tokens, use the functions in the Security Token's transfers namespace",
33+
});
34+
}
35+
2436
try {
2537
token = await contractWrappers.getERC20TokenWrapper({ address: tokenAddress });
2638
} catch (err) {
@@ -58,7 +70,7 @@ export class TransferErc20 extends Procedure<TransferErc20ProcedureArgs> {
5870

5971
await this.addTransaction(token.transfer, {
6072
tag: PolyTransactionTag.TransferErc20,
61-
resolver: _receipt => {
73+
resolver: async _receipt => {
6274
return factories.erc20TokenBalanceFactory.refresh(
6375
Erc20TokenBalance.generateId({ tokenAddress: address, walletAddress: receiver })
6476
);

0 commit comments

Comments
 (0)