Skip to content

Commit 9062fdf

Browse files
authored
Merge pull request #587 from PolymathNetwork/CLI-bug-fix
Alternative symbol() ABI for ERC20 tokens
2 parents 6ff157b + be6264e commit 9062fdf

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

CLI/commands/dividends_manager.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,7 @@ async function manageExistingDividend(dividendIndex) {
240240
let dividendTokenSymbol = 'ETH';
241241
if (dividendsType === 'ERC20') {
242242
dividendTokenAddress = await currentDividendsModule.methods.dividendTokens(dividendIndex).call();
243-
let erc20token = new web3.eth.Contract(abis.erc20(), dividendTokenAddress);
244-
dividendTokenSymbol = await erc20token.methods.symbol().call();
243+
dividendTokenSymbol = await getERC20TokenSymbol(dividendTokenAddress);
245244
}
246245
let progress = await currentDividendsModule.methods.getDividendProgress(dividendIndex).call();
247246
let investorArray = progress[0];
@@ -387,10 +386,11 @@ async function createDividends() {
387386
limitMessage: "Must be a valid ERC20 address",
388387
defaultInput: polyToken.options.address
389388
});
390-
token = new web3.eth.Contract(abis.erc20(), dividendToken);
391-
try {
392-
dividendSymbol = await token.methods.symbol().call();
393-
} catch (err) {
389+
let erc20Symbol = await getERC20TokenSymbol(dividendToken);
390+
if (erc20Symbol != null) {
391+
token = new web3.eth.Contract(abis.erc20(), dividendToken);
392+
dividendSymbol = erc20Symbol;
393+
} else {
394394
console.log(chalk.red(`${dividendToken} is not a valid ERC20 token address!!`));
395395
}
396396
} while (dividendSymbol === 'ETH');
@@ -738,8 +738,7 @@ async function getDividends() {
738738
let tokenSymbol = 'ETH';
739739
if (dividendsType === 'ERC20') {
740740
let tokenAddress = await currentDividendsModule.methods.dividendTokens(i).call();
741-
let erc20token = new web3.eth.Contract(abis.erc20(), tokenAddress);
742-
tokenSymbol = await erc20token.methods.symbol().call();
741+
tokenSymbol = await getERC20TokenSymbol(tokenAddress);
743742
}
744743
dividends.push(
745744
new DividendData(
@@ -885,6 +884,22 @@ async function selectToken() {
885884
return result;
886885
}
887886

887+
async function getERC20TokenSymbol(tokenAddress) {
888+
let tokenSymbol = null;
889+
try {
890+
let erc20token = new web3.eth.Contract(abis.erc20(), tokenAddress);
891+
tokenSymbol = await erc20token.methods.symbol().call();
892+
} catch (err) {
893+
try {
894+
// Some ERC20 tokens use bytes32 for symbol instead of string
895+
let erc20token = new web3.eth.Contract(abis.alternativeErc20(), tokenAddress);
896+
tokenSymbol = web3.utils.hexToUtf8(await erc20token.methods.symbol().call());
897+
} catch (err) {
898+
}
899+
}
900+
return tokenSymbol;
901+
}
902+
888903
module.exports = {
889904
executeApp: async function (_tokenSymbol) {
890905
await initialize(_tokenSymbol);

CLI/commands/helpers/contract_abis.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,17 @@ module.exports = {
140140
},
141141
erc20: function () {
142142
return erc20ABI;
143+
},
144+
alternativeErc20: function () {
145+
let alternativeErc20 = [{
146+
"constant": true,
147+
"inputs": [],
148+
"name": "symbol",
149+
"outputs": [{ "name": "", "type": "bytes32" }],
150+
"payable": false,
151+
"stateMutability": "view",
152+
"type": "function"
153+
}];
154+
return alternativeErc20;
143155
}
144156
}

0 commit comments

Comments
 (0)