Skip to content

Commit

Permalink
fix lock duration
Browse files Browse the repository at this point in the history
- add lockStakeWithEndTime
- update check validator endtime
  • Loading branch information
thang14 committed Jul 29, 2024
1 parent 8ff0321 commit 6a811e9
Show file tree
Hide file tree
Showing 30 changed files with 254 additions and 103 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"indent": ["error", 4],
"func-names": "off",
"max-len": "off",
"no-underscore-dangle": "off"
"no-underscore-dangle": "off",
"no-restricted-syntax": "off"
}
}

3 changes: 2 additions & 1 deletion contracts/common/Decimal.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;

Check failure on line 1 in contracts/common/Decimal.sol

View workflow job for this annotation

GitHub Actions / Lint sources (18.16.1)

Compiler version ^0.5.0 does not satisfy the ^0.5.8 semver requirement


library Decimal {
// unit is used for decimals, e.g. 0.123456
Expand Down
3 changes: 2 additions & 1 deletion contracts/common/ReentrancyGuard.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;

Check failure on line 1 in contracts/common/ReentrancyGuard.sol

View workflow job for this annotation

GitHub Actions / Lint sources (18.16.1)

Compiler version ^0.5.0 does not satisfy the ^0.5.8 semver requirement

import "./Initializable.sol";

/**
Expand Down
3 changes: 2 additions & 1 deletion contracts/erc20/base/ERC20.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;

Check failure on line 1 in contracts/erc20/base/ERC20.sol

View workflow job for this annotation

GitHub Actions / Lint sources (18.16.1)

Compiler version ^0.5.0 does not satisfy the ^0.5.8 semver requirement


import "@openzeppelin/contracts/math/SafeMath.sol";
import "./IERC20.sol";
Expand Down
3 changes: 2 additions & 1 deletion contracts/erc20/base/ERC20Burnable.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;

Check failure on line 1 in contracts/erc20/base/ERC20Burnable.sol

View workflow job for this annotation

GitHub Actions / Lint sources (18.16.1)

Compiler version ^0.5.0 does not satisfy the ^0.5.8 semver requirement


import "./ERC20.sol";

Expand Down
3 changes: 2 additions & 1 deletion contracts/erc20/base/ERC20Detailed.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;

Check failure on line 1 in contracts/erc20/base/ERC20Detailed.sol

View workflow job for this annotation

GitHub Actions / Lint sources (18.16.1)

Compiler version ^0.5.0 does not satisfy the ^0.5.8 semver requirement


import "./IERC20.sol";
import "../../common/Initializable.sol";
Expand Down
3 changes: 2 additions & 1 deletion contracts/erc20/base/ERC20Mintable.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;

Check failure on line 1 in contracts/erc20/base/ERC20Mintable.sol

View workflow job for this annotation

GitHub Actions / Lint sources (18.16.1)

Compiler version ^0.5.0 does not satisfy the ^0.5.8 semver requirement


import "./ERC20.sol";
import "./MinterRole.sol";
Expand Down
3 changes: 2 additions & 1 deletion contracts/erc20/base/IERC20.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;

Check failure on line 3 in contracts/erc20/base/IERC20.sol

View workflow job for this annotation

GitHub Actions / Lint sources (18.16.1)

Compiler version ^0.5.0 does not satisfy the ^0.5.8 semver requirement


/**
* @dev Interface of the ERC20 standard as defined in the EIP.
Expand Down
3 changes: 2 additions & 1 deletion contracts/erc20/base/MinterRole.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;

Check failure on line 1 in contracts/erc20/base/MinterRole.sol

View workflow job for this annotation

GitHub Actions / Lint sources (18.16.1)

Compiler version ^0.5.0 does not satisfy the ^0.5.8 semver requirement


import "./Roles.sol";

Expand Down
3 changes: 2 additions & 1 deletion contracts/erc20/base/Roles.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;

Check failure on line 1 in contracts/erc20/base/Roles.sol

View workflow job for this annotation

GitHub Actions / Lint sources (18.16.1)

Compiler version ^0.5.0 does not satisfy the ^0.5.8 semver requirement



/**
Expand Down
3 changes: 2 additions & 1 deletion contracts/ownership/Ownable.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;

Check failure on line 1 in contracts/ownership/Ownable.sol

View workflow job for this annotation

GitHub Actions / Lint sources (18.16.1)

Compiler version ^0.5.0 does not satisfy the ^0.5.8 semver requirement


import "../common/Initializable.sol";

Expand Down
3 changes: 2 additions & 1 deletion contracts/sfc/ConstantsManager.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;


import "@openzeppelin/contracts/math/SafeMath.sol";
import "../ownership/Ownable.sol";
Expand Down
3 changes: 2 additions & 1 deletion contracts/sfc/GasPriceConstants.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;


import "../common/Decimal.sol";

Expand Down
3 changes: 2 additions & 1 deletion contracts/sfc/NetworkInitializer.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;


import "./SFCI.sol";
import "./NodeDriver.sol";
Expand Down
3 changes: 2 additions & 1 deletion contracts/sfc/NodeDriver.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;


import "@openzeppelin/contracts/math/SafeMath.sol";
import "../common/Initializable.sol";
Expand Down
3 changes: 2 additions & 1 deletion contracts/sfc/NodeDriverI.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;


interface NodeDriverI {
function setGenesisValidator(address _auth, uint256 validatorID, bytes calldata pubkey, uint256 status, uint256 createdEpoch, uint256 createdTime, uint256 deactivatedEpoch, uint256 deactivatedTime) external;
Expand Down
3 changes: 2 additions & 1 deletion contracts/sfc/SFC.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;


import "./GasPriceConstants.sol";
import "../version/Version.sol";
Expand Down
3 changes: 2 additions & 1 deletion contracts/sfc/SFCBase.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;


import "./SFCState.sol";

Expand Down
3 changes: 2 additions & 1 deletion contracts/sfc/SFCI.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;


interface SFCI {
function currentSealedEpoch() external view returns (uint256);
Expand Down
28 changes: 20 additions & 8 deletions contracts/sfc/SFCLib.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;


import "../common/Decimal.sol";
import "./GasPriceConstants.sol";
Expand Down Expand Up @@ -441,26 +442,29 @@ contract SFCLib is SFCBase {
function _lockStake(address delegator, uint256 toValidatorID, uint256 lockupDuration, uint256 amount) internal {
require(amount <= getUnlockedStake(delegator, toValidatorID), "not enough stake");
require(getValidator[toValidatorID].status == OK_STATUS, "validator isn't active");

require(lockupDuration >= c.minLockupDuration() && lockupDuration <= c.maxLockupDuration(), "incorrect duration");
uint256 endTime = _now().add(lockupDuration);
uint256 duration = lockupDuration;
require(duration >= c.minLockupDuration() && duration <= c.maxLockupDuration(), "incorrect duration");
uint256 endTime = _now().add(duration);
address validatorAddr = getValidator[toValidatorID].auth;
if (delegator != validatorAddr) {
require(getLockupInfo[validatorAddr][toValidatorID].endTime >= endTime, "validator lockup period will end earlier");
if (getLockupInfo[validatorAddr][toValidatorID].endTime >= endTime) {
endTime = getLockupInfo[validatorAddr][toValidatorID].endTime;
duration = endTime.sub(_now());
}
}

_stashRewards(delegator, toValidatorID);

// check lockup duration after _stashRewards, which has erased previous lockup if it has unlocked already
LockedDelegation storage ld = getLockupInfo[delegator][toValidatorID];
require(lockupDuration >= ld.duration, "lockup duration cannot decrease");
require(duration >= ld.duration, "lockup duration cannot decrease");

ld.lockedStake = ld.lockedStake.add(amount);
ld.fromEpoch = currentEpoch();
ld.endTime = endTime;
ld.duration = lockupDuration;
ld.duration = duration;

emit LockedUpStake(delegator, toValidatorID, lockupDuration, amount);
emit LockedUpStake(delegator, toValidatorID, duration, amount);
}

function lockStake(uint256 toValidatorID, uint256 lockupDuration, uint256 amount) public {
Expand All @@ -470,6 +474,14 @@ contract SFCLib is SFCBase {
_lockStake(delegator, toValidatorID, lockupDuration, amount);
}

function lockStakeWithEndTime(uint256 toValidatorID, uint256 endTime, uint256 amount) public {
address delegator = msg.sender;
require(amount > 0, "zero amount");
require(endTime > now(), "invalid endtime");
require(!isLockedUp(delegator, toValidatorID), "already locked up");
_lockStake(delegator, toValidatorID, endTime.sub(now), amount);
}

function relockStake(uint256 toValidatorID, uint256 lockupDuration, uint256 amount) public {
address delegator = msg.sender;
_lockStake(delegator, toValidatorID, lockupDuration, amount);
Expand Down
3 changes: 2 additions & 1 deletion contracts/sfc/SFCState.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;


import "./NodeDriver.sol";
import "../ownership/Ownable.sol";
Expand Down
3 changes: 2 additions & 1 deletion contracts/sfc/StakeTokenizer.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;


import "./SFC.sol";
import "../erc20/base/ERC20Burnable.sol";
Expand Down
3 changes: 2 additions & 1 deletion contracts/sfc/Updater.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;


import "./NodeDriver.sol";
import "./SFC.sol";
Expand Down
3 changes: 2 additions & 1 deletion contracts/test/StubEvmWriter.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;


import "../sfc/NodeDriver.sol";

Expand Down
3 changes: 2 additions & 1 deletion contracts/test/UnitTestConstantsManager.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;

import "../sfc/ConstantsManager.sol";

contract UnitTestConstantsManager is ConstantsManager {
Expand Down
3 changes: 2 additions & 1 deletion contracts/test/UnitTestSFC.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;


import "../sfc/SFC.sol";
import "../sfc/SFCI.sol";
Expand Down
3 changes: 2 additions & 1 deletion contracts/version/Version.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0.0;
pragma solidity ^0.5.0;


/**
* @dev Version contract gives the versioning information of the implementation contract
Expand Down
90 changes: 45 additions & 45 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,54 @@ require('hardhat-contract-sizer');
require('@nomiclabs/hardhat-etherscan');
require('dotenv').config();

const PRIVATE_KEY = process.env.PRIVATE_KEY;
const API_KEY = process.env.API_KEY;
const { PRIVATE_KEY } = process.env;
const { API_KEY } = process.env;

module.exports = {
networks: {
hardhat: {
allowUnlimitedContractSize: true
networks: {
hardhat: {
allowUnlimitedContractSize: true,
},
localhost: {
url: 'http://127.0.0.1:8545',
},
mainnet: {
url: 'https://rpc-mainnet.uniultra.xyz',
chainId: 39,
},
testnet: {
url: 'https://rpc-nebulas-testnet.uniultra.xyz',
chainId: 2484,
accounts: [`0x${PRIVATE_KEY}`],
},
},
localhost: {
url: 'http://127.0.0.1:8545'
etherscan: {
apiKey: {
u2uTestnet: API_KEY,
},
},
mainnet: {
url: 'https://rpc-mainnet.uniultra.xyz',
chainId: 39
contractSizer: {
runOnCompile: true,
},
mocha: {},
abiExporter: {
path: './build/contracts',
clear: true,
flat: true,
spacing: 2,
},
solidity: {
version: '0.5.17',
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
gasReporter: {
currency: 'USD',
enabled: false,
gasPrice: 50,
},
testnet: {
url: 'https://rpc-nebulas-testnet.uniultra.xyz',
chainId: 2484,
accounts: [`0x${PRIVATE_KEY}`]
}
},
etherscan: {
apiKey: {
u2uTestnet: API_KEY
}
},
contractSizer: {
runOnCompile: true
},
mocha: {},
abiExporter: {
path: './build/contracts',
clear: true,
flat: true,
spacing: 2
},
solidity: {
version: '0.5.17',
settings: {
optimizer: {
enabled: true,
runs: 200
}
}
},
gasReporter: {
currency: 'USD',
enabled: false,
gasPrice: 50
}
};
Loading

0 comments on commit 6a811e9

Please sign in to comment.