Amendment Idea: Stop Orders #389
mvadari
started this conversation in
XLS Ideas (pre standard proposal)
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Stop Orders
Abstract
Trading on the XRP Ledger currently lacks native support for conditional orders, such as stop-loss or stop-limit orders. Traders must rely on off-ledger solutions or manual monitoring, which exposes them to execution risk and reduces the reliability of decentralized trading. Introducing on-chain stop orders addresses these gaps while keeping the ledger fully deterministic and secure.
1. Overview
We propose:
Offerledger entryDirectoryNodeledger entryOfferCreatetransactionOfferModifytransactionbook_offersRPCThis feature will require an amendment, tentatively titled
StopOrder.2. Ledger Entry:
OfferThe
Offerobject tracks an offer placed on the CLOB DEX. This object type already exists on the XRPL, but is being extended as a part of this spec to also support permissioned DEX domains.2.1. Fields
As a reference, here are the existing fields for the
Offerobject.AccountstringAccountIDAdditionalBooksarraySTArrayBookDirectorystringHash256BookNodestringUInt64DomainIDstringHash256ExpirationnumberUInt32LedgerEntryTypeOfferstringUInt160x006F, mapped to the stringOffer, indicates that this is an offer entry.OwnerNodestringUInt64PreviousTxnIDstringHash256PreviousTxnLgrSeqnumberUInt32SequencenumberUInt32Sequencevalue of theOfferCreatetransaction that created this offer. Used in combination with theAccountto identify this offer.TakerPaysobjectAmountTakerGetsobjectAmountThis spec proposes the following additions:
StopPricestringNumberTakerGets.2.2. Flags
Offerentries can have the following flags combined into theFlagsfield:lsfPassive0x00010000lsfSell0x00020000tfSellonly matters if you get a better rate than you asked for, which can only happen when the offer is initially placed.lsfHybrid0x00040000This spec proposes the following additions:
lsfStopLimit0x00080000lsfStopBuy0x001000003. Ledger Entry:
DirectoryNodeThe
Offerobject tracks an offer placed on the CLOB DEX.The
DirectoryNodeledger entry type provides a list of links to other entries in the ledger's state data. A single conceptual Directory takes the form of a doubly linked list, with one or moreDirectoryNodeentries each containing up to 32 IDs of other entries. The firstDirectoryNodeentry is called the root of the directory, and all entries other than the root can be added or deleted as necessary.This object type already exists on the XRPL, but is being extended as a part of this spec to also support permissioned DEX domains.
There are three types of directories: owner directories (for the objects an account owns), offer directories (for offers in the orderbook), and NFT offer directories (for NFT offers).
The proposed modification allows for another type of directory: conditional offer directories. The offers in this directory are sorted by their "stop price", not the price of the offer.
3.1. Fields
As a reference, here are the existing fields for the
DirectoryNodeobject.DomainIDstringHash256Flags0numberUInt32DirectoryNodeobjects. The value is always0.IndexesarrayVector256IndexNextnumberUInt64IndexPreviousnumberUInt64LedgerEntryTypeDirectoryNodestringUInt160x0064, mapped to the stringDirectoryNode, indicates that this object is part of a directory.RootIndexstringHash256TakerGetsCurrencystringHash160TakerGetsamount from the offers in this directory.TakerGetsIssuerstringHash160TakerGetsamount from the offers in this directory.TakerPaysCurrencystringHash160TakerPaysamount from the offers in this directory.TakerPaysIssuerstringHash160TakerPaysamount from the offers in this directory.This spec does not propose any changes to the fields.
3.2. Object ID
3.2.1. Background: Current Offer Directory ID
There are three different formulas for creating the ID of a DirectoryNode, depending on which of the following the DirectoryNode represents:
The first page of an Offer directory has a special ID: the higher 192 bits define the order book, and the remaining 64 bits define the exchange rate of the offers in that directory. (The ID is big-endian, so the book is in the more significant bits, which come first, and the quality is in the less significant bits which come last.) This provides a way to iterate through an order book from best offers to worst. Specifically: the first 192 bits are the first 192 bits of the SHA-512Half of the following values, concatenated in order:
0x0042)TakerPaysCurrencyTakerGetsCurrencyTakerPaysIssuerTakerGetsIssuerDomainIDof the orderbook, if applicableThe lower 64 bits of an Offer directory's ID represent the
TakerPaysamount divided byTakerGetsamount from the offer(s) in that directory as a 64-bit number in the XRP Ledger's internal amount format.If the DirectoryNode is not the first page in the directory, it has an ID that is the SHA-512Half of the following values, concatenated in order:
DirectoryNodespace key (0x0064)DirectoryNodeDirectoryNode, this value is an integer 1 or higher.)3.2.2. Proposed Change
This proposal involves having a separate set of directories that hold conditional offers (just stop for now, but can maybe be extended in other ways - I'm not a trading expert, so idk)
The object ID for the conditional offer directories will be as follows:
TakerPaysCurrencyTakerGetsCurrencyTakerPaysIssuerTakerGetsIssuerDomainIDof the orderbook, if applicable.4. Transaction:
OfferCreateThe
OfferCreatetransaction creates an offer on the CLOB DEX. This transaction type already exists on the XRPL, but is being extended as a part of this spec to also support permissioned DEX domains.4.1. Fields
As a reference, here are the existing fields for the
OfferCreatetransaction.DomainIDstringHash256ExpirationnumberUInt32OfferSequencenumberUInt32OfferCancel.TakerGetsstringAmountTakerPaysstringAmountThis spec proposes a new field:
StopPricestringNumberTakerGets.4.2. Flags
This spec proposes additional flags:
tfStopLimit0x00200000tfStopBuy0x004000004.3. Failure Conditions
The existing set of failure conditions for
OfferCreatewill continue to exist.4.4. State Changes
The existing set of state changes for
OfferCreatewill continue to exist.In addition:
5.
OfferModifyAllows you to modify an offer after its creation (including stop price for a stop offer)
6. RPC:
book_offersProbably need some changes here to accommodate this new feature
n+1. Open Questions
Appendix
Appendix A: Alternate Designs
Beta Was this translation helpful? Give feedback.
All reactions