Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
e3c173e
Initial commit of staker V3
letsleroyu Jan 26, 2022
b5db694
Checkpoints, different tps for holders
letsleroyu Jan 27, 2022
c8c9b8c
NFT stacking, IOU tokens minting and stuff
letsleroyu Jan 31, 2022
72ea5b0
Claim function refactor
letsleroyu Jan 31, 2022
6b04651
NFTStaking, refactoring NFTStaking
letsleroyu Feb 1, 2022
26e70c8
StakerNFT refactoring gas costs and contract size
letsleroyu Feb 2, 2022
5ffc60d
Refacotoring for contract size
letsleroyu Feb 2, 2022
361bcfb
Updated calculations and depositing
letsleroyu Feb 3, 2022
48166d7
StakerV3 Diamond added
Feb 22, 2022
5adc8c2
partly refactored and fully covered with tests StakerV3ds
deathwing00000 Mar 15, 2022
95c0501
implemented diamond standard for StakerV1,V2, refactored StakerV3ds, …
deathwing00000 Mar 17, 2022
7fabb2c
optimizing contract via replacing all requires with reverts and custo…
deathwing00000 Mar 18, 2022
c4c6840
Optimizing and scenario testing
deathwing00000 Mar 21, 2022
ab9cc01
implemented time lock deposits and tests for it.
deathwing00000 Mar 25, 2022
be03102
implemented compound interst feature and covered with tests
deathwing00000 Mar 28, 2022
92c82d4
fixed updatePool when multiple time locks are expired
deathwing00000 Mar 29, 2022
b67ded2
optimized updatePool and multiple token unlocks test case done
deathwing00000 Mar 29, 2022
2658066
another fixes at updatePool and developer shares
deathwing00000 Mar 30, 2022
3639167
redesigned facets
deathwing00000 Apr 11, 2022
9a64982
Refactored facets and fixed bugs
deathwing00000 Jun 22, 2022
9ef9b2e
Deleted unused files.
deathwing00000 Jun 22, 2022
0c95412
Deleted unused files.
deathwing00000 Jun 22, 2022
630f204
Initial commit of staker V3
letsleroyu Jan 26, 2022
2daeb75
Checkpoints, different tps for holders
letsleroyu Jan 27, 2022
58679fd
NFT stacking, IOU tokens minting and stuff
letsleroyu Jan 31, 2022
e6248f3
Claim function refactor
letsleroyu Jan 31, 2022
9564174
NFTStaking, refactoring NFTStaking
letsleroyu Feb 1, 2022
41fe317
StakerNFT refactoring gas costs and contract size
letsleroyu Feb 2, 2022
f32fd09
Refacotoring for contract size
letsleroyu Feb 2, 2022
5bef2cf
Updated calculations and depositing
letsleroyu Feb 3, 2022
92b7cf9
StakerV3 Diamond added
Feb 22, 2022
70358c0
partly refactored and fully covered with tests StakerV3ds
deathwing00000 Mar 15, 2022
d176d9a
implemented diamond standard for StakerV1,V2, refactored StakerV3ds, …
deathwing00000 Mar 17, 2022
1178097
optimizing contract via replacing all requires with reverts and custo…
deathwing00000 Mar 18, 2022
644b797
Optimizing and scenario testing
deathwing00000 Mar 21, 2022
821e36f
implemented time lock deposits and tests for it.
deathwing00000 Mar 25, 2022
da0dd99
implemented compound interst feature and covered with tests
deathwing00000 Mar 28, 2022
2ce494f
fixed updatePool when multiple time locks are expired
deathwing00000 Mar 29, 2022
de6b78c
optimized updatePool and multiple token unlocks test case done
deathwing00000 Mar 29, 2022
8bfba19
another fixes at updatePool and developer shares
deathwing00000 Mar 30, 2022
32c4041
redesigned facets
deathwing00000 Apr 11, 2022
6ee3960
Refactored facets and fixed bugs
deathwing00000 Jun 22, 2022
d967171
Deleted unused files.
deathwing00000 Jun 22, 2022
cb7bb75
Deleted unused files.
deathwing00000 Jun 22, 2022
07c9a39
Sample-env additions
deathwing00000 Jun 22, 2022
833f184
Rebasing to master
deathwing00000 Jun 22, 2022
14d0ceb
Merge branch 'master' into staker-facets-redesign
deathwing00000 Jul 11, 2022
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
3 changes: 3 additions & 0 deletions .sample-env
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
INFURA_PROJECT_ID=
DEPLOYER_PRIVATE_KEY=
ETHERSCAN_API_KEY=
ALCHEMY_KEY=
REPORT_GAS=
COINMARKETCAP_API_KEY=
2 changes: 1 addition & 1 deletion .solcover.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Exclude the legacy compiler MultiSigWallet.sol file from instrumentation.
module.exports = {
skipFiles: [ 'MultiSigWallet.sol' ]
skipFiles: ["MultiSigWallet.sol"],
};
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"solidity.compileUsingRemoteVersion": "v0.8.8+commit.dddeac2f",
"solidity-va.uml.actors.enable": false
}
286 changes: 145 additions & 141 deletions contracts/access/PermitControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.7;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "hardhat/console.sol";

