diff --git a/solidity/contracts/integrator/AbstractTBTCDepositor.sol b/solidity/contracts/integrator/AbstractTBTCDepositor.sol index 7aeab8844..0ba4928ba 100644 --- a/solidity/contracts/integrator/AbstractTBTCDepositor.sol +++ b/solidity/contracts/integrator/AbstractTBTCDepositor.sol @@ -54,7 +54,7 @@ import "./ITBTCVault.sol"; /// // Embed necessary context as extra data. /// bytes32 extraData = ...; /// -/// uint256 depositKey = _initializeDeposit( +/// (uint256 depositKey, uint256 initialDepositAmount) = _initializeDeposit( /// fundingTx, /// reveal, /// extraData @@ -123,6 +123,8 @@ abstract contract AbstractTBTCDepositor { /// `keccak256(fundingTxHash | reveal.fundingOutputIndex)`. This /// key can be used to refer to the deposit in the Bridge and /// TBTCVault contracts. + /// @return initialDepositAmount Amount of funding transaction deposit. In + /// TBTC token decimals precision. /// @dev Requirements: /// - The revealed vault address must match the TBTCVault address, /// - All requirements from {Bridge#revealDepositWithExtraData} @@ -134,10 +136,10 @@ abstract contract AbstractTBTCDepositor { IBridgeTypes.BitcoinTxInfo calldata fundingTx, IBridgeTypes.DepositRevealInfo calldata reveal, bytes32 extraData - ) internal returns (uint256) { + ) internal returns (uint256 depositKey, uint256 initialDepositAmount) { require(reveal.vault == address(tbtcVault), "Vault address mismatch"); - uint256 depositKey = _calculateDepositKey( + depositKey = _calculateDepositKey( _calculateBitcoinTxHash(fundingTx), reveal.fundingOutputIndex ); @@ -148,7 +150,9 @@ abstract contract AbstractTBTCDepositor { // an explicit check here. bridge.revealDepositWithExtraData(fundingTx, reveal, extraData); - return depositKey; + initialDepositAmount = + bridge.deposits(depositKey).amount * + SATOSHI_MULTIPLIER; } /// @notice Finalizes a deposit by calculating the amount of TBTC minted @@ -289,4 +293,16 @@ abstract contract AbstractTBTCDepositor { ) .hash256View(); } + + /// @notice Returns minimum deposit amount. + /// @return Minimum deposit amount. In TBTC token decimals precision. + // slither-disable-next-line dead-code + function _minDepositAmount() internal view returns (uint256) { + // Read tBTC Bridge Deposit Dust Threshold in satoshi precision. + (uint64 bridgeDepositDustThresholdSat, , , ) = bridge + .depositParameters(); + + // Convert tBTC Bridge Deposit Dust Threshold to TBTC token precision. + return bridgeDepositDustThresholdSat * SATOSHI_MULTIPLIER; + } } diff --git a/solidity/contracts/test/TestTBTCDepositor.sol b/solidity/contracts/test/TestTBTCDepositor.sol index bf0a2d5ea..a54155b11 100644 --- a/solidity/contracts/test/TestTBTCDepositor.sol +++ b/solidity/contracts/test/TestTBTCDepositor.sol @@ -11,7 +11,10 @@ import "../integrator/ITBTCVault.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; contract TestTBTCDepositor is AbstractTBTCDepositor { - event InitializeDepositReturned(uint256 depositKey); + event InitializeDepositReturned( + uint256 depositKey, + uint256 initialDepositAmount + ); event FinalizeDepositReturned( uint256 initialDepositAmount, @@ -28,8 +31,12 @@ contract TestTBTCDepositor is AbstractTBTCDepositor { IBridgeTypes.DepositRevealInfo calldata reveal, bytes32 extraData ) external { - uint256 depositKey = _initializeDeposit(fundingTx, reveal, extraData); - emit InitializeDepositReturned(depositKey); + (uint256 depositKey, uint256 initialDepositAmount) = _initializeDeposit( + fundingTx, + reveal, + extraData + ); + emit InitializeDepositReturned(depositKey, initialDepositAmount); } function finalizeDepositPublic(uint256 depositKey) external { @@ -51,6 +58,10 @@ contract TestTBTCDepositor is AbstractTBTCDepositor { ) external view returns (uint256) { return _calculateTbtcAmount(depositAmountSat, depositTreasuryFeeSat); } + + function minDepositAmountPublic() external view returns (uint256) { + return _minDepositAmount(); + } } contract MockBridge is IBridge { diff --git a/solidity/test/integrator/AbstractTBTCDepositor.test.ts b/solidity/test/integrator/AbstractTBTCDepositor.test.ts index 14b51c25f..fda52941f 100644 --- a/solidity/test/integrator/AbstractTBTCDepositor.test.ts +++ b/solidity/test/integrator/AbstractTBTCDepositor.test.ts @@ -9,7 +9,6 @@ import type { import { to1ePrecision } from "../helpers/contract-test-helpers" const { createSnapshot, restoreSnapshot } = helpers.snapshot -const { lastBlockTime } = helpers.time const loadFixture = (vault: string) => ({ fundingTx: { @@ -109,6 +108,8 @@ describe("AbstractTBTCDepositor", () => { }) context("when deposit is accepted by the Bridge", () => { + const expectedInitialDepositAmount = to1ePrecision(10000, 10) + let tx: ContractTransaction before(async () => { @@ -134,7 +135,7 @@ describe("AbstractTBTCDepositor", () => { it("should return proper values", async () => { await expect(tx) .to.emit(depositor, "InitializeDepositReturned") - .withArgs(fixture.expectedDepositKey) + .withArgs(fixture.expectedDepositKey, expectedInitialDepositAmount) }) }) }) @@ -438,4 +439,24 @@ describe("AbstractTBTCDepositor", () => { }) }) }) + + describe("_minDepositAmount", () => { + before(async () => { + await createSnapshot() + + // Set deposit dust threshold to 0.1 BTC. + await bridge.setDepositDustThreshold(1000000) + }) + + after(async () => { + await restoreSnapshot() + }) + + it("returns value in TBTC token precision", async () => { + // 1000000 sat * 1e10 TBTC + expect(await depositor.minDepositAmountPublic()).to.be.equal( + to1ePrecision(1000000, 10) + ) + }) + }) })