Skip to content

Commit

Permalink
Merge branch 'main' into acre-subgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuba authored Mar 18, 2024
2 parents 3d4e6f7 + 5dcfc76 commit 8df7eb8
Show file tree
Hide file tree
Showing 49 changed files with 6,591 additions and 2,336 deletions.
1 change: 1 addition & 0 deletions .github/workflows/reusable-core-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ jobs:
name: core-build
path: |
core/build/
core/cache/
core/typechain/
if-no-files-found: error
22 changes: 15 additions & 7 deletions core/contracts/AcreBitcoinDepositor.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.21;

import "@openzeppelin/contracts/access/Ownable2Step.sol";
import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
Expand All @@ -11,7 +11,6 @@ import "@keep-network/tbtc-v2/contracts/integrator/AbstractTBTCDepositor.sol";

import {stBTC} from "./stBTC.sol";

// TODO: Make Upgradable
// TODO: Make Pausable

/// @title Acre Bitcoin Depositor contract.
Expand All @@ -38,7 +37,10 @@ import {stBTC} from "./stBTC.sol";
/// Depositor address. After tBTC is minted to the Depositor, on the stake
/// finalization tBTC is staked in Acre and stBTC shares are emitted
/// to the staker.
contract AcreBitcoinDepositor is AbstractTBTCDepositor, Ownable2Step {
contract AcreBitcoinDepositor is
AbstractTBTCDepositor,
Ownable2StepUpgradeable
{
using SafeERC20 for IERC20;

/// @notice State of the stake request.
Expand Down Expand Up @@ -263,19 +265,25 @@ contract AcreBitcoinDepositor is AbstractTBTCDepositor, Ownable2Step {
uint256 bridgeMinDepositAmount
);

/// @notice Acre Bitcoin Depositor contract constructor.
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

/// @notice Acre Bitcoin Depositor contract initializer.
/// @param bridge tBTC Bridge contract instance.
/// @param tbtcVault tBTC Vault contract instance.
/// @param _tbtcToken tBTC token contract instance.
/// @param _stbtc stBTC contract instance.
// TODO: Move to initializer when making the contract upgradeable.
constructor(
function initialize(
address bridge,
address tbtcVault,
address _tbtcToken,
address _stbtc
) Ownable(msg.sender) {
) public initializer {
__AbstractTBTCDepositor_initialize(bridge, tbtcVault);
__Ownable2Step_init();
__Ownable_init(msg.sender);

if (address(_tbtcToken) == address(0)) {
revert TbtcTokenZeroAddress();
Expand Down
23 changes: 16 additions & 7 deletions core/contracts/stBTC.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.21;

import "@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC4626Upgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable2Step.sol";
import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";

import "./Dispatcher.sol";

/// @title stBTC
Expand All @@ -17,7 +18,7 @@ import "./Dispatcher.sol";
/// of yield-bearing vaults. This contract facilitates the minting and
/// burning of shares (stBTC), which are represented as standard ERC20
/// tokens, providing a seamless exchange with tBTC tokens.
contract stBTC is ERC4626, Ownable2Step {
contract stBTC is ERC4626Upgradeable, Ownable2StepUpgradeable {
using SafeERC20 for IERC20;

/// Dispatcher contract that routes tBTC from stBTC to a given vault and back.
Expand Down Expand Up @@ -64,14 +65,22 @@ contract stBTC is ERC4626, Ownable2Step {
/// Reverts if the address is disallowed.
error DisallowedAddress();

constructor(
IERC20 _tbtc,
address _treasury
) ERC4626(_tbtc) ERC20("Acre Staked Bitcoin", "stBTC") Ownable(msg.sender) {
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

function initialize(IERC20 asset, address _treasury) public initializer {
__ERC4626_init(asset);
__ERC20_init("Acre Staked Bitcoin", "stBTC");
__Ownable2Step_init();
__Ownable_init(msg.sender);

if (address(_treasury) == address(0)) {
revert ZeroAddress();
}
treasury = _treasury;

// TODO: Revisit the exact values closer to the launch.
minimumDepositAmount = 0.001 * 1e18; // 0.001 tBTC
maximumTotalAssets = 25 * 1e18; // 25 tBTC
Expand Down
7 changes: 0 additions & 7 deletions core/contracts/test/AcreBitcoinDepositorHarness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ import {TestERC20} from "./TestERC20.sol";
/// This solution follows Foundry recommendation:
/// https://book.getfoundry.sh/tutorials/best-practices#internal-functions
contract AcreBitcoinDepositorHarness is AcreBitcoinDepositor {
constructor(
address bridge,
address tbtcVault,
address tbtcToken,
address stbtc
) AcreBitcoinDepositor(bridge, tbtcVault, tbtcToken, stbtc) {}

function exposed_finalizeBridging(
uint256 depositKey
) external returns (uint256 amountToStake, address staker) {
Expand Down
Loading

0 comments on commit 8df7eb8

Please sign in to comment.