Skip to content
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

Merged
merged 11 commits into from
Sep 10, 2024
Merged

feat(target_chains/ton): add update_price_feeds #1870

merged 11 commits into from
Sep 10, 2024

Conversation

cctdaniel
Copy link
Contributor

@cctdaniel cctdaniel commented Sep 4, 2024

No description provided.

Copy link

vercel bot commented Sep 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-reference ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 9, 2024 1:05pm
staking-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 9, 2024 1:05pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
xc-admin-frontend ⬜️ Ignored (Inspect) Visit Preview Sep 9, 2024 1:05pm

Comment on lines -16 to -19
;; Constants
const int GUARDIAN_SET_EXPIRY = 86400; ;; 1 day in seconds
const int UPGRADE_MODULE = 0x0000000000000000000000000000000000000000000000000000000000436f7265; ;; "Core" (left-padded to 256 bits) in hex

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Comment on lines +121 to +156
// 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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +59 to 96
// 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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@ali-bahjati ali-bahjati left a 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.

target_chains/ton/contracts/contracts/Pyth.fc Show resolved Hide resolved
target_chains/ton/contracts/contracts/Wormhole.fc Outdated Show resolved Hide resolved
Comment on lines +149 to +174
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);
Copy link
Collaborator

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.

Copy link
Contributor Author

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
@cctdaniel cctdaniel merged commit 498edea into main Sep 10, 2024
6 checks passed
@cctdaniel cctdaniel deleted the ton-pyth branch September 10, 2024 06:06
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants