UniswapV3PriceProvider

Overview

License: MIT

contract UniswapV3PriceProvider is PriceProvider, Initializable, AccessControlUpgradeable

Structs info

UniswapV3Metadata

struct UniswapV3Metadata {
	bool isActive;
	address[] aggregatorPath;
}

UniswapV3MetadataPair

struct UniswapV3MetadataPair {
	address token;
	address pairToken;
	uint8 tokenDecimals;
	uint8 pairTokenDecimals;
	uint32 pricePointTWAPperiod;
}

Events info

SetTokenAndPair

event SetTokenAndPair(address indexed token, address indexed pair)

Emitted when the token and pair addresses are set for the UniswapV3PriceProvider contract.

Parameters:

ChangeActive

event ChangeActive(address indexed token, bool active)

Emitted when the active status of a token changes.

Parameters:

SetTokenDecimals

event SetTokenDecimals(uint8 newTokenDecimals)

Emitted when the token decimals is set.

Parameters:

SetTokenAndAggregator

event SetTokenAndAggregator(address indexed token, address[] aggregatorPath, uint32[] pricePointPeriod)

Emitted when a token and its corresponding UniswapV3 aggregator path are set.

Parameters:

Constants info

MODERATOR_ROLE (0x797669c9)

bytes32 constant MODERATOR_ROLE = keccak256("MODERATOR_ROLE")

DESCRIPTION (0xf1ae8856)

string constant DESCRIPTION = "Price provider that uses uniswapV3"

MAX_PRICE_PATH_LENGTH (0x01a9a5d3)

uint8 constant MAX_PRICE_PATH_LENGTH = 4

State variables info

tokenDecimals (0x3b97e856)

uint8 tokenDecimals

uniswapV3Metadata (0xe84cbb89)

mapping(address => struct UniswapV3PriceProvider.UniswapV3Metadata) uniswapV3Metadata

uniswapV3MetadataPair (0x918d7a98)

mapping(address => struct UniswapV3PriceProvider.UniswapV3MetadataPair) uniswapV3MetadataPair

Modifiers info

onlyModerator

modifier onlyModerator()

Modifier to restrict access to functions to only the contract moderator.

Functions info

initialize (0x8129fc1c)

function initialize() public initializer

Initializes the contract by setting up the access control roles and the number of decimals for the USD token. decimals is set to 18.

setTokenDecimals (0xf2cf47be)

function setTokenDecimals(uint8 newTokenDecimals) public onlyModerator

Sets the number of decimals used by the token. Only the moderator can call this function.

Parameters:

setTokenAndPair (0x8d46526f)

function setTokenAndPair(
    address token,
    address[] memory aggregatorPath,
    uint32[] memory pricePointPeriod
) external onlyModerator

Set token and aggregator path.

Requirements:

  • The token must be listed in the UniswapV3PriceProvider contract.

  • Only the contract moderator can call this function.

Parameters:

changeActive (0x258a4532)

function changeActive(address token, bool active) public override onlyModerator

Changes the active status of a token in the UniswapV3PriceProvider con tract.

Requirements:

  • The token must be listed in the UniswapV3PriceProvider contract.

  • Only the contract moderator can call this function.

Parameters:

isListed (0xf794062e)

function isListed(address token) public view override returns (bool)

Check if a token is listed on UniswapV3.

Parameters:

Return values:

isActive (0x9f8a13d7)

function isActive(address token) public view override returns (bool)

Returns whether the specified token is active or not.

Parameters:

Return values:

getPrice (0x41976e09)

function getPrice(
    address token
) public view override returns (uint256 priceMantissa, uint8 priceDecimals)

This function requires that the token is active in the price provider. Returns the price of a given token in pairAsset, and the number of decimals for the price.

Parameters:

Return values:

getUnderlyingTokenPrice (0x8020c854)

function getUnderlyingTokenPrice(
    address token,
    address pair
) public view returns (uint256 price, uint8 priceDecimals, address pairAsset)

getPriceDecimals (0x1b30aafc)

function getPriceDecimals() public view override returns (uint8)

Returns the number of decimals used for the USD price.

Return values:

getUniswapV3Metadata (0xb790348b)

function getUniswapV3Metadata(
    address token
) public view returns (UniswapV3PriceProvider.UniswapV3Metadata memory)

Returns the metadata set up for token.

Parameters:

Return values:

Last updated