Skip to content

Commit

Permalink
Use deposit amounts from AbstractDepositorContract
Browse files Browse the repository at this point in the history
The abstract contract exposes the values, so the implementation doesn't
have to interact with the bridge and do any precision conversion.
These changes depend on:
keep-network/tbtc-v2#791
  • Loading branch information
nkuba committed Feb 27, 2024
1 parent 0787a6a commit fefbc11
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
29 changes: 11 additions & 18 deletions core/contracts/AcreBitcoinDepositor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ contract AcreBitcoinDepositor is AbstractTBTCDepositor, Ownable2Step {

/// @dev Attempted to set minimum stake amount to a value lower than the
/// tBTC Bridge deposit dust threshold.
error MinStakeAmountLowerThanBridgeDepositDustThreshold(
error MinStakeAmountLowerThanBridgeMinDeposit(
uint256 minStakeAmount,
uint256 bridgeMinDepositAmount
);
Expand Down Expand Up @@ -321,7 +321,7 @@ contract AcreBitcoinDepositor is AbstractTBTCDepositor, Ownable2Step {
// We don't check if the request was already initialized, as this check
// is enforced in `_initializeDeposit` when calling the
// `Bridge.revealDepositWithExtraData` function.
uint256 depositKey = _initializeDeposit(
(uint256 depositKey, uint256 initialDepositAmount) = _initializeDeposit(
fundingTx,
reveal,
encodeExtraData(staker, referral)
Expand All @@ -333,11 +333,11 @@ contract AcreBitcoinDepositor is AbstractTBTCDepositor, Ownable2Step {
StakeRequestState.Initialized
);

uint256 depositAmount = bridge.deposits(depositKey).amount *
SATOSHI_MULTIPLIER;

if (depositAmount > maxSingleStakeAmount)
revert ExceededMaxSingleStake(depositAmount, maxSingleStakeAmount);
if (initialDepositAmount > maxSingleStakeAmount)
revert ExceededMaxSingleStake(
initialDepositAmount,
maxSingleStakeAmount
);

emit StakeRequestInitialized(depositKey, msg.sender, staker);
}
Expand Down Expand Up @@ -510,20 +510,13 @@ contract AcreBitcoinDepositor is AbstractTBTCDepositor, Ownable2Step {
function updateMinStakeAmount(
uint256 newMinStakeAmount
) external onlyOwner {
// Read tBTC Bridge Deposit Dust Threshold in satoshi precision.
(uint64 bridgeDepositDustThresholdSat, , , ) = bridge
.depositParameters();

// Convert tBTC Bridge Deposit Dust Threshold to tBTC token precision.
uint256 bridgeDepositDustThreshold = uint256(
bridgeDepositDustThresholdSat
) * SATOSHI_MULTIPLIER;
uint256 minBridgeDepositAmount = _minDepositAmount();

// Check if new value is at least equal the tBTC Bridge Deposit Dust Threshold.
if (newMinStakeAmount < bridgeDepositDustThreshold)
revert MinStakeAmountLowerThanBridgeDepositDustThreshold(
if (newMinStakeAmount < minBridgeDepositAmount)
revert MinStakeAmountLowerThanBridgeMinDeposit(
newMinStakeAmount,
bridgeDepositDustThreshold
minBridgeDepositAmount
);

minStakeAmount = newMinStakeAmount;
Expand Down
2 changes: 1 addition & 1 deletion core/test/AcreBitcoinDepositor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@ describe("AcreBitcoinDepositor", () => {
)
.to.be.revertedWithCustomError(
bitcoinDepositor,
"MinStakeAmountLowerThanBridgeDepositDustThreshold",
"MinStakeAmountLowerThanBridgeMinDeposit",
)
.withArgs(newMinStakeAmount, bridgeDepositDustThreshold)
})
Expand Down

0 comments on commit fefbc11

Please sign in to comment.