Introduce AMM support (XLS-30d): (#4294)

Add AMM functionality:
- InstanceCreate
- Deposit
- Withdraw
- Governance
- Auctioning
- payment engine integration

To support this functionality, add:
- New RPC method, `amm_info`, to fetch pool and LPT balances
- AMM Root Account
- trust line for each IOU AMM token
- trust line to track Liquidity Provider Tokens (LPT)
- `ltAMM` object

The `ltAMM` object tracks:
- fee votes
- auction slot bids
- AMM tokens pair
- total outstanding tokens balance
- `AMMID` to AMM `RootAccountID` mapping

Add new classes to facilitate AMM integration into the payment engine.
`BookStep` uses these classes to infer if AMM liquidity can be consumed.

The AMM formula implementation uses the new Number class added in #4192.
IOUAmount and STAmount use Number arithmetic.

Add AMM unit tests for all features.

AMM requires the following amendments:
- featureAMM
- fixUniversalNumber
- featureFlowCross

Notes:
- Current trading fee threshold is 1%
- AMM currency is generated by: 0x03 + 152 bits of sha256{cur1, cur2}
- Current max AMM Offers is 30

---------

Co-authored-by: Howard Hinnant <howard.hinnant@gmail.com>
This commit is contained in:
Gregory Tsipenyuk
2023-07-12 13:52:50 -04:00
committed by tequ
parent b7a29cad94
commit 8dbc6db079
108 changed files with 19083 additions and 1717 deletions

View File

@@ -42,6 +42,9 @@ transResults()
TERUnderlyingType,
std::pair<char const* const, char const* const>> const results
{
MAKE_ERROR(tecAMM_BALANCE, "AMM has invalid balance."),
MAKE_ERROR(tecAMM_INVALID_TOKENS, "AMM invalid LP tokens."),
MAKE_ERROR(tecAMM_FAILED, "AMM transaction failed."),
MAKE_ERROR(tecCLAIM, "Fee claimed. Sequence used. No action."),
MAKE_ERROR(tecDIR_FULL, "Can not add entry to full directory."),
MAKE_ERROR(tecFAILED_PROCESSING, "Failed to correctly process transaction."),
@@ -58,6 +61,7 @@ transResults()
MAKE_ERROR(tecOVERSIZE, "Object exceeded serialization limits."),
MAKE_ERROR(tecUNFUNDED, "Not enough XAH to satisfy the reserve requirement."),
MAKE_ERROR(tecUNFUNDED_ADD, "DEPRECATED."),
MAKE_ERROR(tecUNFUNDED_AMM, "Insufficient balance to fund AMM."),
MAKE_ERROR(tecUNFUNDED_OFFER, "Insufficient balance to fund created offer."),
MAKE_ERROR(tecUNFUNDED_PAYMENT, "Insufficient balance to send."),
MAKE_ERROR(tecOWNERS, "Non-zero owner count."),
@@ -140,6 +144,7 @@ transResults()
MAKE_ERROR(telIMPORT_VL_KEY_NOT_RECOGNISED, "Import vl key was not recognized."),
MAKE_ERROR(telCAN_NOT_QUEUE_IMPORT, "Import transaction was not able to be directly applied and cannot be queued."),
MAKE_ERROR(temMALFORMED, "Malformed transaction."),
MAKE_ERROR(temBAD_AMM_TOKENS, "Malformed: Invalid LPTokens."),
MAKE_ERROR(temBAD_AMOUNT, "Can only send positive amounts."),
MAKE_ERROR(temBAD_CURRENCY, "Malformed: Bad currency."),
MAKE_ERROR(temBAD_EXPIRATION, "Malformed: Bad expiration."),
@@ -192,6 +197,7 @@ transResults()
MAKE_ERROR(terQUEUED, "Held until escalated fee drops."),
MAKE_ERROR(terPRE_TICKET, "Ticket is not yet in ledger."),
MAKE_ERROR(terNO_HOOK, "No hook with that hash exists on the ledger."),
MAKE_ERROR(terNO_AMM, "AMM doesn't exist for the asset pair."),
MAKE_ERROR(tesSUCCESS, "The transaction was applied. Only final in a validated ledger."),
MAKE_ERROR(tesPARTIAL, "The transaction was applied but should be submitted again until returning tesSUCCESS."),