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

feat: introduce operational treasury and admin role for pools #72

Merged
merged 8 commits into from
Mar 7, 2025

Conversation

EvgeniiZaitsevCW
Copy link
Collaborator

@EvgeniiZaitsevCW EvgeniiZaitsevCW commented Feb 21, 2025

Main changes.

  1. The operational treasury has been introduced on the liquidity pool smart contract to simplify managing its borrowable balance through special new functions.

  2. The admin role has been reintroduced to the liquidity pool smart contract. Accounts with that roles can execute the new functions to deposit and withdraw tokens using the operation treasury account configured on the contract.

    The new role definition
    /// @dev The role of this contract admin.
    bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
  3. The new pool balance management functions are depositFromOperationalTreasury() and withdrawToOperationalTreasury():

    The definition of new functions
    /// @dev Deposits tokens to the liquidity pool from the operational treasury.
    /// @param amount The amount of tokens to deposit.
    function depositFromOperationalTreasury(uint256 amount) external onlyRole(ADMIN_ROLE) {...}
    
    /// @dev Withdraws tokens from the liquidity pool to the operational treasury.
    /// @param amount The amount of tokens to withdraw from the borrowable balance.
    function withdrawToOperationalTreasury(uint256 amount) external onlyRole(ADMIN_ROLE) {....}
  4. The token flows for the new pool balance management functions:

    • depositFromOperationalTreasury(): operationTreasury => liquidityPool;
    • withdrawToOperationalTreasury(): liquidityPool => operationTreasury;
    • no other balances are changed.
  5. No additional events have been introduced for the new pool balance management functions. The existing Deposit and Withdrawal events are emitted by the new functions.

  6. New functions setOperationalTreasury() and operationalTreasury() have been introduced to set and get the address of the operational treasury on the liquidity pool smart contract:

    The definition of new functions
    /// @dev Sets the operational treasury address.
    ///
    /// See the {operationalTreasury} function comments for more details.
    ///
    /// @param newTreasury The new address of the operational treasury to set.
    function setOperationalTreasury(address newTreasury) external onlyRole(OWNER_ROLE) {....}
    
    /// @dev Returns the operational treasury address.
    ///
    /// The operational treasury is used to deposit and withdraw tokens through special functions.
    ///
    /// @return The current address of the operational treasury.
    function operationalTreasury() external view returns (address) {....}
  7. The new OperationalTreasuryChanged event has been introduced to the liquidity pool smart contract. The new event is emitted when the operational treasury address is changed:

    The new event definition
    /// @dev Emitted when the operational treasury address has been changed.
    ///
    /// See the {operationalTreasury} function comments for more details.
    ///
    /// @param newTreasury The updated address of the operational treasury.
    /// @param oldTreasury The previous address of the operational treasury.
    event OperationalTreasuryChanged(address newTreasury, address oldTreasury);

Versioning

The smart contracts version has been updated to v1.13.0.

Migration Steps

After upgrading the CapybaraFinance smart-contracts call the LiquidityPool.initAdminRole() function without parameters once from an account with the owner role. It will initialize the admin role and grant it to the caller.

Test Coverage

The new changes have been fully covered by tests.

Test coverage details
File % Stmts % Branch % Funcs % Lines
contracts/ 100.00 100.00 100.00 100.00
├─ CreditLine.sol 100.00 100.00 100.00 100.00
├─ CreditLineStorage.sol 100.00 100.00 100.00 100.00
├─ LendingMarket.sol 100.00 100.00 100.00 100.00
├─ LendingMarketStorage.sol 100.00 100.00 100.00 100.00
├─ LiquidityPool.sol 100.00 100.00 100.00 100.00
├─ LiquidityPoolStorage.sol 100.00 100.00 100.00 100.00
contracts/base/ 100.00 100.00 100.00 100.00
├─ AccessControlExtUpgradeable.sol 100.00 100.00 100.00 100.00
├─ PausableExtUpgradeable.sol 100.00 100.00 100.00 100.00
├─ UUPSExtUpgradeable.sol 100.00 100.00 100.00 100.00
├─ Versionable.sol 100.00 100.00 100.00 100.00
contracts/interfaces/ 100.00 100.00 100.00 100.00
├─ ICreditLine.sol 100.00 100.00 100.00 100.00
├─ ICreditLineTypes.sol 100.00 100.00 100.00 100.00
├─ ILendingMarket.sol 100.00 100.00 100.00 100.00
├─ ILiquidityPool.sol 100.00 100.00 100.00 100.00
├─ IVersionable.sol 100.00 100.00 100.00 100.00
contracts/libraries/ 100.00 98.00 100.00 100.00
├─ ABDKMath64x64.sol 100.00 97.73 100.00 100.00
├─ Constants.sol 100.00 100.00 100.00 100.00
├─ Error.sol 100.00 100.00 100.00 100.00
├─ InterestMath.sol 100.00 100.00 100.00 100.00
├─ Loan.sol 100.00 100.00 100.00 100.00
├─ Rounding.sol 100.00 100.00 100.00 100.00
├─ SafeCast.sol 100.00 100.00 100.00 100.00
contracts/mocks/ 100.00 100.00 100.00 100.00
├─ ABDKMath64x64Mock.sol 100.00 100.00 100.00 100.00
├─ AccessControlExtUpgradeableMock.sol 100.00 100.00 100.00 100.00
├─ CreditLineMock.sol 100.00 100.00 100.00 100.00
├─ ERC20Mock.sol 100.00 100.00 100.00 100.00
├─ LendingMarketMock.sol 100.00 100.00 100.00 100.00
├─ LiquidityPoolMock.sol 100.00 100.00 100.00 100.00
├─ PausableExtUpgradeableMock.sol 100.00 100.00 100.00 100.00
├─ RoundingMock.sol 100.00 100.00 100.00 100.00
├─ UUPSExtUpgradableMock.sol 100.00 100.00 100.00 100.00
contracts/testables/ 100.00 100.00 100.00 100.00
├─ CreditLineTestable.sol 100.00 100.00 100.00 100.00
├─ LendingMarketTestable.sol 100.00 100.00 100.00 100.00
├─ LiquidityPoolTestable.sol 100.00 100.00 100.00 100.00
----------------------------------------- ---------- ---------- ---------- ----------
All files 100.00 99.80 100.00 100.00
----------------------------------------- ---------- ---------- ---------- ----------

Copy link

codecov bot commented Feb 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (a75a81f) to head (63148eb).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #72   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           23        23           
  Lines         1057      1089   +32     
  Branches       156       218   +62     
=========================================
+ Hits          1057      1089   +32     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@igorsenych-cw igorsenych-cw merged commit cabb92e into main Mar 7, 2025
10 checks passed
@igorsenych-cw igorsenych-cw deleted the external-treasury-for-pools branch March 7, 2025 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants