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

Staking #52

Merged
merged 65 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
05030cf
Add OpenZeppelin contracts
r-czajkowski Nov 24, 2023
c80b77c
Update solhint rules
r-czajkowski Nov 24, 2023
3ebb88b
Initial implementation of the main Acre contract
r-czajkowski Nov 24, 2023
c81cfd5
Add initial implementation of the stake function.
r-czajkowski Nov 24, 2023
e754aca
Add `@thesis/solidity-contracts` dependency
r-czajkowski Nov 27, 2023
f36c65c
Add support for receive approval pattern to Acre
r-czajkowski Nov 27, 2023
14c14e1
Add test token contract
r-czajkowski Nov 27, 2023
02c2b3b
Add basic unit tests for staking
r-czajkowski Nov 27, 2023
a9b6c0c
Remove unnecessary `super` keyword
r-czajkowski Nov 28, 2023
a4f9f87
Update the name of the ERC4626 token
r-czajkowski Nov 28, 2023
028319f
Remove unnecessary undersocre for `_token`
r-czajkowski Nov 28, 2023
f1a126b
Update the `stake` function
r-czajkowski Nov 28, 2023
684d667
Update the Acre unit tests
r-czajkowski Nov 28, 2023
829c3ed
Rename param in `stake` function
r-czajkowski Nov 28, 2023
ffaaba6
Update `Acre` unit tests
r-czajkowski Nov 28, 2023
142c71f
Merge branch 'main' into token-vault
r-czajkowski Nov 28, 2023
b8a5b96
Fix typo
r-czajkowski Nov 30, 2023
6132a7b
Add more unit tests for staking flow
r-czajkowski Nov 30, 2023
3a3cb35
Add `Staked` event
r-czajkowski Nov 30, 2023
e319a62
Merge branch 'main' into token-vault
r-czajkowski Nov 30, 2023
6837e74
Revert "Add support for receive approval pattern to Acre"
r-czajkowski Nov 30, 2023
c960102
Remove unit tests for receive approval pattern
r-czajkowski Nov 30, 2023
c3c674d
Merge branch 'main' into token-vault
r-czajkowski Nov 30, 2023
58d2ddd
Rename variable in fixture
r-czajkowski Nov 30, 2023
05b2091
Update unit test for staking
r-czajkowski Nov 30, 2023
a77b1a4
Rename variable
r-czajkowski Nov 30, 2023
4c9eeec
Fix typo
r-czajkowski Nov 30, 2023
249fb11
Rename variable in tests
r-czajkowski Nov 30, 2023
20086c6
Update staking flow unit tests
r-czajkowski Nov 30, 2023
63aac1b
Use unnamed return in the `stake` fn
r-czajkowski Dec 4, 2023
e923f5e
Leave TODO in the `stake` fn
r-czajkowski Dec 4, 2023
5403ac3
Rename constructor parameter in Acre
r-czajkowski Dec 4, 2023
6511fef
Remove `@thesis/solidity-contracts` dependency
r-czajkowski Dec 4, 2023
84bdf8e
Add unit test heleprs
r-czajkowski Dec 4, 2023
ce16fba
Add more unit tests for staking
r-czajkowski Dec 4, 2023
c3a2bd8
Update solhint config
r-czajkowski Dec 4, 2023
b20259e
Add more stakers to the Acre test fixture
r-czajkowski Dec 4, 2023
300b2a9
Rename variable in Acre unit tests
r-czajkowski Dec 5, 2023
44b3f85
Update comment in Acre unit tests
r-czajkowski Dec 5, 2023
b84ee1b
Update staking flow unit tests
r-czajkowski Dec 5, 2023
3a312f7
Add documentation comments for `Acre` contract
r-czajkowski Dec 5, 2023
05fb49d
Merge branch 'main' into token-vault
r-czajkowski Dec 5, 2023
277dc1e
Rename `Staked` event
r-czajkowski Dec 5, 2023
eb91b4d
Update the `stake` fn
r-czajkowski Dec 5, 2023
fbb2085
Update `stake` fn docs
r-czajkowski Dec 5, 2023
48eeed3
Rename variable in Acre unit tests
r-czajkowski Dec 5, 2023
f7003b8
Rename variable in `acreFixture`
r-czajkowski Dec 5, 2023
076a29c
Update the `acreFixture` fn
r-czajkowski Dec 5, 2023
961580b
Update the test name
r-czajkowski Dec 5, 2023
9674f5e
Rename file
r-czajkowski Dec 5, 2023
9737ed8
Avoid infinite approvals in unit tests
r-czajkowski Dec 5, 2023
d33c552
Get rid of unnecessary `Staker` type in unit tests
r-czajkowski Dec 5, 2023
eef74bc
Hardcode expected values in unit tests
r-czajkowski Dec 5, 2023
8a243cf
Remove unnecessary check in unit test
r-czajkowski Dec 5, 2023
b812107
Rename test context name
r-czajkowski Dec 5, 2023
910a399
Update `without referral` test case
r-czajkowski Dec 5, 2023
a868dce
Improve test case
r-czajkowski Dec 5, 2023
567b52c
Make sure the tx is reverted with expected reason
r-czajkowski Dec 5, 2023
4889a03
Use dedicated variable in unit test
r-czajkowski Dec 5, 2023
9cac49c
Update staking unit tests
r-czajkowski Dec 5, 2023
88ee4d6
Complicate the math in test scenario
r-czajkowski Dec 5, 2023
2750286
Improve Acre contract docs comment
r-czajkowski Dec 6, 2023
ed73109
Remove unnecessary check expectation in test
r-czajkowski Dec 6, 2023
68b81d0
Remove unnecessary check
r-czajkowski Dec 6, 2023
e55dad2
Merge branch 'main' into token-vault
r-czajkowski Dec 6, 2023
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: 1 addition & 2 deletions core/.solhint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"extends": "thesis",
"plugins": [],
"rules": {}
"plugins": []
}
41 changes: 37 additions & 4 deletions core/contracts/Acre.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,42 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.21;

