Skip to content

Commit

Permalink
prettier formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tjcloa committed Jun 15, 2021
1 parent 525f1f1 commit 9af5992
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 101 deletions.
14 changes: 8 additions & 6 deletions contracts/farm/LiquidityMining.sol
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,12 @@ contract LiquidityMining is LiquidityMiningStorage {
* @param _user the address of user, tokens will be deposited to it
* @param alreadyTransferred true if the pool tokens have already been transferred
*/
function _deposit(address _poolToken, uint256 _amount, address _user, bool alreadyTransferred) internal{
function _deposit(
address _poolToken,
uint256 _amount,
address _user,
bool alreadyTransferred
) internal {
require(poolIdList[_poolToken] != 0, "Pool token not found");
address userAddress = _user != address(0) ? _user : msg.sender;

Expand All @@ -371,8 +376,7 @@ contract LiquidityMining is LiquidityMiningStorage {

if (_amount > 0) {
//receives pool tokens from msg.sender, it can be user or WrapperProxy contract
if(!alreadyTransferred)
pool.poolToken.safeTransferFrom(address(msg.sender), address(this), _amount);
if (!alreadyTransferred) pool.poolToken.safeTransferFrom(address(msg.sender), address(this), _amount);
user.amount = user.amount.add(_amount);
}
_updateRewardDebt(pool, user);
Expand Down Expand Up @@ -605,10 +609,8 @@ contract LiquidityMining is LiquidityMiningStorage {
* @param _poolToken the address of pool token
* @param _user the address of the user
*/
function getUserPoolTokenBalance(address _poolToken, address _user) external view returns (uint256){
function getUserPoolTokenBalance(address _poolToken, address _user) external view returns (uint256) {
UserInfo memory ui = getUserInfo(_poolToken, _user);
return ui.amount;
}


}
58 changes: 28 additions & 30 deletions contracts/farm/LiquidityMiningConfigToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,31 @@ import "../openzeppelin/IERC20_.sol";
* @dev We need this token for having a flexibility with LiquidityMining configuration
*/
contract LiquidityMiningConfigToken is IERC20_ {

function totalSupply() external view returns (uint256) {
return 0;
}

function balanceOf(address account) external view returns (uint256) {
return 0;
}

function transfer(address recipient, uint256 amount) external returns (bool) {
return false;
}

function allowance(address owner, address spender) external view returns (uint256) {
return 0;
}

function approve(address spender, uint256 amount) external returns (bool) {
return false;
}

function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool) {
return false;
}

}
function totalSupply() external view returns (uint256) {
return 0;
}

function balanceOf(address account) external view returns (uint256) {
return 0;
}

function transfer(address recipient, uint256 amount) external returns (bool) {
return false;
}

function allowance(address owner, address spender) external view returns (uint256) {
return 0;
}

function approve(address spender, uint256 amount) external returns (bool) {
return false;
}

function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool) {
return false;
}
}
2 changes: 1 addition & 1 deletion contracts/modules/Affiliates.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ contract Affiliates is State, AffiliatesEvents {
SetAffiliatesReferrerResult memory result;

result.userNotFirstTradeFlag = getUserNotFirstTradeFlag(user);
result.alreadySet = affiliatesUserReferrer[user] != address(0);
result.alreadySet = affiliatesUserReferrer[user] != address(0);
result.success = !(result.userNotFirstTradeFlag || result.alreadySet || user == referrer);
if (result.success) {
affiliatesUserReferrer[user] = referrer;
Expand Down
68 changes: 33 additions & 35 deletions contracts/utils/AdminRole.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,36 @@ pragma solidity 0.5.17;
import "../openzeppelin/Ownable.sol";

contract AdminRole is Ownable {

/// @dev user => flag whether user has admin role.
mapping(address => bool) public admins;

event AdminAdded(address admin);
event AdminRemoved(address admin);

/**
* @dev Throws if called by any account other than the owner or admin.
* or on our own overriding sovrynOwnable.
*/
modifier onlyAuthorized() {
require(isOwner() || admins[msg.sender], "unauthorized");
_;
}

/**
* @notice Add account to ACL.
* @param _admin The addresses of the account to grant permissions.
* */
function addAdmin(address _admin) public onlyOwner {
admins[_admin] = true;
emit AdminAdded(_admin);
}

/**
* @notice Remove account from ACL.
* @param _admin The addresses of the account to revoke permissions.
* */
function removeAdmin(address _admin) public onlyOwner {
admins[_admin] = false;
emit AdminRemoved(_admin);
}

}
/// @dev user => flag whether user has admin role.
mapping(address => bool) public admins;

event AdminAdded(address admin);
event AdminRemoved(address admin);

/**
* @dev Throws if called by any account other than the owner or admin.
* or on our own overriding sovrynOwnable.
*/
modifier onlyAuthorized() {
require(isOwner() || admins[msg.sender], "unauthorized");
_;
}

/**
* @notice Add account to ACL.
* @param _admin The addresses of the account to grant permissions.
* */
function addAdmin(address _admin) public onlyOwner {
admins[_admin] = true;
emit AdminAdded(_admin);
}

/**
* @notice Remove account from ACL.
* @param _admin The addresses of the account to revoke permissions.
* */
function removeAdmin(address _admin) public onlyOwner {
admins[_admin] = false;
emit AdminRemoved(_admin);
}
}
4 changes: 1 addition & 3 deletions tests-js/affiliates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ contract("Affiliates", (accounts) => {

// Creating the instance of newLockedSOV Contract.
await sovryn.setLockedSOVAddress(
(
await LockedSOV.new(tokenSOV.address, vestingRegistry.address, cliff, duration, [owner])
).address
(await LockedSOV.new(tokenSOV.address, vestingRegistry.address, cliff, duration, [owner])).address
);
lockedSOV = await LockedSOV.at(await sovryn.lockedSOVAddress());
});
Expand Down
4 changes: 1 addition & 3 deletions tests-js/affiliates_integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ contract("Affiliates", (accounts) => {

// Creating the instance of newLockedSOV Contract.
await sovryn.setLockedSOVAddress(
(
await LockedSOV.new(tokenSOV.address, vestingRegistry.address, cliff, duration, [owner])
).address
(await LockedSOV.new(tokenSOV.address, vestingRegistry.address, cliff, duration, [owner])).address
);
lockedSOV = await LockedSOV.at(await sovryn.lockedSOVAddress());
});
Expand Down
41 changes: 24 additions & 17 deletions tests-js/farm/LiquidityMining.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ describe("LiquidityMining", () => {
});

it("fails if unlockedImmediatelyPercent >= 10000", async () => {
await expectRevert(liquidityMining.setUnlockedImmediatelyPercent(100000), "Unlocked immediately percent has to be less than 10000.");
await expectRevert(
liquidityMining.setUnlockedImmediatelyPercent(100000),
"Unlocked immediately percent has to be less than 10000."
);
});
});

Expand Down Expand Up @@ -389,10 +392,10 @@ describe("LiquidityMining", () => {
});

it("only owner or admin should be able to add pool token", async () => {
await expectRevert(liquidityMining.add(token2.address, new BN(1), false, {from: account1}), "unauthorized");
await expectRevert(liquidityMining.add(token2.address, new BN(1), false, { from: account1 }), "unauthorized");

await liquidityMining.addAdmin(account1);
await liquidityMining.add(token2.address, new BN(1), false, {from: account1});
await liquidityMining.add(token2.address, new BN(1), false, { from: account1 });
});
});

