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

Prepare release 1.0.1 #194

Closed
wants to merge 12 commits into from
Closed
5 changes: 3 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ on:
pull_request:
types: [closed]
branches:
- 'v*.*.*'
- develop
- beta
- release-candidate
- stable
- 'v*.*.*'
push:
tags:
- 'custom-release-*'
Expand Down Expand Up @@ -52,7 +53,7 @@ jobs:
echo "PRERELEASE=$PRERELEASE" >> $GITHUB_ENV

- name: Generate ABI
run: npx hardhat run scripts/generateAbi.ts
run: yarn exec hardhat run scripts/generateAbi.ts

- name: Store artifacts
uses: actions/upload-artifact@v4
Expand Down
7 changes: 7 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "solhint:all",
"rules": {
"foundry-test-functions": "off",
"not-rely-on-time": "off",

"code-complexity": "error",
Expand All @@ -14,8 +15,14 @@
}
],
"function-max-lines": "error",
"gas-increment-by-one": "error",
"gas-indexed-events": "error",
"gas-length-in-loops": "error",
"gas-strict-inequalities": "error",
"imports-order": "error",
"max-line-length": ["error", 100],
"max-states-count": "error",
"named-parameters-mapping": "error",
"no-empty-blocks": "error",
"no-global-import": "error",
"no-unused-import": "error",
Expand Down
59 changes: 24 additions & 35 deletions contracts/Paymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,25 @@ pragma solidity ^0.8.19;

// cspell:words structs IERC20

import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {AccessManagedUpgradeable}
import { AccessManagedUpgradeable }
from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagedUpgradeable.sol";

