Skip to content

CoreInternals ​

Git Source

Inherits:Error, CommonHelpers, Events

Functions ​

_supplyOrWithdraw ​

supply or withdraw for both with interest & interest free. positive amount_ is deposit, negative amount_ is withdraw.

solidity
function _supplyOrWithdraw(address token_, int256 amount_, uint256 supplyExchangePrice_)
    internal
    returns (int256 newSupplyInterestRaw_, int256 newSupplyInterestFree_);

_borrowOrPayback ​

borrow or payback for both with interest & interest free. positive amount_ is borrow, negative amount_ is payback.

solidity
function _borrowOrPayback(address token_, int256 amount_, uint256 borrowExchangePrice_)
    internal
    returns (int256 newBorrowInterestRaw_, int256 newBorrowInterestFree_);

_isInOutBalancedOut ​

checks if supplyAmount_ & borrowAmount_ amounts transfers can be skipped (DEX-protocol use-case).

  • Requirements:
  • callbackData_ MUST be > 63 bytes and encoded so that "from" address is the last 20 bytes in the last 32 bytes slot, also for native token operations where liquidityCallback is not triggered! from address must come at last position if there is more data. I.e. encode like: abi.encode(otherVar1, otherVar2, FROM_ADDRESS). Note dynamic types used with abi.encode come at the end so if dynamic types are needed, you must use abi.encodePacked to ensure the from address is at the end.
  • this "from" address must match withdrawTo_ or borrowTo_ and must be == msg.sender
  • callbackData_ must in addition to the from address as described above include bytes32 SKIP_TRANSFERS in the slot before (bytes 32 to 63)
  • msg.value must be 0.
  • Amounts must be either:
  • supply(+) == borrow(+), withdraw(-) == payback(-).
  • Liquidity must be on the winning side (deposit < borrow OR payback < withdraw).
solidity
function _isInOutBalancedOut(
    int256 supplyAmount_,
    int256 borrowAmount_,
    address withdrawTo_,
    address borrowTo_,
    bytes memory callbackData_
) internal view returns (bool);

_isNetTransfers ​

checks if net transfers should be done only (DEX-protocol use-case).

  • Requirements:
  • callbackData_ MUST be > 63 bytes and encoded so that "from" address is the last 20 bytes in the last 32 bytes slot, also for native token operations where liquidityCallback is not triggered! from address must come at last position if there is more data. I.e. encode like: abi.encode(otherVar1, otherVar2, FROM_ADDRESS). Note dynamic types used with abi.encode come at the end so if dynamic types are needed, you must use abi.encodePacked to ensure the from address is at the end.
  • this "from" address must match withdrawTo_ or borrowTo_ in case of net transfer out
  • callbackData_ must in addition to the from address as described above include bytes32 NET_TRANSFERS in the slot before (second last slot)
  • Amounts must be so that it's a 2 action operation, with some input and some output
solidity
function _isNetTransfers(
    int256 supplyAmount_,
    int256 borrowAmount_,
    address withdrawTo_,
    address borrowTo_,
    bytes memory callbackData_
) internal pure returns (bool isNetTransfers_, uint256 operateAmountOut_);

_checkEnforceTotalInputAmount ​

Checks and enforces the total input amount for a protocol callback.

Supports legacy DexV1 and new protocols (e.g., DexV2) by decoding callbackData accordingly.

solidity
function _checkEnforceTotalInputAmount(uint256 expectedInputAmount_, bytes memory callbackData_)
    internal
    pure
    returns (uint256);

Parameters

NameTypeDescription
expectedInputAmount_uint256The expected input amount to be enforced.
callbackData_bytesThe callback data containing protocol-specific input information.

Returns

NameTypeDescription
<none>uint256The validated or updated input amount to be used.

_checkMaxOperateAmountRatio ​

checks newOperateAmount_ to be within an acceptable valid ratio compared to existingTotalAmount_ serves as additional input validation and operate effects check.

solidity
function _checkMaxOperateAmountRatio(uint256 newOperateAmount_, uint256 existingTotalAmount_, bool isDepositBorrow_)
    internal
    pure;