Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v2.2.0 #489

Merged
merged 9 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added audit/spearbit-incremental-Nov-2024.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions contracts/common/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ contract Errors {
error PoolOwnerOrHumaOwnerRequired(); // 0x3e984120
error PoolOperatorRequired(); // 0xae7fe070
error PoolOwnerRequired(); // 0x8b506451
error PoolOwnerTreasuryRequired(); // 0xf527eb38
error HumaTreasuryRequired(); // 0x6e0a9ac9
error PoolOwnerOrEARequired(); // 0xe54466f3
error PauserRequired(); // 0xd4a99e4e
Expand Down
4 changes: 4 additions & 0 deletions contracts/credit/Credit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,10 @@ abstract contract Credit is PoolConfigCache, CreditStorage, ICredit {
revert Errors.SentinelServiceAccountRequired();
}

function _onlyPoolOwnerTreasury(address account) internal view {
if (account != poolConfig.poolOwnerTreasury()) revert Errors.PoolOwnerTreasuryRequired();
}

/**
* @notice Returns from whose account the funds for payment should be extracted.
* @notice This function exists because of Auto-pay:
Expand Down
14 changes: 14 additions & 0 deletions contracts/credit/CreditLine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ contract CreditLine is Credit, ICreditLine {
return _makePayment(borrower, creditHash, amount);
}

/// @inheritdoc ICreditLine
function makePaymentOnBehalfOf(
address borrower,
uint256 amount
) external virtual override returns (uint256 amountPaid, bool paidoff) {
poolConfig.onlyProtocolAndPoolOn();
_onlyPoolOwnerTreasury(msg.sender);

bytes32 creditHash = getCreditHash(borrower);
creditManager.onlyCreditBorrower(creditHash, borrower);

return _makePayment(borrower, creditHash, amount);
}

/// @inheritdoc ICreditLine
function makePrincipalPayment(
uint256 amount
Expand Down
35 changes: 35 additions & 0 deletions contracts/credit/ReceivableBackedCreditLine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ contract ReceivableBackedCreditLine is Credit, IERC721Receiver {
address by
);

/**
* @notice A payment has been made against the credit line by someone on behalf of the borrower.
* @param borrower The address of the borrower.
* @param receivableId The ID of the receivable.
* @param amount The payback amount.
* @param by The address that initiated the payment.
*/
event PaymentMadeOnBehalfOfWithReceivable(
address indexed borrower,
uint256 indexed receivableId,
uint256 amount,
address by
);

/**
* @notice A borrowing event has happened to the credit line.
* @param borrower The address of the borrower.
Expand Down Expand Up @@ -118,6 +132,27 @@ contract ReceivableBackedCreditLine is Credit, IERC721Receiver {
emit PaymentMadeWithReceivable(borrower, receivableId, amount, msg.sender);
}

/**
* @notice Allows the Pool Owner Treasury to pay back on behalf of the borrower with a receivable
*/
function makePaymentOnBehalfOfWithReceivable(
address borrower,
uint256 receivableId,
uint256 amount
) public virtual returns (uint256 amountPaid, bool paidoff) {
poolConfig.onlyProtocolAndPoolOn();
_onlyPoolOwnerTreasury(msg.sender);

bytes32 creditHash = getCreditHash(borrower);
creditManager.onlyCreditBorrower(creditHash, borrower);

_prepareForPayment(borrower, poolConfig.receivableAsset(), receivableId);

(amountPaid, paidoff) = _makePayment(borrower, creditHash, amount);

emit PaymentMadeOnBehalfOfWithReceivable(borrower, receivableId, amount, msg.sender);
}

/**
* @notice Allows the borrower to payback the principal and label it with a receivable
*/
Expand Down
17 changes: 17 additions & 0 deletions contracts/credit/interfaces/ICreditLine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ interface ICreditLine {
uint256 amount
) external returns (uint256 amountPaid, bool paidoff);

/**
* @notice Makes one payment for the credit line by the pool owner treasury on behalf of the borrower.
* If this is the final payment, it automatically triggers the payoff process.
* @notice Warning: payments should be made by calling this function. No token should be transferred directly
* to the contract.
* @param borrower The address of the borrower.
* @param amount The payment amount.
* @return amountPaid The actual amount paid to the contract. When the tendered
* amount is larger than the payoff amount, the contract only accepts the payoff amount.
* @return paidoff A flag indicating whether the account has been paid off.
* @custom:access Only the Pool Owner Treasury can call this function.
*/
function makePaymentOnBehalfOf(
address borrower,
uint256 amount
) external returns (uint256 amountPaid, bool paidoff);

/**
* @notice Makes a payment towards the principal for the credit line. Even if there is additional amount remaining
* after the principal is paid off, this function will only accept the amount up to the total principal due.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "huma-contracts-v2",
"version": "2.1.0",
"version": "2.2.0",
"description": "",
"keywords": [],
"license": "AGPL-3.0-or-later",
Expand Down
1 change: 1 addition & 0 deletions scripts/error-functions.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"PoolOwnerOrHumaOwnerRequired()": "0x3e984120",
"PoolOperatorRequired()": "0xae7fe070",
"PoolOwnerRequired()": "0x8b506451",
"PoolOwnerTreasuryRequired()": "0xf527eb38",
"HumaTreasuryRequired()": "0x6e0a9ac9",
"PoolOwnerOrEARequired()": "0xe54466f3",
"PauserRequired()": "0xd4a99e4e",
Expand Down
Loading
Loading