IScheduler.sol 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // SPDX-License-Identifier: Apache 2
  2. pragma solidity ^0.8.0;
  3. import "@pythnetwork/pyth-sdk-solidity/IPyth.sol";
  4. import "@pythnetwork/pyth-sdk-solidity/PythStructs.sol";
  5. import "./SchedulerEvents.sol";
  6. import "./SchedulerStructs.sol";
  7. interface IScheduler is SchedulerEvents {
  8. /// @notice Creates a new subscription
  9. /// @dev Requires msg.value to be at least the minimum balance for the subscription (calculated by getMinimumBalance()).
  10. /// @param subscriptionParams The parameters for the subscription
  11. /// @return subscriptionId The ID of the newly created subscription
  12. function createSubscription(
  13. SchedulerStructs.SubscriptionParams calldata subscriptionParams
  14. ) external payable returns (uint256 subscriptionId);
  15. /// @notice Gets a subscription's parameters and status
  16. /// @param subscriptionId The ID of the subscription
  17. /// @return params The subscription parameters
  18. /// @return status The subscription status
  19. function getSubscription(
  20. uint256 subscriptionId
  21. )
  22. external
  23. view
  24. returns (
  25. SchedulerStructs.SubscriptionParams memory params,
  26. SchedulerStructs.SubscriptionStatus memory status
  27. );
  28. /// @notice Updates an existing subscription
  29. /// @dev You can activate or deactivate a subscription by setting isActive to true or false. Reactivating a subscription
  30. /// requires the subscription to hold at least the minimum balance (calculated by getMinimumBalance()).
  31. /// @dev Any Ether sent with this call (`msg.value`) will be added to the subscription's balance before processing the update.
  32. /// @param subscriptionId The ID of the subscription to update
  33. /// @param newSubscriptionParams The new parameters for the subscription
  34. function updateSubscription(
  35. uint256 subscriptionId,
  36. SchedulerStructs.SubscriptionParams calldata newSubscriptionParams
  37. ) external payable;
  38. /// @notice Updates price feeds for a subscription.
  39. /// @dev The updateData must contain all price feeds for the subscription, not a subset or superset.
  40. /// @dev Internally, the updateData is verified using the Pyth contract and validates update conditions.
  41. /// The call will only succeed if the update conditions for the subscription are met.
  42. /// @param subscriptionId The ID of the subscription
  43. /// @param updateData The price update data from Pyth
  44. function updatePriceFeeds(
  45. uint256 subscriptionId,
  46. bytes[] calldata updateData
  47. ) external;
  48. /// @notice Returns the price of a price feed without any sanity checks.
  49. /// @dev This function returns the most recent price update in this contract without any recency checks.
  50. /// This function is unsafe as the returned price update may be arbitrarily far in the past.
  51. ///
  52. /// Users of this function should check the `publishTime` in the price to ensure that the returned price is
  53. /// sufficiently recent for their application. If you are considering using this function, it may be
  54. /// safer / easier to use `getPricesNoOlderThan`.
  55. /// @return prices - please read the documentation of PythStructs.Price to understand how to use this safely.
  56. function getPricesUnsafe(
  57. uint256 subscriptionId,
  58. bytes32[] calldata priceIds
  59. ) external view returns (PythStructs.Price[] memory prices);
  60. /// @notice Returns the price that is no older than `age` seconds of the current time.
  61. /// @dev This function is a sanity-checked version of `getPriceUnsafe` which is useful in
  62. /// applications that require a sufficiently-recent price. Reverts if the price wasn't updated sufficiently
  63. /// recently.
  64. /// @return prices - please read the documentation of PythStructs.Price to understand how to use this safely.
  65. function getPricesNoOlderThan(
  66. uint256 subscriptionId,
  67. bytes32[] calldata priceIds,
  68. uint256 age
  69. ) external view returns (PythStructs.Price[] memory prices);
  70. /// @notice Returns the exponentially-weighted moving average price of a price feed without any sanity checks.
  71. /// @dev This function returns the same price as `getEmaPrice` in the case where the price is available.
  72. /// However, if the price is not recent this function returns the latest available price.
  73. ///
  74. /// The returned price can be from arbitrarily far in the past; this function makes no guarantees that
  75. /// the returned price is recent or useful for any particular application.
  76. ///
  77. /// Users of this function should check the `publishTime` in the price to ensure that the returned price is
  78. /// sufficiently recent for their application. If you are considering using this function, it may be
  79. /// safer / easier to use either `getEmaPrice` or `getEmaPriceNoOlderThan`.
  80. /// @return prices - please read the documentation of PythStructs.Price to understand how to use this safely.
  81. function getEmaPricesUnsafe(
  82. uint256 subscriptionId,
  83. bytes32[] calldata priceIds
  84. ) external view returns (PythStructs.Price[] memory prices);
  85. /// @notice Returns the exponentially-weighted moving average price that is no older than `age_seconds` seconds
  86. /// of the current time.
  87. /// @dev This function is a sanity-checked version of `getEmaPricesUnsafe` which is useful in
  88. /// applications that require a sufficiently-recent price. Reverts if the price wasn't updated sufficiently
  89. /// recently.
  90. /// @return prices - please read the documentation of PythStructs.Price to understand how to use this safely.
  91. function getEmaPricesNoOlderThan(
  92. uint256 subscriptionId,
  93. bytes32[] calldata priceIds,
  94. uint256 age_seconds
  95. ) external view returns (PythStructs.Price[] memory prices);
  96. /// @notice Adds funds to a subscription's balance
  97. /// @param subscriptionId The ID of the subscription
  98. function addFunds(uint256 subscriptionId) external payable;
  99. /// @notice Withdraws funds from a subscription's balance.
  100. /// @dev A minimum balance must be maintained for active subscriptions. To withdraw past
  101. /// the minimum balance limit, deactivate the subscription first.
  102. /// @param subscriptionId The ID of the subscription
  103. /// @param amount The amount to withdraw
  104. function withdrawFunds(uint256 subscriptionId, uint256 amount) external;
  105. /// @notice Returns the minimum balance an active subscription of a given size needs to hold.
  106. /// @param numPriceFeeds The number of price feeds in the subscription.
  107. function getMinimumBalance(
  108. uint8 numPriceFeeds
  109. ) external view returns (uint256 minimumBalanceInWei);
  110. /// @notice Gets all active subscriptions with their parameters, paginated.
  111. /// @dev This function has no access control to allow keepers to discover active subscriptions.
  112. /// @dev Note that the order of subscription IDs returned may not be sequential and can change
  113. /// when subscriptions are deactivated or reactivated.
  114. /// @param startIndex The starting index within the list of active subscriptions (NOT the subscription ID).
  115. /// @param maxResults The maximum number of results to return starting from startIndex.
  116. /// @return subscriptionIds Array of active subscription IDs
  117. /// @return subscriptionParams Array of subscription parameters for each active subscription
  118. /// @return totalCount Total number of active subscriptions
  119. function getActiveSubscriptions(
  120. uint256 startIndex,
  121. uint256 maxResults
  122. )
  123. external
  124. view
  125. returns (
  126. uint256[] memory subscriptionIds,
  127. SchedulerStructs.SubscriptionParams[] memory subscriptionParams,
  128. uint256 totalCount
  129. );
  130. }