From 7f95435e1c860be889313cdaa621516f242c9985 Mon Sep 17 00:00:00 2001 From: kyriediculous Date: Mon, 30 Oct 2023 16:52:58 +0100 Subject: [PATCH] fix: update tToken symbol and name --- src/tenderizer/Tenderizer.sol | 43 ++++++-------------------------- src/utils/StaticCall.sol | 29 +++++++++++++++++++++ src/utils/Utils.sol | 28 +++++++++++++++++++++ test/tenderizer/Tenderizer.t.sol | 7 +++--- 4 files changed, 69 insertions(+), 38 deletions(-) create mode 100644 src/utils/StaticCall.sol create mode 100644 src/utils/Utils.sol diff --git a/src/tenderizer/Tenderizer.sol b/src/tenderizer/Tenderizer.sol index 31277c1..a30ca97 100644 --- a/src/tenderizer/Tenderizer.sol +++ b/src/tenderizer/Tenderizer.sol @@ -21,6 +21,8 @@ import { TenderizerImmutableArgs, TenderizerEvents } from "core/tenderizer/Tende import { TToken } from "core/tendertoken/TToken.sol"; import { Multicall } from "core/utils/Multicall.sol"; import { SelfPermit } from "core/utils/SelfPermit.sol"; +import { _staticcall } from "core/utils/StaticCall.sol"; +import { addressToString } from "core/utils/Utils.sol"; /** * @title Tenderizer @@ -43,12 +45,12 @@ contract Tenderizer is TenderizerImmutableArgs, TenderizerEvents, TToken, Multic // @inheritdoc TToken function name() external view override returns (string memory) { - return string.concat(Tenderizer(address(this)).symbol(), "-", addressToString(validator())); + return string.concat("tender ", _baseSymbol()); } // @inheritdoc TToken function symbol() external view override returns (string memory) { - return string.concat("t", ERC20(asset()).symbol()); + return string.concat("t", _baseSymbol()); } // @inheritdoc TToken @@ -168,6 +170,10 @@ contract Tenderizer is TenderizerImmutableArgs, TenderizerEvents, TToken, Multic fees = rewards * fee / FEE_BASE; } + function _baseSymbol() internal view returns (string memory) { + return string.concat(ERC20(asset()).symbol(), "-", addressToString(validator())); + } + function _adapter() internal view returns (Adapter) { return Adapter(_registry().adapter(asset())); } @@ -219,36 +225,3 @@ contract Tenderizer is TenderizerImmutableArgs, TenderizerEvents, TToken, Multic withdrawAmount = abi.decode(_adapter()._delegatecall(abi.encodeCall(_adapter().withdraw, (validator, unlockID))), (uint256)); } } - -error StaticCallFailed(address to, bytes data, string message); - -function _staticcall(address target, bytes memory data) view returns (bytes memory) { - // solhint-disable-next-line avoid-low-level-calls - (bool success, bytes memory returnData) = address(target).staticcall(data); - - if (!success) { - if (returnData.length < 68) revert StaticCallFailed(address(target), data, ""); - assembly { - returnData := add(returnData, 0x04) - } - revert StaticCallFailed(address(target), data, abi.decode(returnData, (string))); - } - - return returnData; -} - -function addressToString(address _addr) pure returns (string memory) { - bytes32 value = bytes32(uint256(uint160(_addr))); - bytes memory alphabet = "0123456789abcdef"; - - bytes memory str = new bytes(42); - str[0] = "0"; - str[1] = "x"; - - for (uint256 i = 0; i < 20; i++) { - str[2 + i * 2] = alphabet[uint8(value[i + 12] >> 4)]; - str[3 + i * 2] = alphabet[uint8(value[i + 12] & 0x0f)]; - } - - return string(str); -} diff --git a/src/utils/StaticCall.sol b/src/utils/StaticCall.sol new file mode 100644 index 0000000..b8a9240 --- /dev/null +++ b/src/utils/StaticCall.sol @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: MIT +// +// _____ _ _ +// |_ _| | | (_) +// | | ___ _ __ __| | ___ _ __ _ _______ +// | |/ _ \ '_ \ / _` |/ _ \ '__| |_ / _ \ +// | | __/ | | | (_| | __/ | | |/ / __/ +// \_/\___|_| |_|\__,_|\___|_| |_/___\___| +// +// Copyright (c) Tenderize Labs Ltd + +pragma solidity >=0.8.19; + +error StaticCallFailed(address to, bytes data, string message); + +function _staticcall(address target, bytes memory data) view returns (bytes memory) { + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returnData) = address(target).staticcall(data); + + if (!success) { + if (returnData.length < 68) revert StaticCallFailed(address(target), data, ""); + assembly { + returnData := add(returnData, 0x04) + } + revert StaticCallFailed(address(target), data, abi.decode(returnData, (string))); + } + + return returnData; +} diff --git a/src/utils/Utils.sol b/src/utils/Utils.sol new file mode 100644 index 0000000..8952e80 --- /dev/null +++ b/src/utils/Utils.sol @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: MIT +// +// _____ _ _ +// |_ _| | | (_) +// | | ___ _ __ __| | ___ _ __ _ _______ +// | |/ _ \ '_ \ / _` |/ _ \ '__| |_ / _ \ +// | | __/ | | | (_| | __/ | | |/ / __/ +// \_/\___|_| |_|\__,_|\___|_| |_/___\___| +// +// Copyright (c) Tenderize Labs Ltd + +pragma solidity >=0.8.19; + +function addressToString(address _addr) pure returns (string memory) { + bytes32 value = bytes32(uint256(uint160(_addr))); + bytes memory alphabet = "0123456789abcdef"; + + bytes memory str = new bytes(42); + str[0] = "0"; + str[1] = "x"; + + for (uint256 i = 0; i < 20; i++) { + str[2 + i * 2] = alphabet[uint8(value[i + 12] >> 4)]; + str[3 + i * 2] = alphabet[uint8(value[i + 12] & 0x0f)]; + } + + return string(str); +} diff --git a/test/tenderizer/Tenderizer.t.sol b/test/tenderizer/Tenderizer.t.sol index 8cbd3c7..bf6a436 100644 --- a/test/tenderizer/Tenderizer.t.sol +++ b/test/tenderizer/Tenderizer.t.sol @@ -18,11 +18,12 @@ import { IERC20, IERC20Metadata } from "core/interfaces/IERC20.sol"; import { Adapter, TenderizerHarness } from "test/tenderizer/Tenderizer.harness.sol"; import { AdapterDelegateCall } from "core/adapters/Adapter.sol"; import { TenderizerEvents } from "core/tenderizer/TenderizerBase.sol"; -import { StaticCallFailed } from "core/tenderizer/Tenderizer.sol"; +import { StaticCallFailed } from "core/utils/StaticCall.sol"; import { TToken } from "core/tendertoken/TToken.sol"; import { Unlocks } from "core/unlocks/Unlocks.sol"; import { Registry } from "core/registry/Registry.sol"; import { ClonesWithImmutableArgs } from "clones/ClonesWithImmutableArgs.sol"; +import { addressToString } from "core/utils/Utils.sol"; contract TenderizerSetup is Test, TestHelpers { using ClonesWithImmutableArgs for address; @@ -65,12 +66,12 @@ contract TenderizerSetup is Test, TestHelpers { contract TenderizerTest is TenderizerSetup, TenderizerEvents { function test_Name() public { vm.expectCall(asset, abi.encodeCall(IERC20Metadata.symbol, ())); - assertEq(tenderizer.name(), string(abi.encodePacked("tender", symbol, " ", validator)), "invalid name"); + assertEq(tenderizer.name(), string.concat("tender ", symbol, "-", addressToString(validator)), "invalid name"); } function test_Symbol() public { vm.expectCall(asset, abi.encodeCall(IERC20Metadata.symbol, ())); - assertEq(tenderizer.symbol(), string(abi.encodePacked("t", symbol, "_", validator)), "invalid symbol"); + assertEq(tenderizer.symbol(), string.concat("t", symbol, "-", addressToString(validator)), "invalid name"); } function test_InitialVaules() public {