Skip to content
This repository was archived by the owner on May 6, 2025. It is now read-only.

Update the SDK for downstream optimizations #32

Merged
merged 8 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove unneccsary events and event fields
  • Loading branch information
ali-behjati committed Nov 14, 2022
commit e424470a862aa13b9ebc9c6a7be9df9c85b4566f
14 changes: 2 additions & 12 deletions MockPyth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,37 +41,27 @@ contract MockPyth is AbstractPyth {
require(success, "failed to transfer update fee");
}

uint freshPrices = 0;

// Chain ID is id of the source chain that the price update comes from. Since it is just a mock contract
// We set it to 1.
uint16 chainId = 1;

for(uint i = 0; i < updateData.length; i++) {
PythStructs.PriceFeed memory priceFeed = abi.decode(updateData[i], (PythStructs.PriceFeed));

bool fresh = false;
uint lastPublishTime = priceFeeds[priceFeed.id].price.publishTime;

if (lastPublishTime < priceFeed.price.publishTime) {
// Price information is more recent than the existing price information.
fresh = true;
priceFeeds[priceFeed.id] = priceFeed;
freshPrices += 1;
emit PriceFeedUpdate(priceFeed.id, uint64(lastPublishTime), priceFeed.price.price, priceFeed.price.conf);
}

emit PriceFeedUpdate(priceFeed.id, fresh, chainId, sequenceNumber, priceFeed.price.publishTime,
lastPublishTime, priceFeed.price.price, priceFeed.price.conf);
}

// In the real contract, the input of this function contains multiple batches that each contain multiple prices.
// This event is emitted when a batch is processed. In this mock contract we consider there is only one batch of prices.
// Each batch has (chainId, sequenceNumber) as it's unique identifier. Here chainId is set to 1 and an increasing sequence number is used.
emit BatchPriceFeedUpdate(chainId, sequenceNumber, updateData.length, freshPrices);
emit BatchPriceFeedUpdate(chainId, sequenceNumber);
sequenceNumber += 1;

// There is only 1 batch of prices
emit UpdatePriceFeeds(msg.sender, 1, requiredFee);
}

function getUpdateFee(bytes[] calldata updateData) public override view returns (uint feeAmount) {
Expand Down
17 changes: 2 additions & 15 deletions PythEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,13 @@ pragma solidity ^0.8.0;
interface PythEvents {
/// @dev Emitted when an update for price feed with `id` is processed successfully.
/// @param id The Pyth Price Feed ID.
/// @param fresh True if the price update is more recent and stored.
/// @param chainId ID of the source chain that the batch price update containing this price.
/// This value comes from Wormhole, and you can find the corresponding chains at https://docs.wormholenetwork.com/wormhole/contracts.
/// @param sequenceNumber Sequence number of the batch price update containing this price.
/// @param lastPublishTime Publish time of the previously stored price.
/// @param publishTime Publish time of the given price update.
/// @param price Price of the given price update.
/// @param conf Confidence interval of the given price update.
event PriceFeedUpdate(bytes32 indexed id, bool indexed fresh, uint16 chainId, uint64 sequenceNumber, uint lastPublishTime, uint publishTime, int64 price, uint64 conf);
event PriceFeedUpdate(bytes32 indexed id, uint64 publishTime, int64 price, uint64 conf);

/// @dev Emitted when a batch price update is processed successfully.
/// @param chainId ID of the source chain that the batch price update comes from.
/// @param sequenceNumber Sequence number of the batch price update.
/// @param batchSize Number of prices within the batch price update.
/// @param freshPricesInBatch Number of prices that were more recent and were stored.
event BatchPriceFeedUpdate(uint16 chainId, uint64 sequenceNumber, uint batchSize, uint freshPricesInBatch);

/// @dev Emitted when a call to `updatePriceFeeds` is processed successfully.
/// @param sender Sender of the call (`msg.sender`).
/// @param batchCount Number of batches that this function processed.
/// @param fee Amount of paid fee for updating the prices.
event UpdatePriceFeeds(address indexed sender, uint batchCount, uint fee);
event BatchPriceFeedUpdate(uint16 chainId, uint64 sequenceNumber);
}