// Uncomment this line to use console.log
// import "hardhat/console.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol";

contract Acre {
// TODO: add your implementation
/// @title Acre
/// @notice Implementation of the ERR-4626 tokenized vault standard. ERC-4626 is
/// a standard to optimize and unify the technical parameters of
/// yield-bearing vaults. This contract allows the minting and burning
/// of shares, represented as standard ERC20 token, in exchange for tBTC
/// tokens.
/// @dev ERC-4626 standard extends the ERC-20 token.
contract Acre is ERC4626 {
dimpar marked this conversation as resolved.
Show resolved Hide resolved
event StakeReferral(bytes32 indexed referral, uint256 assets);

constructor(
IERC20 tbtc
) ERC4626(tbtc) ERC20("Acre Staked Bitcoin", "stBTC") {}

dimpar marked this conversation as resolved.
Show resolved Hide resolved
/// @notice Stakes a given amount of tBTC token and mints shares to a
/// receiver.
/// @dev This function calls `deposit` function from `ERC4626` contract. The
/// amount of the assets has to be pre-approved in the tBTC contract.
/// @param assets Approved amount for the transfer and stake.
/// @param receiver The address to which the shares will be minted.
/// @param referral Data used for referral program.
/// @return shares Minted shares.
function stake(
uint256 assets,
address receiver,
bytes32 referral
dimpar marked this conversation as resolved.
Show resolved Hide resolved
) public returns (uint256) {
// TODO: revisit the type of referral.
uint256 shares = deposit(assets, receiver);

if (referral != bytes32(0)) {
emit StakeReferral(referral, assets);
}

return shares;
dimpar marked this conversation as resolved.
Show resolved Hide resolved
}
}
12 changes: 12 additions & 0 deletions core/contracts/test/TestERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.21;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract TestERC20 is ERC20 {
constructor() ERC20("Test Token", "TEST") {}

function mint(address account, uint256 value) external {
_mint(account, value);
}
}
3 changes: 3 additions & 0 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@
"ts-node": "^10.9.1",
"typechain": "^8.3.2",
"typescript": "^5.3.2"
},
"dependencies": {
"@openzeppelin/contracts": "^5.0.0"
}
}
Loading
Loading