bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 28쪽 중 6쪽
designed to be unpredictable, to discourage
front-running
.
The XRP Ledger does not natively represent concepts such as market orders, stop orders, or trading on leverage. Some of these may be possible with creative use of custom tokens and Offer properties.
As a decentralized system, the XRP Ledger does not have any personal information on the actual people and organizations behind the
accounts
involved in trading. The ledger itself cannot implement restrictions around who can or cannot participate in trading, and users and issuers must take care to follow any relevant laws to regulate trading tokens that represent various types of underlying assets. Features such as
freezes
and
authorized trust lines
are intended to help issuers comply with relevant laws and regulations.
See Also
Concepts:
See
Offers
for details on how trades work in the XRP Ledger.
See
Tokens
for an overview of how various types of value can be represented in the XRP Ledger.
References:
account_offers method
to look up Offers placed by an account
book_offers method
to look up Offers to buy or sell a given currency pair
OfferCreate transaction
to place a new Offer or replace an existing Offer
OfferCancel transaction
to cancel an existing Offer
Offer object
for the data structure of passive Offers in the ledger
DirectoryNode object
for the data structure that tracks all the Offers for a given currency pair and exchange rate.
Offers
Offers are the XRP Ledger's form of currency trading orders. Understand their lifecycle and properties.
Auto-Bridging
Auto-bridging automatically connects order books using XRP as an intermediary when it reduces costs.
Tick Size
Issuers can set custom tick sizes for currencies to reduce churn in order books over miniscule differences in exchange rates.
Automated Market Makers (AMMs)
Automated Market Makers (AMMs) are an essential part of cryptocurrency, providing liquidity between asset pairs. Learn more about AMMs and the XRP Ledger.
Permissioned Domains
Learn how Permissioned Domains on the XRP Ledger enable controlled, secure blockchain environments. Explore their role in decentralized exchanges (DEXes) and lending protocols.
Permissioned DEXes
The definition and details of a Permissioned Domain instance.
## /docs/concepts/tokens/decentralized-exchange/permissioned-dexes
Permissioned DEXes
Copy
Permissioned DEXes are controlled environments for trading within the XRP Ledger's
decentralized exchange (DEX)
. Trading in a permissioned DEX works like trading in the open DEX, except that a
permissioned domain
controls who can place and accept offers. By relying on permissioned DEXes, regulated businesses can participate in trading on the XRP Ledger while ensuring that all the counterparties they deal with have been properly vetted.
There can be multiple permissioned DEXes within the XRP Ledger blockchain. Each one is uniquely associated with a permissioned domain, which acts as an allow-list for accessing that DEX. Trades placed within a permissioned DEX can only execute against other trades in the same permissioned DEX. Each permissioned DEX can have order books for any number of currency pairs, as needed.
Requires the
PermissionedDEX
amendment
.
Loading...
Background: The Need for Permissioned DEXes
The XRP Ledger has had a single,
open DEX
since it launched. Anyone with an XRPL account can trade in this DEX, and the system automatically executes matching orders, also called offers, with no regard for who placed them. Orders also provide liquidity to cross-currency payments, which can potentially execute several trades as part of one atomic transaction.
Since the system inherently knows nothing about the people and organizations behind the accounts, there is no certainty who the counterparties are for any given trade. However, economic sanctions and financial regulations often place strict rules against transacting with criminals, terrorists, or specific countries. Given these limitations, regulated financial institutions may not be willing to take the risk of trading in the open DEX.
More background reading:
Decentralized Exchange
Offers
Permissioned Domains
Key Roles in a Permissioned DEX
To use a permissioned DEX, parties with the following roles and responsibilities need to exist:
At least two traders to place matching offers. For example, one selling USD for XRP and one selling XRP for USD.
A permissioned domain owner, who controls which credentials give access to the domain.
A credential issuer, who issues credentials to accounts they approve.
It is possible for a single account to play more than one of these roles. For example, you could be the permissioned domain owner, credential issuer,
and
a trader all at once. The only restriction is that the traders must be different accounts.
Figure: A permissioned order book, linked to a permissioned domain. Owen is both the domain owner and the issuer of one of the domain's accepted credentials. Tracy is able to trade in the permissioned order book because she holds an appropriate credential issued by Owen.
Understanding the Permissioned DEX Structure: Offer Types and Interaction
With the permissioned DEXes feature, a trade offer can be
open
,
permissioned
, or
hybrid
.
Open Offers
An open offer uses the open DEX and can be matched by anyone else's open offer, hybrid offer, an
Automated Market Maker (AMM)
, or a combination of offers and an AMM.
Open offers
are unchanged from how the XRPL's DEX works without permissioned DEXes.
Permissioned Offers
A permissioned offer specifies a domain ID and is only valid if a permissioned domain with the matching ID exists and the account placing the offer has access to that domain because they hold the correct credentials. Permissioned offers are placed into an order book for the given domain and currency pair, separate from the open DEX's order book for that currency pair.
Permissioned offers can only execute by matching other permissioned offers that specify the same domain ID.
Cross-currency payments
can also specify a domain ID, in which case they are restricted to only consuming offers from the corresponding permissioned DEX. Trades in a permissioned DEX can still use
auto-bridging
as long as the necessary orders all exist in the same permissioned DEX.
Hybrid Offers
A hybrid offer specifies a domain ID and a flag marking it as hybrid. Like a permissioned offer, it is only valid if the specified permissioned domain exists and the account placing the offer has access to that domain. However, a hybrid offer can match offers in both the specified DEX and the open DEX.
Hybrid offers are tracked in both the open DEX order book and the domain-specific order book for their currency pair, and can be consumed by matching offers from either. When placed, they preferentially match offers from the permissioned DEX.
How Open, Hybrid, and Permissioned Offers Match
In summary, see the following table summarizing what offers can match:
Offer/Payment Type
Open Offer
Hybrid Offer
Permissioned Offer
AMM
Open
✅
✅
❌
✅
Hybrid
✅
✅
✅ (same domain)
✅
Permissioned
❌
❌
✅ (same domain)
❌
There is no single ledger entry to represent a given permissioned DEX: it implicitly exists as all the order books with the same domain ID. Order books with a given domain ID are created when valid offers are placed using that domain ID, and those order books are automatically deleted when they are empty.
A single transaction can use multiple order books with the same domain ID—in other words, different currency pairs in the same permissioned DEX—either as part of a longer
cross-currency payment
or through auto-bridging. A hybrid offer can match a mix of permissioned and open offers, but a transaction cannot use multiple different domains.
The amount of liquidity and the best exchange rate available in any given DEX may vary depending on the offers placed in that DEX. Some traders may choose to trade in multiple permissioned DEXes and the open DEX to arbitrage price differences, while other traders may trade strictly in one domain, depending on their compliance requirements.
Figure: The open DEX, and two different permissioned DEXes, each containing order books for a subset of possible currency pairs.
Invalid Permissioned Offers
In addition to the ways offers can be unfunded in the open DEX, offers in a permissioned DEX can become
invalid
. Invalid offers are treated the same way as unfunded offers and are automatically removed whenever a transaction modifies the order book containing them. They can remain in the ledger data indefinitely until a transaction removes them, but they cannot be executed if they are invalid.
Reasons a permissioned offer can become invalid include:
A credential, held by the account placing the offer, has expired or has been deleted.
The permissioned domain has been updated to change the set of credentials that grant access, and the account placing the offer does not hold any of the new credentials.
The permissioned domain has been deleted.
Like with unfunded offers, it is possible for an offer to become temporarily invalid and then become valid again. For example, if a trader's credential that grants access to a permissioned domain expires, their offers in the corresponding permissioned DEX would be invalid; but if they get the credential renewed, any offers that hadn't already been removed automatically become valid again.
Limitations of Permissioned DEXes
The permissioned DEXes feature is enabled by the
PermissionedDEX
amendment, and relies on the
Credentials
and
Permissioned Domains
amendments, so it cannot be used until
all
of those amendments have been enabled.
Not Compatible with AMMs
Permissioned DEXes are incompatible with
Automated Market Makers (AMMs)
. Permissioned offers and permissioned payments cannot be filled by AMMs, and access to AMMs cannot be restricted by a permissioned domain. Trades that use the open DEX can sometimes consume a hybrid offer and use an AMM in the same transaction, but transactions that specify a domain cannot use any AMMs.
Permissioned DEXes are independent
Each permissioned DEX is separate, with its own order books and offers. A single transaction cannot trade in multiple permissioned DEXes or aggregate liquidity from multiple permissioned DEXes. Hybrid offers can use a mix of one permissioned DEX and the open DEX, but they cannot use multiple different permissioned DEXes.
Security Considerations for Permissioned DEXes
The security and fairness of a permissioned DEX depend on the owner of the permissioned domain and the issuers of credentials that grant access to it. At a baseline, the definition of each credential and the requirements for getting that credential are defined and enforced by the credential issuer, so the existence of a permissioned domain does not inherently mean anything about who is able to use it in practice.
A credential issuer can issue or revoke credentials at their discretion. If they are unreliable or compromised, so is any permissioned domain that accepts their credentials. Similarly, the domain owner can modify the domain's list of accepted credentials to grant or deny access to the domain arbitrarily, so if they are untrustworthy or compromised, the domain is as well.
## /docs/concepts/tokens/decentralized-exchange/automated-market-makers
Automated Market Makers
Copy
Automated Market Makers (AMMs) provide liquidity in the XRP Ledger's decentralized exchange (DEX). Each AMM holds a pool of two assets. You can swap between the two assets at an exchange rate set by a mathematical formula.
Those who deposit assets into an AMM are called
liquidity providers
. In return, liquidity providers receive
LP tokens
from the AMM.
LP tokens enable liquidity providers to:
Redeem their LP tokens for a share of the assets in the AMM pool, including fees collected.
Vote to change the AMM fee settings, each vote weighted by how many LP tokens the voter holds.
Bid some of their LP tokens to receive a temporary discount on the AMM trading fees.
Requires the
AMM
amendment
.
Loading...
How the AMM Works
An AMM holds two different assets: at most one of these can be XRP, and one or both of them can be
trust line tokens
. For any given pair of assets, there can be up to one AMM in the ledger. Anyone can create the AMM for an asset pair if it doesn't exist, or deposit to an AMM if it already exists. (Support for
Multi-Purpose Tokens
is planned as part of the in-development
MPTokensV2 amendment
.)
When you want to trade in the decentralized exchange, your
offers
and
cross-currency payments
can automatically use AMMs to complete the trade. A single transaction might execute by matching offers, AMMs, or a mix of both, depending on what's cheaper. You can
read a transaction's metadata
to see what liquidity it consumed.
An AMM sets its exchange rate based on the balance of assets in the pool. When you trade against an AMM, the exchange rate adjusts based on how much your trade shifts the balance of assets the AMM holds. As its supply of one asset goes down, the price of that asset goes up; as its supply of an asset goes up, the price of that asset goes down.
An AMM gives generally better exchange rates when it has larger overall amounts in its pool. This is because any given trade causes a smaller shift in the balance of the AMM's assets. The more a trade unbalances the AMM's supply of the two assets, the more extreme the exchange rate becomes.
The AMM also charges a percentage trading fee on top of the exchange rate.
The XRP Ledger implements a
geometric mean
AMM with a weight parameter of 0.5, so it functions like a
constant product
market maker. For a detailed explanation of the
constant product
AMM formula and the economics of AMMs in general, see
Kris Machowski's Introduction to Automated Market Makers
.
Token Issuers
Tokens with different issuers are considered different assets. This means that there can be an AMM for two tokens with the same currency code but different issuers. For example,
FOO
issued by WayGate is different than
FOO
issued by StableFoo. Similarly, the tokens can have the same issuer but different currency codes. The trade direction doesn't matter; the AMM for FOO.WayGate to XRP is the same as the AMM for XRP to FOO.WayGate.
Currency Risk
When the flow of funds between the two assets in a pool is relatively active and balanced, the fees provide a source of passive income for liquidity providers. However, when the relative price between the assets shifts, liquidity providers can take a loss on the
currency risk
.
AMM and DEX Interaction
AMMs are integrated with the central limit order book (CLOB)-based DEX to enhance liquidity. Offers and payments are automatically optimized to determine whether swapping within a liquidity pool, through the order books, or both, provides the best rate and executes accordingly. This ensures that transactions use the most efficient path for trades, whether through offers on the DEX or through AMM pools, or a combination of the two.
The diagram below illustrates how an offer interacts with other offers and AMM liquidity in the DEX.
Restrictions on Assets
To prevent misuse, some restrictions apply to the assets used in an AMM. If you try to create an AMM with an asset that does not meet these restrictions, the transaction fails. The rules are as follows:
The asset must not be an LP token from another AMM.
If the asset is a token whose issuer uses
Authorized Trust Lines
, the creator of the AMM must be authorized to hold those tokens. Only your authorized trust lines can deposit that token into the AMM or withdraw it; however, you can still deposit or withdraw the other asset.
If the
Clawback amendment
is enabled, the issuer of the token must not have enabled the ability to claw back their tokens.
AMM and LP Tokens
Whoever creates the AMM becomes the first liquidity provider, and receives LP tokens that represent 100% ownership of assets in the AMM's pool. Whoever holds an AMM's LP tokens can redeem some or all of those LP tokens to withdraw assets from the AMM in proportion to the amounts currently there. (The proportions shift over time as people trade against the AMM.) The AMM does not charge a fee when withdrawing both assets.
For example, if you created an AMM with 5 ETH and 5 USD, and then someone exchanged 1.26 USD for 1 ETH, the pool now has 4 ETH and 6.26 USD in it. You can spend half your LP tokens to withdraw 2 ETH and 3.13 USD.
Anyone can deposit assets to an existing AMM. When they do, they receive new LP tokens based on how much they deposited. The amount that a liquidity provider can withdraw from an AMM is based on the proportion of the AMM's LP tokens they hold compared to the total number of LP tokens outstanding. For more information about calculating your share, see
Calculate the Value of Your LP Tokens
.
LP tokens are a specific type of
trust line token
and share most of the properties of other trust line tokens. You can use them in many types of payment, or trade them in the decentralized exchange. To receive LP tokens as payment from other holders, you must set up a
trust line
with a non-zero limit with the AMM Account as the issuer. However, you cannot send and receive LP tokens directly to and from the AMM through regular payments types. Instead, LP tokens are automatically issued when you do an
AMMDeposit transaction
, and you redeem them using an
AMMWithdraw transaction
.
The AMM is designed so that an AMM's asset pool is empty if and only if the AMM has no outstanding LP tokens. This situation can only occur as the result of an
AMMWithdraw
transaction; when it does, the AMM is automatically deleted.
LP Token Currency Codes
LP tokens use a special type of currency code in the 160-bit hexadecimal
"non-standard" format
. These codes have the first 8 bits
0x03
. The remainder of the code is a SHA-512 hash, truncated to the first 152 bits, of the two assets' currency codes and their issuers. (The assets are placed in a "canonical order" with the numerically lower currency+issuer pair first.) As a result, the LP tokens for a given asset pair's AMM have a predictable, consistent currency code.
LP Token Freeze
If an LP token is associated with a liquidity pool that contains at least one frozen asset, the LP token is also frozen. This means:
The holder can't send the frozen LP token to other accounts.
The holder can receive frozen LP tokens, but can't send them out (similar to frozen trust lines).
Frozen LP tokens affect the following transactions:
Payment
An account can no longer send frozen LP tokens through direct payment.
OfferCreate
Accounts are prohibited from creating offers that would sell frozen LP tokens.
Offers that contain frozen LP tokens cannot be consumed on the DEX.
CheckCash
Cashing a check fails if it attempts to cash a frozen LP token from the sender.
NFTokenCreateOffer
Buyers are prohibited from creating buy offers that use frozen LP tokens.
NFTokenAcceptOffer
Buyers can't accept a sell offer if the offer requires the use of frozen LP tokens as payment.
LP Token Transferability
If an AMM's pool holds an MPT that doesn't have the
Can Transfer
flag enabled, the AMM's LP tokens can only be transferred to or from the MPT's issuer. This affects the following transactions:
Payment
An account can't send these LP tokens to another non-issuer holder. The transaction fails with
tecNO_AUTH
.
OfferCreate
Offers to sell these LP tokens are treated as unfunded, the same as an offer to sell a frozen LP token.
AMM and Trading Fees
Trading fees are a source of passive income for liquidity providers. They offset the currency risk of letting others trade against the pool's assets. Trading fees are paid to the AMM, not directly to liquidity providers. Liquidity providers benefit because they can redeem their LP tokens for a percentage of the AMM pool.
Liquidity providers can vote to set the fee from 0% to 1%, in increments of 0.001%. Liquidity pro프로젝트로 돌아가기