Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: add installment credit support #8

Merged
merged 17 commits into from
Dec 27, 2024
Merged

Conversation

igorsenych-cw
Copy link
Collaborator

@igorsenych-cw igorsenych-cw commented Dec 27, 2024

Main changes

To support installment loans on the CreditAgent contract, new initiateInstallmentCredit, revokeInstallmentCredit, and getInstallmentCredit functions were added. When installment credit is initiated or its state is changed, the InstallmentCreditStatusChanged event is emitted.

    /**
     * @dev Emitted when the status of an installment credit is changed.
     * @param txId The unique identifier of the related cash-out operation.
     * @param borrower The address of the borrower.
     * @param newStatus The current status of the credit.
     * @param oldStatus The previous status of the credit.
     * @param firstInstallmentId The unique ID of the related first installment loan on the lending market or zero if not taken.
     * @param programId The unique identifier of the lending program for the credit.
     * @param lastDurationInPeriods The duration of the last installment in periods.
     * @param totalBorrowAmount The total amount of all installments.
     * @param totalAddonAmount The total addon amount of all installments.
     * @param installmentCount The number of installments.
     */
    event InstallmentCreditStatusChanged(
        bytes32 indexed txId,
        address indexed borrower,
        CreditStatus newStatus,
        CreditStatus oldStatus,
        uint256 firstInstallmentId,
        uint256 programId,
        uint256 lastDurationInPeriods,
        uint256 totalBorrowAmount,
        uint256 totalAddonAmount,
        uint256 installmentCount
    );

    /**
     * @dev Initiates an installment credit.
     *
     * This function is expected to be called by a limited number of accounts.
     *
     * @param txId The unique identifier of the related cash-out operation.
     * @param borrower The address of the borrower.
     * @param programId The unique identifier of the lending program for the credit.
     * @param durationsInPeriods The duration of each installment in periods.
     * @param borrowAmounts The amounts of each installment.
     * @param addonAmounts The addon amounts of each installment.
     */
    function initiateInstallmentCredit(
        bytes32 txId,
        address borrower,
        uint256 programId,
        uint256[] calldata durationsInPeriods,
        uint256[] calldata borrowAmounts,
        uint256[] calldata addonAmounts
    ) external;

    /**
     * @dev Revokes an installment credit.
     *
     * This function is expected to be called by a limited number of accounts.
     *
     * @param txId The unique identifier of the related cash-out operation.
     */
    function revokeInstallmentCredit(bytes32 txId) external;

    /**
     * @dev Returns an installment credit structure by its unique identifier.
     * @param txId The unique identifier of the related cash-out operation.
     * @return The installment credit structure.
     */
    function getInstallmentCredit(bytes32 txId) external view returns (InstallmentCredit memory);

    /// @dev The data of a single installment credit.
    struct InstallmentCredit {
        // Slot 1
        address borrower; // ------------- The address of the borrower.
        uint32 programId; // ------------- The unique identifier of a lending program for the credit.
        CreditStatus status; // ---------- The status of the credit, see {CreditStatus}.
        // uint56 __reserved; // --------- Reserved for future use until the end of the storage slot.
        // Slot 2
        uint32[] durationsInPeriods; // -- The duration of each installment in periods.
        // Slot 3
        uint64[] borrowAmounts; // ------- The amounts of each installment.
        // Slot 4
        uint64[] addonAmounts; // -------- The addon amounts of each installment.
        // Slot 5
        uint256 firstInstallmentId; // --- The unique ID of the related first installment loan on the lending market or zero if not taken.
    }

Versioning

The version of the CreditAgent contract has been changed: 1.1.0 => 1.2.0.

Test coverage

New functionality was fully covered by tests.

@igorsenych-cw igorsenych-cw merged commit 15524b7 into main Dec 27, 2024
7 checks passed
@igorsenych-cw igorsenych-cw deleted the installment-credit branch December 27, 2024 14:20
@igorsenych-cw igorsenych-cw changed the title Add installment credit support feat: add installment credit support Dec 27, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants