dsa-resolvers-deprecated/contracts/protocols/mainnet/erc20.sol

96 lines
3.1 KiB
Solidity
Raw Normal View History

2021-03-17 14:02:06 +00:00
pragma solidity ^0.6.10;
pragma experimental ABIEncoderV2;
2020-04-10 17:40:02 +00:00
interface TokenInterface {
function balanceOf(address) external view returns (uint);
2020-06-25 14:29:53 +00:00
function allowance(address owner, address spender) external view returns (uint256);
2021-03-17 14:02:06 +00:00
function decimals() external view returns (uint);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
}
2020-04-10 17:40:02 +00:00
2020-06-25 15:28:53 +00:00
contract Resolver {
2021-03-17 14:02:06 +00:00
struct TokenData {
bool isToken;
string name;
string symbol;
uint256 decimals;
}
function getTokenDetails(address[] memory tknAddress) public view returns (TokenData[] memory) {
TokenData[] memory tokenDatas = new TokenData[](tknAddress.length);
for (uint i = 0; i < tknAddress.length; i++) {
if (tknAddress[i] == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) {
tokenDatas[i] = TokenData(
true,
"ETHER",
"ETH",
18
);
} else {
TokenInterface token = TokenInterface(tknAddress[i]);
2021-04-05 20:14:57 +00:00
bool isToken = true;
try token.symbol() {
} catch {
isToken = false;
continue;
}
2021-03-17 14:02:06 +00:00
try token.name() {
2021-04-05 20:14:57 +00:00
} catch {
isToken = false;
continue;
}
try token.decimals() {
} catch {
isToken = false;
continue;
}
tokenDatas[i] = TokenData(
2021-03-17 14:02:06 +00:00
true,
token.name(),
token.symbol(),
token.decimals()
2021-04-05 20:14:57 +00:00
);
2021-03-17 14:02:06 +00:00
}
}
return tokenDatas;
}
2020-06-25 15:28:53 +00:00
2020-04-10 17:40:02 +00:00
function getBalances(address owner, address[] memory tknAddress) public view returns (uint[] memory) {
uint[] memory tokensBal = new uint[](tknAddress.length);
for (uint i = 0; i < tknAddress.length; i++) {
if (tknAddress[i] == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) {
tokensBal[i] = owner.balance;
} else {
TokenInterface token = TokenInterface(tknAddress[i]);
tokensBal[i] = token.balanceOf(owner);
}
}
return tokensBal;
}
2020-06-25 14:29:53 +00:00
2020-06-25 14:30:36 +00:00
function getAllowances(address owner, address spender, address[] memory tknAddress) public view returns (uint[] memory) {
2020-06-25 14:29:53 +00:00
uint[] memory tokenAllowances = new uint[](tknAddress.length);
for (uint i = 0; i < tknAddress.length; i++) {
if (tknAddress[i] == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) {
2020-06-25 15:28:53 +00:00
tokenAllowances[i] = 0;
2020-06-25 14:29:53 +00:00
} else {
TokenInterface token = TokenInterface(tknAddress[i]);
tokenAllowances[i] = token.allowance(owner, spender);
}
}
return tokenAllowances;
}
2020-06-25 15:28:53 +00:00
}
contract InstaERC20Resolver is Resolver {
2021-04-05 20:14:57 +00:00
string public constant name = "ERC20-Resolver-v1.1";
2020-06-25 15:28:53 +00:00
2020-04-10 17:40:02 +00:00
}