// SPDX-License-Identifier: MIT
pragma solidity 0.8.29;
import { RequestOracle } from "@dia-data/contracts-spectra/RequestOracle.sol";
contract PullOracleSample {
address public constant DIA_RECIPIENT = 0x9bb71344Ed950F9cFD85EE1C7258553B01d95FA0; // DIA testnet
uint32 public constant DESTINATION_DOMAIN = 100640; // DIA testnet chain id
RequestOracle public diaOracle;
string public key = "BTC/USD";
constructor(address _requestOracle) {
diaOracle = RequestOracle(payable(_requestOracle));
}
/*
* To calculate the request fee on each chain, you can check the script below:
* https://github.com/diadata-org/Spectra-interoperability/blob/main/contracts/scripts/sendTestMessage.mjs#L111
*/
function requestPrice(string memory key) external payable {
diaOracle.request{value: msg.value}(
DIA_RECIPIENT,
DESTINATION_DOMAIN,
abi.encode(key)
);
}
function getPrice()
external
view
returns (
uint128 timestampOflatestPrice,
uint128 latestPrice
) {
(timestampOflatestPrice, latestPrice) =
diaOracle.updates(key);
}
}