/**
@title An advanced permission-management contract.
Expand All @@ -18,21 +19,21 @@ import "@openzeppelin/contracts/utils/Address.sol";
August 23rd, 2021.
*/
abstract contract PermitControl is Ownable {
using Address for address;
using Address for address;

/// A special reserved constant for representing no rights.
bytes32 public constant ZERO_RIGHT = hex"00000000000000000000000000000000";
/// A special reserved constant for representing no rights.
bytes32 public constant ZERO_RIGHT = hex"00000000000000000000000000000000";

/// A special constant specifying the unique, universal-rights circumstance.
bytes32 public constant UNIVERSAL = hex"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
/// A special constant specifying the unique, universal-rights circumstance.
bytes32 public constant UNIVERSAL = hex"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";

/*
/*
A special constant specifying the unique manager right. This right allows an
address to freely-manipulate the `managedRight` mapping.
**/
bytes32 public constant MANAGER = hex"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
bytes32 public constant MANAGER = hex"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";

/**
/**
A mapping of per-address permissions to the circumstances, represented as
an additional layer of generic bytes32 data, under which the addresses have
various permits. A permit in this sense is represented by a per-circumstance
Expand All @@ -45,19 +46,19 @@ abstract contract PermitControl is Ownable {
max-integer circumstance. Perpetual rights may be given an expiry time of
max-integer.
*/
mapping( address => mapping( bytes32 => mapping( bytes32 => uint256 )))
public permissions;
mapping(address => mapping(bytes32 => mapping(bytes32 => uint256)))
public permissions;

/**
/**
An additional mapping of managed rights to manager rights. This mapping
represents the administrator relationship that various rights have with one
another. An address with a manager right may freely set permits for that
manager right's managed rights. Each right may be managed by only one other
right.
*/
mapping( bytes32 => bytes32 ) public managerRight;
mapping(bytes32 => bytes32) public managerRight;

/**
/**
An event emitted when an address has a permit updated. This event captures,
through its various parameter combinations, the cases of granting a permit,
updating the expiration time of a permit, or revoking a permit.
Expand All @@ -68,32 +69,32 @@ abstract contract PermitControl is Ownable {
@param role The role which was updated.
@param expirationTime The time when the permit expires.
*/
event PermitUpdated(
address indexed updator,
address indexed updatee,
bytes32 circumstance,
bytes32 indexed role,
uint256 expirationTime
);

// /**
// A version of PermitUpdated for work with setPermits() function.
// @param updator The address which has updated the permit.
// @param updatees The addresses whose permit were updated.
// @param circumstances The circumstances wherein the permits were updated.
// @param roles The roles which were updated.
// @param expirationTimes The times when the permits expire.
// */
// event PermitsUpdated(
// address indexed updator,
// address[] indexed updatees,
// bytes32[] circumstances,
// bytes32[] indexed roles,
// uint256[] expirationTimes
// );

/**
event PermitUpdated(
address indexed updator,
address indexed updatee,
bytes32 circumstance,
bytes32 indexed role,
uint256 expirationTime
);

// /**
// A version of PermitUpdated for work with setPermits() function.

// @param updator The address which has updated the permit.
// @param updatees The addresses whose permit were updated.
// @param circumstances The circumstances wherein the permits were updated.
// @param roles The roles which were updated.
// @param expirationTimes The times when the permits expire.
// */
// event PermitsUpdated(
// address indexed updator,
// address[] indexed updatees,
// bytes32[] circumstances,
// bytes32[] indexed roles,
// uint256[] expirationTimes
// );

/**
An event emitted when a management relationship in `managerRight` is
updated. This event captures adding and revoking management permissions via
observing the update history of the `managerRight` value.
Expand All @@ -102,13 +103,13 @@ abstract contract PermitControl is Ownable {
@param managedRight The right which had its manager updated.
@param managerRight The new manager right which was updated to.
*/
event ManagementUpdated(
address indexed manager,
bytes32 indexed managedRight,
bytes32 indexed managerRight
);
event ManagementUpdated(
address indexed manager,
bytes32 indexed managedRight,
bytes32 indexed managerRight
);

/**
/**
A modifier which allows only the super-administrative owner or addresses
with a specified valid right to perform a call.

Expand All @@ -117,24 +118,23 @@ abstract contract PermitControl is Ownable {
@param _right The right to validate for the calling address. It must be
non-expired and exist within the specified `_circumstance`.
*/
modifier hasValidPermit(
bytes32 _circumstance,
bytes32 _right
) {
require(_msgSender() == owner()
|| hasRight(_msgSender(), _circumstance, _right),
"P1");
_;
}

/**
modifier hasValidPermit(bytes32 _circumstance, bytes32 _right) {
require(
_msgSender() == owner() ||
hasRight(_msgSender(), _circumstance, _right),
"P1"
);
_;
}

/**
Return a version number for this contract's interface.
*/
function version() external virtual pure returns (uint256) {
return 1;
}
function version() external pure virtual returns (uint256) {
return 1;
}

/**
/**
Determine whether or not an address has some rights under the given
circumstance, and if they do have the right, until when.

Expand All @@ -144,15 +144,15 @@ abstract contract PermitControl is Ownable {
@return The timestamp in seconds when the `_right` expires. If the timestamp
is zero, we can assume that the user never had the right.
*/
function hasRightUntil(
address _address,
bytes32 _circumstance,
bytes32 _right
) public view returns (uint256) {
return permissions[_address][_circumstance][_right];
}

/**
function hasRightUntil(
address _address,
bytes32 _circumstance,
bytes32 _right
) public view returns (uint256) {
return permissions[_address][_circumstance][_right];
}

/**
Determine whether or not an address has some rights under the given
circumstance,

Expand All @@ -161,15 +161,15 @@ abstract contract PermitControl is Ownable {
@param _right The right to check for validity.
@return true or false, whether user has rights and time is valid.
*/
function hasRight(
address _address,
bytes32 _circumstance,
bytes32 _right
) public view returns (bool) {
return permissions[_address][_circumstance][_right] > block.timestamp;
}

/**
function hasRight(
address _address,
bytes32 _circumstance,
bytes32 _right
) public view returns (bool) {
return permissions[_address][_circumstance][_right] > block.timestamp;
}

/**
Set the permit to a specific address under some circumstances. A permit may
only be set by the super-administrative contract owner or an address holding
some delegated management permit.
Expand All @@ -180,59 +180,63 @@ abstract contract PermitControl is Ownable {
@param _expirationTime The time when the `_right` expires for the provided
`_circumstance`.
*/
function setPermit(
address _address,
bytes32 _circumstance,
bytes32 _right,
uint256 _expirationTime
) public virtual hasValidPermit(UNIVERSAL, managerRight[_right]) {
require(_right != ZERO_RIGHT,
"P2");
permissions[_address][_circumstance][_right] = _expirationTime;
emit PermitUpdated(_msgSender(), _address, _circumstance, _right,
_expirationTime);
}

// /**
// Version of setPermit() that works with multiple addresses in one transaction.

// @param _addresses The array of addresses to assign the specified `_right` to.
// @param _circumstances The array of circumstances in which the `_right` is
// valid.
// @param _rights The array of specific rights to assign.
// @param _expirationTimes The array of times when the `_rights` expires for
// the provided _circumstance`.
// */
// function setPermits(
// address[] memory _addresses,
// bytes32[] memory _circumstances,
// bytes32[] memory _rights,
// uint256[] memory _expirationTimes
// ) public virtual {
// require((_addresses.length == _circumstances.length)
// && (_circumstances.length == _rights.length)
// && (_rights.length == _expirationTimes.length),
// "leghts of input arrays are not equal"
// );
// bytes32 lastRight;
// for(uint i = 0; i < _rights.length; i++) {
// if (lastRight != _rights[i] || (i == 0)) {
// require(_msgSender() == owner() || hasRight(_msgSender(), _circumstances[i], _rights[i]), "P1");
// require(_rights[i] != ZERO_RIGHT, "P2");
// lastRight = _rights[i];
// }
// permissions[_addresses[i]][_circumstances[i]][_rights[i]] = _expirationTimes[i];
// }
// emit PermitsUpdated(
// _msgSender(),
// _addresses,
// _circumstances,
// _rights,
// _expirationTimes
// );
// }

/**
function setPermit(
address _address,
bytes32 _circumstance,
bytes32 _right,
uint256 _expirationTime
) public virtual hasValidPermit(UNIVERSAL, managerRight[_right]) {
require(_right != ZERO_RIGHT, "P2");
permissions[_address][_circumstance][_right] = _expirationTime;
emit PermitUpdated(
_msgSender(),
_address,
_circumstance,
_right,
_expirationTime
);
}

// /**
// Version of setPermit() that works with multiple addresses in one transaction.

// @param _addresses The array of addresses to assign the specified `_right` to.
// @param _circumstances The array of circumstances in which the `_right` is
// valid.
// @param _rights The array of specific rights to assign.
// @param _expirationTimes The array of times when the `_rights` expires for
// the provided _circumstance`.
// */
// function setPermits(
// address[] memory _addresses,
// bytes32[] memory _circumstances,
// bytes32[] memory _rights,
// uint256[] memory _expirationTimes
// ) public virtual {
// require((_addresses.length == _circumstances.length)
// && (_circumstances.length == _rights.length)
// && (_rights.length == _expirationTimes.length),
// "leghts of input arrays are not equal"
// );
// bytes32 lastRight;
// for(uint i = 0; i < _rights.length; i++) {
// if (lastRight != _rights[i] || (i == 0)) {
// require(_msgSender() == owner() || hasRight(_msgSender(), _circumstances[i], _rights[i]), "P1");
// require(_rights[i] != ZERO_RIGHT, "P2");
// lastRight = _rights[i];
// }
// permissions[_addresses[i]][_circumstances[i]][_rights[i]] = _expirationTimes[i];
// }
// emit PermitsUpdated(
// _msgSender(),
// _addresses,
// _circumstances,
// _rights,
// _expirationTimes
// );
// }

/**
Set the `_managerRight` whose `UNIVERSAL` holders may freely manage the
specified `_managedRight`.

Expand All @@ -241,13 +245,13 @@ abstract contract PermitControl is Ownable {
@param _managerRight The right whose `UNIVERSAL` holders may manage
`_managedRight`.
*/
function setManagerRight(
bytes32 _managedRight,
bytes32 _managerRight
) external virtual hasValidPermit(UNIVERSAL, MANAGER) {
require(_managedRight != ZERO_RIGHT,
"P3");
managerRight[_managedRight] = _managerRight;
emit ManagementUpdated(_msgSender(), _managedRight, _managerRight);
}
}
function setManagerRight(bytes32 _managedRight, bytes32 _managerRight)
external
virtual
hasValidPermit(UNIVERSAL, MANAGER)
{
require(_managedRight != ZERO_RIGHT, "P3");
managerRight[_managedRight] = _managerRight;
emit ManagementUpdated(_msgSender(), _managedRight, _managerRight);
}
}
Loading