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:
newModerator
address
The address to which moderator role is granted.
RevokeModeratorRole
event RevokeModeratorRole(address indexed moderator)
Emitted when the moderator role is revoked from an account.
Parameters:
moderator
address
The address from which moderator role is revoked.
SetTokenAndPair
event SetTokenAndPair(address indexed token, address indexed pair)
Emitted when the token and pair addresses are set for the UniswapV2PriceProvider contract.
Parameters:
token
address
The address of the token that is set.
pair
address
The address of the pair that is set.
ChangeActive
event ChangeActive(address indexed token, bool active)
Emitted when the active status of a token changes.
Parameters:
token
address
The address of the token whose active status has changed.
active
bool
The new active status of the token.
SetTokenDecimals
event SetTokenDecimals(uint8 newTokenDecimals)
Emitted when the token decimals is set.
Parameters:
newTokenDecimals
uint8
The new token decimals.
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:
newModerator
address
The address of the new moderator.
revokeModerator (0x36445636)
function revokeModerator(address moderator) public onlyAdmin
Revokes the moderator role from an address.
Parameters:
moderator
address
The address of the moderator to be revoked.
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:
newTokenDecimals
uint8
The new number of decimals used by the token.
setTokenAndPair (0xa6ff9e94)
function setTokenAndPair(address token, address pair) public onlyModerator
Sets the token and pair addresses for the UniswapV2PriceProvider contract.
Requirements:
token
andpair
addresses must not be zero.Only the contract moderator can call this function.
The
token
andpair
addresses must be valid.The
metadata
struct for thetoken
address must be updated with thepair
address,pairAsset
address,tokenDecimals
, andpairAssetDecimals
.
Parameters:
token
address
The address of the token to be set.
pair
address
The address of the pair to be set.
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:
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)
Check if a token is listed on UniswapV2.
Parameters:
token
address
The address of the token to check.
Return values:
[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 the specified token is active or not.
Parameters:
token
address
The address of the token to check.
Return values:
[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)
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:
token
address
The address of the token to get the price for.
Return values:
price
uint256
The price of the token in pairAsset.
priceDecimals
uint8
The number of decimals for the price.
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:
uniswapPair
address
The address of the Uniswap V2 pair.
tokenA
address
The address of the first token.
tokenB
address
The address of the second token.
Return values:
reserveA
uint256
The reserve of the first token.
reserveB
uint256
The reserve of the second token.
getPriceDecimals (0x1b30aafc)
function getPriceDecimals() public view override returns (uint8)
Returns the number of decimals used for the USD price.
Return values:
[0]
uint8
The number of decimals used for the USD price.
Last updated