-
Notifications
You must be signed in to change notification settings - Fork 49
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
feat(staking): add BTC support #60
Conversation
@andresaiello can you, please, take a look and see if this look right? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Will merge after I check it out on the real testnet. |
New dependencies detected. Learn more about Socket for GitHub ↗︎
|
👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎ This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. Ignoring: Next stepsTake a deeper look at the dependencyTake a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev. Remove the packageIf you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency. Mark a package as acceptable riskTo ignore an alert, reply with a comment starting with |
@SocketSecurity ignore [email protected] |
SystemContract public immutable systemContract; | ||
uint256 public immutable chainID; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think immutable could be written in full uppercase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's not the solidity standard and is not the one with use. is more important to be consistent with all the contracts.
|
||
SystemContract public immutable systemContract; | ||
uint256 public immutable chainID; | ||
uint256 public rewardRate = 1; | ||
uint256 constant BITCOIN = 18332; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be more visual grouping immutable and constant together, no public between
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mapping(address => address) public beneficiaries; | ||
mapping(address => uint256) public lastStakeTime; | ||
uint256 public rewardRate = 1; | ||
|
||
constructor( | ||
string memory name_, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string memory name_, | |
string memory _name, |
Same comment for variables below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's the old standard. in current solidity standard _ at the end means avoid name collision and at the beginning is only for private names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, didn't know that, I've never seen this standard
mapping(address => uint256) public stakes; | ||
mapping(address => bytes) public withdrawAddresses; | ||
mapping(address => address) public beneficiaries; | ||
mapping(address => uint256) public lastStakeTime; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage of singulare/plural is not consistent.
We might want to have lastStakeTimes
or using stake
, etc..
Since these are maps I would tend to say singular makes more sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_; | ||
} | ||
|
||
function bytesToBech32Bytes( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this one could be internal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -9,15 +9,17 @@ import "@zetachain/toolkit/contracts/BytesHelperLib.sol"; | |||
contract Staking is ERC20, zContract { | |||
error SenderNotSystemContract(); | |||
error WrongChain(); | |||
error NotAuthorizedToClaim(); | |||
error UnknownAction(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can set attributes to error, UnknownAction(uint action)
. In practice this allows to have a more explicit error, this might be a good thing to show in the tutorial
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the comments, @lumtis! Really appreciate it! |
beneficiaries[staker] = beneficiary; | ||
} | ||
lastStakeTime[staker] = block.timestamp; | ||
require(stakes[staker] >= amount, "Overflow detected"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change it to custom errors like the others
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IZRC20(zrc20).withdraw(abi.encodePacked(msg.sender), amount - gasFee); | ||
IZRC20(zrc20).withdraw(recipient, amount - gasFee); | ||
|
||
stakes[staker] = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be aligned with check then do pattern, move this before the withdrawal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reviewing, @andresaiello & @lumtis! |
Mofidied the contract to work with EVM and Bitcoin.