-
Notifications
You must be signed in to change notification settings - Fork 97
[intent-coprocessor]: Price Discovery Protocol #684
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
Open
dharjeezy
wants to merge
32
commits into
main
Choose a base branch
from
dami/filler-price-pair-update
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
b0e0383
allow fillers to sumbmit pair price using membership and non membersh…
dharjeezy fad61b6
vec
dharjeezy c8257eb
Merge branch 'main' of github.com:polytope-labs/hyperbridge into dami…
dharjeezy 004dd9c
dual-path price submission system for verified prices and unverified …
dharjeezy cb2c312
TreasuryAccount in config
dharjeezy 9d13e85
fmt
dharjeezy 6e47e72
introduce price range input, include docs
dharjeezy 6b7dcc1
cross-chain filler verification by inspecting RedeemEscrow messages …
dharjeezy 00d16dd
fully reserve deposit price submission
dharjeezy 4fd12d4
simplex integration for price update
dharjeezy fb824aa
address concerns
dharjeezy 789d109
tested out implementation
dharjeezy dae9ad7
update to doc
dharjeezy d925949
block price submissions when a withdrawal is in progress, use H256 fo…
dharjeezy 9307348
Merge main: resolve conflicts in FX strategy and simplex config
dharjeezy 561ad9d
remove service
dharjeezy ffc5a1e
use price policy to get points
dharjeezy f9cbd1d
clear stale prices per pair, compute pair ids automatically, submit a…
dharjeezy 6762e78
simplify pair IDs to keccak256("base/quote"), replace timestamp with …
dharjeezy ef25136
benchmarks, simplified price entries
dharjeezy a73292f
configurable stablecoin addresses, update simtest, and add per-entry …
dharjeezy dcfb1c1
update docs
dharjeezy 790e716
getQuotes method
dharjeezy 37d57f3
Merge branches 'dami/filler-price-pair-update' and 'main' of github.c…
dharjeezy 51bc01d
refacoring
dharjeezy 46c3574
introduce side to differentiate prices for asks and bids,
dharjeezy 93e5fe6
interpolate
dharjeezy 03dff76
revert side
dharjeezy 8a3f9cd
register pair via reserve deposits
dharjeezy b243ee4
Merge branch 'main' of github.com:polytope-labs/hyperbridge into dami…
dharjeezy 80d0398
fee based submission
dharjeezy 231c1f2
filter 24 hours prices
dharjeezy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "title": "Intent Gateway", | ||
| "pages": ["overview", "placing-orders", "cancelling-orders", "simplex"], | ||
| "pages": ["overview", "placing-orders", "cancelling-orders", "simplex", "price-submission"], | ||
| "defaultOpen": false | ||
| } |
70 changes: 70 additions & 0 deletions
70
docs/content/developers/intent-gateway/price-submission.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| --- | ||
| title: Price Submission Protocol | ||
| description: Dual-path price submission system for the intents coprocessor pallet | ||
| --- | ||
|
|
||
| # Price Submission Protocol | ||
|
|
||
| ## Overview | ||
|
|
||
| The intents system needs on-chain price data for token pairs to function correctly. The challenge is sourcing reliable prices without depending on external oracles, while still ensuring data availability when verified sources are temporarily scarce. | ||
|
|
||
| ## Protocol Overview | ||
|
|
||
| The `submit_pair_price` extrinsic on the intents coprocessor pallet accepts price submissions for governance-approved token pairs. It supports two confidence levels through a single entry point, distinguished by an optional `verification` parameter. All prices are assumed to have 18 decimal places. | ||
|
|
||
| ### Verified Prices (High Confidence) | ||
|
|
||
| Fillers who have actually filled orders on the IntentGateway contract submit prices along with cryptographic proof of their fill. This path exists because fillers are the most trustworthy source of price data. They have real skin in the game and their prices reflect actual market activity. | ||
|
|
||
| A verified submission requires three things: | ||
|
|
||
| 1. **Two ISMP state proofs** against the IntentGateway contract's `_filled` mapping. A non-membership proof at height H1 shows the order was not yet filled, and a membership proof at height H2 shows it was filled. Together these bracket when the fill occurred and extract the filler's EVM address from storage. | ||
|
|
||
| 2. **Proof freshness.** Both the gap between H1 and H2, and the age of H2 relative to the current time, must fall within a governance-configured threshold. This prevents stale or manufactured proofs from being accepted. | ||
|
|
||
| 3. **An EVM signature** over `keccak256(SCALE_encode(nonce, pair_id, price))`. This proves the substrate account submitting the price actually controls the EVM account that performed the fill. The nonce is tracked on-chain per EVM address to prevent signature replay. This pattern follows the existing approach in `pallet-ismp-relayer`. | ||
|
|
||
| The 52-byte proof key binds verification to a specific gateway contract. The first 20 bytes are the gateway address (used by the EVM state machine client to locate the contract in the world state trie) and the last 32 bytes are the hashed storage slot for `_filled[commitment]`. | ||
|
|
||
| Verified prices are stored in `VerifiedPrices` with no cap. The goal is to accumulate as many real data points as possible within each price window. | ||
|
|
||
| ### Unverified Prices (Low Confidence) | ||
|
|
||
| Anyone can submit a price without proofs by paying a fee in bridge tokens. This path exists to maintain price data availability even when verified submissions are sparse. The fee, which is transferred to the treasury, discourages spam while keeping the door open for market participants who have price information but haven't filled orders themselves. | ||
|
|
||
| Unverified prices are stored separately in `UnverifiedPrices` and capped per pair at `MaxUnverifiedSubmissions`. When the cap is reached, the oldest entry is replaced using a first-in, first-out policy. Both the fee and the cap must be configured via governance for unverified submissions to be accepted. | ||
|
|
||
| ### Why Two Confidence Levels | ||
|
|
||
| Keeping verified and unverified prices separate lets consumers make informed decisions. A DEX might only trust verified prices for settlement, while a UI might display both to give users a fuller picture. Mixing them into a single pool would dilute the signal from proven fills. | ||
|
|
||
| ## Price Window and Data Lifecycle | ||
|
|
||
| Prices are organized into daily windows, which are governance-configurable via `PriceWindowDurationValue`. | ||
|
|
||
| The `on_initialize` hook runs every block and checks whether the current window has expired. When it has, it clears `UsedCommitments` (which is safe because the freshness threshold independently rejects stale proofs) and resets a `PricesClearedThisWindow` flag to false. | ||
|
|
||
| Prices from the previous window are not cleared immediately. They persist so that consumers can still read yesterday's data. On the first new submission in the new window (verified or unverified), all price entries across all pairs are cleared before the new entry is stored. This lazy clearing approach avoids the cost of iterating all pairs in `on_initialize` while ensuring stale data is replaced as soon as fresh data arrives. | ||
|
|
||
| ### Why Lazy Clearing | ||
|
|
||
| Clearing all price maps in `on_initialize` would cost weight proportional to the number of pairs with data, which is unbounded and paid by the block producer. Instead, the cost is deferred to the first submitter of the new window, who is already paying for a storage write. The global boolean flag (`PricesClearedThisWindow`) makes this a single check per submission after the first. | ||
|
|
||
| ## Recognized Pairs | ||
|
|
||
| Only governance-approved token pairs can receive price submissions. This prevents spam for arbitrary token combinations and keeps storage growth under control. Governance manages pairs through `add_recognized_pair` and `remove_recognized_pair` extrinsics. Removing a pair also cleans up its associated price data. | ||
|
|
||
| ## RPC | ||
|
|
||
| The `intents_getPairPrices(pair_id)` RPC endpoint returns verified and unverified prices separately, allowing consumers to apply their own weighting or filtering based on confidence level. | ||
|
|
||
| ## Governance Parameters | ||
|
|
||
| All key parameters are stored on-chain and updatable via governance extrinsics: | ||
|
|
||
| - `PriceWindowDurationValue` is the length of the price window in milliseconds. | ||
| - `ProofFreshnessThresholdValue` is the maximum allowed age and gap for state proofs in seconds. | ||
| - `MaxUnverifiedSubmissions` is the cap on unverified entries per pair. | ||
| - `UnverifiedSubmissionFee` is the fee charged for unverified submissions. | ||
| - Recognized token pairs determine which pairs accept submissions. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.