diff --git a/contracts/staking/token/LimitedTokenPool.sol b/contracts/staking/token/LimitedTokenPool.sol index 9ae559f..2ad0fde 100644 --- a/contracts/staking/token/LimitedTokenPool.sol +++ b/contracts/staking/token/LimitedTokenPool.sol @@ -56,11 +56,11 @@ contract LimitedTokenPool is Initializable, AccessControl, IOnBlockListener { LockKeeper public lockKeeper; RewardsBank public rewardsBank; - MainConfig public mainConfig; - LimitsConfig public limitsConfig; + MainConfig public mainConfig; // immutable + LimitsConfig public limitsConfig; // mutable Info public info; - mapping(address => Staker) public stakers; + mapping(address => Staker) private stakers; //EVENTS @@ -247,8 +247,12 @@ contract LimitedTokenPool is Initializable, AccessControl, IOnBlockListener { return mainConfig.name; } - function getStaker(address user) public view returns (Staker memory) { - return stakers[user]; + function getStake(address user) public view returns (uint) { + return stakers[user].stake; + } + + function getDeposit(address user) public view returns (uint) { + return stakers[user].deposit; } function getUserRewards(address user) public view returns (uint) { diff --git a/contracts/staking/token/TokenPool.sol b/contracts/staking/token/TokenPool.sol index 3d0c987..3e987bd 100644 --- a/contracts/staking/token/TokenPool.sol +++ b/contracts/staking/token/TokenPool.sol @@ -49,7 +49,7 @@ contract TokenPool is Initializable, AccessControl, IOnBlockListener { LimitsConfig public limitsConfig; // mutable Info public info; - mapping(address => Staker) public stakers; + mapping(address => Staker) private stakers; //EVENTS @@ -63,7 +63,6 @@ contract TokenPool is Initializable, AccessControl, IOnBlockListener { event UnstakeFast(address indexed user, uint amount, uint penalty); function initialize(RewardsBank bank_, LockKeeper keeper_, MainConfig calldata mainConfig_, LimitsConfig calldata limitsConfig_) public initializer { - //TODO: Should validate input params rewardsBank = bank_; lockKeeper = keeper_; mainConfig = mainConfig_; @@ -123,7 +122,7 @@ contract TokenPool is Initializable, AccessControl, IOnBlockListener { // lock funds stakers[msg.sender].lockedWithdrawal = lockKeeper.lockSingle( msg.sender, address(mainConfig.token), uint64(block.timestamp + limitsConfig.lockPeriod), amount + canceledAmount, - string(abi.encodePacked("TokenStaking unstake: ", _addressToString(address(mainConfig.token)))) + string(abi.encodePacked("TokenStaking unstake")) ); _claimRewards(msg.sender); @@ -157,18 +156,6 @@ contract TokenPool is Initializable, AccessControl, IOnBlockListener { // VIEW METHODS - function getMainConfig() public view returns (MainConfig memory) { - return mainConfig; - } - - function getLimitsConfig() public view returns (LimitsConfig memory) { - return limitsConfig; - } - - function getInfo() public view returns (Info memory) { - return info; - } - function getStake(address user) public view returns (uint) { return stakers[user].stake; } @@ -245,21 +232,4 @@ contract TokenPool is Initializable, AccessControl, IOnBlockListener { if (info.totalStake == 0 && info.totalRewards == 0) return amount; return amount * info.totalRewards /info.totalStake; } - - function _addressToString(address x) internal pure returns (string memory) { - bytes memory s = new bytes(40); - for (uint i = 0; i < 20; i++) { - uint8 b = uint8(uint(uint160(x)) / (2 ** (8 * (19 - i)))); - uint8 hi = (b / 16); - uint8 lo = (b - 16 * hi); - s[2 * i] = _char(hi); - s[2 * i + 1] = _char(lo); - } - return string(s); - } - - function _char(uint8 b) internal pure returns (bytes1 c) { - return bytes1(b + (b < 10 ? 0x30 : 0x57)); - } - } diff --git a/test/staking/token/LimitedTokenPool.ts b/test/staking/token/LimitedTokenPool.ts index 99fef78..5b3a43b 100644 --- a/test/staking/token/LimitedTokenPool.ts +++ b/test/staking/token/LimitedTokenPool.ts @@ -123,8 +123,8 @@ describe("LimitedTokenPool", function () { const info = await limitedPool.info(); expect(info.totalDeposit).to.equal(depositAmount); - const staker = await limitedPool.getStaker(owner.address); - expect(staker.deposit).to.equal(depositAmount); + const deposit = await limitedPool.getDeposit(owner.address); + expect(deposit).to.equal(depositAmount); }); it("Should not allow deposit below minimum", async function () { @@ -147,8 +147,8 @@ describe("LimitedTokenPool", function () { const info = await limitedPool.info(); expect(info.totalDeposit).to.equal(ethers.utils.parseEther("500")); - const staker = await limitedPool.getStaker(owner.address); - expect(staker.deposit).to.equal(ethers.utils.parseEther("500")); + const deposit = await limitedPool.getDeposit(owner.address); + expect(deposit).to.equal(ethers.utils.parseEther("500")); }); it("Should not allow withdrawal more than deposited", async function () { @@ -176,8 +176,8 @@ describe("LimitedTokenPool", function () { const info = await limitedPool.info(); expect(info.totalStake).to.equal(stakeAmount); - const staker = await limitedPool.getStaker(owner.address); - expect(staker.stake).to.equal(stakeAmount); + const stake = await limitedPool.getStake(owner.address); + expect(stake).to.equal(stakeAmount); }); it("Should not allow staking below minimum", async function () { @@ -218,8 +218,8 @@ describe("LimitedTokenPool", function () { const info = await limitedPool.info(); expect(info.totalStake).to.equal(0); - const staker = await limitedPool.getStaker(owner.address); - expect(staker.stake).to.equal(0); + const stake = await limitedPool.getStake(owner.address); + expect(stake).to.equal(0); }); it("Should not allow unstaking more than staked", async function () { @@ -311,9 +311,10 @@ describe("LimitedTokenPool", function () { expect(info.totalDeposit).to.equal(depositAmount.mul(2)); expect(info.totalStake).to.equal(stakeAmount.mul(2)); - const staker = await limitedPool.getStaker(owner.address); - expect(staker.deposit).to.equal(depositAmount.mul(2)); - expect(staker.stake).to.equal(stakeAmount.mul(2)); + const deposit = await limitedPool.getDeposit(owner.address); + const stake = await limitedPool.getStake(owner.address); + expect(deposit).to.equal(depositAmount.mul(2)); + expect(stake).to.equal(stakeAmount.mul(2)); }); it("Should handle rewards correctly after multiple stakes and unstakes", async function () { @@ -399,13 +400,15 @@ describe("LimitedTokenPool", function () { await limitedPool.connect(user1).stake(ethers.utils.parseEther("200")); await limitedPool.connect(user2).stake(ethers.utils.parseEther("100")); - const infoUser1 = await limitedPool.getStaker(user1.address); - const infoUser2 = await limitedPool.getStaker(user2.address); + const depositUser1 = await limitedPool.getDeposit(user1.address); + const stakeUser1 = await limitedPool.getStake(user1.address); + const depositUser2 = await limitedPool.getDeposit(user2.address); + const stakeUser2 = await limitedPool.getStake(user2.address); - expect(infoUser1.deposit).to.equal(ethers.utils.parseEther("500")); - expect(infoUser1.stake).to.equal(ethers.utils.parseEther("200")); - expect(infoUser2.deposit).to.equal(ethers.utils.parseEther("300")); - expect(infoUser2.stake).to.equal(ethers.utils.parseEther("100")); + expect(depositUser1).to.equal(ethers.utils.parseEther("500")); + expect(stakeUser1).to.equal(ethers.utils.parseEther("200")); + expect(depositUser2).to.equal(ethers.utils.parseEther("300")); + expect(stakeUser2).to.equal(ethers.utils.parseEther("100")); const poolInfo = await limitedPool.info(); expect(poolInfo.totalDeposit).to.equal(ethers.utils.parseEther("800"));