Expand Down Expand Up @@ -441,10 +444,10 @@ describe("LiquidityMining", () => {

it("only owner or admin should be able to update pool token", async () => {
await liquidityMining.add(token2.address, new BN(1), false);
await expectRevert(liquidityMining.update(token2.address, new BN(1), false, {from: account1}), "unauthorized");
await expectRevert(liquidityMining.update(token2.address, new BN(1), false, { from: account1 }), "unauthorized");

await liquidityMining.addAdmin(account1);
await liquidityMining.update(token2.address, new BN(1), false, {from: account1});
await liquidityMining.update(token2.address, new BN(1), false, { from: account1 });
});
});

Expand Down Expand Up @@ -700,7 +703,7 @@ describe("LiquidityMining", () => {
user: account1,
poolToken: token1.address,
amount: amount,
accumulatedReward: expectedAccumulatedReward
accumulatedReward: expectedAccumulatedReward,
});
});

Expand Down Expand Up @@ -1291,19 +1294,19 @@ describe("LiquidityMining", () => {
//Maximum reward per week: 100K SOV (or 100M SOV)
//Maximum reward per block: 4.9604 SOV (4.9604 * 2880 * 7 = 100001.664)

const REWARD_TOKENS_PER_BLOCK = new BN(49604).mul(new BN(10**14)).mul(new BN(1000));
const REWARD_TOKENS_PER_BLOCK = new BN(49604).mul(new BN(10 ** 14)).mul(new BN(1000));
// const REWARD_TOKENS_PER_BLOCK = new BN(49604).mul(new BN(10**14));

//SOV/BTC pool 40K per week
//ETH/BTC pool 37.5K per week (from second week)
//Dummy pool 100K - SOV/BTC pool (- ETH/BTC pool)

const MAX_ALLOCATION_POINT = new BN(100000).mul(new BN(1000));
const MAX_ALLOCATION_POINT = new BN(100000).mul(new BN(1000));
// const MAX_ALLOCATION_POINT = new BN(100000);
const ALLOCATION_POINT_SOV_BTC = new BN(40000);
const ALLOCATION_POINT_ETH_BTC = new BN(37500);
const ALLOCATION_POINT_SOV_BTC = new BN(40000);
const ALLOCATION_POINT_ETH_BTC = new BN(37500);

const ALLOCATION_POINT_SOV_BTC_2 = new BN(30000);
const ALLOCATION_POINT_SOV_BTC_2 = new BN(30000);

const amount = new BN(1000);

Expand Down Expand Up @@ -1350,7 +1353,9 @@ describe("LiquidityMining", () => {
const userInfo = await liquidityMining.getUserInfo(SOVBTCpool, account1);
//10 blocks passed
let passedBlocks = 10;
let expectedUserReward = REWARD_TOKENS_PER_BLOCK.mul(new BN(passedBlocks)).mul(ALLOCATION_POINT_SOV_BTC).div(MAX_ALLOCATION_POINT);
let expectedUserReward = REWARD_TOKENS_PER_BLOCK.mul(new BN(passedBlocks))
.mul(ALLOCATION_POINT_SOV_BTC)
.div(MAX_ALLOCATION_POINT);
expect(userInfo.accumulatedReward).bignumber.equal(expectedUserReward);
console.log(expectedUserReward.toString());
});
Expand Down Expand Up @@ -1388,14 +1393,16 @@ describe("LiquidityMining", () => {
const userInfo = await liquidityMining.getUserInfo(SOVBTCpool, account1);
//10 blocks + 5 blocks passed
let passedBlocks = 10 + 1; //block should be add to calculation with old values
let expectedUserReward = REWARD_TOKENS_PER_BLOCK.mul(new BN(passedBlocks)).mul(ALLOCATION_POINT_SOV_BTC).div(MAX_ALLOCATION_POINT);
let expectedUserReward = REWARD_TOKENS_PER_BLOCK.mul(new BN(passedBlocks))
.mul(ALLOCATION_POINT_SOV_BTC)
.div(MAX_ALLOCATION_POINT);
passedBlocks = 5 - 1; //block should be removed from calculation with new values
expectedUserReward = expectedUserReward
.add(REWARD_TOKENS_PER_BLOCK.mul(new BN(passedBlocks)).mul(ALLOCATION_POINT_SOV_BTC_2).div(MAX_ALLOCATION_POINT));
expectedUserReward = expectedUserReward.add(
REWARD_TOKENS_PER_BLOCK.mul(new BN(passedBlocks)).mul(ALLOCATION_POINT_SOV_BTC_2).div(MAX_ALLOCATION_POINT)
);
expect(userInfo.accumulatedReward).bignumber.equal(expectedUserReward);
console.log(expectedUserReward.toString());
});

});

describe("onTokensDeposited", () => {
Expand Down Expand Up @@ -1579,7 +1586,7 @@ describe("LiquidityMining", () => {
expect(rewardList[0]).bignumber.equal("0");
});

it("getUserPoolTokenBalance", async()=>{
it("getUserPoolTokenBalance", async () => {
await liquidityMining.deposit(token1.address, new BN(500), ZERO_ADDRESS, { from: account1 });
let poolTokenBalance = await liquidityMining.getUserPoolTokenBalance(token1.address, account1);
expect(poolTokenBalance).bignumber.equal(new BN(500));
Expand Down
8 changes: 2 additions & 6 deletions tests-js/other/OracleIntegration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,8 @@ contract("OracleIntegration", (accounts) => {
describe("OracleIntegration Tests", () => {
it("Test moc oracle integration", async () => {
const [price_feeds, price_feeds_moc] = await set_oracle(
(
await price_feed_rsk_mockup()
).address,
(
await price_feed_moc_mockup()
).address
(await price_feed_rsk_mockup()).address,
(await price_feed_moc_mockup()).address
);

let res = await price_feeds.queryPrecision(BZRX.address, WRBTC.address);
Expand Down

0 comments on commit 9af5992

Please sign in to comment.