Skip to content

Commit

Permalink
Merge branch 'main' into redesign-dapp
Browse files Browse the repository at this point in the history
  • Loading branch information
kkosiorowska authored Sep 4, 2024
2 parents a4c7ebe + 11dc037 commit 33c057d
Show file tree
Hide file tree
Showing 13 changed files with 1,750 additions and 205 deletions.
2 changes: 1 addition & 1 deletion dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@chakra-ui/react": "^2.8.2",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@orangekit/react": "1.0.0-beta.29",
"@orangekit/react": "1.0.0-beta.30",
"@orangekit/sign-in-with-wallet": "1.0.0-beta.6",
"@reduxjs/toolkit": "^2.2.0",
"@rehooks/local-storage": "^2.4.5",
Expand Down
38 changes: 10 additions & 28 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@acre-btc/contracts": "workspace:*",
"@keep-network/tbtc-v2.ts": "2.5.0-dev.3",
"@ledgerhq/wallet-api-client": "1.5.0",
"@orangekit/sdk": "1.0.0-beta.14",
"@orangekit/sdk": "1.0.0-beta.16",
"@swan-bitcoin/xpub-lib": "0.1.5",
"ethers": "6.10.0",
"ethers-v5": "npm:ethers@^5.5.2"
Expand Down
60 changes: 46 additions & 14 deletions solidity/contracts/MezoAllocator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,15 @@ contract MezoAllocator is IDispatcher, Ownable2StepUpgradeable {
uint256 newDepositAmount
);
/// @notice Emitted when tBTC is withdrawn from MezoPortal.
event DepositWithdrawn(uint256 indexed depositId, uint256 amount);
/// If MezoAllocator has a positive balance part of the requested amount
/// is withdrawn from MezoAllocator and the rest from MezoPortal.
event WithdrawFromMezoPortal(
uint256 indexed depositId,
uint256 requestedAmount,
uint256 amountWithdrawnFromPortal
);
/// @notice Emitted when tBTC is withdrawn from MezoAllocator.
event WithdrawFromMezoAllocator(uint256 amount);
/// @notice Emitted when the maintainer address is updated.
event MaintainerAdded(address indexed maintainer);
/// @notice Emitted when the maintainer address is updated.
Expand All @@ -142,6 +150,12 @@ contract MezoAllocator is IDispatcher, Ownable2StepUpgradeable {
error MaintainerNotRegistered();
/// @notice Reverts if the maintainer has been already registered.
error MaintainerAlreadyRegistered();
/// @notice Reverts if the requested amount to withdraw exceeds the amount
/// deposited in the Mezo Portal.
error WithdrawalAmountExceedsDepositBalance(
uint256 requestedAmount,
uint256 depositAmount
);

modifier onlyMaintainer() {
if (!isMaintainer[msg.sender]) {
Expand Down Expand Up @@ -225,20 +239,35 @@ contract MezoAllocator is IDispatcher, Ownable2StepUpgradeable {
function withdraw(uint256 amount) external {
if (msg.sender != address(stbtc)) revert CallerNotStbtc();

emit DepositWithdrawn(depositId, amount);
uint256 unallocatedBalance = tbtc.balanceOf(address(this));

if (amount > unallocatedBalance) {
uint256 amountToWithdraw = amount - unallocatedBalance;

emit WithdrawFromMezoPortal(depositId, amount, amountToWithdraw);

if (amountToWithdraw < depositBalance) {
mezoPortal.withdrawPartially(
address(tbtc),
depositId,
uint96(amountToWithdraw)
);
// slither-disable-next-line incorrect-equality
} else if (amountToWithdraw == depositBalance) {
mezoPortal.withdraw(address(tbtc), depositId);
} else {
revert WithdrawalAmountExceedsDepositBalance(
amountToWithdraw,
depositBalance
);
}

if (amount < depositBalance) {
mezoPortal.withdrawPartially(
address(tbtc),
depositId,
uint96(amount)
);
// slither-disable-next-line reentrancy-no-eth
depositBalance -= uint96(amountToWithdraw);
} else {
mezoPortal.withdraw(address(tbtc), depositId);
emit WithdrawFromMezoAllocator(amount);
}

// slither-disable-next-line reentrancy-no-eth
depositBalance -= uint96(amount);
tbtc.safeTransfer(address(stbtc), amount);
}

Expand All @@ -250,9 +279,12 @@ contract MezoAllocator is IDispatcher, Ownable2StepUpgradeable {
.getDeposit(address(this), address(tbtc), depositId)
.balance;

emit DepositReleased(depositId, amount);
depositBalance = 0;
mezoPortal.withdraw(address(tbtc), depositId);
if (amount > 0) {
emit DepositReleased(depositId, amount);
depositBalance = 0;
mezoPortal.withdraw(address(tbtc), depositId);
}

tbtc.safeTransfer(address(stbtc), tbtc.balanceOf(address(this)));
}

Expand Down
2 changes: 1 addition & 1 deletion solidity/deploy/33_update_debt_allowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {

const mezoPortal = await deployments.get("MezoPortal")

const debtAllowance = 500000000000000000000n // 500 stBTC
const debtAllowance = 1000000000000000000000n // 1000 stBTC

log(`updating debt allowance for ${mezoPortal.address}`)

Expand Down
Loading

0 comments on commit 33c057d

Please sign in to comment.