Skip to content

Commit

Permalink
Extract calculateTbtcAmount function
Browse files Browse the repository at this point in the history
Here we extract the tbtc amount calculation logic to a separate
`calculateTbtcAmount` function. We are making it `virtual` to allow
child contracts override it if they need to do so.
  • Loading branch information
lukasz-zimnoch committed Jan 29, 2024
1 parent 47dd043 commit 0bb665f
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions solidity/contracts/bridge/DepositorProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,28 @@ abstract contract DepositorProxy {
// being called again for the same deposit.
delete pendingDeposits[depositKey];

uint256 tbtcAmount = calculateTbtcAmount(
deposit.amount,
deposit.treasuryFee
);

emit DepositFinalized(
depositKey,
tbtcAmount,
/* solhint-disable-next-line not-rely-on-time */
uint32(block.timestamp)
);

onDepositFinalized(depositKey, tbtcAmount, deposit.extraData);
}

function calculateTbtcAmount(
uint64 depositAmountSat,
uint64 depositTreasuryFeeSat
) internal virtual view returns (uint256) {
// Both deposit amount and treasury fee are in the 1e8 satoshi precision.
// We need to convert them to the 1e18 TBTC precision.
uint256 amountSubTreasury = (deposit.amount - deposit.treasuryFee) *
uint256 amountSubTreasury = (depositAmountSat - depositTreasuryFeeSat) *
SATOSHI_MULTIPLIER;

uint256 omFeeDivisor = tbtcVault.optimisticMintingFeeDivisor();
Expand All @@ -113,16 +132,7 @@ abstract contract DepositorProxy {
(,,uint64 depositTxMaxFee,) = bridge.depositParameters();
uint256 txMaxFee = depositTxMaxFee * SATOSHI_MULTIPLIER;

uint256 tbtcAmount = amountSubTreasury - omFee - txMaxFee;

emit DepositFinalized(
depositKey,
tbtcAmount,
/* solhint-disable-next-line not-rely-on-time */
uint32(block.timestamp)
);

onDepositFinalized(depositKey, tbtcAmount, deposit.extraData);
return amountSubTreasury - omFee - txMaxFee;
}

function onDepositFinalized(
Expand Down

0 comments on commit 0bb665f

Please sign in to comment.