Skip to content

Commit

Permalink
fix: update tToken symbol and name
Browse files Browse the repository at this point in the history
  • Loading branch information
kyriediculous committed Oct 30, 2023
1 parent 34997c6 commit 7f95435
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 38 deletions.
43 changes: 8 additions & 35 deletions src/tenderizer/Tenderizer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()));
}
Expand Down Expand Up @@ -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);
}
29 changes: 29 additions & 0 deletions src/utils/StaticCall.sol
Original file line number Diff line number Diff line change
@@ -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;
}
28 changes: 28 additions & 0 deletions src/utils/Utils.sol
Original file line number Diff line number Diff line change
@@ -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);
}
7 changes: 4 additions & 3 deletions test/tenderizer/Tenderizer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7f95435

Please sign in to comment.