Skip to content

TokenAmtResolver ​

Git Source

Inherits:Error

Title: TokenAmtResolver

Utility for converting between token amounts and USD values using the FluidUsdOracle. All USD values are in 1e27 precision (1 USD = 1e27). Inheritable by auth contracts, limit handlers, resolvers, or any consumer that needs token <-> USD conversions.

Constants ​

ORACLE_PRECISION ​

solidity
uint256 private constant ORACLE_PRECISION = 1e27

Functions ​

_getUsdValueForTokenAmount ​

Converts a token amount to its USD value using the oracle's getPriceRawForMode.

solidity
function _getUsdValueForTokenAmount(address usdOracle_, address token_, uint256 amount_, uint8 priceMode_)
    internal
    view
    returns (uint256 usdValue_);

Parameters

NameTypeDescription
usdOracle_addressAddress of the FluidUsdOracle.
token_addressThe token address.
amount_uint256The token amount in token decimals.
priceMode_uint8The price mode (PRICE_MODE_MARKET = 1, PRICE_MODE_PEG = 2).

Returns

NameTypeDescription
usdValue_uint256The USD value in 1e27 precision.

_getTokenAmountForUsdValue ​

Converts a USD value to a token amount using the oracle's getPriceRawForMode.

solidity
function _getTokenAmountForUsdValue(address usdOracle_, address token_, uint256 usdValue_, uint8 priceMode_)
    internal
    view
    returns (uint256 amount_);

Parameters

NameTypeDescription
usdOracle_addressAddress of the FluidUsdOracle.
token_addressThe token address.
usdValue_uint256The USD value in 1e27 precision.
priceMode_uint8The price mode (PRICE_MODE_MARKET = 1, PRICE_MODE_PEG = 2).

Returns

NameTypeDescription
amount_uint256The token amount in token decimals.