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

First draft of staking contract. #5

Closed
wants to merge 15 commits into from
Closed

Conversation

kellan-simiotics
Copy link

No description provided.

Copy link
Contributor

@ogarciarevett ogarciarevett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reentrancy guard issues

depositToken = IERC20(_depositToken);
}

function stake(uint256 _amount, address _receiver) external {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where's the reentrancy guard for this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

it("Should stake/unstake tokens for self", async function () {
const initialBalance = await token.balanceOf(user1.address);

await staking.connect(user1).stake(stakeAmount, user1.address);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (non-blocking): I think we should also assert events emission, especially because this gonna be used for the indexers

Suggested change
await staking.connect(user1).stake(stakeAmount, user1.address);
await expect(staking.connect(user1).stake(stakeAmount, user1.address)).to.emit("Stake", staking).withArgs(...)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added event expectations.

* @title Game7 Staking
* @author Game7 Engineering Team - [email protected]
*/
contract Staking2 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (non-blocking): I saw that the contract does not have a constructor called. It might be worth having an empty constructor since non-constructed contracts have zero code length, and some contracts use the function isContract before calling. Do we want to have the contract constructed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added constructor.

return depositsOf[user].length;
}

function deposit(address _tokenAddress, uint256 _amount, uint256 _duration, address _receiver) external {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (non-blocking): Since duration is being casted to uint64, i think it can be directly typed to uint64 in the function parameter

Suggested change
function deposit(address _tokenAddress, uint256 _amount, uint256 _duration, address _receiver) external {
function deposit(address _tokenAddress, uint256 _amount, uint64 _duration, address _receiver) external {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly address in future. Seems low priority.

emit Deposited(_tokenAddress, _receiver, msg.sender, _duration, _amount);
}

function withdraw(uint256 _depositId, address _receiver) external {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (non-blocking): As a user, I would be stressed over ensuring I am passing the right address as the receiver. I would love to have a function that receives only the deposit ID and withdraws it to the msg.sender. I think we can achieve that with function overloading:

Suggested change
function withdraw(uint256 _depositId, address _receiver) external {
function withdraw(uint256 _depositId, address _receiver) external {
_withdraw(_depositId, _receiver);
}
function withdraw(uint256 _depositId) external {
_withdraw(_depositId, msg.sender);
}
function _withdraw(uint256 _depositId, address _receiver) external {
....
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overloaded both deposit and withdraw.

return depositsOf[user].length;
}

function deposit(address _tokenAddress, uint256 _amount, uint256 _duration, address _receiver) external {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (non-blocking): As a user, I would like to know if, in the future, we want to deposit/stake multiple tokens in just one transaction. Or even stake different amounts of the same token for different periods. I want to do that in just one transaction. Maybe we should put the arguments as arrays to support that:

Suggested change
function deposit(address _tokenAddress, uint256 _amount, uint256 _duration, address _receiver) external {
function deposit(address[] memory _tokenAddresses, uint256[] memory _amounts, uint256[] memory _durations, address[] memory _receivers) external {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly, but I don't see a strong need for this right now. I believe the current plan is to incentivize just 3 different locking periods and we're not sure what other tokens we will want users to stake. The need for a batch method seems low.

require(_amount > 0, "Staking.deposit: cannot deposit 0");

IERC20 depositToken = IERC20(_tokenAddress);
depositToken.transferFrom(msg.sender, address(this), _amount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (blocking): How will we deal with the native token?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants