- LeverageCloneFactory Functions
- LeverageProxyImpl Functions
- PositionLogic Library Functions
- PositionUtils Library Functions
- Mathematical Formulas
- Key Data Structures
Purpose: Main entry point for creating leveraged positions
Steps:
- Salt Generation: Create deterministic salt for proxy deployment
- Proxy Prediction: Predict the proxy address using deterministic deployment
- Token Transfer: Transfer collateral from user to factory
- Proxy Creation: Deploy deterministic proxy contract
- Position Creation: Call proxy's createPosition function
- Counter Update: Increment user's position counter
Mathematical Operations:
salt = keccak256(abi.encodePacked(msg.sender, positionCounter[msg.sender], address(this)))
predictedProxy = Clones.predictDeterministicAddress(implementation, salt, address(this))
proxyAddress = Clones.cloneDeterministic(implementation, salt)
positionCounter[msg.sender]++Purpose: Calculates preview for position creation
Steps:
- Parameter Validation: Ensure implementation is initialized
- Preview Calculation: Delegate to PositionUtils.windPositionPreview
- Return Preview: Return calculated leverage preview
Mathematical Operations:
- Delegates to
PositionUtils.windPositionPreview() - Creates temporary Position struct for calculation
Purpose: Returns maximum safe leverage for given parameters
Steps:
- Parameter Validation: Ensure implementation is initialized
- Calculation: Delegate to PositionUtils.getMaxMultiplier
- Return Result: Return maximum multiplier result
Mathematical Operations:
- Delegates to
PositionUtils.getMaxMultiplier()
Purpose: Handles swap operations during position creation
Steps:
- Access Control: Ensure caller is a valid child proxy
- Swap Execution: Delegate to PositionLogic.createSwapCallback
- Return Results: Return swap amounts
Mathematical Operations:
- Delegates to
PositionLogic.createSwapCallback()
Purpose: Reinitializes proxy after implementation upgrade
Steps:
- Access Control: Ensure caller is proxy owner
- Proxy Call: Call initialize function on proxy
- Success Check: Verify reinitialization succeeded
Mathematical Operations:
- No direct calculations (administrative function)
Purpose: Emergency function to recover stuck tokens
Steps:
- Access Control: Only owner can call
- Token Transfer: Transfer all tokens to owner
- Balance Check: Get current token balance
Mathematical Operations:
balance = token.balanceOf(address(this))
token.safeTransfer(owner(), balance)Purpose: Initializes the proxy contract
Steps:
- Owner Validation: Ensure owner is not zero address
- Factory Setup: Set factory address to caller
- Ownership Transfer: Transfer ownership to specified owner
- Event Emission: Emit initialization event
Mathematical Operations:
- No direct calculations (initialization function)
Purpose: Creates a leveraged position (called by factory)
Steps:
- Access Control: Ensure caller is factory
- Logic Delegation: Delegate to PositionLogic.create
- Constants Retrieval: Get constants from factory
Mathematical Operations:
- Delegates to
PositionLogic.create()
Purpose: Closes a leveraged position completely
Steps:
- Access Control: Ensure caller is owner
- Logic Delegation: Delegate to PositionLogic.close
- Constants Retrieval: Get constants from factory
Mathematical Operations:
- Delegates to
PositionLogic.close()
Purpose: Allows manual/partial closure of positions
Steps:
- Access Control: Ensure caller is owner
- Logic Delegation: Delegate to PositionLogic.closeManual
- Constants Retrieval: Get constants from factory
Mathematical Operations:
- Delegates to
PositionLogic.closeManual()
Purpose: Increases leverage of existing position
Steps:
- Access Control: Ensure caller is owner
- Logic Delegation: Delegate to PositionLogic.wind
- Constants Retrieval: Get constants from factory
Mathematical Operations:
- Delegates to
PositionLogic.wind()
Purpose: Decreases leverage of existing position
Steps:
- Access Control: Ensure caller is owner
- Logic Delegation: Delegate to PositionLogic.unwind
- Constants Retrieval: Get constants from factory
Mathematical Operations:
- Delegates to
PositionLogic.unwind()
Purpose: Calculates preview for position closure
Steps:
- Logic Delegation: Delegate to PositionLogic.closePreview
- Constants Retrieval: Get constants from factory
- Return Preview: Return calculated preview
Mathematical Operations:
- Delegates to
PositionLogic.closePreview()
Purpose: Calculates preview for manual position closure
Steps:
- Logic Delegation: Delegate to PositionLogic.closeManualPreview
- Constants Retrieval: Get constants from factory
- Return Preview: Return calculated preview
Mathematical Operations:
- Delegates to
PositionLogic.closeManualPreview()
Purpose: Calculates preview for increasing leverage
Steps:
- Logic Delegation: Delegate to PositionLogic.windPreview
- Constants Retrieval: Get constants from factory
- Return Preview: Return calculated preview
Mathematical Operations:
- Delegates to
PositionLogic.windPreview()
Purpose: Calculates preview for decreasing leverage
Steps:
- Logic Delegation: Delegate to PositionLogic.unwindPreview
- Constants Retrieval: Get constants from factory
- Return Preview: Return calculated preview
Mathematical Operations:
- Delegates to
PositionLogic.unwindPreview()
Purpose: Handles Aave flash loan callbacks
Steps:
- Parameter Construction: Build PositionCallbackParams
- Logic Delegation: Delegate to PositionLogic.handleCallback
- Constants Retrieval: Get constants from factory
- Return Success: Return true for successful execution
Mathematical Operations:
- Delegates to
PositionLogic.handleCallback()
Purpose: Handles ERC3156 flash loan callbacks
Steps:
- Parameter Construction: Build PositionCallbackParams
- Logic Delegation: Delegate to PositionLogic.handleCallback
- Constants Retrieval: Get constants from factory
- Return Hash: Return keccak256('ERC3156FlashBorrower.onFlashLoan')
Mathematical Operations:
- Delegates to
PositionLogic.handleCallback()
Purpose: Returns current position details
Steps:
- Logic Delegation: Delegate to PositionLogic.getPositionDetails
- Constants Retrieval: Get constants from factory
- Return Details: Return position details
Mathematical Operations:
- Delegates to
PositionLogic.getPositionDetails()
Purpose: Executes multiple calls atomically
Steps:
- Access Control: Ensure caller is owner
- Loop Execution: Execute each call in sequence
- Error Handling: Handle reverts based on allowRevert flag
- Result Processing: Process call results
Mathematical Operations:
for (uint256 i = 0; i < calls.length; i++) {
(bool success, bytes memory result) = calls[i].target.call{value: calls[i].value}(calls[i].data);
if (!success && !calls[i].allowRevert) {
revert(string(result));
}
}Purpose: Emergency function to recover stuck tokens
Steps:
- Access Control: Ensure caller is owner
- Address Validation: Ensure recipient is not zero
- Balance Check: Get current token balance
- Token Transfer: Transfer tokens to recipient
Mathematical Operations:
balance = IERC20(token).balanceOf(address(this))
if (balance > 0) {
IERC20(token).safeTransfer(to, balance);
}Purpose: Emergency function to recover stuck ETH
Steps:
- Access Control: Ensure caller is owner
- Address Validation: Ensure recipient is not zero
- ETH Transfer: Transfer ETH to recipient
Mathematical Operations:
balance = address(this).balance
if (balance > 0) {
payable(to).transfer(balance);
}Purpose: Creates a new leveraged position using flash loans
Steps:
- Parameter Validation: Check collateral/debt assets, amounts, and health factors
- EMode Check: Enable eMode if available for the asset pairing
- Flash Loan: Borrow collateral asset from Aave pool
- Callback Execution: Execute position creation logic in callback
Mathematical Operations:
- No direct calculations (delegates to preview functions)
Purpose: Closes a leveraged position completely
Steps:
- Preview Calculation: Calculate close preview using
_closePreview() - Flash Loan: Borrow debt asset to repay position
- Swap Execution: Swap collateral for debt tokens via Gluex
- Position Cleanup: Reset position state to zero
Mathematical Operations:
- Uses
_calculateClosePreview()for USD-based calculations - Handles decimal conversions between collateral and debt tokens
Purpose: Allows partial or full manual closure of positions
Steps:
- Repay Calculation: Calculate repayment amount based on percentage
- Withdrawal Calculation: Calculate collateral withdrawal amount
- Position Update: Update position state without calling unwind functions
- Health Factor Check: Ensure position remains healthy
Mathematical Operations:
repayAmount = (currentDebt * repayPercent) / 1e18
withdrawAmount = (currentCollateral * repayPercent) / 1e18
newLeverageMultiplier = (remainingCollateral * 1e18) / remainingUserCollateralPurpose: Increases leverage of existing position
Steps:
- Preview Calculation: Calculate wind preview
- Flash Loan: Borrow additional collateral
- Swap Execution: Swap debt for more collateral
- Position Update: Update leverage multiplier
Mathematical Operations:
- Delegates to
windPositionPreview()for calculations
Purpose: Decreases leverage of existing position
Steps:
- Preview Calculation: Calculate unwind preview
- Flash Loan: Borrow debt tokens
- Swap Execution: Swap collateral for debt tokens
- Position Update: Update leverage multiplier
Mathematical Operations:
- Delegates to
unwindPositionPreview()for calculations
Purpose: Calculates the preview for creating a new leveraged position
Mathematical Steps:
collateralPrice = getAssetPrice(collateralAsset)
debtPrice = getAssetPrice(debtAsset)
collateralDecimals = IERC20Metadata(collateralAsset).decimals()
debtDecimals = IERC20Metadata(debtAsset).decimals()
priceDecimals = getPriceDecimals(constants)initialCollateralAmountUSD = (collateralAmount * collateralPrice) * (10^(18 - collateralDecimals)) / (10^priceDecimals)
initialCollateralAmountTokens = collateralAmountcollateralAmountTokens = initialCollateralAmountTokens * leverageMultiplier / 1e18
collateralAmountUSD = initialCollateralAmountUSD * leverageMultiplier / 1e18debtAmountUSD = collateralAmountUSD - initialCollateralAmountUSD
flashLoanFee = (collateralAmountUSD * flashLoanFeeBps) / 10000
totalDebtUSD = debtAmountUSD + flashLoanFee
debtAmountTokens = (totalDebtUSD * (10^priceDecimals)) / debtPrice
debtAmountTokens = scaleDecimals(debtAmountTokens, debtDecimals)totalCollateralUSD = existingCollateral + newCollateralUSD/1e10
totalDebtUSD = existingDebt + newDebtUSD/1e10
healthFactor = (totalCollateralUSD * liquidationThresholdWad) / totalDebtUSDPurpose: Calculates preview for increasing leverage on existing position
Mathematical Steps:
additionalDebt18 = (newCollateralAmount * leverageMultiplier) / 1e18
additionalDebt = scaleDecimals(additionalDebt18, debtDecimals)newTotalCollateral = oldCollateral + newCollateralAmount
newTotalDebt = oldDebt + additionalDebt
newTotalCollateralUSD = oldCollateralUSD + newCollateralUSD
newTotalDebtUSD = oldDebtUSD + newDebtUSDnewHealthFactor = (newTotalCollateralUSD * liquidationThresholdWad) / newTotalDebtUSDPurpose: Calculates preview for decreasing leverage on existing position
Mathematical Steps:
userCollateral = newParams.collateralAmount
newCollateralAmount = userCollateral * leverageMultiplier / 1e18collateralToRemove = max(0, oldCollateral - newCollateralAmount)// Uses previewLeverage() with new parameters
newPreview = previewLeverage(totalParams, constants)
// Calculate differences
debtReduction = oldDebt - newDebt
collateralReduction = oldCollateral - newCollateralPurpose: Calculates the maximum safe leverage multiplier for given parameters
Mathematical Steps:
// For USDXL
usdxlLiquidity = usdxlFlashMinter.reserveCapacity - usdxlFlashMinter.reserveLevel
aTokenLiquidity = aToken.reserveCapacity - aToken.reserveLevel
borrowLiquidity = min(usdxlLiquidity, aTokenLiquidity)
// For other assets
borrowLiquidity = IERC20(debtAsset).balanceOf(aTokenAddress)// EMode or regular reserve data
ltv = reserveConfiguration.getLtv()
liquidationThreshold = reserveConfiguration.getLiquidationThreshold()
ltvWad = ltv * 1e14
liqThresholdWad = liquidationThreshold * 1e14(requiredCollateralDebtRatio, totalCollateralDebtRatio) = _calculateRequiredCollateralUSD(
targetHealthFactor,
1e18,
ltvWad
)requiredCollateralTokens = requiredCollateralDebtRatio * (10^priceDecimals) / collateralPrice
requiredCollateralTokens = scaleDecimals(requiredCollateralTokens, collateralDecimals)maxMultiplier = totalCollateralDebtRatio * 1e18 / requiredCollateralDebtRatio
maxBorrow = borrowLiquidity
maxBorrowUSD = maxBorrow * debtPrice / (10^priceDecimals)
maxCollateralAmountUSD = requiredCollateralDebtRatio * maxBorrowUSD / 1e18
maxCollateralAmountTokens = maxCollateralAmountUSD * (10^priceDecimals) / collateralPriceif (supplyCap > 0) {
availableSupply = supplyCap - currentSupply
if (availableSupply < maxCollateralWithMultiplier) {
maxCollateralAmountTokens = availableSupply * 1e18 / maxMultiplier
// Recalculate maxBorrow based on supply cap limit
}
}Purpose: Calculates preview for completely closing a position
Mathematical Steps:
currentDebt = getCurrentDebt(constants, position.debtAsset)
currentCollateral = getCurrentCollateral(constants, position)debtPrice = getAssetPrice(debtAsset)
collateralPrice = getCollateralPrice(collateralAsset)
debtUSD = currentDebt * debtPrice / (10^debtDecimals)
collateralUSD = currentCollateral * collateralPrice / (10^collateralDecimals)totalDebtWithFee = debtUSD + flashLoanFee
collateralToSellUSD = totalDebtWithFee
collateralToSell = collateralToSellUSD * (10^collateralDecimals) / collateralPriceremainingCollateral = currentCollateral - collateralToSell
expectedDebtTokens = totalDebtWithFeePurpose: Main entry point for creating leveraged positions
Steps:
- Salt Generation: Create deterministic salt for proxy deployment
- Proxy Prediction: Predict the proxy address using deterministic deployment
- Token Transfer: Transfer collateral from user to factory
- Proxy Creation: Deploy deterministic proxy contract
- Position Creation: Call proxy's createPosition function
- Counter Update: Increment user's position counter
Mathematical Operations:
salt = keccak256(abi.encodePacked(msg.sender, positionCounter[msg.sender], address(this)))
predictedProxy = Clones.predictDeterministicAddress(implementation, salt, address(this))
proxyAddress = Clones.cloneDeterministic(implementation, salt)
positionCounter[msg.sender]++Purpose: Calculates preview for position creation
Steps:
- Parameter Validation: Ensure implementation is initialized
- Preview Calculation: Delegate to PositionUtils.windPositionPreview
- Return Preview: Return calculated leverage preview
Mathematical Operations:
- Delegates to
PositionUtils.windPositionPreview() - Creates temporary Position struct for calculation
Purpose: Returns maximum safe leverage for given parameters
Steps:
- Parameter Validation: Ensure implementation is initialized
- Calculation: Delegate to PositionUtils.getMaxMultiplier
- Return Result: Return maximum multiplier result
Mathematical Operations:
- Delegates to
PositionUtils.getMaxMultiplier()
Purpose: Handles swap operations during position creation
Steps:
- Access Control: Ensure caller is a valid child proxy
- Swap Execution: Delegate to PositionLogic.createSwapCallback
- Return Results: Return swap amounts
Mathematical Operations:
- Delegates to
PositionLogic.createSwapCallback()
Purpose: Reinitializes proxy after implementation upgrade
Steps:
- Access Control: Ensure caller is proxy owner
- Proxy Call: Call initialize function on proxy
- Success Check: Verify reinitialization succeeded
Mathematical Operations:
- No direct calculations (administrative function)
Purpose: Emergency function to recover stuck tokens
Steps:
- Access Control: Only owner can call
- Token Transfer: Transfer all tokens to owner
- Balance Check: Get current token balance
Mathematical Operations:
balance = token.balanceOf(address(this))
token.safeTransfer(owner(), balance)Purpose: Initializes the proxy contract
Steps:
- Owner Validation: Ensure owner is not zero address
- Factory Setup: Set factory address to caller
- Ownership Transfer: Transfer ownership to specified owner
- Event Emission: Emit initialization event
Mathematical Operations:
- No direct calculations (initialization function)
Purpose: Creates a leveraged position (called by factory)
Steps:
- Access Control: Ensure caller is factory
- Logic Delegation: Delegate to PositionLogic.create
- Constants Retrieval: Get constants from factory
Mathematical Operations:
- Delegates to
PositionLogic.create()
Purpose: Closes a leveraged position completely
Steps:
- Access Control: Ensure caller is owner
- Logic Delegation: Delegate to PositionLogic.close
- Constants Retrieval: Get constants from factory
Mathematical Operations:
- Delegates to
PositionLogic.close()
Purpose: Allows manual/partial closure of positions
Steps:
- Access Control: Ensure caller is owner
- Logic Delegation: Delegate to PositionLogic.closeManual
- Constants Retrieval: Get constants from factory
Mathematical Operations:
- Delegates to
PositionLogic.closeManual()
Purpose: Increases leverage of existing position
Steps:
- Access Control: Ensure caller is owner
- Logic Delegation: Delegate to PositionLogic.wind
- Constants Retrieval: Get constants from factory
Mathematical Operations:
- Delegates to
PositionLogic.wind()
Purpose: Decreases leverage of existing position
Steps:
- Access Control: Ensure caller is owner
- Logic Delegation: Delegate to PositionLogic.unwind
- Constants Retrieval: Get constants from factory
Mathematical Operations:
- Delegates to
PositionLogic.unwind()
Purpose: Calculates preview for position closure
Steps:
- Logic Delegation: Delegate to PositionLogic.closePreview
- Constants Retrieval: Get constants from factory
- Return Preview: Return calculated preview
Mathematical Operations:
- Delegates to
PositionLogic.closePreview()
Purpose: Calculates preview for manual position closure
Steps:
- Logic Delegation: Delegate to PositionLogic.closeManualPreview
- Constants Retrieval: Get constants from factory
- Return Preview: Return calculated preview
Mathematical Operations:
- Delegates to
PositionLogic.closeManualPreview()
Purpose: Calculates preview for increasing leverage
Steps:
- Logic Delegation: Delegate to PositionLogic.windPreview
- Constants Retrieval: Get constants from factory
- Return Preview: Return calculated preview
Mathematical Operations:
- Delegates to
PositionLogic.windPreview()
Purpose: Calculates preview for decreasing leverage
Steps:
- Logic Delegation: Delegate to PositionLogic.unwindPreview
- Constants Retrieval: Get constants from factory
- Return Preview: Return calculated preview
Mathematical Operations:
- Delegates to
PositionLogic.unwindPreview()
Purpose: Handles Aave flash loan callbacks
Steps:
- Parameter Construction: Build PositionCallbackParams
- Logic Delegation: Delegate to PositionLogic.handleCallback
- Constants Retrieval: Get constants from factory
- Return Success: Return true for successful execution
Mathematical Operations:
- Delegates to
PositionLogic.handleCallback()
Purpose: Handles ERC3156 flash loan callbacks
Steps:
- Parameter Construction: Build PositionCallbackParams
- Logic Delegation: Delegate to PositionLogic.handleCallback
- Constants Retrieval: Get constants from factory
- Return Hash: Return keccak256('ERC3156FlashBorrower.onFlashLoan')
Mathematical Operations:
- Delegates to
PositionLogic.handleCallback()
Purpose: Returns current position details
Steps:
- Logic Delegation: Delegate to PositionLogic.getPositionDetails
- Constants Retrieval: Get constants from factory
- Return Details: Return position details
Mathematical Operations:
- Delegates to
PositionLogic.getPositionDetails()
Purpose: Executes multiple calls atomically
Steps:
- Access Control: Ensure caller is owner
- Loop Execution: Execute each call in sequence
- Error Handling: Handle reverts based on allowRevert flag
- Result Processing: Process call results
Mathematical Operations:
for (uint256 i = 0; i < calls.length; i++) {
(bool success, bytes memory result) = calls[i].target.call{value: calls[i].value}(calls[i].data);
if (!success && !calls[i].allowRevert) {
revert(string(result));
}
}Purpose: Emergency function to recover stuck tokens
Steps:
- Access Control: Ensure caller is owner
- Address Validation: Ensure recipient is not zero
- Balance Check: Get current token balance
- Token Transfer: Transfer tokens to recipient
Mathematical Operations:
balance = IERC20(token).balanceOf(address(this))
if (balance > 0) {
IERC20(token).safeTransfer(to, balance);
}Purpose: Emergency function to recover stuck ETH
Steps:
- Access Control: Ensure caller is owner
- Address Validation: Ensure recipient is not zero
- ETH Transfer: Transfer ETH to recipient
Mathematical Operations:
balance = address(this).balance
if (balance > 0) {
payable(to).transfer(balance);
}healthFactor = (totalCollateralUSD * liquidationThreshold) / totalDebtUSDleverageMultiplier = totalCollateral / userCollateralrequiredRatio = (targetHealthFactor * 1e18) / liquidationThreshold// Scale up (add decimals)
scaledAmount = amount * (10^decimals)
// Scale down (remove decimals)
scaledAmount = amount / (10^decimals)usdValue = tokenAmount * price / (10^tokenDecimals)
tokenAmount = usdValue * (10^tokenDecimals) / pricesalt = keccak256(abi.encodePacked(owner, positionCounter, factory))
proxyAddress = Clones.predictDeterministicAddress(implementation, salt, factory)struct LeveragePreview {
uint256 initialCollateralAmountUSD; // User's initial collateral in USD
uint256 initialCollateralAmountTokens; // User's initial collateral in tokens
uint256 collateralAmountUSD; // Total collateral in USD
uint256 collateralAmountTokens; // Total collateral in tokens
uint256 debtAmountUSD; // Total debt in USD
uint256 debtAmountTokens; // Total debt in tokens
uint256 resultingHealthFactor; // Calculated health factor
}struct GetMaxMultiplierResult {
uint256 requiredCollateralDebtRatio; // Required ratio for target health factor
uint256 totalCollateralDebtRatio; // Total ratio available
uint256 requiredCollateralTokens; // Required collateral in tokens
uint256 maxMultiplier; // Maximum safe leverage multiplier
uint256 maxBorrow; // Maximum borrow amount
uint256 maxBorrowUSD; // Maximum borrow in USD
uint256 maxCollateralAmountUSD; // Maximum collateral in USD
uint256 maxCollateralAmountTokens; // Maximum collateral in tokens
}struct Position {
address collateralAsset; // Collateral asset address
address debtAsset; // Debt asset address
uint256 leverageMultiplier; // Current leverage multiplier
uint256 userCollateral; // User's collateral amount
}struct PositionParams {
LeverageParams input; // Leverage parameters
uint256 debtAmount; // Debt amount
string gluexData; // Gluex swap data
}struct Call {
address target; // Target contract address
uint256 value; // ETH value to send
bytes data; // Call data
bool allowRevert; // Whether to allow reverts
}- Minimum Multiplier:
1e18(1x leverage) - Minimum Health Factor:
1500000000000000000(1.5x) - Flash Loan Fee: Typically 9 basis points (0.09%)
- Price Decimals: 8 or 18 depending on oracle
- LTV WAD: LTV * 1e14 (for precision)
- Liquidation Threshold WAD: Liquidation threshold * 1e14
MULTIPLIER_TOO_LOW: Leverage below minimumMULTIPLIER_TOO_HIGH: Leverage exceeds maximum safe levelHEALTH_FACTOR_TOO_LOW: Health factor below minimum thresholdCOLLATERAL_AMOUNT_TOO_LOW: Insufficient collateralBORROW_CAP_EXCEEDED: Borrowing exceeds pool limitsSUPPLY_CAP_EXCEEDED: Collateral supply exceeds limitsDEBT_CEILING_EXCEEDED: Total debt exceeds ceilingONLY_FACTORY: Function called by non-factory addressONLY_OWNER: Function called by non-ownerINVALID_IMPLEMENTATION: Invalid implementation addressIMPLEMENTATION_NOT_INITIALIZED: Implementation not set
- Division by zero prevention
- Underflow/overflow protection
- Price validation (non-zero prices)
- Cap and ceiling enforcement
- Health factor validation
- Access control enforcement
- Address validation
- LeverageCloneFactory: Creates and manages proxy instances
- Deterministic Deployment: Uses CREATE2 for predictable addresses
- Position Counter: Tracks positions per user for deterministic salts
- LeverageProxyImpl: Implementation contract for all proxies
- Beacon Proxy: Single implementation for all user positions
- Upgradeable: Implementation can be upgraded without affecting user positions
- Aave V3: Primary flash loan provider
- USDXL Flash Minter: Alternative flash loan provider
- ERC3156: Standard flash loan interface
- Gluex Router: DEX for token swaps
- Callback Pattern: Handles swap operations during flash loans
This document provides a comprehensive overview of all the mathematical operations and functions in the leverage system, including the factory and proxy implementation layers, suitable for technical presentations and documentation.