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

feat(staking): add BTC support #60

Merged
merged 28 commits into from
Sep 22, 2023
Merged

feat(staking): add BTC support #60

merged 28 commits into from
Sep 22, 2023

Conversation

fadeev
Copy link
Member

@fadeev fadeev commented Sep 5, 2023

Mofidied the contract to work with EVM and Bitcoin.

@fadeev
Copy link
Member Author

fadeev commented Sep 5, 2023

@andresaiello can you, please, take a look and see if this look right?

Copy link
Collaborator

@andresaiello andresaiello left a comment

Choose a reason for hiding this comment

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

LGTM

@fadeev fadeev marked this pull request as ready for review September 5, 2023 15:52
@fadeev fadeev requested a review from lucas-janon as a code owner September 5, 2023 15:52
@fadeev
Copy link
Member Author

fadeev commented Sep 5, 2023

Will merge after I check it out on the real testnet.

@fadeev fadeev marked this pull request as draft September 13, 2023 07:42
@fadeev fadeev marked this pull request as ready for review September 20, 2023 15:48
@fadeev fadeev requested a review from andresaiello September 20, 2023 15:48
@socket-security
Copy link

New dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
@zetachain/toolkit 2.2.2 network, filesystem, environment +91 28.5 MB lucasjanon
@types/node 20.6.3 None +0 3.86 MB types

@socket-security
Copy link

socket-security bot commented Sep 21, 2023

👍 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: [email protected]

Next steps

Take a deeper look at the dependency

Take 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 package

If 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 risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of package-name@version specifiers. e.g. @SocketSecurity ignore [email protected] bar@* or ignore all packages with @SocketSecurity ignore-all

@fadeev
Copy link
Member Author

fadeev commented Sep 21, 2023

@SocketSecurity ignore [email protected]

Comment on lines 14 to 15
SystemContract public immutable systemContract;
uint256 public immutable chainID;
Copy link
Member

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.

Copy link
Collaborator

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;
Copy link
Member

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

Copy link
Member Author

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_,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
string memory name_,
string memory _name,

Same comment for variables below

Copy link
Collaborator

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

Copy link
Member

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

Comment on lines 19 to 22
mapping(address => uint256) public stakes;
mapping(address => bytes) public withdrawAddresses;
mapping(address => address) public beneficiaries;
mapping(address => uint256) public lastStakeTime;
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

_;
}

function bytesToBech32Bytes(
Copy link
Member

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

Copy link
Member Author

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();
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

omnichain/staking/contracts/Staking.sol Outdated Show resolved Hide resolved
@fadeev
Copy link
Member Author

fadeev commented Sep 21, 2023

Thanks for all the comments, @lumtis! Really appreciate it!

beneficiaries[staker] = beneficiary;
}
lastStakeTime[staker] = block.timestamp;
require(stakes[staker] >= amount, "Overflow detected");
Copy link
Collaborator

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

Copy link
Member Author

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;
Copy link
Collaborator

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

Copy link
Member Author

Choose a reason for hiding this comment

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

@fadeev
Copy link
Member Author

fadeev commented Sep 22, 2023

Thanks for reviewing, @andresaiello & @lumtis!

@fadeev fadeev merged commit abb7a57 into main Sep 22, 2023
4 checks passed
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