Skip to main content

Prices contract

Prices

You can use this contract to get prices from Sanr oracles.

Used in Predictions contract

Methods​

changePrice​

function changePrice(bytes32 symbol, uint256 newPrice) external nonpayable

Saves new symbol price

Parameters​

NameTypeDescription
symbolbytes32Symbol which price oracle want to save. Like 'BTC/USD'. In bytes32 'BTC/USD' is 0x4254432f55534400000000000000000000000000000000000000000000000000
newPriceuint256Symbol price *10^18. So if BTC/USD new price is 50000 newPrice should be 50000000000000000000000

changePrices​

function changePrices(bytes32[] symbol, uint256[] newPrice) external nonpayable

Saves new symbols prices

Parameters​

NameTypeDescription
symbolbytes32[]Symbols which prices oracle want to save. Like ['BTC/USD', 'BTC/ETH']. In bytes32 [0x4254432f55534400000000000000000000000000000000000000000000000000,0x4254432f45544800000000000000000000000000000000000000000000000000]
newPriceuint256[]Symbol prices *10^18. So if BTC/USD new price is 50000 and BTC/ETH price is 3000 newPrice should be [50000000000000000000000,3000000000000000000000]

currentPrice​

function currentPrice(bytes32 symbol) external view returns (uint256 price, uint256 timestamp, uint256 index)

Get last saved symbol price

Parameters​

NameTypeDescription
symbolbytes32Symbol which price you want to see. Like 'BTC/USD'. In bytes32 'BTC/USD' is 0x4254432f55534400000000000000000000000000000000000000000000000000

Returns​

NameTypeDescription
priceuint256Symbol price *10^18
timestampuint256Timestamp when the price was saved to this contract
indexuint256Total number of already saved prices for this symbol

currentPrices​

function currentPrices(bytes32[] symbol) external view returns (uint256[] prices, uint256[] timestamps, uint256[] indexes)

Get last saved symbols prices

Parameters​

NameTypeDescription
symbolbytes32[]Symbols which price you want to see. Like ['BTC/USD', 'BTC/ETH']. In bytes32 [0x4254432f55534400000000000000000000000000000000000000000000000000,0x4254432f45544800000000000000000000000000000000000000000000000000]

Returns​

NameTypeDescription
pricesuint256[]Symbols prices *10^18
timestampsuint256[]Timestamps when the prices was saved to this contract
indexesuint256[]Total number of already saved prices for these symbols

operators​

function operators(address) external view returns (bool)

Shows is the address allowed to push prices to this contract

variable. changing in setOperator()

Parameters​

NameTypeDescription
_0addressundefined

Returns​

NameTypeDescription
_0boolBool that is true if the address allowed to push prices to this contract

owner​

function owner() external view returns (address)

Returns the address of the current owner.

Returns​

NameTypeDescription
_0addressundefined

pricesByIndex​

function pricesByIndex(bytes32, uint256) external view returns (uint256 timestamp, uint256 price)

Shows the symbol price *10^18 and block timestamp when the price was saved to this contract by the index which is the ordinal number of the saved prices for this symbol

variable. changing in changePrice(). used to get current price in currentPrice()

Parameters​

NameTypeDescription
_0bytes32undefined
_1uint256undefined

Returns​

NameTypeDescription
timestampuint256undefined
priceuint256undefined

pricesByIndexes​

function pricesByIndexes(bytes32 symbol, uint256[] indexes) external view returns (struct Prices.Price[] prices)

Shows the symbol prices *10^18 and block timestamps when the prices was saved to this contract by the indexes which is the ordinal numbers of the saved prices for this symbol

Parameters​

NameTypeDescription
symbolbytes32Symbol which price you want to see. Like 'BTC/USD'. In bytes32 'BTC/USD' is 0x4254432f55534400000000000000000000000000000000000000000000000000
indexesuint256[]Ordinal numbers of the saved prices for this symbol.

Returns​

NameTypeDescription
pricesPrices.Price[]Structs that contains symbol price *10^18 and block timestamp when the price was saved to this contract

renounceOwnership​

function renounceOwnership() external nonpayable

Leaves the contract without owner. It will not be possible to call onlyOwner functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.

setOperator​

function setOperator(address operator, bool authorized) external nonpayable

Approve or disapprove the operator address

only for contract owner

Parameters​

NameTypeDescription
operatoraddressThe operator address
authorizedboolIs this address should be allowed to push prices

totalPrices​

function totalPrices(bytes32) external view returns (uint256)

Shows the total number symbol prices on this contract

variable. changing in changePrice(). used to get current price in currentPrice()

Parameters​

NameTypeDescription
_0bytes32undefined

Returns​

NameTypeDescription
_0uint256Total number of symbol prices on this contract

transferOwnership​

function transferOwnership(address newOwner) external nonpayable

Transfers ownership of the contract to a new account (newOwner). Can only be called by the current owner.

Parameters​

NameTypeDescription
newOwneraddressundefined

Events​

OwnershipTransferred​

event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)

Parameters​

NameTypeDescription
previousOwner indexedaddressundefined
newOwner indexedaddressundefined

SetOperator​

event SetOperator(address indexed operator, bool indexed authorized)

This event is emitted when contract owner approve or disapprove the operator address

emitted in setOperator() function

Parameters​

NameTypeDescription
operator indexedaddressThe operator address
authorized indexedboolIs this address should be allowed to push prices

Errors​

OwnableInvalidOwner​

error OwnableInvalidOwner(address owner)

The owner is not a valid owner account. (eg. address(0))

Parameters​

NameTypeDescription
owneraddressundefined

OwnableUnauthorizedAccount​

error OwnableUnauthorizedAccount(address account)

The caller account is not authorized to perform an operation.

Parameters​

NameTypeDescription
accountaddressundefined