import {
SchainPriceIsNotSet,
SkaleTokenIsNotSet,
SklPriceIsNotSet,
SklPriceIsOutdated
} from "./errors/Parameters.sol";
import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol";
import { EnumerableSet }
from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import { DateTimeUtils, Seconds, Timestamp, Months }
from "@skalenetwork/paymaster-interfaces/DateTimeUtils.sol";
import { IPaymaster, SchainHash, USD, ValidatorId }
from "@skalenetwork/paymaster-interfaces/IPaymaster.sol";
import { SKL } from "@skalenetwork/paymaster-interfaces/types/Skl.sol";
import { SchainPriceIsNotSet, SkaleTokenIsNotSet, SklPriceIsNotSet, SklPriceIsOutdated }
from "./errors/Parameters.sol";
import {
ReplenishmentPeriodIsTooBig,
ReplenishmentPeriodIsTooSmall,
TooSmallAllowance,
TransferFailure
} from "./errors/Replenishment.sol";
import {SchainNotFound, SchainAddingError, SchainDeletionError} from "./errors/Schain.sol";
import { SchainNotFound, SchainAddingError, SchainDeletionError } from "./errors/Schain.sol";
import {
ValidatorNotFound,
ValidatorAddingError,
Expand All @@ -49,22 +50,9 @@ import {
ValidatorDeletionError,
ValidatorHasBeenRemoved
} from "./errors/Validator.sol";
import {
IPaymaster,
SchainHash,
USD,
ValidatorId
} from "@skalenetwork/paymaster-interfaces/IPaymaster.sol";
import {TypedMap} from "./structs/typed/TypedMap.sol";
import {SKL} from "@skalenetwork/paymaster-interfaces/types/Skl.sol";
import {
DateTimeUtils,
Seconds,
Timestamp,
Months
} from "@skalenetwork/paymaster-interfaces/DateTimeUtils.sol";
import {SequenceLibrary} from "./Sequence.sol";
import {TimelineLibrary} from "./Timeline.sol";
import { SequenceLibrary } from "./Sequence.sol";
import { TypedMap } from "./structs/typed/TypedMap.sol";
import { TimelineLibrary } from "./Timeline.sol";


contract Paymaster is AccessManagedUpgradeable, IPaymaster {
Expand Down Expand Up @@ -106,7 +94,7 @@ contract Paymaster is AccessManagedUpgradeable, IPaymaster {
TypedMap.AddressToValidatorIdMap addressToValidatorId;
}

mapping(SchainHash => Schain) public schains;
mapping(SchainHash schainHash => Schain schain) public schains;
EnumerableSet.Bytes32Set private _schainHashes;

ValidatorData private _validatorData;
Expand All @@ -121,7 +109,7 @@ contract Paymaster is AccessManagedUpgradeable, IPaymaster {
TimelineLibrary.Timeline private _totalRewards;
SequenceLibrary.Sequence private _totalNodesHistory;

mapping (DebtId => Payment) public debts;
mapping (DebtId debtId => Payment payment) public debts;
DebtId public debtsBegin;
DebtId public debtsEnd;

Expand Down Expand Up @@ -451,8 +439,9 @@ contract Paymaster is AccessManagedUpgradeable, IPaymaster {
}

function getSchainsNames() external view override returns (string[] memory names) {
names = new string[](getSchainsNumber());
for (uint256 i = 0; i < names.length; ++i) {
uint256 length = getSchainsNumber();
names = new string[](length);
for (uint256 i = 0; i < length; ++i) {
names[i] = _getSchain(SchainHash.wrap(_schainHashes.at(i))).name;
}
}
Expand Down Expand Up @@ -523,7 +512,7 @@ contract Paymaster is AccessManagedUpgradeable, IPaymaster {
firstUnpaidDebt = validator.firstUnpaidDebt;
}
validator.nodesHistory.clear(before);
if (Timestamp.wrap(0) != validator.deleted && validator.deleted <= before) {
if (Timestamp.wrap(0) != validator.deleted && !(validator.deleted > before)) {
_removeValidator(validator);
}
}
Expand Down Expand Up @@ -631,12 +620,12 @@ contract Paymaster is AccessManagedUpgradeable, IPaymaster {
returns (bool debtWasCreated)
{
debtWasCreated = false;
if (current <= payment.from) {
if (!(current > payment.from)) {
// payment for the future
_totalRewards.add(payment.from, payment.to, SKL.unwrap(payment.amount));
} else {
debtWasCreated = true;
if (payment.to <= current) {
if (!(payment.to > current)) {
// payment for the past
_addDebt(
payment,
Expand Down Expand Up @@ -875,7 +864,7 @@ contract Paymaster is AccessManagedUpgradeable, IPaymaster {
returns (uint256 newNodesNumber)
{
newNodesNumber = currentNodesNumber;
while (nodesIterator.hasNext() && nodesIterator.nextTimestamp <= cursor) {
while (nodesIterator.hasNext() && !(nodesIterator.nextTimestamp > cursor)) {
if (nodesIterator.step(nodesHistory)) {
newNodesNumber = nodesHistory.getValue(nodesIterator);
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/Sequence.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ library SequenceLibrary {
function add(Sequence storage sequence, Timestamp timestamp, uint256 value) internal {
uint256 length = sequence.ids.length();
if (length > 0) {
if (timestamp <= _getNodeByIndex(sequence, length - 1).timestamp) {
if (!(timestamp > _getNodeByIndex(sequence, length - 1).timestamp)) {
revert CannotAddToThePast();
}
}
Expand Down Expand Up @@ -143,7 +143,7 @@ library SequenceLibrary {
if(iterator.idIndex == _BEFORE_FIRST_ELEMENT) {
return 0;
}
if(iterator.idIndex >= iterator.sequenceSize) {
if(!(iterator.idIndex < iterator.sequenceSize)) {
return _getNodeByIndex(sequence, iterator.sequenceSize - 1).value;
}
return _getNodeByIndex(sequence, iterator.idIndex).value;
Expand Down Expand Up @@ -187,7 +187,7 @@ library SequenceLibrary {
if (iterator.idIndex == _BEFORE_FIRST_ELEMENT) {
iterator.idIndex = 0;
} else {
iterator.idIndex += 1;
++iterator.idIndex;
}
if (iterator.idIndex + 1 < iterator.sequenceSize) {
iterator.nextTimestamp = _getNodeByIndex(sequence, iterator.idIndex + 1).timestamp;
Expand Down
16 changes: 8 additions & 8 deletions contracts/Timeline.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ pragma solidity ^0.8.19;

// cspell:words deque structs

import {TypedDoubleEndedQueue} from "./structs/typed/TypedDoubleEndedQueue.sol";
import {TypedPriorityQueue} from "./structs/typed/TypedPriorityQueue.sol";
import {
DateTimeUtils,
Seconds,
Timestamp
} from "@skalenetwork/paymaster-interfaces/DateTimeUtils.sol";
import {TypedDoubleEndedQueue} from "./structs/typed/TypedDoubleEndedQueue.sol";
import {TypedPriorityQueue} from "./structs/typed/TypedPriorityQueue.sol";


library TimelineLibrary {
Expand Down Expand Up @@ -85,7 +85,7 @@ library TimelineLibrary {
// Library internal functions should not have leading underscore
// solhint-disable-next-line private-vars-leading-underscore
function process(Timeline storage timeline, Timestamp until) internal {
if (until <= timeline.processedUntil) {
if (!(timeline.processedUntil < until)) {
return;
}

Expand Down Expand Up @@ -176,7 +176,7 @@ library TimelineLibrary {
valuesAmount > 0;
--valuesAmount
) {
if (before <= _getValueByIndex(timeline, 0).timestamp) {
if (!(before > _getValueByIndex(timeline, 0).timestamp)) {
break;
}
ValueId valueId = timeline.valuesQueue.popFront();
Expand Down Expand Up @@ -246,7 +246,7 @@ library TimelineLibrary {
return 0;
}
Timestamp firstValueTimestamp = _getValueByIndex(timeline, 0).timestamp;
if (to <= firstValueTimestamp) {
if (!(to > firstValueTimestamp)) {
return 0;
}
if (from < firstValueTimestamp) {
Expand Down Expand Up @@ -406,14 +406,14 @@ library TimelineLibrary {
if (timestamp < _getValueByIndex(timeline, 0).timestamp) {
revert TimestampIsOutOfValues();
}
if (_getCurrentValue(timeline).timestamp <= timestamp) {
if (!(_getCurrentValue(timeline).timestamp > timestamp)) {
return timeline.valuesQueue.length() - 1;
}
uint256 left = 0;
uint256 right = timeline.valuesQueue.length() - 1;
while (left + 1 < right) {
uint256 middle = (left + right) / 2;
if (_getValueByIndex(timeline, middle).timestamp <= timestamp) {
if (!(_getValueByIndex(timeline, middle).timestamp > timestamp)) {
left = middle;
} else {
right = middle;
Expand All @@ -424,7 +424,7 @@ library TimelineLibrary {

function _createValue(Timeline storage timeline, Value memory value) private {
if(!timeline.valuesQueue.empty() &&
value.timestamp <= _getCurrentValue(timeline).timestamp) {
!(value.timestamp > _getCurrentValue(timeline).timestamp)) {
revert CannotSetValueInThePast();
}
ValueId valuesEnd = timeline.valuesEnd;
Expand Down
2 changes: 1 addition & 1 deletion contracts/errors/Validator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

pragma solidity ^0.8.18;

import {ValidatorId} from "@skalenetwork/paymaster-interfaces/IPaymaster.sol";
import {Timestamp} from "@skalenetwork/paymaster-interfaces/DateTimeUtils.sol";
import {ValidatorId} from "@skalenetwork/paymaster-interfaces/IPaymaster.sol";


error ValidatorNotFound(
Expand Down
4 changes: 2 additions & 2 deletions contracts/interfaces/test/IFastForwardPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

pragma solidity ^0.8.18;

import {Seconds, Timestamp} from "../../Paymaster.sol";
import {IPaymaster} from "@skalenetwork/paymaster-interfaces/IPaymaster.sol";
import { IPaymaster } from "@skalenetwork/paymaster-interfaces/IPaymaster.sol";
import { Seconds, Timestamp } from "./../../Paymaster.sol";


interface IFastForwardPaymaster is IPaymaster {
Expand Down
8 changes: 4 additions & 4 deletions contracts/structs/Heap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ library HeapLibrary {
}

event HeapValueAdded(
uint256 value
uint256 indexed value
);

event HeapValueRemoved(
uint256 value
uint256 indexed value
);

// Library internal functions should not have leading underscore
Expand Down Expand Up @@ -154,7 +154,7 @@ library HeapLibrary {
}
NodeId parent = _getParentNode(node);
uint256 parentValue = _getValue(heap, parent);
if (parentValue <= value) {
if (!(parentValue > value)) {
_setValue(heap, node, value);
} else {
_setValue(heap, node, parentValue);
Expand Down Expand Up @@ -220,7 +220,7 @@ library HeapLibrary {
}

function _exists(NodeId node, NodeId lastNode) private pure returns (bool result) {
return NodeId.unwrap(node) <= NodeId.unwrap(lastNode);
return !(NodeId.unwrap(node) > NodeId.unwrap(lastNode));
}

function _getValue(Heap storage heap, NodeId node) private view returns (uint256 value) {
Expand Down
4 changes: 2 additions & 2 deletions contracts/structs/typed/TypedPriorityQueue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pragma solidity ^0.8.20;

// cspell:words structs

import {PriorityQueueLibrary} from "../PriorityQueue.sol";
import {TimelineLibrary} from "../../Timeline.sol";
import { TimelineLibrary } from "./../../Timeline.sol";
import { PriorityQueueLibrary } from "./../PriorityQueue.sol";


library TypedPriorityQueue {
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/FastForwardPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

pragma solidity ^0.8.19;

import {DateTimeUtils, Paymaster, Seconds, Timestamp} from "../Paymaster.sol";
import {IFastForwardPaymaster, IPaymaster} from "../interfaces/test/IFastForwardPaymaster.sol";
import { IFastForwardPaymaster, IPaymaster } from "./../interfaces/test/IFastForwardPaymaster.sol";
import { DateTimeUtils, Paymaster, Seconds, Timestamp } from "./../Paymaster.sol";


contract FastForwardPaymaster is Paymaster, IFastForwardPaymaster {
Expand Down
6 changes: 3 additions & 3 deletions contracts/test/SequenceTester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

pragma solidity ^0.8.19;

import {ISequenceTester} from "../interfaces/test/ISequenceTester.sol";
import {SequenceLibrary} from "../Sequence.sol";
import {Timestamp} from "@skalenetwork/paymaster-interfaces/DateTimeUtils.sol";
import { Timestamp } from "@skalenetwork/paymaster-interfaces/DateTimeUtils.sol";
import { ISequenceTester } from "./../interfaces/test/ISequenceTester.sol";
import { SequenceLibrary } from "./../Sequence.sol";


contract SequenceTester is ISequenceTester {
Expand Down
6 changes: 3 additions & 3 deletions contracts/test/TimelineTester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ pragma solidity ^0.8.19;

// cspell:words structs

import {ITimelineTester} from "../interfaces/test/ITimelineTester.sol";
import {TimelineLibrary} from "../Timeline.sol";
import {Timestamp} from "@skalenetwork/paymaster-interfaces/DateTimeUtils.sol";
import { Timestamp } from "@skalenetwork/paymaster-interfaces/DateTimeUtils.sol";
import { ITimelineTester } from "./../interfaces/test/ITimelineTester.sol";
import { TimelineLibrary } from "./../Timeline.sol";


contract TimelineTester is ITimelineTester {
Expand Down
Loading
Loading