File tree Expand file tree Collapse file tree 1 file changed +33
-1
lines changed
Expand file tree Collapse file tree 1 file changed +33
-1
lines changed Original file line number Diff line number Diff line change 33// (c) Gearbox Foundation, 2024.
44pragma solidity ^ 0.8.17 ;
55
6- contract TokenCompressor {}
6+ import {TokenInfo} from "../types/MarketData.sol " ;
7+ import {IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol " ;
8+ import {LibString} from "@solady/utils/LibString.sol " ;
9+
10+ contract TokenCompressor {
11+ function getTokenInfo (address token ) public view returns (TokenInfo memory result ) {
12+ result.token = token;
13+ result.decimals = IERC20Metadata (token).decimals ();
14+
15+ // Fallback to low-level call to handle bytes32 symbol
16+ (bool success , bytes memory data ) = token.staticcall (abi.encodeWithSignature ("symbol() " ));
17+ if (success) {
18+ if (data.length == 32 ) {
19+ result.symbol = LibString.fromSmallString (bytes32 (data));
20+ } else {
21+ result.symbol = abi.decode (data, (string ));
22+ }
23+ } else {
24+ revert ("symbol retrieval failed " );
25+ }
26+
27+ (success, data) = token.staticcall (abi.encodeWithSignature ("name() " ));
28+ if (success) {
29+ if (data.length == 32 ) {
30+ result.name = LibString.fromSmallString (bytes32 (data));
31+ } else {
32+ result.name = abi.decode (data, (string ));
33+ }
34+ } else {
35+ revert ("name retrieval failed " );
36+ }
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments