Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,20 @@ contract LenderCommitmentGroup_Pool_V2 is


// uint256 immutable public DEFAULT_WITHDRAW_DELAY_TIME_SECONDS = 300;
// uint256 immutable public MAX_WITHDRAW_DELAY_TIME = 86400;
uint256 immutable public MAX_WITHDRAW_DELAY_TIME = 86400;

mapping(uint256 => bool) public activeBids;
mapping(uint256 => uint256) public activeBidsAmountDueRemaining;

int256 tokenDifferenceFromLiquidations;

bool private firstDepositMade_deprecated; // no longer used
uint256 public withdrawDelayTimeSeconds; // immutable for now - use withdrawDelayBypassForAccount
uint256 public withdrawDelayTimeSeconds;

IUniswapPricingLibrary.PoolRouteConfig[] public poolOracleRoutes;

//configured by the owner. If 0 , not used.
uint256 public maxPrincipalPerCollateralAmount;
uint256 private maxPrincipalPerCollateralAmount;


uint256 public lastUnpausedAt;
Expand Down Expand Up @@ -277,12 +277,7 @@ contract LenderCommitmentGroup_Pool_V2 is
UNISWAP_PRICING_HELPER = _uniswapPricingHelper;
}

/**
* @notice Initializes the LenderCommitmentGroup_Smart contract.
* @param _commitmentGroupConfig Configuration for the commitment group (lending pool).
* @param _poolOracleRoutes Route configuration for the principal/collateral oracle.

*/

function initialize(

CommitmentGroupConfig calldata _commitmentGroupConfig,
Expand Down Expand Up @@ -742,14 +737,21 @@ contract LenderCommitmentGroup_Pool_V2 is
return pairPriceWithTwapFromOracle;
}


function getMaxPrincipalPerCollateralAmount() public view returns (uint256) {


return maxPrincipalPerCollateralAmount;
}

/**
* @notice Calculates the principal token amount per collateral token based on Uniswap oracle prices
* @dev Uses Uniswap TWAP and applies any configured maximum limits
* @dev Returns the lesser of the oracle price or the configured maximum (if set)
* @param poolOracleRoutes Array of pool route configurations to use for price calculation
* @return The principal per collateral ratio, expanded by the Uniswap expansion factor
*/
function getPrincipalForCollateralForPoolRoutes(
/* function getPrincipalForCollateralForPoolRoutes(
IUniswapPricingLibrary.PoolRouteConfig[] memory poolOracleRoutes
) external view virtual returns (uint256 ) {

Expand All @@ -766,7 +768,7 @@ contract LenderCommitmentGroup_Pool_V2 is


return principalPerCollateralAmount;
}
} */


/**
Expand Down Expand Up @@ -1149,6 +1151,20 @@ contract LenderCommitmentGroup_Pool_V2 is
withdrawDelayBypassForAccount[_addr] = _bypass;

}



/**
* @notice Sets the delay time for withdrawing shares. Only Protocol Owner.
* @param _seconds Delay time in seconds.
*/
function setWithdrawDelayTime(uint256 _seconds)
external
onlyProtocolOwner {
require( _seconds < MAX_WITHDRAW_DELAY_TIME , "WD");

withdrawDelayTimeSeconds = _seconds;
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ interface ILenderCommitmentGroup_V2 {

IUniswapPricingLibrary.PoolRouteConfig[] calldata _poolOracleRoutes

)
external
;
) external ;



Expand All @@ -38,4 +36,7 @@ interface ILenderCommitmentGroup_V2 {

function getTokenDifferenceFromLiquidations() external view returns (int256);


// function getMaxPrincipalPerCollateralAmount() external view returns (uint256);

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";

import {ILenderCommitmentGroup_V2} from "../interfaces/ILenderCommitmentGroup_V2.sol";


/*

Expand Down Expand Up @@ -157,4 +161,39 @@ contract UniswapPricingHelper
return FullMath.mulDiv(sqrtPriceX96, sqrtPriceX96, FixedPoint96.Q96);
}


// ----



/**
* @notice Calculates the principal token amount per collateral token based on Uniswap oracle prices
* @dev Uses Uniswap TWAP and applies any configured maximum limits
* @dev Returns the lesser of the oracle price or the configured maximum (if set)
* @param poolOracleRoutes Array of pool route configurations to use for price calculation
* @param pool th address of the pool
* @return The principal per collateral ratio, expanded by the Uniswap expansion factor
*/
function getPrincipalForCollateralForPoolRoutes(
IUniswapPricingLibrary.PoolRouteConfig[] memory poolOracleRoutes,
address pool
) external view virtual returns (uint256 ) {

uint256 pairPriceWithTwapFromOracle = getUniswapPriceRatioForPoolRoutes(poolOracleRoutes);


uint256 maxPrincipalPerCollateralAmount = 0 ;

uint256 principalPerCollateralAmount = maxPrincipalPerCollateralAmount == 0
? pairPriceWithTwapFromOracle
: Math.min(
pairPriceWithTwapFromOracle,
maxPrincipalPerCollateralAmount //this is expanded by uniswap exp factor
);


return principalPerCollateralAmount;
}


}