Skip to content

Add Deposit method #10

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
41 changes: 28 additions & 13 deletions src/SystemStaking2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ contract SystemStaking2 is ERC721, Ownable, Pausable {
mapping(uint256 => Bucket) private __buckets;
// beneficiary of donation
address payable public beneficiary;

//// delegate address -> bucket type -> count
constructor(uint256 _minAmount, address payable _beneficiary) ERC721("BucketNFT", "BKT") {
MIN_AMOUNT = _minAmount;
Expand Down Expand Up @@ -148,10 +149,7 @@ contract SystemStaking2 is ERC721, Ownable, Pausable {
}
}

function lock(
uint256 _bucketId,
uint256 _duration
) external whenNotPaused {
function lock(uint256 _bucketId, uint256 _duration) external whenNotPaused {
_assertDuration(_duration);
_lock(_bucketId, _duration);
}
Expand Down Expand Up @@ -241,10 +239,14 @@ contract SystemStaking2 is ERC721, Ownable, Pausable {
emit BucketExpanded(_bucketId, bucket.amount, _newDuration);
}

function changeDelegate(
uint256 _bucketId,
address _delegate
) external whenNotPaused {
function deposit(uint256 _bucketId) external payable whenNotPaused {
Bucket storage bucket = __buckets[_bucketId];
_assertInLock(bucket.unlockedAt);
bucket.amount += msg.value;
emit BucketExpanded(_bucketId, bucket.amount, bucket.duration);
}

function changeDelegate(uint256 _bucketId, address _delegate) external whenNotPaused {
_changeDelegate(_bucketId, _delegate);
}

Expand Down Expand Up @@ -338,7 +340,10 @@ contract SystemStaking2 is ERC721, Ownable, Pausable {
}
}

function _blocksToUnstake(uint256 _unlockedAt, uint256 _duration) internal view returns (uint256) {
function _blocksToUnstake(
uint256 _unlockedAt,
uint256 _duration
) internal view returns (uint256) {
if (!_isTriggered(_unlockedAt)) {
return _duration;
}
Expand All @@ -351,15 +356,19 @@ contract SystemStaking2 is ERC721, Ownable, Pausable {
}
}

function _stake(uint256 _amount, uint256 _duration, address _delegate) internal returns (uint256) {
function _stake(
uint256 _amount,
uint256 _duration,
address _delegate
) internal returns (uint256) {
uint256 bucketId = __currBucketId = unsafeInc(__currBucketId);
__buckets[bucketId] = Bucket(_amount, _duration, UINT256_MAX, UINT256_MAX, _delegate);
_safeMint(msg.sender, bucketId);
emit Staked(bucketId, _delegate, _amount, _duration);
return bucketId;
}

function _unlock(uint256 _bucketId) internal onlyBucketOwner(_bucketId) {
function _unlock(uint256 _bucketId) internal onlyBucketOwner(_bucketId) {
Bucket storage bucket = __buckets[_bucketId];
_assertInLock(bucket.unlockedAt);
bucket.unlockedAt = block.number;
Expand Down Expand Up @@ -387,7 +396,10 @@ contract SystemStaking2 is ERC721, Ownable, Pausable {
emit Unstaked(_bucketId);
}

function _withdraw(uint256 _bucketId, address payable _recipient) internal onlyBucketOwner(_bucketId) {
function _withdraw(
uint256 _bucketId,
address payable _recipient
) internal onlyBucketOwner(_bucketId) {
Bucket storage bucket = __buckets[_bucketId];
if (_blocksToWithdraw(bucket.unstakedAt) != 0) {
revert ErrNotReady();
Expand All @@ -397,7 +409,10 @@ contract SystemStaking2 is ERC721, Ownable, Pausable {
emit Withdrawal(_bucketId, _recipient);
}

function _changeDelegate(uint256 _bucketId, address _newDelegate) internal onlyBucketOwner(_bucketId) {
function _changeDelegate(
uint256 _bucketId,
address _newDelegate
) internal onlyBucketOwner(_bucketId) {
Bucket storage _bucket = __buckets[_bucketId];
_assertInStake(_bucket.unstakedAt);
if (_bucket.delegate == _newDelegate) {
Expand Down
Loading