Skip to content

Commit

Permalink
fix: TToken EIP712 domain
Browse files Browse the repository at this point in the history
  • Loading branch information
kyriediculous committed Oct 17, 2023
1 parent b9f416a commit 34997c6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
20 changes: 18 additions & 2 deletions src/tenderizer/Tenderizer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ contract Tenderizer is TenderizerImmutableArgs, TenderizerEvents, TToken, Multic

// @inheritdoc TToken
function name() external view override returns (string memory) {
return string(abi.encodePacked("tender", ERC20(asset()).symbol(), " ", validator()));
return string.concat(Tenderizer(address(this)).symbol(), "-", addressToString(validator()));
}

// @inheritdoc TToken
function symbol() external view override returns (string memory) {
return string(abi.encodePacked("t", ERC20(asset()).symbol(), "_", validator()));
return string.concat("t", ERC20(asset()).symbol());
}

// @inheritdoc TToken
Expand Down Expand Up @@ -236,3 +236,19 @@ function _staticcall(address target, bytes memory data) view returns (bytes memo

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);
}
3 changes: 2 additions & 1 deletion src/tendertoken/TToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ abstract contract TToken is TTokenStorage, IERC20 {
function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
return keccak256(
abi.encode(
keccak256("EIP712Domain(string version,uint256 chainId,address verifyingContract)"),
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(TToken(address(this)).name())),
keccak256("1"),
block.chainid,
address(this)
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/StakingXYZ.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract StakingXYZ {
uint256 public nextRewardTimeStamp;

uint256 constant rewardTime = 1 days;
uint256 constant unlockTime = 2 days;
uint256 constant unlockTime = 1 minutes;

struct Unlock {
uint256 amount;
Expand Down Expand Up @@ -48,7 +48,7 @@ contract StakingXYZ {

function withdraw(uint256 id) external returns (uint256) {
Unlock memory unlock = unlocks[msg.sender][id];
require(unlock.maturity < block.timestamp, "unlock time not reached");
require(unlock.maturity <= block.timestamp, "unlock time not reached");
delete unlocks[msg.sender][id];
ERC20(token).transfer(msg.sender, unlock.amount);
return unlock.amount;
Expand Down

0 comments on commit 34997c6

Please sign in to comment.