# XRP Ledger AMM APIs are now live!

Alpha
API Categorization: Alpha (unstable API, expect changes).

Ripple Custody (Wallet) brings deeper integration into the XRP ledger through our latest AMM APIs. These APIs allow customers to programmatically interact with AMMs on the XRP Ledger.

## Use-cases

1. Trading and market making - Providing liquidity into AMMs makes it easy to generate revenue on-chain.
2. Asset Tokenization - XRP’s AMMs make it easy to provide liquidity on-chain, enabling token issuers to facilitate trades using the built-in DEX.


## Security considerations

Transactions initiated using AMM APIs are subject to the same policy engine rules. Since `AMMCreate` and `AMMDeposit` result in multiple assets being withdrawn from the wallet, the policy engine will expect policies to be defined for each affected asset.

For example, if an `AMMDeposit` transaction is depositing into a `RLUSD/USD` pool, the policy engine will require the policies to be defined for the following assets:

1. RLUSD.
2. USD.


Note that issuer must be defined in the policy for issued assets such as above.

## Limitations

AMM APIs are available on XRP Ledger only.

## AMM Deposit

### Summary

AMM Deposit is only supported in two-asset mode. Depositing using a single asset into a two-asset pool is currently unsupported.

### Unsupported modes

The request parameter `lpTokenOut` is not yet supported.

Flag `DEPOSIT_SINGLE_ASSET` is not supported.

The request parameter `amount2` must be specified.

Update
AMM Deposit now supports single-asset deposits: set `flags` to `DEPOSIT_SINGLE_ASSET` with `amount` and omit `amount2`. `lpTokenOut` is still unsupported. See [Deposit into an AMM](/pt-br/products/wallet/transactions/xrpl/xrpl-via-the-api#deposit-into-an-amm-amm-deposit-via-the-api).

## AMM Withdraw

### Summary

AMM Withdraw supports two request shapes. Both require `asset` and `asset2` to identify the pool, `lpTokenIn` for the number of LP tokens to redeem, and a `flags` value:

| `flags` | Amount fields | Behavior |
|  --- | --- | --- |
| `WITHDRAW_LP_TOKEN` | `lpTokenIn` only. Omit `amount`. | Redeems LP tokens for both pool assets. |
| `WITHDRAW_ONE_ASSET_LP_TOKEN` | `lpTokenIn` and `amount`. | Redeems LP tokens for the first asset only. |


**Example:** Redeem LP tokens for both pool assets.

```json
{
  "asset": { "asset": "XRP" },
  "asset2": { "asset": "USD", "issuer": "rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq" },
  "lpTokenIn": {
    "asset": "03930D02208264E2E40EC1B0C09E4DB96EE197B1",
    "issuer": "rMEdVzU8mtEArzjrN9avm3kA675GX7ez8W",
    "value": "100"
  },
  "flags": "WITHDRAW_LP_TOKEN"
}
```

### Unsupported modes

Ripple Custody (Wallet) rejects an AMM Withdraw request that:

- Omits `lpTokenIn` or `flags`
- Sets any flag other than `WITHDRAW_LP_TOKEN` or `WITHDRAW_ONE_ASSET_LP_TOKEN`
- Sets `amount2` or `ePrice`
- Sets `amount` with `WITHDRAW_LP_TOKEN`, or omits it with `WITHDRAW_ONE_ASSET_LP_TOKEN`


## References

* AMM Create
  * XRP Ledger reference: [https://xrpl.org/docs/references/protocol/transactions/types/ammcreate](https://xrpl.org/docs/references/protocol/transactions/types/ammcreate)
  * Ripple Custody (Wallet) API reference: [Ripple Custody (Wallet) API](/pt-br/products/wallet/api-docs/palisade-api/palisade-api)
* AMM Deposit
  * XRP Ledger reference: [https://xrpl.org/docs/references/protocol/transactions/types/ammdeposit](https://xrpl.org/docs/references/protocol/transactions/types/ammdeposit)
  * Ripple Custody (Wallet) API reference: [Ripple Custody (Wallet) API](/pt-br/products/wallet/api-docs/palisade-api/palisade-api)
* AMM Withdraw
  * XRP Ledger reference: [https://xrpl.org/docs/references/protocol/transactions/types/ammwithdraw](https://xrpl.org/docs/references/protocol/transactions/types/ammwithdraw)
  * Ripple Custody (Wallet) API reference: [Ripple Custody (Wallet) API](/pt-br/products/wallet/api-docs/palisade-api/palisade-api)