|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +pragma solidity >=0.8.0 <0.9.0; |
| 3 | + |
| 4 | +import { ILoan } from "../../facets/loan/ILoan.sol"; |
| 5 | +import { ITransferByPartition } from "../../facets/transferByPartition/ITransferByPartition.sol"; |
| 6 | + |
| 7 | +/** |
| 8 | + * @title MockLoanHolding |
| 9 | + * @author Asset Tokenization Studio Team |
| 10 | + * @notice Configurable test stand-in for a loan holding asset that the |
| 11 | + * LoansPortfolio facet reads from at runtime. |
| 12 | + * @dev Exposes exactly the two call surfaces the portfolio invokes: |
| 13 | + * `getLoanDetails()` (collateral classification + performance status) |
| 14 | + * and `balanceOfByPartition(...)` (ownership balance). Only the |
| 15 | + * fields the portfolio reads are configurable; all other struct |
| 16 | + * members return their type defaults. |
| 17 | + */ |
| 18 | +contract MockLoanHolding is ITransferByPartition { |
| 19 | + uint256 internal _totalCollateralValue; |
| 20 | + ILoan.PerformanceStatus internal _performanceStatus; |
| 21 | + mapping(bytes32 partition => mapping(address holder => uint256)) internal _balances; |
| 22 | + |
| 23 | + /** |
| 24 | + * @notice Sets the collateral value and performance classification. |
| 25 | + * @param totalCollateralValue_ Total collateral backing the loan. |
| 26 | + * @param performanceStatus_ Current repayment performance category. |
| 27 | + */ |
| 28 | + function setLoanState(uint256 totalCollateralValue_, ILoan.PerformanceStatus performanceStatus_) external { |
| 29 | + _totalCollateralValue = totalCollateralValue_; |
| 30 | + _performanceStatus = performanceStatus_; |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * @notice Sets the token balance for a given partition and holder. |
| 35 | + * @param _partition Partition identifier. |
| 36 | + * @param _holder Address of the token holder. |
| 37 | + * @param _amount Raw token balance to assign. |
| 38 | + */ |
| 39 | + function setBalance(bytes32 _partition, address _holder, uint256 _amount) external { |
| 40 | + _balances[_partition][_holder] = _amount; |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * @notice Minimal transfer-by-partition stub for the LoansPortfolio withdraw path. |
| 45 | + * @dev Decrements `msg.sender`'s balance and increments the recipient's balance |
| 46 | + * in `_partition`. Reverts with `InvalidPartition` when `msg.sender` holds |
| 47 | + * fewer tokens than `value`. Intended solely for test scenarios where the |
| 48 | + * portfolio withdraws loan holdings. |
| 49 | + * @param _partition Source partition. |
| 50 | + * @param _basicTransferInfo Recipient address and token amount. |
| 51 | + * @param _data Additional data (forwarded to the event, otherwise unused). |
| 52 | + * @return The partition identifier (`_partition`). |
| 53 | + */ |
| 54 | + function transferByPartition( |
| 55 | + bytes32 _partition, |
| 56 | + BasicTransferInfo calldata _basicTransferInfo, |
| 57 | + bytes calldata _data |
| 58 | + ) external returns (bytes32) { |
| 59 | + address from = msg.sender; |
| 60 | + address to = _basicTransferInfo.to; |
| 61 | + uint256 value = _basicTransferInfo.value; |
| 62 | + |
| 63 | + if (_balances[_partition][from] < value) { |
| 64 | + revert InvalidPartition(from, _partition); |
| 65 | + } |
| 66 | + |
| 67 | + _balances[_partition][from] -= value; |
| 68 | + _balances[_partition][to] += value; |
| 69 | + |
| 70 | + emit TransferByPartition(_partition, from, from, to, value, _data, ""); |
| 71 | + |
| 72 | + return _partition; |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * @notice No-op stub required by `ITransferByPartition`. |
| 77 | + * @dev The real initialiser is never called on the mock; this exists solely |
| 78 | + * to satisfy the interface. |
| 79 | + */ |
| 80 | + function initializeTransferByPartition() external {} |
| 81 | + |
| 82 | + /** |
| 83 | + * @notice Returns the loan details with configurable fields populated. |
| 84 | + * @dev Only `collateral.totalCollateralValue` and |
| 85 | + * `loanPerformanceStatus.performanceStatus` carry the values set |
| 86 | + * via `setLoanState`; all other struct members return zero / their |
| 87 | + * type default, matching the portfolio's read pattern. |
| 88 | + * @return loanDetailsData_ LoanDetailsData struct. |
| 89 | + */ |
| 90 | + function getLoanDetails() external view returns (ILoan.LoanDetailsData memory loanDetailsData_) { |
| 91 | + loanDetailsData_.collateral.totalCollateralValue = _totalCollateralValue; |
| 92 | + loanDetailsData_.loanPerformanceStatus.performanceStatus = _performanceStatus; |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * @notice Returns the configured token balance for a partition and holder. |
| 97 | + * @param _partition Partition identifier. |
| 98 | + * @param _holder Address of the token holder. |
| 99 | + * @return The balance previously set via `setBalance`. |
| 100 | + */ |
| 101 | + function balanceOfByPartition(bytes32 _partition, address _holder) external view returns (uint256) { |
| 102 | + return _balances[_partition][_holder]; |
| 103 | + } |
| 104 | +} |
0 commit comments