PythGetters.sol 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // contracts/Getters.sol
  2. // SPDX-License-Identifier: Apache 2
  3. pragma solidity ^0.8.0;
  4. import "../wormhole/interfaces/IWormhole.sol";
  5. import "./PythInternalStructs.sol";
  6. import "./PythState.sol";
  7. contract PythGetters is PythState {
  8. function wormhole() public view returns (IWormhole) {
  9. return IWormhole(_state.wormhole);
  10. }
  11. /// Deprecated, use `validDataSources` instead
  12. function pyth2WormholeChainId() public view returns (uint16) {
  13. return _state._deprecatedPyth2WormholeChainId;
  14. }
  15. /// Deprecated, use `validDataSources` instead
  16. function pyth2WormholeEmitter() public view returns (bytes32) {
  17. return _state._deprecatedPyth2WormholeEmitter;
  18. }
  19. function latestPriceInfo(
  20. bytes32 priceId
  21. ) internal view returns (PythInternalStructs.PriceInfo memory info) {
  22. return _state.latestPriceInfo[priceId];
  23. }
  24. function latestPriceInfoPublishTime(
  25. bytes32 priceId
  26. ) public view returns (uint64) {
  27. return _state.latestPriceInfo[priceId].publishTime;
  28. }
  29. function hashDataSource(
  30. PythInternalStructs.DataSource memory ds
  31. ) public pure returns (bytes32) {
  32. return keccak256(abi.encodePacked(ds.chainId, ds.emitterAddress));
  33. }
  34. function isValidDataSource(
  35. uint16 dataSourceChainId,
  36. bytes32 dataSourceEmitterAddress
  37. ) public view returns (bool) {
  38. return
  39. _state.isValidDataSource[
  40. keccak256(
  41. abi.encodePacked(
  42. dataSourceChainId,
  43. dataSourceEmitterAddress
  44. )
  45. )
  46. ];
  47. }
  48. function isValidGovernanceDataSource(
  49. uint16 governanceChainId,
  50. bytes32 governanceEmitterAddress
  51. ) public view returns (bool) {
  52. return
  53. _state.governanceDataSource.chainId == governanceChainId &&
  54. _state.governanceDataSource.emitterAddress ==
  55. governanceEmitterAddress;
  56. }
  57. function chainId() public view returns (uint16) {
  58. return wormhole().chainId();
  59. }
  60. function lastExecutedGovernanceSequence() public view returns (uint64) {
  61. return _state.lastExecutedGovernanceSequence;
  62. }
  63. function validDataSources()
  64. public
  65. view
  66. returns (PythInternalStructs.DataSource[] memory)
  67. {
  68. return _state.validDataSources;
  69. }
  70. function governanceDataSource()
  71. public
  72. view
  73. returns (PythInternalStructs.DataSource memory)
  74. {
  75. return _state.governanceDataSource;
  76. }
  77. function singleUpdateFeeInWei() public view returns (uint) {
  78. return _state.singleUpdateFeeInWei;
  79. }
  80. function validTimePeriodSeconds() public view returns (uint) {
  81. return _state.validTimePeriodSeconds;
  82. }
  83. function governanceDataSourceIndex() public view returns (uint32) {
  84. return _state.governanceDataSourceIndex;
  85. }
  86. }