-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(target_chains/ton): add update_price_feeds #1870
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
;; Constants | ||
const int GUARDIAN_SET_EXPIRY = 86400; ;; 1 day in seconds | ||
const int UPGRADE_MODULE = 0x0000000000000000000000000000000000000000000000000000000000436f7265; ;; "Core" (left-padded to 256 bits) in hex | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to common/constants.fc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is unfortunate because a cell has a limit of 4 refs max, and when we store dict, the underlying also uses refs which will then exceed this limit, hence we break them into 4 general groups:
- price_feeds_cell
- data_sources_cell
- guardian_set_cell
- governance_cell
happy to get any alternative feedback if there are better ways to do this
// Group price feeds and update fee | ||
const priceFeedsCell = beginCell() | ||
.storeDict(priceDict) | ||
.storeUint(singleUpdateFee, 256) | ||
.endCell(); | ||
|
||
// Group data sources information | ||
const dataSourcesCell = beginCell() | ||
.storeDict(dataSourcesDict) | ||
.storeUint(dataSources.length, 32) | ||
.storeDict(isValidDataSourceDict) | ||
.endCell(); | ||
|
||
// Group guardian set information | ||
const guardianSetCell = beginCell() | ||
.storeUint(guardianSetIndex, 32) | ||
.storeDict(createGuardianSetsDict(guardianSet, guardianSetIndex)) | ||
.endCell(); | ||
|
||
// Group chain and governance information | ||
const governanceCell = beginCell() | ||
.storeUint(chainId, 16) | ||
.storeUint(governanceChainId, 16) | ||
.storeBuffer(Buffer.from(governanceContract, "hex")) | ||
.storeDict(Dictionary.empty()) // consumed_governance_actions | ||
.storeRef(beginCell()) // governance_data_source, empty for initial state | ||
.storeUint(0, 64) // last_executed_governance_sequence | ||
.storeUint(0, 32) // governance_data_source_index | ||
.endCell(); | ||
|
||
// Create the main cell with references to grouped data | ||
return beginCell() | ||
.storeDict(priceDict) // latest_price_feeds | ||
.storeUint(singleUpdateFee, 256) // single_update_fee | ||
.storeUint(0, 32) | ||
.storeDict(Dictionary.empty()) | ||
.storeUint(0, 16) | ||
.storeUint(0, 16) | ||
.storeBuffer( | ||
Buffer.from( | ||
"0000000000000000000000000000000000000000000000000000000000000000", | ||
"hex" | ||
) | ||
) | ||
.storeDict(Dictionary.empty()) // consumed_governance_actions, | ||
.storeRef(priceFeedsCell) | ||
.storeRef(dataSourcesCell) | ||
.storeRef(guardianSetCell) | ||
.storeRef(governanceCell) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as mentioned here: https://github.com/pyth-network/pyth-crosschain/pull/1870/files#r1743750041
// Group price feeds and update fee (empty for Wormhole) | ||
const priceFeedsCell = beginCell() | ||
.storeDict(Dictionary.empty()) // latest_price_feeds, empty for initial state | ||
.storeUint(0, 256) // single_update_fee, set to 0 for testing | ||
.endCell(); | ||
|
||
// Group data sources information (empty for initial state) | ||
const dataSourcesCell = beginCell() | ||
.storeDict(Dictionary.empty()) // data_sources, empty for initial state | ||
.storeUint(0, 32) // num_data_sources, set to 0 for initial state | ||
.storeDict(Dictionary.empty()) // is_valid_data_source, empty for initial state | ||
.endCell(); | ||
|
||
// Group guardian set information | ||
const guardianSetCell = beginCell() | ||
.storeUint(guardianSetIndex, 32) | ||
.storeDict(guardianSets) | ||
.storeDict(createGuardianSetsDict(guardianSet, guardianSetIndex)) | ||
.endCell(); | ||
|
||
// Group chain and governance information | ||
const governanceCell = beginCell() | ||
.storeUint(chainId, 16) | ||
.storeUint(governanceChainId, 16) | ||
.storeBuffer(Buffer.from(governanceContract, "hex")) | ||
.storeDict(Dictionary.empty()) // consumed_governance_actions, empty for initial state | ||
.storeRef(beginCell()) // governance_data_source, empty for initial state | ||
.storeUint(0, 64) // last_executed_governance_sequence, set to 0 for initial state | ||
.storeUint(0, 32) // governance_data_source_index, set to 0 for initial state | ||
.endCell(); | ||
|
||
// Create the main cell with references to grouped data | ||
return beginCell() | ||
.storeRef(priceFeedsCell) | ||
.storeRef(dataSourcesCell) | ||
.storeRef(guardianSetCell) | ||
.storeRef(governanceCell) | ||
.endCell(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as mentioned here: https://github.com/pyth-network/pyth-crosschain/pull/1870/files#r1743750041
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I have some questions and suggestions. Will approve after you address them.
price_slice~load_int(64); ;; Skip price | ||
price_slice~load_uint(64); ;; Skip conf | ||
price_slice~load_int(32); ;; Skip expo | ||
latest_publish_time = price_slice~load_uint(64); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: i think having latest_publish_time as the first element is more ergonomic in the places it is being used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm i was trying to keep it as the same order as the message in read_and_verify_message
* add more placeholder test functions * add logic for tests * precommit * add test for get_chain_id * move execute_governance_action to Pyth.fc * add comments to test contracts * precommit
No description provided.