-
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 31 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
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 | ||
| } |
103 changes: 103 additions & 0 deletions
103
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,103 @@ | ||
| --- | ||
| title: Price Submission Protocol | ||
| description: Fee based price submission system for the intents coprocessor pallet | ||
| --- | ||
|
|
||
| # Price Submission Protocol | ||
|
|
||
| ## Overview | ||
|
|
||
| The intents system needs onchain price data for token pairs to function correctly. Rather than relying on external oracles, the protocol allows anyone to submit prices for governance approved token pairs by paying a per submission fee. The fee is transferred to the treasury. Each submission overwrites the submitter's previous prices for that pair, so there is no accumulation of stale data, only the latest prices from each filler are stored. | ||
|
|
||
| ## Submitting Prices | ||
|
|
||
| The `submit_pair_price` extrinsic on the intents coprocessor pallet is the entry point for all price submissions. It accepts a pair ID and a bounded list of price entries. All prices and amount ranges are encoded as U256 values scaled by 10^18, giving 18 decimal places of precision. | ||
|
|
||
| Submissions are batched. Each call accepts up to `MaxPriceEntries` entries (a compile time constant configurable per runtime), where each entry specifies an amount threshold and the corresponding price of the base token in terms of the quote token. This makes it possible to quote different rates for different order sizes in a single transaction. For example, a submitter might quote USDC/CNGN at 1414 for amounts starting at 0, and 1420 for amounts starting at 1000. | ||
|
|
||
| Each price entry contains two fields. The `amount` field is the base token amount threshold at which this price applies. The `price` field is the cost of one unit of the base token in terms of the quote token. The pallet rejects empty submissions. When stored onchain, each entry becomes a `PriceEntry` that also includes a Unix timestamp of when the submission was made. | ||
|
|
||
| ## Fee Model | ||
|
|
||
| Every call to `submit_pair_price` charges a fee from the submitter's balance. The fee is transferred to the treasury via `Currency::transfer`. The fee amount is set by governance through the `set_price_submission_fee` extrinsic. If the fee is zero, submissions are free. | ||
|
|
||
| This design discourages spam while keeping the barrier to entry low for active market participants. | ||
|
|
||
| ## Storage Model | ||
|
|
||
| Prices are stored in a `StorageDoubleMap` keyed by `(pair_id, filler)`. Each filler's entry for a pair is a bounded vector of their latest price entries. Submitting new prices for a pair completely replaces the filler's previous entries. There is no merging or appending. | ||
|
|
||
| This means each filler maintains exactly one set of prices per pair. Resubmissions are cheap because they simply overwrite the existing data. There is no need for cleanup or expiry mechanisms. The frontend can filter by filler or timestamp freshness as needed. | ||
|
|
||
| ## RPC | ||
|
|
||
| The `intents_getPairPrices(pair_id)` RPC endpoint returns all price entries for a given token pair across all fillers. The raw onchain values (U256 scaled by 10^18) are converted to human readable decimal strings with fractional precision preserved. For example, an onchain value of 1414500000000000000000 is returned as the string "1414.5". Each returned entry includes the `amount` threshold, the `price`, the `filler` account hash, and the `timestamp`. | ||
|
|
||
| ## Simplex Filler Integration | ||
|
|
||
| The simplex filler submits price updates automatically as part of the FX strategy. When the filler starts and a `hyperfx` strategy is configured with a `pairId`, the FX strategy spawns a periodic task that converts its ask price curve into onchain price entries and submits them via `IntentsCoprocessor.submitPairPrice()`. There is no separate price configuration section; the prices come directly from the strategy's existing ask price curve, which is the same curve used to evaluate order profitability. | ||
|
|
||
| The task runs on a configurable interval (defaulting to every 5 minutes). An initial submission is triggered shortly after startup so that prices are available immediately rather than waiting for the first interval to elapse. | ||
|
|
||
| ### Configuration | ||
|
|
||
| Price submission is enabled by adding a `pairId` to the `hyperfx` strategy in the filler TOML configuration file. The ask price curve points are converted into price entries automatically, where each point on the curve defines a price range. | ||
|
|
||
| ```toml | ||
| [[strategies]] | ||
| type = "hyperfx" | ||
| pairId = "0x..." # Onchain pair ID (keccak256 of base_address ++ quote_address) | ||
| maxOrderUsd = "5000" | ||
|
|
||
| [[strategies.askPriceCurve]] | ||
| amount = "0" | ||
| price = "1414" | ||
|
|
||
| [[strategies.askPriceCurve]] | ||
| amount = "1000" | ||
| price = "1420" | ||
|
|
||
| [[strategies.bidPriceCurve]] | ||
| amount = "0" | ||
| price = "1500" | ||
|
|
||
| [[strategies.bidPriceCurve]] | ||
| amount = "1000" | ||
| price = "1490" | ||
|
|
||
| [strategies.exoticTokenAddresses] | ||
| "EVM-56" = "0xabc..." | ||
|
|
||
| [strategies.stablecoinAddresses] | ||
| "EVM-56" = "0xdef..." | ||
| ``` | ||
|
|
||
| The ask curve points are sorted by amount and each point becomes a price entry. The range for each entry spans from that point's amount to just below the next point's amount. The last point extends to a large upper bound. Amounts and prices are converted to 18 decimal format before submission. | ||
|
|
||
| Each submission pays a fee to the treasury. Subsequent submissions for the same pair overwrite the previous entries, keeping only the latest prices onchain. | ||
|
|
||
| ### SDK Usage | ||
|
|
||
| The `IntentsCoprocessor` class in `@hyperbridge/sdk` exposes methods for price submission directly. These methods accept raw 18 decimal bigint values. | ||
|
|
||
| ```typescript | ||
| import { IntentsCoprocessor } from "@hyperbridge/sdk" | ||
| import { parseUnits } from "viem" | ||
|
|
||
| const coprocessor = await IntentsCoprocessor.connect(wsUrl, substratePrivateKey) | ||
|
|
||
| // Submit prices for a token pair (values in 18 decimal format) | ||
| // Each submission overwrites previous entries for this filler + pair | ||
| await coprocessor.submitPairPrice("0x...", [ | ||
| { amount: parseUnits("0", 18), price: parseUnits("1414", 18) }, | ||
| { amount: parseUnits("1000", 18), price: parseUnits("1420", 18) }, | ||
| ]) | ||
| ``` | ||
|
|
||
| ## Governance Parameters | ||
|
|
||
| The protocol has several parameters that are stored onchain and updatable through governance extrinsics. | ||
|
|
||
| `PriceSubmissionFee` is the fee charged per submission, transferred to the treasury. Set via `set_price_submission_fee`. | ||
|
|
||
| `MaxPriceEntries` is a compile time constant (configurable per runtime) that limits how many price entries can be included in a single submission. | ||
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
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.