Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(lint): lint files #6

Merged
merged 2 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 15.x
- name: Use Node.js 16.x
uses: actions/setup-node@v2
with:
node-version: 15.x
node-version: 16.x
- name: yarn, compile, hint, coverage
run: |
yarn
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage
22 changes: 22 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"printWidth": 100,
"tabWidth": 4,
"overrides": [
{
"files": "*.*.{ts,js}",
"options": {
"parser": "typescript",
"trailingComma": "all",
"arrowParens": "always",
"singleQuote": true
}
},
{
"files": "*.sol",
"options": {
"bracketSpacing": true,
"explicitTypes": "always"
}
}
]
}
17 changes: 7 additions & 10 deletions .solcover.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
module.exports = {
providerOptions: {
network_id: 1337,
_chainId: 1337,
_chainIdRpc: 1337
},
skipFiles: [
"external",
"test"
]
};
providerOptions: {
network_id: 1337,
_chainId: 1337,
_chainIdRpc: 1337,
},
skipFiles: ['external', 'test'],
};
3 changes: 2 additions & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
"func-order": "off",
"mark-callable-contracts": "off",
"no-empty-blocks": "off",
"compiler-version": ["error", "^0.6.0"],
"compiler-version": ["error", "0.8.6"],
"private-vars-leading-underscore": "off",
"code-complexity": "warn",
"const-name-snakecase": "warn",
"function-max-lines": "warn",
"func-visibility": ["warn", { "ignoreConstructors": true }],
"max-line-length": ["warn", 160],
"avoid-suicide": "error",
"avoid-sha3": "warn",
Expand Down
204 changes: 102 additions & 102 deletions contracts/DrawCalculatorTimelock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,119 +16,119 @@ import "./interfaces/IDrawCalculatorTimelock.sol";
malicously set Draw in the unfortunate event an Owner is compromised.
*/
contract DrawCalculatorTimelock is IDrawCalculatorTimelock, Manageable {
/* ============ Global Variables ============ */

/// @notice Internal DrawCalculator reference.
IDrawCalculator internal immutable calculator;

/// @notice Seconds required to elapse before newest Draw is available
uint32 internal timelockDuration;

/// @notice Internal Timelock struct reference.
Timelock internal timelock;

/* ============ Deploy ============ */

/**
* @notice Initialize DrawCalculatorTimelockTrigger smart contract.
* @param _owner Address of the DrawCalculator owner.
* @param _calculator DrawCalculator address.
* @param _timelockDuration Elapsed seconds before new Draw is available.
*/
constructor(
address _owner,
IDrawCalculator _calculator,
uint32 _timelockDuration
) Ownable(_owner) {
calculator = _calculator;
timelockDuration = _timelockDuration;

emit Deployed(_calculator, _timelockDuration);
}

/* ============ Global Variables ============ */
/* ============ External Functions ============ */

/// @notice Internal DrawCalculator reference.
IDrawCalculator internal immutable calculator;
/// @inheritdoc IDrawCalculatorTimelock
function calculate(
address user,
uint32[] calldata drawIds,
bytes calldata data
) external view override returns (uint256[] memory) {
Timelock memory _timelock = timelock;

/// @notice Seconds required to elapse before newest Draw is available
uint32 internal timelockDuration;
for (uint256 i = 0; i < drawIds.length; i++) {
// if draw id matches timelock and not expired, revert
if (drawIds[i] == _timelock.drawId) {
_requireTimelockElapsed(_timelock);
}
}

/// @notice Internal Timelock struct reference.
Timelock internal timelock;
return calculator.calculate(user, drawIds, data);
}

/* ============ Deploy ============ */
/// @inheritdoc IDrawCalculatorTimelock
function lock(uint32 _drawId) external override onlyManagerOrOwner returns (bool) {
Timelock memory _timelock = timelock;
require(_drawId == _timelock.drawId + 1, "OM/not-drawid-plus-one");
_requireTimelockElapsed(_timelock);
timelock = Timelock({ drawId: _drawId, timestamp: uint128(block.timestamp) });
return true;
}

/**
* @notice Initialize DrawCalculatorTimelockTrigger smart contract.
* @param _owner Address of the DrawCalculator owner.
* @param _calculator DrawCalculator address.
* @param _timelockDuration Elapsed seconds before new Draw is available.
*/
constructor (
address _owner,
IDrawCalculator _calculator,
uint32 _timelockDuration
) Ownable(_owner) {
calculator = _calculator;
timelockDuration = _timelockDuration;
/// @inheritdoc IDrawCalculatorTimelock
function getDrawCalculator() external view override returns (IDrawCalculator) {
return calculator;
}

emit Deployed(_calculator, _timelockDuration);
}
/// @inheritdoc IDrawCalculatorTimelock
function getTimelock() external view override returns (Timelock memory) {
return timelock;
}

/* ============ External Functions ============ */
/// @inheritdoc IDrawCalculatorTimelock
function getTimelockDuration() external view override returns (uint32) {
return timelockDuration;
}

/// @inheritdoc IDrawCalculatorTimelock
function calculate(address user, uint32[] calldata drawIds, bytes calldata data) external override view returns (uint256[] memory) {
Timelock memory _timelock = timelock;
/// @inheritdoc IDrawCalculatorTimelock
function setTimelock(Timelock memory _timelock) external override onlyOwner {
timelock = _timelock;

for (uint256 i = 0; i < drawIds.length; i++) {
// if draw id matches timelock and not expired, revert
if (drawIds[i] == _timelock.drawId) {
_requireTimelockElapsed(_timelock);
}
emit TimelockSet(_timelock);
}

return calculator.calculate(user, drawIds, data);
}

/// @inheritdoc IDrawCalculatorTimelock
function lock(uint32 _drawId) external override onlyManagerOrOwner returns (bool) {
Timelock memory _timelock = timelock;
require(_drawId == _timelock.drawId + 1, "OM/not-drawid-plus-one");
_requireTimelockElapsed(_timelock);
timelock = Timelock({
drawId: _drawId,
timestamp: uint128(block.timestamp)
});
return true;
}

/// @inheritdoc IDrawCalculatorTimelock
function getDrawCalculator() external override view returns (IDrawCalculator) {
return calculator;
}

/// @inheritdoc IDrawCalculatorTimelock
function getTimelock() external override view returns (Timelock memory) {
return timelock;
}

/// @inheritdoc IDrawCalculatorTimelock
function getTimelockDuration() external override view returns (uint32) {
return timelockDuration;
}

/// @inheritdoc IDrawCalculatorTimelock
function setTimelock(Timelock memory _timelock) external override onlyOwner {
timelock = _timelock;

emit TimelockSet(_timelock);
}

/// @inheritdoc IDrawCalculatorTimelock
function setTimelockDuration(uint32 _timelockDuration) external override onlyOwner {
timelockDuration = _timelockDuration;

emit TimelockDurationSet(_timelockDuration);
}

/// @inheritdoc IDrawCalculatorTimelock
function hasElapsed() external override view returns (bool) {
return _timelockHasElapsed(timelock);
}


/* ============ Internal Functions ============ */

/**
* @notice Read global DrawCalculator variable.
* @return IDrawCalculator
*/
function _timelockHasElapsed(Timelock memory _timelock) internal view returns (bool) {
// If the timelock hasn't been initialized, then it's elapsed
if (_timelock.timestamp == 0) { return true; }
// otherwise if the timelock has expired, we're good.
return (block.timestamp > _timelock.timestamp + timelockDuration);
}

/**
* @notice Require the timelock "cooldown" period has elapsed
* @param _timelock the Timelock to check
*/
function _requireTimelockElapsed(Timelock memory _timelock) internal view {
require(_timelockHasElapsed(_timelock), "OM/timelock-not-expired");
}
/// @inheritdoc IDrawCalculatorTimelock
function setTimelockDuration(uint32 _timelockDuration) external override onlyOwner {
timelockDuration = _timelockDuration;

emit TimelockDurationSet(_timelockDuration);
}

/// @inheritdoc IDrawCalculatorTimelock
function hasElapsed() external view override returns (bool) {
return _timelockHasElapsed(timelock);
}

/* ============ Internal Functions ============ */

/**
* @notice Read global DrawCalculator variable.
* @return IDrawCalculator
*/
function _timelockHasElapsed(Timelock memory _timelock) internal view returns (bool) {
// If the timelock hasn't been initialized, then it's elapsed
if (_timelock.timestamp == 0) {
return true;
}
// otherwise if the timelock has expired, we're good.
return (block.timestamp > _timelock.timestamp + timelockDuration);
}

/**
* @notice Require the timelock "cooldown" period has elapsed
* @param _timelock the Timelock to check
*/
function _requireTimelockElapsed(Timelock memory _timelock) internal view {
require(_timelockHasElapsed(_timelock), "OM/timelock-not-expired");
}
}
83 changes: 42 additions & 41 deletions contracts/L1TimelockTrigger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,53 +18,54 @@ import "./interfaces/IDrawCalculatorTimelock.sol";
malicously set Draw in the unfortunate event an Owner is compromised.
*/
contract L1TimelockTrigger is Manageable {
/* ============ Events ============ */

/* ============ Events ============ */
/// @notice Emitted when the contract is deployed.
/// @param prizeDistributionHistory The address of the prize distribution history contract.
/// @param timelock The address of the DrawCalculatorTimelock
event Deployed(
IPrizeDistributionHistory indexed prizeDistributionHistory,
IDrawCalculatorTimelock indexed timelock
);

/// @notice Emitted when the contract is deployed.
/// @param prizeDistributionHistory The address of the prize distribution history contract.
/// @param timelock The address of the DrawCalculatorTimelock
event Deployed(
IPrizeDistributionHistory indexed prizeDistributionHistory,
IDrawCalculatorTimelock indexed timelock
);
/* ============ Global Variables ============ */

/* ============ Global Variables ============ */
/// @notice Internal PrizeDistributionHistory reference.
IPrizeDistributionHistory public immutable prizeDistributionHistory;

/// @notice Internal PrizeDistributionHistory reference.
IPrizeDistributionHistory public immutable prizeDistributionHistory;
/// @notice Timelock struct reference.
IDrawCalculatorTimelock public timelock;

/// @notice Timelock struct reference.
IDrawCalculatorTimelock public timelock;
/* ============ Deploy ============ */

/* ============ Deploy ============ */
/**
* @notice Initialize L1TimelockTrigger smart contract.
* @param _owner Address of the L1TimelockTrigger owner.
* @param _prizeDistributionHistory PrizeDistributionHistory address
* @param _timelock Elapsed seconds before new Draw is available
*/
constructor(
address _owner,
IPrizeDistributionHistory _prizeDistributionHistory,
IDrawCalculatorTimelock _timelock
) Ownable(_owner) {
prizeDistributionHistory = _prizeDistributionHistory;
timelock = _timelock;

/**
* @notice Initialize L1TimelockTrigger smart contract.
* @param _owner Address of the L1TimelockTrigger owner.
* @param _prizeDistributionHistory PrizeDistributionHistory address
* @param _timelock Elapsed seconds before new Draw is available
*/
constructor (
address _owner,
IPrizeDistributionHistory _prizeDistributionHistory,
IDrawCalculatorTimelock _timelock
) Ownable(_owner) {
prizeDistributionHistory = _prizeDistributionHistory;
timelock = _timelock;

emit Deployed(_prizeDistributionHistory, _timelock);
}

/**
* @notice Push Draw onto draws ring buffer history.
* @dev Restricts new draws by forcing a push timelock.
* @param _drawId draw id
* @param _drawSetting Draw settings
*/
function push(uint32 _drawId, DrawLib.PrizeDistribution memory _drawSetting) external onlyManagerOrOwner {
timelock.lock(_drawId);
prizeDistributionHistory.pushPrizeDistribution(_drawId, _drawSetting);
}
emit Deployed(_prizeDistributionHistory, _timelock);
}

/**
* @notice Push Draw onto draws ring buffer history.
* @dev Restricts new draws by forcing a push timelock.
* @param _drawId draw id
* @param _drawSetting Draw settings
*/
function push(uint32 _drawId, DrawLib.PrizeDistribution memory _drawSetting)
external
onlyManagerOrOwner
{
timelock.lock(_drawId);
prizeDistributionHistory.pushPrizeDistribution(_drawId, _drawSetting);
}
}
Loading