UniswapV2PriceProvider

Overview

License: MIT

contract UniswapV2PriceProvider is PriceProvider, Initializable, AccessControlUpgradeable

This implementation can be affected by price manipulation due to not using TWAP. For development purposes only

Structs info

UniswapV2Metadata

struct UniswapV2Metadata {
	bool isActive;
	address pair;
	address pairAsset;
	uint8 tokenDecimals;
	uint8 pairAssetDecimals;
}

Events info

GrantModeratorRole

event GrantModeratorRole(address indexed newModerator)

Emitted when the moderator role is granted to a new account.

Parameters:

RevokeModeratorRole

event RevokeModeratorRole(address indexed moderator)

Emitted when the moderator role is revoked from an account.

Parameters:

SetTokenAndPair

event SetTokenAndPair(address indexed token, address indexed pair)

Emitted when the token and pair addresses are set for the UniswapV2PriceProvider 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:

Constants info

MODERATOR_ROLE (0x797669c9)

bytes32 constant MODERATOR_ROLE = keccak256("MODERATOR_ROLE")

DESCRIPTION (0xf1ae8856)

string constant DESCRIPTION = "Price provider that uses uniswapV2"

State variables info

tokenDecimals (0x3b97e856)

uint8 tokenDecimals

uniswapV2Metadata (0x809205db)

mapping(address => struct UniswapV2PriceProvider.UniswapV2Metadata) uniswapV2Metadata

Modifiers info

onlyAdmin

modifier onlyAdmin()

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

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.

grantModerator (0x6981c7ae)

function grantModerator(address newModerator) public onlyAdmin

Grants the moderator role to a new address.

Parameters:

revokeModerator (0x36445636)

function revokeModerator(address moderator) public onlyAdmin

Revokes the moderator role from an address.

Parameters:

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 (0xa6ff9e94)

function setTokenAndPair(address token, address pair) public onlyModerator

Sets the token and pair addresses for the UniswapV2PriceProvider contract.

Requirements:

  • token and pair addresses must not be zero.

  • Only the contract moderator can call this function.

  • The token and pair addresses must be valid.

  • The metadata struct for the token address must be updated with the pair address, pairAsset address, tokenDecimals, and pairAssetDecimals.

Parameters:

changeActive (0x258a4532)

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

Changes the active status of a token in the UniswapV2PriceProvider contract.

Requirements:

  • The token must be listed in the UniswapV2PriceProvider 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 UniswapV2.

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 price, 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:

getReserves (0x32749461)

function getReserves(
    address uniswapPair,
    address tokenA,
    address tokenB
) public view returns (uint256 reserveA, uint256 reserveB)

Returns the reserves of the specified Uniswap V2 pair for the given tokens.

Parameters:

Return values:

getPriceDecimals (0x1b30aafc)

function getPriceDecimals() public view override returns (uint8)

Returns the number of decimals used for the USD price.

Return values:

Last updated