Skip to content

Commit f96c4b1

Browse files
committed
doc: improve readme
1 parent 7e6eef7 commit f96c4b1

File tree

2 files changed

+41
-17
lines changed

2 files changed

+41
-17
lines changed

target_chains/ethereum/pulse_sdk/solidity/README.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,28 @@ struct SubscriptionParams {
5656
}
5757
```
5858

59+
### SubscriptionStatus
60+
61+
This struct tracks the current status of a Pulse subscription:
62+
63+
```solidity
64+
struct SubscriptionStatus {
65+
uint256 priceLastUpdatedAt; // Timestamp of the last update. All feeds in the subscription are updated together.
66+
uint256 balanceInWei; // Balance that will be used to fund the subscription's upkeep.
67+
uint256 totalUpdates; // Tracks update count across all feeds in the subscription (increments by number of feeds per update)
68+
uint256 totalSpent; // Counter of total fees paid for subscription upkeep in wei.
69+
}
70+
```
71+
5972
### UpdateCriteria
6073

6174
This struct defines when price feeds should be updated:
6275

6376
```solidity
6477
struct UpdateCriteria {
65-
bool updateOnHeartbeat; // Update based on time elapsed
78+
bool updateOnHeartbeat; // Should update based on time elapsed
6679
uint32 heartbeatSeconds; // Time interval for heartbeat updates
67-
bool updateOnDeviation; // Update based on price deviation
80+
bool updateOnDeviation; // Should update on price deviation
6881
uint32 deviationThresholdBps; // Price deviation threshold in basis points
6982
}
7083
```
@@ -93,13 +106,19 @@ uint256 minBalance = pulse.getMinimumBalance(uint8(params.priceIds.length));
93106
uint256 subscriptionId = pulse.createSubscription{value: minBalance}(params);
94107
```
95108

109+
## Updating a Subscription
110+
111+
You can update an existing subscription's parameters using the `updateSubscription` method. Only the subscription manager (the address that created it) can update a subscription, and permanent subscriptions cannot be updated afterwards.
112+
96113
## Reading Price Feeds
97114

98115
```solidity
99116
bytes32[] memory priceIds = new bytes32[](1);
100117
priceIds[0] = bytes32(...); // Pyth price feed ID
101118
102-
PythStructs.Price[] memory prices = pulse.getPricesUnsafe(subscriptionId, priceIds);
119+
// Specify maximum age in seconds (e.g., 300 seconds = 5 minutes)
120+
uint256 maxAge = 300;
121+
PythStructs.Price[] memory prices = pulse.getPricesNoOlderThan(subscriptionId, priceIds, maxAge);
103122
104123
// Access price data
105124
int64 price = prices[0].price;

target_chains/ethereum/pulse_sdk/solidity/SchedulerStructs.sol

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,32 @@
22

33
pragma solidity ^0.8.0;
44

5+
/// @title SchedulerStructs
6+
/// @notice Contains data structures used by the Pyth Pulse protocol
57
contract SchedulerStructs {
8+
/// @notice Parameters defining a Pulse subscription
69
struct SubscriptionParams {
7-
bytes32[] priceIds;
8-
address[] readerWhitelist;
9-
bool whitelistEnabled;
10-
bool isActive;
11-
bool isPermanent;
12-
UpdateCriteria updateCriteria;
10+
bytes32[] priceIds; // Array of Pyth price feed IDs to subscribe to
11+
address[] readerWhitelist; // Optional array of addresses allowed to read prices
12+
bool whitelistEnabled; // Whether to enforce whitelist or allow anyone to read
13+
bool isActive; // Whether the subscription is active
14+
bool isPermanent; // Whether the subscription can be updated
15+
UpdateCriteria updateCriteria; // When to update the price feeds
1316
}
1417

18+
/// @notice Status information for a Pulse subscription
1519
struct SubscriptionStatus {
16-
uint256 priceLastUpdatedAt;
17-
uint256 balanceInWei;
18-
uint256 totalUpdates;
19-
uint256 totalSpent;
20+
uint256 priceLastUpdatedAt; // Timestamp of the last update. All feeds in the subscription are updated together.
21+
uint256 balanceInWei; // Balance that will be used to fund the subscription's upkeep.
22+
uint256 totalUpdates; // Tracks update count across all feeds in the subscription (increments by number of feeds per update)
23+
uint256 totalSpent; // Counter of total fees paid for subscription upkeep in wei.
2024
}
2125

26+
/// @notice Criteria for when price feeds should be updated
2227
struct UpdateCriteria {
23-
bool updateOnHeartbeat;
24-
uint32 heartbeatSeconds;
25-
bool updateOnDeviation;
26-
uint32 deviationThresholdBps;
28+
bool updateOnHeartbeat; // Should update based on time elapsed
29+
uint32 heartbeatSeconds; // Time interval for heartbeat updates
30+
bool updateOnDeviation; // Should update based on price deviation
31+
uint32 deviationThresholdBps; // Price deviation threshold in basis points
2732
}
2833
}

0 commit comments

Comments
 (0)