Skip to content

Commit f461def

Browse files
Tests WIP
1 parent d6a5d7c commit f461def

File tree

3 files changed

+44
-29
lines changed

3 files changed

+44
-29
lines changed

contracts/staking/token/SingleSidePool.sol

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ contract SingleSidePool is Initializable, AccessControl, IOnBlockListener {
1515

1616
struct Config {
1717
IERC20 token;
18-
RewardsBank rewardsBank;
19-
LockKeeper lockKeeper;
2018
string name;
2119
address rewardToken;
2220
uint rewardTokenPrice; // The coefficient to calculate the reward token amount
@@ -42,6 +40,8 @@ contract SingleSidePool is Initializable, AccessControl, IOnBlockListener {
4240
}
4341

4442
bool public active;
43+
RewardsBank rewardsBank;
44+
LockKeeper lockKeeper;
4545

4646
Config public config;
4747
Info public info;
@@ -63,7 +63,9 @@ contract SingleSidePool is Initializable, AccessControl, IOnBlockListener {
6363
event UnstakeLocked(address indexed user, uint amount, uint unlockTime, uint creationTime);
6464
event UnstakeFast(address indexed user, uint amount, uint penalty);
6565

66-
function initialize(Config calldata config_) public initializer {
66+
function initialize(RewardsBank bank_, LockKeeper keeper_, Config calldata config_) public initializer {
67+
rewardsBank = bank_;
68+
lockKeeper = keeper_;
6769
config = config_;
6870

6971
info.lastInterestUpdate = block.timestamp;
@@ -133,13 +135,13 @@ contract SingleSidePool is Initializable, AccessControl, IOnBlockListener {
133135

134136
// cancel previous lock (if exists). canceledAmount will be added to new lock
135137
uint canceledAmount;
136-
if (config.lockKeeper.getLock(stakers[msg.sender].lockedWithdrawal).totalClaims > 0) // prev lock exists
137-
canceledAmount = config.lockKeeper.cancelLock(stakers[msg.sender].lockedWithdrawal);
138+
if (lockKeeper.getLock(stakers[msg.sender].lockedWithdrawal).totalClaims > 0) // prev lock exists
139+
canceledAmount = lockKeeper.cancelLock(stakers[msg.sender].lockedWithdrawal);
138140

139-
config.token.approve(address(config.lockKeeper), amount + canceledAmount);
141+
config.token.approve(address(lockKeeper), amount + canceledAmount);
140142

141143
// lock funds
142-
stakers[msg.sender].lockedWithdrawal = config.lockKeeper.lockSingle(
144+
stakers[msg.sender].lockedWithdrawal = lockKeeper.lockSingle(
143145
msg.sender, address(config.token), uint64(block.timestamp + config.lockPeriod), amount + canceledAmount,
144146
string(abi.encodePacked("TokenStaking unstake: ", _addressToString(address(config.token))))
145147
);
@@ -252,7 +254,7 @@ contract SingleSidePool is Initializable, AccessControl, IOnBlockListener {
252254
stakers[user].claimableRewards = 0;
253255

254256
uint rewardTokenAmount = amount * config.rewardTokenPrice;
255-
config.rewardsBank.withdrawErc20(config.rewardToken, payable(user), rewardTokenAmount);
257+
rewardsBank.withdrawErc20(config.rewardToken, payable(user), rewardTokenAmount);
256258
emit Claim(user, rewardTokenAmount);
257259
}
258260

contracts/staking/token/TokenPoolsManager.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ contract TokenPoolsManager is AccessControl{
4141
function createSingleSidePool(SingleSidePool.Config calldata params) public onlyRole(DEFAULT_ADMIN_ROLE) returns (address) {
4242
console.log("Entered createPool");
4343
bytes memory data = abi.encodeWithSignature(
44-
"initialize((address,address,address,string,address,uint256,uint256,uint256,uint256,uint256,uint256))",
45-
params);
44+
"initialize(address,address,(address,string,address,uint256,uint256,uint256,uint256,uint256,uint256))",
45+
bank, lockKeeper, params);
4646
address pool = address(new BeaconProxy(address(singleSideBeacon), data));
4747
console.log("Pool created at address: %s", pool);
4848
pools[params.name] = pool;

test/staking/token/TokenPoolsManager.ts

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import {
66
TokenPoolsManager,
77
RewardsBank,
88
AirBond__factory,
9+
SingleSidePool,
910
RewardsBank__factory,
1011
TokenPoolsManager__factory,
1112
LockKeeper__factory,
13+
LockKeeper,
1214
} from "../../../typechain-types";
1315

1416
import SignleSidePoolJson from "../../../artifacts/contracts/staking/token/SingleSidePool.sol/SingleSidePool.json";
@@ -20,6 +22,7 @@ describe("PoolsManager", function () {
2022
let rewardsBank: RewardsBank;
2123
let tokenAddr: string;
2224
let owner: SignerWithAddress;
25+
let lockKeeper: LockKeeper;
2326

2427
async function deploy() {
2528
const [owner] = await ethers.getSigners();
@@ -41,24 +44,29 @@ describe("PoolsManager", function () {
4144
await (await rewardsBank.grantRole(await rewardsBank.DEFAULT_ADMIN_ROLE(), poolsManager.address)).wait();
4245
const tokenAddr = airBond.address;
4346

44-
return { poolsManager, rewardsBank, tokenAddr, owner };
47+
return { poolsManager, rewardsBank, lockKeeper, tokenAddr, owner };
4548
}
4649

4750
beforeEach(async function () {
48-
({ poolsManager, rewardsBank, tokenAddr, owner } = await loadFixture(deploy));
51+
({ poolsManager, rewardsBank, lockKeeper, tokenAddr, owner } = await loadFixture(deploy));
4952
});
5053

51-
describe("Pool Management", function () {
52-
it("Should allow the owner to create a pool", async function () {
53-
const minStakeValue = 10;
54-
const fastUnstakePenalty = 100000; // 10%
55-
const interest = 100000; // 10%
56-
const interestRate = 24 * 60 * 60; // 24 hours
57-
const lockPeriod = 24 * 60 * 60; // 24 hours
58-
const rewardsTokenPrice = 1;
54+
describe("SingleSidePool Management", function () {
55+
it("Should allow the owner to create a single side pool", async function () {
56+
const singleSidePoolConfig: SingleSidePool.ConfigStruct = {
57+
token: tokenAddr,
58+
name: "TestPool",
59+
minStakeValue: 10,
60+
rewardToken: tokenAddr,
61+
rewardTokenPrice: 1,
62+
fastUnstakePenalty: 100000, // 10%
63+
interest: 100000, // 10%
64+
interestRate: 24 * 60 * 60, // 24 hours
65+
lockPeriod: 24 * 60 * 60, // 24 hours
66+
};
5967

6068
console.log("before createPool");
61-
const tx = await poolsManager.createPool(tokenAddr, "TestProxy", minStakeValue, fastUnstakePenalty, interest, interestRate, lockPeriod, tokenAddr, rewardsTokenPrice);
69+
const tx = await poolsManager.createSingleSidePool(singleSidePoolConfig);
6270
const receipt = await tx.wait();
6371
console.log("Receipt: ", receipt);
6472
const poolAddress = receipt.events![4].args![1];
@@ -67,14 +75,19 @@ describe("PoolsManager", function () {
6775
});
6876

6977
it("Should activate and deactivate a pool", async function () {
70-
const minStakeValue = 10;
71-
const fastUnstakePenalty = 100000; // 10%
72-
const interest = 100000; // 10%
73-
const interestRate = 24 * 60 * 60; // 24 hours
74-
const lockPeriod = 24 * 60 * 60; // 24 hours
75-
const rewardsTokenPrice = 1;
76-
77-
await poolsManager.createPool(tokenAddr, "TestProxy", minStakeValue, fastUnstakePenalty, interest, interestRate, lockPeriod, tokenAddr, rewardsTokenPrice);
78+
const singleSidePoolConfig: SingleSidePool.ConfigStruct = {
79+
token: tokenAddr,
80+
name: "TestPool",
81+
minStakeValue: 10,
82+
rewardToken: tokenAddr,
83+
rewardTokenPrice: 1,
84+
fastUnstakePenalty: 100000, // 10%
85+
interest: 100000, // 10%
86+
interestRate: 24 * 60 * 60, // 24 hours
87+
lockPeriod: 24 * 60 * 60, // 24 hours
88+
};
89+
90+
await poolsManager.createSingleSidePool(tokenAddr, "TestProxy", minStakeValue, fastUnstakePenalty, interest, interestRate, lockPeriod, tokenAddr, rewardsTokenPrice);
7891
const poolAddress = await poolsManager.getPoolAddress("TestProxy");
7992
console.log("Pool Address: ", poolAddress);
8093

0 commit comments

Comments
 (0)