UniswapV2PriceProviderMock

Overview

License: MIT

contract UniswapV2PriceProviderMock is PriceProvider, Initializable, AccessControlUpgradeable

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

Structs info

PriceInfo

struct PriceInfo {
	uint256 price;
	uint8 tokenDecimals;
}

UniswapV2Metadata

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

Events info

GrantModeratorRole

event GrantModeratorRole(address indexed newModerator)

RevokeModeratorRole

event RevokeModeratorRole(address indexed moderator)

SetTokenAndPrice

event SetTokenAndPrice(address indexed token, uint256 price)

ChangeActive

event ChangeActive(address indexed token, bool active)

SetTokenDecimals

event SetTokenDecimals(uint8 newTokenDecimals)

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 UniswapV2PriceProviderMock.UniswapV2Metadata) uniswapV2Metadata

tokenPrice (0x84ba3f69)

mapping(address => struct UniswapV2PriceProviderMock.PriceInfo) tokenPrice

Modifiers info

onlyAdmin

modifier onlyAdmin()

onlyModerator

modifier onlyModerator()

Functions info

initialize (0x8129fc1c)

function initialize() public initializer

grantModerator (0x6981c7ae)

function grantModerator(address newModerator) public onlyAdmin

revokeModerator (0x36445636)

function revokeModerator(address moderator) public onlyAdmin

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:

NameTypeDescription

newTokenDecimals

uint8

The new number of decimals used by the token.

setTokenAndPrice (0x179750ec)

function setTokenAndPrice(address token, uint256 price) public onlyModerator

changeActive (0x258a4532)

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

Changes the active status of a token.

Parameters:

NameTypeDescription

token

address

The address of the token to change the active status for.

active

bool

The new active status of the token.

isListed (0xf794062e)

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

Returns a boolean indicating whether the given token address is listed in the price provider.

Parameters:

NameTypeDescription

token

address

The address of the token to check.

Return values:

NameTypeDescription

[0]

bool

A boolean indicating whether the token is listed or not.

isActive (0x9f8a13d7)

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

Returns whether a token is active or not.

Parameters:

NameTypeDescription

token

address

The address of the token to check.

Return values:

NameTypeDescription

[0]

bool

A boolean indicating whether the token is active or not.

getPrice (0x41976e09)

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

Returns the price of the specified token.

Parameters:

NameTypeDescription

token

address

The address of the token to get the price for.

Return values:

NameTypeDescription

priceMantissa

uint256

The price of the token, represented as a mantissa.

priceDecimals

uint8

The number of decimal places in the token's price.

getReserves (0x32749461)

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

getPriceDecimals (0x1b30aafc)

function getPriceDecimals() public view override returns (uint8)

Returns the number of decimal places for the price returned by the price provider.

Return values:

NameTypeDescription

priceDecimals

uint8

The number of decimal places for the price.

Last updated