-
Notifications
You must be signed in to change notification settings - Fork 122
[runtime/simplex]]: add phantom order support for passive price and liquidity indexing #983
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
Draft
dharjeezy
wants to merge
10
commits into
main
Choose a base branch
from
dami/phantom-order
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.
Draft
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
62c3163
add phantom order support for passive price and liquidity indexing
dharjeezy e26564e
generate phantom order in pallet hook, governance config, remove solv…
dharjeezy 4460afb
update simnode indexer
dharjeezy 6eb80a1
simulate bid
dharjeezy f00dad3
merge main into dami/phantom-order
dharjeezy eb273ac
expand PhantomOrderRegistered event with token pair fields and implem…
dharjeezy 3d34405
doc schemas
dharjeezy d23b75d
use SDK exposed abis and functions
dharjeezy ce46fcb
rev
dharjeezy b1a15c9
use zero output
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,10 @@ use sp_io::offchain_index; | |
| use sp_runtime::traits::{ConstU32, Zero}; | ||
| pub use weights::WeightInfo; | ||
|
|
||
| use types::{Bid, GatewayInfo, IntentGatewayParams, RequestKind, TokenDecimalsUpdate, TokenInfo}; | ||
| use types::{ | ||
| Bid, GatewayInfo, IntentGatewayParams, PhantomOrderInfo, RequestKind, TokenDecimalsUpdate, | ||
| TokenInfo, | ||
| }; | ||
|
|
||
| // Re-export pallet items so that they can be accessed from the crate namespace. | ||
| pub use pallet::*; | ||
|
|
@@ -83,6 +86,11 @@ pub mod pallet { | |
| #[pallet::constant] | ||
| type StorageDepositFee: Get<BalanceOf<Self>>; | ||
|
|
||
| /// How many blocks after phantom order creation bids are accepted. Fallback when | ||
| /// the PhantomBidWindow storage value is zero. | ||
| #[pallet::constant] | ||
| type PhantomOrderBidWindowBlocks: Get<u32>; | ||
|
|
||
| /// Origin that can perform governance actions | ||
| type GovernanceOrigin: EnsureOrigin<Self::RuntimeOrigin>; | ||
|
|
||
|
|
@@ -119,6 +127,17 @@ pub mod pallet { | |
| pub type Gateways<T: Config> = | ||
| StorageMap<_, Blake2_128Concat, StateMachine, GatewayInfo, OptionQuery>; | ||
|
|
||
| /// The single active phantom order. Only one is recognised at a time; registering | ||
| /// a new one replaces the previous. | ||
| #[pallet::storage] | ||
| pub type CurrentPhantomOrder<T: Config> = | ||
| StorageValue<_, (H256, PhantomOrderInfo<BlockNumberFor<T>>), OptionQuery>; | ||
|
|
||
| /// Governance-updatable bid acceptance window for phantom orders (in blocks). | ||
| /// Falls back to PhantomOrderBidWindowBlocks when zero. | ||
| #[pallet::storage] | ||
| pub type PhantomBidWindow<T: Config> = StorageValue<_, u32, ValueQuery>; | ||
|
|
||
| #[pallet::event] | ||
| #[pallet::generate_deposit(pub(super) fn deposit_event)] | ||
| pub enum Event<T: Config> { | ||
|
|
@@ -147,6 +166,10 @@ pub mod pallet { | |
| }, | ||
| /// Storage deposit fee was updated | ||
| StorageDepositFeeUpdated { fee: BalanceOf<T> }, | ||
| /// A phantom order was registered as the current active one | ||
| PhantomOrderRegistered { commitment: H256, chain: Vec<u8>, created_at: BlockNumberFor<T> }, | ||
| /// The phantom order bid window was updated | ||
| PhantomBidWindowUpdated { window: u32 }, | ||
| } | ||
|
|
||
| #[pallet::error] | ||
|
|
@@ -163,6 +186,10 @@ pub mod pallet { | |
| InvalidUserOp, | ||
| /// Failed to dispatch cross-chain request | ||
| DispatchFailed, | ||
| /// A bid was submitted for a phantom order after the acceptance window closed | ||
| PhantomOrderBidWindowClosed, | ||
| /// A filler already has a bid for this phantom order | ||
| DuplicatePhantomBid, | ||
| } | ||
|
|
||
| #[pallet::call] | ||
|
|
@@ -191,6 +218,22 @@ pub mod pallet { | |
| // Validate user_op is not empty | ||
| ensure!(!user_op.is_empty(), Error::<T>::InvalidUserOp); | ||
|
|
||
| // Phantom orders have stricter rules: one bid per filler, no updates, and only | ||
| // within the configured acceptance window after the order was registered. | ||
| if let Some((phantom_commitment, info)) = CurrentPhantomOrder::<T>::get() { | ||
| if commitment == phantom_commitment { | ||
| let window: BlockNumberFor<T> = Self::phantom_bid_window().into(); | ||
| ensure!( | ||
| frame_system::Pallet::<T>::block_number() <= info.created_at_block + window, | ||
| Error::<T>::PhantomOrderBidWindowClosed | ||
| ); | ||
| ensure!( | ||
| !Bids::<T>::contains_key(&commitment, &filler), | ||
| Error::<T>::DuplicatePhantomBid | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // If a bid already exists, unreserve the old deposit first | ||
| if let Some(old_deposit) = Bids::<T>::get(&commitment, &filler) { | ||
| <T as Config>::Currency::unreserve(&filler, old_deposit); | ||
|
|
@@ -280,10 +323,8 @@ pub mod pallet { | |
| } | ||
|
|
||
| // Prepare cross-chain request to notify existing gateway | ||
| let new_deployment = types::NewDeployment { | ||
| chain: state_machine.to_string().into_bytes(), | ||
| gateway, | ||
| }; | ||
| let new_deployment = | ||
| types::NewDeployment { chain: state_machine.to_string().into_bytes(), gateway }; | ||
| let request = RequestKind::AddDeployment(new_deployment); | ||
| let body = request.encode_body(); | ||
|
|
||
|
|
@@ -443,6 +484,39 @@ pub mod pallet { | |
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| /// Register a phantom order as the single active one. Replaces any previously | ||
| /// registered phantom order. Called by the intent coprocessor service. | ||
| #[pallet::call_index(7)] | ||
| #[pallet::weight(T::WeightInfo::register_phantom_order())] | ||
| pub fn register_phantom_order( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not correct, the phantom order should be generated by the runtime in the pallet hooks |
||
| origin: OriginFor<T>, | ||
| commitment: H256, | ||
| chain: Vec<u8>, | ||
| ) -> DispatchResult { | ||
| ensure_signed(origin)?; | ||
|
|
||
| let created_at = frame_system::Pallet::<T>::block_number(); | ||
| let info = PhantomOrderInfo { created_at_block: created_at, chain: chain.clone() }; | ||
| CurrentPhantomOrder::<T>::put((commitment, info)); | ||
|
|
||
| Self::deposit_event(Event::PhantomOrderRegistered { commitment, chain, created_at }); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| /// Update the phantom order bid acceptance window. | ||
| #[pallet::call_index(8)] | ||
| #[pallet::weight(T::WeightInfo::set_phantom_bid_window())] | ||
| pub fn set_phantom_bid_window(origin: OriginFor<T>, window: u32) -> DispatchResult { | ||
| T::GovernanceOrigin::ensure_origin(origin)?; | ||
|
|
||
| PhantomBidWindow::<T>::put(window); | ||
|
|
||
| Self::deposit_event(Event::PhantomBidWindowUpdated { window }); | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| impl<T: Config> Pallet<T> | ||
|
|
@@ -461,6 +535,15 @@ pub mod pallet { | |
| } | ||
| } | ||
|
|
||
| pub fn phantom_bid_window() -> u32 { | ||
| let window = PhantomBidWindow::<T>::get(); | ||
| if window == 0 { | ||
| T::PhantomOrderBidWindowBlocks::get() | ||
| } else { | ||
| window | ||
| } | ||
| } | ||
|
|
||
| /// Generate offchain storage key for a bid | ||
| pub fn offchain_bid_key(commitment: &H256, filler: &T::AccountId) -> Vec<u8> { | ||
| offchain_bid_key_raw(commitment, &filler.encode()) | ||
|
|
||
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.
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.
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.
There's no extrinsic to setup the phantom order details, like token pairs, chain for the order?