You can find the list of supported assets here .
The current Pragma addresses are:
Network Address Explorer Starknet Mainnet 0x2a85bd616f912537c50a49a4076db02c00b29b2cdc8a197ce92ed1837fa875b Starkscan Voyager Starknet Sepolia 0x36031daa264c24520b11d93af622c848b2499b66b41d611bac95e13cfca131a Starkscan Voyager
Sample Code
If you are just trying to get started with our price feeds, see the self-contained code snippets below. If you’d like to use more advanced oracle functions please see the further information below. You can find a full sample data feed consumer contract here and the full Oracle interface specification is available here .
Add Pragma as a dependency to your scarb/snforge project
get_asset_price_median.cairo
usage.cairo
use pragma_lib:: abi:: { IPragmaABIDispatcher , IPragmaABIDispatcherTrait } ;
use pragma_lib:: types:: { AggregationMode , DataType , PragmaPricesResponse } ;
use starknet:: ContractAddress ;
use starknet:: contract_address:: contract_address_const;
const KEY : felt252 = 18669995996566340 ;
fn get_asset_price_median ( oracle_address: ContractAddress , asset : DataType ) -> u128 {
let oracle_dispatcher = IPragmaABIDispatcher { contract_address : oracle_address} ;
let output : PragmaPricesResponse = oracle_dispatcher. get_data ( asset, AggregationMode :: Median ( ( ) ) ) ;
return output. price;
}
SOL/USD Spot Average Price, filtered by sources
get_asset_price_average.cairo
usage.cairo
use pragma_lib:: abi:: { IPragmaABIDispatcher , IPragmaABIDispatcherTrait } ;
use pragma_lib:: types:: { AggregationMode , DataType , PragmaPricesResponse } ;
use starknet:: ContractAddress ;
use starknet:: contract_address:: contract_address_const;
use array:: ArrayTrait ;
const KEY : felt252 = 23449611697214276 ;
const OKX : felt252 = 'OKX ';
const BINANCE : felt252 = 'BINANCE ';
fn get_asset_price_average ( oracle_address: ContractAddress , asset : DataType , sources : Span < felt252> ) -> u128 {
let oracle_dispatcher = IPragmaABIDispatcher { contract_address : oracle_address} ;
let output : PragmaPricesResponse = oracle_dispatcher. get_data_for_sources ( asset, AggregationMode :: Mean ( ( ) ) , sources) ;
return output. price;
}
BTC/USD Future Price
get_asset_price_median.cairo
usage.cairo
use pragma_lib:: abi:: { IPragmaABIDispatcher , IPragmaABIDispatcherTrait } ;
use pragma_lib:: types:: { AggregationMode , DataType , PragmaPricesResponse } ;
use starknet:: ContractAddress ;
use starknet:: contract_address:: contract_address_const;
const KEY : felt252 = 18669995996566340 ;
fn get_asset_price_median ( oracle_address: ContractAddress , asset : DataType ) -> u128 {
let oracle_dispatcher = IPragmaABIDispatcher { contract_address : oracle_address} ;
let output : PragmaPricesResponse = oracle_dispatcher. get_data ( asset, AggregationMode :: Median ( ( ) ) ) ;
return output. price;
}
Conversion Rate
For some assets such as liquid staking tokens, it’s actually more relevant to use the conversion rate rather than the market price given the liquidity is often poor for these assets.
To use this special aggregation method, the base token first needs to be associated to a vault address which follows the ERC4626 standard.
Sample code
get_asset_conversion_rate.cairo
usage.cairo
use pragma_lib:: abi:: { IPragmaABIDispatcher , IPragmaABIDispatcherTrait } ;
use pragma_lib:: types:: { AggregationMode , DataType , PragmaPricesResponse } ;
use starknet:: ContractAddress ;
use starknet:: contract_address:: contract_address_const;
const KEY : felt252 = 1629317993172502401860 ;
fn get_asset_conversion_rate ( oracle_address: ContractAddress , asset : DataType ) -> u128 {
let oracle_dispatcher = IPragmaABIDispatcher { contract_address : oracle_address} ;
let output : PragmaPricesResponse = oracle_dispatcher. get_data ( asset, AggregationMode :: ConversionRate ) ;
return output. price;
}
Alternatively, we implemented a specialized conversion rate feed that automatically calculates the conversion rate for specific feeds. Calling these feeds follows a process similar to retrieving spot BTC/USD prices.
Supported feeds:
Pair Pair Id Decimals CONVERSION_XSTRK/USD 384270964630611589151504336040175440891848512324 8 CONVERSION_SSTRK/USD 384270964630611589151504335947941720523300754244 8
get_asset_conversion_rate.cairo
usage.cairo
use pragma_lib:: abi:: { IPragmaABIDispatcher , IPragmaABIDispatcherTrait } ;
use pragma_lib:: types:: { AggregationMode , DataType , PragmaPricesResponse } ;
use starknet:: ContractAddress ;
use starknet:: contract_address:: contract_address_const;
const KEY : felt252 = 384270964630611589151504336040175440891848512324 ;
fn get_asset_conversion_rate ( oracle_address: ContractAddress , asset : DataType ) -> u128 {
let oracle_dispatcher = IPragmaABIDispatcher { contract_address : oracle_address} ;
let output : PragmaPricesResponse = oracle_dispatcher. get_data ( asset, AggregationMode :: Median ) ;
return output. price;
}
It will only work with the Median
aggregation mode.
Technical Specification