From 25bdb692cbae830526aecfabe6e24a9bed61e35c Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 16 Aug 2022 14:57:07 -0400 Subject: [PATCH 01/93] update definitions.json --- .../src/enums/definitions.json | 319 +++++++++++++++++- 1 file changed, 318 insertions(+), 1 deletion(-) diff --git a/packages/ripple-binary-codec/src/enums/definitions.json b/packages/ripple-binary-codec/src/enums/definitions.json index 317e1feb71..605dd2a2c2 100644 --- a/packages/ripple-binary-codec/src/enums/definitions.json +++ b/packages/ripple-binary-codec/src/enums/definitions.json @@ -44,6 +44,7 @@ "NegativeUNL": 78, "NFTokenPage": 80, "NFTokenOffer": 55, + "Amm": 121, "Any": -3, "Child": -2, "Nickname": 110, @@ -271,6 +272,16 @@ "type": "UInt16" } ], + [ + "TradingFee", + { + "nth": 5, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt16" + } + ], [ "Version", { @@ -761,6 +772,46 @@ "type": "UInt32" } ], + [ + "FeeVal", + { + "nth": 47, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "VoteWeight", + { + "nth": 48, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "TimeStamp", + { + "nth": 49, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "DiscountedFee", + { + "nth": 50, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], [ "IndexNext", { @@ -981,6 +1032,26 @@ "type": "Hash160" } ], + [ + "TokenCurrency", + { + "nth": 5, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Hash160" + } + ], + [ + "TokenIssuer", + { + "nth": 6, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Hash160" + } + ], [ "LedgerHash", { @@ -1111,6 +1182,16 @@ "type": "Hash256" } ], + [ + "AMMID", + { + "nth": 14, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Hash256" + } + ], [ "BookDirectory", { @@ -1381,6 +1462,46 @@ "type": "Amount" } ], + [ + "Asset1", + { + "nth": 11, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Amount" + } + ], + [ + "Asset2", + { + "nth": 12, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Amount" + } + ], + [ + "MinSlotPrice", + { + "nth": 13, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Amount" + } + ], + [ + "MaxSlotPrice", + { + "nth": 14, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Amount" + } + ], [ "MinimumOffer", { @@ -1421,6 +1542,86 @@ "type": "Amount" } ], + [ + "Asset1In", + { + "nth": 20, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Amount" + } + ], + [ + "Asset2In", + { + "nth": 21, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Amount" + } + ], + [ + "Asset1Out", + { + "nth": 22, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Amount" + } + ], + [ + "Asset2Out", + { + "nth": 23, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Amount" + } + ], + [ + "LPTokens", + { + "nth": 24, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Amount" + } + ], + [ + "EPrice", + { + "nth": 25, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Amount" + } + ], + [ + "Price", + { + "nth": 26, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Amount" + } + ], + [ + "LPTokenBalance", + { + "nth": 27, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Amount" + } + ], [ "PublicKey", { @@ -1751,6 +1952,16 @@ "type": "AccountID" } ], + [ + "AMMAccount", + { + "nth": 11, + "isVLEncoded": true, + "isSerialized": true, + "isSigningField": true, + "type": "AccountID" + } + ], [ "HookAccount", { @@ -1941,6 +2152,16 @@ "type": "STObject" } ], + [ + "AMM", + { + "nth": 15, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "STObject" + } + ], [ "Signer", { @@ -2021,6 +2242,66 @@ "type": "STObject" } ], + [ + "VoteEntry", + { + "nth": 25, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "STObject" + } + ], + [ + "AuctionSlot", + { + "nth": 27, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "STObject" + } + ], + [ + "AuthAccount", + { + "nth": 28, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "STObject" + } + ], + [ + "AMMToken", + { + "nth": 29, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "STObject" + } + ], + [ + "Token1", + { + "nth": 30, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "STObject" + } + ], + [ + "Token2", + { + "nth": 31, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "STObject" + } + ], [ "Signers", { @@ -2111,6 +2392,26 @@ "type": "STArray" } ], + [ + "VoteSlots", + { + "nth": 14, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "STArray" + } + ], + [ + "AuthAccounts", + { + "nth": 21, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "STArray" + } + ], [ "Majorities", { @@ -2215,6 +2516,8 @@ "temUNKNOWN": -264, "temSEQ_AND_TICKET": -263, "temBAD_NFTOKEN_TRANSFER_FEE": -262, + "temBAD_AMM_OPTIONS": -261, + "temBAD_AMM_TOKENS": -260, "tefFAILURE": -199, "tefALREADY": -198, @@ -2298,7 +2601,16 @@ "tecCANT_ACCEPT_OWN_NFTOKEN_OFFER": 158, "tecINSUFFICIENT_FUNDS": 159, "tecOBJECT_NOT_FOUND": 160, - "tecINSUFFICIENT_PAYMENT": 161 + "tecINSUFFICIENT_PAYMENT": 161, + "tecUNFUNDED_AMM": 162, + "tecAMM_BALANCE": 163, + "tecAMM_FAILED_DEPOSIT": 164, + "tecAMM_FAILED_WITHDRAW": 165, + "tecAMM_INVALID_TOKENS": 166, + "tecAMM_EXISTS": 167, + "tecAMM_FAILED_BID": 168, + "tecAMM_DIRECT_PAYMENT": 169, + "tecAMM_FAILED_VOTE": 170 }, "TRANSACTION_TYPES": { "Invalid": -1, @@ -2330,6 +2642,11 @@ "NFTokenCreateOffer": 27, "NFTokenCancelOffer": 28, "NFTokenAcceptOffer": 29, + "AMMInstanceCreate": 35, + "AMMDeposit": 36, + "AMMWithdraw": 37, + "AMMVote": 38, + "AMMBid": 39, "EnableAmendment": 100, "SetFee": 101, "UNLModify": 102 From 2680c34689b34a3dc4f93b4046de18d9115e3321 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 17 Aug 2022 22:38:31 -0400 Subject: [PATCH 02/93] add AMMInstanceCreate --- .../models/transactions/AMMInstanceCreate.ts | 76 ++++++++ .../xrpl/src/models/transactions/index.ts | 1 + .../src/models/transactions/transaction.ts | 9 + .../xrpl/test/models/AMMInstanceCreate.ts | 166 ++++++++++++++++++ 4 files changed, 252 insertions(+) create mode 100644 packages/xrpl/src/models/transactions/AMMInstanceCreate.ts create mode 100644 packages/xrpl/test/models/AMMInstanceCreate.ts diff --git a/packages/xrpl/src/models/transactions/AMMInstanceCreate.ts b/packages/xrpl/src/models/transactions/AMMInstanceCreate.ts new file mode 100644 index 0000000000..5ffec4d6b5 --- /dev/null +++ b/packages/xrpl/src/models/transactions/AMMInstanceCreate.ts @@ -0,0 +1,76 @@ +import { ValidationError } from '../../errors' +import { Amount } from '../common' + +import { BaseTransaction, isAmount, validateBaseTransaction } from './common' + +const MAX_TRADING_FEE: number = 65000 + +/** + * AMMInstanceCreate is used to create AccountRoot and the corresponding + * AMM ledger entries. + * + * This allows for the creation of only one AMM instance per unique asset pair. + */ +export interface AMMInstanceCreate extends BaseTransaction { + TransactionType: 'AMMInstanceCreate' + + /** + * Specifies one of the pool assets (XRP or token) of the AMM instance. + */ + Asset1: Amount + + /** + * Specifies the other pool asset of the AMM instance. + */ + Asset2: Amount + + /** + * Specifies the fee, in basis point, to be charged + * to the traders for the trades executed against the AMM instance. + * Trading fee is a percentage of the trading volume. + * Valid values for this field are between 0 and 65000 inclusive. + * A value of 1 is equivalent to 1/10 bps or 0.001%, allowing trading fee + * between 0% and 65%. + */ + TradingFee: number +} + +/** + * Verify the form and type of an AMMInstanceCreate at runtime. + * + * @param tx - An AMMInstanceCreate Transaction. + * @throws When the AMMInstanceCreate is Malformed. + */ +export function validateAMMInstanceCreate(tx: Record): void { + validateBaseTransaction(tx) + + if (tx.Asset1 === undefined) { + throw new ValidationError('AMMInstanceCreate: missing field Asset1') + } + + if (!isAmount(tx.Asset1)) { + throw new ValidationError('AMMInstanceCreate: Asset1 must be an Amount') + } + + if (tx.Asset2 === undefined) { + throw new ValidationError('AMMInstanceCreate: missing field Asset2') + } + + if (!isAmount(tx.Asset2)) { + throw new ValidationError('AMMInstanceCreate: Asset2 must be an Amount') + } + + if (tx.TradingFee === undefined) { + throw new ValidationError('AMMInstanceCreate: missing field TradingFee') + } + + if (typeof tx.TradingFee !== 'number') { + throw new ValidationError('AMMInstanceCreate: TradingFee must be a number') + } + + if (tx.TradingFee > MAX_TRADING_FEE) { + throw new ValidationError( + `AMMInstanceCreate: TradingFee must not be greater than ${MAX_TRADING_FEE}`, + ) + } +} diff --git a/packages/xrpl/src/models/transactions/index.ts b/packages/xrpl/src/models/transactions/index.ts index 499444243c..e8d20b621f 100644 --- a/packages/xrpl/src/models/transactions/index.ts +++ b/packages/xrpl/src/models/transactions/index.ts @@ -7,6 +7,7 @@ export { AccountSet, } from './accountSet' export { AccountDelete } from './accountDelete' +export { AMMInstanceCreate } from './AMMInstanceCreate' export { CheckCancel } from './checkCancel' export { CheckCash } from './checkCash' export { CheckCreate } from './checkCreate' diff --git a/packages/xrpl/src/models/transactions/transaction.ts b/packages/xrpl/src/models/transactions/transaction.ts index e5a26b8f49..16bd4de4dc 100644 --- a/packages/xrpl/src/models/transactions/transaction.ts +++ b/packages/xrpl/src/models/transactions/transaction.ts @@ -9,6 +9,10 @@ import { setTransactionFlagsToNumber } from '../utils/flags' import { AccountDelete, validateAccountDelete } from './accountDelete' import { AccountSet, validateAccountSet } from './accountSet' +import { + AMMInstanceCreate, + validateAMMInstanceCreate, +} from './AMMInstanceCreate' import { CheckCancel, validateCheckCancel } from './checkCancel' import { CheckCash, validateCheckCash } from './checkCash' import { CheckCreate, validateCheckCreate } from './checkCreate' @@ -57,6 +61,7 @@ import { TrustSet, validateTrustSet } from './trustSet' export type Transaction = | AccountDelete | AccountSet + | AMMInstanceCreate | CheckCancel | CheckCash | CheckCreate @@ -115,6 +120,10 @@ export function validate(transaction: Record): void { validateAccountSet(tx) break + case 'AMMInstanceCreate': + validateAMMInstanceCreate(tx) + break + case 'CheckCancel': validateCheckCancel(tx) break diff --git a/packages/xrpl/test/models/AMMInstanceCreate.ts b/packages/xrpl/test/models/AMMInstanceCreate.ts new file mode 100644 index 0000000000..6e9fbde63a --- /dev/null +++ b/packages/xrpl/test/models/AMMInstanceCreate.ts @@ -0,0 +1,166 @@ +import { assert } from 'chai' +import { validate, ValidationError } from 'xrpl-local' + +/** + * NFTokenMint Transaction Verification Testing. + * + * Providing runtime verification testing for each specific transaction type. + */ +describe('AMMInstanceCreate', function () { + it(`verifies valid AMMInstanceCreate`, function () { + const validTx = { + TransactionType: 'AMMInstanceCreate', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + Asset1: '1000', + Asset2: { + currency: 'USD', + issuer: 'rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9', + value: '1000', + }, + TradingFee: 12, + Sequence: 1337, + } as any + + assert.doesNotThrow(() => validate(validTx)) + }) + + it(`throws w/ missing Asset1`, function () { + const invalid = { + TransactionType: 'AMMInstanceCreate', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + Asset2: { + currency: 'USD', + issuer: 'rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9', + value: '1000', + }, + TradingFee: 12, + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalid), + ValidationError, + 'AMMInstanceCreate: missing field Asset1', + ) + }) + + it(`throws w/ Asset1 must be an Amount`, function () { + const invalidAsset1 = 1000 + const invalidTx = { + TransactionType: 'AMMInstanceCreate', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + Asset1: invalidAsset1, + Asset2: { + currency: 'USD', + issuer: 'rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9', + value: '1000', + }, + TradingFee: 12, + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalidTx), + ValidationError, + 'AMMInstanceCreate: Asset1 must be an Amount', + ) + }) + + it(`throws w/ missing Asset2`, function () { + const invalid = { + TransactionType: 'AMMInstanceCreate', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + Asset1: '1000', + TradingFee: 12, + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalid), + ValidationError, + 'AMMInstanceCreate: missing field Asset2', + ) + }) + + it(`throws w/ Asset2 must be an Amount`, function () { + const invalidAsset2 = 1000 + const invalidTx = { + TransactionType: 'AMMInstanceCreate', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + Asset1: '1000', + Asset2: invalidAsset2, + TradingFee: 12, + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalidTx), + ValidationError, + 'AMMInstanceCreate: Asset2 must be an Amount', + ) + }) + + it(`throws w/ missing TradingFee`, function () { + const invalid = { + TransactionType: 'AMMInstanceCreate', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + Asset1: '1000', + Asset2: { + currency: 'USD', + issuer: 'rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9', + value: '1000', + }, + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalid), + ValidationError, + 'AMMInstanceCreate: missing field TradingFee', + ) + }) + + it(`throws w/ TradingFee must be a number`, function () { + const invalidTradingFee = '12' + const invalidTx = { + TransactionType: 'AMMInstanceCreate', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + Asset1: '1000', + Asset2: { + currency: 'USD', + issuer: 'rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9', + value: '1000', + }, + TradingFee: invalidTradingFee, + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalidTx), + ValidationError, + 'AMMInstanceCreate: TradingFee must be a number', + ) + }) + + it(`throws w/ TradingFee must not be greater than 65000`, function () { + const invalidTradingFee = 65001 + const invalidTx = { + TransactionType: 'AMMInstanceCreate', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + Asset1: '1000', + Asset2: { + currency: 'USD', + issuer: 'rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9', + value: '1000', + }, + TradingFee: invalidTradingFee, + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalidTx), + ValidationError, + `AMMInstanceCreate: TradingFee must not be greater than 65000`, + ) + }) +}) From 6bcfc2be3236157c6fc5d37f3381cd5bc382ba08 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Thu, 18 Aug 2022 13:38:44 -0400 Subject: [PATCH 03/93] renamed LPTokens to LPToken in definitions.json --- packages/ripple-binary-codec/src/enums/definitions.json | 2 +- packages/xrpl/src/models/transactions/AMMInstanceCreate.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ripple-binary-codec/src/enums/definitions.json b/packages/ripple-binary-codec/src/enums/definitions.json index 605dd2a2c2..ce449a5174 100644 --- a/packages/ripple-binary-codec/src/enums/definitions.json +++ b/packages/ripple-binary-codec/src/enums/definitions.json @@ -1583,7 +1583,7 @@ } ], [ - "LPTokens", + "LPToken", { "nth": 24, "isVLEncoded": false, diff --git a/packages/xrpl/src/models/transactions/AMMInstanceCreate.ts b/packages/xrpl/src/models/transactions/AMMInstanceCreate.ts index 5ffec4d6b5..637f9c2592 100644 --- a/packages/xrpl/src/models/transactions/AMMInstanceCreate.ts +++ b/packages/xrpl/src/models/transactions/AMMInstanceCreate.ts @@ -3,7 +3,7 @@ import { Amount } from '../common' import { BaseTransaction, isAmount, validateBaseTransaction } from './common' -const MAX_TRADING_FEE: number = 65000 +const MAX_TRADING_FEE = 65000 /** * AMMInstanceCreate is used to create AccountRoot and the corresponding From ff60b547e3097a4495657540245c9198824146a5 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Thu, 18 Aug 2022 14:14:30 -0400 Subject: [PATCH 04/93] update HISTORY.md --- packages/xrpl/HISTORY.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index 98bd07c2b0..1ee6990e7f 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -8,6 +8,9 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr * `Wallet.fromMnemonic` detects when an invalid encoding is provided, and throws an error * Made unexpected errors in `submitAndWait` more verbose to make them easier to debug. +### Added +* Support for Automated Market Maker (AMM). + ## 2.3.1 (2022-06-27) ### Fixed * Signing tx with standard currency codes with lowercase and allowed symbols causing an error on decode. From 3461fcc929f1c4a79a4960dfe8e0dbbd8d58f9bf Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Thu, 18 Aug 2022 16:00:25 -0400 Subject: [PATCH 05/93] add amm_info RPC command --- packages/xrpl/src/client/index.ts | 4 + packages/xrpl/src/models/methods/ammInfo.ts | 81 +++++++++++++++++++++ packages/xrpl/src/models/methods/index.ts | 5 ++ 3 files changed, 90 insertions(+) create mode 100644 packages/xrpl/src/models/methods/ammInfo.ts diff --git a/packages/xrpl/src/client/index.ts b/packages/xrpl/src/client/index.ts index ef64d8c537..9dd00f8184 100644 --- a/packages/xrpl/src/client/index.ts +++ b/packages/xrpl/src/client/index.ts @@ -24,6 +24,9 @@ import { AccountOffersResponse, AccountTxRequest, AccountTxResponse, + // AMM methods + AMMInfoRequest, + AMMInfoResponse, GatewayBalancesRequest, GatewayBalancesResponse, NoRippleCheckRequest, @@ -298,6 +301,7 @@ class Client extends EventEmitter { ): Promise public async request(r: AccountOffersRequest): Promise public async request(r: AccountTxRequest): Promise + public async request(r: AMMInfoRequest): Promise public async request(r: BookOffersRequest): Promise public async request(r: ChannelVerifyRequest): Promise public async request( diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts new file mode 100644 index 0000000000..afb58e0a23 --- /dev/null +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -0,0 +1,81 @@ +import { Amount, IssuedCurrencyAmount } from '../common' + +import { BaseRequest, BaseResponse } from './baseMethod' + +/** + * The `amm_info` command retrieves information about an AMM instance. + * Returns an {@link AMMInfoResponse}. + * + * @category Requests + */ +export interface AMMInfoRequest extends BaseRequest { + command: 'amm_info' + + /** + * A hash that uniquely identifies the AMM instance. + */ + amm_id?: string + + /** + * Specifies one of the pool assets (XRP or token) of the AMM instance. + */ + asset1?: Amount + + /** + * Specifies the other pool asset of the AMM instance. + */ + asset2?: Amount +} + +/** + * Response expected from an {@link AMMInfoRequest}. + * + * @category Responses + */ +export interface AMMInfoResponse extends BaseResponse { + result: { + /** + * The account that tracks the balance of LPTokens between the AMM instance via Trustline. + */ + AMMAccount: string + + /** + * Specifies one of the pool assets (XRP or token) of the AMM instance. + */ + Asset1: Amount + + /** + * Specifies the other pool asset of the AMM instance. + */ + Asset2: Amount + + /** + * Represents the liquidity providers' shares of the AMM instance's pools. + * LPTokens are tokens on XRPL. Each LPToken represents a proportional share of each pool of the AMM instance. + * The AMM instance account issues the LPTokens to LPs upon liquidity provision. + * LPTokens are balanced in the LPs trustline upon liquidity removal. + */ + LPToken: IssuedCurrencyAmount + + /** + * Specifies the fee, in basis point, to be charged to the traders for the trades + * executed against the AMM instance. Trading fee is a percentage of the trading volume. + * Valid values for this field are between 0 and 65000 inclusive. + * A value of 1 is equivalent to 1/10 bps or 0.001%, allowing trading fee + * between 0% and 65%. This field is required. + */ + TradingFee: number + + /** + * The ledger index of the current in-progress ledger, which was used when + * retrieving this information. + */ + ledger_current_index?: number + + /** + * True if this data is from a validated ledger version; if omitted or set + * to false, this data is not final. + */ + validated?: boolean + } +} diff --git a/packages/xrpl/src/models/methods/index.ts b/packages/xrpl/src/models/methods/index.ts index 7c5aee3974..7f40a5d839 100644 --- a/packages/xrpl/src/models/methods/index.ts +++ b/packages/xrpl/src/models/methods/index.ts @@ -16,6 +16,7 @@ import { AccountOffersResponse, } from './accountOffers' import { AccountTxRequest, AccountTxResponse } from './accountTx' +import { AMMInfoRequest, AMMInfoResponse } from './ammInfo' import { ErrorResponse } from './baseMethod' import { BookOffersRequest, BookOffer, BookOffersResponse } from './bookOffers' import { ChannelVerifyRequest, ChannelVerifyResponse } from './channelVerify' @@ -87,6 +88,7 @@ type Request = | AccountObjectsRequest | AccountOffersRequest | AccountTxRequest + | AMMInfoRequest | GatewayBalancesRequest | NoRippleCheckRequest // ledger methods @@ -137,6 +139,7 @@ type Response = | AccountObjectsResponse | AccountOffersResponse | AccountTxResponse + | AMMInfoResponse | GatewayBalancesResponse | NoRippleCheckResponse // ledger methods @@ -195,6 +198,8 @@ export { AccountOffersResponse, AccountTxRequest, AccountTxResponse, + AMMInfoRequest, + AMMInfoResponse, GatewayBalancesRequest, GatewayBalancesResponse, NoRippleCheckRequest, From e64a668ef6212fb30a0f27d28b703a3f02f29753 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Thu, 18 Aug 2022 22:19:50 -0400 Subject: [PATCH 06/93] add AMMDeposit --- .../src/models/transactions/AMMDeposit.ts | 99 ++++++++++++ .../xrpl/src/models/transactions/index.ts | 1 + .../src/models/transactions/transaction.ts | 6 + packages/xrpl/test/models/AMMDeposit.ts | 145 ++++++++++++++++++ .../xrpl/test/models/AMMInstanceCreate.ts | 2 +- 5 files changed, 252 insertions(+), 1 deletion(-) create mode 100644 packages/xrpl/src/models/transactions/AMMDeposit.ts create mode 100644 packages/xrpl/test/models/AMMDeposit.ts diff --git a/packages/xrpl/src/models/transactions/AMMDeposit.ts b/packages/xrpl/src/models/transactions/AMMDeposit.ts new file mode 100644 index 0000000000..fca1ae4c80 --- /dev/null +++ b/packages/xrpl/src/models/transactions/AMMDeposit.ts @@ -0,0 +1,99 @@ +/* eslint-disable complexity -- required for validateAMMDeposit */ +import { ValidationError } from '../../errors' +import { Amount, IssuedCurrencyAmount } from '../common' + +import { + BaseTransaction, + isAmount, + isIssuedCurrency, + validateBaseTransaction, +} from './common' + +/** + * AMMDeposit is the deposit transaction used to add liquidity to the AMM instance pool, + * thus obtaining some share of the instance's pools in the form of LPToken. + * + * The following are the recommended valid combinations: + * - LPToken + * - Asset1In + * - Asset1In and Asset2In + * - Asset1In and LPToken + * - Asset1In and EPrice + */ +export interface AMMDeposit extends BaseTransaction { + TransactionType: 'AMMDeposit' + + /** + * A hash that uniquely identifies the AMM instance. This field is required. + */ + AMMID: string + + /** + * Specifies the amount of shares of the AMM instance pools that the trader + * wants to redeem or trade in. + */ + LPToken?: IssuedCurrencyAmount + + /** + * Specifies one of the pool assets (XRP or token) of the AMM instance to + * deposit more of its value. + */ + Asset1In?: Amount + + /** + * Specifies the other pool asset of the AMM instance to deposit more of + * its value. + */ + Asset2In?: Amount + + /** + * Specifies the maximum effective-price that LPToken can be traded out. + */ + EPrice?: number +} + +/** + * Verify the form and type of an AMMDeposit at runtime. + * + * @param tx - An AMMDeposit Transaction. + * @throws When the AMMDeposit is Malformed. + */ +export function validateAMMDeposit(tx: Record): void { + validateBaseTransaction(tx) + + if (tx.AMMID === undefined) { + throw new ValidationError('AMMDeposit: missing field AMMID') + } + + if (typeof tx.AMMID !== 'string') { + throw new ValidationError('AMMDeposit: AMMID must be a string') + } + + if (tx.Asset2In !== undefined && tx.Asset1In === undefined) { + throw new ValidationError('AMMDeposit: must set Asset1In with Asset2In') + } else if (tx.EPrice !== undefined && tx.Asset1In === undefined) { + throw new ValidationError('AMMDeposit: must set Asset1In with EPrice') + } else if (tx.LPToken === undefined && tx.Asset1In === undefined) { + throw new ValidationError( + 'AMMDeposit: must set either or both LPToken with Asset1In', + ) + } + + if (tx.LPToken !== undefined && !isIssuedCurrency(tx.LPToken)) { + throw new ValidationError( + 'AMMDeposit: LPToken must be an IssuedCurrencyAmount', + ) + } + + if (tx.Asset1In !== undefined && !isAmount(tx.Asset1In)) { + throw new ValidationError('AMMDeposit: Asset1In must be an Amount') + } + + if (tx.Asset2In !== undefined && !isAmount(tx.Asset2In)) { + throw new ValidationError('AMMDeposit: Asset2In must be an Amount') + } + + if (tx.EPrice !== undefined && typeof tx.EPrice !== 'string') { + throw new ValidationError('AMMDeposit: EPrice must be a string') + } +} diff --git a/packages/xrpl/src/models/transactions/index.ts b/packages/xrpl/src/models/transactions/index.ts index e8d20b621f..77d2e19a8b 100644 --- a/packages/xrpl/src/models/transactions/index.ts +++ b/packages/xrpl/src/models/transactions/index.ts @@ -7,6 +7,7 @@ export { AccountSet, } from './accountSet' export { AccountDelete } from './accountDelete' +export { AMMDeposit } from './AMMDeposit' export { AMMInstanceCreate } from './AMMInstanceCreate' export { CheckCancel } from './checkCancel' export { CheckCash } from './checkCash' diff --git a/packages/xrpl/src/models/transactions/transaction.ts b/packages/xrpl/src/models/transactions/transaction.ts index 16bd4de4dc..6fb89dc3cc 100644 --- a/packages/xrpl/src/models/transactions/transaction.ts +++ b/packages/xrpl/src/models/transactions/transaction.ts @@ -9,6 +9,7 @@ import { setTransactionFlagsToNumber } from '../utils/flags' import { AccountDelete, validateAccountDelete } from './accountDelete' import { AccountSet, validateAccountSet } from './accountSet' +import { AMMDeposit, validateAMMDeposit } from './AMMDeposit' import { AMMInstanceCreate, validateAMMInstanceCreate, @@ -61,6 +62,7 @@ import { TrustSet, validateTrustSet } from './trustSet' export type Transaction = | AccountDelete | AccountSet + | AMMDeposit | AMMInstanceCreate | CheckCancel | CheckCash @@ -120,6 +122,10 @@ export function validate(transaction: Record): void { validateAccountSet(tx) break + case 'AMMDeposit': + validateAMMDeposit(tx) + break + case 'AMMInstanceCreate': validateAMMInstanceCreate(tx) break diff --git a/packages/xrpl/test/models/AMMDeposit.ts b/packages/xrpl/test/models/AMMDeposit.ts new file mode 100644 index 0000000000..535ca216f7 --- /dev/null +++ b/packages/xrpl/test/models/AMMDeposit.ts @@ -0,0 +1,145 @@ +import { assert } from 'chai' +import { validate, ValidationError } from 'xrpl-local' + +/** + * AMMDeposit Transaction Verification Testing. + * + * Providing runtime verification testing for each specific transaction type. + */ +describe('AMMDeposit', function () { + it(`verifies valid AMMDeposit with LPToken`, function () { + const validTx = { + TransactionType: 'AMMDeposit', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', + LPToken: { + currency: 'B3813FCAB4EE68B3D0D735D6849465A9113EE048', + issuer: 'rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg', + value: '1000', + }, + Sequence: 1337, + } as any + + assert.doesNotThrow(() => validate(validTx)) + }) + + it(`verifies valid AMMDeposit with Asset1In`, function () { + const validTx = { + TransactionType: 'AMMDeposit', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', + Asset1In: '1000', + Sequence: 1337, + } as any + + assert.doesNotThrow(() => validate(validTx)) + }) + + it(`verifies valid AMMDeposit with Asset1In and LPToken`, function () { + const validTx = { + TransactionType: 'AMMDeposit', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', + Asset1In: '1000', + LPToken: { + currency: 'B3813FCAB4EE68B3D0D735D6849465A9113EE048', + issuer: 'rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg', + value: '1000', + }, + Sequence: 1337, + } as any + + assert.doesNotThrow(() => validate(validTx)) + }) + + it(`verifies valid AMMDeposit with Asset1In and EPrice`, function () { + const validTx = { + TransactionType: 'AMMDeposit', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', + Asset1In: '1000', + EPrice: '25', + Sequence: 1337, + } as any + + assert.doesNotThrow(() => validate(validTx)) + }) + + it(`throws w/ missing AMMID`, function () { + const invalid = { + TransactionType: 'AMMDeposit', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + Asset1In: '1000', + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalid), + ValidationError, + 'AMMDeposit: missing field AMMID', + ) + }) + + it(`throws w/ AMMID must be a string`, function () { + const invalid = { + TransactionType: 'AMMDeposit', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: 1234, + Asset1In: '1000', + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalid), + ValidationError, + 'AMMDeposit: AMMID must be a string', + ) + }) + + it(`throws w/ must set either or both LPToken with Asset1In`, function () { + const invalid = { + TransactionType: 'AMMDeposit', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalid), + ValidationError, + 'AMMDeposit: must set either or both LPToken with Asset1In', + ) + }) + + it(`throws w/ must set Asset1In with Asset2In`, function () { + const invalid = { + TransactionType: 'AMMDeposit', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', + Asset2In: '500', + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalid), + ValidationError, + 'AMMDeposit: must set Asset1In with Asset2In', + ) + }) + + it(`throws w/ must set Asset1In with EPrice`, function () { + const invalid = { + TransactionType: 'AMMDeposit', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', + EPrice: '25', + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalid), + ValidationError, + 'AMMDeposit: must set Asset1In with EPrice', + ) + }) +}) diff --git a/packages/xrpl/test/models/AMMInstanceCreate.ts b/packages/xrpl/test/models/AMMInstanceCreate.ts index 6e9fbde63a..6ed798becc 100644 --- a/packages/xrpl/test/models/AMMInstanceCreate.ts +++ b/packages/xrpl/test/models/AMMInstanceCreate.ts @@ -2,7 +2,7 @@ import { assert } from 'chai' import { validate, ValidationError } from 'xrpl-local' /** - * NFTokenMint Transaction Verification Testing. + * AMMInstanceCreate Transaction Verification Testing. * * Providing runtime verification testing for each specific transaction type. */ From 35fef6512f6358f74aa0aba09ca0483f0d8e1a48 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Thu, 18 Aug 2022 23:11:24 -0400 Subject: [PATCH 07/93] use null check for missing fields --- .../xrpl/src/models/transactions/AMMDeposit.ts | 16 ++++++++-------- .../src/models/transactions/AMMInstanceCreate.ts | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/xrpl/src/models/transactions/AMMDeposit.ts b/packages/xrpl/src/models/transactions/AMMDeposit.ts index fca1ae4c80..d01a5b3b8e 100644 --- a/packages/xrpl/src/models/transactions/AMMDeposit.ts +++ b/packages/xrpl/src/models/transactions/AMMDeposit.ts @@ -61,7 +61,7 @@ export interface AMMDeposit extends BaseTransaction { export function validateAMMDeposit(tx: Record): void { validateBaseTransaction(tx) - if (tx.AMMID === undefined) { + if (tx.AMMID == null) { throw new ValidationError('AMMDeposit: missing field AMMID') } @@ -69,31 +69,31 @@ export function validateAMMDeposit(tx: Record): void { throw new ValidationError('AMMDeposit: AMMID must be a string') } - if (tx.Asset2In !== undefined && tx.Asset1In === undefined) { + if (tx.Asset2In != null && tx.Asset1In == null) { throw new ValidationError('AMMDeposit: must set Asset1In with Asset2In') - } else if (tx.EPrice !== undefined && tx.Asset1In === undefined) { + } else if (tx.EPrice != null && tx.Asset1In == null) { throw new ValidationError('AMMDeposit: must set Asset1In with EPrice') - } else if (tx.LPToken === undefined && tx.Asset1In === undefined) { + } else if (tx.LPToken == null && tx.Asset1In == null) { throw new ValidationError( 'AMMDeposit: must set either or both LPToken with Asset1In', ) } - if (tx.LPToken !== undefined && !isIssuedCurrency(tx.LPToken)) { + if (tx.LPToken != null && !isIssuedCurrency(tx.LPToken)) { throw new ValidationError( 'AMMDeposit: LPToken must be an IssuedCurrencyAmount', ) } - if (tx.Asset1In !== undefined && !isAmount(tx.Asset1In)) { + if (tx.Asset1In != null && !isAmount(tx.Asset1In)) { throw new ValidationError('AMMDeposit: Asset1In must be an Amount') } - if (tx.Asset2In !== undefined && !isAmount(tx.Asset2In)) { + if (tx.Asset2In != null && !isAmount(tx.Asset2In)) { throw new ValidationError('AMMDeposit: Asset2In must be an Amount') } - if (tx.EPrice !== undefined && typeof tx.EPrice !== 'string') { + if (tx.EPrice != null && typeof tx.EPrice !== 'string') { throw new ValidationError('AMMDeposit: EPrice must be a string') } } diff --git a/packages/xrpl/src/models/transactions/AMMInstanceCreate.ts b/packages/xrpl/src/models/transactions/AMMInstanceCreate.ts index 637f9c2592..3ac676b420 100644 --- a/packages/xrpl/src/models/transactions/AMMInstanceCreate.ts +++ b/packages/xrpl/src/models/transactions/AMMInstanceCreate.ts @@ -44,7 +44,7 @@ export interface AMMInstanceCreate extends BaseTransaction { export function validateAMMInstanceCreate(tx: Record): void { validateBaseTransaction(tx) - if (tx.Asset1 === undefined) { + if (tx.Asset1 == null) { throw new ValidationError('AMMInstanceCreate: missing field Asset1') } @@ -52,7 +52,7 @@ export function validateAMMInstanceCreate(tx: Record): void { throw new ValidationError('AMMInstanceCreate: Asset1 must be an Amount') } - if (tx.Asset2 === undefined) { + if (tx.Asset2 == null) { throw new ValidationError('AMMInstanceCreate: missing field Asset2') } @@ -60,7 +60,7 @@ export function validateAMMInstanceCreate(tx: Record): void { throw new ValidationError('AMMInstanceCreate: Asset2 must be an Amount') } - if (tx.TradingFee === undefined) { + if (tx.TradingFee == null) { throw new ValidationError('AMMInstanceCreate: missing field TradingFee') } From 3617487c321afc25bf29ac71e4f660fa247c9718 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Thu, 18 Aug 2022 23:51:16 -0400 Subject: [PATCH 08/93] add AMMWithdraw --- .../src/models/transactions/AMMWithdraw.ts | 101 ++++++++++++ .../xrpl/src/models/transactions/index.ts | 1 + .../src/models/transactions/transaction.ts | 6 + packages/xrpl/test/models/AMMWithdraw.ts | 145 ++++++++++++++++++ 4 files changed, 253 insertions(+) create mode 100644 packages/xrpl/src/models/transactions/AMMWithdraw.ts create mode 100644 packages/xrpl/test/models/AMMWithdraw.ts diff --git a/packages/xrpl/src/models/transactions/AMMWithdraw.ts b/packages/xrpl/src/models/transactions/AMMWithdraw.ts new file mode 100644 index 0000000000..00aa78df55 --- /dev/null +++ b/packages/xrpl/src/models/transactions/AMMWithdraw.ts @@ -0,0 +1,101 @@ +/* eslint-disable complexity -- required for validateAMMWithdraw */ +import { ValidationError } from '../../errors' +import { Amount, IssuedCurrencyAmount } from '../common' + +import { + BaseTransaction, + isAmount, + isIssuedCurrency, + validateBaseTransaction, +} from './common' + +/** + * AMMWithdraw is the withdraw transaction used to remove liquidity from the AMM + * instance pool, thus redeeming some share of the pools that one owns in the form + * of LPToken. + * + * The following are the recommended valid combinations: + * - LPToken + * - Asset1Out + * - Asset1Out and Asset2Out + * - Asset1Out and LPToken + * - Asset1Out and EPrice + */ +export interface AMMWithdraw extends BaseTransaction { + TransactionType: 'AMMWithdraw' + + /** + * A hash that uniquely identifies the AMM instance. This field is required. + */ + AMMID: string + + /** + * Specifies the amount of shares of the AMM instance pools that the trader + * wants to redeem or trade in. + */ + LPToken?: IssuedCurrencyAmount + + /** + * Specifies one of the pools assets that the trader wants to remove. + * If the asset is XRP, then the Asset1Out is a string specifying the number of drops. + * Otherwise it is an IssuedCurrencyAmount object. + */ + Asset1Out?: Amount + + /** + * Specifies the other pool asset that the trader wants to remove. + */ + Asset2Out?: Amount + + /** + * Specifies the effective-price of the token out after successful execution of + * the transaction. + */ + EPrice?: number +} + +/** + * Verify the form and type of an AMMWithdraw at runtime. + * + * @param tx - An AMMWithdraw Transaction. + * @throws When the AMMWithdraw is Malformed. + */ +export function validateAMMWithdraw(tx: Record): void { + validateBaseTransaction(tx) + + if (tx.AMMID == null) { + throw new ValidationError('AMMWithdraw: missing field AMMID') + } + + if (typeof tx.AMMID !== 'string') { + throw new ValidationError('AMMWithdraw: AMMID must be a string') + } + + if (tx.Asset2Out != null && tx.Asset1Out == null) { + throw new ValidationError('AMMWithdraw: must set Asset1Out with Asset2Out') + } else if (tx.EPrice != null && tx.Asset1Out == null) { + throw new ValidationError('AMMWithdraw: must set Asset1Out with EPrice') + } else if (tx.LPToken == null && tx.Asset1Out == null) { + throw new ValidationError( + 'AMMWithdraw: must set either or both LPToken with Asset1Out', + ) + } + + if (tx.LPToken != null && !isIssuedCurrency(tx.LPToken)) { + throw new ValidationError( + 'AMMWithdraw: LPToken must be an IssuedCurrencyAmount', + ) + } + + if (tx.Asset1Out != null && !isAmount(tx.Asset1Out)) { + throw new ValidationError('AMMWithdraw: Asset1Out must be an Amount') + } + + if (tx.Asset2Out != null && !isAmount(tx.Asset2Out)) { + throw new ValidationError('AMMWithdraw: Asset2Out must be an Amount') + } + + if (tx.EPrice != null && typeof tx.EPrice !== 'string') { + throw new ValidationError('AMMWithdraw: EPrice must be a string') + } +} diff --git a/packages/xrpl/src/models/transactions/index.ts b/packages/xrpl/src/models/transactions/index.ts index 77d2e19a8b..2fc2362208 100644 --- a/packages/xrpl/src/models/transactions/index.ts +++ b/packages/xrpl/src/models/transactions/index.ts @@ -9,6 +9,7 @@ export { export { AccountDelete } from './accountDelete' export { AMMDeposit } from './AMMDeposit' export { AMMInstanceCreate } from './AMMInstanceCreate' +export { AMMWithdraw } from './AMMWithdraw' export { CheckCancel } from './checkCancel' export { CheckCash } from './checkCash' export { CheckCreate } from './checkCreate' diff --git a/packages/xrpl/src/models/transactions/transaction.ts b/packages/xrpl/src/models/transactions/transaction.ts index 6fb89dc3cc..06a7032361 100644 --- a/packages/xrpl/src/models/transactions/transaction.ts +++ b/packages/xrpl/src/models/transactions/transaction.ts @@ -14,6 +14,7 @@ import { AMMInstanceCreate, validateAMMInstanceCreate, } from './AMMInstanceCreate' +import { AMMWithdraw, validateAMMWithdraw } from './AMMWithdraw' import { CheckCancel, validateCheckCancel } from './checkCancel' import { CheckCash, validateCheckCash } from './checkCash' import { CheckCreate, validateCheckCreate } from './checkCreate' @@ -64,6 +65,7 @@ export type Transaction = | AccountSet | AMMDeposit | AMMInstanceCreate + | AMMWithdraw | CheckCancel | CheckCash | CheckCreate @@ -130,6 +132,10 @@ export function validate(transaction: Record): void { validateAMMInstanceCreate(tx) break + case 'AMMWithdraw': + validateAMMWithdraw(tx) + break + case 'CheckCancel': validateCheckCancel(tx) break diff --git a/packages/xrpl/test/models/AMMWithdraw.ts b/packages/xrpl/test/models/AMMWithdraw.ts new file mode 100644 index 0000000000..f12d819e14 --- /dev/null +++ b/packages/xrpl/test/models/AMMWithdraw.ts @@ -0,0 +1,145 @@ +import { assert } from 'chai' +import { validate, ValidationError } from 'xrpl-local' + +/** + * AMMWithdraw Transaction Verification Testing. + * + * Providing runtime verification testing for each specific transaction type. + */ +describe('AMMWithdraw', function () { + it(`verifies valid AMMWithdraw with LPToken`, function () { + const validTx = { + TransactionType: 'AMMWithdraw', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', + LPToken: { + currency: 'B3813FCAB4EE68B3D0D735D6849465A9113EE048', + issuer: 'rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg', + value: '1000', + }, + Sequence: 1337, + } as any + + assert.doesNotThrow(() => validate(validTx)) + }) + + it(`verifies valid AMMWithdraw with Asset1Out`, function () { + const validTx = { + TransactionType: 'AMMWithdraw', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', + Asset1Out: '1000', + Sequence: 1337, + } as any + + assert.doesNotThrow(() => validate(validTx)) + }) + + it(`verifies valid AMMWithdraw with Asset1Out and LPToken`, function () { + const validTx = { + TransactionType: 'AMMWithdraw', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', + Asset1Out: '1000', + LPToken: { + currency: 'B3813FCAB4EE68B3D0D735D6849465A9113EE048', + issuer: 'rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg', + value: '1000', + }, + Sequence: 1337, + } as any + + assert.doesNotThrow(() => validate(validTx)) + }) + + it(`verifies valid AMMWithdraw with Asset1Out and EPrice`, function () { + const validTx = { + TransactionType: 'AMMWithdraw', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', + Asset1Out: '1000', + EPrice: '25', + Sequence: 1337, + } as any + + assert.doesNotThrow(() => validate(validTx)) + }) + + it(`throws w/ missing AMMID`, function () { + const invalid = { + TransactionType: 'AMMWithdraw', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + Asset1Out: '1000', + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalid), + ValidationError, + 'AMMWithdraw: missing field AMMID', + ) + }) + + it(`throws w/ AMMID must be a string`, function () { + const invalid = { + TransactionType: 'AMMWithdraw', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: 1234, + Asset1Out: '1000', + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalid), + ValidationError, + 'AMMWithdraw: AMMID must be a string', + ) + }) + + it(`throws w/ must set either or both LPToken with Asset1Out`, function () { + const invalid = { + TransactionType: 'AMMWithdraw', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalid), + ValidationError, + 'AMMWithdraw: must set either or both LPToken with Asset1Out', + ) + }) + + it(`throws w/ must set Asset1Out with Asset2Out`, function () { + const invalid = { + TransactionType: 'AMMWithdraw', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', + Asset2Out: '500', + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalid), + ValidationError, + 'AMMWithdraw: must set Asset1Out with Asset2Out', + ) + }) + + it(`throws w/ must set Asset1Out with EPrice`, function () { + const invalid = { + TransactionType: 'AMMWithdraw', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', + EPrice: '25', + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalid), + ValidationError, + 'AMMWithdraw: must set Asset1Out with EPrice', + ) + }) +}) From b794f909ad1967b01d71145f0cc6e999840ceba9 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Fri, 19 Aug 2022 17:18:46 -0400 Subject: [PATCH 09/93] add AMMVote --- .../xrpl/src/models/transactions/AMMVote.ts | 55 ++++++++++++ .../xrpl/src/models/transactions/index.ts | 1 + .../src/models/transactions/transaction.ts | 6 ++ packages/xrpl/test/models/AMMVote.ts | 83 +++++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 packages/xrpl/src/models/transactions/AMMVote.ts create mode 100644 packages/xrpl/test/models/AMMVote.ts diff --git a/packages/xrpl/src/models/transactions/AMMVote.ts b/packages/xrpl/src/models/transactions/AMMVote.ts new file mode 100644 index 0000000000..d1d737205a --- /dev/null +++ b/packages/xrpl/src/models/transactions/AMMVote.ts @@ -0,0 +1,55 @@ +import { ValidationError } from '../../errors' + +import { + BaseTransaction, + validateBaseTransaction, +} from './common' + +/** + * AMMVote is used for submitting a vote for the trading fee of an AMM Instance. + * + * Any XRPL account that holds LPToken for an AMM instance may submit this + * transaction to vote for the trading fee for that instance. + */ +export interface AMMVote extends BaseTransaction { + TransactionType: 'AMMVote' + + /** + * A hash that uniquely identifies the AMM instance. This field is required. + */ + AMMID: string + + /** + * Specifies the fee, in basis point. + * Valid values for this field are between 0 and 65000 inclusive. + * A value of 1 is equivalent to 1/10 bps or 0.001%, allowing trading fee + * between 0% and 65%. This field is required. + */ + FeeVal: number +} + +/** + * Verify the form and type of an AMMVote at runtime. + * + * @param tx - An AMMVote Transaction. + * @throws When the AMMVote is Malformed. + */ +export function validateAMMVote(tx: Record): void { + validateBaseTransaction(tx) + + if (tx.AMMID == null) { + throw new ValidationError('AMMVote: missing field AMMID') + } + + if (typeof tx.AMMID !== 'string') { + throw new ValidationError('AMMVote: AMMID must be a string') + } + + if (tx.FeeVal == null) { + throw new ValidationError('AMMVote: missing field FeeVal') + } + + if (typeof tx.FeeVal !== 'number') { + throw new ValidationError('AMMVote: FeeVal must be a number') + } +} diff --git a/packages/xrpl/src/models/transactions/index.ts b/packages/xrpl/src/models/transactions/index.ts index 2fc2362208..a6ebf054f4 100644 --- a/packages/xrpl/src/models/transactions/index.ts +++ b/packages/xrpl/src/models/transactions/index.ts @@ -9,6 +9,7 @@ export { export { AccountDelete } from './accountDelete' export { AMMDeposit } from './AMMDeposit' export { AMMInstanceCreate } from './AMMInstanceCreate' +export { AMMVote } from './AMMVote' export { AMMWithdraw } from './AMMWithdraw' export { CheckCancel } from './checkCancel' export { CheckCash } from './checkCash' diff --git a/packages/xrpl/src/models/transactions/transaction.ts b/packages/xrpl/src/models/transactions/transaction.ts index 06a7032361..d17a800ad1 100644 --- a/packages/xrpl/src/models/transactions/transaction.ts +++ b/packages/xrpl/src/models/transactions/transaction.ts @@ -14,6 +14,7 @@ import { AMMInstanceCreate, validateAMMInstanceCreate, } from './AMMInstanceCreate' +import { AMMVote, validateAMMVote } from './AMMVote' import { AMMWithdraw, validateAMMWithdraw } from './AMMWithdraw' import { CheckCancel, validateCheckCancel } from './checkCancel' import { CheckCash, validateCheckCash } from './checkCash' @@ -65,6 +66,7 @@ export type Transaction = | AccountSet | AMMDeposit | AMMInstanceCreate + | AMMVote | AMMWithdraw | CheckCancel | CheckCash @@ -132,6 +134,10 @@ export function validate(transaction: Record): void { validateAMMInstanceCreate(tx) break + case 'AMMVote': + validateAMMVote(tx) + break + case 'AMMWithdraw': validateAMMWithdraw(tx) break diff --git a/packages/xrpl/test/models/AMMVote.ts b/packages/xrpl/test/models/AMMVote.ts new file mode 100644 index 0000000000..b704c34924 --- /dev/null +++ b/packages/xrpl/test/models/AMMVote.ts @@ -0,0 +1,83 @@ +import { assert } from 'chai' +import { validate, ValidationError } from 'xrpl-local' + +/** + * AMMVote Transaction Verification Testing. + * + * Providing runtime verification testing for each specific transaction type. + */ +describe('AMMVote', function () { + it(`verifies valid AMMVote`, function () { + const validTx = { + TransactionType: 'AMMVote', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', + FeeVal: 25, + Sequence: 1337, + } as any + + assert.doesNotThrow(() => validate(validTx)) + }) + + it(`throws w/ missing field AMMID`, function () { + const invalid = { + TransactionType: 'AMMVote', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + FeeVal: 25, + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalid), + ValidationError, + 'AMMVote: missing field AMMID', + ) + }) + + it(`throws w/ AMMID must be a string`, function () { + const invalid = { + TransactionType: 'AMMVote', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: 1234, + FeeVal: 25, + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalid), + ValidationError, + 'AMMVote: AMMID must be a string', + ) + }) + + it(`throws w/ missing field FeeVal`, function () { + const invalid = { + TransactionType: 'AMMVote', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalid), + ValidationError, + 'AMMVote: missing field FeeVal', + ) + }) + + it(`throws w/ FeeVal must be a number`, function () { + const invalid = { + TransactionType: 'AMMVote', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', + FeeVal: '25', + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalid), + ValidationError, + 'AMMVote: FeeVal must be a number', + ) + }) +}) From e79dcb5d2f1c57a7f0869b2a5ae3077500e4f8e9 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Fri, 19 Aug 2022 17:20:23 -0400 Subject: [PATCH 10/93] fix lint error --- packages/xrpl/src/models/transactions/AMMVote.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/xrpl/src/models/transactions/AMMVote.ts b/packages/xrpl/src/models/transactions/AMMVote.ts index d1d737205a..560bbd2ab6 100644 --- a/packages/xrpl/src/models/transactions/AMMVote.ts +++ b/packages/xrpl/src/models/transactions/AMMVote.ts @@ -1,9 +1,6 @@ import { ValidationError } from '../../errors' -import { - BaseTransaction, - validateBaseTransaction, -} from './common' +import { BaseTransaction, validateBaseTransaction } from './common' /** * AMMVote is used for submitting a vote for the trading fee of an AMM Instance. From db6d32f98bc8a04cd50a9a1743827ba0bb8af091 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Fri, 19 Aug 2022 21:48:26 -0400 Subject: [PATCH 11/93] add max trading fee check to AMMVote --- packages/xrpl/src/models/transactions/AMMVote.ts | 8 ++++++++ packages/xrpl/test/models/AMMVote.ts | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/packages/xrpl/src/models/transactions/AMMVote.ts b/packages/xrpl/src/models/transactions/AMMVote.ts index 560bbd2ab6..e226f04151 100644 --- a/packages/xrpl/src/models/transactions/AMMVote.ts +++ b/packages/xrpl/src/models/transactions/AMMVote.ts @@ -2,6 +2,8 @@ import { ValidationError } from '../../errors' import { BaseTransaction, validateBaseTransaction } from './common' +const MAX_TRADING_FEE = 65000 + /** * AMMVote is used for submitting a vote for the trading fee of an AMM Instance. * @@ -49,4 +51,10 @@ export function validateAMMVote(tx: Record): void { if (typeof tx.FeeVal !== 'number') { throw new ValidationError('AMMVote: FeeVal must be a number') } + + if (tx.FeeVal > MAX_TRADING_FEE) { + throw new ValidationError( + `AMMVote: FeeVal must not be greater than ${MAX_TRADING_FEE}`, + ) + } } diff --git a/packages/xrpl/test/models/AMMVote.ts b/packages/xrpl/test/models/AMMVote.ts index b704c34924..6c0e03fdc9 100644 --- a/packages/xrpl/test/models/AMMVote.ts +++ b/packages/xrpl/test/models/AMMVote.ts @@ -80,4 +80,20 @@ describe('AMMVote', function () { 'AMMVote: FeeVal must be a number', ) }) + + it(`throws w/ FeeVal must not be greater than 65000`, function () { + const invalid = { + TransactionType: 'AMMVote', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', + FeeVal: 65001, + Sequence: 1337, + } as any + + assert.throws( + () => validate(invalid), + ValidationError, + 'AMMVote: FeeVal must not be greater than 65000', + ) + }) }) From 78e0a866cdff7a4e7e35e9210ef11d5bbcc4806f Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Fri, 19 Aug 2022 21:59:30 -0400 Subject: [PATCH 12/93] refactor MAX_TRADING_FEE to be in one place --- packages/xrpl/src/models/transactions/AMMInstanceCreate.ts | 6 +++--- packages/xrpl/src/models/transactions/AMMVote.ts | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/xrpl/src/models/transactions/AMMInstanceCreate.ts b/packages/xrpl/src/models/transactions/AMMInstanceCreate.ts index 3ac676b420..dec294e9af 100644 --- a/packages/xrpl/src/models/transactions/AMMInstanceCreate.ts +++ b/packages/xrpl/src/models/transactions/AMMInstanceCreate.ts @@ -3,7 +3,7 @@ import { Amount } from '../common' import { BaseTransaction, isAmount, validateBaseTransaction } from './common' -const MAX_TRADING_FEE = 65000 +export const AMM_MAX_TRADING_FEE = 65000 /** * AMMInstanceCreate is used to create AccountRoot and the corresponding @@ -68,9 +68,9 @@ export function validateAMMInstanceCreate(tx: Record): void { throw new ValidationError('AMMInstanceCreate: TradingFee must be a number') } - if (tx.TradingFee > MAX_TRADING_FEE) { + if (tx.TradingFee > AMM_MAX_TRADING_FEE) { throw new ValidationError( - `AMMInstanceCreate: TradingFee must not be greater than ${MAX_TRADING_FEE}`, + `AMMInstanceCreate: TradingFee must not be greater than ${AMM_MAX_TRADING_FEE}`, ) } } diff --git a/packages/xrpl/src/models/transactions/AMMVote.ts b/packages/xrpl/src/models/transactions/AMMVote.ts index e226f04151..621ce23223 100644 --- a/packages/xrpl/src/models/transactions/AMMVote.ts +++ b/packages/xrpl/src/models/transactions/AMMVote.ts @@ -1,9 +1,8 @@ import { ValidationError } from '../../errors' +import { AMM_MAX_TRADING_FEE } from './AMMInstanceCreate' import { BaseTransaction, validateBaseTransaction } from './common' -const MAX_TRADING_FEE = 65000 - /** * AMMVote is used for submitting a vote for the trading fee of an AMM Instance. * @@ -52,9 +51,9 @@ export function validateAMMVote(tx: Record): void { throw new ValidationError('AMMVote: FeeVal must be a number') } - if (tx.FeeVal > MAX_TRADING_FEE) { + if (tx.FeeVal > AMM_MAX_TRADING_FEE) { throw new ValidationError( - `AMMVote: FeeVal must not be greater than ${MAX_TRADING_FEE}`, + `AMMVote: FeeVal must not be greater than ${AMM_MAX_TRADING_FEE}`, ) } } From 7a035afca1ee59710d30c93e86ae3c07022d5f9a Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Sat, 20 Aug 2022 09:33:53 -0400 Subject: [PATCH 13/93] add AMMBid --- .../xrpl/src/models/transactions/AMMBid.ts | 79 +++++++++++++++ .../xrpl/src/models/transactions/index.ts | 1 + .../src/models/transactions/transaction.ts | 6 ++ packages/xrpl/test/models/AMMBid.ts | 98 +++++++++++++++++++ 4 files changed, 184 insertions(+) create mode 100644 packages/xrpl/src/models/transactions/AMMBid.ts create mode 100644 packages/xrpl/test/models/AMMBid.ts diff --git a/packages/xrpl/src/models/transactions/AMMBid.ts b/packages/xrpl/src/models/transactions/AMMBid.ts new file mode 100644 index 0000000000..d88fd6c085 --- /dev/null +++ b/packages/xrpl/src/models/transactions/AMMBid.ts @@ -0,0 +1,79 @@ +import { ValidationError } from '../../errors' +import { Amount } from '../common' + +import { BaseTransaction, isAmount, validateBaseTransaction } from './common' + +const MAX_AUTH_ACCOUNTS = 4 + +/** + * AMMBid is used for submitting a vote for the trading fee of an AMM Instance. + * + * Any XRPL account that holds LPToken for an AMM instance may submit this + * transaction to vote for the trading fee for that instance. + */ +export interface AMMBid extends BaseTransaction { + TransactionType: 'AMMBid' + + /** + * A hash that uniquely identifies the AMM instance. This field is required. + */ + AMMID: string + + /** + * This field represents the minimum price that the bidder wants to pay for the slot. + * It is specified in units of LPToken. If specified let MinSlotPrice be X and let + * the slot-price computed by price scheduling algorithm be Y, then bidder always pays + * the max(X, Y). + */ + MinSlotPrice?: Amount + + /** + * This field represents the maximum price that the bidder wants to pay for the slot. + * It is specified in units of LPToken. + */ + MaxSlotPrice?: Amount + + /** + * This field represents an array of XRPL account IDs that are authorized to trade + * at the discounted fee against the AMM instance. + * A maximum of four accounts can be provided. + */ + AuthAccounts?: string[] +} + +/** + * Verify the form and type of an AMMBid at runtime. + * + * @param tx - An AMMBid Transaction. + * @throws When the AMMBid is Malformed. + */ +export function validateAMMBid(tx: Record): void { + validateBaseTransaction(tx) + + if (tx.AMMID == null) { + throw new ValidationError('AMMBid: missing field AMMID') + } + + if (typeof tx.AMMID !== 'string') { + throw new ValidationError('AMMBid: AMMID must be a string') + } + + if (tx.MinSlotPrice != null && !isAmount(tx.MinSlotPrice)) { + throw new ValidationError('AMMBid: MinSlotPrice must be an Amount') + } + + if (tx.MaxSlotPrice != null && !isAmount(tx.MaxSlotPrice)) { + throw new ValidationError('AMMBid: MaxSlotPrice must be an Amount') + } + + if (tx.AuthAccounts != null) { + if (!Array.isArray(tx.AuthAccounts)) { + throw new ValidationError(`AMMBid: AuthAccounts must be a string array`) + } + if (tx.AuthAccounts.length > MAX_AUTH_ACCOUNTS) { + throw new ValidationError( + `AMMBid: AuthAccounts length must not be greater than ${MAX_AUTH_ACCOUNTS}`, + ) + } + } +} diff --git a/packages/xrpl/src/models/transactions/index.ts b/packages/xrpl/src/models/transactions/index.ts index a6ebf054f4..187b308ef7 100644 --- a/packages/xrpl/src/models/transactions/index.ts +++ b/packages/xrpl/src/models/transactions/index.ts @@ -7,6 +7,7 @@ export { AccountSet, } from './accountSet' export { AccountDelete } from './accountDelete' +export { AMMBid } from './AMMBid' export { AMMDeposit } from './AMMDeposit' export { AMMInstanceCreate } from './AMMInstanceCreate' export { AMMVote } from './AMMVote' diff --git a/packages/xrpl/src/models/transactions/transaction.ts b/packages/xrpl/src/models/transactions/transaction.ts index d17a800ad1..1b5c6624c1 100644 --- a/packages/xrpl/src/models/transactions/transaction.ts +++ b/packages/xrpl/src/models/transactions/transaction.ts @@ -9,6 +9,7 @@ import { setTransactionFlagsToNumber } from '../utils/flags' import { AccountDelete, validateAccountDelete } from './accountDelete' import { AccountSet, validateAccountSet } from './accountSet' +import { AMMBid, validateAMMBid } from './AMMBid' import { AMMDeposit, validateAMMDeposit } from './AMMDeposit' import { AMMInstanceCreate, @@ -64,6 +65,7 @@ import { TrustSet, validateTrustSet } from './trustSet' export type Transaction = | AccountDelete | AccountSet + | AMMBid | AMMDeposit | AMMInstanceCreate | AMMVote @@ -126,6 +128,10 @@ export function validate(transaction: Record): void { validateAccountSet(tx) break + case 'AMMBid': + validateAMMBid(tx) + break + case 'AMMDeposit': validateAMMDeposit(tx) break diff --git a/packages/xrpl/test/models/AMMBid.ts b/packages/xrpl/test/models/AMMBid.ts new file mode 100644 index 0000000000..ece8b69298 --- /dev/null +++ b/packages/xrpl/test/models/AMMBid.ts @@ -0,0 +1,98 @@ +import { assert } from 'chai' +import { validate, ValidationError } from 'xrpl-local' + +/** + * AMMBid Transaction Verification Testing. + * + * Providing runtime verification testing for each specific transaction type. + */ +describe('AMMBid', function () { + let bid + + beforeEach(function () { + bid = { + TransactionType: 'AMMBid', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', + MinSlotPrice: '5', + MaxSlotPrice: '10', + AuthAccounts: [ + { + AuthAccount: { + Account: 'rNZdsTBP5tH1M6GHC6bTreHAp6ouP8iZSh', + }, + }, + { + AuthAccount: { + Account: 'rfpFv97Dwu89FTyUwPjtpZBbuZxTqqgTmH', + }, + }, + { + AuthAccount: { + Account: 'rzzYHPGb8Pa64oqxCzmuffm122bitq3Vb', + }, + }, + { + AuthAccount: { + Account: 'rhwxHxaHok86fe4LykBom1jSJ3RYQJs1h4', + }, + }, + ], + Sequence: 1337, + } as any + }) + + it(`verifies valid AMMBid`, function () { + assert.doesNotThrow(() => validate(bid)) + }) + + it(`throws w/ missing field AMMID`, function () { + delete bid.AMMID + assert.throws( + () => validate(bid), + ValidationError, + 'AMMBid: missing field AMMID', + ) + }) + + it(`throws w/ AMMID must be a string`, function () { + bid.AMMID = 1234 + assert.throws( + () => validate(bid), + ValidationError, + 'AMMBid: AMMID must be a string', + ) + }) + + it(`throws w/ MinSlotPrice must be an Amount`, function () { + bid.MinSlotPrice = 5 + assert.throws( + () => validate(bid), + ValidationError, + 'AMMBid: MinSlotPrice must be an Amount', + ) + }) + + it(`throws w/ MaxSlotPrice must be an Amount`, function () { + bid.MaxSlotPrice = 10 + assert.throws( + () => validate(bid), + ValidationError, + 'AMMBid: MaxSlotPrice must be an Amount', + ) + }) + + it(`throws w/ AuthAccounts length must not be greater than 4`, function () { + bid.AuthAccounts.push({ + AuthAccount: { + Account: 'r3X6noRsvaLapAKCG78zAtWcbhB3sggS1s', + }, + }) + + assert.throws( + () => validate(bid), + ValidationError, + 'AMMBid: AuthAccounts length must not be greater than 4', + ) + }) +}) From 4b18f06dbb7d9def8c75f156025f3790d89200d5 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Sat, 20 Aug 2022 09:43:33 -0400 Subject: [PATCH 14/93] add AuthAccount interface to AMMBid --- packages/xrpl/src/models/transactions/AMMBid.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/transactions/AMMBid.ts b/packages/xrpl/src/models/transactions/AMMBid.ts index d88fd6c085..94a26569f9 100644 --- a/packages/xrpl/src/models/transactions/AMMBid.ts +++ b/packages/xrpl/src/models/transactions/AMMBid.ts @@ -5,6 +5,12 @@ import { BaseTransaction, isAmount, validateBaseTransaction } from './common' const MAX_AUTH_ACCOUNTS = 4 +interface AuthAccount { + AuthAccount: { + Account: string + } +} + /** * AMMBid is used for submitting a vote for the trading fee of an AMM Instance. * @@ -38,7 +44,7 @@ export interface AMMBid extends BaseTransaction { * at the discounted fee against the AMM instance. * A maximum of four accounts can be provided. */ - AuthAccounts?: string[] + AuthAccounts?: AuthAccount[] } /** From 835dc6776717c6b92b6abe6727cd750e7d88532b Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Sat, 20 Aug 2022 10:54:14 -0400 Subject: [PATCH 15/93] refactor tests --- packages/xrpl/test/models/AMMDeposit.ts | 114 +++++------------ .../xrpl/test/models/AMMInstanceCreate.ts | 115 ++++-------------- packages/xrpl/test/models/AMMVote.ts | 63 +++------- packages/xrpl/test/models/AMMWithdraw.ts | 114 +++++------------ 4 files changed, 98 insertions(+), 308 deletions(-) diff --git a/packages/xrpl/test/models/AMMDeposit.ts b/packages/xrpl/test/models/AMMDeposit.ts index 535ca216f7..ea81e8cf60 100644 --- a/packages/xrpl/test/models/AMMDeposit.ts +++ b/packages/xrpl/test/models/AMMDeposit.ts @@ -7,137 +7,83 @@ import { validate, ValidationError } from 'xrpl-local' * Providing runtime verification testing for each specific transaction type. */ describe('AMMDeposit', function () { - it(`verifies valid AMMDeposit with LPToken`, function () { - const validTx = { + const LPToken = { + currency: 'B3813FCAB4EE68B3D0D735D6849465A9113EE048', + issuer: 'rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg', + value: '1000', + } + let deposit + + beforeEach(function () { + deposit = { TransactionType: 'AMMDeposit', Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', - LPToken: { - currency: 'B3813FCAB4EE68B3D0D735D6849465A9113EE048', - issuer: 'rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg', - value: '1000', - }, Sequence: 1337, } as any + }) - assert.doesNotThrow(() => validate(validTx)) + it(`verifies valid AMMDeposit with LPToken`, function () { + deposit.LPToken = LPToken + assert.doesNotThrow(() => validate(deposit)) }) it(`verifies valid AMMDeposit with Asset1In`, function () { - const validTx = { - TransactionType: 'AMMDeposit', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', - Asset1In: '1000', - Sequence: 1337, - } as any - - assert.doesNotThrow(() => validate(validTx)) + deposit.Asset1In = '1000' + assert.doesNotThrow(() => validate(deposit)) }) it(`verifies valid AMMDeposit with Asset1In and LPToken`, function () { - const validTx = { - TransactionType: 'AMMDeposit', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', - Asset1In: '1000', - LPToken: { - currency: 'B3813FCAB4EE68B3D0D735D6849465A9113EE048', - issuer: 'rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg', - value: '1000', - }, - Sequence: 1337, - } as any - - assert.doesNotThrow(() => validate(validTx)) + deposit.Asset1In = '1000' + deposit.LPToken = LPToken + assert.doesNotThrow(() => validate(deposit)) }) it(`verifies valid AMMDeposit with Asset1In and EPrice`, function () { - const validTx = { - TransactionType: 'AMMDeposit', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', - Asset1In: '1000', - EPrice: '25', - Sequence: 1337, - } as any - - assert.doesNotThrow(() => validate(validTx)) + deposit.Asset1In = '1000' + deposit.EPrice = '25' + assert.doesNotThrow(() => validate(deposit)) }) it(`throws w/ missing AMMID`, function () { - const invalid = { - TransactionType: 'AMMDeposit', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - Asset1In: '1000', - Sequence: 1337, - } as any - + delete deposit.AMMID assert.throws( - () => validate(invalid), + () => validate(deposit), ValidationError, 'AMMDeposit: missing field AMMID', ) }) it(`throws w/ AMMID must be a string`, function () { - const invalid = { - TransactionType: 'AMMDeposit', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: 1234, - Asset1In: '1000', - Sequence: 1337, - } as any - + deposit.AMMID = 1234 assert.throws( - () => validate(invalid), + () => validate(deposit), ValidationError, 'AMMDeposit: AMMID must be a string', ) }) it(`throws w/ must set either or both LPToken with Asset1In`, function () { - const invalid = { - TransactionType: 'AMMDeposit', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', - Sequence: 1337, - } as any - assert.throws( - () => validate(invalid), + () => validate(deposit), ValidationError, 'AMMDeposit: must set either or both LPToken with Asset1In', ) }) it(`throws w/ must set Asset1In with Asset2In`, function () { - const invalid = { - TransactionType: 'AMMDeposit', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', - Asset2In: '500', - Sequence: 1337, - } as any - + deposit.Asset2In = '500' assert.throws( - () => validate(invalid), + () => validate(deposit), ValidationError, 'AMMDeposit: must set Asset1In with Asset2In', ) }) it(`throws w/ must set Asset1In with EPrice`, function () { - const invalid = { - TransactionType: 'AMMDeposit', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', - EPrice: '25', - Sequence: 1337, - } as any - + deposit.EPrice = '25' assert.throws( - () => validate(invalid), + () => validate(deposit), ValidationError, 'AMMDeposit: must set Asset1In with EPrice', ) diff --git a/packages/xrpl/test/models/AMMInstanceCreate.ts b/packages/xrpl/test/models/AMMInstanceCreate.ts index 6ed798becc..04d2a6778c 100644 --- a/packages/xrpl/test/models/AMMInstanceCreate.ts +++ b/packages/xrpl/test/models/AMMInstanceCreate.ts @@ -7,8 +7,10 @@ import { validate, ValidationError } from 'xrpl-local' * Providing runtime verification testing for each specific transaction type. */ describe('AMMInstanceCreate', function () { - it(`verifies valid AMMInstanceCreate`, function () { - const validTx = { + let instanceCreate + + beforeEach(function () { + instanceCreate = { TransactionType: 'AMMInstanceCreate', Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', Asset1: '1000', @@ -20,145 +22,70 @@ describe('AMMInstanceCreate', function () { TradingFee: 12, Sequence: 1337, } as any + }) - assert.doesNotThrow(() => validate(validTx)) + it(`verifies valid AMMInstanceCreate`, function () { + assert.doesNotThrow(() => validate(instanceCreate)) }) it(`throws w/ missing Asset1`, function () { - const invalid = { - TransactionType: 'AMMInstanceCreate', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - Asset2: { - currency: 'USD', - issuer: 'rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9', - value: '1000', - }, - TradingFee: 12, - Sequence: 1337, - } as any - + delete instanceCreate.Asset1 assert.throws( - () => validate(invalid), + () => validate(instanceCreate), ValidationError, 'AMMInstanceCreate: missing field Asset1', ) }) it(`throws w/ Asset1 must be an Amount`, function () { - const invalidAsset1 = 1000 - const invalidTx = { - TransactionType: 'AMMInstanceCreate', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - Asset1: invalidAsset1, - Asset2: { - currency: 'USD', - issuer: 'rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9', - value: '1000', - }, - TradingFee: 12, - Sequence: 1337, - } as any - + instanceCreate.Asset1 = 1000 assert.throws( - () => validate(invalidTx), + () => validate(instanceCreate), ValidationError, 'AMMInstanceCreate: Asset1 must be an Amount', ) }) it(`throws w/ missing Asset2`, function () { - const invalid = { - TransactionType: 'AMMInstanceCreate', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - Asset1: '1000', - TradingFee: 12, - Sequence: 1337, - } as any - + delete instanceCreate.Asset2 assert.throws( - () => validate(invalid), + () => validate(instanceCreate), ValidationError, 'AMMInstanceCreate: missing field Asset2', ) }) it(`throws w/ Asset2 must be an Amount`, function () { - const invalidAsset2 = 1000 - const invalidTx = { - TransactionType: 'AMMInstanceCreate', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - Asset1: '1000', - Asset2: invalidAsset2, - TradingFee: 12, - Sequence: 1337, - } as any - + instanceCreate.Asset2 = 1000 assert.throws( - () => validate(invalidTx), + () => validate(instanceCreate), ValidationError, 'AMMInstanceCreate: Asset2 must be an Amount', ) }) it(`throws w/ missing TradingFee`, function () { - const invalid = { - TransactionType: 'AMMInstanceCreate', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - Asset1: '1000', - Asset2: { - currency: 'USD', - issuer: 'rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9', - value: '1000', - }, - Sequence: 1337, - } as any - + delete instanceCreate.TradingFee assert.throws( - () => validate(invalid), + () => validate(instanceCreate), ValidationError, 'AMMInstanceCreate: missing field TradingFee', ) }) it(`throws w/ TradingFee must be a number`, function () { - const invalidTradingFee = '12' - const invalidTx = { - TransactionType: 'AMMInstanceCreate', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - Asset1: '1000', - Asset2: { - currency: 'USD', - issuer: 'rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9', - value: '1000', - }, - TradingFee: invalidTradingFee, - Sequence: 1337, - } as any - + instanceCreate.TradingFee = '12' assert.throws( - () => validate(invalidTx), + () => validate(instanceCreate), ValidationError, 'AMMInstanceCreate: TradingFee must be a number', ) }) it(`throws w/ TradingFee must not be greater than 65000`, function () { - const invalidTradingFee = 65001 - const invalidTx = { - TransactionType: 'AMMInstanceCreate', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - Asset1: '1000', - Asset2: { - currency: 'USD', - issuer: 'rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9', - value: '1000', - }, - TradingFee: invalidTradingFee, - Sequence: 1337, - } as any - + instanceCreate.TradingFee = 65001 assert.throws( - () => validate(invalidTx), + () => validate(instanceCreate), ValidationError, `AMMInstanceCreate: TradingFee must not be greater than 65000`, ) diff --git a/packages/xrpl/test/models/AMMVote.ts b/packages/xrpl/test/models/AMMVote.ts index 6c0e03fdc9..9e7d6c0928 100644 --- a/packages/xrpl/test/models/AMMVote.ts +++ b/packages/xrpl/test/models/AMMVote.ts @@ -7,91 +7,62 @@ import { validate, ValidationError } from 'xrpl-local' * Providing runtime verification testing for each specific transaction type. */ describe('AMMVote', function () { - it(`verifies valid AMMVote`, function () { - const validTx = { + let vote + + beforeEach(function () { + vote = { TransactionType: 'AMMVote', Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', FeeVal: 25, Sequence: 1337, } as any + }) - assert.doesNotThrow(() => validate(validTx)) + it(`verifies valid AMMVote`, function () { + assert.doesNotThrow(() => validate(vote)) }) it(`throws w/ missing field AMMID`, function () { - const invalid = { - TransactionType: 'AMMVote', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - FeeVal: 25, - Sequence: 1337, - } as any - + delete vote.AMMID assert.throws( - () => validate(invalid), + () => validate(vote), ValidationError, 'AMMVote: missing field AMMID', ) }) it(`throws w/ AMMID must be a string`, function () { - const invalid = { - TransactionType: 'AMMVote', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: 1234, - FeeVal: 25, - Sequence: 1337, - } as any - + vote.AMMID = 1234 assert.throws( - () => validate(invalid), + () => validate(vote), ValidationError, 'AMMVote: AMMID must be a string', ) }) it(`throws w/ missing field FeeVal`, function () { - const invalid = { - TransactionType: 'AMMVote', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', - Sequence: 1337, - } as any - + delete vote.FeeVal assert.throws( - () => validate(invalid), + () => validate(vote), ValidationError, 'AMMVote: missing field FeeVal', ) }) it(`throws w/ FeeVal must be a number`, function () { - const invalid = { - TransactionType: 'AMMVote', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', - FeeVal: '25', - Sequence: 1337, - } as any - + vote.FeeVal = '25' assert.throws( - () => validate(invalid), + () => validate(vote), ValidationError, 'AMMVote: FeeVal must be a number', ) }) it(`throws w/ FeeVal must not be greater than 65000`, function () { - const invalid = { - TransactionType: 'AMMVote', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', - FeeVal: 65001, - Sequence: 1337, - } as any - + vote.FeeVal = 65001 assert.throws( - () => validate(invalid), + () => validate(vote), ValidationError, 'AMMVote: FeeVal must not be greater than 65000', ) diff --git a/packages/xrpl/test/models/AMMWithdraw.ts b/packages/xrpl/test/models/AMMWithdraw.ts index f12d819e14..1f5e6c20ea 100644 --- a/packages/xrpl/test/models/AMMWithdraw.ts +++ b/packages/xrpl/test/models/AMMWithdraw.ts @@ -7,137 +7,83 @@ import { validate, ValidationError } from 'xrpl-local' * Providing runtime verification testing for each specific transaction type. */ describe('AMMWithdraw', function () { - it(`verifies valid AMMWithdraw with LPToken`, function () { - const validTx = { + const LPToken = { + currency: 'B3813FCAB4EE68B3D0D735D6849465A9113EE048', + issuer: 'rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg', + value: '1000', + } + let withdraw + + beforeEach(function () { + withdraw = { TransactionType: 'AMMWithdraw', Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', - LPToken: { - currency: 'B3813FCAB4EE68B3D0D735D6849465A9113EE048', - issuer: 'rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg', - value: '1000', - }, Sequence: 1337, } as any + }) - assert.doesNotThrow(() => validate(validTx)) + it(`verifies valid AMMWithdraw with LPToken`, function () { + withdraw.LPToken = LPToken + assert.doesNotThrow(() => validate(withdraw)) }) it(`verifies valid AMMWithdraw with Asset1Out`, function () { - const validTx = { - TransactionType: 'AMMWithdraw', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', - Asset1Out: '1000', - Sequence: 1337, - } as any - - assert.doesNotThrow(() => validate(validTx)) + withdraw.Asset1Out = '1000' + assert.doesNotThrow(() => validate(withdraw)) }) it(`verifies valid AMMWithdraw with Asset1Out and LPToken`, function () { - const validTx = { - TransactionType: 'AMMWithdraw', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', - Asset1Out: '1000', - LPToken: { - currency: 'B3813FCAB4EE68B3D0D735D6849465A9113EE048', - issuer: 'rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg', - value: '1000', - }, - Sequence: 1337, - } as any - - assert.doesNotThrow(() => validate(validTx)) + withdraw.Asset1Out = '1000' + withdraw.LPToken = LPToken + assert.doesNotThrow(() => validate(withdraw)) }) it(`verifies valid AMMWithdraw with Asset1Out and EPrice`, function () { - const validTx = { - TransactionType: 'AMMWithdraw', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', - Asset1Out: '1000', - EPrice: '25', - Sequence: 1337, - } as any - - assert.doesNotThrow(() => validate(validTx)) + withdraw.Asset1Out = '1000' + withdraw.EPrice = '25' + assert.doesNotThrow(() => validate(withdraw)) }) it(`throws w/ missing AMMID`, function () { - const invalid = { - TransactionType: 'AMMWithdraw', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - Asset1Out: '1000', - Sequence: 1337, - } as any - + delete withdraw.AMMID assert.throws( - () => validate(invalid), + () => validate(withdraw), ValidationError, 'AMMWithdraw: missing field AMMID', ) }) it(`throws w/ AMMID must be a string`, function () { - const invalid = { - TransactionType: 'AMMWithdraw', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: 1234, - Asset1Out: '1000', - Sequence: 1337, - } as any - + withdraw.AMMID = 1234 assert.throws( - () => validate(invalid), + () => validate(withdraw), ValidationError, 'AMMWithdraw: AMMID must be a string', ) }) it(`throws w/ must set either or both LPToken with Asset1Out`, function () { - const invalid = { - TransactionType: 'AMMWithdraw', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', - Sequence: 1337, - } as any - assert.throws( - () => validate(invalid), + () => validate(withdraw), ValidationError, 'AMMWithdraw: must set either or both LPToken with Asset1Out', ) }) it(`throws w/ must set Asset1Out with Asset2Out`, function () { - const invalid = { - TransactionType: 'AMMWithdraw', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', - Asset2Out: '500', - Sequence: 1337, - } as any - + withdraw.Asset2Out = '500' assert.throws( - () => validate(invalid), + () => validate(withdraw), ValidationError, 'AMMWithdraw: must set Asset1Out with Asset2Out', ) }) it(`throws w/ must set Asset1Out with EPrice`, function () { - const invalid = { - TransactionType: 'AMMWithdraw', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', - EPrice: '25', - Sequence: 1337, - } as any - + withdraw.EPrice = '25' assert.throws( - () => validate(invalid), + () => validate(withdraw), ValidationError, 'AMMWithdraw: must set Asset1Out with EPrice', ) From c95f8afc21f65734e026c292b74adbce0902a333 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Sun, 28 Aug 2022 14:04:13 -0400 Subject: [PATCH 16/93] add AMMID to AMMInfoResponse --- packages/xrpl/src/models/methods/ammInfo.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index afb58e0a23..373834033d 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -39,6 +39,11 @@ export interface AMMInfoResponse extends BaseResponse { */ AMMAccount: string + /** + * A hash that uniquely identifies the AMM instance. This field is required. + */ + AMMID: string + /** * Specifies one of the pool assets (XRP or token) of the AMM instance. */ From b8e4f2405a680673bbd866b8c9a286a9b772d4aa Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 30 Aug 2022 10:59:03 -0400 Subject: [PATCH 17/93] update amm_info docstrings --- packages/xrpl/src/models/methods/ammInfo.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index 373834033d..93755a2d8c 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -18,11 +18,13 @@ export interface AMMInfoRequest extends BaseRequest { /** * Specifies one of the pool assets (XRP or token) of the AMM instance. + * Both asset1 and asset2 must be defined to specify an AMM instance. */ asset1?: Amount /** * Specifies the other pool asset of the AMM instance. + * Both asset1 and asset2 must be defined to specify an AMM instance. */ asset2?: Amount } @@ -40,7 +42,7 @@ export interface AMMInfoResponse extends BaseResponse { AMMAccount: string /** - * A hash that uniquely identifies the AMM instance. This field is required. + * A hash that uniquely identifies the AMM instance. */ AMMID: string From ed7760c55525aaf462dde1c0012b0096792a668d Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 30 Aug 2022 16:29:49 -0400 Subject: [PATCH 18/93] fix EPrice type to be Amount --- packages/xrpl/src/models/transactions/AMMDeposit.ts | 2 +- packages/xrpl/src/models/transactions/AMMWithdraw.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/xrpl/src/models/transactions/AMMDeposit.ts b/packages/xrpl/src/models/transactions/AMMDeposit.ts index d01a5b3b8e..d74620ad5d 100644 --- a/packages/xrpl/src/models/transactions/AMMDeposit.ts +++ b/packages/xrpl/src/models/transactions/AMMDeposit.ts @@ -49,7 +49,7 @@ export interface AMMDeposit extends BaseTransaction { /** * Specifies the maximum effective-price that LPToken can be traded out. */ - EPrice?: number + EPrice?: Amount } /** diff --git a/packages/xrpl/src/models/transactions/AMMWithdraw.ts b/packages/xrpl/src/models/transactions/AMMWithdraw.ts index 00aa78df55..2556e0e34e 100644 --- a/packages/xrpl/src/models/transactions/AMMWithdraw.ts +++ b/packages/xrpl/src/models/transactions/AMMWithdraw.ts @@ -51,7 +51,7 @@ export interface AMMWithdraw extends BaseTransaction { * Specifies the effective-price of the token out after successful execution of * the transaction. */ - EPrice?: number + EPrice?: Amount } /** From 0de755bb0bf7df2bf4e54a9108fe634b84d51555 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 30 Aug 2022 16:49:48 -0400 Subject: [PATCH 19/93] update EPrice validation error message and add missing tests --- .../src/models/transactions/AMMDeposit.ts | 2 +- .../src/models/transactions/AMMWithdraw.ts | 2 +- packages/xrpl/test/models/AMMDeposit.ts | 38 +++++++++++++++++++ packages/xrpl/test/models/AMMWithdraw.ts | 38 +++++++++++++++++++ 4 files changed, 78 insertions(+), 2 deletions(-) diff --git a/packages/xrpl/src/models/transactions/AMMDeposit.ts b/packages/xrpl/src/models/transactions/AMMDeposit.ts index d74620ad5d..086381e022 100644 --- a/packages/xrpl/src/models/transactions/AMMDeposit.ts +++ b/packages/xrpl/src/models/transactions/AMMDeposit.ts @@ -94,6 +94,6 @@ export function validateAMMDeposit(tx: Record): void { } if (tx.EPrice != null && typeof tx.EPrice !== 'string') { - throw new ValidationError('AMMDeposit: EPrice must be a string') + throw new ValidationError('AMMDeposit: EPrice must be an Amount') } } diff --git a/packages/xrpl/src/models/transactions/AMMWithdraw.ts b/packages/xrpl/src/models/transactions/AMMWithdraw.ts index 2556e0e34e..1c777f78d2 100644 --- a/packages/xrpl/src/models/transactions/AMMWithdraw.ts +++ b/packages/xrpl/src/models/transactions/AMMWithdraw.ts @@ -96,6 +96,6 @@ export function validateAMMWithdraw(tx: Record): void { } if (tx.EPrice != null && typeof tx.EPrice !== 'string') { - throw new ValidationError('AMMWithdraw: EPrice must be a string') + throw new ValidationError('AMMWithdraw: EPrice must be an Amount') } } diff --git a/packages/xrpl/test/models/AMMDeposit.ts b/packages/xrpl/test/models/AMMDeposit.ts index ea81e8cf60..e926646ada 100644 --- a/packages/xrpl/test/models/AMMDeposit.ts +++ b/packages/xrpl/test/models/AMMDeposit.ts @@ -88,4 +88,42 @@ describe('AMMDeposit', function () { 'AMMDeposit: must set Asset1In with EPrice', ) }) + + it(`throws w/ LPToken must be an IssuedCurrencyAmount`, function () { + deposit.LPToken = 1234 + assert.throws( + () => validate(deposit), + ValidationError, + 'AMMDeposit: LPToken must be an IssuedCurrencyAmount', + ) + }) + + it(`throws w/ Asset1In must be an Amount`, function () { + deposit.Asset1In = 1234 + assert.throws( + () => validate(deposit), + ValidationError, + 'AMMDeposit: Asset1In must be an Amount', + ) + }) + + it(`throws w/ Asset2In must be an Amount`, function () { + deposit.Asset1In = '1000' + deposit.Asset2In = 1234 + assert.throws( + () => validate(deposit), + ValidationError, + 'AMMDeposit: Asset2In must be an Amount', + ) + }) + + it(`throws w/ EPrice must be an Amount`, function () { + deposit.Asset1In = '1000' + deposit.EPrice = 1234 + assert.throws( + () => validate(deposit), + ValidationError, + 'AMMDeposit: EPrice must be an Amount', + ) + }) }) diff --git a/packages/xrpl/test/models/AMMWithdraw.ts b/packages/xrpl/test/models/AMMWithdraw.ts index 1f5e6c20ea..5f8eca420d 100644 --- a/packages/xrpl/test/models/AMMWithdraw.ts +++ b/packages/xrpl/test/models/AMMWithdraw.ts @@ -88,4 +88,42 @@ describe('AMMWithdraw', function () { 'AMMWithdraw: must set Asset1Out with EPrice', ) }) + + it(`throws w/ LPToken must be an IssuedCurrencyAmount`, function () { + withdraw.LPToken = 1234 + assert.throws( + () => validate(withdraw), + ValidationError, + 'AMMWithdraw: LPToken must be an IssuedCurrencyAmount', + ) + }) + + it(`throws w/ Asset1Out must be an Amount`, function () { + withdraw.Asset1Out = 1234 + assert.throws( + () => validate(withdraw), + ValidationError, + 'AMMWithdraw: Asset1Out must be an Amount', + ) + }) + + it(`throws w/ Asset2Out must be an Amount`, function () { + withdraw.Asset1Out = '1000' + withdraw.Asset2Out = 1234 + assert.throws( + () => validate(withdraw), + ValidationError, + 'AMMWithdraw: Asset2Out must be an Amount', + ) + }) + + it(`throws w/ EPrice must be an Amount`, function () { + withdraw.Asset1Out = '1000' + withdraw.EPrice = 1234 + assert.throws( + () => validate(withdraw), + ValidationError, + 'AMMWithdraw: EPrice must be an Amount', + ) + }) }) From e13b27e43fccab023326d40b939b7fb4fb93d3d5 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 30 Aug 2022 17:45:22 -0400 Subject: [PATCH 20/93] update definitions to fix AMM in LEDGER_ENTRY_TYPES --- packages/ripple-binary-codec/src/enums/definitions.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ripple-binary-codec/src/enums/definitions.json b/packages/ripple-binary-codec/src/enums/definitions.json index ce449a5174..cc0fc1d04a 100644 --- a/packages/ripple-binary-codec/src/enums/definitions.json +++ b/packages/ripple-binary-codec/src/enums/definitions.json @@ -44,7 +44,7 @@ "NegativeUNL": 78, "NFTokenPage": 80, "NFTokenOffer": 55, - "Amm": 121, + "AMM": 121, "Any": -3, "Child": -2, "Nickname": 110, From 2796c2aeeff92538287148ffc942fbfca31c52bc Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 30 Aug 2022 18:07:22 -0400 Subject: [PATCH 21/93] add missing test case Asset1In and Asset2In valid --- packages/xrpl/test/models/AMMDeposit.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/xrpl/test/models/AMMDeposit.ts b/packages/xrpl/test/models/AMMDeposit.ts index e926646ada..dbe4035a4b 100644 --- a/packages/xrpl/test/models/AMMDeposit.ts +++ b/packages/xrpl/test/models/AMMDeposit.ts @@ -33,6 +33,12 @@ describe('AMMDeposit', function () { assert.doesNotThrow(() => validate(deposit)) }) + it(`verifies valid AMMDeposit with Asset1In adn Asset2In`, function () { + deposit.Asset1In = '1000' + deposit.Asset2In = '1000' + assert.doesNotThrow(() => validate(deposit)) + }) + it(`verifies valid AMMDeposit with Asset1In and LPToken`, function () { deposit.Asset1In = '1000' deposit.LPToken = LPToken From 6150d33a61d6c220dbb1316af3e62a4257a46bd8 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 30 Aug 2022 18:10:40 -0400 Subject: [PATCH 22/93] add missing test case Asset1Out and Asset2Out valid --- packages/xrpl/test/models/AMMDeposit.ts | 2 +- packages/xrpl/test/models/AMMWithdraw.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/xrpl/test/models/AMMDeposit.ts b/packages/xrpl/test/models/AMMDeposit.ts index dbe4035a4b..d10eb64cf7 100644 --- a/packages/xrpl/test/models/AMMDeposit.ts +++ b/packages/xrpl/test/models/AMMDeposit.ts @@ -33,7 +33,7 @@ describe('AMMDeposit', function () { assert.doesNotThrow(() => validate(deposit)) }) - it(`verifies valid AMMDeposit with Asset1In adn Asset2In`, function () { + it(`verifies valid AMMDeposit with Asset1In and Asset2In`, function () { deposit.Asset1In = '1000' deposit.Asset2In = '1000' assert.doesNotThrow(() => validate(deposit)) diff --git a/packages/xrpl/test/models/AMMWithdraw.ts b/packages/xrpl/test/models/AMMWithdraw.ts index 5f8eca420d..a2fc2d9fa5 100644 --- a/packages/xrpl/test/models/AMMWithdraw.ts +++ b/packages/xrpl/test/models/AMMWithdraw.ts @@ -33,6 +33,12 @@ describe('AMMWithdraw', function () { assert.doesNotThrow(() => validate(withdraw)) }) + it(`verifies valid AMMWithdraw with Asset1Out and Asset2Out`, function () { + withdraw.Asset1Out = '1000' + withdraw.Asset2Out = '1000' + assert.doesNotThrow(() => validate(withdraw)) + }) + it(`verifies valid AMMWithdraw with Asset1Out and LPToken`, function () { withdraw.Asset1Out = '1000' withdraw.LPToken = LPToken From 8ef2483e151fb648445a8a7ccd6f1da693c42ff8 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 30 Aug 2022 18:45:34 -0400 Subject: [PATCH 23/93] add negative FeeVal check --- packages/xrpl/src/models/transactions/AMMVote.ts | 4 ++-- packages/xrpl/test/models/AMMVote.ts | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/xrpl/src/models/transactions/AMMVote.ts b/packages/xrpl/src/models/transactions/AMMVote.ts index 621ce23223..270a4141aa 100644 --- a/packages/xrpl/src/models/transactions/AMMVote.ts +++ b/packages/xrpl/src/models/transactions/AMMVote.ts @@ -51,9 +51,9 @@ export function validateAMMVote(tx: Record): void { throw new ValidationError('AMMVote: FeeVal must be a number') } - if (tx.FeeVal > AMM_MAX_TRADING_FEE) { + if (tx.FeeVal < 0 || tx.FeeVal > AMM_MAX_TRADING_FEE) { throw new ValidationError( - `AMMVote: FeeVal must not be greater than ${AMM_MAX_TRADING_FEE}`, + `AMMVote: FeeVal must be between 0 and ${AMM_MAX_TRADING_FEE}`, ) } } diff --git a/packages/xrpl/test/models/AMMVote.ts b/packages/xrpl/test/models/AMMVote.ts index 9e7d6c0928..b7ae2852df 100644 --- a/packages/xrpl/test/models/AMMVote.ts +++ b/packages/xrpl/test/models/AMMVote.ts @@ -59,12 +59,21 @@ describe('AMMVote', function () { ) }) - it(`throws w/ FeeVal must not be greater than 65000`, function () { + it(`throws when FeeVal is greater than AMM_MAX_TRADING_FEE`, function () { vote.FeeVal = 65001 assert.throws( () => validate(vote), ValidationError, - 'AMMVote: FeeVal must not be greater than 65000', + 'AMMVote: FeeVal must be between 0 and 65000', + ) + }) + + it(`throws when FeeVal is a negative number`, function () { + vote.FeeVal = -1 + assert.throws( + () => validate(vote), + ValidationError, + 'AMMVote: FeeVal must be between 0 and 65000', ) }) }) From e9778ebcdbbc3a67aa636cf65df74c28983bbb52 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 30 Aug 2022 18:48:54 -0400 Subject: [PATCH 24/93] update HISTORY.md to specify XLS-30 --- packages/xrpl/HISTORY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index 1ee6990e7f..52d9b44c7e 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -9,7 +9,7 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr * Made unexpected errors in `submitAndWait` more verbose to make them easier to debug. ### Added -* Support for Automated Market Maker (AMM). +* Support for Automated Market Maker (AMM) transactions and requests as defined in XLS-30. ## 2.3.1 (2022-06-27) ### Fixed From 6a06412b2d9f08c1909054b1d80c93405f22b267 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 30 Aug 2022 19:01:08 -0400 Subject: [PATCH 25/93] update wording on AMMDeposit & AMMWithdraw validation errors --- packages/xrpl/src/models/transactions/AMMDeposit.ts | 2 +- packages/xrpl/src/models/transactions/AMMWithdraw.ts | 2 +- packages/xrpl/test/models/AMMDeposit.ts | 4 ++-- packages/xrpl/test/models/AMMWithdraw.ts | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/xrpl/src/models/transactions/AMMDeposit.ts b/packages/xrpl/src/models/transactions/AMMDeposit.ts index 086381e022..b28ca0ae34 100644 --- a/packages/xrpl/src/models/transactions/AMMDeposit.ts +++ b/packages/xrpl/src/models/transactions/AMMDeposit.ts @@ -75,7 +75,7 @@ export function validateAMMDeposit(tx: Record): void { throw new ValidationError('AMMDeposit: must set Asset1In with EPrice') } else if (tx.LPToken == null && tx.Asset1In == null) { throw new ValidationError( - 'AMMDeposit: must set either or both LPToken with Asset1In', + 'AMMDeposit: must set at least LPToken or Asset1In', ) } diff --git a/packages/xrpl/src/models/transactions/AMMWithdraw.ts b/packages/xrpl/src/models/transactions/AMMWithdraw.ts index 1c777f78d2..9e222e04b0 100644 --- a/packages/xrpl/src/models/transactions/AMMWithdraw.ts +++ b/packages/xrpl/src/models/transactions/AMMWithdraw.ts @@ -77,7 +77,7 @@ export function validateAMMWithdraw(tx: Record): void { throw new ValidationError('AMMWithdraw: must set Asset1Out with EPrice') } else if (tx.LPToken == null && tx.Asset1Out == null) { throw new ValidationError( - 'AMMWithdraw: must set either or both LPToken with Asset1Out', + 'AMMWithdraw: must set at least LPToken or Asset1Out', ) } diff --git a/packages/xrpl/test/models/AMMDeposit.ts b/packages/xrpl/test/models/AMMDeposit.ts index d10eb64cf7..1d54ba25c3 100644 --- a/packages/xrpl/test/models/AMMDeposit.ts +++ b/packages/xrpl/test/models/AMMDeposit.ts @@ -69,11 +69,11 @@ describe('AMMDeposit', function () { ) }) - it(`throws w/ must set either or both LPToken with Asset1In`, function () { + it(`throws w/ must set at least LPToken or Asset1In`, function () { assert.throws( () => validate(deposit), ValidationError, - 'AMMDeposit: must set either or both LPToken with Asset1In', + 'AMMDeposit: must set at least LPToken or Asset1In', ) }) diff --git a/packages/xrpl/test/models/AMMWithdraw.ts b/packages/xrpl/test/models/AMMWithdraw.ts index a2fc2d9fa5..68fdd3146c 100644 --- a/packages/xrpl/test/models/AMMWithdraw.ts +++ b/packages/xrpl/test/models/AMMWithdraw.ts @@ -69,11 +69,11 @@ describe('AMMWithdraw', function () { ) }) - it(`throws w/ must set either or both LPToken with Asset1Out`, function () { + it(`throws w/ must set at least LPToken or Asset1Out`, function () { assert.throws( () => validate(withdraw), ValidationError, - 'AMMWithdraw: must set either or both LPToken with Asset1Out', + 'AMMWithdraw: must set at least LPToken or Asset1Out', ) }) From 85b8a3930b3b4c3a506f41cf5bcc18413bc9e0db Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 30 Aug 2022 19:09:55 -0400 Subject: [PATCH 26/93] add negative TradingFee check --- .../src/models/transactions/AMMInstanceCreate.ts | 4 ++-- packages/xrpl/test/models/AMMInstanceCreate.ts | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/xrpl/src/models/transactions/AMMInstanceCreate.ts b/packages/xrpl/src/models/transactions/AMMInstanceCreate.ts index dec294e9af..23faa33056 100644 --- a/packages/xrpl/src/models/transactions/AMMInstanceCreate.ts +++ b/packages/xrpl/src/models/transactions/AMMInstanceCreate.ts @@ -68,9 +68,9 @@ export function validateAMMInstanceCreate(tx: Record): void { throw new ValidationError('AMMInstanceCreate: TradingFee must be a number') } - if (tx.TradingFee > AMM_MAX_TRADING_FEE) { + if (tx.TradingFee < 0 || tx.TradingFee > AMM_MAX_TRADING_FEE) { throw new ValidationError( - `AMMInstanceCreate: TradingFee must not be greater than ${AMM_MAX_TRADING_FEE}`, + `AMMInstanceCreate: TradingFee must be between 0 and ${AMM_MAX_TRADING_FEE}`, ) } } diff --git a/packages/xrpl/test/models/AMMInstanceCreate.ts b/packages/xrpl/test/models/AMMInstanceCreate.ts index 04d2a6778c..8e4f15973f 100644 --- a/packages/xrpl/test/models/AMMInstanceCreate.ts +++ b/packages/xrpl/test/models/AMMInstanceCreate.ts @@ -82,12 +82,21 @@ describe('AMMInstanceCreate', function () { ) }) - it(`throws w/ TradingFee must not be greater than 65000`, function () { + it(`throws when TradingFee is greater than 65000`, function () { instanceCreate.TradingFee = 65001 assert.throws( () => validate(instanceCreate), ValidationError, - `AMMInstanceCreate: TradingFee must not be greater than 65000`, + `AMMInstanceCreate: TradingFee must be between 0 and 65000`, + ) + }) + + it(`throws when TradingFee is a negative number`, function () { + instanceCreate.TradingFee = -1 + assert.throws( + () => validate(instanceCreate), + ValidationError, + `AMMInstanceCreate: TradingFee must be between 0 and 65000`, ) }) }) From a174d09489c532e2ade183f86b925e9ff1da3da0 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Thu, 1 Sep 2022 23:13:13 -0400 Subject: [PATCH 27/93] fix ammInfo response --- packages/xrpl/src/models/methods/ammInfo.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index 93755a2d8c..ea36096da0 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -41,11 +41,6 @@ export interface AMMInfoResponse extends BaseResponse { */ AMMAccount: string - /** - * A hash that uniquely identifies the AMM instance. - */ - AMMID: string - /** * Specifies one of the pool assets (XRP or token) of the AMM instance. */ From 533c8ab9ac9efa7299d5dd5159d9ee7ef44674d7 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Fri, 2 Sep 2022 00:05:48 -0400 Subject: [PATCH 28/93] add AMMID as optional param in ammInfo response --- packages/xrpl/src/models/methods/ammInfo.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index ea36096da0..0fb1e60d73 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -68,6 +68,11 @@ export interface AMMInfoResponse extends BaseResponse { */ TradingFee: number + /** + * A hash that uniquely identifies the AMM instance. + */ + AMMID?: string + /** * The ledger index of the current in-progress ledger, which was used when * retrieving this information. From c0e0c15fc17dc9c87a3ff8c72c5e9c1352ea8fca Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Fri, 2 Sep 2022 00:18:45 -0400 Subject: [PATCH 29/93] fix EPrice validation checks in AMMDeposit & AMMWithdraw --- packages/xrpl/src/models/transactions/AMMDeposit.ts | 2 +- packages/xrpl/src/models/transactions/AMMWithdraw.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/xrpl/src/models/transactions/AMMDeposit.ts b/packages/xrpl/src/models/transactions/AMMDeposit.ts index b28ca0ae34..0b62664a3c 100644 --- a/packages/xrpl/src/models/transactions/AMMDeposit.ts +++ b/packages/xrpl/src/models/transactions/AMMDeposit.ts @@ -93,7 +93,7 @@ export function validateAMMDeposit(tx: Record): void { throw new ValidationError('AMMDeposit: Asset2In must be an Amount') } - if (tx.EPrice != null && typeof tx.EPrice !== 'string') { + if (tx.EPrice != null && typeof !isAmount(tx.EPrice)) { throw new ValidationError('AMMDeposit: EPrice must be an Amount') } } diff --git a/packages/xrpl/src/models/transactions/AMMWithdraw.ts b/packages/xrpl/src/models/transactions/AMMWithdraw.ts index 9e222e04b0..8fdf059d87 100644 --- a/packages/xrpl/src/models/transactions/AMMWithdraw.ts +++ b/packages/xrpl/src/models/transactions/AMMWithdraw.ts @@ -95,7 +95,7 @@ export function validateAMMWithdraw(tx: Record): void { throw new ValidationError('AMMWithdraw: Asset2Out must be an Amount') } - if (tx.EPrice != null && typeof tx.EPrice !== 'string') { + if (tx.EPrice != null && typeof !isAmount(tx.EPrice)) { throw new ValidationError('AMMWithdraw: EPrice must be an Amount') } } From 56b70aa8453e4d9485dee782e9eecae8eff5aa4d Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Mon, 5 Sep 2022 14:35:19 -0400 Subject: [PATCH 30/93] add VoteSlots as optional param in AMMInfoResponse --- packages/xrpl/src/models/methods/ammInfo.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index 0fb1e60d73..529c2a86ad 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -29,6 +29,14 @@ export interface AMMInfoRequest extends BaseRequest { asset2?: Amount } +interface VoteEntry { + VoteEntry: { + Account: string + FeeVal: number + VoteWeight: number + } +} + /** * Response expected from an {@link AMMInfoRequest}. * @@ -73,6 +81,11 @@ export interface AMMInfoResponse extends BaseResponse { */ AMMID?: string + /** + * Keeps a track of up to eight active votes for the instance. + */ + VoteSlots?: VoteEntry[] + /** * The ledger index of the current in-progress ledger, which was used when * retrieving this information. From aed4353c6cb057ba052d455fa167f5281b99c9a2 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Mon, 5 Sep 2022 14:46:47 -0400 Subject: [PATCH 31/93] update VoteEntry interface --- packages/xrpl/src/models/methods/ammInfo.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index 529c2a86ad..8e70e3ad09 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -30,11 +30,8 @@ export interface AMMInfoRequest extends BaseRequest { } interface VoteEntry { - VoteEntry: { - Account: string - FeeVal: number - VoteWeight: number - } + FeeVal: number + VoteWeight: number } /** From 220d9fb1b0e913dbdd86c2152aa09a88f42d693d Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 13 Sep 2022 13:53:44 -0400 Subject: [PATCH 32/93] fix deposit and withdraw tests --- packages/xrpl/src/models/transactions/AMMDeposit.ts | 2 +- packages/xrpl/src/models/transactions/AMMWithdraw.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/xrpl/src/models/transactions/AMMDeposit.ts b/packages/xrpl/src/models/transactions/AMMDeposit.ts index 0b62664a3c..66616d0856 100644 --- a/packages/xrpl/src/models/transactions/AMMDeposit.ts +++ b/packages/xrpl/src/models/transactions/AMMDeposit.ts @@ -93,7 +93,7 @@ export function validateAMMDeposit(tx: Record): void { throw new ValidationError('AMMDeposit: Asset2In must be an Amount') } - if (tx.EPrice != null && typeof !isAmount(tx.EPrice)) { + if (tx.EPrice != null && !isAmount(tx.EPrice)) { throw new ValidationError('AMMDeposit: EPrice must be an Amount') } } diff --git a/packages/xrpl/src/models/transactions/AMMWithdraw.ts b/packages/xrpl/src/models/transactions/AMMWithdraw.ts index 8fdf059d87..ae997466fc 100644 --- a/packages/xrpl/src/models/transactions/AMMWithdraw.ts +++ b/packages/xrpl/src/models/transactions/AMMWithdraw.ts @@ -95,7 +95,7 @@ export function validateAMMWithdraw(tx: Record): void { throw new ValidationError('AMMWithdraw: Asset2Out must be an Amount') } - if (tx.EPrice != null && typeof !isAmount(tx.EPrice)) { + if (tx.EPrice != null && !isAmount(tx.EPrice)) { throw new ValidationError('AMMWithdraw: EPrice must be an Amount') } } From a80f159e013773074ce6c7eb1660d78f2c48acc2 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 14 Sep 2022 21:52:54 -0400 Subject: [PATCH 33/93] fix AMMBid ValidationError --- packages/xrpl/src/models/transactions/AMMBid.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/transactions/AMMBid.ts b/packages/xrpl/src/models/transactions/AMMBid.ts index 94a26569f9..e02c3cc288 100644 --- a/packages/xrpl/src/models/transactions/AMMBid.ts +++ b/packages/xrpl/src/models/transactions/AMMBid.ts @@ -74,7 +74,9 @@ export function validateAMMBid(tx: Record): void { if (tx.AuthAccounts != null) { if (!Array.isArray(tx.AuthAccounts)) { - throw new ValidationError(`AMMBid: AuthAccounts must be a string array`) + throw new ValidationError( + `AMMBid: AuthAccounts must be an AuthAccount array`, + ) } if (tx.AuthAccounts.length > MAX_AUTH_ACCOUNTS) { throw new ValidationError( From a2bce8f51371b9ad2ba1eacb3440d2d9a4c26555 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Thu, 15 Sep 2022 15:24:42 -0400 Subject: [PATCH 34/93] update definitions.json with different AuthAccounts number --- .../src/enums/definitions.json | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/ripple-binary-codec/src/enums/definitions.json b/packages/ripple-binary-codec/src/enums/definitions.json index cc0fc1d04a..2c3b655c9b 100644 --- a/packages/ripple-binary-codec/src/enums/definitions.json +++ b/packages/ripple-binary-codec/src/enums/definitions.json @@ -2402,16 +2402,6 @@ "type": "STArray" } ], - [ - "AuthAccounts", - { - "nth": 21, - "isVLEncoded": false, - "isSerialized": true, - "isSigningField": true, - "type": "STArray" - } - ], [ "Majorities", { @@ -2461,6 +2451,16 @@ "isSigningField": true, "type": "STArray" } + ], + [ + "AuthAccounts", + { + "nth": 26, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "STArray" + } ] ], "TRANSACTION_RESULTS": { From a76aeb223316d5723383c4261ea3c18a2ab30189 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Mon, 31 Oct 2022 13:55:50 -0400 Subject: [PATCH 35/93] Change amm_info asset parameters to Currency type --- packages/xrpl/src/models/methods/ammInfo.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index 8e70e3ad09..4d51ccddd8 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -1,4 +1,4 @@ -import { Amount, IssuedCurrencyAmount } from '../common' +import { Amount, Currency, IssuedCurrencyAmount } from '../common' import { BaseRequest, BaseResponse } from './baseMethod' @@ -20,13 +20,13 @@ export interface AMMInfoRequest extends BaseRequest { * Specifies one of the pool assets (XRP or token) of the AMM instance. * Both asset1 and asset2 must be defined to specify an AMM instance. */ - asset1?: Amount + asset1?: Currency /** * Specifies the other pool asset of the AMM instance. * Both asset1 and asset2 must be defined to specify an AMM instance. */ - asset2?: Amount + asset2?: Currency } interface VoteEntry { From acdfbd55e56bec1ea4d2b9db8095ded7610de694 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 9 Nov 2022 10:07:39 -0500 Subject: [PATCH 36/93] API name changes with updated definitions.json --- .../src/enums/definitions.json | 147 ++++-------------- .../xrpl/src/models/transactions/AMMBid.ts | 14 +- .../{AMMInstanceCreate.ts => AMMCreate.ts} | 40 ++--- .../src/models/transactions/AMMDeposit.ts | 44 +++--- .../xrpl/src/models/transactions/AMMVote.ts | 16 +- .../src/models/transactions/AMMWithdraw.ts | 44 +++--- .../xrpl/src/models/transactions/index.ts | 2 +- .../src/models/transactions/transaction.ts | 11 +- packages/xrpl/test/models/AMMBid.ts | 16 +- packages/xrpl/test/models/AMMCreate.ts | 102 ++++++++++++ packages/xrpl/test/models/AMMDeposit.ts | 62 ++++---- .../xrpl/test/models/AMMInstanceCreate.ts | 102 ------------ packages/xrpl/test/models/AMMVote.ts | 26 ++-- packages/xrpl/test/models/AMMWithdraw.ts | 62 ++++---- 14 files changed, 303 insertions(+), 385 deletions(-) rename packages/xrpl/src/models/transactions/{AMMInstanceCreate.ts => AMMCreate.ts} (50%) create mode 100644 packages/xrpl/test/models/AMMCreate.ts delete mode 100644 packages/xrpl/test/models/AMMInstanceCreate.ts diff --git a/packages/ripple-binary-codec/src/enums/definitions.json b/packages/ripple-binary-codec/src/enums/definitions.json index 2c3b655c9b..55bbac88a7 100644 --- a/packages/ripple-binary-codec/src/enums/definitions.json +++ b/packages/ripple-binary-codec/src/enums/definitions.json @@ -21,6 +21,7 @@ "UInt192": 21, "UInt384": 22, "UInt512": 23, + "Issue": 24, "Transaction": 10001, "LedgerEntry": 10002, "Validation": 10003, @@ -772,30 +773,10 @@ "type": "UInt32" } ], - [ - "FeeVal", - { - "nth": 47, - "isVLEncoded": false, - "isSerialized": true, - "isSigningField": true, - "type": "UInt32" - } - ], [ "VoteWeight", { - "nth": 48, - "isVLEncoded": false, - "isSerialized": true, - "isSigningField": true, - "type": "UInt32" - } - ], - [ - "TimeStamp", - { - "nth": 49, + "nth": 47, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -805,7 +786,7 @@ [ "DiscountedFee", { - "nth": 50, + "nth": 48, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -1463,7 +1444,7 @@ } ], [ - "Asset1", + "Amount2", { "nth": 11, "isVLEncoded": false, @@ -1473,7 +1454,7 @@ } ], [ - "Asset2", + "MinBidPrice", { "nth": 12, "isVLEncoded": false, @@ -1483,7 +1464,7 @@ } ], [ - "MinSlotPrice", + "MaxBidPrice", { "nth": 13, "isVLEncoded": false, @@ -1492,16 +1473,6 @@ "type": "Amount" } ], - [ - "MaxSlotPrice", - { - "nth": 14, - "isVLEncoded": false, - "isSerialized": true, - "isSigningField": true, - "type": "Amount" - } - ], [ "MinimumOffer", { @@ -1543,7 +1514,7 @@ } ], [ - "Asset1In", + "LPTokenOut", { "nth": 20, "isVLEncoded": false, @@ -1553,7 +1524,7 @@ } ], [ - "Asset2In", + "LPTokenIn", { "nth": 21, "isVLEncoded": false, @@ -1562,40 +1533,10 @@ "type": "Amount" } ], - [ - "Asset1Out", - { - "nth": 22, - "isVLEncoded": false, - "isSerialized": true, - "isSigningField": true, - "type": "Amount" - } - ], - [ - "Asset2Out", - { - "nth": 23, - "isVLEncoded": false, - "isSerialized": true, - "isSigningField": true, - "type": "Amount" - } - ], - [ - "LPToken", - { - "nth": 24, - "isVLEncoded": false, - "isSerialized": true, - "isSigningField": true, - "type": "Amount" - } - ], [ "EPrice", { - "nth": 25, + "nth": 22, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -1605,7 +1546,7 @@ [ "Price", { - "nth": 26, + "nth": 23, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -1615,7 +1556,7 @@ [ "LPTokenBalance", { - "nth": 27, + "nth": 24, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -2022,6 +1963,26 @@ "type": "PathSet" } ], + [ + "Asset", + { + "nth": 1, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Issue" + } + ], + [ + "Asset2", + { + "nth": 2, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Issue" + } + ], [ "TransactionMetaData", { @@ -2152,16 +2113,6 @@ "type": "STObject" } ], - [ - "AMM", - { - "nth": 15, - "isVLEncoded": false, - "isSerialized": true, - "isSigningField": true, - "type": "STObject" - } - ], [ "Signer", { @@ -2272,36 +2223,6 @@ "type": "STObject" } ], - [ - "AMMToken", - { - "nth": 29, - "isVLEncoded": false, - "isSerialized": true, - "isSigningField": true, - "type": "STObject" - } - ], - [ - "Token1", - { - "nth": 30, - "isVLEncoded": false, - "isSerialized": true, - "isSigningField": true, - "type": "STObject" - } - ], - [ - "Token2", - { - "nth": 31, - "isVLEncoded": false, - "isSerialized": true, - "isSigningField": true, - "type": "STObject" - } - ], [ "Signers", { @@ -2553,6 +2474,7 @@ "terNO_RIPPLE": -90, "terQUEUED": -89, "terPRE_TICKET": -88, + "terNO_AMM": -87, "tesSUCCESS": 0, @@ -2609,8 +2531,7 @@ "tecAMM_INVALID_TOKENS": 166, "tecAMM_EXISTS": 167, "tecAMM_FAILED_BID": 168, - "tecAMM_DIRECT_PAYMENT": 169, - "tecAMM_FAILED_VOTE": 170 + "tecAMM_FAILED_VOTE": 169 }, "TRANSACTION_TYPES": { "Invalid": -1, @@ -2642,7 +2563,7 @@ "NFTokenCreateOffer": 27, "NFTokenCancelOffer": 28, "NFTokenAcceptOffer": 29, - "AMMInstanceCreate": 35, + "AMMCreate": 35, "AMMDeposit": 36, "AMMWithdraw": 37, "AMMVote": 38, diff --git a/packages/xrpl/src/models/transactions/AMMBid.ts b/packages/xrpl/src/models/transactions/AMMBid.ts index e02c3cc288..cc74a2f26d 100644 --- a/packages/xrpl/src/models/transactions/AMMBid.ts +++ b/packages/xrpl/src/models/transactions/AMMBid.ts @@ -27,17 +27,17 @@ export interface AMMBid extends BaseTransaction { /** * This field represents the minimum price that the bidder wants to pay for the slot. - * It is specified in units of LPToken. If specified let MinSlotPrice be X and let + * It is specified in units of LPToken. If specified let MinBidPrice be X and let * the slot-price computed by price scheduling algorithm be Y, then bidder always pays * the max(X, Y). */ - MinSlotPrice?: Amount + MinBidPrice?: Amount /** * This field represents the maximum price that the bidder wants to pay for the slot. * It is specified in units of LPToken. */ - MaxSlotPrice?: Amount + MaxBidPrice?: Amount /** * This field represents an array of XRPL account IDs that are authorized to trade @@ -64,12 +64,12 @@ export function validateAMMBid(tx: Record): void { throw new ValidationError('AMMBid: AMMID must be a string') } - if (tx.MinSlotPrice != null && !isAmount(tx.MinSlotPrice)) { - throw new ValidationError('AMMBid: MinSlotPrice must be an Amount') + if (tx.MinBidPrice != null && !isAmount(tx.MinBidPrice)) { + throw new ValidationError('AMMBid: MinBidPrice must be an Amount') } - if (tx.MaxSlotPrice != null && !isAmount(tx.MaxSlotPrice)) { - throw new ValidationError('AMMBid: MaxSlotPrice must be an Amount') + if (tx.MaxBidPrice != null && !isAmount(tx.MaxBidPrice)) { + throw new ValidationError('AMMBid: MaxBidPrice must be an Amount') } if (tx.AuthAccounts != null) { diff --git a/packages/xrpl/src/models/transactions/AMMInstanceCreate.ts b/packages/xrpl/src/models/transactions/AMMCreate.ts similarity index 50% rename from packages/xrpl/src/models/transactions/AMMInstanceCreate.ts rename to packages/xrpl/src/models/transactions/AMMCreate.ts index 23faa33056..fbeda32d44 100644 --- a/packages/xrpl/src/models/transactions/AMMInstanceCreate.ts +++ b/packages/xrpl/src/models/transactions/AMMCreate.ts @@ -6,23 +6,23 @@ import { BaseTransaction, isAmount, validateBaseTransaction } from './common' export const AMM_MAX_TRADING_FEE = 65000 /** - * AMMInstanceCreate is used to create AccountRoot and the corresponding + * AMMCreate is used to create AccountRoot and the corresponding * AMM ledger entries. * * This allows for the creation of only one AMM instance per unique asset pair. */ -export interface AMMInstanceCreate extends BaseTransaction { - TransactionType: 'AMMInstanceCreate' +export interface AMMCreate extends BaseTransaction { + TransactionType: 'AMMCreate' /** * Specifies one of the pool assets (XRP or token) of the AMM instance. */ - Asset1: Amount + Amount: Amount /** * Specifies the other pool asset of the AMM instance. */ - Asset2: Amount + Amount2: Amount /** * Specifies the fee, in basis point, to be charged @@ -36,41 +36,41 @@ export interface AMMInstanceCreate extends BaseTransaction { } /** - * Verify the form and type of an AMMInstanceCreate at runtime. + * Verify the form and type of an AMMCreate at runtime. * - * @param tx - An AMMInstanceCreate Transaction. - * @throws When the AMMInstanceCreate is Malformed. + * @param tx - An AMMCreate Transaction. + * @throws When the AMMCreate is Malformed. */ -export function validateAMMInstanceCreate(tx: Record): void { +export function validateAMMCreate(tx: Record): void { validateBaseTransaction(tx) - if (tx.Asset1 == null) { - throw new ValidationError('AMMInstanceCreate: missing field Asset1') + if (tx.Amount == null) { + throw new ValidationError('AMMCreate: missing field Amount') } - if (!isAmount(tx.Asset1)) { - throw new ValidationError('AMMInstanceCreate: Asset1 must be an Amount') + if (!isAmount(tx.Amount)) { + throw new ValidationError('AMMCreate: Amount must be an Amount') } - if (tx.Asset2 == null) { - throw new ValidationError('AMMInstanceCreate: missing field Asset2') + if (tx.Amount2 == null) { + throw new ValidationError('AMMCreate: missing field Amount2') } - if (!isAmount(tx.Asset2)) { - throw new ValidationError('AMMInstanceCreate: Asset2 must be an Amount') + if (!isAmount(tx.Amount2)) { + throw new ValidationError('AMMCreate: Amount2 must be an Amount') } if (tx.TradingFee == null) { - throw new ValidationError('AMMInstanceCreate: missing field TradingFee') + throw new ValidationError('AMMCreate: missing field TradingFee') } if (typeof tx.TradingFee !== 'number') { - throw new ValidationError('AMMInstanceCreate: TradingFee must be a number') + throw new ValidationError('AMMCreate: TradingFee must be a number') } if (tx.TradingFee < 0 || tx.TradingFee > AMM_MAX_TRADING_FEE) { throw new ValidationError( - `AMMInstanceCreate: TradingFee must be between 0 and ${AMM_MAX_TRADING_FEE}`, + `AMMCreate: TradingFee must be between 0 and ${AMM_MAX_TRADING_FEE}`, ) } } diff --git a/packages/xrpl/src/models/transactions/AMMDeposit.ts b/packages/xrpl/src/models/transactions/AMMDeposit.ts index 66616d0856..6132464dd0 100644 --- a/packages/xrpl/src/models/transactions/AMMDeposit.ts +++ b/packages/xrpl/src/models/transactions/AMMDeposit.ts @@ -11,14 +11,14 @@ import { /** * AMMDeposit is the deposit transaction used to add liquidity to the AMM instance pool, - * thus obtaining some share of the instance's pools in the form of LPToken. + * thus obtaining some share of the instance's pools in the form of LPTokenOut. * * The following are the recommended valid combinations: - * - LPToken - * - Asset1In - * - Asset1In and Asset2In - * - Asset1In and LPToken - * - Asset1In and EPrice + * - LPTokenOut + * - Amount + * - Amount and Amount2 + * - Amount and LPTokenOut + * - Amount and EPrice */ export interface AMMDeposit extends BaseTransaction { TransactionType: 'AMMDeposit' @@ -32,22 +32,22 @@ export interface AMMDeposit extends BaseTransaction { * Specifies the amount of shares of the AMM instance pools that the trader * wants to redeem or trade in. */ - LPToken?: IssuedCurrencyAmount + LPTokenOut?: IssuedCurrencyAmount /** * Specifies one of the pool assets (XRP or token) of the AMM instance to * deposit more of its value. */ - Asset1In?: Amount + Amount?: Amount /** * Specifies the other pool asset of the AMM instance to deposit more of * its value. */ - Asset2In?: Amount + Amount2?: Amount /** - * Specifies the maximum effective-price that LPToken can be traded out. + * Specifies the maximum effective-price that LPTokenOut can be traded out. */ EPrice?: Amount } @@ -69,28 +69,28 @@ export function validateAMMDeposit(tx: Record): void { throw new ValidationError('AMMDeposit: AMMID must be a string') } - if (tx.Asset2In != null && tx.Asset1In == null) { - throw new ValidationError('AMMDeposit: must set Asset1In with Asset2In') - } else if (tx.EPrice != null && tx.Asset1In == null) { - throw new ValidationError('AMMDeposit: must set Asset1In with EPrice') - } else if (tx.LPToken == null && tx.Asset1In == null) { + if (tx.Amount2 != null && tx.Amount == null) { + throw new ValidationError('AMMDeposit: must set Amount with Amount2') + } else if (tx.EPrice != null && tx.Amount == null) { + throw new ValidationError('AMMDeposit: must set Amount with EPrice') + } else if (tx.LPTokenOut == null && tx.Amount == null) { throw new ValidationError( - 'AMMDeposit: must set at least LPToken or Asset1In', + 'AMMDeposit: must set at least LPTokenOut or Amount', ) } - if (tx.LPToken != null && !isIssuedCurrency(tx.LPToken)) { + if (tx.LPTokenOut != null && !isIssuedCurrency(tx.LPTokenOut)) { throw new ValidationError( - 'AMMDeposit: LPToken must be an IssuedCurrencyAmount', + 'AMMDeposit: LPTokenOut must be an IssuedCurrencyAmount', ) } - if (tx.Asset1In != null && !isAmount(tx.Asset1In)) { - throw new ValidationError('AMMDeposit: Asset1In must be an Amount') + if (tx.Amount != null && !isAmount(tx.Amount)) { + throw new ValidationError('AMMDeposit: Amount must be an Amount') } - if (tx.Asset2In != null && !isAmount(tx.Asset2In)) { - throw new ValidationError('AMMDeposit: Asset2In must be an Amount') + if (tx.Amount2 != null && !isAmount(tx.Amount2)) { + throw new ValidationError('AMMDeposit: Amount2 must be an Amount') } if (tx.EPrice != null && !isAmount(tx.EPrice)) { diff --git a/packages/xrpl/src/models/transactions/AMMVote.ts b/packages/xrpl/src/models/transactions/AMMVote.ts index 270a4141aa..bc69f9d4ea 100644 --- a/packages/xrpl/src/models/transactions/AMMVote.ts +++ b/packages/xrpl/src/models/transactions/AMMVote.ts @@ -1,6 +1,6 @@ import { ValidationError } from '../../errors' -import { AMM_MAX_TRADING_FEE } from './AMMInstanceCreate' +import { AMM_MAX_TRADING_FEE } from './AMMCreate' import { BaseTransaction, validateBaseTransaction } from './common' /** @@ -23,7 +23,7 @@ export interface AMMVote extends BaseTransaction { * A value of 1 is equivalent to 1/10 bps or 0.001%, allowing trading fee * between 0% and 65%. This field is required. */ - FeeVal: number + TradingFee: number } /** @@ -43,17 +43,17 @@ export function validateAMMVote(tx: Record): void { throw new ValidationError('AMMVote: AMMID must be a string') } - if (tx.FeeVal == null) { - throw new ValidationError('AMMVote: missing field FeeVal') + if (tx.TradingFee == null) { + throw new ValidationError('AMMVote: missing field TradingFee') } - if (typeof tx.FeeVal !== 'number') { - throw new ValidationError('AMMVote: FeeVal must be a number') + if (typeof tx.TradingFee !== 'number') { + throw new ValidationError('AMMVote: TradingFee must be a number') } - if (tx.FeeVal < 0 || tx.FeeVal > AMM_MAX_TRADING_FEE) { + if (tx.TradingFee < 0 || tx.TradingFee > AMM_MAX_TRADING_FEE) { throw new ValidationError( - `AMMVote: FeeVal must be between 0 and ${AMM_MAX_TRADING_FEE}`, + `AMMVote: TradingFee must be between 0 and ${AMM_MAX_TRADING_FEE}`, ) } } diff --git a/packages/xrpl/src/models/transactions/AMMWithdraw.ts b/packages/xrpl/src/models/transactions/AMMWithdraw.ts index ae997466fc..04a6cb8b78 100644 --- a/packages/xrpl/src/models/transactions/AMMWithdraw.ts +++ b/packages/xrpl/src/models/transactions/AMMWithdraw.ts @@ -12,14 +12,14 @@ import { /** * AMMWithdraw is the withdraw transaction used to remove liquidity from the AMM * instance pool, thus redeeming some share of the pools that one owns in the form - * of LPToken. + * of LPTokenIn. * * The following are the recommended valid combinations: - * - LPToken - * - Asset1Out - * - Asset1Out and Asset2Out - * - Asset1Out and LPToken - * - Asset1Out and EPrice + * - LPTokenIn + * - Amount + * - Amount and Amount2 + * - Amount and LPTokenIn + * - Amount and EPrice */ export interface AMMWithdraw extends BaseTransaction { TransactionType: 'AMMWithdraw' @@ -33,19 +33,19 @@ export interface AMMWithdraw extends BaseTransaction { * Specifies the amount of shares of the AMM instance pools that the trader * wants to redeem or trade in. */ - LPToken?: IssuedCurrencyAmount + LPTokenIn?: IssuedCurrencyAmount /** * Specifies one of the pools assets that the trader wants to remove. - * If the asset is XRP, then the Asset1Out is a string specifying the number of drops. + * If the asset is XRP, then the Amount is a string specifying the number of drops. * Otherwise it is an IssuedCurrencyAmount object. */ - Asset1Out?: Amount + Amount?: Amount /** * Specifies the other pool asset that the trader wants to remove. */ - Asset2Out?: Amount + Amount2?: Amount /** * Specifies the effective-price of the token out after successful execution of @@ -71,28 +71,28 @@ export function validateAMMWithdraw(tx: Record): void { throw new ValidationError('AMMWithdraw: AMMID must be a string') } - if (tx.Asset2Out != null && tx.Asset1Out == null) { - throw new ValidationError('AMMWithdraw: must set Asset1Out with Asset2Out') - } else if (tx.EPrice != null && tx.Asset1Out == null) { - throw new ValidationError('AMMWithdraw: must set Asset1Out with EPrice') - } else if (tx.LPToken == null && tx.Asset1Out == null) { + if (tx.Amount2 != null && tx.Amount == null) { + throw new ValidationError('AMMWithdraw: must set Amount with Amount2') + } else if (tx.EPrice != null && tx.Amount == null) { + throw new ValidationError('AMMWithdraw: must set Amount with EPrice') + } else if (tx.LPTokenIn == null && tx.Amount == null) { throw new ValidationError( - 'AMMWithdraw: must set at least LPToken or Asset1Out', + 'AMMWithdraw: must set at least LPTokenIn or Amount', ) } - if (tx.LPToken != null && !isIssuedCurrency(tx.LPToken)) { + if (tx.LPTokenIn != null && !isIssuedCurrency(tx.LPTokenIn)) { throw new ValidationError( - 'AMMWithdraw: LPToken must be an IssuedCurrencyAmount', + 'AMMWithdraw: LPTokenIn must be an IssuedCurrencyAmount', ) } - if (tx.Asset1Out != null && !isAmount(tx.Asset1Out)) { - throw new ValidationError('AMMWithdraw: Asset1Out must be an Amount') + if (tx.Amount != null && !isAmount(tx.Amount)) { + throw new ValidationError('AMMWithdraw: Amount must be an Amount') } - if (tx.Asset2Out != null && !isAmount(tx.Asset2Out)) { - throw new ValidationError('AMMWithdraw: Asset2Out must be an Amount') + if (tx.Amount2 != null && !isAmount(tx.Amount2)) { + throw new ValidationError('AMMWithdraw: Amount2 must be an Amount') } if (tx.EPrice != null && !isAmount(tx.EPrice)) { diff --git a/packages/xrpl/src/models/transactions/index.ts b/packages/xrpl/src/models/transactions/index.ts index 187b308ef7..a9b5c26c3d 100644 --- a/packages/xrpl/src/models/transactions/index.ts +++ b/packages/xrpl/src/models/transactions/index.ts @@ -9,7 +9,7 @@ export { export { AccountDelete } from './accountDelete' export { AMMBid } from './AMMBid' export { AMMDeposit } from './AMMDeposit' -export { AMMInstanceCreate } from './AMMInstanceCreate' +export { AMMCreate } from './AMMCreate' export { AMMVote } from './AMMVote' export { AMMWithdraw } from './AMMWithdraw' export { CheckCancel } from './checkCancel' diff --git a/packages/xrpl/src/models/transactions/transaction.ts b/packages/xrpl/src/models/transactions/transaction.ts index 1b5c6624c1..e6ad2fc59c 100644 --- a/packages/xrpl/src/models/transactions/transaction.ts +++ b/packages/xrpl/src/models/transactions/transaction.ts @@ -11,10 +11,7 @@ import { AccountDelete, validateAccountDelete } from './accountDelete' import { AccountSet, validateAccountSet } from './accountSet' import { AMMBid, validateAMMBid } from './AMMBid' import { AMMDeposit, validateAMMDeposit } from './AMMDeposit' -import { - AMMInstanceCreate, - validateAMMInstanceCreate, -} from './AMMInstanceCreate' +import { AMMCreate, validateAMMCreate } from './AMMCreate' import { AMMVote, validateAMMVote } from './AMMVote' import { AMMWithdraw, validateAMMWithdraw } from './AMMWithdraw' import { CheckCancel, validateCheckCancel } from './checkCancel' @@ -67,7 +64,7 @@ export type Transaction = | AccountSet | AMMBid | AMMDeposit - | AMMInstanceCreate + | AMMCreate | AMMVote | AMMWithdraw | CheckCancel @@ -136,8 +133,8 @@ export function validate(transaction: Record): void { validateAMMDeposit(tx) break - case 'AMMInstanceCreate': - validateAMMInstanceCreate(tx) + case 'AMMCreate': + validateAMMCreate(tx) break case 'AMMVote': diff --git a/packages/xrpl/test/models/AMMBid.ts b/packages/xrpl/test/models/AMMBid.ts index ece8b69298..08e07a8c10 100644 --- a/packages/xrpl/test/models/AMMBid.ts +++ b/packages/xrpl/test/models/AMMBid.ts @@ -14,8 +14,8 @@ describe('AMMBid', function () { TransactionType: 'AMMBid', Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', - MinSlotPrice: '5', - MaxSlotPrice: '10', + MinBidPrice: '5', + MaxBidPrice: '10', AuthAccounts: [ { AuthAccount: { @@ -64,21 +64,21 @@ describe('AMMBid', function () { ) }) - it(`throws w/ MinSlotPrice must be an Amount`, function () { - bid.MinSlotPrice = 5 + it(`throws w/ MinBidPrice must be an Amount`, function () { + bid.MinBidPrice = 5 assert.throws( () => validate(bid), ValidationError, - 'AMMBid: MinSlotPrice must be an Amount', + 'AMMBid: MinBidPrice must be an Amount', ) }) - it(`throws w/ MaxSlotPrice must be an Amount`, function () { - bid.MaxSlotPrice = 10 + it(`throws w/ MaxBidPrice must be an Amount`, function () { + bid.MaxBidPrice = 10 assert.throws( () => validate(bid), ValidationError, - 'AMMBid: MaxSlotPrice must be an Amount', + 'AMMBid: MaxBidPrice must be an Amount', ) }) diff --git a/packages/xrpl/test/models/AMMCreate.ts b/packages/xrpl/test/models/AMMCreate.ts new file mode 100644 index 0000000000..ce18ef9ede --- /dev/null +++ b/packages/xrpl/test/models/AMMCreate.ts @@ -0,0 +1,102 @@ +import { assert } from 'chai' +import { validate, ValidationError } from 'xrpl-local' + +/** + * AMMCreate Transaction Verification Testing. + * + * Providing runtime verification testing for each specific transaction type. + */ +describe('AMMCreate', function () { + let ammCreate + + beforeEach(function () { + ammCreate = { + TransactionType: 'AMMCreate', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + Amount: '1000', + Amount2: { + currency: 'USD', + issuer: 'rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9', + value: '1000', + }, + TradingFee: 12, + Sequence: 1337, + } as any + }) + + it(`verifies valid AMMCreate`, function () { + assert.doesNotThrow(() => validate(ammCreate)) + }) + + it(`throws w/ missing Amount`, function () { + delete ammCreate.Amount + assert.throws( + () => validate(ammCreate), + ValidationError, + 'AMMCreate: missing field Amount', + ) + }) + + it(`throws w/ Amount must be an Amount`, function () { + ammCreate.Amount = 1000 + assert.throws( + () => validate(ammCreate), + ValidationError, + 'AMMCreate: Amount must be an Amount', + ) + }) + + it(`throws w/ missing Amount2`, function () { + delete ammCreate.Amount2 + assert.throws( + () => validate(ammCreate), + ValidationError, + 'AMMCreate: missing field Amount2', + ) + }) + + it(`throws w/ Amount2 must be an Amount`, function () { + ammCreate.Amount2 = 1000 + assert.throws( + () => validate(ammCreate), + ValidationError, + 'AMMCreate: Amount2 must be an Amount', + ) + }) + + it(`throws w/ missing TradingFee`, function () { + delete ammCreate.TradingFee + assert.throws( + () => validate(ammCreate), + ValidationError, + 'AMMCreate: missing field TradingFee', + ) + }) + + it(`throws w/ TradingFee must be a number`, function () { + ammCreate.TradingFee = '12' + assert.throws( + () => validate(ammCreate), + ValidationError, + 'AMMCreate: TradingFee must be a number', + ) + }) + + it(`throws when TradingFee is greater than 65000`, function () { + ammCreate.TradingFee = 65001 + assert.throws( + () => validate(ammCreate), + ValidationError, + `AMMCreate: TradingFee must be between 0 and 65000`, + ) + }) + + it(`throws when TradingFee is a negative number`, function () { + ammCreate.TradingFee = -1 + assert.throws( + () => validate(ammCreate), + ValidationError, + `AMMCreate: TradingFee must be between 0 and 65000`, + ) + }) +}) diff --git a/packages/xrpl/test/models/AMMDeposit.ts b/packages/xrpl/test/models/AMMDeposit.ts index 1d54ba25c3..00a37440a5 100644 --- a/packages/xrpl/test/models/AMMDeposit.ts +++ b/packages/xrpl/test/models/AMMDeposit.ts @@ -7,7 +7,7 @@ import { validate, ValidationError } from 'xrpl-local' * Providing runtime verification testing for each specific transaction type. */ describe('AMMDeposit', function () { - const LPToken = { + const LPTokenOut = { currency: 'B3813FCAB4EE68B3D0D735D6849465A9113EE048', issuer: 'rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg', value: '1000', @@ -23,30 +23,30 @@ describe('AMMDeposit', function () { } as any }) - it(`verifies valid AMMDeposit with LPToken`, function () { - deposit.LPToken = LPToken + it(`verifies valid AMMDeposit with LPTokenOut`, function () { + deposit.LPTokenOut = LPTokenOut assert.doesNotThrow(() => validate(deposit)) }) - it(`verifies valid AMMDeposit with Asset1In`, function () { - deposit.Asset1In = '1000' + it(`verifies valid AMMDeposit with Amount`, function () { + deposit.Amount = '1000' assert.doesNotThrow(() => validate(deposit)) }) - it(`verifies valid AMMDeposit with Asset1In and Asset2In`, function () { - deposit.Asset1In = '1000' - deposit.Asset2In = '1000' + it(`verifies valid AMMDeposit with Amount and Amount2`, function () { + deposit.Amount = '1000' + deposit.Amount2 = '1000' assert.doesNotThrow(() => validate(deposit)) }) - it(`verifies valid AMMDeposit with Asset1In and LPToken`, function () { - deposit.Asset1In = '1000' - deposit.LPToken = LPToken + it(`verifies valid AMMDeposit with Amount and LPTokenOut`, function () { + deposit.Amount = '1000' + deposit.LPTokenOut = LPTokenOut assert.doesNotThrow(() => validate(deposit)) }) - it(`verifies valid AMMDeposit with Asset1In and EPrice`, function () { - deposit.Asset1In = '1000' + it(`verifies valid AMMDeposit with Amount and EPrice`, function () { + deposit.Amount = '1000' deposit.EPrice = '25' assert.doesNotThrow(() => validate(deposit)) }) @@ -69,62 +69,62 @@ describe('AMMDeposit', function () { ) }) - it(`throws w/ must set at least LPToken or Asset1In`, function () { + it(`throws w/ must set at least LPTokenOut or Amount`, function () { assert.throws( () => validate(deposit), ValidationError, - 'AMMDeposit: must set at least LPToken or Asset1In', + 'AMMDeposit: must set at least LPTokenOut or Amount', ) }) - it(`throws w/ must set Asset1In with Asset2In`, function () { - deposit.Asset2In = '500' + it(`throws w/ must set Amount with Amount2`, function () { + deposit.Amount2 = '500' assert.throws( () => validate(deposit), ValidationError, - 'AMMDeposit: must set Asset1In with Asset2In', + 'AMMDeposit: must set Amount with Amount2', ) }) - it(`throws w/ must set Asset1In with EPrice`, function () { + it(`throws w/ must set Amount with EPrice`, function () { deposit.EPrice = '25' assert.throws( () => validate(deposit), ValidationError, - 'AMMDeposit: must set Asset1In with EPrice', + 'AMMDeposit: must set Amount with EPrice', ) }) - it(`throws w/ LPToken must be an IssuedCurrencyAmount`, function () { - deposit.LPToken = 1234 + it(`throws w/ LPTokenOut must be an IssuedCurrencyAmount`, function () { + deposit.LPTokenOut = 1234 assert.throws( () => validate(deposit), ValidationError, - 'AMMDeposit: LPToken must be an IssuedCurrencyAmount', + 'AMMDeposit: LPTokenOut must be an IssuedCurrencyAmount', ) }) - it(`throws w/ Asset1In must be an Amount`, function () { - deposit.Asset1In = 1234 + it(`throws w/ Amount must be an Amount`, function () { + deposit.Amount = 1234 assert.throws( () => validate(deposit), ValidationError, - 'AMMDeposit: Asset1In must be an Amount', + 'AMMDeposit: Amount must be an Amount', ) }) - it(`throws w/ Asset2In must be an Amount`, function () { - deposit.Asset1In = '1000' - deposit.Asset2In = 1234 + it(`throws w/ Amount2 must be an Amount`, function () { + deposit.Amount = '1000' + deposit.Amount2 = 1234 assert.throws( () => validate(deposit), ValidationError, - 'AMMDeposit: Asset2In must be an Amount', + 'AMMDeposit: Amount2 must be an Amount', ) }) it(`throws w/ EPrice must be an Amount`, function () { - deposit.Asset1In = '1000' + deposit.Amount = '1000' deposit.EPrice = 1234 assert.throws( () => validate(deposit), diff --git a/packages/xrpl/test/models/AMMInstanceCreate.ts b/packages/xrpl/test/models/AMMInstanceCreate.ts deleted file mode 100644 index 8e4f15973f..0000000000 --- a/packages/xrpl/test/models/AMMInstanceCreate.ts +++ /dev/null @@ -1,102 +0,0 @@ -import { assert } from 'chai' -import { validate, ValidationError } from 'xrpl-local' - -/** - * AMMInstanceCreate Transaction Verification Testing. - * - * Providing runtime verification testing for each specific transaction type. - */ -describe('AMMInstanceCreate', function () { - let instanceCreate - - beforeEach(function () { - instanceCreate = { - TransactionType: 'AMMInstanceCreate', - Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - Asset1: '1000', - Asset2: { - currency: 'USD', - issuer: 'rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9', - value: '1000', - }, - TradingFee: 12, - Sequence: 1337, - } as any - }) - - it(`verifies valid AMMInstanceCreate`, function () { - assert.doesNotThrow(() => validate(instanceCreate)) - }) - - it(`throws w/ missing Asset1`, function () { - delete instanceCreate.Asset1 - assert.throws( - () => validate(instanceCreate), - ValidationError, - 'AMMInstanceCreate: missing field Asset1', - ) - }) - - it(`throws w/ Asset1 must be an Amount`, function () { - instanceCreate.Asset1 = 1000 - assert.throws( - () => validate(instanceCreate), - ValidationError, - 'AMMInstanceCreate: Asset1 must be an Amount', - ) - }) - - it(`throws w/ missing Asset2`, function () { - delete instanceCreate.Asset2 - assert.throws( - () => validate(instanceCreate), - ValidationError, - 'AMMInstanceCreate: missing field Asset2', - ) - }) - - it(`throws w/ Asset2 must be an Amount`, function () { - instanceCreate.Asset2 = 1000 - assert.throws( - () => validate(instanceCreate), - ValidationError, - 'AMMInstanceCreate: Asset2 must be an Amount', - ) - }) - - it(`throws w/ missing TradingFee`, function () { - delete instanceCreate.TradingFee - assert.throws( - () => validate(instanceCreate), - ValidationError, - 'AMMInstanceCreate: missing field TradingFee', - ) - }) - - it(`throws w/ TradingFee must be a number`, function () { - instanceCreate.TradingFee = '12' - assert.throws( - () => validate(instanceCreate), - ValidationError, - 'AMMInstanceCreate: TradingFee must be a number', - ) - }) - - it(`throws when TradingFee is greater than 65000`, function () { - instanceCreate.TradingFee = 65001 - assert.throws( - () => validate(instanceCreate), - ValidationError, - `AMMInstanceCreate: TradingFee must be between 0 and 65000`, - ) - }) - - it(`throws when TradingFee is a negative number`, function () { - instanceCreate.TradingFee = -1 - assert.throws( - () => validate(instanceCreate), - ValidationError, - `AMMInstanceCreate: TradingFee must be between 0 and 65000`, - ) - }) -}) diff --git a/packages/xrpl/test/models/AMMVote.ts b/packages/xrpl/test/models/AMMVote.ts index b7ae2852df..b813d7b565 100644 --- a/packages/xrpl/test/models/AMMVote.ts +++ b/packages/xrpl/test/models/AMMVote.ts @@ -14,7 +14,7 @@ describe('AMMVote', function () { TransactionType: 'AMMVote', Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', - FeeVal: 25, + TradingFee: 25, Sequence: 1337, } as any }) @@ -41,39 +41,39 @@ describe('AMMVote', function () { ) }) - it(`throws w/ missing field FeeVal`, function () { - delete vote.FeeVal + it(`throws w/ missing field TradingFee`, function () { + delete vote.TradingFee assert.throws( () => validate(vote), ValidationError, - 'AMMVote: missing field FeeVal', + 'AMMVote: missing field TradingFee', ) }) - it(`throws w/ FeeVal must be a number`, function () { - vote.FeeVal = '25' + it(`throws w/ TradingFee must be a number`, function () { + vote.TradingFee = '25' assert.throws( () => validate(vote), ValidationError, - 'AMMVote: FeeVal must be a number', + 'AMMVote: TradingFee must be a number', ) }) - it(`throws when FeeVal is greater than AMM_MAX_TRADING_FEE`, function () { - vote.FeeVal = 65001 + it(`throws when TradingFee is greater than AMM_MAX_TRADING_FEE`, function () { + vote.TradingFee = 65001 assert.throws( () => validate(vote), ValidationError, - 'AMMVote: FeeVal must be between 0 and 65000', + 'AMMVote: TradingFee must be between 0 and 65000', ) }) - it(`throws when FeeVal is a negative number`, function () { - vote.FeeVal = -1 + it(`throws when TradingFee is a negative number`, function () { + vote.TradingFee = -1 assert.throws( () => validate(vote), ValidationError, - 'AMMVote: FeeVal must be between 0 and 65000', + 'AMMVote: TradingFee must be between 0 and 65000', ) }) }) diff --git a/packages/xrpl/test/models/AMMWithdraw.ts b/packages/xrpl/test/models/AMMWithdraw.ts index 68fdd3146c..f8c51894a7 100644 --- a/packages/xrpl/test/models/AMMWithdraw.ts +++ b/packages/xrpl/test/models/AMMWithdraw.ts @@ -7,7 +7,7 @@ import { validate, ValidationError } from 'xrpl-local' * Providing runtime verification testing for each specific transaction type. */ describe('AMMWithdraw', function () { - const LPToken = { + const LPTokenIn = { currency: 'B3813FCAB4EE68B3D0D735D6849465A9113EE048', issuer: 'rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg', value: '1000', @@ -23,30 +23,30 @@ describe('AMMWithdraw', function () { } as any }) - it(`verifies valid AMMWithdraw with LPToken`, function () { - withdraw.LPToken = LPToken + it(`verifies valid AMMWithdraw with LPTokenIn`, function () { + withdraw.LPTokenIn = LPTokenIn assert.doesNotThrow(() => validate(withdraw)) }) - it(`verifies valid AMMWithdraw with Asset1Out`, function () { - withdraw.Asset1Out = '1000' + it(`verifies valid AMMWithdraw with Amount`, function () { + withdraw.Amount = '1000' assert.doesNotThrow(() => validate(withdraw)) }) - it(`verifies valid AMMWithdraw with Asset1Out and Asset2Out`, function () { - withdraw.Asset1Out = '1000' - withdraw.Asset2Out = '1000' + it(`verifies valid AMMWithdraw with Amount and Amount2`, function () { + withdraw.Amount = '1000' + withdraw.Amount2 = '1000' assert.doesNotThrow(() => validate(withdraw)) }) - it(`verifies valid AMMWithdraw with Asset1Out and LPToken`, function () { - withdraw.Asset1Out = '1000' - withdraw.LPToken = LPToken + it(`verifies valid AMMWithdraw with Amount and LPTokenIn`, function () { + withdraw.Amount = '1000' + withdraw.LPTokenIn = LPTokenIn assert.doesNotThrow(() => validate(withdraw)) }) - it(`verifies valid AMMWithdraw with Asset1Out and EPrice`, function () { - withdraw.Asset1Out = '1000' + it(`verifies valid AMMWithdraw with Amount and EPrice`, function () { + withdraw.Amount = '1000' withdraw.EPrice = '25' assert.doesNotThrow(() => validate(withdraw)) }) @@ -69,62 +69,62 @@ describe('AMMWithdraw', function () { ) }) - it(`throws w/ must set at least LPToken or Asset1Out`, function () { + it(`throws w/ must set at least LPTokenIn or Amount`, function () { assert.throws( () => validate(withdraw), ValidationError, - 'AMMWithdraw: must set at least LPToken or Asset1Out', + 'AMMWithdraw: must set at least LPTokenIn or Amount', ) }) - it(`throws w/ must set Asset1Out with Asset2Out`, function () { - withdraw.Asset2Out = '500' + it(`throws w/ must set Amount with Amount2`, function () { + withdraw.Amount2 = '500' assert.throws( () => validate(withdraw), ValidationError, - 'AMMWithdraw: must set Asset1Out with Asset2Out', + 'AMMWithdraw: must set Amount with Amount2', ) }) - it(`throws w/ must set Asset1Out with EPrice`, function () { + it(`throws w/ must set Amount with EPrice`, function () { withdraw.EPrice = '25' assert.throws( () => validate(withdraw), ValidationError, - 'AMMWithdraw: must set Asset1Out with EPrice', + 'AMMWithdraw: must set Amount with EPrice', ) }) - it(`throws w/ LPToken must be an IssuedCurrencyAmount`, function () { - withdraw.LPToken = 1234 + it(`throws w/ LPTokenIn must be an IssuedCurrencyAmount`, function () { + withdraw.LPTokenIn = 1234 assert.throws( () => validate(withdraw), ValidationError, - 'AMMWithdraw: LPToken must be an IssuedCurrencyAmount', + 'AMMWithdraw: LPTokenIn must be an IssuedCurrencyAmount', ) }) - it(`throws w/ Asset1Out must be an Amount`, function () { - withdraw.Asset1Out = 1234 + it(`throws w/ Amount must be an Amount`, function () { + withdraw.Amount = 1234 assert.throws( () => validate(withdraw), ValidationError, - 'AMMWithdraw: Asset1Out must be an Amount', + 'AMMWithdraw: Amount must be an Amount', ) }) - it(`throws w/ Asset2Out must be an Amount`, function () { - withdraw.Asset1Out = '1000' - withdraw.Asset2Out = 1234 + it(`throws w/ Amount2 must be an Amount`, function () { + withdraw.Amount = '1000' + withdraw.Amount2 = 1234 assert.throws( () => validate(withdraw), ValidationError, - 'AMMWithdraw: Asset2Out must be an Amount', + 'AMMWithdraw: Amount2 must be an Amount', ) }) it(`throws w/ EPrice must be an Amount`, function () { - withdraw.Asset1Out = '1000' + withdraw.Amount = '1000' withdraw.EPrice = 1234 assert.throws( () => validate(withdraw), From 54b86bc1d795c5b20fc3a8ad53dda72b6acd7c82 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 9 Nov 2022 10:14:02 -0500 Subject: [PATCH 37/93] rename amm_info param asset1 -> asset --- packages/xrpl/src/models/methods/ammInfo.ts | 8 ++++---- packages/xrpl/src/models/transactions/transaction.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index 4d51ccddd8..6f3a663cbd 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -18,13 +18,13 @@ export interface AMMInfoRequest extends BaseRequest { /** * Specifies one of the pool assets (XRP or token) of the AMM instance. - * Both asset1 and asset2 must be defined to specify an AMM instance. + * Both asset and asset2 must be defined to specify an AMM instance. */ - asset1?: Currency + asset?: Currency /** * Specifies the other pool asset of the AMM instance. - * Both asset1 and asset2 must be defined to specify an AMM instance. + * Both asset and asset2 must be defined to specify an AMM instance. */ asset2?: Currency } @@ -49,7 +49,7 @@ export interface AMMInfoResponse extends BaseResponse { /** * Specifies one of the pool assets (XRP or token) of the AMM instance. */ - Asset1: Amount + asset: Amount /** * Specifies the other pool asset of the AMM instance. diff --git a/packages/xrpl/src/models/transactions/transaction.ts b/packages/xrpl/src/models/transactions/transaction.ts index e6ad2fc59c..cfa8994af1 100644 --- a/packages/xrpl/src/models/transactions/transaction.ts +++ b/packages/xrpl/src/models/transactions/transaction.ts @@ -10,8 +10,8 @@ import { setTransactionFlagsToNumber } from '../utils/flags' import { AccountDelete, validateAccountDelete } from './accountDelete' import { AccountSet, validateAccountSet } from './accountSet' import { AMMBid, validateAMMBid } from './AMMBid' -import { AMMDeposit, validateAMMDeposit } from './AMMDeposit' import { AMMCreate, validateAMMCreate } from './AMMCreate' +import { AMMDeposit, validateAMMDeposit } from './AMMDeposit' import { AMMVote, validateAMMVote } from './AMMVote' import { AMMWithdraw, validateAMMWithdraw } from './AMMWithdraw' import { CheckCancel, validateCheckCancel } from './checkCancel' From c99aa048dae5e3af2deadfe60a886ba5abbf8a2d Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 9 Nov 2022 10:21:14 -0500 Subject: [PATCH 38/93] fix typo --- packages/xrpl/src/models/methods/ammInfo.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index 6f3a663cbd..136c64a570 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -49,7 +49,7 @@ export interface AMMInfoResponse extends BaseResponse { /** * Specifies one of the pool assets (XRP or token) of the AMM instance. */ - asset: Amount + Asset: Amount /** * Specifies the other pool asset of the AMM instance. From 3120abc627826cca5cbd772e47c91a1d108fad78 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 9 Nov 2022 10:27:57 -0500 Subject: [PATCH 39/93] change AMM_MAX_TRADING_FEE to 1% --- packages/xrpl/src/models/methods/ammInfo.ts | 4 ++-- packages/xrpl/src/models/transactions/AMMCreate.ts | 6 +++--- packages/xrpl/src/models/transactions/AMMVote.ts | 4 ++-- packages/xrpl/test/models/AMMCreate.ts | 8 ++++---- packages/xrpl/test/models/AMMVote.ts | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index 136c64a570..7a966122d8 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -67,9 +67,9 @@ export interface AMMInfoResponse extends BaseResponse { /** * Specifies the fee, in basis point, to be charged to the traders for the trades * executed against the AMM instance. Trading fee is a percentage of the trading volume. - * Valid values for this field are between 0 and 65000 inclusive. + * Valid values for this field are between 0 and 1000 inclusive. * A value of 1 is equivalent to 1/10 bps or 0.001%, allowing trading fee - * between 0% and 65%. This field is required. + * between 0% and 1%. This field is required. */ TradingFee: number diff --git a/packages/xrpl/src/models/transactions/AMMCreate.ts b/packages/xrpl/src/models/transactions/AMMCreate.ts index fbeda32d44..9ce8b68dc2 100644 --- a/packages/xrpl/src/models/transactions/AMMCreate.ts +++ b/packages/xrpl/src/models/transactions/AMMCreate.ts @@ -3,7 +3,7 @@ import { Amount } from '../common' import { BaseTransaction, isAmount, validateBaseTransaction } from './common' -export const AMM_MAX_TRADING_FEE = 65000 +export const AMM_MAX_TRADING_FEE = 1000 /** * AMMCreate is used to create AccountRoot and the corresponding @@ -28,9 +28,9 @@ export interface AMMCreate extends BaseTransaction { * Specifies the fee, in basis point, to be charged * to the traders for the trades executed against the AMM instance. * Trading fee is a percentage of the trading volume. - * Valid values for this field are between 0 and 65000 inclusive. + * Valid values for this field are between 0 and 1000 inclusive. * A value of 1 is equivalent to 1/10 bps or 0.001%, allowing trading fee - * between 0% and 65%. + * between 0% and 1%. */ TradingFee: number } diff --git a/packages/xrpl/src/models/transactions/AMMVote.ts b/packages/xrpl/src/models/transactions/AMMVote.ts index bc69f9d4ea..b53ccd199b 100644 --- a/packages/xrpl/src/models/transactions/AMMVote.ts +++ b/packages/xrpl/src/models/transactions/AMMVote.ts @@ -19,9 +19,9 @@ export interface AMMVote extends BaseTransaction { /** * Specifies the fee, in basis point. - * Valid values for this field are between 0 and 65000 inclusive. + * Valid values for this field are between 0 and 1000 inclusive. * A value of 1 is equivalent to 1/10 bps or 0.001%, allowing trading fee - * between 0% and 65%. This field is required. + * between 0% and 1%. This field is required. */ TradingFee: number } diff --git a/packages/xrpl/test/models/AMMCreate.ts b/packages/xrpl/test/models/AMMCreate.ts index ce18ef9ede..d75a1f17f7 100644 --- a/packages/xrpl/test/models/AMMCreate.ts +++ b/packages/xrpl/test/models/AMMCreate.ts @@ -82,12 +82,12 @@ describe('AMMCreate', function () { ) }) - it(`throws when TradingFee is greater than 65000`, function () { - ammCreate.TradingFee = 65001 + it(`throws when TradingFee is greater than 1000`, function () { + ammCreate.TradingFee = 1001 assert.throws( () => validate(ammCreate), ValidationError, - `AMMCreate: TradingFee must be between 0 and 65000`, + `AMMCreate: TradingFee must be between 0 and 1000`, ) }) @@ -96,7 +96,7 @@ describe('AMMCreate', function () { assert.throws( () => validate(ammCreate), ValidationError, - `AMMCreate: TradingFee must be between 0 and 65000`, + `AMMCreate: TradingFee must be between 0 and 1000`, ) }) }) diff --git a/packages/xrpl/test/models/AMMVote.ts b/packages/xrpl/test/models/AMMVote.ts index b813d7b565..962680522a 100644 --- a/packages/xrpl/test/models/AMMVote.ts +++ b/packages/xrpl/test/models/AMMVote.ts @@ -60,11 +60,11 @@ describe('AMMVote', function () { }) it(`throws when TradingFee is greater than AMM_MAX_TRADING_FEE`, function () { - vote.TradingFee = 65001 + vote.TradingFee = 1001 assert.throws( () => validate(vote), ValidationError, - 'AMMVote: TradingFee must be between 0 and 65000', + 'AMMVote: TradingFee must be between 0 and 1000', ) }) @@ -73,7 +73,7 @@ describe('AMMVote', function () { assert.throws( () => validate(vote), ValidationError, - 'AMMVote: TradingFee must be between 0 and 65000', + 'AMMVote: TradingFee must be between 0 and 1000', ) }) }) From 25752d77a4701b844e85a73fd9fea8d5a965954a Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 9 Nov 2022 11:51:08 -0500 Subject: [PATCH 40/93] Use Asset/Asset2 instead of AMMID for Deposit/Withdraw/Bid/Vote --- packages/xrpl/src/models/common/index.ts | 2 ++ .../xrpl/src/models/transactions/AMMBid.ts | 19 ++++++++----------- .../src/models/transactions/AMMDeposit.ts | 19 ++++++++----------- .../xrpl/src/models/transactions/AMMVote.ts | 18 ++++++++---------- .../src/models/transactions/AMMWithdraw.ts | 19 ++++++++----------- packages/xrpl/test/models/AMMBid.ts | 19 ------------------- packages/xrpl/test/models/AMMDeposit.ts | 19 ------------------- packages/xrpl/test/models/AMMVote.ts | 19 ------------------- packages/xrpl/test/models/AMMWithdraw.ts | 19 ------------------- 9 files changed, 34 insertions(+), 119 deletions(-) diff --git a/packages/xrpl/src/models/common/index.ts b/packages/xrpl/src/models/common/index.ts index 26625c7467..c6cea185af 100644 --- a/packages/xrpl/src/models/common/index.ts +++ b/packages/xrpl/src/models/common/index.ts @@ -22,6 +22,8 @@ interface IssuedCurrency { export type Currency = IssuedCurrency | XRP +export type Issue = Currency + export interface IssuedCurrencyAmount extends IssuedCurrency { value: string } diff --git a/packages/xrpl/src/models/transactions/AMMBid.ts b/packages/xrpl/src/models/transactions/AMMBid.ts index cc74a2f26d..7cdd09cc14 100644 --- a/packages/xrpl/src/models/transactions/AMMBid.ts +++ b/packages/xrpl/src/models/transactions/AMMBid.ts @@ -1,5 +1,5 @@ import { ValidationError } from '../../errors' -import { Amount } from '../common' +import { Amount, Issue } from '../common' import { BaseTransaction, isAmount, validateBaseTransaction } from './common' @@ -21,9 +21,14 @@ export interface AMMBid extends BaseTransaction { TransactionType: 'AMMBid' /** - * A hash that uniquely identifies the AMM instance. This field is required. + * Specifies one of the pool assets (XRP or token) of the AMM instance. */ - AMMID: string + Asset: Issue + + /** + * Specifies the other pool asset of the AMM instance. + */ + Asset2: Issue /** * This field represents the minimum price that the bidder wants to pay for the slot. @@ -56,14 +61,6 @@ export interface AMMBid extends BaseTransaction { export function validateAMMBid(tx: Record): void { validateBaseTransaction(tx) - if (tx.AMMID == null) { - throw new ValidationError('AMMBid: missing field AMMID') - } - - if (typeof tx.AMMID !== 'string') { - throw new ValidationError('AMMBid: AMMID must be a string') - } - if (tx.MinBidPrice != null && !isAmount(tx.MinBidPrice)) { throw new ValidationError('AMMBid: MinBidPrice must be an Amount') } diff --git a/packages/xrpl/src/models/transactions/AMMDeposit.ts b/packages/xrpl/src/models/transactions/AMMDeposit.ts index 6132464dd0..98008e435a 100644 --- a/packages/xrpl/src/models/transactions/AMMDeposit.ts +++ b/packages/xrpl/src/models/transactions/AMMDeposit.ts @@ -1,6 +1,6 @@ /* eslint-disable complexity -- required for validateAMMDeposit */ import { ValidationError } from '../../errors' -import { Amount, IssuedCurrencyAmount } from '../common' +import { Amount, Issue, IssuedCurrencyAmount } from '../common' import { BaseTransaction, @@ -24,9 +24,14 @@ export interface AMMDeposit extends BaseTransaction { TransactionType: 'AMMDeposit' /** - * A hash that uniquely identifies the AMM instance. This field is required. + * Specifies one of the pool assets (XRP or token) of the AMM instance. */ - AMMID: string + Asset: Issue + + /** + * Specifies the other pool asset of the AMM instance. + */ + Asset2: Issue /** * Specifies the amount of shares of the AMM instance pools that the trader @@ -61,14 +66,6 @@ export interface AMMDeposit extends BaseTransaction { export function validateAMMDeposit(tx: Record): void { validateBaseTransaction(tx) - if (tx.AMMID == null) { - throw new ValidationError('AMMDeposit: missing field AMMID') - } - - if (typeof tx.AMMID !== 'string') { - throw new ValidationError('AMMDeposit: AMMID must be a string') - } - if (tx.Amount2 != null && tx.Amount == null) { throw new ValidationError('AMMDeposit: must set Amount with Amount2') } else if (tx.EPrice != null && tx.Amount == null) { diff --git a/packages/xrpl/src/models/transactions/AMMVote.ts b/packages/xrpl/src/models/transactions/AMMVote.ts index b53ccd199b..38324ec6d6 100644 --- a/packages/xrpl/src/models/transactions/AMMVote.ts +++ b/packages/xrpl/src/models/transactions/AMMVote.ts @@ -1,4 +1,5 @@ import { ValidationError } from '../../errors' +import { Issue } from '../common' import { AMM_MAX_TRADING_FEE } from './AMMCreate' import { BaseTransaction, validateBaseTransaction } from './common' @@ -13,9 +14,14 @@ export interface AMMVote extends BaseTransaction { TransactionType: 'AMMVote' /** - * A hash that uniquely identifies the AMM instance. This field is required. + * Specifies one of the pool assets (XRP or token) of the AMM instance. */ - AMMID: string + Asset: Issue + + /** + * Specifies the other pool asset of the AMM instance. + */ + Asset2: Issue /** * Specifies the fee, in basis point. @@ -35,14 +41,6 @@ export interface AMMVote extends BaseTransaction { export function validateAMMVote(tx: Record): void { validateBaseTransaction(tx) - if (tx.AMMID == null) { - throw new ValidationError('AMMVote: missing field AMMID') - } - - if (typeof tx.AMMID !== 'string') { - throw new ValidationError('AMMVote: AMMID must be a string') - } - if (tx.TradingFee == null) { throw new ValidationError('AMMVote: missing field TradingFee') } diff --git a/packages/xrpl/src/models/transactions/AMMWithdraw.ts b/packages/xrpl/src/models/transactions/AMMWithdraw.ts index 04a6cb8b78..41ac9dc1c0 100644 --- a/packages/xrpl/src/models/transactions/AMMWithdraw.ts +++ b/packages/xrpl/src/models/transactions/AMMWithdraw.ts @@ -1,6 +1,6 @@ /* eslint-disable complexity -- required for validateAMMWithdraw */ import { ValidationError } from '../../errors' -import { Amount, IssuedCurrencyAmount } from '../common' +import { Amount, Issue, IssuedCurrencyAmount } from '../common' import { BaseTransaction, @@ -25,9 +25,14 @@ export interface AMMWithdraw extends BaseTransaction { TransactionType: 'AMMWithdraw' /** - * A hash that uniquely identifies the AMM instance. This field is required. + * Specifies one of the pool assets (XRP or token) of the AMM instance. */ - AMMID: string + Asset: Issue + + /** + * Specifies the other pool asset of the AMM instance. + */ + Asset2: Issue /** * Specifies the amount of shares of the AMM instance pools that the trader @@ -63,14 +68,6 @@ export interface AMMWithdraw extends BaseTransaction { export function validateAMMWithdraw(tx: Record): void { validateBaseTransaction(tx) - if (tx.AMMID == null) { - throw new ValidationError('AMMWithdraw: missing field AMMID') - } - - if (typeof tx.AMMID !== 'string') { - throw new ValidationError('AMMWithdraw: AMMID must be a string') - } - if (tx.Amount2 != null && tx.Amount == null) { throw new ValidationError('AMMWithdraw: must set Amount with Amount2') } else if (tx.EPrice != null && tx.Amount == null) { diff --git a/packages/xrpl/test/models/AMMBid.ts b/packages/xrpl/test/models/AMMBid.ts index 08e07a8c10..121a698f00 100644 --- a/packages/xrpl/test/models/AMMBid.ts +++ b/packages/xrpl/test/models/AMMBid.ts @@ -13,7 +13,6 @@ describe('AMMBid', function () { bid = { TransactionType: 'AMMBid', Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', MinBidPrice: '5', MaxBidPrice: '10', AuthAccounts: [ @@ -46,24 +45,6 @@ describe('AMMBid', function () { assert.doesNotThrow(() => validate(bid)) }) - it(`throws w/ missing field AMMID`, function () { - delete bid.AMMID - assert.throws( - () => validate(bid), - ValidationError, - 'AMMBid: missing field AMMID', - ) - }) - - it(`throws w/ AMMID must be a string`, function () { - bid.AMMID = 1234 - assert.throws( - () => validate(bid), - ValidationError, - 'AMMBid: AMMID must be a string', - ) - }) - it(`throws w/ MinBidPrice must be an Amount`, function () { bid.MinBidPrice = 5 assert.throws( diff --git a/packages/xrpl/test/models/AMMDeposit.ts b/packages/xrpl/test/models/AMMDeposit.ts index 00a37440a5..853c22664f 100644 --- a/packages/xrpl/test/models/AMMDeposit.ts +++ b/packages/xrpl/test/models/AMMDeposit.ts @@ -18,7 +18,6 @@ describe('AMMDeposit', function () { deposit = { TransactionType: 'AMMDeposit', Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', Sequence: 1337, } as any }) @@ -51,24 +50,6 @@ describe('AMMDeposit', function () { assert.doesNotThrow(() => validate(deposit)) }) - it(`throws w/ missing AMMID`, function () { - delete deposit.AMMID - assert.throws( - () => validate(deposit), - ValidationError, - 'AMMDeposit: missing field AMMID', - ) - }) - - it(`throws w/ AMMID must be a string`, function () { - deposit.AMMID = 1234 - assert.throws( - () => validate(deposit), - ValidationError, - 'AMMDeposit: AMMID must be a string', - ) - }) - it(`throws w/ must set at least LPTokenOut or Amount`, function () { assert.throws( () => validate(deposit), diff --git a/packages/xrpl/test/models/AMMVote.ts b/packages/xrpl/test/models/AMMVote.ts index 962680522a..ae625841ca 100644 --- a/packages/xrpl/test/models/AMMVote.ts +++ b/packages/xrpl/test/models/AMMVote.ts @@ -13,7 +13,6 @@ describe('AMMVote', function () { vote = { TransactionType: 'AMMVote', Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', TradingFee: 25, Sequence: 1337, } as any @@ -23,24 +22,6 @@ describe('AMMVote', function () { assert.doesNotThrow(() => validate(vote)) }) - it(`throws w/ missing field AMMID`, function () { - delete vote.AMMID - assert.throws( - () => validate(vote), - ValidationError, - 'AMMVote: missing field AMMID', - ) - }) - - it(`throws w/ AMMID must be a string`, function () { - vote.AMMID = 1234 - assert.throws( - () => validate(vote), - ValidationError, - 'AMMVote: AMMID must be a string', - ) - }) - it(`throws w/ missing field TradingFee`, function () { delete vote.TradingFee assert.throws( diff --git a/packages/xrpl/test/models/AMMWithdraw.ts b/packages/xrpl/test/models/AMMWithdraw.ts index f8c51894a7..3231512530 100644 --- a/packages/xrpl/test/models/AMMWithdraw.ts +++ b/packages/xrpl/test/models/AMMWithdraw.ts @@ -18,7 +18,6 @@ describe('AMMWithdraw', function () { withdraw = { TransactionType: 'AMMWithdraw', Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - AMMID: '24BA86F99302CF124AB27311C831F5BFAA72C4625DDA65B7EDF346A60CC19883', Sequence: 1337, } as any }) @@ -51,24 +50,6 @@ describe('AMMWithdraw', function () { assert.doesNotThrow(() => validate(withdraw)) }) - it(`throws w/ missing AMMID`, function () { - delete withdraw.AMMID - assert.throws( - () => validate(withdraw), - ValidationError, - 'AMMWithdraw: missing field AMMID', - ) - }) - - it(`throws w/ AMMID must be a string`, function () { - withdraw.AMMID = 1234 - assert.throws( - () => validate(withdraw), - ValidationError, - 'AMMWithdraw: AMMID must be a string', - ) - }) - it(`throws w/ must set at least LPTokenIn or Amount`, function () { assert.throws( () => validate(withdraw), From 64d8a904f08b3463bddea8c9c64971398d257431 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 9 Nov 2022 13:37:20 -0500 Subject: [PATCH 41/93] add Deposit/Withdraw flags --- .../src/models/transactions/AMMDeposit.ts | 22 ++++++++++++++++ .../src/models/transactions/AMMWithdraw.ts | 26 +++++++++++++++++++ .../xrpl/src/models/transactions/index.ts | 12 +++++++-- packages/xrpl/src/models/utils/flags.ts | 26 +++++++++++++++++++ packages/xrpl/test/models/AMMDeposit.ts | 9 ++++++- packages/xrpl/test/models/AMMWithdraw.ts | 5 +++- 6 files changed, 96 insertions(+), 4 deletions(-) diff --git a/packages/xrpl/src/models/transactions/AMMDeposit.ts b/packages/xrpl/src/models/transactions/AMMDeposit.ts index 98008e435a..b321d5e11b 100644 --- a/packages/xrpl/src/models/transactions/AMMDeposit.ts +++ b/packages/xrpl/src/models/transactions/AMMDeposit.ts @@ -4,11 +4,33 @@ import { Amount, Issue, IssuedCurrencyAmount } from '../common' import { BaseTransaction, + GlobalFlags, isAmount, isIssuedCurrency, validateBaseTransaction, } from './common' +/** + * Enum representing values for AMMDeposit Transaction Flags. + * + * @category Transaction Flags + */ +export enum AMMDepositFlags { + tfLPToken = 0x00010000, + tfSingleAsset = 0x00080000, + tfTwoAsset = 0x00100000, + tfOneAssetLPToken = 0x00200000, + tfLimitLPToken = 0x00400000, +} + +export interface AMMDepositFlagsInterface extends GlobalFlags { + tfLPToken?: boolean + tfSingleAsset?: boolean + tfTwoAsset?: boolean + tfOneAssetLPToken?: boolean + tfLimitLPToken?: boolean +} + /** * AMMDeposit is the deposit transaction used to add liquidity to the AMM instance pool, * thus obtaining some share of the instance's pools in the form of LPTokenOut. diff --git a/packages/xrpl/src/models/transactions/AMMWithdraw.ts b/packages/xrpl/src/models/transactions/AMMWithdraw.ts index 41ac9dc1c0..d7ecefd5b1 100644 --- a/packages/xrpl/src/models/transactions/AMMWithdraw.ts +++ b/packages/xrpl/src/models/transactions/AMMWithdraw.ts @@ -4,11 +4,37 @@ import { Amount, Issue, IssuedCurrencyAmount } from '../common' import { BaseTransaction, + GlobalFlags, isAmount, isIssuedCurrency, validateBaseTransaction, } from './common' +/** + * Enum representing values for AMMWithdrawFlags Transaction Flags. + * + * @category Transaction Flags + */ +export enum AMMWithdrawFlags { + tfLPToken = 0x00010000, + tfWithdrawAll = 0x00020000, + tfOneAssetWithdrawAll = 0x00040000, + tfSingleAsset = 0x00080000, + tfTwoAsset = 0x00100000, + tfOneAssetLPToken = 0x00200000, + tfLimitLPToken = 0x00400000, +} + +export interface AMMWithdrawFlagsInterface extends GlobalFlags { + tfLPToken?: boolean + tfWithdrawAll?: boolean + tfOneAssetWithdrawAll?: boolean + tfSingleAsset?: boolean + tfTwoAsset?: boolean + tfOneAssetLPToken?: boolean + tfLimitLPToken?: boolean +} + /** * AMMWithdraw is the withdraw transaction used to remove liquidity from the AMM * instance pool, thus redeeming some share of the pools that one owns in the form diff --git a/packages/xrpl/src/models/transactions/index.ts b/packages/xrpl/src/models/transactions/index.ts index a9b5c26c3d..354b50ad3d 100644 --- a/packages/xrpl/src/models/transactions/index.ts +++ b/packages/xrpl/src/models/transactions/index.ts @@ -8,10 +8,18 @@ export { } from './accountSet' export { AccountDelete } from './accountDelete' export { AMMBid } from './AMMBid' -export { AMMDeposit } from './AMMDeposit' +export { + AMMDepositFlags, + AMMDepositFlagsInterface, + AMMDeposit, +} from './AMMDeposit' export { AMMCreate } from './AMMCreate' export { AMMVote } from './AMMVote' -export { AMMWithdraw } from './AMMWithdraw' +export { + AMMWithdrawFlags, + AMMWithdrawFlagsInterface, + AMMWithdraw, +} from './AMMWithdraw' export { CheckCancel } from './checkCancel' export { CheckCash } from './checkCash' export { CheckCreate } from './checkCreate' diff --git a/packages/xrpl/src/models/utils/flags.ts b/packages/xrpl/src/models/utils/flags.ts index f185c99b84..a410813002 100644 --- a/packages/xrpl/src/models/utils/flags.ts +++ b/packages/xrpl/src/models/utils/flags.ts @@ -10,6 +10,14 @@ import { AccountSetFlagsInterface, AccountSetTfFlags, } from '../transactions/accountSet' +import { + AMMDepositFlags, + AMMDepositFlagsInterface, +} from '../transactions/AMMDeposit' +import { + AMMWithdrawFlags, + AMMWithdrawFlagsInterface, +} from '../transactions/AMMWithdraw' import { GlobalFlags } from '../transactions/common' import { OfferCreateFlagsInterface, @@ -63,6 +71,12 @@ export function setTransactionFlagsToNumber(tx: Transaction): void { case 'AccountSet': tx.Flags = convertAccountSetFlagsToNumber(tx.Flags) return + case 'AMMDeposit': + tx.Flags = convertAMMDepositFlagsToNumber(tx.Flags) + return + case 'AMMWithdraw': + tx.Flags = convertAMMWithdrawFlagsToNumber(tx.Flags) + return case 'OfferCreate': tx.Flags = convertOfferCreateFlagsToNumber(tx.Flags) return @@ -86,6 +100,18 @@ function convertAccountSetFlagsToNumber( return reduceFlags(flags, AccountSetTfFlags) } +function convertAMMDepositFlagsToNumber( + flags: AMMDepositFlagsInterface, +): number { + return reduceFlags(flags, AMMDepositFlags) +} + +function convertAMMWithdrawFlagsToNumber( + flags: AMMWithdrawFlagsInterface, +): number { + return reduceFlags(flags, AMMWithdrawFlags) +} + function convertOfferCreateFlagsToNumber( flags: OfferCreateFlagsInterface, ): number { diff --git a/packages/xrpl/test/models/AMMDeposit.ts b/packages/xrpl/test/models/AMMDeposit.ts index 853c22664f..4fef86bc41 100644 --- a/packages/xrpl/test/models/AMMDeposit.ts +++ b/packages/xrpl/test/models/AMMDeposit.ts @@ -1,5 +1,6 @@ +/* eslint-disable no-bitwise -- bitwise necessary for enabling flags */ import { assert } from 'chai' -import { validate, ValidationError } from 'xrpl-local' +import { AMMDepositFlags, validate, ValidationError } from 'xrpl-local' /** * AMMDeposit Transaction Verification Testing. @@ -19,34 +20,40 @@ describe('AMMDeposit', function () { TransactionType: 'AMMDeposit', Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', Sequence: 1337, + Flags: 0, } as any }) it(`verifies valid AMMDeposit with LPTokenOut`, function () { deposit.LPTokenOut = LPTokenOut + deposit.Flags |= AMMDepositFlags.tfLPToken assert.doesNotThrow(() => validate(deposit)) }) it(`verifies valid AMMDeposit with Amount`, function () { deposit.Amount = '1000' + deposit.Flags |= AMMDepositFlags.tfSingleAsset assert.doesNotThrow(() => validate(deposit)) }) it(`verifies valid AMMDeposit with Amount and Amount2`, function () { deposit.Amount = '1000' deposit.Amount2 = '1000' + deposit.Flags |= AMMDepositFlags.tfTwoAsset assert.doesNotThrow(() => validate(deposit)) }) it(`verifies valid AMMDeposit with Amount and LPTokenOut`, function () { deposit.Amount = '1000' deposit.LPTokenOut = LPTokenOut + deposit.Flags |= AMMDepositFlags.tfOneAssetLPToken assert.doesNotThrow(() => validate(deposit)) }) it(`verifies valid AMMDeposit with Amount and EPrice`, function () { deposit.Amount = '1000' deposit.EPrice = '25' + deposit.Flags |= AMMDepositFlags.tfLimitLPToken assert.doesNotThrow(() => validate(deposit)) }) diff --git a/packages/xrpl/test/models/AMMWithdraw.ts b/packages/xrpl/test/models/AMMWithdraw.ts index 3231512530..ae7a984df8 100644 --- a/packages/xrpl/test/models/AMMWithdraw.ts +++ b/packages/xrpl/test/models/AMMWithdraw.ts @@ -1,5 +1,6 @@ +/* eslint-disable no-bitwise -- bitwise necessary for enabling flags */ import { assert } from 'chai' -import { validate, ValidationError } from 'xrpl-local' +import { AMMWithdrawFlags, validate, ValidationError } from 'xrpl-local' /** * AMMWithdraw Transaction Verification Testing. @@ -19,6 +20,7 @@ describe('AMMWithdraw', function () { TransactionType: 'AMMWithdraw', Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', Sequence: 1337, + Flags: 0, } as any }) @@ -29,6 +31,7 @@ describe('AMMWithdraw', function () { it(`verifies valid AMMWithdraw with Amount`, function () { withdraw.Amount = '1000' + withdraw.Flags |= AMMWithdrawFlags.tfSingleAsset assert.doesNotThrow(() => validate(withdraw)) }) From bcdd8fe2cf8810f350dd84829875b715a1b2147f Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 9 Nov 2022 14:59:12 -0500 Subject: [PATCH 42/93] rename FeeVal -> TradingFee in VoteEntry --- packages/xrpl/src/models/methods/ammInfo.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index 7a966122d8..0448148c01 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -30,7 +30,7 @@ export interface AMMInfoRequest extends BaseRequest { } interface VoteEntry { - FeeVal: number + TradingFee: number VoteWeight: number } From eba8bd2ec1d9ecc4647ba5bc10db74900ba2ba55 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 9 Nov 2022 15:09:33 -0500 Subject: [PATCH 43/93] rename MinBidPrice -> BidMin and MaxBidPrice -> BidMax --- .../src/enums/definitions.json | 4 ++-- packages/xrpl/src/models/transactions/AMMBid.ts | 14 +++++++------- packages/xrpl/test/models/AMMBid.ts | 16 ++++++++-------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/ripple-binary-codec/src/enums/definitions.json b/packages/ripple-binary-codec/src/enums/definitions.json index 55bbac88a7..b9aa434c77 100644 --- a/packages/ripple-binary-codec/src/enums/definitions.json +++ b/packages/ripple-binary-codec/src/enums/definitions.json @@ -1454,7 +1454,7 @@ } ], [ - "MinBidPrice", + "BidMin", { "nth": 12, "isVLEncoded": false, @@ -1464,7 +1464,7 @@ } ], [ - "MaxBidPrice", + "BidMax", { "nth": 13, "isVLEncoded": false, diff --git a/packages/xrpl/src/models/transactions/AMMBid.ts b/packages/xrpl/src/models/transactions/AMMBid.ts index 7cdd09cc14..4e6469b1d8 100644 --- a/packages/xrpl/src/models/transactions/AMMBid.ts +++ b/packages/xrpl/src/models/transactions/AMMBid.ts @@ -32,17 +32,17 @@ export interface AMMBid extends BaseTransaction { /** * This field represents the minimum price that the bidder wants to pay for the slot. - * It is specified in units of LPToken. If specified let MinBidPrice be X and let + * It is specified in units of LPToken. If specified let BidMin be X and let * the slot-price computed by price scheduling algorithm be Y, then bidder always pays * the max(X, Y). */ - MinBidPrice?: Amount + BidMin?: Amount /** * This field represents the maximum price that the bidder wants to pay for the slot. * It is specified in units of LPToken. */ - MaxBidPrice?: Amount + BidMax?: Amount /** * This field represents an array of XRPL account IDs that are authorized to trade @@ -61,12 +61,12 @@ export interface AMMBid extends BaseTransaction { export function validateAMMBid(tx: Record): void { validateBaseTransaction(tx) - if (tx.MinBidPrice != null && !isAmount(tx.MinBidPrice)) { - throw new ValidationError('AMMBid: MinBidPrice must be an Amount') + if (tx.BidMin != null && !isAmount(tx.BidMin)) { + throw new ValidationError('AMMBid: BidMin must be an Amount') } - if (tx.MaxBidPrice != null && !isAmount(tx.MaxBidPrice)) { - throw new ValidationError('AMMBid: MaxBidPrice must be an Amount') + if (tx.BidMax != null && !isAmount(tx.BidMax)) { + throw new ValidationError('AMMBid: BidMax must be an Amount') } if (tx.AuthAccounts != null) { diff --git a/packages/xrpl/test/models/AMMBid.ts b/packages/xrpl/test/models/AMMBid.ts index 121a698f00..d41545476c 100644 --- a/packages/xrpl/test/models/AMMBid.ts +++ b/packages/xrpl/test/models/AMMBid.ts @@ -13,8 +13,8 @@ describe('AMMBid', function () { bid = { TransactionType: 'AMMBid', Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', - MinBidPrice: '5', - MaxBidPrice: '10', + BidMin: '5', + BidMax: '10', AuthAccounts: [ { AuthAccount: { @@ -45,21 +45,21 @@ describe('AMMBid', function () { assert.doesNotThrow(() => validate(bid)) }) - it(`throws w/ MinBidPrice must be an Amount`, function () { - bid.MinBidPrice = 5 + it(`throws w/ BidMin must be an Amount`, function () { + bid.BidMin = 5 assert.throws( () => validate(bid), ValidationError, - 'AMMBid: MinBidPrice must be an Amount', + 'AMMBid: BidMin must be an Amount', ) }) - it(`throws w/ MaxBidPrice must be an Amount`, function () { - bid.MaxBidPrice = 10 + it(`throws w/ BidMax must be an Amount`, function () { + bid.BidMax = 10 assert.throws( () => validate(bid), ValidationError, - 'AMMBid: MaxBidPrice must be an Amount', + 'AMMBid: BidMax must be an Amount', ) }) From 1c26e8b6d53ae76b72b2bf8951a6b3030ca423b4 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 9 Nov 2022 15:20:37 -0500 Subject: [PATCH 44/93] update definitions to change Asset & Asset2 nth values to 3 & 4 --- packages/ripple-binary-codec/src/enums/definitions.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ripple-binary-codec/src/enums/definitions.json b/packages/ripple-binary-codec/src/enums/definitions.json index b9aa434c77..c9d2c49452 100644 --- a/packages/ripple-binary-codec/src/enums/definitions.json +++ b/packages/ripple-binary-codec/src/enums/definitions.json @@ -1966,7 +1966,7 @@ [ "Asset", { - "nth": 1, + "nth": 3, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -1976,7 +1976,7 @@ [ "Asset2", { - "nth": 2, + "nth": 4, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, From 40388cc1e58bcb9042417147a98dd2105dddedd2 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 16 Nov 2022 14:02:24 -0500 Subject: [PATCH 45/93] update definitions --- .../src/enums/definitions.json | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/packages/ripple-binary-codec/src/enums/definitions.json b/packages/ripple-binary-codec/src/enums/definitions.json index c9d2c49452..ab3bc26fac 100644 --- a/packages/ripple-binary-codec/src/enums/definitions.json +++ b/packages/ripple-binary-codec/src/enums/definitions.json @@ -1013,26 +1013,6 @@ "type": "Hash160" } ], - [ - "TokenCurrency", - { - "nth": 5, - "isVLEncoded": false, - "isSerialized": true, - "isSigningField": true, - "type": "Hash160" - } - ], - [ - "TokenIssuer", - { - "nth": 6, - "isVLEncoded": false, - "isSerialized": true, - "isSigningField": true, - "type": "Hash160" - } - ], [ "LedgerHash", { From 0574fabf47ea71f797e530bb059e0f4051f414fb Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 16 Nov 2022 20:58:57 -0500 Subject: [PATCH 46/93] add Issue type and tests for Asset/Asset2 --- .../ripple-binary-codec/src/types/index.ts | 2 + .../ripple-binary-codec/src/types/issue.ts | 96 +++++++++++++++++++ .../xrpl/src/models/transactions/AMMBid.ts | 23 ++++- .../src/models/transactions/AMMDeposit.ts | 17 ++++ .../xrpl/src/models/transactions/AMMVote.ts | 18 +++- .../src/models/transactions/AMMWithdraw.ts | 17 ++++ .../xrpl/src/models/transactions/common.ts | 21 +++- packages/xrpl/test/models/AMMBid.ts | 43 +++++++++ packages/xrpl/test/models/AMMDeposit.ts | 55 ++++++++++- packages/xrpl/test/models/AMMVote.ts | 43 +++++++++ packages/xrpl/test/models/AMMWithdraw.ts | 55 ++++++++++- 11 files changed, 383 insertions(+), 7 deletions(-) create mode 100644 packages/ripple-binary-codec/src/types/issue.ts diff --git a/packages/ripple-binary-codec/src/types/index.ts b/packages/ripple-binary-codec/src/types/index.ts index 5efa199a5a..aa0c280e7a 100644 --- a/packages/ripple-binary-codec/src/types/index.ts +++ b/packages/ripple-binary-codec/src/types/index.ts @@ -11,6 +11,7 @@ import { Currency } from './currency' import { Hash128 } from './hash-128' import { Hash160 } from './hash-160' import { Hash256 } from './hash-256' +import { Issue } from './issue' import { PathSet } from './path-set' import { STArray } from './st-array' import { STObject } from './st-object' @@ -28,6 +29,7 @@ const coreTypes = { Hash128, Hash160, Hash256, + Issue, PathSet, STArray, STObject, diff --git a/packages/ripple-binary-codec/src/types/issue.ts b/packages/ripple-binary-codec/src/types/issue.ts new file mode 100644 index 0000000000..29bd160b2c --- /dev/null +++ b/packages/ripple-binary-codec/src/types/issue.ts @@ -0,0 +1,96 @@ +import { BinaryParser } from '../serdes/binary-parser' + +import { AccountID } from './account-id' +import { Currency } from './currency' +import { JsonObject, SerializedType } from './serialized-type' +import { Buffer } from 'buffer/' + +/** + * Interface for JSON objects that represent amounts + */ +interface IssueObject extends JsonObject { + currency: string + issuer?: string +} + +/** + * Type guard for AmountObject + */ +function isIssueObject(arg): arg is IssueObject { + const keys = Object.keys(arg).sort() + if (keys.length === 1) { + return keys[0] === 'currency' + } + return keys.length === 2 && keys[0] === 'currency' && keys[1] === 'issuer' +} + +/** + * Class for serializing/Deserializing Amounts + */ +class Issue extends SerializedType { + static readonly ZERO_ISSUED_CURRENCY: Issue = new Issue(Buffer.alloc(20)) + + constructor(bytes: Buffer) { + super(bytes ?? Issue.ZERO_ISSUED_CURRENCY.bytes) + } + + /** + * Construct an amount from an IOU or string amount + * + * @param value An Amount, object representing an IOU, or a string + * representing an integer amount + * @returns An Amount object + */ + static from(value: T): Issue { + if (value instanceof Issue) { + return value + } + + if (isIssueObject(value)) { + const currency = Currency.from(value.currency).toBytes() + if (value.issuer == null) { + return new Issue(currency) + } + const issuer = AccountID.from(value.issuer).toBytes() + return new Issue(Buffer.concat([currency, issuer])) + } + + throw new Error('Invalid type to construct an Amount') + } + + /** + * Read an amount from a BinaryParser + * + * @param parser BinaryParser to read the Amount from + * @returns An Amount object + */ + static fromParser(parser: BinaryParser): Issue { + const currency = parser.read(20) + if (new Currency(currency).toJSON() === 'XRP') { + return new Issue(currency) + } + const currencyAndIssuer = [currency, parser.read(20)] + return new Issue(Buffer.concat(currencyAndIssuer)) + } + + /** + * Get the JSON representation of this Amount + * + * @returns the JSON interpretation of this.bytes + */ + toJSON(): IssueObject { + const parser = new BinaryParser(this.toString()) + const currency = Currency.fromParser(parser) as Currency + if (currency.toJSON() === 'XRP') { + return { currency: currency.toJSON() } + } + const issuer = AccountID.fromParser(parser) as AccountID + + return { + currency: currency.toJSON(), + issuer: issuer.toJSON(), + } + } +} + +export { Issue, IssueObject } diff --git a/packages/xrpl/src/models/transactions/AMMBid.ts b/packages/xrpl/src/models/transactions/AMMBid.ts index 4e6469b1d8..70ef4222f8 100644 --- a/packages/xrpl/src/models/transactions/AMMBid.ts +++ b/packages/xrpl/src/models/transactions/AMMBid.ts @@ -1,7 +1,12 @@ import { ValidationError } from '../../errors' import { Amount, Issue } from '../common' -import { BaseTransaction, isAmount, validateBaseTransaction } from './common' +import { + BaseTransaction, + isAmount, + isIssue, + validateBaseTransaction, +} from './common' const MAX_AUTH_ACCOUNTS = 4 @@ -61,6 +66,22 @@ export interface AMMBid extends BaseTransaction { export function validateAMMBid(tx: Record): void { validateBaseTransaction(tx) + if (tx.Asset == null) { + throw new ValidationError('AMMBid: missing field Asset') + } + + if (!isIssue(tx.Asset)) { + throw new ValidationError('AMMBid: Asset must be an Issue') + } + + if (tx.Asset2 == null) { + throw new ValidationError('AMMBid: missing field Asset2') + } + + if (!isIssue(tx.Asset2)) { + throw new ValidationError('AMMBid: Asset2 must be an Issue') + } + if (tx.BidMin != null && !isAmount(tx.BidMin)) { throw new ValidationError('AMMBid: BidMin must be an Amount') } diff --git a/packages/xrpl/src/models/transactions/AMMDeposit.ts b/packages/xrpl/src/models/transactions/AMMDeposit.ts index b321d5e11b..0770d33886 100644 --- a/packages/xrpl/src/models/transactions/AMMDeposit.ts +++ b/packages/xrpl/src/models/transactions/AMMDeposit.ts @@ -6,6 +6,7 @@ import { BaseTransaction, GlobalFlags, isAmount, + isIssue, isIssuedCurrency, validateBaseTransaction, } from './common' @@ -88,6 +89,22 @@ export interface AMMDeposit extends BaseTransaction { export function validateAMMDeposit(tx: Record): void { validateBaseTransaction(tx) + if (tx.Asset == null) { + throw new ValidationError('AMMDeposit: missing field Asset') + } + + if (!isIssue(tx.Asset)) { + throw new ValidationError('AMMDeposit: Asset must be an Issue') + } + + if (tx.Asset2 == null) { + throw new ValidationError('AMMDeposit: missing field Asset2') + } + + if (!isIssue(tx.Asset2)) { + throw new ValidationError('AMMDeposit: Asset2 must be an Issue') + } + if (tx.Amount2 != null && tx.Amount == null) { throw new ValidationError('AMMDeposit: must set Amount with Amount2') } else if (tx.EPrice != null && tx.Amount == null) { diff --git a/packages/xrpl/src/models/transactions/AMMVote.ts b/packages/xrpl/src/models/transactions/AMMVote.ts index 38324ec6d6..ce33acfe7b 100644 --- a/packages/xrpl/src/models/transactions/AMMVote.ts +++ b/packages/xrpl/src/models/transactions/AMMVote.ts @@ -2,7 +2,7 @@ import { ValidationError } from '../../errors' import { Issue } from '../common' import { AMM_MAX_TRADING_FEE } from './AMMCreate' -import { BaseTransaction, validateBaseTransaction } from './common' +import { BaseTransaction, isIssue, validateBaseTransaction } from './common' /** * AMMVote is used for submitting a vote for the trading fee of an AMM Instance. @@ -41,6 +41,22 @@ export interface AMMVote extends BaseTransaction { export function validateAMMVote(tx: Record): void { validateBaseTransaction(tx) + if (tx.Asset == null) { + throw new ValidationError('AMMVote: missing field Asset') + } + + if (!isIssue(tx.Asset)) { + throw new ValidationError('AMMVote: Asset must be an Issue') + } + + if (tx.Asset2 == null) { + throw new ValidationError('AMMVote: missing field Asset2') + } + + if (!isIssue(tx.Asset2)) { + throw new ValidationError('AMMVote: Asset2 must be an Issue') + } + if (tx.TradingFee == null) { throw new ValidationError('AMMVote: missing field TradingFee') } diff --git a/packages/xrpl/src/models/transactions/AMMWithdraw.ts b/packages/xrpl/src/models/transactions/AMMWithdraw.ts index d7ecefd5b1..eac8d2186b 100644 --- a/packages/xrpl/src/models/transactions/AMMWithdraw.ts +++ b/packages/xrpl/src/models/transactions/AMMWithdraw.ts @@ -6,6 +6,7 @@ import { BaseTransaction, GlobalFlags, isAmount, + isIssue, isIssuedCurrency, validateBaseTransaction, } from './common' @@ -94,6 +95,22 @@ export interface AMMWithdraw extends BaseTransaction { export function validateAMMWithdraw(tx: Record): void { validateBaseTransaction(tx) + if (tx.Asset == null) { + throw new ValidationError('AMMWithdraw: missing field Asset') + } + + if (!isIssue(tx.Asset)) { + throw new ValidationError('AMMWithdraw: Asset must be an Issue') + } + + if (tx.Asset2 == null) { + throw new ValidationError('AMMWithdraw: missing field Asset2') + } + + if (!isIssue(tx.Asset2)) { + throw new ValidationError('AMMWithdraw: Asset2 must be an Issue') + } + if (tx.Amount2 != null && tx.Amount == null) { throw new ValidationError('AMMWithdraw: must set Amount with Amount2') } else if (tx.EPrice != null && tx.Amount == null) { diff --git a/packages/xrpl/src/models/transactions/common.ts b/packages/xrpl/src/models/transactions/common.ts index 498a2d748e..bd330b7b92 100644 --- a/packages/xrpl/src/models/transactions/common.ts +++ b/packages/xrpl/src/models/transactions/common.ts @@ -4,7 +4,7 @@ import { TRANSACTION_TYPES } from 'ripple-binary-codec' import { ValidationError } from '../../errors' -import { Amount, IssuedCurrencyAmount, Memo, Signer } from '../common' +import { Amount, Issue, IssuedCurrencyAmount, Memo, Signer } from '../common' import { onlyHasFields } from '../utils' const MEMO_SIZE = 3 @@ -84,6 +84,25 @@ export function isAmount(amount: unknown): amount is Amount { return typeof amount === 'string' || isIssuedCurrency(amount) } +/** + * Verify the form and type of an Issue at runtime. + * + * @param input - The object to check the form and type of. + * @returns Whether the Issue is malformed. + */ +export function isIssue(input: unknown): input is Issue { + if (!isRecord(input)) { + return false + } + const length = Object.keys(input).length + return ( + (length === 1 && input.currency === 'XRP') || + (length === 2 && + typeof input.currency === 'string' && + typeof input.issuer === 'string') + ) +} + // eslint-disable-next-line @typescript-eslint/no-empty-interface -- no global flags right now, so this is fine export interface GlobalFlags {} diff --git a/packages/xrpl/test/models/AMMBid.ts b/packages/xrpl/test/models/AMMBid.ts index d41545476c..834bf34daf 100644 --- a/packages/xrpl/test/models/AMMBid.ts +++ b/packages/xrpl/test/models/AMMBid.ts @@ -13,6 +13,13 @@ describe('AMMBid', function () { bid = { TransactionType: 'AMMBid', Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + Asset: { + currency: 'XRP', + }, + Asset2: { + currency: 'ETH', + issuer: 'rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd', + }, BidMin: '5', BidMax: '10', AuthAccounts: [ @@ -45,6 +52,42 @@ describe('AMMBid', function () { assert.doesNotThrow(() => validate(bid)) }) + it(`throws w/ missing field Asset`, function () { + delete bid.Asset + assert.throws( + () => validate(bid), + ValidationError, + 'AMMBid: missing field Asset', + ) + }) + + it(`throws w/ Asset must be an Issue`, function () { + bid.Asset = 1234 + assert.throws( + () => validate(bid), + ValidationError, + 'AMMBid: Asset must be an Issue', + ) + }) + + it(`throws w/ missing field Asset2`, function () { + delete bid.Asset2 + assert.throws( + () => validate(bid), + ValidationError, + 'AMMBid: missing field Asset2', + ) + }) + + it(`throws w/ Asset2 must be an Issue`, function () { + bid.Asset2 = 1234 + assert.throws( + () => validate(bid), + ValidationError, + 'AMMBid: Asset2 must be an Issue', + ) + }) + it(`throws w/ BidMin must be an Amount`, function () { bid.BidMin = 5 assert.throws( diff --git a/packages/xrpl/test/models/AMMDeposit.ts b/packages/xrpl/test/models/AMMDeposit.ts index 4fef86bc41..f7b65fd31a 100644 --- a/packages/xrpl/test/models/AMMDeposit.ts +++ b/packages/xrpl/test/models/AMMDeposit.ts @@ -19,6 +19,13 @@ describe('AMMDeposit', function () { deposit = { TransactionType: 'AMMDeposit', Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + Asset: { + currency: 'XRP', + }, + Asset2: { + currency: 'ETH', + issuer: 'rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd', + }, Sequence: 1337, Flags: 0, } as any @@ -38,7 +45,11 @@ describe('AMMDeposit', function () { it(`verifies valid AMMDeposit with Amount and Amount2`, function () { deposit.Amount = '1000' - deposit.Amount2 = '1000' + deposit.Amount2 = { + currency: 'ETH', + issuer: 'rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd', + value: '2.5', + } deposit.Flags |= AMMDepositFlags.tfTwoAsset assert.doesNotThrow(() => validate(deposit)) }) @@ -57,6 +68,42 @@ describe('AMMDeposit', function () { assert.doesNotThrow(() => validate(deposit)) }) + it(`throws w/ missing field Asset`, function () { + delete deposit.Asset + assert.throws( + () => validate(deposit), + ValidationError, + 'AMMDeposit: missing field Asset', + ) + }) + + it(`throws w/ Asset must be an Issue`, function () { + deposit.Asset = 1234 + assert.throws( + () => validate(deposit), + ValidationError, + 'AMMDeposit: Asset must be an Issue', + ) + }) + + it(`throws w/ missing field Asset2`, function () { + delete deposit.Asset2 + assert.throws( + () => validate(deposit), + ValidationError, + 'AMMDeposit: missing field Asset2', + ) + }) + + it(`throws w/ Asset2 must be an Issue`, function () { + deposit.Asset2 = 1234 + assert.throws( + () => validate(deposit), + ValidationError, + 'AMMDeposit: Asset2 must be an Issue', + ) + }) + it(`throws w/ must set at least LPTokenOut or Amount`, function () { assert.throws( () => validate(deposit), @@ -66,7 +113,11 @@ describe('AMMDeposit', function () { }) it(`throws w/ must set Amount with Amount2`, function () { - deposit.Amount2 = '500' + deposit.Amount2 = { + currency: 'ETH', + issuer: 'rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd', + value: '2.5', + } assert.throws( () => validate(deposit), ValidationError, diff --git a/packages/xrpl/test/models/AMMVote.ts b/packages/xrpl/test/models/AMMVote.ts index ae625841ca..f00350b402 100644 --- a/packages/xrpl/test/models/AMMVote.ts +++ b/packages/xrpl/test/models/AMMVote.ts @@ -13,6 +13,13 @@ describe('AMMVote', function () { vote = { TransactionType: 'AMMVote', Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + Asset: { + currency: 'XRP', + }, + Asset2: { + currency: 'ETH', + issuer: 'rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd', + }, TradingFee: 25, Sequence: 1337, } as any @@ -22,6 +29,42 @@ describe('AMMVote', function () { assert.doesNotThrow(() => validate(vote)) }) + it(`throws w/ missing field Asset`, function () { + delete vote.Asset + assert.throws( + () => validate(vote), + ValidationError, + 'AMMVote: missing field Asset', + ) + }) + + it(`throws w/ Asset must be an Issue`, function () { + vote.Asset = 1234 + assert.throws( + () => validate(vote), + ValidationError, + 'AMMVote: Asset must be an Issue', + ) + }) + + it(`throws w/ missing field Asset2`, function () { + delete vote.Asset2 + assert.throws( + () => validate(vote), + ValidationError, + 'AMMVote: missing field Asset2', + ) + }) + + it(`throws w/ Asset2 must be an Issue`, function () { + vote.Asset2 = 1234 + assert.throws( + () => validate(vote), + ValidationError, + 'AMMVote: Asset2 must be an Issue', + ) + }) + it(`throws w/ missing field TradingFee`, function () { delete vote.TradingFee assert.throws( diff --git a/packages/xrpl/test/models/AMMWithdraw.ts b/packages/xrpl/test/models/AMMWithdraw.ts index ae7a984df8..d14b1aac07 100644 --- a/packages/xrpl/test/models/AMMWithdraw.ts +++ b/packages/xrpl/test/models/AMMWithdraw.ts @@ -19,6 +19,13 @@ describe('AMMWithdraw', function () { withdraw = { TransactionType: 'AMMWithdraw', Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + Asset: { + currency: 'XRP', + }, + Asset2: { + currency: 'ETH', + issuer: 'rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd', + }, Sequence: 1337, Flags: 0, } as any @@ -37,7 +44,11 @@ describe('AMMWithdraw', function () { it(`verifies valid AMMWithdraw with Amount and Amount2`, function () { withdraw.Amount = '1000' - withdraw.Amount2 = '1000' + withdraw.Amount2 = { + currency: 'ETH', + issuer: 'rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd', + value: '2.5', + } assert.doesNotThrow(() => validate(withdraw)) }) @@ -53,6 +64,42 @@ describe('AMMWithdraw', function () { assert.doesNotThrow(() => validate(withdraw)) }) + it(`throws w/ missing field Asset`, function () { + delete withdraw.Asset + assert.throws( + () => validate(withdraw), + ValidationError, + 'AMMWithdraw: missing field Asset', + ) + }) + + it(`throws w/ Asset must be an Issue`, function () { + withdraw.Asset = 1234 + assert.throws( + () => validate(withdraw), + ValidationError, + 'AMMWithdraw: Asset must be an Issue', + ) + }) + + it(`throws w/ missing field Asset2`, function () { + delete withdraw.Asset2 + assert.throws( + () => validate(withdraw), + ValidationError, + 'AMMWithdraw: missing field Asset2', + ) + }) + + it(`throws w/ Asset2 must be an Issue`, function () { + withdraw.Asset2 = 1234 + assert.throws( + () => validate(withdraw), + ValidationError, + 'AMMWithdraw: Asset2 must be an Issue', + ) + }) + it(`throws w/ must set at least LPTokenIn or Amount`, function () { assert.throws( () => validate(withdraw), @@ -62,7 +109,11 @@ describe('AMMWithdraw', function () { }) it(`throws w/ must set Amount with Amount2`, function () { - withdraw.Amount2 = '500' + withdraw.Amount2 = { + currency: 'ETH', + issuer: 'rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd', + value: '2.5', + } assert.throws( () => validate(withdraw), ValidationError, From 64e4242085a9d49f6f6a31381bb4e7d438ba589c Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 16 Nov 2022 21:03:08 -0500 Subject: [PATCH 47/93] remove AMMID from amm_info and use Issue type --- packages/xrpl/src/models/methods/ammInfo.ts | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index 0448148c01..5f014ad428 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -1,4 +1,4 @@ -import { Amount, Currency, IssuedCurrencyAmount } from '../common' +import { Issue, IssuedCurrencyAmount } from '../common' import { BaseRequest, BaseResponse } from './baseMethod' @@ -11,22 +11,17 @@ import { BaseRequest, BaseResponse } from './baseMethod' export interface AMMInfoRequest extends BaseRequest { command: 'amm_info' - /** - * A hash that uniquely identifies the AMM instance. - */ - amm_id?: string - /** * Specifies one of the pool assets (XRP or token) of the AMM instance. * Both asset and asset2 must be defined to specify an AMM instance. */ - asset?: Currency + asset?: Issue /** * Specifies the other pool asset of the AMM instance. * Both asset and asset2 must be defined to specify an AMM instance. */ - asset2?: Currency + asset2?: Issue } interface VoteEntry { @@ -49,12 +44,12 @@ export interface AMMInfoResponse extends BaseResponse { /** * Specifies one of the pool assets (XRP or token) of the AMM instance. */ - Asset: Amount + Asset: Issue /** * Specifies the other pool asset of the AMM instance. */ - Asset2: Amount + Asset2: Issue /** * Represents the liquidity providers' shares of the AMM instance's pools. @@ -73,11 +68,6 @@ export interface AMMInfoResponse extends BaseResponse { */ TradingFee: number - /** - * A hash that uniquely identifies the AMM instance. - */ - AMMID?: string - /** * Keeps a track of up to eight active votes for the instance. */ From e32db9dd39d5b4b3c1593024ad81474b38eb3c16 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 16 Nov 2022 21:21:21 -0500 Subject: [PATCH 48/93] update amm_info fields --- packages/xrpl/src/models/methods/ammInfo.ts | 55 ++++++++++++++++++--- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index 5f014ad428..2ba30ebcf7 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -1,4 +1,4 @@ -import { Issue, IssuedCurrencyAmount } from '../common' +import { Amount, Issue, IssuedCurrencyAmount } from '../common' import { BaseRequest, BaseResponse } from './baseMethod' @@ -24,9 +24,18 @@ export interface AMMInfoRequest extends BaseRequest { asset2?: Issue } +interface AuthAccount { + AuthAccount: { + Account: string + } +} + interface VoteEntry { - TradingFee: number - VoteWeight: number + VoteEntry: { + Account: string + TradingFee: number + VoteWeight: number + } } /** @@ -52,12 +61,42 @@ export interface AMMInfoResponse extends BaseResponse { Asset2: Issue /** - * Represents the liquidity providers' shares of the AMM instance's pools. - * LPTokens are tokens on XRPL. Each LPToken represents a proportional share of each pool of the AMM instance. - * The AMM instance account issues the LPTokens to LPs upon liquidity provision. - * LPTokens are balanced in the LPs trustline upon liquidity removal. + * Details of the current owner of the auction slot. + */ + AuctionSlot?: { + /** + * The current owner of this auction slot. + */ + Account: string + + /** + * A list of at most 4 additional accounts that are authorized to trade at the discounted fee for this AMM instance. + */ + AuthAccounts: AuthAccount[] + + /** + * The trading fee to be charged to the auction owner, in the same format as TradingFee. + * By default this is 0, meaning that the auction owner can trade at no fee instead of the standard fee for this AMM. + */ + DiscountedFee: number + + /** + * The time when this slot expires, in seconds since the Ripple Epoch. + */ + Expiration: string + + /** + * The amount the auction owner paid to win this slot, in LPTokens. + */ + Price: Amount + } + + /** + * The total outstanding balance of liquidity provider tokens from this AMM instance. + * The holders of these tokens can vote on the AMM's trading fee in proportion to their holdings, + * or redeem the tokens for a share of the AMM's assets which grows with the trading fees collected. */ - LPToken: IssuedCurrencyAmount + LPTokenBalance: IssuedCurrencyAmount /** * Specifies the fee, in basis point, to be charged to the traders for the trades From ff65441d3317ea9f88131335f4969ed5f9f0fd63 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 16 Nov 2022 21:24:40 -0500 Subject: [PATCH 49/93] fix lint errors --- packages/xrpl/src/models/methods/ammInfo.ts | 2 +- packages/xrpl/src/models/transactions/AMMBid.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index 2ba30ebcf7..68eeb7a06b 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -92,7 +92,7 @@ export interface AMMInfoResponse extends BaseResponse { } /** - * The total outstanding balance of liquidity provider tokens from this AMM instance. + * The total outstanding balance of liquidity provider tokens from this AMM instance. * The holders of these tokens can vote on the AMM's trading fee in proportion to their holdings, * or redeem the tokens for a share of the AMM's assets which grows with the trading fees collected. */ diff --git a/packages/xrpl/src/models/transactions/AMMBid.ts b/packages/xrpl/src/models/transactions/AMMBid.ts index 70ef4222f8..1a6ec81055 100644 --- a/packages/xrpl/src/models/transactions/AMMBid.ts +++ b/packages/xrpl/src/models/transactions/AMMBid.ts @@ -1,3 +1,4 @@ +/* eslint-disable complexity -- required for validateAMMBid */ import { ValidationError } from '../../errors' import { Amount, Issue } from '../common' From 434ad71672bc5ea76bfa764204b43f7503d7d490 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Thu, 17 Nov 2022 09:34:40 -0500 Subject: [PATCH 50/93] update unit tests --- packages/xrpl/test/models/AMMWithdraw.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/xrpl/test/models/AMMWithdraw.ts b/packages/xrpl/test/models/AMMWithdraw.ts index d14b1aac07..153766f8b5 100644 --- a/packages/xrpl/test/models/AMMWithdraw.ts +++ b/packages/xrpl/test/models/AMMWithdraw.ts @@ -33,6 +33,7 @@ describe('AMMWithdraw', function () { it(`verifies valid AMMWithdraw with LPTokenIn`, function () { withdraw.LPTokenIn = LPTokenIn + withdraw.Flags |= AMMWithdrawFlags.tfLPToken assert.doesNotThrow(() => validate(withdraw)) }) @@ -49,18 +50,21 @@ describe('AMMWithdraw', function () { issuer: 'rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd', value: '2.5', } + withdraw.Flags |= AMMWithdrawFlags.tfTwoAsset assert.doesNotThrow(() => validate(withdraw)) }) it(`verifies valid AMMWithdraw with Amount and LPTokenIn`, function () { withdraw.Amount = '1000' withdraw.LPTokenIn = LPTokenIn + withdraw.Flags |= AMMWithdrawFlags.tfOneAssetLPToken assert.doesNotThrow(() => validate(withdraw)) }) it(`verifies valid AMMWithdraw with Amount and EPrice`, function () { withdraw.Amount = '1000' withdraw.EPrice = '25' + withdraw.Flags |= AMMWithdrawFlags.tfLimitLPToken assert.doesNotThrow(() => validate(withdraw)) }) From 09707537901eb29a2460fb2a993b5c06ecda0418 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Thu, 17 Nov 2022 13:14:25 -0500 Subject: [PATCH 51/93] add AMM codec-fixtures --- .../test/fixtures/codec-fixtures.json | 209 +++++++++++++++++- 1 file changed, 208 insertions(+), 1 deletion(-) diff --git a/packages/ripple-binary-codec/test/fixtures/codec-fixtures.json b/packages/ripple-binary-codec/test/fixtures/codec-fixtures.json index 15aa20f198..5758dbf5b5 100644 --- a/packages/ripple-binary-codec/test/fixtures/codec-fixtures.json +++ b/packages/ripple-binary-codec/test/fixtures/codec-fixtures.json @@ -4448,6 +4448,213 @@ "Flags": 0, "Sequence": 62 } + }, + { + "binary": "12002315000A220000000024000000026140000000000027106840000000000000016BD5838D7EA4C680000000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C7321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D07440913E39EC2BA0E5BC4C5DF1222B1AE9E76758F2B8FFEF1F056076147BB0ADC8117CD0296360DA08B3D48BE9EFC8693C03A253E0D9F166C19CA8D936F9E61A1100811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E", + "json": { + "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "TransactionType": "AMMCreate", + "TxnSignature": "913E39EC2BA0E5BC4C5DF1222B1AE9E76758F2B8FFEF1F056076147BB0ADC8117CD0296360DA08B3D48BE9EFC8693C03A253E0D9F166C19CA8D936F9E61A1100", + "Amount": "10000", + "Amount2": { + "currency": "ETH", + "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9", + "value": "10000" + }, + "TradingFee": 10, + "Fee": "1", + "Flags": 0, + "Sequence": 2, + "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0" + } + }, + { + "binary": "120024220001000024000000026840000000000000016014D5438D7EA4C68000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0487321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D074409EEE8CF88C668B955E7EEAB1B4A1B059EDF4F51B7F1546810F87E3E48B09237F015C651E37FB40A979E00EA21361D4E18D7A33DB7DD23070CEEAB2648AB3BB0D811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "json": { + "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "TransactionType": "AMMDeposit", + "TxnSignature": "9EEE8CF88C668B955E7EEAB1B4A1B059EDF4F51B7F1546810F87E3E48B09237F015C651E37FB40A979E00EA21361D4E18D7A33DB7DD23070CEEAB2648AB3BB0D", + "Asset": {"currency": "XRP"}, + "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, + "LPTokenOut": {"currency": "B3813FCAB4EE68B3D0D735D6849465A9113EE048", "issuer": "rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg", "value": "1000"}, + "Fee": "1", + "Flags": 65536, + "Sequence": 2, + "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0" + } + }, + { + "binary": "120024220008000024000000026140000000000003E86840000000000000017321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D07440BD18A6E2B10B451F61CFADC32B59A0243702DC5DAAE556D51CB9C79981D40C78101FFA9DE6163CFBDF6E7578DF02F2AE3B8A5AB60697E0746D65064D91E8F90A811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "json": { + "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "TransactionType": "AMMDeposit", + "Asset": {"currency": "XRP"}, + "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, + "Amount": "1000", + "Fee": "1", + "Flags": 524288, + "Sequence": 2, + "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", + "TxnSignature": "BD18A6E2B10B451F61CFADC32B59A0243702DC5DAAE556D51CB9C79981D40C78101FFA9DE6163CFBDF6E7578DF02F2AE3B8A5AB60697E0746D65064D91E8F90A" + } + }, + { + "binary": "120024220010000024000000026140000000000003E86840000000000000016BD511C37937E080000000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C7321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D07440E0B1AE32A0F731BF0CEF0D019295BD7F35B22F11A5962F65FA99EE4D38993B14B53DB11C15E36D756E282812E9015D38A6F225940A157693F43F9B795C59950F811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "json": { + "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "TransactionType": "AMMDeposit", + "Asset": {"currency": "XRP"}, + "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, + "Amount": "1000", + "Amount2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9", "value": "500"}, + "Fee": "1", + "Flags": 1048576, + "Sequence": 2, + "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", + "TxnSignature": "E0B1AE32A0F731BF0CEF0D019295BD7F35B22F11A5962F65FA99EE4D38993B14B53DB11C15E36D756E282812E9015D38A6F225940A157693F43F9B795C59950F" + } + }, + { + "binary": "120024220020000024000000026140000000000003E86840000000000000016014D5438D7EA4C68000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0487321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D07440452BC59F9EE12C224EC983EFDF580F20C4A50E897105FD1FB13520D9753CFB02BD210599181574DF6AD0DB6A42C1EA48D9E48FC3D11B9008E4C76FBB163D5B00811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "json": { + "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "TransactionType": "AMMDeposit", + "Asset": {"currency": "XRP"}, + "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, + "Amount": "1000", + "LPTokenOut": {"currency": "B3813FCAB4EE68B3D0D735D6849465A9113EE048", "issuer": "rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg", "value": "1000"}, + "Fee": "1", + "Flags": 2097152, + "Sequence": 2, + "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", + "TxnSignature": "452BC59F9EE12C224EC983EFDF580F20C4A50E897105FD1FB13520D9753CFB02BD210599181574DF6AD0DB6A42C1EA48D9E48FC3D11B9008E4C76FBB163D5B00" + } + }, + { + "binary": "120024220040000024000000026140000000000003E8684000000000000001601640000000000000197321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D07440DD6685DC586FAA6AD2D50D785900122EB147D4AC09A55D7080267A9B38180F87CEC44B823359FC3F0AC0104D47B53FFC6B80415664C3C4582672420A0100F70C811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "json": { + "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "TransactionType": "AMMDeposit", + "Asset": {"currency": "XRP"}, + "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, + "Amount": "1000", + "EPrice": "25", + "Fee": "1", + "Flags": 4194304, + "Sequence": 2, + "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", + "TxnSignature": "DD6685DC586FAA6AD2D50D785900122EB147D4AC09A55D7080267A9B38180F87CEC44B823359FC3F0AC0104D47B53FFC6B80415664C3C4582672420A0100F70C" + } + }, + { + "binary": "120025220001000024000000026840000000000000016015D5438D7EA4C68000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0487321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0744066944797E9F03808C9A00AAEFF786AD74FEB2E64B51A9601E89ABA820AAA15927C2E961A9CCA22C4B0D2A2B55E342BD6E297BD765B6F4D3FDCA578A3416BB505811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "json": { + "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "TransactionType": "AMMWithdraw", + "Asset": {"currency": "XRP"}, + "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, + "LPTokenIn": {"currency": "B3813FCAB4EE68B3D0D735D6849465A9113EE048", "issuer": "rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg", "value": "1000"}, + "Fee": "1", + "Flags": 65536, + "Sequence": 2, + "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", + "TxnSignature": "66944797E9F03808C9A00AAEFF786AD74FEB2E64B51A9601E89ABA820AAA15927C2E961A9CCA22C4B0D2A2B55E342BD6E297BD765B6F4D3FDCA578A3416BB505" + } + }, + { + "binary": "120025220008000024000000026140000000000003E86840000000000000017321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D07440E30397CE7E99B13D35FFB5C66725B17F4F103675E10293C7B1D63C1BE3FA81B884BD3FBD31B52F6B811F99C5FBB5102D170EC379C268DF80DABF04E7F2DD4F0C811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "json": { + "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "TransactionType": "AMMWithdraw", + "Asset": {"currency": "XRP"}, + "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, + "Amount": "1000", + "Fee": "1", + "Flags": 524288, + "Sequence": 2, + "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", + "TxnSignature": "E30397CE7E99B13D35FFB5C66725B17F4F103675E10293C7B1D63C1BE3FA81B884BD3FBD31B52F6B811F99C5FBB5102D170EC379C268DF80DABF04E7F2DD4F0C" + } + }, + { + "binary": "120025220010000024000000026140000000000003E86840000000000000016BD511C37937E080000000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C7321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D07440C0818312B269A4EF16C1C7EBBB74EFD1852A288BB214A714B8BE3B5F4B2F9CFDFF4F66C931B8434244A8016035B9EC9493B7CF5E0ACF4570A88DF808D79E4300811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "json": { + "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "TransactionType": "AMMWithdraw", + "Asset": {"currency": "XRP"}, + "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, + "Amount": "1000", + "Amount2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9", "value": "500"}, + "Fee": "1", + "Flags": 1048576, + "Sequence": 2, + "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", + "TxnSignature": "C0818312B269A4EF16C1C7EBBB74EFD1852A288BB214A714B8BE3B5F4B2F9CFDFF4F66C931B8434244A8016035B9EC9493B7CF5E0ACF4570A88DF808D79E4300" + } + }, + { + "binary": "120025220020000024000000026140000000000003E86840000000000000016015D5438D7EA4C68000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0487321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0744073552B3DC7AE99DDF4E4FF0D60E6D0BE4688E3474D363603FA25DA6AD8BBA8F0E4E3EA82ADB2B57F5B9A6C379969E00095546DDA0E74FF3D0F0689351C2F8C06811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "json": { + "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "TransactionType": "AMMWithdraw", + "Asset": {"currency": "XRP"}, + "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, + "Amount": "1000", + "LPTokenIn": {"currency": "B3813FCAB4EE68B3D0D735D6849465A9113EE048", "issuer": "rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg", "value": "1000"}, + "Fee": "1", + "Flags": 2097152, + "Sequence": 2, + "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", + "TxnSignature": "73552B3DC7AE99DDF4E4FF0D60E6D0BE4688E3474D363603FA25DA6AD8BBA8F0E4E3EA82ADB2B57F5B9A6C379969E00095546DDA0E74FF3D0F0689351C2F8C06" + } + }, + { + "binary": "120025220040000024000000026140000000000003E8684000000000000001601640000000000000197321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0744023BAFE5BFE58E7BF0B02B5875983D007C10796C8E62A190BF688EBE5D8A104DAD2DE7EDE995FE2E494883FD8140F38E22E3376A2F49C50EFCAA00C7499A4690E811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "json": { + "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "TransactionType": "AMMWithdraw", + "Asset": {"currency": "XRP"}, + "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, + "Amount": "1000", + "EPrice": "25", + "Fee": "1", + "Flags": 4194304, + "Sequence": 2, + "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", + "TxnSignature": "23BAFE5BFE58E7BF0B02B5875983D007C10796C8E62A190BF688EBE5D8A104DAD2DE7EDE995FE2E494883FD8140F38E22E3376A2F49C50EFCAA00C7499A4690E" + } + }, + { + "binary": "120027220000000024000000026840000000000000016CD4C8E1BC9BF04000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0486DD4CC6F3B40B6C000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0487321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D074406B2A1548E6DC14681356C27CCBE7072CAB2AD8C72D0D7A045916FB0E0DBE6BF71A429CC519E9200172829D3EEF79100899D3A8710C1C3C1A2B664FD64086AD0A811462D4D845D20B4F09CFEA8BB4C01063D99FC9673EF01AE01C81149A91957F8F16BC57F3F200CD8C98375BF1791586E1F10318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "json": { + "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "TransactionType": "AMMBid", + "Asset": {"currency": "XRP"}, + "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, + "AuthAccounts": [{"AuthAccount": {"Account": "rEaHTti4HZsMBpxTAF4ncWxkcdqDh1h6P7"}}], + "BidMax": {"currency": "B3813FCAB4EE68B3D0D735D6849465A9113EE048", "issuer": "rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg", "value": "35"}, + "BidMin": {"currency": "B3813FCAB4EE68B3D0D735D6849465A9113EE048", "issuer": "rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg", "value": "25"}, + "Fee": "1", + "Flags": 0, + "Sequence": 2, + "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", + "TxnSignature": "6B2A1548E6DC14681356C27CCBE7072CAB2AD8C72D0D7A045916FB0E0DBE6BF71A429CC519E9200172829D3EEF79100899D3A8710C1C3C1A2B664FD64086AD0A" + } + }, + { + "binary": "1200261500EA220000000024000000026840000000000000017321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0744072767CF9A0F5E9C9DA6BBB6E84905B0ECDF122D3E2D730843EFD377521E8E73664AD809D0A54E8C75CD1735ACB64E310BB49FDED10913FA150B8C006D4ACEC00811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "json": { + "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "TransactionType": "AMMVote", + "Asset": {"currency": "XRP"}, + "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, + "TradingFee": 234, + "Fee": "1", + "Flags": 0, + "Sequence": 2, + "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", + "TxnSignature": "72767CF9A0F5E9C9DA6BBB6E84905B0ECDF122D3E2D730843EFD377521E8E73664AD809D0A54E8C75CD1735ACB64E310BB49FDED10913FA150B8C006D4ACEC00" + } }], "ledgerData": [{ "binary": "01E91435016340767BF1C4A3EACEB081770D8ADE216C85445DD6FB002C6B5A2930F2DECE006DA18150CB18F6DD33F6F0990754C962A7CCE62F332FF9C13939B03B864117F0BDA86B6E9B4F873B5C3E520634D343EF5D9D9A4246643D64DAD278BA95DC0EAC6EB5350CF970D521276CDE21276CE60A00", @@ -4463,4 +4670,4 @@ "transaction_hash": "DD33F6F0990754C962A7CCE62F332FF9C13939B03B864117F0BDA86B6E9B4F87" } }] -} \ No newline at end of file +} From feafc0c91b332ed37f10dbd853d2c07125d921f1 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Thu, 17 Nov 2022 13:37:45 -0500 Subject: [PATCH 52/93] update Issue type --- packages/ripple-binary-codec/src/types/issue.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ripple-binary-codec/src/types/issue.ts b/packages/ripple-binary-codec/src/types/issue.ts index 29bd160b2c..3c3925b945 100644 --- a/packages/ripple-binary-codec/src/types/issue.ts +++ b/packages/ripple-binary-codec/src/types/issue.ts @@ -41,7 +41,7 @@ class Issue extends SerializedType { * representing an integer amount * @returns An Amount object */ - static from(value: T): Issue { + static from(value: T): Issue { if (value instanceof Issue) { return value } From 98f8223b23def3229a42e56d39db42d8a65f506b Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Thu, 17 Nov 2022 14:20:57 -0500 Subject: [PATCH 53/93] add one asset and withdraw all tests --- .../src/models/transactions/AMMWithdraw.ts | 4 ---- packages/xrpl/test/models/AMMWithdraw.ts | 19 +++++++++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/xrpl/src/models/transactions/AMMWithdraw.ts b/packages/xrpl/src/models/transactions/AMMWithdraw.ts index eac8d2186b..1d8a9aa9d8 100644 --- a/packages/xrpl/src/models/transactions/AMMWithdraw.ts +++ b/packages/xrpl/src/models/transactions/AMMWithdraw.ts @@ -115,10 +115,6 @@ export function validateAMMWithdraw(tx: Record): void { throw new ValidationError('AMMWithdraw: must set Amount with Amount2') } else if (tx.EPrice != null && tx.Amount == null) { throw new ValidationError('AMMWithdraw: must set Amount with EPrice') - } else if (tx.LPTokenIn == null && tx.Amount == null) { - throw new ValidationError( - 'AMMWithdraw: must set at least LPTokenIn or Amount', - ) } if (tx.LPTokenIn != null && !isIssuedCurrency(tx.LPTokenIn)) { diff --git a/packages/xrpl/test/models/AMMWithdraw.ts b/packages/xrpl/test/models/AMMWithdraw.ts index 153766f8b5..c5ac476a49 100644 --- a/packages/xrpl/test/models/AMMWithdraw.ts +++ b/packages/xrpl/test/models/AMMWithdraw.ts @@ -68,6 +68,17 @@ describe('AMMWithdraw', function () { assert.doesNotThrow(() => validate(withdraw)) }) + it(`verifies valid AMMWithdraw one asset withdraw all`, function () { + withdraw.Amount = '1000' + withdraw.Flags |= AMMWithdrawFlags.tfOneAssetWithdrawAll + assert.doesNotThrow(() => validate(withdraw)) + }) + + it(`verifies valid AMMWithdraw withdraw all`, function () { + withdraw.Flags |= AMMWithdrawFlags.tfWithdrawAll + assert.doesNotThrow(() => validate(withdraw)) + }) + it(`throws w/ missing field Asset`, function () { delete withdraw.Asset assert.throws( @@ -104,14 +115,6 @@ describe('AMMWithdraw', function () { ) }) - it(`throws w/ must set at least LPTokenIn or Amount`, function () { - assert.throws( - () => validate(withdraw), - ValidationError, - 'AMMWithdraw: must set at least LPTokenIn or Amount', - ) - }) - it(`throws w/ must set Amount with Amount2`, function () { withdraw.Amount2 = { currency: 'ETH', From ec1d8b67a50de5639914ddca5a931708d3f6482a Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Thu, 15 Dec 2022 13:06:39 -0500 Subject: [PATCH 54/93] refactor amm_info response fields to match AMMDevnet --- packages/xrpl/src/models/methods/ammInfo.ts | 131 +++++++++++--------- 1 file changed, 69 insertions(+), 62 deletions(-) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index 68eeb7a06b..e179a3df48 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -45,83 +45,90 @@ interface VoteEntry { */ export interface AMMInfoResponse extends BaseResponse { result: { - /** - * The account that tracks the balance of LPTokens between the AMM instance via Trustline. - */ - AMMAccount: string - - /** - * Specifies one of the pool assets (XRP or token) of the AMM instance. - */ - Asset: Issue - - /** - * Specifies the other pool asset of the AMM instance. - */ - Asset2: Issue - - /** - * Details of the current owner of the auction slot. - */ - AuctionSlot?: { + amm: { /** - * The current owner of this auction slot. + * The account that tracks the balance of LPTokens between the AMM instance via Trustline. */ - Account: string + AMMAccount: string /** - * A list of at most 4 additional accounts that are authorized to trade at the discounted fee for this AMM instance. + * The AMM identifier that uniquely identifies an AMM instance. */ - AuthAccounts: AuthAccount[] + AMMID: string /** - * The trading fee to be charged to the auction owner, in the same format as TradingFee. - * By default this is 0, meaning that the auction owner can trade at no fee instead of the standard fee for this AMM. + * One of the pool assets (XRP or token) of the AMM instance. */ - DiscountedFee: number + Amount: Amount /** - * The time when this slot expires, in seconds since the Ripple Epoch. + * The other pool asset of the AMM instance. */ - Expiration: string + Amount2: Amount /** - * The amount the auction owner paid to win this slot, in LPTokens. + * Details of the current owner of the auction slot. */ - Price: Amount - } + AuctionSlot?: { + /** + * The current owner of this auction slot. + */ + Account: string + + /** + * A list of at most 4 additional accounts that are authorized to trade at the discounted fee for this AMM instance. + */ + AuthAccounts: AuthAccount[] + + /** + * The trading fee to be charged to the auction owner, in the same format as TradingFee. + * By default this is 0, meaning that the auction owner can trade at no fee instead of the standard fee for this AMM. + */ + DiscountedFee: number + + /** + * The time when this slot expires, in seconds since the Ripple Epoch. + */ + Expiration: string + + /** + * The amount the auction owner paid to win this slot, in LPTokens. + */ + Price: Amount + } - /** - * The total outstanding balance of liquidity provider tokens from this AMM instance. - * The holders of these tokens can vote on the AMM's trading fee in proportion to their holdings, - * or redeem the tokens for a share of the AMM's assets which grows with the trading fees collected. - */ - LPTokenBalance: IssuedCurrencyAmount - - /** - * Specifies the fee, in basis point, to be charged to the traders for the trades - * executed against the AMM instance. Trading fee is a percentage of the trading volume. - * Valid values for this field are between 0 and 1000 inclusive. - * A value of 1 is equivalent to 1/10 bps or 0.001%, allowing trading fee - * between 0% and 1%. This field is required. - */ - TradingFee: number + /** + * The total outstanding balance of liquidity provider tokens from this AMM instance. + * The holders of these tokens can vote on the AMM's trading fee in proportion to their holdings, + * or redeem the tokens for a share of the AMM's assets which grows with the trading fees collected. + */ + LPToken: IssuedCurrencyAmount + + /** + * Specifies the fee, in basis point, to be charged to the traders for the trades + * executed against the AMM instance. Trading fee is a percentage of the trading volume. + * Valid values for this field are between 0 and 1000 inclusive. + * A value of 1 is equivalent to 1/10 bps or 0.001%, allowing trading fee + * between 0% and 1%. This field is required. + */ + TradingFee: number + + /** + * Keeps a track of up to eight active votes for the instance. + */ + VoteSlots?: VoteEntry[] + + /** + * The ledger index of the current in-progress ledger, which was used when + * retrieving this information. + */ + ledger_current_index?: number - /** - * Keeps a track of up to eight active votes for the instance. - */ - VoteSlots?: VoteEntry[] - - /** - * The ledger index of the current in-progress ledger, which was used when - * retrieving this information. - */ - ledger_current_index?: number - - /** - * True if this data is from a validated ledger version; if omitted or set - * to false, this data is not final. - */ - validated?: boolean + /** + * True if this data is from a validated ledger version; if omitted or set + * to false, this data is not final. + */ + validated?: boolean + } } } From 218ca005e1aa62e44715ef9fe31364d52056d7c0 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Mon, 9 Jan 2023 17:30:05 -0500 Subject: [PATCH 55/93] update definitions.json with refactored error codes --- .../ripple-binary-codec/src/enums/definitions.json | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/ripple-binary-codec/src/enums/definitions.json b/packages/ripple-binary-codec/src/enums/definitions.json index ab3bc26fac..e5ecefb487 100644 --- a/packages/ripple-binary-codec/src/enums/definitions.json +++ b/packages/ripple-binary-codec/src/enums/definitions.json @@ -2417,8 +2417,7 @@ "temUNKNOWN": -264, "temSEQ_AND_TICKET": -263, "temBAD_NFTOKEN_TRANSFER_FEE": -262, - "temBAD_AMM_OPTIONS": -261, - "temBAD_AMM_TOKENS": -260, + "temAMM_BAD_TOKENS": -261, "tefFAILURE": -199, "tefALREADY": -198, @@ -2504,14 +2503,13 @@ "tecINSUFFICIENT_FUNDS": 159, "tecOBJECT_NOT_FOUND": 160, "tecINSUFFICIENT_PAYMENT": 161, - "tecUNFUNDED_AMM": 162, + "tecAMM_UNFUNDED": 162, "tecAMM_BALANCE": 163, "tecAMM_FAILED_DEPOSIT": 164, "tecAMM_FAILED_WITHDRAW": 165, "tecAMM_INVALID_TOKENS": 166, - "tecAMM_EXISTS": 167, - "tecAMM_FAILED_BID": 168, - "tecAMM_FAILED_VOTE": 169 + "tecAMM_FAILED_BID": 167, + "tecAMM_FAILED_VOTE": 168 }, "TRANSACTION_TYPES": { "Invalid": -1, From e634db3dd2004b83edeb9884cb5c91dc91b329af Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Mon, 9 Jan 2023 17:43:48 -0500 Subject: [PATCH 56/93] update ammInfo.ts response model --- packages/xrpl/src/models/methods/ammInfo.ts | 65 +++++++++++++-------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index e179a3df48..4a63df9314 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -25,17 +25,13 @@ export interface AMMInfoRequest extends BaseRequest { } interface AuthAccount { - AuthAccount: { - Account: string - } + account: string } interface VoteEntry { - VoteEntry: { - Account: string - TradingFee: number - VoteWeight: number - } + account: string + trading_fee: number + vote_weight: number } /** @@ -49,52 +45,54 @@ export interface AMMInfoResponse extends BaseResponse { /** * The account that tracks the balance of LPTokens between the AMM instance via Trustline. */ - AMMAccount: string + amm_account: string /** - * The AMM identifier that uniquely identifies an AMM instance. + * One of the pool assets (XRP or token) of the AMM instance. */ - AMMID: string + amount: Amount /** - * One of the pool assets (XRP or token) of the AMM instance. + * The other pool asset of the AMM instance. */ - Amount: Amount + amount2: Amount /** - * The other pool asset of the AMM instance. + * Flag indicating whether asset2 is frozen. */ - Amount2: Amount + asset2_frozen: boolean /** * Details of the current owner of the auction slot. */ - AuctionSlot?: { + auction_slot?: { /** * The current owner of this auction slot. */ - Account: string + account: string /** * A list of at most 4 additional accounts that are authorized to trade at the discounted fee for this AMM instance. */ - AuthAccounts: AuthAccount[] + auth_accounts: AuthAccount[] /** * The trading fee to be charged to the auction owner, in the same format as TradingFee. * By default this is 0, meaning that the auction owner can trade at no fee instead of the standard fee for this AMM. */ - DiscountedFee: number + discounted_fee: number /** * The time when this slot expires, in seconds since the Ripple Epoch. */ - Expiration: string + expiration: string /** * The amount the auction owner paid to win this slot, in LPTokens. */ - Price: Amount + price: Amount + + time_interval: number } /** @@ -102,7 +100,7 @@ export interface AMMInfoResponse extends BaseResponse { * The holders of these tokens can vote on the AMM's trading fee in proportion to their holdings, * or redeem the tokens for a share of the AMM's assets which grows with the trading fees collected. */ - LPToken: IssuedCurrencyAmount + lp_token: IssuedCurrencyAmount /** * Specifies the fee, in basis point, to be charged to the traders for the trades @@ -111,12 +109,12 @@ export interface AMMInfoResponse extends BaseResponse { * A value of 1 is equivalent to 1/10 bps or 0.001%, allowing trading fee * between 0% and 1%. This field is required. */ - TradingFee: number + trading_fee: number /** * Keeps a track of up to eight active votes for the instance. */ - VoteSlots?: VoteEntry[] + vote_slots?: VoteEntry[] /** * The ledger index of the current in-progress ledger, which was used when @@ -130,5 +128,24 @@ export interface AMMInfoResponse extends BaseResponse { */ validated?: boolean } + + /** + * The identifying hash of the ledger that was used to generate this + * response. + */ + ledger_hash?: string + + /** + * The ledger index of the ledger version that was used to generate this + * response. + */ + ledger_index?: number + + /** + * If included and set to true, the information in this response comes from + * a validated ledger version. Otherwise, the information is subject to + * change. + */ + validated?: boolean } } From f3d6bd4be4634bb87b29cf92eb3fb520da64851b Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Mon, 9 Jan 2023 17:51:33 -0500 Subject: [PATCH 57/93] remove invalid fields from ammInfo.ts response model --- packages/xrpl/src/models/methods/ammInfo.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index 4a63df9314..eaf6fd9f1d 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -115,18 +115,6 @@ export interface AMMInfoResponse extends BaseResponse { * Keeps a track of up to eight active votes for the instance. */ vote_slots?: VoteEntry[] - - /** - * The ledger index of the current in-progress ledger, which was used when - * retrieving this information. - */ - ledger_current_index?: number - - /** - * True if this data is from a validated ledger version; if omitted or set - * to false, this data is not final. - */ - validated?: boolean } /** From 8cdeb2ba99ce3682b3b00ab38111fbf65e7bcffe Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Mon, 9 Jan 2023 18:13:18 -0500 Subject: [PATCH 58/93] update time_interval description --- packages/xrpl/src/models/methods/ammInfo.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index eaf6fd9f1d..205857085c 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -92,6 +92,9 @@ export interface AMMInfoResponse extends BaseResponse { */ price: Amount + /** + * Total slot time of 24-hours is divided into 20 equal time intervals. + */ time_interval: number } From 287dc1acf8f0d0e56287f6de602ab09648f9637d Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 15 Feb 2023 18:18:07 -0500 Subject: [PATCH 59/93] rename test model names and fix lint errors --- packages/xrpl/test/models/{AMMBid.ts => AMMBid.test.ts} | 3 ++- packages/xrpl/test/models/{AMMCreate.ts => AMMCreate.test.ts} | 3 ++- .../xrpl/test/models/{AMMDeposit.ts => AMMDeposit.test.ts} | 3 ++- packages/xrpl/test/models/{AMMVote.ts => AMMVote.test.ts} | 3 ++- .../xrpl/test/models/{AMMWithdraw.ts => AMMWithdraw.test.ts} | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) rename packages/xrpl/test/models/{AMMBid.ts => AMMBid.test.ts} (97%) rename packages/xrpl/test/models/{AMMCreate.ts => AMMCreate.test.ts} (97%) rename packages/xrpl/test/models/{AMMDeposit.ts => AMMDeposit.test.ts} (98%) rename packages/xrpl/test/models/{AMMVote.ts => AMMVote.test.ts} (97%) rename packages/xrpl/test/models/{AMMWithdraw.ts => AMMWithdraw.test.ts} (98%) diff --git a/packages/xrpl/test/models/AMMBid.ts b/packages/xrpl/test/models/AMMBid.test.ts similarity index 97% rename from packages/xrpl/test/models/AMMBid.ts rename to packages/xrpl/test/models/AMMBid.test.ts index 834bf34daf..0ef28dce45 100644 --- a/packages/xrpl/test/models/AMMBid.ts +++ b/packages/xrpl/test/models/AMMBid.test.ts @@ -1,5 +1,6 @@ import { assert } from 'chai' -import { validate, ValidationError } from 'xrpl-local' + +import { validate, ValidationError } from '../../src' /** * AMMBid Transaction Verification Testing. diff --git a/packages/xrpl/test/models/AMMCreate.ts b/packages/xrpl/test/models/AMMCreate.test.ts similarity index 97% rename from packages/xrpl/test/models/AMMCreate.ts rename to packages/xrpl/test/models/AMMCreate.test.ts index d75a1f17f7..03b5028b3b 100644 --- a/packages/xrpl/test/models/AMMCreate.ts +++ b/packages/xrpl/test/models/AMMCreate.test.ts @@ -1,5 +1,6 @@ import { assert } from 'chai' -import { validate, ValidationError } from 'xrpl-local' + +import { validate, ValidationError } from '../../src' /** * AMMCreate Transaction Verification Testing. diff --git a/packages/xrpl/test/models/AMMDeposit.ts b/packages/xrpl/test/models/AMMDeposit.test.ts similarity index 98% rename from packages/xrpl/test/models/AMMDeposit.ts rename to packages/xrpl/test/models/AMMDeposit.test.ts index f7b65fd31a..9eeb6ec37e 100644 --- a/packages/xrpl/test/models/AMMDeposit.ts +++ b/packages/xrpl/test/models/AMMDeposit.test.ts @@ -1,6 +1,7 @@ /* eslint-disable no-bitwise -- bitwise necessary for enabling flags */ import { assert } from 'chai' -import { AMMDepositFlags, validate, ValidationError } from 'xrpl-local' + +import { AMMDepositFlags, validate, ValidationError } from '../../src' /** * AMMDeposit Transaction Verification Testing. diff --git a/packages/xrpl/test/models/AMMVote.ts b/packages/xrpl/test/models/AMMVote.test.ts similarity index 97% rename from packages/xrpl/test/models/AMMVote.ts rename to packages/xrpl/test/models/AMMVote.test.ts index f00350b402..765690cc6e 100644 --- a/packages/xrpl/test/models/AMMVote.ts +++ b/packages/xrpl/test/models/AMMVote.test.ts @@ -1,5 +1,6 @@ import { assert } from 'chai' -import { validate, ValidationError } from 'xrpl-local' + +import { validate, ValidationError } from '../../src' /** * AMMVote Transaction Verification Testing. diff --git a/packages/xrpl/test/models/AMMWithdraw.ts b/packages/xrpl/test/models/AMMWithdraw.test.ts similarity index 98% rename from packages/xrpl/test/models/AMMWithdraw.ts rename to packages/xrpl/test/models/AMMWithdraw.test.ts index c5ac476a49..27a5c5c077 100644 --- a/packages/xrpl/test/models/AMMWithdraw.ts +++ b/packages/xrpl/test/models/AMMWithdraw.test.ts @@ -1,6 +1,7 @@ /* eslint-disable no-bitwise -- bitwise necessary for enabling flags */ import { assert } from 'chai' -import { AMMWithdrawFlags, validate, ValidationError } from 'xrpl-local' + +import { AMMWithdrawFlags, validate, ValidationError } from '../../src' /** * AMMWithdraw Transaction Verification Testing. From 7e8427785cdececec9c83d61c7c01f02baeb433b Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 15 Feb 2023 18:21:30 -0500 Subject: [PATCH 60/93] add Owner Reserve Fee for AMMCreate transaction --- packages/xrpl/src/sugar/autofill.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/xrpl/src/sugar/autofill.ts b/packages/xrpl/src/sugar/autofill.ts index 05d50a961f..cdcc97b0ec 100644 --- a/packages/xrpl/src/sugar/autofill.ts +++ b/packages/xrpl/src/sugar/autofill.ts @@ -140,7 +140,7 @@ async function setNextValidSequenceNumber( tx.Sequence = data.result.account_data.Sequence } -async function fetchAccountDeleteFee(client: Client): Promise { +async function fetchOwnerReserveFee(client: Client): Promise { const response = await client.request({ command: 'server_state' }) const fee = response.result.state.validated_ledger?.reserve_inc @@ -172,9 +172,11 @@ async function calculateFeePerTransactionType( baseFee = product.dp(0, BigNumber.ROUND_CEIL) } - // AccountDelete Transaction - if (tx.TransactionType === 'AccountDelete') { - baseFee = await fetchAccountDeleteFee(client) + if ( + tx.TransactionType === 'AccountDelete' || + tx.TransactionType === 'AMMCreate' + ) { + baseFee = await fetchOwnerReserveFee(client) } /* From d2f7fe622bfbdb9e9c89f7c6b4a2347301b5be72 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 15 Feb 2023 18:45:07 -0500 Subject: [PATCH 61/93] add missing asset_frozen field --- packages/xrpl/src/models/methods/ammInfo.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index 205857085c..6ad5135fe4 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -58,7 +58,12 @@ export interface AMMInfoResponse extends BaseResponse { amount2: Amount /** - * Flag indicating whether asset2 is frozen. + * (Omitted for XRP) If true, the amount currency is currently frozen for asset. + */ + asset_frozen: boolean + + /** + * (Omitted for XRP) If true, the amount currency is currently frozen for asset2. */ asset2_frozen: boolean From df75b4a908dda6be78a282a72d29d02f071445d7 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 15 Feb 2023 23:13:05 -0500 Subject: [PATCH 62/93] replace Issue with IssuedCurrency --- packages/xrpl/src/models/common/index.ts | 4 +- packages/xrpl/src/models/methods/ammInfo.ts | 6 +-- .../xrpl/src/models/transactions/AMMBid.ts | 6 +-- .../src/models/transactions/AMMDeposit.ts | 6 +-- .../xrpl/src/models/transactions/AMMVote.ts | 6 +-- .../src/models/transactions/AMMWithdraw.ts | 6 +-- .../xrpl/src/models/transactions/common.ts | 50 +++++++++++-------- 7 files changed, 44 insertions(+), 40 deletions(-) diff --git a/packages/xrpl/src/models/common/index.ts b/packages/xrpl/src/models/common/index.ts index bd7e1279d2..e8b3b76f79 100644 --- a/packages/xrpl/src/models/common/index.ts +++ b/packages/xrpl/src/models/common/index.ts @@ -4,15 +4,13 @@ interface XRP { currency: 'XRP' } -interface IssuedCurrency { +export interface IssuedCurrency { currency: string issuer: string } export type Currency = IssuedCurrency | XRP -export type Issue = Currency - export interface IssuedCurrencyAmount extends IssuedCurrency { value: string } diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index 6ad5135fe4..c033d3afc4 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -1,4 +1,4 @@ -import { Amount, Issue, IssuedCurrencyAmount } from '../common' +import { Amount, IssuedCurrency, IssuedCurrencyAmount } from '../common' import { BaseRequest, BaseResponse } from './baseMethod' @@ -15,13 +15,13 @@ export interface AMMInfoRequest extends BaseRequest { * Specifies one of the pool assets (XRP or token) of the AMM instance. * Both asset and asset2 must be defined to specify an AMM instance. */ - asset?: Issue + asset?: IssuedCurrency /** * Specifies the other pool asset of the AMM instance. * Both asset and asset2 must be defined to specify an AMM instance. */ - asset2?: Issue + asset2?: IssuedCurrency } interface AuthAccount { diff --git a/packages/xrpl/src/models/transactions/AMMBid.ts b/packages/xrpl/src/models/transactions/AMMBid.ts index 1a6ec81055..e5ff1a953b 100644 --- a/packages/xrpl/src/models/transactions/AMMBid.ts +++ b/packages/xrpl/src/models/transactions/AMMBid.ts @@ -1,6 +1,6 @@ /* eslint-disable complexity -- required for validateAMMBid */ import { ValidationError } from '../../errors' -import { Amount, Issue } from '../common' +import { Amount, IssuedCurrency } from '../common' import { BaseTransaction, @@ -29,12 +29,12 @@ export interface AMMBid extends BaseTransaction { /** * Specifies one of the pool assets (XRP or token) of the AMM instance. */ - Asset: Issue + Asset: IssuedCurrency /** * Specifies the other pool asset of the AMM instance. */ - Asset2: Issue + Asset2: IssuedCurrency /** * This field represents the minimum price that the bidder wants to pay for the slot. diff --git a/packages/xrpl/src/models/transactions/AMMDeposit.ts b/packages/xrpl/src/models/transactions/AMMDeposit.ts index 0770d33886..9177b12f98 100644 --- a/packages/xrpl/src/models/transactions/AMMDeposit.ts +++ b/packages/xrpl/src/models/transactions/AMMDeposit.ts @@ -1,6 +1,6 @@ /* eslint-disable complexity -- required for validateAMMDeposit */ import { ValidationError } from '../../errors' -import { Amount, Issue, IssuedCurrencyAmount } from '../common' +import { Amount, IssuedCurrency, IssuedCurrencyAmount } from '../common' import { BaseTransaction, @@ -49,12 +49,12 @@ export interface AMMDeposit extends BaseTransaction { /** * Specifies one of the pool assets (XRP or token) of the AMM instance. */ - Asset: Issue + Asset: IssuedCurrency /** * Specifies the other pool asset of the AMM instance. */ - Asset2: Issue + Asset2: IssuedCurrency /** * Specifies the amount of shares of the AMM instance pools that the trader diff --git a/packages/xrpl/src/models/transactions/AMMVote.ts b/packages/xrpl/src/models/transactions/AMMVote.ts index ce33acfe7b..cd19c736ab 100644 --- a/packages/xrpl/src/models/transactions/AMMVote.ts +++ b/packages/xrpl/src/models/transactions/AMMVote.ts @@ -1,5 +1,5 @@ import { ValidationError } from '../../errors' -import { Issue } from '../common' +import { IssuedCurrency } from '../common' import { AMM_MAX_TRADING_FEE } from './AMMCreate' import { BaseTransaction, isIssue, validateBaseTransaction } from './common' @@ -16,12 +16,12 @@ export interface AMMVote extends BaseTransaction { /** * Specifies one of the pool assets (XRP or token) of the AMM instance. */ - Asset: Issue + Asset: IssuedCurrency /** * Specifies the other pool asset of the AMM instance. */ - Asset2: Issue + Asset2: IssuedCurrency /** * Specifies the fee, in basis point. diff --git a/packages/xrpl/src/models/transactions/AMMWithdraw.ts b/packages/xrpl/src/models/transactions/AMMWithdraw.ts index 1d8a9aa9d8..4a64431afc 100644 --- a/packages/xrpl/src/models/transactions/AMMWithdraw.ts +++ b/packages/xrpl/src/models/transactions/AMMWithdraw.ts @@ -1,6 +1,6 @@ /* eslint-disable complexity -- required for validateAMMWithdraw */ import { ValidationError } from '../../errors' -import { Amount, Issue, IssuedCurrencyAmount } from '../common' +import { Amount, IssuedCurrency, IssuedCurrencyAmount } from '../common' import { BaseTransaction, @@ -54,12 +54,12 @@ export interface AMMWithdraw extends BaseTransaction { /** * Specifies one of the pool assets (XRP or token) of the AMM instance. */ - Asset: Issue + Asset: IssuedCurrency /** * Specifies the other pool asset of the AMM instance. */ - Asset2: Issue + Asset2: IssuedCurrency /** * Specifies the amount of shares of the AMM instance pools that the trader diff --git a/packages/xrpl/src/models/transactions/common.ts b/packages/xrpl/src/models/transactions/common.ts index bd330b7b92..b685730c64 100644 --- a/packages/xrpl/src/models/transactions/common.ts +++ b/packages/xrpl/src/models/transactions/common.ts @@ -4,7 +4,13 @@ import { TRANSACTION_TYPES } from 'ripple-binary-codec' import { ValidationError } from '../../errors' -import { Amount, Issue, IssuedCurrencyAmount, Memo, Signer } from '../common' +import { + Amount, + IssuedCurrency, + IssuedCurrencyAmount, + Memo, + Signer, +} from '../common' import { onlyHasFields } from '../utils' const MEMO_SIZE = 3 @@ -50,17 +56,36 @@ function isSigner(obj: unknown): boolean { ) } +const XRP_CURRENCY_SIZE = 1 +const ISSUE_SIZE = 2 const ISSUED_CURRENCY_SIZE = 3 function isRecord(value: unknown): value is Record { return value !== null && typeof value === 'object' } +/** + * Verify the form and type of an IssuedCurrency at runtime. + * + * @param input - The input to check the form and type of. + * @returns Whether the IssuedCurrency is properly formed. + */ +export function isIssue(input: unknown): input is IssuedCurrency { + return ( + isRecord(input) && + ((Object.keys(input).length === ISSUE_SIZE && + typeof input.issuer === 'string' && + typeof input.currency === 'string') || + (Object.keys(input).length === XRP_CURRENCY_SIZE && + input.currency === 'XRP')) + ) +} + /** * Verify the form and type of an IssuedCurrencyAmount at runtime. * * @param input - The input to check the form and type of. - * @returns Whether the IssuedCurrencyAmount is malformed. + * @returns Whether the IssuedCurrencyAmount is properly formed. */ export function isIssuedCurrency( input: unknown, @@ -78,31 +103,12 @@ export function isIssuedCurrency( * Verify the form and type of an Amount at runtime. * * @param amount - The object to check the form and type of. - * @returns Whether the Amount is malformed. + * @returns Whether the Amount is properly formed. */ export function isAmount(amount: unknown): amount is Amount { return typeof amount === 'string' || isIssuedCurrency(amount) } -/** - * Verify the form and type of an Issue at runtime. - * - * @param input - The object to check the form and type of. - * @returns Whether the Issue is malformed. - */ -export function isIssue(input: unknown): input is Issue { - if (!isRecord(input)) { - return false - } - const length = Object.keys(input).length - return ( - (length === 1 && input.currency === 'XRP') || - (length === 2 && - typeof input.currency === 'string' && - typeof input.issuer === 'string') - ) -} - // eslint-disable-next-line @typescript-eslint/no-empty-interface -- no global flags right now, so this is fine export interface GlobalFlags {} From 651780fe67f5f656315a768f0bf237d1398fdb5c Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Thu, 16 Feb 2023 12:37:29 -0500 Subject: [PATCH 63/93] refactor: convert flags to number --- packages/xrpl/src/models/utils/flags.ts | 85 +++++-------------------- 1 file changed, 15 insertions(+), 70 deletions(-) diff --git a/packages/xrpl/src/models/utils/flags.ts b/packages/xrpl/src/models/utils/flags.ts index a410813002..ad5dcacae9 100644 --- a/packages/xrpl/src/models/utils/flags.ts +++ b/packages/xrpl/src/models/utils/flags.ts @@ -6,30 +6,15 @@ import { AccountRootFlagsInterface, AccountRootFlags, } from '../ledger/AccountRoot' -import { - AccountSetFlagsInterface, - AccountSetTfFlags, -} from '../transactions/accountSet' -import { - AMMDepositFlags, - AMMDepositFlagsInterface, -} from '../transactions/AMMDeposit' -import { - AMMWithdrawFlags, - AMMWithdrawFlagsInterface, -} from '../transactions/AMMWithdraw' +import { AccountSetTfFlags } from '../transactions/accountSet' +import { AMMDepositFlags } from '../transactions/AMMDeposit' +import { AMMWithdrawFlags } from '../transactions/AMMWithdraw' import { GlobalFlags } from '../transactions/common' -import { - OfferCreateFlagsInterface, - OfferCreateFlags, -} from '../transactions/offerCreate' -import { PaymentFlagsInterface, PaymentFlags } from '../transactions/payment' -import { - PaymentChannelClaimFlagsInterface, - PaymentChannelClaimFlags, -} from '../transactions/paymentChannelClaim' +import { OfferCreateFlags } from '../transactions/offerCreate' +import { PaymentFlags } from '../transactions/payment' +import { PaymentChannelClaimFlags } from '../transactions/paymentChannelClaim' import type { Transaction } from '../transactions/transaction' -import { TrustSetFlagsInterface, TrustSetFlags } from '../transactions/trustSet' +import { TrustSetFlags } from '../transactions/trustSet' import { isFlagEnabled } from '.' @@ -69,73 +54,33 @@ export function setTransactionFlagsToNumber(tx: Transaction): void { switch (tx.TransactionType) { case 'AccountSet': - tx.Flags = convertAccountSetFlagsToNumber(tx.Flags) + tx.Flags = convertFlagsToNumber(tx.Flags, AccountSetTfFlags) return case 'AMMDeposit': - tx.Flags = convertAMMDepositFlagsToNumber(tx.Flags) + tx.Flags = convertFlagsToNumber(tx.Flags, AMMDepositFlags) return case 'AMMWithdraw': - tx.Flags = convertAMMWithdrawFlagsToNumber(tx.Flags) + tx.Flags = convertFlagsToNumber(tx.Flags, AMMWithdrawFlags) return case 'OfferCreate': - tx.Flags = convertOfferCreateFlagsToNumber(tx.Flags) + tx.Flags = convertFlagsToNumber(tx.Flags, OfferCreateFlags) return case 'PaymentChannelClaim': - tx.Flags = convertPaymentChannelClaimFlagsToNumber(tx.Flags) + tx.Flags = convertFlagsToNumber(tx.Flags, PaymentChannelClaimFlags) return case 'Payment': - tx.Flags = convertPaymentTransactionFlagsToNumber(tx.Flags) + tx.Flags = convertFlagsToNumber(tx.Flags, PaymentFlags) return case 'TrustSet': - tx.Flags = convertTrustSetFlagsToNumber(tx.Flags) + tx.Flags = convertFlagsToNumber(tx.Flags, TrustSetFlags) return default: tx.Flags = 0 } } -function convertAccountSetFlagsToNumber( - flags: AccountSetFlagsInterface, -): number { - return reduceFlags(flags, AccountSetTfFlags) -} - -function convertAMMDepositFlagsToNumber( - flags: AMMDepositFlagsInterface, -): number { - return reduceFlags(flags, AMMDepositFlags) -} - -function convertAMMWithdrawFlagsToNumber( - flags: AMMWithdrawFlagsInterface, -): number { - return reduceFlags(flags, AMMWithdrawFlags) -} - -function convertOfferCreateFlagsToNumber( - flags: OfferCreateFlagsInterface, -): number { - return reduceFlags(flags, OfferCreateFlags) -} - -function convertPaymentChannelClaimFlagsToNumber( - flags: PaymentChannelClaimFlagsInterface, -): number { - return reduceFlags(flags, PaymentChannelClaimFlags) -} - -function convertPaymentTransactionFlagsToNumber( - flags: PaymentFlagsInterface, -): number { - return reduceFlags(flags, PaymentFlags) -} - -function convertTrustSetFlagsToNumber(flags: TrustSetFlagsInterface): number { - return reduceFlags(flags, TrustSetFlags) -} - // eslint-disable-next-line @typescript-eslint/no-explicit-any -- added ValidationError check for flagEnum -function reduceFlags(flags: GlobalFlags, flagEnum: any): number { +function convertFlagsToNumber(flags: GlobalFlags, flagEnum: any): number { return Object.keys(flags).reduce((resultFlags, flag) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- safe member access if (flagEnum[flag] == null) { From d43fd788d4f2d11b4cbba8b61fd656b9a91add36 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 21 Feb 2023 13:12:14 -0500 Subject: [PATCH 64/93] update asset pair to use Currency type --- packages/xrpl/src/models/methods/ammInfo.ts | 6 +++--- packages/xrpl/src/models/transactions/AMMBid.ts | 6 +++--- packages/xrpl/src/models/transactions/AMMDeposit.ts | 6 +++--- packages/xrpl/src/models/transactions/AMMVote.ts | 6 +++--- packages/xrpl/src/models/transactions/AMMWithdraw.ts | 6 +++--- packages/xrpl/src/models/transactions/common.ts | 10 ++-------- 6 files changed, 17 insertions(+), 23 deletions(-) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index c033d3afc4..75c644ed6e 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -1,4 +1,4 @@ -import { Amount, IssuedCurrency, IssuedCurrencyAmount } from '../common' +import { Amount, Currency, IssuedCurrencyAmount } from '../common' import { BaseRequest, BaseResponse } from './baseMethod' @@ -15,13 +15,13 @@ export interface AMMInfoRequest extends BaseRequest { * Specifies one of the pool assets (XRP or token) of the AMM instance. * Both asset and asset2 must be defined to specify an AMM instance. */ - asset?: IssuedCurrency + asset: Currency /** * Specifies the other pool asset of the AMM instance. * Both asset and asset2 must be defined to specify an AMM instance. */ - asset2?: IssuedCurrency + asset2: Currency } interface AuthAccount { diff --git a/packages/xrpl/src/models/transactions/AMMBid.ts b/packages/xrpl/src/models/transactions/AMMBid.ts index e5ff1a953b..12ca4a7493 100644 --- a/packages/xrpl/src/models/transactions/AMMBid.ts +++ b/packages/xrpl/src/models/transactions/AMMBid.ts @@ -1,6 +1,6 @@ /* eslint-disable complexity -- required for validateAMMBid */ import { ValidationError } from '../../errors' -import { Amount, IssuedCurrency } from '../common' +import { Amount, Currency } from '../common' import { BaseTransaction, @@ -29,12 +29,12 @@ export interface AMMBid extends BaseTransaction { /** * Specifies one of the pool assets (XRP or token) of the AMM instance. */ - Asset: IssuedCurrency + Asset: Currency /** * Specifies the other pool asset of the AMM instance. */ - Asset2: IssuedCurrency + Asset2: Currency /** * This field represents the minimum price that the bidder wants to pay for the slot. diff --git a/packages/xrpl/src/models/transactions/AMMDeposit.ts b/packages/xrpl/src/models/transactions/AMMDeposit.ts index 9177b12f98..89a4c7254d 100644 --- a/packages/xrpl/src/models/transactions/AMMDeposit.ts +++ b/packages/xrpl/src/models/transactions/AMMDeposit.ts @@ -1,6 +1,6 @@ /* eslint-disable complexity -- required for validateAMMDeposit */ import { ValidationError } from '../../errors' -import { Amount, IssuedCurrency, IssuedCurrencyAmount } from '../common' +import { Amount, Currency, IssuedCurrencyAmount } from '../common' import { BaseTransaction, @@ -49,12 +49,12 @@ export interface AMMDeposit extends BaseTransaction { /** * Specifies one of the pool assets (XRP or token) of the AMM instance. */ - Asset: IssuedCurrency + Asset: Currency /** * Specifies the other pool asset of the AMM instance. */ - Asset2: IssuedCurrency + Asset2: Currency /** * Specifies the amount of shares of the AMM instance pools that the trader diff --git a/packages/xrpl/src/models/transactions/AMMVote.ts b/packages/xrpl/src/models/transactions/AMMVote.ts index cd19c736ab..a702765082 100644 --- a/packages/xrpl/src/models/transactions/AMMVote.ts +++ b/packages/xrpl/src/models/transactions/AMMVote.ts @@ -1,5 +1,5 @@ import { ValidationError } from '../../errors' -import { IssuedCurrency } from '../common' +import { Currency } from '../common' import { AMM_MAX_TRADING_FEE } from './AMMCreate' import { BaseTransaction, isIssue, validateBaseTransaction } from './common' @@ -16,12 +16,12 @@ export interface AMMVote extends BaseTransaction { /** * Specifies one of the pool assets (XRP or token) of the AMM instance. */ - Asset: IssuedCurrency + Asset: Currency /** * Specifies the other pool asset of the AMM instance. */ - Asset2: IssuedCurrency + Asset2: Currency /** * Specifies the fee, in basis point. diff --git a/packages/xrpl/src/models/transactions/AMMWithdraw.ts b/packages/xrpl/src/models/transactions/AMMWithdraw.ts index 4a64431afc..e564a62509 100644 --- a/packages/xrpl/src/models/transactions/AMMWithdraw.ts +++ b/packages/xrpl/src/models/transactions/AMMWithdraw.ts @@ -1,6 +1,6 @@ /* eslint-disable complexity -- required for validateAMMWithdraw */ import { ValidationError } from '../../errors' -import { Amount, IssuedCurrency, IssuedCurrencyAmount } from '../common' +import { Amount, Currency, IssuedCurrencyAmount } from '../common' import { BaseTransaction, @@ -54,12 +54,12 @@ export interface AMMWithdraw extends BaseTransaction { /** * Specifies one of the pool assets (XRP or token) of the AMM instance. */ - Asset: IssuedCurrency + Asset: Currency /** * Specifies the other pool asset of the AMM instance. */ - Asset2: IssuedCurrency + Asset2: Currency /** * Specifies the amount of shares of the AMM instance pools that the trader diff --git a/packages/xrpl/src/models/transactions/common.ts b/packages/xrpl/src/models/transactions/common.ts index b685730c64..14051fb543 100644 --- a/packages/xrpl/src/models/transactions/common.ts +++ b/packages/xrpl/src/models/transactions/common.ts @@ -4,13 +4,7 @@ import { TRANSACTION_TYPES } from 'ripple-binary-codec' import { ValidationError } from '../../errors' -import { - Amount, - IssuedCurrency, - IssuedCurrencyAmount, - Memo, - Signer, -} from '../common' +import { Amount, Currency, IssuedCurrencyAmount, Memo, Signer } from '../common' import { onlyHasFields } from '../utils' const MEMO_SIZE = 3 @@ -70,7 +64,7 @@ function isRecord(value: unknown): value is Record { * @param input - The input to check the form and type of. * @returns Whether the IssuedCurrency is properly formed. */ -export function isIssue(input: unknown): input is IssuedCurrency { +export function isIssue(input: unknown): input is Currency { return ( isRecord(input) && ((Object.keys(input).length === ISSUE_SIZE && From f9f210715c951989d512aaf14711b9dd4c1410ae Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 22 Feb 2023 19:22:01 -0500 Subject: [PATCH 65/93] refactor isIssue to isCurrency --- packages/xrpl/src/models/transactions/AMMBid.ts | 6 +++--- packages/xrpl/src/models/transactions/AMMDeposit.ts | 6 +++--- packages/xrpl/src/models/transactions/AMMVote.ts | 6 +++--- packages/xrpl/src/models/transactions/AMMWithdraw.ts | 6 +++--- packages/xrpl/src/models/transactions/common.ts | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/xrpl/src/models/transactions/AMMBid.ts b/packages/xrpl/src/models/transactions/AMMBid.ts index 12ca4a7493..eabbf7eba2 100644 --- a/packages/xrpl/src/models/transactions/AMMBid.ts +++ b/packages/xrpl/src/models/transactions/AMMBid.ts @@ -5,7 +5,7 @@ import { Amount, Currency } from '../common' import { BaseTransaction, isAmount, - isIssue, + isCurrency, validateBaseTransaction, } from './common' @@ -71,7 +71,7 @@ export function validateAMMBid(tx: Record): void { throw new ValidationError('AMMBid: missing field Asset') } - if (!isIssue(tx.Asset)) { + if (!isCurrency(tx.Asset)) { throw new ValidationError('AMMBid: Asset must be an Issue') } @@ -79,7 +79,7 @@ export function validateAMMBid(tx: Record): void { throw new ValidationError('AMMBid: missing field Asset2') } - if (!isIssue(tx.Asset2)) { + if (!isCurrency(tx.Asset2)) { throw new ValidationError('AMMBid: Asset2 must be an Issue') } diff --git a/packages/xrpl/src/models/transactions/AMMDeposit.ts b/packages/xrpl/src/models/transactions/AMMDeposit.ts index 89a4c7254d..856ef2e799 100644 --- a/packages/xrpl/src/models/transactions/AMMDeposit.ts +++ b/packages/xrpl/src/models/transactions/AMMDeposit.ts @@ -6,7 +6,7 @@ import { BaseTransaction, GlobalFlags, isAmount, - isIssue, + isCurrency, isIssuedCurrency, validateBaseTransaction, } from './common' @@ -93,7 +93,7 @@ export function validateAMMDeposit(tx: Record): void { throw new ValidationError('AMMDeposit: missing field Asset') } - if (!isIssue(tx.Asset)) { + if (!isCurrency(tx.Asset)) { throw new ValidationError('AMMDeposit: Asset must be an Issue') } @@ -101,7 +101,7 @@ export function validateAMMDeposit(tx: Record): void { throw new ValidationError('AMMDeposit: missing field Asset2') } - if (!isIssue(tx.Asset2)) { + if (!isCurrency(tx.Asset2)) { throw new ValidationError('AMMDeposit: Asset2 must be an Issue') } diff --git a/packages/xrpl/src/models/transactions/AMMVote.ts b/packages/xrpl/src/models/transactions/AMMVote.ts index a702765082..98734823bc 100644 --- a/packages/xrpl/src/models/transactions/AMMVote.ts +++ b/packages/xrpl/src/models/transactions/AMMVote.ts @@ -2,7 +2,7 @@ import { ValidationError } from '../../errors' import { Currency } from '../common' import { AMM_MAX_TRADING_FEE } from './AMMCreate' -import { BaseTransaction, isIssue, validateBaseTransaction } from './common' +import { BaseTransaction, isCurrency, validateBaseTransaction } from './common' /** * AMMVote is used for submitting a vote for the trading fee of an AMM Instance. @@ -45,7 +45,7 @@ export function validateAMMVote(tx: Record): void { throw new ValidationError('AMMVote: missing field Asset') } - if (!isIssue(tx.Asset)) { + if (!isCurrency(tx.Asset)) { throw new ValidationError('AMMVote: Asset must be an Issue') } @@ -53,7 +53,7 @@ export function validateAMMVote(tx: Record): void { throw new ValidationError('AMMVote: missing field Asset2') } - if (!isIssue(tx.Asset2)) { + if (!isCurrency(tx.Asset2)) { throw new ValidationError('AMMVote: Asset2 must be an Issue') } diff --git a/packages/xrpl/src/models/transactions/AMMWithdraw.ts b/packages/xrpl/src/models/transactions/AMMWithdraw.ts index e564a62509..36bcbf423a 100644 --- a/packages/xrpl/src/models/transactions/AMMWithdraw.ts +++ b/packages/xrpl/src/models/transactions/AMMWithdraw.ts @@ -6,7 +6,7 @@ import { BaseTransaction, GlobalFlags, isAmount, - isIssue, + isCurrency, isIssuedCurrency, validateBaseTransaction, } from './common' @@ -99,7 +99,7 @@ export function validateAMMWithdraw(tx: Record): void { throw new ValidationError('AMMWithdraw: missing field Asset') } - if (!isIssue(tx.Asset)) { + if (!isCurrency(tx.Asset)) { throw new ValidationError('AMMWithdraw: Asset must be an Issue') } @@ -107,7 +107,7 @@ export function validateAMMWithdraw(tx: Record): void { throw new ValidationError('AMMWithdraw: missing field Asset2') } - if (!isIssue(tx.Asset2)) { + if (!isCurrency(tx.Asset2)) { throw new ValidationError('AMMWithdraw: Asset2 must be an Issue') } diff --git a/packages/xrpl/src/models/transactions/common.ts b/packages/xrpl/src/models/transactions/common.ts index 14051fb543..f8e7a532fc 100644 --- a/packages/xrpl/src/models/transactions/common.ts +++ b/packages/xrpl/src/models/transactions/common.ts @@ -64,7 +64,7 @@ function isRecord(value: unknown): value is Record { * @param input - The input to check the form and type of. * @returns Whether the IssuedCurrency is properly formed. */ -export function isIssue(input: unknown): input is Currency { +export function isCurrency(input: unknown): input is Currency { return ( isRecord(input) && ((Object.keys(input).length === ISSUE_SIZE && From bad598f29f4f7db2bd98599eb154808065166290 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 16 May 2023 17:27:35 -0400 Subject: [PATCH 66/93] add AMM ledger entry object, lsfAMM flag, amm fields to LedgerEntryRequest --- packages/xrpl/src/models/ledger/AMM.ts | 90 +++++++++++++++++++ .../xrpl/src/models/ledger/AccountRoot.ts | 8 ++ .../xrpl/src/models/ledger/LedgerEntry.ts | 2 + packages/xrpl/src/models/methods/ammInfo.ts | 4 +- .../xrpl/src/models/methods/ledgerEntry.ts | 15 ++++ 5 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 packages/xrpl/src/models/ledger/AMM.ts diff --git a/packages/xrpl/src/models/ledger/AMM.ts b/packages/xrpl/src/models/ledger/AMM.ts new file mode 100644 index 0000000000..1e501c8245 --- /dev/null +++ b/packages/xrpl/src/models/ledger/AMM.ts @@ -0,0 +1,90 @@ +import { Currency } from '../common' + +import BaseLedgerEntry from './BaseLedgerEntry' + +interface AuthAccount { + AuthAccount: { + account: string + } +} + +interface VoteSlot { + VoteEntry: { + Account: string + TradingFee: number + VoteWeight: number + } +} + +/** + * The AMM object type describes a single Automated Market Maker (AMM) instance. + * + * @category Ledger Entries + */ +export default interface AMM extends BaseLedgerEntry { + LedgerEntryType: 'AMM' + /** + * The address of the special account that holds this AMM's assets. + */ + AMMAccount: string + /** + * The definition for one of the two assets this AMM holds. + */ + Asset: { + currency: string + issuer?: string + } + /** + * The definition for the other asset this AMM holds. + */ + Asset2: { + currency: string + issuer?: string + } + /** + * Details of the current owner of the auction slot. + */ + AuctionSlot?: { + /** + * The current owner of this auction slot. + */ + Account: string + /** + * A list of at most 4 additional accounts that are authorized to trade at the discounted fee for this AMM instance. + */ + AuthAccounts?: AuthAccount[] + /** + * The trading fee to be charged to the auction owner, in the same format as TradingFee. + * By default this is 0, meaning that the auction owner can trade at no fee instead of the standard fee for this AMM. + */ + DiscountedFee: number + /** + * The time when this slot expires, in seconds since the Ripple Epoch. + */ + Expiration: number + /** + * The amount the auction owner paid to win this slot, in LP Tokens. + */ + Price: Currency + } + /** + * The total outstanding balance of liquidity provider tokens from this AMM instance. + * The holders of these tokens can vote on the AMM's trading fee in proportion to their holdings, + * or redeem the tokens for a share of the AMM's assets which grows with the trading fees collected. + */ + LPTokenBalance: Currency + /** + * The percentage fee to be charged for trades against this AMM instance, in units of 1/100,000. + * The maximum value is 1000, for a 1% fee. + */ + TradingFee: number + /** + * A list of vote objects, representing votes on the pool's trading fee. + */ + VoteSlots?: VoteSlot[] + /** + * A bit-map of boolean flags. No flags are defined for the AMM object + * type, so this value is always 0. + */ + Flags: 0 +} diff --git a/packages/xrpl/src/models/ledger/AccountRoot.ts b/packages/xrpl/src/models/ledger/AccountRoot.ts index b98ead82a2..55a5bdbfce 100644 --- a/packages/xrpl/src/models/ledger/AccountRoot.ts +++ b/packages/xrpl/src/models/ledger/AccountRoot.ts @@ -116,6 +116,10 @@ export interface AccountRootFlagsInterface { * (It has DepositAuth enabled.) */ lsfDepositAuth?: boolean + /** + * This account is an Automated Market Maker (AMM) instance. + */ + lsfAMM?: boolean /** * Disallow incoming NFTOffers from other accounts. */ @@ -172,6 +176,10 @@ export enum AccountRootFlags { * (It has DepositAuth enabled.) */ lsfDepositAuth = 0x01000000, + /** + * This account is an Automated Market Maker (AMM) instance. + */ + lsfAMM = 0x02000000, /** * Disallow incoming NFTOffers from other accounts. */ diff --git a/packages/xrpl/src/models/ledger/LedgerEntry.ts b/packages/xrpl/src/models/ledger/LedgerEntry.ts index 1302c32e7d..c09883fb17 100644 --- a/packages/xrpl/src/models/ledger/LedgerEntry.ts +++ b/packages/xrpl/src/models/ledger/LedgerEntry.ts @@ -1,5 +1,6 @@ import AccountRoot from './AccountRoot' import Amendments from './Amendments' +import AMM from './AMM' import Check from './Check' import DepositPreauth from './DepositPreauth' import DirectoryNode from './DirectoryNode' @@ -16,6 +17,7 @@ import Ticket from './Ticket' type LedgerEntry = | AccountRoot | Amendments + | AMM | Check | DepositPreauth | DirectoryNode diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index 75c644ed6e..8d9568349d 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -28,7 +28,7 @@ interface AuthAccount { account: string } -interface VoteEntry { +interface VoteSlot { account: string trading_fee: number vote_weight: number @@ -122,7 +122,7 @@ export interface AMMInfoResponse extends BaseResponse { /** * Keeps a track of up to eight active votes for the instance. */ - vote_slots?: VoteEntry[] + vote_slots?: VoteSlot[] } /** diff --git a/packages/xrpl/src/models/methods/ledgerEntry.ts b/packages/xrpl/src/models/methods/ledgerEntry.ts index f499aab84c..fe8f9527a3 100644 --- a/packages/xrpl/src/models/methods/ledgerEntry.ts +++ b/packages/xrpl/src/models/methods/ledgerEntry.ts @@ -21,6 +21,21 @@ import { BaseRequest, BaseResponse } from './baseMethod' */ export interface LedgerEntryRequest extends BaseRequest { command: 'ledger_entry' + /** + * Retrieve an Automated Market Maker (AMM) object from the ledger. + * This is similar to amm_info method, but the ledger_entry version returns only the ledger entry as stored. + */ + amm?: { + asset: { + currency: string + issuer?: string + } + asset2: { + currency: string + issuer?: string + } + } + /** * If true, return the requested ledger object's contents as a hex string in * the XRP Ledger's binary format. Otherwise, return data in JSON format. The From aa37dfe925c7989666c40b89706baece58a09714 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 16 May 2023 17:56:03 -0400 Subject: [PATCH 67/93] update definitions.json --- .../src/enums/definitions.json | 85 ++++++++++++++----- 1 file changed, 64 insertions(+), 21 deletions(-) diff --git a/packages/ripple-binary-codec/src/enums/definitions.json b/packages/ripple-binary-codec/src/enums/definitions.json index e5ecefb487..1e638ce181 100644 --- a/packages/ripple-binary-codec/src/enums/definitions.json +++ b/packages/ripple-binary-codec/src/enums/definitions.json @@ -333,6 +333,16 @@ "type": "UInt16" } ], + [ + "NetworkID", + { + "nth": 1, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], [ "Flags", { @@ -776,7 +786,7 @@ [ "VoteWeight", { - "nth": 47, + "nth": 48, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -786,7 +796,17 @@ [ "DiscountedFee", { - "nth": 48, + "nth": 49, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "FirstNFTokenSequence", + { + "nth": 50, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -1493,10 +1513,40 @@ "type": "Amount" } ], + [ + "BaseFeeDrops", + { + "nth": 22, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Amount" + } + ], + [ + "ReserveBaseDrops", + { + "nth": 23, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Amount" + } + ], + [ + "ReserveIncrementDrops", + { + "nth": 24, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Amount" + } + ], [ "LPTokenOut", { - "nth": 20, + "nth": 25, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -1506,7 +1556,7 @@ [ "LPTokenIn", { - "nth": 21, + "nth": 26, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -1516,7 +1566,7 @@ [ "EPrice", { - "nth": 22, + "nth": 27, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -1526,7 +1576,7 @@ [ "Price", { - "nth": 23, + "nth": 28, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -1536,7 +1586,7 @@ [ "LPTokenBalance", { - "nth": 24, + "nth": 29, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -1873,16 +1923,6 @@ "type": "AccountID" } ], - [ - "AMMAccount", - { - "nth": 11, - "isVLEncoded": true, - "isSerialized": true, - "isSigningField": true, - "type": "AccountID" - } - ], [ "HookAccount", { @@ -2186,7 +2226,7 @@ [ "AuctionSlot", { - "nth": 27, + "nth": 26, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -2196,7 +2236,7 @@ [ "AuthAccount", { - "nth": 28, + "nth": 27, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -2296,7 +2336,7 @@ [ "VoteSlots", { - "nth": 14, + "nth": 12, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -2356,7 +2396,7 @@ [ "AuthAccounts", { - "nth": 26, + "nth": 21, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -2378,6 +2418,9 @@ "telCAN_NOT_QUEUE_BLOCKED": -389, "telCAN_NOT_QUEUE_FEE": -388, "telCAN_NOT_QUEUE_FULL": -387, + "telWRONG_NETWORK": -386, + "telREQUIRES_NETWORK_ID": -385, + "telNETWORK_ID_MAKES_TX_NON_CANONICAL": -384, "temMALFORMED": -299, "temBAD_AMOUNT": -298, From a2f5b57b5d1e1d0327b0117124eb235e1dc114a4 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 23 May 2023 16:29:51 -0400 Subject: [PATCH 68/93] WIP defintions --- packages/ripple-binary-codec/src/enums/definitions.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ripple-binary-codec/src/enums/definitions.json b/packages/ripple-binary-codec/src/enums/definitions.json index 1e638ce181..402df6973c 100644 --- a/packages/ripple-binary-codec/src/enums/definitions.json +++ b/packages/ripple-binary-codec/src/enums/definitions.json @@ -1586,7 +1586,7 @@ [ "LPTokenBalance", { - "nth": 29, + "nth": 31, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, From 8c34754a1ca1250626cdc0338ea59c49cb18a594 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 23 May 2023 16:36:20 -0400 Subject: [PATCH 69/93] update codec-fixtures --- .../test/fixtures/codec-fixtures.json | 156 +++++++++--------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/packages/ripple-binary-codec/test/fixtures/codec-fixtures.json b/packages/ripple-binary-codec/test/fixtures/codec-fixtures.json index 5758dbf5b5..53611f1d13 100644 --- a/packages/ripple-binary-codec/test/fixtures/codec-fixtures.json +++ b/packages/ripple-binary-codec/test/fixtures/codec-fixtures.json @@ -4450,11 +4450,11 @@ } }, { - "binary": "12002315000A220000000024000000026140000000000027106840000000000000016BD5838D7EA4C680000000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C7321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D07440913E39EC2BA0E5BC4C5DF1222B1AE9E76758F2B8FFEF1F056076147BB0ADC8117CD0296360DA08B3D48BE9EFC8693C03A253E0D9F166C19CA8D936F9E61A1100811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E", + "binary": "12002315000A2200000000240015DAE161400000000000271068400000000000000A6BD5838D7EA4C680000000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C7321ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B87440B3154D968314FCEB58001E1B0C3A4CFB33DF9FF6C73207E5EAEB9BD07E2747672168E1A2786D950495C38BD8DEE3391BF45F3008DD36F4B12E7C07D82CA5250E8114F92F27CC5EE2F2760278FE096D0CBE32BDD3653A", "json": { - "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "Account": "rP5ZkB5RZQaECsSVR4DeSFK4fAw52BYtbw", "TransactionType": "AMMCreate", - "TxnSignature": "913E39EC2BA0E5BC4C5DF1222B1AE9E76758F2B8FFEF1F056076147BB0ADC8117CD0296360DA08B3D48BE9EFC8693C03A253E0D9F166C19CA8D936F9E61A1100", + "TxnSignature": "B3154D968314FCEB58001E1B0C3A4CFB33DF9FF6C73207E5EAEB9BD07E2747672168E1A2786D950495C38BD8DEE3391BF45F3008DD36F4B12E7C07D82CA5250E", "Amount": "10000", "Amount2": { "currency": "ETH", @@ -4462,198 +4462,198 @@ "value": "10000" }, "TradingFee": 10, - "Fee": "1", + "Fee": "10", "Flags": 0, - "Sequence": 2, - "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0" + "Sequence": 1432289, + "SigningPubKey": "ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B8" } }, { - "binary": "120024220001000024000000026840000000000000016014D5438D7EA4C68000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0487321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D074409EEE8CF88C668B955E7EEAB1B4A1B059EDF4F51B7F1546810F87E3E48B09237F015C651E37FB40A979E00EA21361D4E18D7A33DB7DD23070CEEAB2648AB3BB0D811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "binary": "1200242200010000240015DAE168400000000000000A6019D5438D7EA4C68000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0487321ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B874408073C588E7EF672DD171E414638D9AF8DBE9A1359E030DE3E1C9AA6A38A2CE9E138CB56482BB844F7228D48B1E4AD7D09BB7E9F639C115958EEEA374749CA00B8114F92F27CC5EE2F2760278FE096D0CBE32BDD3653A0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", "json": { - "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "Account": "rP5ZkB5RZQaECsSVR4DeSFK4fAw52BYtbw", "TransactionType": "AMMDeposit", - "TxnSignature": "9EEE8CF88C668B955E7EEAB1B4A1B059EDF4F51B7F1546810F87E3E48B09237F015C651E37FB40A979E00EA21361D4E18D7A33DB7DD23070CEEAB2648AB3BB0D", + "TxnSignature": "8073C588E7EF672DD171E414638D9AF8DBE9A1359E030DE3E1C9AA6A38A2CE9E138CB56482BB844F7228D48B1E4AD7D09BB7E9F639C115958EEEA374749CA00B", "Asset": {"currency": "XRP"}, "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, "LPTokenOut": {"currency": "B3813FCAB4EE68B3D0D735D6849465A9113EE048", "issuer": "rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg", "value": "1000"}, - "Fee": "1", + "Fee": "10", "Flags": 65536, - "Sequence": 2, - "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0" + "Sequence": 1432289, + "SigningPubKey": "ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B8" } }, { - "binary": "120024220008000024000000026140000000000003E86840000000000000017321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D07440BD18A6E2B10B451F61CFADC32B59A0243702DC5DAAE556D51CB9C79981D40C78101FFA9DE6163CFBDF6E7578DF02F2AE3B8A5AB60697E0746D65064D91E8F90A811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "binary": "1200242200080000240015DAE16140000000000003E868400000000000000A7321ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B8744096CA066F42871C55088D2758D64148921B1ACAA5C6C648D0F7D675BBF47F87DF711F17C5BD172666D5AEC257520C587A849A6E063345609D91E121A78816EB048114F92F27CC5EE2F2760278FE096D0CBE32BDD3653A0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", "json": { - "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "Account": "rP5ZkB5RZQaECsSVR4DeSFK4fAw52BYtbw", "TransactionType": "AMMDeposit", "Asset": {"currency": "XRP"}, "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, "Amount": "1000", - "Fee": "1", + "Fee": "10", "Flags": 524288, - "Sequence": 2, - "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", - "TxnSignature": "BD18A6E2B10B451F61CFADC32B59A0243702DC5DAAE556D51CB9C79981D40C78101FFA9DE6163CFBDF6E7578DF02F2AE3B8A5AB60697E0746D65064D91E8F90A" + "Sequence": 1432289, + "SigningPubKey": "ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B8", + "TxnSignature": "96CA066F42871C55088D2758D64148921B1ACAA5C6C648D0F7D675BBF47F87DF711F17C5BD172666D5AEC257520C587A849A6E063345609D91E121A78816EB04" } }, { - "binary": "120024220010000024000000026140000000000003E86840000000000000016BD511C37937E080000000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C7321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D07440E0B1AE32A0F731BF0CEF0D019295BD7F35B22F11A5962F65FA99EE4D38993B14B53DB11C15E36D756E282812E9015D38A6F225940A157693F43F9B795C59950F811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "binary": "1200242200100000240015DAE16140000000000003E868400000000000000A6BD511C37937E080000000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C7321ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B87440FC22B16A098C236ED7EDB3EBC983026DFD218A03C8BAA848F3E1D5389D5B8B00473C1178C5BA257BFA2DCD433C414690A430A5CFD71C1C0A7F7BF725EC1759018114F92F27CC5EE2F2760278FE096D0CBE32BDD3653A0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", "json": { - "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "Account": "rP5ZkB5RZQaECsSVR4DeSFK4fAw52BYtbw", "TransactionType": "AMMDeposit", "Asset": {"currency": "XRP"}, "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, "Amount": "1000", "Amount2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9", "value": "500"}, - "Fee": "1", + "Fee": "10", "Flags": 1048576, - "Sequence": 2, - "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", - "TxnSignature": "E0B1AE32A0F731BF0CEF0D019295BD7F35B22F11A5962F65FA99EE4D38993B14B53DB11C15E36D756E282812E9015D38A6F225940A157693F43F9B795C59950F" + "Sequence": 1432289, + "SigningPubKey": "ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B8", + "TxnSignature": "FC22B16A098C236ED7EDB3EBC983026DFD218A03C8BAA848F3E1D5389D5B8B00473C1178C5BA257BFA2DCD433C414690A430A5CFD71C1C0A7F7BF725EC175901" } }, { - "binary": "120024220020000024000000026140000000000003E86840000000000000016014D5438D7EA4C68000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0487321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D07440452BC59F9EE12C224EC983EFDF580F20C4A50E897105FD1FB13520D9753CFB02BD210599181574DF6AD0DB6A42C1EA48D9E48FC3D11B9008E4C76FBB163D5B00811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "binary": "1200242200200000240015DAE16140000000000003E868400000000000000A6019D5438D7EA4C68000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0487321ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B87440117CF90F9B113AD3BD638B6DB63562B37C287D5180F278B3CCF58FC14A5BAEE98307EA0F6DFE19E2FBA887C92955BA5D1A04F92ADAAEB309DE89C3610D074C098114F92F27CC5EE2F2760278FE096D0CBE32BDD3653A0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", "json": { - "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "Account": "rP5ZkB5RZQaECsSVR4DeSFK4fAw52BYtbw", "TransactionType": "AMMDeposit", "Asset": {"currency": "XRP"}, "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, "Amount": "1000", "LPTokenOut": {"currency": "B3813FCAB4EE68B3D0D735D6849465A9113EE048", "issuer": "rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg", "value": "1000"}, - "Fee": "1", + "Fee": "10", "Flags": 2097152, - "Sequence": 2, - "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", - "TxnSignature": "452BC59F9EE12C224EC983EFDF580F20C4A50E897105FD1FB13520D9753CFB02BD210599181574DF6AD0DB6A42C1EA48D9E48FC3D11B9008E4C76FBB163D5B00" + "Sequence": 1432289, + "SigningPubKey": "ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B8", + "TxnSignature": "117CF90F9B113AD3BD638B6DB63562B37C287D5180F278B3CCF58FC14A5BAEE98307EA0F6DFE19E2FBA887C92955BA5D1A04F92ADAAEB309DE89C3610D074C09" } }, { - "binary": "120024220040000024000000026140000000000003E8684000000000000001601640000000000000197321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D07440DD6685DC586FAA6AD2D50D785900122EB147D4AC09A55D7080267A9B38180F87CEC44B823359FC3F0AC0104D47B53FFC6B80415664C3C4582672420A0100F70C811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "binary": "1200242200400000240015DAE16140000000000003E868400000000000000A601B40000000000000197321ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B874405E51EBC6B52A7C3BA5D0AE2FC8F62E779B80182009B3108A87AB6D770D68F56053C193DB0640128E4765565970625B1E2878E116AC854E6DED412202CCDE0B0D8114F92F27CC5EE2F2760278FE096D0CBE32BDD3653A0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", "json": { - "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "Account": "rP5ZkB5RZQaECsSVR4DeSFK4fAw52BYtbw", "TransactionType": "AMMDeposit", "Asset": {"currency": "XRP"}, "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, "Amount": "1000", "EPrice": "25", - "Fee": "1", + "Fee": "10", "Flags": 4194304, - "Sequence": 2, - "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", - "TxnSignature": "DD6685DC586FAA6AD2D50D785900122EB147D4AC09A55D7080267A9B38180F87CEC44B823359FC3F0AC0104D47B53FFC6B80415664C3C4582672420A0100F70C" + "Sequence": 1432289, + "SigningPubKey": "ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B8", + "TxnSignature": "5E51EBC6B52A7C3BA5D0AE2FC8F62E779B80182009B3108A87AB6D770D68F56053C193DB0640128E4765565970625B1E2878E116AC854E6DED412202CCDE0B0D" } }, { - "binary": "120025220001000024000000026840000000000000016015D5438D7EA4C68000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0487321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0744066944797E9F03808C9A00AAEFF786AD74FEB2E64B51A9601E89ABA820AAA15927C2E961A9CCA22C4B0D2A2B55E342BD6E297BD765B6F4D3FDCA578A3416BB505811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "binary": "1200252200010000240015DAE168400000000000000A601AD5438D7EA4C68000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0487321ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B874409D4F41FC452526C0AD17191959D9B6D04A3C73B3A6C29E0F34C8459675A83A7A7D6E3021390EC8C9BE6C93E11C167E12016465E523F64F9EB3194B0A52E418028114F92F27CC5EE2F2760278FE096D0CBE32BDD3653A0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", "json": { - "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "Account": "rP5ZkB5RZQaECsSVR4DeSFK4fAw52BYtbw", "TransactionType": "AMMWithdraw", "Asset": {"currency": "XRP"}, "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, "LPTokenIn": {"currency": "B3813FCAB4EE68B3D0D735D6849465A9113EE048", "issuer": "rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg", "value": "1000"}, - "Fee": "1", + "Fee": "10", "Flags": 65536, - "Sequence": 2, - "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", - "TxnSignature": "66944797E9F03808C9A00AAEFF786AD74FEB2E64B51A9601E89ABA820AAA15927C2E961A9CCA22C4B0D2A2B55E342BD6E297BD765B6F4D3FDCA578A3416BB505" + "Sequence": 1432289, + "SigningPubKey": "ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B8", + "TxnSignature": "9D4F41FC452526C0AD17191959D9B6D04A3C73B3A6C29E0F34C8459675A83A7A7D6E3021390EC8C9BE6C93E11C167E12016465E523F64F9EB3194B0A52E41802" } }, { - "binary": "120025220008000024000000026140000000000003E86840000000000000017321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D07440E30397CE7E99B13D35FFB5C66725B17F4F103675E10293C7B1D63C1BE3FA81B884BD3FBD31B52F6B811F99C5FBB5102D170EC379C268DF80DABF04E7F2DD4F0C811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "binary": "1200252200080000240015DAE16140000000000003E868400000000000000A7321ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B87440E2C60D56C337D6D73E4B7D53579C93C666605494E82A89DD58CFDE79E2A4866BCF52370A2146877A2EF748E98168373710001133A51B645D89491849079035018114F92F27CC5EE2F2760278FE096D0CBE32BDD3653A0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", "json": { - "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "Account": "rP5ZkB5RZQaECsSVR4DeSFK4fAw52BYtbw", "TransactionType": "AMMWithdraw", "Asset": {"currency": "XRP"}, "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, "Amount": "1000", - "Fee": "1", + "Fee": "10", "Flags": 524288, - "Sequence": 2, - "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", - "TxnSignature": "E30397CE7E99B13D35FFB5C66725B17F4F103675E10293C7B1D63C1BE3FA81B884BD3FBD31B52F6B811F99C5FBB5102D170EC379C268DF80DABF04E7F2DD4F0C" + "Sequence": 1432289, + "SigningPubKey": "ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B8", + "TxnSignature": "E2C60D56C337D6D73E4B7D53579C93C666605494E82A89DD58CFDE79E2A4866BCF52370A2146877A2EF748E98168373710001133A51B645D8949184907903501" } }, { - "binary": "120025220010000024000000026140000000000003E86840000000000000016BD511C37937E080000000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C7321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D07440C0818312B269A4EF16C1C7EBBB74EFD1852A288BB214A714B8BE3B5F4B2F9CFDFF4F66C931B8434244A8016035B9EC9493B7CF5E0ACF4570A88DF808D79E4300811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "binary": "1200252200100000240015DAE16140000000000003E868400000000000000A6BD511C37937E080000000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C7321ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B87440D2FCD7D03E53358BC6188BA88A7BA4FF2519B639C3B5C0EBCBDCB704426CA2837111430E92A6003D1CD0D81C63682C74839320539EC4F89B82AA5607714952028114F92F27CC5EE2F2760278FE096D0CBE32BDD3653A0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", "json": { - "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "Account": "rP5ZkB5RZQaECsSVR4DeSFK4fAw52BYtbw", "TransactionType": "AMMWithdraw", "Asset": {"currency": "XRP"}, "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, "Amount": "1000", "Amount2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9", "value": "500"}, - "Fee": "1", + "Fee": "10", "Flags": 1048576, - "Sequence": 2, - "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", - "TxnSignature": "C0818312B269A4EF16C1C7EBBB74EFD1852A288BB214A714B8BE3B5F4B2F9CFDFF4F66C931B8434244A8016035B9EC9493B7CF5E0ACF4570A88DF808D79E4300" + "Sequence": 1432289, + "SigningPubKey": "ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B8", + "TxnSignature": "D2FCD7D03E53358BC6188BA88A7BA4FF2519B639C3B5C0EBCBDCB704426CA2837111430E92A6003D1CD0D81C63682C74839320539EC4F89B82AA560771495202" } }, { - "binary": "120025220020000024000000026140000000000003E86840000000000000016015D5438D7EA4C68000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0487321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0744073552B3DC7AE99DDF4E4FF0D60E6D0BE4688E3474D363603FA25DA6AD8BBA8F0E4E3EA82ADB2B57F5B9A6C379969E00095546DDA0E74FF3D0F0689351C2F8C06811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "binary": "1200252200200000240015DAE16140000000000003E868400000000000000A601AD5438D7EA4C68000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0487321ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B8744042DA5620E924E2D2059BBB4E0C4F03244140ACED93B543136FEEDF802165F814D09F45C7E2A4618468442516F4712A23B1D3332D5DBDBAE830337F39F259C90F8114F92F27CC5EE2F2760278FE096D0CBE32BDD3653A0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", "json": { - "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "Account": "rP5ZkB5RZQaECsSVR4DeSFK4fAw52BYtbw", "TransactionType": "AMMWithdraw", "Asset": {"currency": "XRP"}, "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, "Amount": "1000", "LPTokenIn": {"currency": "B3813FCAB4EE68B3D0D735D6849465A9113EE048", "issuer": "rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg", "value": "1000"}, - "Fee": "1", + "Fee": "10", "Flags": 2097152, - "Sequence": 2, - "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", - "TxnSignature": "73552B3DC7AE99DDF4E4FF0D60E6D0BE4688E3474D363603FA25DA6AD8BBA8F0E4E3EA82ADB2B57F5B9A6C379969E00095546DDA0E74FF3D0F0689351C2F8C06" + "Sequence": 1432289, + "SigningPubKey": "ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B8", + "TxnSignature": "42DA5620E924E2D2059BBB4E0C4F03244140ACED93B543136FEEDF802165F814D09F45C7E2A4618468442516F4712A23B1D3332D5DBDBAE830337F39F259C90F" } }, { - "binary": "120025220040000024000000026140000000000003E8684000000000000001601640000000000000197321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0744023BAFE5BFE58E7BF0B02B5875983D007C10796C8E62A190BF688EBE5D8A104DAD2DE7EDE995FE2E494883FD8140F38E22E3376A2F49C50EFCAA00C7499A4690E811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "binary": "1200252200400000240015DAE16140000000000003E868400000000000000A601B40000000000000197321ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B8744045BCEE5A12E5F5F1FB085A24F2F7FD962BBCB0D89A44A5319E3F7E3799E1870341880B6F684132971DDDF2E6B15356B3F407962D6D4E8DE10989F3B16E3CB90D8114F92F27CC5EE2F2760278FE096D0CBE32BDD3653A0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", "json": { - "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "Account": "rP5ZkB5RZQaECsSVR4DeSFK4fAw52BYtbw", "TransactionType": "AMMWithdraw", "Asset": {"currency": "XRP"}, "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, "Amount": "1000", "EPrice": "25", - "Fee": "1", + "Fee": "10", "Flags": 4194304, - "Sequence": 2, - "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", - "TxnSignature": "23BAFE5BFE58E7BF0B02B5875983D007C10796C8E62A190BF688EBE5D8A104DAD2DE7EDE995FE2E494883FD8140F38E22E3376A2F49C50EFCAA00C7499A4690E" + "Sequence": 1432289, + "SigningPubKey": "ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B8", + "TxnSignature": "45BCEE5A12E5F5F1FB085A24F2F7FD962BBCB0D89A44A5319E3F7E3799E1870341880B6F684132971DDDF2E6B15356B3F407962D6D4E8DE10989F3B16E3CB90D" } }, { - "binary": "120027220000000024000000026840000000000000016CD4C8E1BC9BF04000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0486DD4CC6F3B40B6C000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0487321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D074406B2A1548E6DC14681356C27CCBE7072CAB2AD8C72D0D7A045916FB0E0DBE6BF71A429CC519E9200172829D3EEF79100899D3A8710C1C3C1A2B664FD64086AD0A811462D4D845D20B4F09CFEA8BB4C01063D99FC9673EF01AE01C81149A91957F8F16BC57F3F200CD8C98375BF1791586E1F10318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "binary": "1200272200000000240015DAE168400000000000000A6CD4C8E1BC9BF04000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0486DD4CC6F3B40B6C000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0487321ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B87440F8EAAFB5EC1A69275167589969F0B9764BACE6BC8CC81482C2FC5ACCE691EDBD0D88D141137B1253BB1B9AC90A8A52CB37F5B6F7E1028B06DD06F91BE06F5A0F8114F92F27CC5EE2F2760278FE096D0CBE32BDD3653AF015E01B81149A91957F8F16BC57F3F200CD8C98375BF1791586E1F10318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", "json": { - "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "Account": "rP5ZkB5RZQaECsSVR4DeSFK4fAw52BYtbw", "TransactionType": "AMMBid", "Asset": {"currency": "XRP"}, "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, "AuthAccounts": [{"AuthAccount": {"Account": "rEaHTti4HZsMBpxTAF4ncWxkcdqDh1h6P7"}}], "BidMax": {"currency": "B3813FCAB4EE68B3D0D735D6849465A9113EE048", "issuer": "rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg", "value": "35"}, "BidMin": {"currency": "B3813FCAB4EE68B3D0D735D6849465A9113EE048", "issuer": "rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg", "value": "25"}, - "Fee": "1", + "Fee": "10", "Flags": 0, - "Sequence": 2, - "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", - "TxnSignature": "6B2A1548E6DC14681356C27CCBE7072CAB2AD8C72D0D7A045916FB0E0DBE6BF71A429CC519E9200172829D3EEF79100899D3A8710C1C3C1A2B664FD64086AD0A" + "Sequence": 1432289, + "SigningPubKey": "ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B8", + "TxnSignature": "F8EAAFB5EC1A69275167589969F0B9764BACE6BC8CC81482C2FC5ACCE691EDBD0D88D141137B1253BB1B9AC90A8A52CB37F5B6F7E1028B06DD06F91BE06F5A0F" } }, { - "binary": "1200261500EA220000000024000000026840000000000000017321ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0744072767CF9A0F5E9C9DA6BBB6E84905B0ECDF122D3E2D730843EFD377521E8E73664AD809D0A54E8C75CD1735ACB64E310BB49FDED10913FA150B8C006D4ACEC00811462D4D845D20B4F09CFEA8BB4C01063D99FC9673E0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "binary": "1200261500EA2200000000240015DAE168400000000000000A7321ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B87440BC2F6E76969E3747E9BDE183C97573B086212F09D5387460E6EE2F32953E85EAEB9618FBBEF077276E30E59D619FCF7C7BDCDDDD9EB94D7CE1DD5CE9246B21078114F92F27CC5EE2F2760278FE096D0CBE32BDD3653A0318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", "json": { - "Account": "rwr2UWxNwoBdysPSiDDraTQjAQKZEeZAcV", + "Account": "rP5ZkB5RZQaECsSVR4DeSFK4fAw52BYtbw", "TransactionType": "AMMVote", "Asset": {"currency": "XRP"}, "Asset2": {"currency": "ETH", "issuer": "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9"}, "TradingFee": 234, - "Fee": "1", + "Fee": "10", "Flags": 0, - "Sequence": 2, - "SigningPubKey": "ED8A00C1D29E762266576408B08D583B987673550655F930635678B436D5CDF7D0", - "TxnSignature": "72767CF9A0F5E9C9DA6BBB6E84905B0ECDF122D3E2D730843EFD377521E8E73664AD809D0A54E8C75CD1735ACB64E310BB49FDED10913FA150B8C006D4ACEC00" + "Sequence": 1432289, + "SigningPubKey": "ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B8", + "TxnSignature": "BC2F6E76969E3747E9BDE183C97573B086212F09D5387460E6EE2F32953E85EAEB9618FBBEF077276E30E59D619FCF7C7BDCDDDD9EB94D7CE1DD5CE9246B2107" } }], "ledgerData": [{ From 70609e070bdc24c34780de0ed1afa36430f7e50c Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 24 May 2023 12:37:37 -0400 Subject: [PATCH 70/93] fix definitions test --- packages/ripple-binary-codec/test/definitions.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ripple-binary-codec/test/definitions.test.js b/packages/ripple-binary-codec/test/definitions.test.js index 3ac575b3a9..043f65b0c1 100644 --- a/packages/ripple-binary-codec/test/definitions.test.js +++ b/packages/ripple-binary-codec/test/definitions.test.js @@ -69,7 +69,7 @@ describe('encode and decode using new types as a parameter', function () { // Normally this would be generated directly from rippled with something like `server_definitions`. // Added here to make it easier to see what is actually changing in the definitions.json file. const definitions = JSON.parse(JSON.stringify(normalDefinitionsJson)) - definitions.TYPES.NewType = 24 + definitions.TYPES.NewType = 31 definitions.FIELDS.push([ 'TestField', { From 7664b6273cf4664f42d9757c6aed995a890d140d Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 6 Jun 2023 18:04:22 -0400 Subject: [PATCH 71/93] update DiscountedFee definition --- .../src/enums/definitions.json | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/ripple-binary-codec/src/enums/definitions.json b/packages/ripple-binary-codec/src/enums/definitions.json index 402df6973c..7c7e976302 100644 --- a/packages/ripple-binary-codec/src/enums/definitions.json +++ b/packages/ripple-binary-codec/src/enums/definitions.json @@ -283,6 +283,16 @@ "type": "UInt16" } ], + [ + "DiscountedFee", + { + "nth": 6, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt16" + } + ], [ "Version", { @@ -793,16 +803,6 @@ "type": "UInt32" } ], - [ - "DiscountedFee", - { - "nth": 49, - "isVLEncoded": false, - "isSerialized": true, - "isSigningField": true, - "type": "UInt32" - } - ], [ "FirstNFTokenSequence", { From 143f860d0310f8fa55267e5a0b832d098ae031d7 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 7 Jun 2023 14:35:24 -0400 Subject: [PATCH 72/93] update definitions --- packages/ripple-binary-codec/src/enums/definitions.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/ripple-binary-codec/src/enums/definitions.json b/packages/ripple-binary-codec/src/enums/definitions.json index 7c7e976302..3bf5a024aa 100644 --- a/packages/ripple-binary-codec/src/enums/definitions.json +++ b/packages/ripple-binary-codec/src/enums/definitions.json @@ -2396,7 +2396,7 @@ [ "AuthAccounts", { - "nth": 21, + "nth": 25, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -2460,7 +2460,7 @@ "temUNKNOWN": -264, "temSEQ_AND_TICKET": -263, "temBAD_NFTOKEN_TRANSFER_FEE": -262, - "temAMM_BAD_TOKENS": -261, + "temBAD_AMM_TOKENS": -261, "tefFAILURE": -199, "tefALREADY": -198, @@ -2546,7 +2546,7 @@ "tecINSUFFICIENT_FUNDS": 159, "tecOBJECT_NOT_FOUND": 160, "tecINSUFFICIENT_PAYMENT": 161, - "tecAMM_UNFUNDED": 162, + "tecUNFUNDED_AMM": 162, "tecAMM_BALANCE": 163, "tecAMM_FAILED_DEPOSIT": 164, "tecAMM_FAILED_WITHDRAW": 165, From f8eb8325fc73b6ddc3d9dc8f543f987ced0e4583 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 7 Jun 2023 14:37:06 -0400 Subject: [PATCH 73/93] update codec-fixtures --- packages/ripple-binary-codec/test/fixtures/codec-fixtures.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ripple-binary-codec/test/fixtures/codec-fixtures.json b/packages/ripple-binary-codec/test/fixtures/codec-fixtures.json index 53611f1d13..f7995f77b1 100644 --- a/packages/ripple-binary-codec/test/fixtures/codec-fixtures.json +++ b/packages/ripple-binary-codec/test/fixtures/codec-fixtures.json @@ -4625,7 +4625,7 @@ } }, { - "binary": "1200272200000000240015DAE168400000000000000A6CD4C8E1BC9BF04000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0486DD4CC6F3B40B6C000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0487321ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B87440F8EAAFB5EC1A69275167589969F0B9764BACE6BC8CC81482C2FC5ACCE691EDBD0D88D141137B1253BB1B9AC90A8A52CB37F5B6F7E1028B06DD06F91BE06F5A0F8114F92F27CC5EE2F2760278FE096D0CBE32BDD3653AF015E01B81149A91957F8F16BC57F3F200CD8C98375BF1791586E1F10318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", + "binary": "1200272200000000240015DAE168400000000000000A6CD4C8E1BC9BF04000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0486DD4CC6F3B40B6C000B3813FCAB4EE68B3D0D735D6849465A9113EE048B3813FCAB4EE68B3D0D735D6849465A9113EE0487321ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B87440F8EAAFB5EC1A69275167589969F0B9764BACE6BC8CC81482C2FC5ACCE691EDBD0D88D141137B1253BB1B9AC90A8A52CB37F5B6F7E1028B06DD06F91BE06F5A0F8114F92F27CC5EE2F2760278FE096D0CBE32BDD3653AF019E01B81149A91957F8F16BC57F3F200CD8C98375BF1791586E1F10318000000000000000000000000000000000000000004180000000000000000000000004554480000000000FBEF9A3A2B814E807745FA3D9C32FFD155FA2E8C", "json": { "Account": "rP5ZkB5RZQaECsSVR4DeSFK4fAw52BYtbw", "TransactionType": "AMMBid", From d7c4361cf1ece029a9aefd9bf6320dd594a3a2ad Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Fri, 9 Jun 2023 16:52:00 -0400 Subject: [PATCH 74/93] update definitions --- packages/ripple-binary-codec/src/enums/definitions.json | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/ripple-binary-codec/src/enums/definitions.json b/packages/ripple-binary-codec/src/enums/definitions.json index 3bf5a024aa..f6d5f43fac 100644 --- a/packages/ripple-binary-codec/src/enums/definitions.json +++ b/packages/ripple-binary-codec/src/enums/definitions.json @@ -2548,11 +2548,8 @@ "tecINSUFFICIENT_PAYMENT": 161, "tecUNFUNDED_AMM": 162, "tecAMM_BALANCE": 163, - "tecAMM_FAILED_DEPOSIT": 164, - "tecAMM_FAILED_WITHDRAW": 165, - "tecAMM_INVALID_TOKENS": 166, - "tecAMM_FAILED_BID": 167, - "tecAMM_FAILED_VOTE": 168 + "tecAMM_FAILED": 164, + "tecAMM_INVALID_TOKENS": 165 }, "TRANSACTION_TYPES": { "Invalid": -1, From e1fcc99feffe46005265009cd1663ac1539facc7 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Mon, 17 Jul 2023 16:24:21 -0400 Subject: [PATCH 75/93] update unit tests --- packages/xrpl/test/models/AMMBid.test.ts | 60 ++++++--------- packages/xrpl/test/models/AMMCreate.test.ts | 50 +++++++++---- packages/xrpl/test/models/AMMDeposit.test.ts | 73 +++++++++++++------ packages/xrpl/test/models/AMMVote.test.ts | 66 +++++++---------- packages/xrpl/test/models/AMMWithdraw.test.ts | 69 +++++++++++++----- 5 files changed, 184 insertions(+), 134 deletions(-) diff --git a/packages/xrpl/test/models/AMMBid.test.ts b/packages/xrpl/test/models/AMMBid.test.ts index 0ef28dce45..e06dac8f27 100644 --- a/packages/xrpl/test/models/AMMBid.test.ts +++ b/packages/xrpl/test/models/AMMBid.test.ts @@ -1,6 +1,7 @@ import { assert } from 'chai' import { validate, ValidationError } from '../../src' +import { validateAMMBid } from '../../src/models/transactions/AMMBid' /** * AMMBid Transaction Verification Testing. @@ -50,61 +51,50 @@ describe('AMMBid', function () { }) it(`verifies valid AMMBid`, function () { + assert.doesNotThrow(() => validateAMMBid(bid)) assert.doesNotThrow(() => validate(bid)) }) it(`throws w/ missing field Asset`, function () { delete bid.Asset - assert.throws( - () => validate(bid), - ValidationError, - 'AMMBid: missing field Asset', - ) + const errorMessage = 'AMMBid: missing field Asset' + assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) + assert.throws(() => validate(bid), ValidationError, errorMessage) }) it(`throws w/ Asset must be an Issue`, function () { bid.Asset = 1234 - assert.throws( - () => validate(bid), - ValidationError, - 'AMMBid: Asset must be an Issue', - ) + const errorMessage = 'AMMBid: Asset must be an Issue' + assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) + assert.throws(() => validate(bid), ValidationError, errorMessage) }) it(`throws w/ missing field Asset2`, function () { delete bid.Asset2 - assert.throws( - () => validate(bid), - ValidationError, - 'AMMBid: missing field Asset2', - ) + const errorMessage = 'AMMBid: missing field Asset2' + assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) + assert.throws(() => validate(bid), ValidationError, errorMessage) }) it(`throws w/ Asset2 must be an Issue`, function () { bid.Asset2 = 1234 - assert.throws( - () => validate(bid), - ValidationError, - 'AMMBid: Asset2 must be an Issue', - ) + const errorMessage = 'AMMBid: Asset2 must be an Issue' + assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) + assert.throws(() => validate(bid), ValidationError, errorMessage) }) it(`throws w/ BidMin must be an Amount`, function () { bid.BidMin = 5 - assert.throws( - () => validate(bid), - ValidationError, - 'AMMBid: BidMin must be an Amount', - ) + const errorMessage = 'AMMBid: BidMin must be an Amount' + assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) + assert.throws(() => validate(bid), ValidationError, errorMessage) }) it(`throws w/ BidMax must be an Amount`, function () { bid.BidMax = 10 - assert.throws( - () => validate(bid), - ValidationError, - 'AMMBid: BidMax must be an Amount', - ) + const errorMessage = 'AMMBid: BidMax must be an Amount' + assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) + assert.throws(() => validate(bid), ValidationError, errorMessage) }) it(`throws w/ AuthAccounts length must not be greater than 4`, function () { @@ -113,11 +103,9 @@ describe('AMMBid', function () { Account: 'r3X6noRsvaLapAKCG78zAtWcbhB3sggS1s', }, }) - - assert.throws( - () => validate(bid), - ValidationError, - 'AMMBid: AuthAccounts length must not be greater than 4', - ) + const errorMessage = + 'AMMBid: AuthAccounts length must not be greater than 4' + assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) + assert.throws(() => validate(bid), ValidationError, errorMessage) }) }) diff --git a/packages/xrpl/test/models/AMMCreate.test.ts b/packages/xrpl/test/models/AMMCreate.test.ts index 03b5028b3b..56242140ab 100644 --- a/packages/xrpl/test/models/AMMCreate.test.ts +++ b/packages/xrpl/test/models/AMMCreate.test.ts @@ -1,6 +1,7 @@ import { assert } from 'chai' import { validate, ValidationError } from '../../src' +import { validateAMMCreate } from '../../src/models/transactions/AMMCreate' /** * AMMCreate Transaction Verification Testing. @@ -26,78 +27,95 @@ describe('AMMCreate', function () { }) it(`verifies valid AMMCreate`, function () { + assert.doesNotThrow(() => validateAMMCreate(ammCreate)) assert.doesNotThrow(() => validate(ammCreate)) }) it(`throws w/ missing Amount`, function () { delete ammCreate.Amount + const errorMessage = 'AMMCreate: missing field Amount' assert.throws( - () => validate(ammCreate), + () => validateAMMCreate(ammCreate), ValidationError, - 'AMMCreate: missing field Amount', + errorMessage, ) + assert.throws(() => validate(ammCreate), ValidationError, errorMessage) }) it(`throws w/ Amount must be an Amount`, function () { ammCreate.Amount = 1000 + const errorMessage = 'AMMCreate: Amount must be an Amount' assert.throws( - () => validate(ammCreate), + () => validateAMMCreate(ammCreate), ValidationError, - 'AMMCreate: Amount must be an Amount', + errorMessage, ) + assert.throws(() => validate(ammCreate), ValidationError, errorMessage) }) it(`throws w/ missing Amount2`, function () { delete ammCreate.Amount2 + const errorMessage = 'AMMCreate: missing field Amount2' assert.throws( - () => validate(ammCreate), + () => validateAMMCreate(ammCreate), ValidationError, - 'AMMCreate: missing field Amount2', + errorMessage, ) + assert.throws(() => validate(ammCreate), ValidationError, errorMessage) }) it(`throws w/ Amount2 must be an Amount`, function () { ammCreate.Amount2 = 1000 + const errorMessage = 'AMMCreate: Amount2 must be an Amount' assert.throws( - () => validate(ammCreate), + () => validateAMMCreate(ammCreate), ValidationError, - 'AMMCreate: Amount2 must be an Amount', + errorMessage, ) + assert.throws(() => validate(ammCreate), ValidationError, errorMessage) }) it(`throws w/ missing TradingFee`, function () { delete ammCreate.TradingFee + const errorMessage = 'AMMCreate: missing field TradingFee' assert.throws( - () => validate(ammCreate), + () => validateAMMCreate(ammCreate), ValidationError, - 'AMMCreate: missing field TradingFee', + errorMessage, ) + assert.throws(() => validate(ammCreate), ValidationError, errorMessage) }) it(`throws w/ TradingFee must be a number`, function () { ammCreate.TradingFee = '12' + const errorMessage = 'AMMCreate: TradingFee must be a number' assert.throws( - () => validate(ammCreate), + () => validateAMMCreate(ammCreate), ValidationError, - 'AMMCreate: TradingFee must be a number', + errorMessage, ) + assert.throws(() => validate(ammCreate), ValidationError, errorMessage) }) it(`throws when TradingFee is greater than 1000`, function () { ammCreate.TradingFee = 1001 + const errorMessage = 'AMMCreate: TradingFee must be between 0 and 1000' assert.throws( - () => validate(ammCreate), + () => validateAMMCreate(ammCreate), ValidationError, - `AMMCreate: TradingFee must be between 0 and 1000`, + errorMessage, ) + assert.throws(() => validate(ammCreate), ValidationError, errorMessage) }) it(`throws when TradingFee is a negative number`, function () { ammCreate.TradingFee = -1 + const errorMessage = 'AMMCreate: TradingFee must be between 0 and 1000' assert.throws( - () => validate(ammCreate), + () => validateAMMCreate(ammCreate), ValidationError, - `AMMCreate: TradingFee must be between 0 and 1000`, + errorMessage, ) + assert.throws(() => validate(ammCreate), ValidationError, errorMessage) }) }) diff --git a/packages/xrpl/test/models/AMMDeposit.test.ts b/packages/xrpl/test/models/AMMDeposit.test.ts index 9eeb6ec37e..b30871f7d5 100644 --- a/packages/xrpl/test/models/AMMDeposit.test.ts +++ b/packages/xrpl/test/models/AMMDeposit.test.ts @@ -2,6 +2,7 @@ import { assert } from 'chai' import { AMMDepositFlags, validate, ValidationError } from '../../src' +import { validateAMMDeposit } from '../../src/models/transactions/AMMDeposit' /** * AMMDeposit Transaction Verification Testing. @@ -35,12 +36,14 @@ describe('AMMDeposit', function () { it(`verifies valid AMMDeposit with LPTokenOut`, function () { deposit.LPTokenOut = LPTokenOut deposit.Flags |= AMMDepositFlags.tfLPToken + assert.doesNotThrow(() => validateAMMDeposit(deposit)) assert.doesNotThrow(() => validate(deposit)) }) it(`verifies valid AMMDeposit with Amount`, function () { deposit.Amount = '1000' deposit.Flags |= AMMDepositFlags.tfSingleAsset + assert.doesNotThrow(() => validateAMMDeposit(deposit)) assert.doesNotThrow(() => validate(deposit)) }) @@ -52,6 +55,7 @@ describe('AMMDeposit', function () { value: '2.5', } deposit.Flags |= AMMDepositFlags.tfTwoAsset + assert.doesNotThrow(() => validateAMMDeposit(deposit)) assert.doesNotThrow(() => validate(deposit)) }) @@ -59,6 +63,7 @@ describe('AMMDeposit', function () { deposit.Amount = '1000' deposit.LPTokenOut = LPTokenOut deposit.Flags |= AMMDepositFlags.tfOneAssetLPToken + assert.doesNotThrow(() => validateAMMDeposit(deposit)) assert.doesNotThrow(() => validate(deposit)) }) @@ -66,51 +71,62 @@ describe('AMMDeposit', function () { deposit.Amount = '1000' deposit.EPrice = '25' deposit.Flags |= AMMDepositFlags.tfLimitLPToken + assert.doesNotThrow(() => validateAMMDeposit(deposit)) assert.doesNotThrow(() => validate(deposit)) }) it(`throws w/ missing field Asset`, function () { delete deposit.Asset + const errorMessage = 'AMMDeposit: missing field Asset' assert.throws( - () => validate(deposit), + () => validateAMMDeposit(deposit), ValidationError, - 'AMMDeposit: missing field Asset', + errorMessage, ) + assert.throws(() => validate(deposit), ValidationError, errorMessage) }) it(`throws w/ Asset must be an Issue`, function () { deposit.Asset = 1234 + const errorMessage = 'AMMDeposit: Asset must be an Issue' assert.throws( - () => validate(deposit), + () => validateAMMDeposit(deposit), ValidationError, - 'AMMDeposit: Asset must be an Issue', + errorMessage, ) + assert.throws(() => validate(deposit), ValidationError, errorMessage) }) it(`throws w/ missing field Asset2`, function () { delete deposit.Asset2 + const errorMessage = 'AMMDeposit: missing field Asset2' assert.throws( - () => validate(deposit), + () => validateAMMDeposit(deposit), ValidationError, - 'AMMDeposit: missing field Asset2', + errorMessage, ) + assert.throws(() => validate(deposit), ValidationError, errorMessage) }) it(`throws w/ Asset2 must be an Issue`, function () { deposit.Asset2 = 1234 + const errorMessage = 'AMMDeposit: Asset2 must be an Issue' assert.throws( - () => validate(deposit), + () => validateAMMDeposit(deposit), ValidationError, - 'AMMDeposit: Asset2 must be an Issue', + errorMessage, ) + assert.throws(() => validate(deposit), ValidationError, errorMessage) }) it(`throws w/ must set at least LPTokenOut or Amount`, function () { + const errorMessage = 'AMMDeposit: must set at least LPTokenOut or Amount' assert.throws( - () => validate(deposit), + () => validateAMMDeposit(deposit), ValidationError, - 'AMMDeposit: must set at least LPTokenOut or Amount', + errorMessage, ) + assert.throws(() => validate(deposit), ValidationError, errorMessage) }) it(`throws w/ must set Amount with Amount2`, function () { @@ -119,57 +135,70 @@ describe('AMMDeposit', function () { issuer: 'rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd', value: '2.5', } + const errorMessage = 'AMMDeposit: must set Amount with Amount2' assert.throws( - () => validate(deposit), + () => validateAMMDeposit(deposit), ValidationError, - 'AMMDeposit: must set Amount with Amount2', + errorMessage, ) + assert.throws(() => validate(deposit), ValidationError, errorMessage) }) it(`throws w/ must set Amount with EPrice`, function () { deposit.EPrice = '25' + const errorMessage = 'AMMDeposit: must set Amount with EPrice' assert.throws( - () => validate(deposit), + () => validateAMMDeposit(deposit), ValidationError, - 'AMMDeposit: must set Amount with EPrice', + errorMessage, ) + assert.throws(() => validate(deposit), ValidationError, errorMessage) }) it(`throws w/ LPTokenOut must be an IssuedCurrencyAmount`, function () { deposit.LPTokenOut = 1234 + const errorMessage = + 'AMMDeposit: LPTokenOut must be an IssuedCurrencyAmount' assert.throws( - () => validate(deposit), + () => validateAMMDeposit(deposit), ValidationError, - 'AMMDeposit: LPTokenOut must be an IssuedCurrencyAmount', + errorMessage, ) + assert.throws(() => validate(deposit), ValidationError, errorMessage) }) it(`throws w/ Amount must be an Amount`, function () { deposit.Amount = 1234 + const errorMessage = 'AMMDeposit: Amount must be an Amount' assert.throws( - () => validate(deposit), + () => validateAMMDeposit(deposit), ValidationError, - 'AMMDeposit: Amount must be an Amount', + errorMessage, ) + assert.throws(() => validate(deposit), ValidationError, errorMessage) }) it(`throws w/ Amount2 must be an Amount`, function () { deposit.Amount = '1000' deposit.Amount2 = 1234 + const errorMessage = 'AMMDeposit: Amount2 must be an Amount' assert.throws( - () => validate(deposit), + () => validateAMMDeposit(deposit), ValidationError, - 'AMMDeposit: Amount2 must be an Amount', + errorMessage, ) + assert.throws(() => validate(deposit), ValidationError, errorMessage) }) it(`throws w/ EPrice must be an Amount`, function () { deposit.Amount = '1000' deposit.EPrice = 1234 + const errorMessage = 'AMMDeposit: EPrice must be an Amount' assert.throws( - () => validate(deposit), + () => validateAMMDeposit(deposit), ValidationError, - 'AMMDeposit: EPrice must be an Amount', + errorMessage, ) + assert.throws(() => validate(deposit), ValidationError, errorMessage) }) }) diff --git a/packages/xrpl/test/models/AMMVote.test.ts b/packages/xrpl/test/models/AMMVote.test.ts index 765690cc6e..dfc11f88eb 100644 --- a/packages/xrpl/test/models/AMMVote.test.ts +++ b/packages/xrpl/test/models/AMMVote.test.ts @@ -1,6 +1,7 @@ import { assert } from 'chai' import { validate, ValidationError } from '../../src' +import { validateAMMVote } from '../../src/models/transactions/AMMVote' /** * AMMVote Transaction Verification Testing. @@ -27,78 +28,63 @@ describe('AMMVote', function () { }) it(`verifies valid AMMVote`, function () { + assert.doesNotThrow(() => validateAMMVote(vote)) assert.doesNotThrow(() => validate(vote)) }) it(`throws w/ missing field Asset`, function () { delete vote.Asset - assert.throws( - () => validate(vote), - ValidationError, - 'AMMVote: missing field Asset', - ) + const errorMessage = 'AMMVote: missing field Asset' + assert.throws(() => validateAMMVote(vote), ValidationError, errorMessage) + assert.throws(() => validate(vote), ValidationError, errorMessage) }) it(`throws w/ Asset must be an Issue`, function () { vote.Asset = 1234 - assert.throws( - () => validate(vote), - ValidationError, - 'AMMVote: Asset must be an Issue', - ) + const errorMessage = 'AMMVote: Asset must be an Issue' + assert.throws(() => validateAMMVote(vote), ValidationError, errorMessage) + assert.throws(() => validate(vote), ValidationError, errorMessage) }) it(`throws w/ missing field Asset2`, function () { delete vote.Asset2 - assert.throws( - () => validate(vote), - ValidationError, - 'AMMVote: missing field Asset2', - ) + const errorMessage = 'AMMVote: missing field Asset2' + assert.throws(() => validateAMMVote(vote), ValidationError, errorMessage) + assert.throws(() => validate(vote), ValidationError, errorMessage) }) it(`throws w/ Asset2 must be an Issue`, function () { vote.Asset2 = 1234 - assert.throws( - () => validate(vote), - ValidationError, - 'AMMVote: Asset2 must be an Issue', - ) + const errorMessage = 'AMMVote: Asset2 must be an Issue' + assert.throws(() => validateAMMVote(vote), ValidationError, errorMessage) + assert.throws(() => validate(vote), ValidationError, errorMessage) }) it(`throws w/ missing field TradingFee`, function () { delete vote.TradingFee - assert.throws( - () => validate(vote), - ValidationError, - 'AMMVote: missing field TradingFee', - ) + const errorMessage = 'AMMVote: missing field TradingFee' + assert.throws(() => validateAMMVote(vote), ValidationError, errorMessage) + assert.throws(() => validate(vote), ValidationError, errorMessage) }) it(`throws w/ TradingFee must be a number`, function () { vote.TradingFee = '25' - assert.throws( - () => validate(vote), - ValidationError, - 'AMMVote: TradingFee must be a number', - ) + const errorMessage = 'AMMVote: TradingFee must be a number' + assert.throws(() => validateAMMVote(vote), ValidationError, errorMessage) + assert.throws(() => validate(vote), ValidationError, errorMessage) }) it(`throws when TradingFee is greater than AMM_MAX_TRADING_FEE`, function () { vote.TradingFee = 1001 - assert.throws( - () => validate(vote), - ValidationError, - 'AMMVote: TradingFee must be between 0 and 1000', - ) + const errorMessage = 'AMMVote: TradingFee must be between 0 and 1000' + assert.throws(() => validateAMMVote(vote), ValidationError, errorMessage) + assert.throws(() => validate(vote), ValidationError, errorMessage) }) it(`throws when TradingFee is a negative number`, function () { vote.TradingFee = -1 - assert.throws( - () => validate(vote), - ValidationError, - 'AMMVote: TradingFee must be between 0 and 1000', - ) + const errorMessage = 'AMMVote: TradingFee must be between 0 and 1000' + assert.throws(() => validateAMMVote(vote), ValidationError, errorMessage) + assert.throws(() => validate(vote), ValidationError, errorMessage) }) }) diff --git a/packages/xrpl/test/models/AMMWithdraw.test.ts b/packages/xrpl/test/models/AMMWithdraw.test.ts index 27a5c5c077..3f21c71470 100644 --- a/packages/xrpl/test/models/AMMWithdraw.test.ts +++ b/packages/xrpl/test/models/AMMWithdraw.test.ts @@ -2,6 +2,7 @@ import { assert } from 'chai' import { AMMWithdrawFlags, validate, ValidationError } from '../../src' +import { validateAMMWithdraw } from '../../src/models/transactions/AMMWithdraw' /** * AMMWithdraw Transaction Verification Testing. @@ -35,12 +36,14 @@ describe('AMMWithdraw', function () { it(`verifies valid AMMWithdraw with LPTokenIn`, function () { withdraw.LPTokenIn = LPTokenIn withdraw.Flags |= AMMWithdrawFlags.tfLPToken + assert.doesNotThrow(() => validateAMMWithdraw(withdraw)) assert.doesNotThrow(() => validate(withdraw)) }) it(`verifies valid AMMWithdraw with Amount`, function () { withdraw.Amount = '1000' withdraw.Flags |= AMMWithdrawFlags.tfSingleAsset + assert.doesNotThrow(() => validateAMMWithdraw(withdraw)) assert.doesNotThrow(() => validate(withdraw)) }) @@ -52,6 +55,7 @@ describe('AMMWithdraw', function () { value: '2.5', } withdraw.Flags |= AMMWithdrawFlags.tfTwoAsset + assert.doesNotThrow(() => validateAMMWithdraw(withdraw)) assert.doesNotThrow(() => validate(withdraw)) }) @@ -59,6 +63,7 @@ describe('AMMWithdraw', function () { withdraw.Amount = '1000' withdraw.LPTokenIn = LPTokenIn withdraw.Flags |= AMMWithdrawFlags.tfOneAssetLPToken + assert.doesNotThrow(() => validateAMMWithdraw(withdraw)) assert.doesNotThrow(() => validate(withdraw)) }) @@ -66,54 +71,65 @@ describe('AMMWithdraw', function () { withdraw.Amount = '1000' withdraw.EPrice = '25' withdraw.Flags |= AMMWithdrawFlags.tfLimitLPToken + assert.doesNotThrow(() => validateAMMWithdraw(withdraw)) assert.doesNotThrow(() => validate(withdraw)) }) it(`verifies valid AMMWithdraw one asset withdraw all`, function () { withdraw.Amount = '1000' withdraw.Flags |= AMMWithdrawFlags.tfOneAssetWithdrawAll + assert.doesNotThrow(() => validateAMMWithdraw(withdraw)) assert.doesNotThrow(() => validate(withdraw)) }) it(`verifies valid AMMWithdraw withdraw all`, function () { withdraw.Flags |= AMMWithdrawFlags.tfWithdrawAll + assert.doesNotThrow(() => validateAMMWithdraw(withdraw)) assert.doesNotThrow(() => validate(withdraw)) }) it(`throws w/ missing field Asset`, function () { delete withdraw.Asset + const errorMessage = 'AMMWithdraw: missing field Asset' assert.throws( - () => validate(withdraw), + () => validateAMMWithdraw(withdraw), ValidationError, - 'AMMWithdraw: missing field Asset', + errorMessage, ) + assert.throws(() => validate(withdraw), ValidationError, errorMessage) }) it(`throws w/ Asset must be an Issue`, function () { withdraw.Asset = 1234 + const errorMessage = 'AMMWithdraw: Asset must be an Issue' assert.throws( - () => validate(withdraw), + () => validateAMMWithdraw(withdraw), ValidationError, - 'AMMWithdraw: Asset must be an Issue', + errorMessage, ) + assert.throws(() => validate(withdraw), ValidationError, errorMessage) }) it(`throws w/ missing field Asset2`, function () { delete withdraw.Asset2 + const errorMessage = 'AMMWithdraw: missing field Asset2' assert.throws( - () => validate(withdraw), + () => validateAMMWithdraw(withdraw), ValidationError, - 'AMMWithdraw: missing field Asset2', + errorMessage, ) + assert.throws(() => validate(withdraw), ValidationError, errorMessage) }) it(`throws w/ Asset2 must be an Issue`, function () { withdraw.Asset2 = 1234 + const errorMessage = 'AMMWithdraw: Asset2 must be an Issue' assert.throws( - () => validate(withdraw), + () => validateAMMWithdraw(withdraw), ValidationError, - 'AMMWithdraw: Asset2 must be an Issue', + errorMessage, ) + assert.throws(() => validate(withdraw), ValidationError, errorMessage) }) it(`throws w/ must set Amount with Amount2`, function () { @@ -122,57 +138,70 @@ describe('AMMWithdraw', function () { issuer: 'rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd', value: '2.5', } + const errorMessage = 'AMMWithdraw: must set Amount with Amount2' assert.throws( - () => validate(withdraw), + () => validateAMMWithdraw(withdraw), ValidationError, - 'AMMWithdraw: must set Amount with Amount2', + errorMessage, ) + assert.throws(() => validate(withdraw), ValidationError, errorMessage) }) it(`throws w/ must set Amount with EPrice`, function () { withdraw.EPrice = '25' + const errorMessage = 'AMMWithdraw: must set Amount with EPrice' assert.throws( - () => validate(withdraw), + () => validateAMMWithdraw(withdraw), ValidationError, - 'AMMWithdraw: must set Amount with EPrice', + errorMessage, ) + assert.throws(() => validate(withdraw), ValidationError, errorMessage) }) it(`throws w/ LPTokenIn must be an IssuedCurrencyAmount`, function () { withdraw.LPTokenIn = 1234 + const errorMessage = + 'AMMWithdraw: LPTokenIn must be an IssuedCurrencyAmount' assert.throws( - () => validate(withdraw), + () => validateAMMWithdraw(withdraw), ValidationError, - 'AMMWithdraw: LPTokenIn must be an IssuedCurrencyAmount', + errorMessage, ) + assert.throws(() => validate(withdraw), ValidationError, errorMessage) }) it(`throws w/ Amount must be an Amount`, function () { withdraw.Amount = 1234 + const errorMessage = 'AMMWithdraw: Amount must be an Amount' assert.throws( - () => validate(withdraw), + () => validateAMMWithdraw(withdraw), ValidationError, - 'AMMWithdraw: Amount must be an Amount', + errorMessage, ) + assert.throws(() => validate(withdraw), ValidationError, errorMessage) }) it(`throws w/ Amount2 must be an Amount`, function () { withdraw.Amount = '1000' withdraw.Amount2 = 1234 + const errorMessage = 'AMMWithdraw: Amount2 must be an Amount' assert.throws( - () => validate(withdraw), + () => validateAMMWithdraw(withdraw), ValidationError, - 'AMMWithdraw: Amount2 must be an Amount', + errorMessage, ) + assert.throws(() => validate(withdraw), ValidationError, errorMessage) }) it(`throws w/ EPrice must be an Amount`, function () { withdraw.Amount = '1000' withdraw.EPrice = 1234 + const errorMessage = 'AMMWithdraw: EPrice must be an Amount' assert.throws( - () => validate(withdraw), + () => validateAMMWithdraw(withdraw), ValidationError, - 'AMMWithdraw: EPrice must be an Amount', + errorMessage, ) + assert.throws(() => validate(withdraw), ValidationError, errorMessage) }) }) From 41e0ee9d4790c871cf12b6120a5696790e42bf28 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Mon, 17 Jul 2023 16:25:25 -0400 Subject: [PATCH 76/93] update amm_info response --- packages/xrpl/src/models/methods/ammInfo.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index 8d9568349d..a8b5893c3e 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -45,7 +45,7 @@ export interface AMMInfoResponse extends BaseResponse { /** * The account that tracks the balance of LPTokens between the AMM instance via Trustline. */ - amm_account: string + account: string /** * One of the pool assets (XRP or token) of the AMM instance. From 41ca08ff5e58cfd867bca0db59a2f87264f3942d Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Mon, 17 Jul 2023 16:29:44 -0400 Subject: [PATCH 77/93] sort imports/exports --- packages/xrpl/src/client/index.ts | 6 +++--- packages/xrpl/src/models/methods/index.ts | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/xrpl/src/client/index.ts b/packages/xrpl/src/client/index.ts index 279f35bc6b..50b978d72a 100644 --- a/packages/xrpl/src/client/index.ts +++ b/packages/xrpl/src/client/index.ts @@ -25,9 +25,6 @@ import { AccountOffersResponse, AccountTxRequest, AccountTxResponse, - // AMM methods - AMMInfoRequest, - AMMInfoResponse, GatewayBalancesRequest, GatewayBalancesResponse, NoRippleCheckRequest, @@ -98,6 +95,9 @@ import { NFTInfoResponse, NFTHistoryRequest, NFTHistoryResponse, + // AMM methods + AMMInfoRequest, + AMMInfoResponse, } from '../models/methods' import { BaseRequest, BaseResponse } from '../models/methods/baseMethod' import { diff --git a/packages/xrpl/src/models/methods/index.ts b/packages/xrpl/src/models/methods/index.ts index 7e1e1cf073..530e7e75cf 100644 --- a/packages/xrpl/src/models/methods/index.ts +++ b/packages/xrpl/src/models/methods/index.ts @@ -160,7 +160,6 @@ type Request = | AccountObjectsRequest | AccountOffersRequest | AccountTxRequest - | AMMInfoRequest | GatewayBalancesRequest | NoRippleCheckRequest // ledger methods @@ -198,6 +197,8 @@ type Request = // clio only methods | NFTInfoRequest | NFTHistoryRequest + // AMM methods + | AMMInfoRequest /** * @category Responses @@ -212,7 +213,6 @@ type Response = | AccountObjectsResponse | AccountOffersResponse | AccountTxResponse - | AMMInfoResponse | GatewayBalancesResponse | NoRippleCheckResponse // ledger methods @@ -250,6 +250,8 @@ type Response = // clio only methods | NFTInfoResponse | NFTHistoryResponse + // AMM methods + | AMMInfoResponse export { // Allow users to define their own requests and responses. This is useful for releasing experimental versions @@ -285,8 +287,6 @@ export { AccountTxRequest, AccountTxResponse, AccountTxTransaction, - AMMInfoRequest, - AMMInfoResponse, GatewayBalance, GatewayBalancesRequest, GatewayBalancesResponse, @@ -385,4 +385,7 @@ export { NFTHistoryRequest, NFTHistoryResponse, NFTHistoryTransaction, + // AMM methods + AMMInfoRequest, + AMMInfoResponse, } From 8cb4a1ed91f4b7473488bc1411864ced05456e96 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Mon, 17 Jul 2023 16:52:46 -0400 Subject: [PATCH 78/93] update jsdoc --- .../xrpl/src/models/transactions/AMMBid.ts | 29 ++++++++------- .../xrpl/src/models/transactions/AMMCreate.ts | 26 +++++++------ .../src/models/transactions/AMMDeposit.ts | 37 ++++++++----------- .../xrpl/src/models/transactions/AMMVote.ts | 16 ++++---- .../src/models/transactions/AMMWithdraw.ts | 37 +++++++------------ 5 files changed, 66 insertions(+), 79 deletions(-) diff --git a/packages/xrpl/src/models/transactions/AMMBid.ts b/packages/xrpl/src/models/transactions/AMMBid.ts index eabbf7eba2..50657729d1 100644 --- a/packages/xrpl/src/models/transactions/AMMBid.ts +++ b/packages/xrpl/src/models/transactions/AMMBid.ts @@ -18,42 +18,43 @@ interface AuthAccount { } /** - * AMMBid is used for submitting a vote for the trading fee of an AMM Instance. + * Bid on an Automated Market Maker's (AMM's) auction slot. * - * Any XRPL account that holds LPToken for an AMM instance may submit this - * transaction to vote for the trading fee for that instance. + * If you win, you can trade against the AMM at a discounted fee until you are outbid or 24 hours have passed. + * If you are outbid before 24 hours have passed, you are refunded part of the cost of your bid based on how much time remains. + * You bid using the AMM's LP Tokens; the amount of a winning bid is returned to the AMM, + * decreasing the outstanding balance of LP Tokens. */ export interface AMMBid extends BaseTransaction { TransactionType: 'AMMBid' /** - * Specifies one of the pool assets (XRP or token) of the AMM instance. + * The definition for one of the assets in the AMM's pool. */ Asset: Currency /** - * Specifies the other pool asset of the AMM instance. + * The definition for the other asset in the AMM's pool. */ Asset2: Currency /** - * This field represents the minimum price that the bidder wants to pay for the slot. - * It is specified in units of LPToken. If specified let BidMin be X and let - * the slot-price computed by price scheduling algorithm be Y, then bidder always pays - * the max(X, Y). + * Pay at least this amount for the slot. + * Setting this value higher makes it harder for others to outbid you. + * If omitted, pay the minimum necessary to win the bid. */ BidMin?: Amount /** - * This field represents the maximum price that the bidder wants to pay for the slot. - * It is specified in units of LPToken. + * Pay at most this amount for the slot. + * If the cost to win the bid is higher than this amount, the transaction fails. + * If omitted, pay as much as necessary to win the bid. */ BidMax?: Amount /** - * This field represents an array of XRPL account IDs that are authorized to trade - * at the discounted fee against the AMM instance. - * A maximum of four accounts can be provided. + * A list of up to 4 additional accounts that you allow to trade at the discounted fee. + * This cannot include the address of the transaction sender. */ AuthAccounts?: AuthAccount[] } diff --git a/packages/xrpl/src/models/transactions/AMMCreate.ts b/packages/xrpl/src/models/transactions/AMMCreate.ts index 9ce8b68dc2..139b2e70c7 100644 --- a/packages/xrpl/src/models/transactions/AMMCreate.ts +++ b/packages/xrpl/src/models/transactions/AMMCreate.ts @@ -6,31 +6,35 @@ import { BaseTransaction, isAmount, validateBaseTransaction } from './common' export const AMM_MAX_TRADING_FEE = 1000 /** - * AMMCreate is used to create AccountRoot and the corresponding - * AMM ledger entries. + * Create a new Automated Market Maker (AMM) instance for trading a pair of assets (fungible tokens or XRP). * - * This allows for the creation of only one AMM instance per unique asset pair. + * Creates both an AMM object and a special AccountRoot object to represent the AMM. + * Also transfers ownership of the starting balance of both assets from the sender to the created AccountRoot + * and issues an initial balance of liquidity provider tokens (LP Tokens) from the AMM account to the sender. + * + * Caution: When you create the AMM, you should fund it with (approximately) equal-value amounts of each asset. + * Otherwise, other users can profit at your expense by trading with this AMM (performing arbitrage). + * The currency risk that liquidity providers take on increases with the volatility (potential for imbalance) of the asset pair. + * The higher the trading fee, the more it offsets this risk, + * so it's best to set the trading fee based on the volatility of the asset pair. */ export interface AMMCreate extends BaseTransaction { TransactionType: 'AMMCreate' /** - * Specifies one of the pool assets (XRP or token) of the AMM instance. + * The first of the two assets to fund this AMM with. This must be a positive amount. */ Amount: Amount /** - * Specifies the other pool asset of the AMM instance. + * The second of the two assets to fund this AMM with. This must be a positive amount. */ Amount2: Amount /** - * Specifies the fee, in basis point, to be charged - * to the traders for the trades executed against the AMM instance. - * Trading fee is a percentage of the trading volume. - * Valid values for this field are between 0 and 1000 inclusive. - * A value of 1 is equivalent to 1/10 bps or 0.001%, allowing trading fee - * between 0% and 1%. + * The fee to charge for trades against this AMM instance, in units of 1/100,000; a value of 1 is equivalent to 0.001%. + * The maximum value is 1000, indicating a 1% fee. + * The minimum value is 0. */ TradingFee: number } diff --git a/packages/xrpl/src/models/transactions/AMMDeposit.ts b/packages/xrpl/src/models/transactions/AMMDeposit.ts index 856ef2e799..53bef9a553 100644 --- a/packages/xrpl/src/models/transactions/AMMDeposit.ts +++ b/packages/xrpl/src/models/transactions/AMMDeposit.ts @@ -33,51 +33,46 @@ export interface AMMDepositFlagsInterface extends GlobalFlags { } /** - * AMMDeposit is the deposit transaction used to add liquidity to the AMM instance pool, - * thus obtaining some share of the instance's pools in the form of LPTokenOut. + * Deposit funds into an Automated Market Maker (AMM) instance + * and receive the AMM's liquidity provider tokens (LP Tokens) in exchange. * - * The following are the recommended valid combinations: - * - LPTokenOut - * - Amount - * - Amount and Amount2 - * - Amount and LPTokenOut - * - Amount and EPrice + * You can deposit one or both of the assets in the AMM's pool. + * If successful, this transaction creates a trust line to the AMM Account (limit 0) to hold the LP Tokens. */ export interface AMMDeposit extends BaseTransaction { TransactionType: 'AMMDeposit' /** - * Specifies one of the pool assets (XRP or token) of the AMM instance. + * The definition for one of the assets in the AMM's pool. */ Asset: Currency /** - * Specifies the other pool asset of the AMM instance. + * The definition for the other asset in the AMM's pool. */ Asset2: Currency /** - * Specifies the amount of shares of the AMM instance pools that the trader - * wants to redeem or trade in. - */ - LPTokenOut?: IssuedCurrencyAmount - - /** - * Specifies one of the pool assets (XRP or token) of the AMM instance to - * deposit more of its value. + * The amount of one asset to deposit to the AMM. + * If present, this must match the type of one of the assets (tokens or XRP) in the AMM's pool. */ Amount?: Amount /** - * Specifies the other pool asset of the AMM instance to deposit more of - * its value. + * The amount of another asset to add to the AMM. + * If present, this must match the type of the other asset in the AMM's pool and cannot be the same asset as Amount. */ Amount2?: Amount /** - * Specifies the maximum effective-price that LPTokenOut can be traded out. + * The maximum effective price, in the deposit asset, to pay for each LP Token received. */ EPrice?: Amount + + /** + * How many of the AMM's LP Tokens to buy. + */ + LPTokenOut?: IssuedCurrencyAmount } /** diff --git a/packages/xrpl/src/models/transactions/AMMVote.ts b/packages/xrpl/src/models/transactions/AMMVote.ts index 98734823bc..8daaf45e98 100644 --- a/packages/xrpl/src/models/transactions/AMMVote.ts +++ b/packages/xrpl/src/models/transactions/AMMVote.ts @@ -5,29 +5,27 @@ import { AMM_MAX_TRADING_FEE } from './AMMCreate' import { BaseTransaction, isCurrency, validateBaseTransaction } from './common' /** - * AMMVote is used for submitting a vote for the trading fee of an AMM Instance. + * Vote on the trading fee for an Automated Market Maker (AMM) instance. * - * Any XRPL account that holds LPToken for an AMM instance may submit this - * transaction to vote for the trading fee for that instance. + * Up to 8 accounts can vote in proportion to the amount of the AMM's LP Tokens they hold. + * Each new vote re-calculates the AMM's trading fee based on a weighted average of the votes. */ export interface AMMVote extends BaseTransaction { TransactionType: 'AMMVote' /** - * Specifies one of the pool assets (XRP or token) of the AMM instance. + * The definition for one of the assets in the AMM's pool. */ Asset: Currency /** - * Specifies the other pool asset of the AMM instance. + * The definition for the other asset in the AMM's pool. */ Asset2: Currency /** - * Specifies the fee, in basis point. - * Valid values for this field are between 0 and 1000 inclusive. - * A value of 1 is equivalent to 1/10 bps or 0.001%, allowing trading fee - * between 0% and 1%. This field is required. + * The proposed fee to vote for, in units of 1/100,000; a value of 1 is equivalent to 0.001%. + * The maximum value is 1000, indicating a 1% fee. */ TradingFee: number } diff --git a/packages/xrpl/src/models/transactions/AMMWithdraw.ts b/packages/xrpl/src/models/transactions/AMMWithdraw.ts index 36bcbf423a..4ebe6efb62 100644 --- a/packages/xrpl/src/models/transactions/AMMWithdraw.ts +++ b/packages/xrpl/src/models/transactions/AMMWithdraw.ts @@ -37,53 +37,42 @@ export interface AMMWithdrawFlagsInterface extends GlobalFlags { } /** - * AMMWithdraw is the withdraw transaction used to remove liquidity from the AMM - * instance pool, thus redeeming some share of the pools that one owns in the form - * of LPTokenIn. - * - * The following are the recommended valid combinations: - * - LPTokenIn - * - Amount - * - Amount and Amount2 - * - Amount and LPTokenIn - * - Amount and EPrice + * Withdraw assets from an Automated Market Maker (AMM) instance by returning the AMM's liquidity provider tokens (LP Tokens). */ export interface AMMWithdraw extends BaseTransaction { TransactionType: 'AMMWithdraw' /** - * Specifies one of the pool assets (XRP or token) of the AMM instance. + * The definition for one of the assets in the AMM's pool. */ Asset: Currency /** - * Specifies the other pool asset of the AMM instance. + * The definition for the other asset in the AMM's pool. */ Asset2: Currency /** - * Specifies the amount of shares of the AMM instance pools that the trader - * wants to redeem or trade in. - */ - LPTokenIn?: IssuedCurrencyAmount - - /** - * Specifies one of the pools assets that the trader wants to remove. - * If the asset is XRP, then the Amount is a string specifying the number of drops. - * Otherwise it is an IssuedCurrencyAmount object. + * The amount of one asset to withdraw from the AMM. + * This must match the type of one of the assets (tokens or XRP) in the AMM's pool. */ Amount?: Amount /** - * Specifies the other pool asset that the trader wants to remove. + * The amount of another asset to withdraw from the AMM. + * If present, this must match the type of the other asset in the AMM's pool and cannot be the same type as Amount. */ Amount2?: Amount /** - * Specifies the effective-price of the token out after successful execution of - * the transaction. + * The minimum effective price, in LP Token returned, to pay per unit of the asset to withdraw. */ EPrice?: Amount + + /** + * How many of the AMM's LP Tokens to redeem. + */ + LPTokenIn?: IssuedCurrencyAmount } /** From 1a9e842af483c336609d0fcfb24220c2928ec05d Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Mon, 17 Jul 2023 17:13:09 -0400 Subject: [PATCH 79/93] update amm_info jsdoc --- packages/xrpl/src/models/methods/ammInfo.ts | 50 +++++++++++---------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index a8b5893c3e..cfb5bcc2c2 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -12,14 +12,12 @@ export interface AMMInfoRequest extends BaseRequest { command: 'amm_info' /** - * Specifies one of the pool assets (XRP or token) of the AMM instance. - * Both asset and asset2 must be defined to specify an AMM instance. + * One of the assets of the AMM pool to look up. */ asset: Currency /** - * Specifies the other pool asset of the AMM instance. - * Both asset and asset2 must be defined to specify an AMM instance. + * The other asset of the AMM pool. */ asset2: Currency } @@ -43,17 +41,19 @@ export interface AMMInfoResponse extends BaseResponse { result: { amm: { /** - * The account that tracks the balance of LPTokens between the AMM instance via Trustline. + * The address of the AMM Account. */ account: string /** - * One of the pool assets (XRP or token) of the AMM instance. + * The total amount of one asset in the AMM's pool. + * Note: This could be asset or asset2 from the request. */ amount: Amount /** - * The other pool asset of the AMM instance. + * The total amount of the other asset in the AMM's pool. + * Note: This could be asset or asset2 from the request. */ amount2: Amount @@ -68,59 +68,61 @@ export interface AMMInfoResponse extends BaseResponse { asset2_frozen: boolean /** - * Details of the current owner of the auction slot. + * (May be omitted) An Auction Slot Object describing the current auction slot holder, if there is one. */ auction_slot?: { /** - * The current owner of this auction slot. + * The address of the account that owns the auction slot. */ account: string /** - * A list of at most 4 additional accounts that are authorized to trade at the discounted fee for this AMM instance. + * A list of additional accounts that the auction slot holder has designated as being eligible + * of the discounted trading fee. + * Each member of this array is an object with one field, account, containing the address of the designated account. */ auth_accounts: AuthAccount[] /** - * The trading fee to be charged to the auction owner, in the same format as TradingFee. - * By default this is 0, meaning that the auction owner can trade at no fee instead of the standard fee for this AMM. + * The discounted trading fee that applies to the auction slot holder, and any eligible accounts + * when trading against this AMM. + * This is always 0. */ discounted_fee: number /** - * The time when this slot expires, in seconds since the Ripple Epoch. + * The ISO 8601 UTC timestamp after which this auction slot expires. + * After expired, the auction slot does not apply (but the data can remain in the ledger + * until another transaction replaces it or cleans it up). */ expiration: string /** - * The amount the auction owner paid to win this slot, in LPTokens. + * The amount, in LP Tokens, that the auction slot holder paid to win the auction slot. + * This affects the price to outbid the current slot holder. */ price: Amount /** - * Total slot time of 24-hours is divided into 20 equal time intervals. + * The current 72-minute time interval this auction slot is in, from 0 to 19. + * The auction slot expires after 24 hours (20 intervals of 72 minutes) + * and affects the cost to outbid the current holder and how much the current holder is refunded if someone outbids them. */ time_interval: number } /** - * The total outstanding balance of liquidity provider tokens from this AMM instance. - * The holders of these tokens can vote on the AMM's trading fee in proportion to their holdings, - * or redeem the tokens for a share of the AMM's assets which grows with the trading fees collected. + * The total amount of this AMM's LP Tokens outstanding. */ lp_token: IssuedCurrencyAmount /** - * Specifies the fee, in basis point, to be charged to the traders for the trades - * executed against the AMM instance. Trading fee is a percentage of the trading volume. - * Valid values for this field are between 0 and 1000 inclusive. - * A value of 1 is equivalent to 1/10 bps or 0.001%, allowing trading fee - * between 0% and 1%. This field is required. + * The AMM's current trading fee, in units of 1/100,000; a value of 1 is equivalent to a 0.001% fee. */ trading_fee: number /** - * Keeps a track of up to eight active votes for the instance. + * (May be omitted) The current votes for the AMM's trading fee, as Vote Slot Objects. */ vote_slots?: VoteSlot[] } From a28198c7e4b7e65d3dbba1cdce48c14886a3a9c4 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Mon, 17 Jul 2023 19:35:27 -0400 Subject: [PATCH 80/93] update jsdoc --- packages/xrpl/src/models/methods/ammInfo.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index cfb5bcc2c2..c451c3f4ba 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -3,7 +3,7 @@ import { Amount, Currency, IssuedCurrencyAmount } from '../common' import { BaseRequest, BaseResponse } from './baseMethod' /** - * The `amm_info` command retrieves information about an AMM instance. + * The `amm_info` method gets information about an Automated Market Maker (AMM) instance. * Returns an {@link AMMInfoResponse}. * * @category Requests @@ -47,13 +47,13 @@ export interface AMMInfoResponse extends BaseResponse { /** * The total amount of one asset in the AMM's pool. - * Note: This could be asset or asset2 from the request. + * (Note: This could be asset or asset2 from the request) */ amount: Amount /** * The total amount of the other asset in the AMM's pool. - * Note: This could be asset or asset2 from the request. + * (Note: This could be asset or asset2 from the request) */ amount2: Amount From 5878433cafbcd9fb72401245498bf5120ae5e6aa Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 25 Jul 2023 19:39:14 -0400 Subject: [PATCH 81/93] convert caution to all caps --- packages/xrpl/src/models/transactions/AMMCreate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/transactions/AMMCreate.ts b/packages/xrpl/src/models/transactions/AMMCreate.ts index 139b2e70c7..8924fa75ff 100644 --- a/packages/xrpl/src/models/transactions/AMMCreate.ts +++ b/packages/xrpl/src/models/transactions/AMMCreate.ts @@ -12,7 +12,7 @@ export const AMM_MAX_TRADING_FEE = 1000 * Also transfers ownership of the starting balance of both assets from the sender to the created AccountRoot * and issues an initial balance of liquidity provider tokens (LP Tokens) from the AMM account to the sender. * - * Caution: When you create the AMM, you should fund it with (approximately) equal-value amounts of each asset. + * CAUTION: When you create the AMM, you should fund it with (approximately) equal-value amounts of each asset. * Otherwise, other users can profit at your expense by trading with this AMM (performing arbitrage). * The currency risk that liquidity providers take on increases with the volatility (potential for imbalance) of the asset pair. * The higher the trading fee, the more it offsets this risk, From 34b667dc869041f2a6dffd343b1f111d2b46e023 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Thu, 27 Jul 2023 18:43:04 -0400 Subject: [PATCH 82/93] add validation for AuthAccounts --- .../xrpl/src/models/transactions/AMMBid.ts | 44 ++++++++++++++ packages/xrpl/test/models/AMMBid.test.ts | 57 +++++++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/packages/xrpl/src/models/transactions/AMMBid.ts b/packages/xrpl/src/models/transactions/AMMBid.ts index 50657729d1..76a5eb9435 100644 --- a/packages/xrpl/src/models/transactions/AMMBid.ts +++ b/packages/xrpl/src/models/transactions/AMMBid.ts @@ -65,6 +65,7 @@ export interface AMMBid extends BaseTransaction { * @param tx - An AMMBid Transaction. * @throws When the AMMBid is Malformed. */ +// eslint-disable-next-line max-lines-per-function -- necessary for validateAMMBid export function validateAMMBid(tx: Record): void { validateBaseTransaction(tx) @@ -103,5 +104,48 @@ export function validateAMMBid(tx: Record): void { `AMMBid: AuthAccounts length must not be greater than ${MAX_AUTH_ACCOUNTS}`, ) } + if ( + !isAuthAccounts( + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Only used by JS + tx.Account as string, + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Only used by JS + tx.AuthAccounts as Array>, + ) + ) { + throw new ValidationError(`AMMBid: invalid AuthAccounts`) + } + } +} + +function isAuthAccounts( + senderAddress: string, + authAccounts: Array>, +): boolean { + for (const authAccount of authAccounts) { + if ( + authAccount.AuthAccount == null || + typeof authAccount.AuthAccount !== 'object' + ) { + return false + } + // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- used for null check + // @ts-expect-error -- used for null check + if (authAccount.AuthAccount.Account == null) { + return false + } + // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- used for null check + // @ts-expect-error -- used for null check + if (typeof authAccount.AuthAccount.Account !== 'string') { + return false + } + // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- used for null check + // @ts-expect-error -- used for null check + if (authAccount.AuthAccount.Account === senderAddress) { + throw new ValidationError( + `AMMBid: AuthAccounts must not include sender's address`, + ) + } } + + return true } diff --git a/packages/xrpl/test/models/AMMBid.test.ts b/packages/xrpl/test/models/AMMBid.test.ts index e06dac8f27..9bbc76ee6e 100644 --- a/packages/xrpl/test/models/AMMBid.test.ts +++ b/packages/xrpl/test/models/AMMBid.test.ts @@ -108,4 +108,61 @@ describe('AMMBid', function () { assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) assert.throws(() => validate(bid), ValidationError, errorMessage) }) + + it(`throws w/ AuthAccounts must be an AuthAccount array`, function () { + bid.AuthAccounts = 1234 + const errorMessage = 'AMMBid: AuthAccounts must be an AuthAccount array' + assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) + assert.throws(() => validate(bid), ValidationError, errorMessage) + }) + + it(`throws w/ invalid AuthAccounts when AuthAccount is null`, function () { + bid.AuthAccounts[0] = { + AuthAccount: null, + } + const errorMessage = 'AMMBid: invalid AuthAccounts' + assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) + assert.throws(() => validate(bid), ValidationError, errorMessage) + }) + + it(`throws w/ invalid AuthAccounts when AuthAccount is undefined`, function () { + bid.AuthAccounts[0] = { + AuthAccount: undefined, + } + const errorMessage = 'AMMBid: invalid AuthAccounts' + assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) + assert.throws(() => validate(bid), ValidationError, errorMessage) + }) + + it(`throws w/ invalid AuthAccounts when AuthAccount is not an object`, function () { + bid.AuthAccounts[0] = { + AuthAccount: 1234, + } + const errorMessage = 'AMMBid: invalid AuthAccounts' + assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) + assert.throws(() => validate(bid), ValidationError, errorMessage) + }) + + it(`throws w/ invalid AuthAccounts when AuthAccount.Account is not a string`, function () { + bid.AuthAccounts[0] = { + AuthAccount: { + Account: 1234, + }, + } + const errorMessage = 'AMMBid: invalid AuthAccounts' + assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) + assert.throws(() => validate(bid), ValidationError, errorMessage) + }) + + it(`throws w/ AuthAccounts must not include sender's address`, function () { + bid.AuthAccounts[0] = { + AuthAccount: { + Account: bid.Account, + }, + } + const errorMessage = + "AMMBid: AuthAccounts must not include sender's address" + assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) + assert.throws(() => validate(bid), ValidationError, errorMessage) + }) }) From 70d180c68b04ab012a48bb4df779d83683c462cf Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Thu, 27 Jul 2023 18:58:43 -0400 Subject: [PATCH 83/93] refactor and export interfaces --- packages/xrpl/src/models/common/index.ts | 6 ++++++ packages/xrpl/src/models/ledger/AMM.ts | 10 ++-------- packages/xrpl/src/models/methods/ammInfo.ts | 20 ++++++++----------- .../xrpl/src/models/transactions/AMMBid.ts | 8 +------- 4 files changed, 17 insertions(+), 27 deletions(-) diff --git a/packages/xrpl/src/models/common/index.ts b/packages/xrpl/src/models/common/index.ts index f64ae22f8a..8a4e06b655 100644 --- a/packages/xrpl/src/models/common/index.ts +++ b/packages/xrpl/src/models/common/index.ts @@ -141,3 +141,9 @@ export interface NFToken { nft_serial: number uri: string } + +export interface AuthAccount { + AuthAccount: { + account: string + } +} diff --git a/packages/xrpl/src/models/ledger/AMM.ts b/packages/xrpl/src/models/ledger/AMM.ts index 1e501c8245..01f3fd1392 100644 --- a/packages/xrpl/src/models/ledger/AMM.ts +++ b/packages/xrpl/src/models/ledger/AMM.ts @@ -1,14 +1,8 @@ -import { Currency } from '../common' +import { AuthAccount, Currency } from '../common' import BaseLedgerEntry from './BaseLedgerEntry' -interface AuthAccount { - AuthAccount: { - account: string - } -} - -interface VoteSlot { +export interface VoteSlot { VoteEntry: { Account: string TradingFee: number diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index c451c3f4ba..d7e819cf2d 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -22,16 +22,6 @@ export interface AMMInfoRequest extends BaseRequest { asset2: Currency } -interface AuthAccount { - account: string -} - -interface VoteSlot { - account: string - trading_fee: number - vote_weight: number -} - /** * Response expected from an {@link AMMInfoRequest}. * @@ -81,7 +71,9 @@ export interface AMMInfoResponse extends BaseResponse { * of the discounted trading fee. * Each member of this array is an object with one field, account, containing the address of the designated account. */ - auth_accounts: AuthAccount[] + auth_accounts: Array<{ + account: string + }> /** * The discounted trading fee that applies to the auction slot holder, and any eligible accounts @@ -124,7 +116,11 @@ export interface AMMInfoResponse extends BaseResponse { /** * (May be omitted) The current votes for the AMM's trading fee, as Vote Slot Objects. */ - vote_slots?: VoteSlot[] + vote_slots?: Array<{ + account: string + trading_fee: number + vote_weight: number + }> } /** diff --git a/packages/xrpl/src/models/transactions/AMMBid.ts b/packages/xrpl/src/models/transactions/AMMBid.ts index 76a5eb9435..ad60a7dc10 100644 --- a/packages/xrpl/src/models/transactions/AMMBid.ts +++ b/packages/xrpl/src/models/transactions/AMMBid.ts @@ -1,6 +1,6 @@ /* eslint-disable complexity -- required for validateAMMBid */ import { ValidationError } from '../../errors' -import { Amount, Currency } from '../common' +import { Amount, AuthAccount, Currency } from '../common' import { BaseTransaction, @@ -11,12 +11,6 @@ import { const MAX_AUTH_ACCOUNTS = 4 -interface AuthAccount { - AuthAccount: { - Account: string - } -} - /** * Bid on an Automated Market Maker's (AMM's) auction slot. * From 2f5b6343ac3ff7388dd6508431ec7f157d3756ff Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 1 Aug 2023 13:01:40 -0400 Subject: [PATCH 84/93] use Currency type --- packages/xrpl/src/models/ledger/AMM.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/xrpl/src/models/ledger/AMM.ts b/packages/xrpl/src/models/ledger/AMM.ts index 01f3fd1392..48149711af 100644 --- a/packages/xrpl/src/models/ledger/AMM.ts +++ b/packages/xrpl/src/models/ledger/AMM.ts @@ -24,17 +24,11 @@ export default interface AMM extends BaseLedgerEntry { /** * The definition for one of the two assets this AMM holds. */ - Asset: { - currency: string - issuer?: string - } + Asset: Currency /** * The definition for the other asset this AMM holds. */ - Asset2: { - currency: string - issuer?: string - } + Asset2: Currency /** * Details of the current owner of the auction slot. */ From 29e5348e6b7040d24810c378c8f23a68a10193f5 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Mon, 7 Aug 2023 21:06:44 -0400 Subject: [PATCH 85/93] update definitions --- packages/ripple-binary-codec/src/enums/definitions.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/ripple-binary-codec/src/enums/definitions.json b/packages/ripple-binary-codec/src/enums/definitions.json index 1911bd47a3..1ab810e449 100644 --- a/packages/ripple-binary-codec/src/enums/definitions.json +++ b/packages/ripple-binary-codec/src/enums/definitions.json @@ -2549,7 +2549,11 @@ "tecUNFUNDED_AMM": 162, "tecAMM_BALANCE": 163, "tecAMM_FAILED": 164, - "tecAMM_INVALID_TOKENS": 165 + "tecAMM_INVALID_TOKENS": 165, + "tecAMM_EMPTY": 166, + "tecAMM_NOT_EMPTY": 167, + "tecAMM_ACCOUNT": 168, + "tecINCOMPLETE": 169 }, "TRANSACTION_TYPES": { "Invalid": -1, @@ -2587,6 +2591,7 @@ "AMMWithdraw": 37, "AMMVote": 38, "AMMBid": 39, + "AMMDelete": 40, "EnableAmendment": 100, "SetFee": 101, "UNLModify": 102 From b5a8b73dde851a71d4a2373435518821b348d1c2 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Mon, 7 Aug 2023 21:38:34 -0400 Subject: [PATCH 86/93] add AMMDelete --- .../xrpl/src/models/transactions/AMMDelete.ts | 47 +++++++++++ .../xrpl/src/models/transactions/index.ts | 1 + .../src/models/transactions/transaction.ts | 6 ++ packages/xrpl/test/models/AMMDelete.test.ts | 78 +++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 packages/xrpl/src/models/transactions/AMMDelete.ts create mode 100644 packages/xrpl/test/models/AMMDelete.test.ts diff --git a/packages/xrpl/src/models/transactions/AMMDelete.ts b/packages/xrpl/src/models/transactions/AMMDelete.ts new file mode 100644 index 0000000000..9b8d34c983 --- /dev/null +++ b/packages/xrpl/src/models/transactions/AMMDelete.ts @@ -0,0 +1,47 @@ +import { ValidationError } from '../../errors' +import { Currency } from '../common' + +import { BaseTransaction, isCurrency, validateBaseTransaction } from './common' + +/** + * TODO: Fill in when docs are ready. + */ +export interface AMMDelete extends BaseTransaction { + TransactionType: 'AMMDelete' + + /** + * The definition for one of the assets in the AMM's pool. + */ + Asset: Currency + + /** + * The definition for the other asset in the AMM's pool. + */ + Asset2: Currency +} + +/** + * Verify the form and type of an AMMDelete at runtime. + * + * @param tx - An AMMDelete Transaction. + * @throws When the AMMDelete is Malformed. + */ +export function validateAMMDelete(tx: Record): void { + validateBaseTransaction(tx) + + if (tx.Asset == null) { + throw new ValidationError('AMMDelete: missing field Asset') + } + + if (!isCurrency(tx.Asset)) { + throw new ValidationError('AMMDelete: Asset must be an Currency') + } + + if (tx.Asset2 == null) { + throw new ValidationError('AMMDelete: missing field Asset2') + } + + if (!isCurrency(tx.Asset2)) { + throw new ValidationError('AMMDelete: Asset2 must be an Currency') + } +} diff --git a/packages/xrpl/src/models/transactions/index.ts b/packages/xrpl/src/models/transactions/index.ts index 8f12922716..f4ac17162b 100644 --- a/packages/xrpl/src/models/transactions/index.ts +++ b/packages/xrpl/src/models/transactions/index.ts @@ -9,6 +9,7 @@ export { } from './accountSet' export { AccountDelete } from './accountDelete' export { AMMBid } from './AMMBid' +export { AMMDelete } from './AMMDelete' export { AMMDepositFlags, AMMDepositFlagsInterface, diff --git a/packages/xrpl/src/models/transactions/transaction.ts b/packages/xrpl/src/models/transactions/transaction.ts index 2616a9ebac..d726e9962d 100644 --- a/packages/xrpl/src/models/transactions/transaction.ts +++ b/packages/xrpl/src/models/transactions/transaction.ts @@ -10,6 +10,7 @@ import { AccountDelete, validateAccountDelete } from './accountDelete' import { AccountSet, validateAccountSet } from './accountSet' import { AMMBid, validateAMMBid } from './AMMBid' import { AMMCreate, validateAMMCreate } from './AMMCreate' +import { AMMDelete, validateAMMDelete } from './AMMDelete' import { AMMDeposit, validateAMMDeposit } from './AMMDeposit' import { AMMVote, validateAMMVote } from './AMMVote' import { AMMWithdraw, validateAMMWithdraw } from './AMMWithdraw' @@ -64,6 +65,7 @@ export type Transaction = | AccountDelete | AccountSet | AMMBid + | AMMDelete | AMMDeposit | AMMCreate | AMMVote @@ -181,6 +183,10 @@ export function validate(transaction: Record): void { validateAMMBid(tx) break + case 'AMMDelete': + validateAMMDelete(tx) + break + case 'AMMDeposit': validateAMMDeposit(tx) break diff --git a/packages/xrpl/test/models/AMMDelete.test.ts b/packages/xrpl/test/models/AMMDelete.test.ts new file mode 100644 index 0000000000..c4121134cd --- /dev/null +++ b/packages/xrpl/test/models/AMMDelete.test.ts @@ -0,0 +1,78 @@ +import { assert } from 'chai' + +import { validate, ValidationError } from '../../src' +import { validateAMMDelete } from '../../src/models/transactions/AMMDelete' + +/** + * AMMDelete Transaction Verification Testing. + * + * Providing runtime verification testing for each specific transaction type. + */ +describe('AMMDelete', function () { + let ammDelete + + beforeEach(function () { + ammDelete = { + TransactionType: 'AMMDelete', + Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', + Asset: { + currency: 'XRP', + }, + Asset2: { + currency: 'ETH', + issuer: 'rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd', + }, + Sequence: 1337, + Flags: 0, + } as any + }) + + it(`verifies valid AMMDelete`, function () { + assert.doesNotThrow(() => validateAMMDelete(ammDelete)) + assert.doesNotThrow(() => validate(ammDelete)) + }) + + it(`throws w/ missing field Asset`, function () { + delete ammDelete.Asset + const errorMessage = 'AMMDelete: missing field Asset' + assert.throws( + () => validateAMMDelete(ammDelete), + ValidationError, + errorMessage, + ) + assert.throws(() => validate(ammDelete), ValidationError, errorMessage) + }) + + it(`throws w/ Asset must be an Currency`, function () { + ammDelete.Asset = 1234 + const errorMessage = 'AMMDelete: Asset must be an Currency' + assert.throws( + () => validateAMMDelete(ammDelete), + ValidationError, + errorMessage, + ) + assert.throws(() => validate(ammDelete), ValidationError, errorMessage) + }) + + it(`throws w/ missing field Asset2`, function () { + delete ammDelete.Asset2 + const errorMessage = 'AMMDelete: missing field Asset2' + assert.throws( + () => validateAMMDelete(ammDelete), + ValidationError, + errorMessage, + ) + assert.throws(() => validate(ammDelete), ValidationError, errorMessage) + }) + + it(`throws w/ Asset2 must be an Currency`, function () { + ammDelete.Asset2 = 1234 + const errorMessage = 'AMMDelete: Asset2 must be an Currency' + assert.throws( + () => validateAMMDelete(ammDelete), + ValidationError, + errorMessage, + ) + assert.throws(() => validate(ammDelete), ValidationError, errorMessage) + }) +}) From 440ef57509e565c144733d2368abd1f0c1351664 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 16 Aug 2023 15:05:55 -0400 Subject: [PATCH 87/93] rename Issue to Currency in error message --- packages/xrpl/src/models/transactions/AMMBid.ts | 4 ++-- packages/xrpl/src/models/transactions/AMMDeposit.ts | 4 ++-- packages/xrpl/src/models/transactions/AMMVote.ts | 4 ++-- packages/xrpl/src/models/transactions/AMMWithdraw.ts | 4 ++-- packages/xrpl/test/models/AMMBid.test.ts | 8 ++++---- packages/xrpl/test/models/AMMDeposit.test.ts | 8 ++++---- packages/xrpl/test/models/AMMVote.test.ts | 8 ++++---- packages/xrpl/test/models/AMMWithdraw.test.ts | 8 ++++---- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/packages/xrpl/src/models/transactions/AMMBid.ts b/packages/xrpl/src/models/transactions/AMMBid.ts index ad60a7dc10..6974f20c7b 100644 --- a/packages/xrpl/src/models/transactions/AMMBid.ts +++ b/packages/xrpl/src/models/transactions/AMMBid.ts @@ -68,7 +68,7 @@ export function validateAMMBid(tx: Record): void { } if (!isCurrency(tx.Asset)) { - throw new ValidationError('AMMBid: Asset must be an Issue') + throw new ValidationError('AMMBid: Asset must be a Currency') } if (tx.Asset2 == null) { @@ -76,7 +76,7 @@ export function validateAMMBid(tx: Record): void { } if (!isCurrency(tx.Asset2)) { - throw new ValidationError('AMMBid: Asset2 must be an Issue') + throw new ValidationError('AMMBid: Asset2 must be a Currency') } if (tx.BidMin != null && !isAmount(tx.BidMin)) { diff --git a/packages/xrpl/src/models/transactions/AMMDeposit.ts b/packages/xrpl/src/models/transactions/AMMDeposit.ts index 53bef9a553..92648fba50 100644 --- a/packages/xrpl/src/models/transactions/AMMDeposit.ts +++ b/packages/xrpl/src/models/transactions/AMMDeposit.ts @@ -89,7 +89,7 @@ export function validateAMMDeposit(tx: Record): void { } if (!isCurrency(tx.Asset)) { - throw new ValidationError('AMMDeposit: Asset must be an Issue') + throw new ValidationError('AMMDeposit: Asset must be a Currency') } if (tx.Asset2 == null) { @@ -97,7 +97,7 @@ export function validateAMMDeposit(tx: Record): void { } if (!isCurrency(tx.Asset2)) { - throw new ValidationError('AMMDeposit: Asset2 must be an Issue') + throw new ValidationError('AMMDeposit: Asset2 must be a Currency') } if (tx.Amount2 != null && tx.Amount == null) { diff --git a/packages/xrpl/src/models/transactions/AMMVote.ts b/packages/xrpl/src/models/transactions/AMMVote.ts index 8daaf45e98..0d469fa0a8 100644 --- a/packages/xrpl/src/models/transactions/AMMVote.ts +++ b/packages/xrpl/src/models/transactions/AMMVote.ts @@ -44,7 +44,7 @@ export function validateAMMVote(tx: Record): void { } if (!isCurrency(tx.Asset)) { - throw new ValidationError('AMMVote: Asset must be an Issue') + throw new ValidationError('AMMVote: Asset must be a Currency') } if (tx.Asset2 == null) { @@ -52,7 +52,7 @@ export function validateAMMVote(tx: Record): void { } if (!isCurrency(tx.Asset2)) { - throw new ValidationError('AMMVote: Asset2 must be an Issue') + throw new ValidationError('AMMVote: Asset2 must be a Currency') } if (tx.TradingFee == null) { diff --git a/packages/xrpl/src/models/transactions/AMMWithdraw.ts b/packages/xrpl/src/models/transactions/AMMWithdraw.ts index 4ebe6efb62..77411616bc 100644 --- a/packages/xrpl/src/models/transactions/AMMWithdraw.ts +++ b/packages/xrpl/src/models/transactions/AMMWithdraw.ts @@ -89,7 +89,7 @@ export function validateAMMWithdraw(tx: Record): void { } if (!isCurrency(tx.Asset)) { - throw new ValidationError('AMMWithdraw: Asset must be an Issue') + throw new ValidationError('AMMWithdraw: Asset must be a Currency') } if (tx.Asset2 == null) { @@ -97,7 +97,7 @@ export function validateAMMWithdraw(tx: Record): void { } if (!isCurrency(tx.Asset2)) { - throw new ValidationError('AMMWithdraw: Asset2 must be an Issue') + throw new ValidationError('AMMWithdraw: Asset2 must be a Currency') } if (tx.Amount2 != null && tx.Amount == null) { diff --git a/packages/xrpl/test/models/AMMBid.test.ts b/packages/xrpl/test/models/AMMBid.test.ts index 9bbc76ee6e..c958804a80 100644 --- a/packages/xrpl/test/models/AMMBid.test.ts +++ b/packages/xrpl/test/models/AMMBid.test.ts @@ -62,9 +62,9 @@ describe('AMMBid', function () { assert.throws(() => validate(bid), ValidationError, errorMessage) }) - it(`throws w/ Asset must be an Issue`, function () { + it(`throws w/ Asset must be a Currency`, function () { bid.Asset = 1234 - const errorMessage = 'AMMBid: Asset must be an Issue' + const errorMessage = 'AMMBid: Asset must be a Currency' assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) assert.throws(() => validate(bid), ValidationError, errorMessage) }) @@ -76,9 +76,9 @@ describe('AMMBid', function () { assert.throws(() => validate(bid), ValidationError, errorMessage) }) - it(`throws w/ Asset2 must be an Issue`, function () { + it(`throws w/ Asset2 must be a Currency`, function () { bid.Asset2 = 1234 - const errorMessage = 'AMMBid: Asset2 must be an Issue' + const errorMessage = 'AMMBid: Asset2 must be a Currency' assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) assert.throws(() => validate(bid), ValidationError, errorMessage) }) diff --git a/packages/xrpl/test/models/AMMDeposit.test.ts b/packages/xrpl/test/models/AMMDeposit.test.ts index b30871f7d5..0f041d86f4 100644 --- a/packages/xrpl/test/models/AMMDeposit.test.ts +++ b/packages/xrpl/test/models/AMMDeposit.test.ts @@ -86,9 +86,9 @@ describe('AMMDeposit', function () { assert.throws(() => validate(deposit), ValidationError, errorMessage) }) - it(`throws w/ Asset must be an Issue`, function () { + it(`throws w/ Asset must be a Currency`, function () { deposit.Asset = 1234 - const errorMessage = 'AMMDeposit: Asset must be an Issue' + const errorMessage = 'AMMDeposit: Asset must be a Currency' assert.throws( () => validateAMMDeposit(deposit), ValidationError, @@ -108,9 +108,9 @@ describe('AMMDeposit', function () { assert.throws(() => validate(deposit), ValidationError, errorMessage) }) - it(`throws w/ Asset2 must be an Issue`, function () { + it(`throws w/ Asset2 must be a Currency`, function () { deposit.Asset2 = 1234 - const errorMessage = 'AMMDeposit: Asset2 must be an Issue' + const errorMessage = 'AMMDeposit: Asset2 must be a Currency' assert.throws( () => validateAMMDeposit(deposit), ValidationError, diff --git a/packages/xrpl/test/models/AMMVote.test.ts b/packages/xrpl/test/models/AMMVote.test.ts index dfc11f88eb..25f6cdeffe 100644 --- a/packages/xrpl/test/models/AMMVote.test.ts +++ b/packages/xrpl/test/models/AMMVote.test.ts @@ -39,9 +39,9 @@ describe('AMMVote', function () { assert.throws(() => validate(vote), ValidationError, errorMessage) }) - it(`throws w/ Asset must be an Issue`, function () { + it(`throws w/ Asset must be a Currency`, function () { vote.Asset = 1234 - const errorMessage = 'AMMVote: Asset must be an Issue' + const errorMessage = 'AMMVote: Asset must be a Currency' assert.throws(() => validateAMMVote(vote), ValidationError, errorMessage) assert.throws(() => validate(vote), ValidationError, errorMessage) }) @@ -53,9 +53,9 @@ describe('AMMVote', function () { assert.throws(() => validate(vote), ValidationError, errorMessage) }) - it(`throws w/ Asset2 must be an Issue`, function () { + it(`throws w/ Asset2 must be a Currency`, function () { vote.Asset2 = 1234 - const errorMessage = 'AMMVote: Asset2 must be an Issue' + const errorMessage = 'AMMVote: Asset2 must be a Currency' assert.throws(() => validateAMMVote(vote), ValidationError, errorMessage) assert.throws(() => validate(vote), ValidationError, errorMessage) }) diff --git a/packages/xrpl/test/models/AMMWithdraw.test.ts b/packages/xrpl/test/models/AMMWithdraw.test.ts index 3f21c71470..47092ef724 100644 --- a/packages/xrpl/test/models/AMMWithdraw.test.ts +++ b/packages/xrpl/test/models/AMMWithdraw.test.ts @@ -99,9 +99,9 @@ describe('AMMWithdraw', function () { assert.throws(() => validate(withdraw), ValidationError, errorMessage) }) - it(`throws w/ Asset must be an Issue`, function () { + it(`throws w/ Asset must be a Currency`, function () { withdraw.Asset = 1234 - const errorMessage = 'AMMWithdraw: Asset must be an Issue' + const errorMessage = 'AMMWithdraw: Asset must be a Currency' assert.throws( () => validateAMMWithdraw(withdraw), ValidationError, @@ -121,9 +121,9 @@ describe('AMMWithdraw', function () { assert.throws(() => validate(withdraw), ValidationError, errorMessage) }) - it(`throws w/ Asset2 must be an Issue`, function () { + it(`throws w/ Asset2 must be a Currency`, function () { withdraw.Asset2 = 1234 - const errorMessage = 'AMMWithdraw: Asset2 must be an Issue' + const errorMessage = 'AMMWithdraw: Asset2 must be a Currency' assert.throws( () => validateAMMWithdraw(withdraw), ValidationError, From 434754c4060077aaaff2e754b86da691590401e4 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 16 Aug 2023 15:10:30 -0400 Subject: [PATCH 88/93] mark asset frozen as optional fields --- packages/xrpl/src/models/methods/ammInfo.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/xrpl/src/models/methods/ammInfo.ts b/packages/xrpl/src/models/methods/ammInfo.ts index d7e819cf2d..bf907ffe43 100644 --- a/packages/xrpl/src/models/methods/ammInfo.ts +++ b/packages/xrpl/src/models/methods/ammInfo.ts @@ -50,12 +50,12 @@ export interface AMMInfoResponse extends BaseResponse { /** * (Omitted for XRP) If true, the amount currency is currently frozen for asset. */ - asset_frozen: boolean + asset_frozen?: boolean /** * (Omitted for XRP) If true, the amount currency is currently frozen for asset2. */ - asset2_frozen: boolean + asset2_frozen?: boolean /** * (May be omitted) An Auction Slot Object describing the current auction slot holder, if there is one. From bffce20bce7bc72b3a5a06519c04abe90ffee7c4 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 16 Aug 2023 15:17:11 -0400 Subject: [PATCH 89/93] refactor isAuthAccounts --- .../xrpl/src/models/transactions/AMMBid.ts | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/packages/xrpl/src/models/transactions/AMMBid.ts b/packages/xrpl/src/models/transactions/AMMBid.ts index 6974f20c7b..8c596b6ac4 100644 --- a/packages/xrpl/src/models/transactions/AMMBid.ts +++ b/packages/xrpl/src/models/transactions/AMMBid.ts @@ -59,7 +59,6 @@ export interface AMMBid extends BaseTransaction { * @param tx - An AMMBid Transaction. * @throws When the AMMBid is Malformed. */ -// eslint-disable-next-line max-lines-per-function -- necessary for validateAMMBid export function validateAMMBid(tx: Record): void { validateBaseTransaction(tx) @@ -98,16 +97,12 @@ export function validateAMMBid(tx: Record): void { `AMMBid: AuthAccounts length must not be greater than ${MAX_AUTH_ACCOUNTS}`, ) } - if ( - !isAuthAccounts( - // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Only used by JS - tx.Account as string, - // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Only used by JS - tx.AuthAccounts as Array>, - ) - ) { - throw new ValidationError(`AMMBid: invalid AuthAccounts`) - } + isAuthAccounts( + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Only used by JS + tx.Account as string, + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Only used by JS + tx.AuthAccounts as Array>, + ) } } @@ -120,17 +115,17 @@ function isAuthAccounts( authAccount.AuthAccount == null || typeof authAccount.AuthAccount !== 'object' ) { - return false + throw new ValidationError(`AMMBid: invalid AuthAccounts`) } // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- used for null check // @ts-expect-error -- used for null check if (authAccount.AuthAccount.Account == null) { - return false + throw new ValidationError(`AMMBid: invalid AuthAccounts`) } // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- used for null check // @ts-expect-error -- used for null check if (typeof authAccount.AuthAccount.Account !== 'string') { - return false + throw new ValidationError(`AMMBid: invalid AuthAccounts`) } // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- used for null check // @ts-expect-error -- used for null check From 760eb9a59bce488d383a40288e265d6e10feef5a Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Wed, 16 Aug 2023 15:21:14 -0400 Subject: [PATCH 90/93] add AMMDelete jsdoc --- packages/xrpl/src/models/transactions/AMMDelete.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/transactions/AMMDelete.ts b/packages/xrpl/src/models/transactions/AMMDelete.ts index 9b8d34c983..9a35f0d76c 100644 --- a/packages/xrpl/src/models/transactions/AMMDelete.ts +++ b/packages/xrpl/src/models/transactions/AMMDelete.ts @@ -4,7 +4,15 @@ import { Currency } from '../common' import { BaseTransaction, isCurrency, validateBaseTransaction } from './common' /** - * TODO: Fill in when docs are ready. + * Delete an empty Automated Market Maker (AMM) instance that could not be fully deleted automatically. + * + * Tip: The AMMWithdraw transaction automatically tries to delete an AMM, along with associated ledger + * entries such as empty trust lines, if it withdrew all the assets from the AMM's pool. + * However, if there are too many trust lines to the AMM account to remove in one transaction, + * it may stop before fully removing the AMM. Similarly, an AMMDelete transaction removes up to + * a maximum number of trust lines; in extreme cases, it may take several AMMDelete transactions + * to fully delete the trust lines and the associated AMM. + * In all cases, the AMM ledger entry and AMM account are deleted by the last such transaction. */ export interface AMMDelete extends BaseTransaction { TransactionType: 'AMMDelete' From 1e007538f66c5507dfd8498e86043c9a266d97e8 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Thu, 17 Aug 2023 12:43:40 -0400 Subject: [PATCH 91/93] rename to validateAuthAccounts --- packages/xrpl/src/models/transactions/AMMBid.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/xrpl/src/models/transactions/AMMBid.ts b/packages/xrpl/src/models/transactions/AMMBid.ts index 8c596b6ac4..b7634ba506 100644 --- a/packages/xrpl/src/models/transactions/AMMBid.ts +++ b/packages/xrpl/src/models/transactions/AMMBid.ts @@ -97,7 +97,7 @@ export function validateAMMBid(tx: Record): void { `AMMBid: AuthAccounts length must not be greater than ${MAX_AUTH_ACCOUNTS}`, ) } - isAuthAccounts( + validateAuthAccounts( // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Only used by JS tx.Account as string, // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Only used by JS @@ -106,7 +106,7 @@ export function validateAMMBid(tx: Record): void { } } -function isAuthAccounts( +function validateAuthAccounts( senderAddress: string, authAccounts: Array>, ): boolean { From 14f68297a01fb50d78e8b9d691237f50a40d2e82 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Thu, 17 Aug 2023 12:45:09 -0400 Subject: [PATCH 92/93] fix typo --- packages/xrpl/src/models/transactions/AMMDelete.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/xrpl/src/models/transactions/AMMDelete.ts b/packages/xrpl/src/models/transactions/AMMDelete.ts index 9a35f0d76c..6e64f8c58b 100644 --- a/packages/xrpl/src/models/transactions/AMMDelete.ts +++ b/packages/xrpl/src/models/transactions/AMMDelete.ts @@ -42,7 +42,7 @@ export function validateAMMDelete(tx: Record): void { } if (!isCurrency(tx.Asset)) { - throw new ValidationError('AMMDelete: Asset must be an Currency') + throw new ValidationError('AMMDelete: Asset must be a Currency') } if (tx.Asset2 == null) { @@ -50,6 +50,6 @@ export function validateAMMDelete(tx: Record): void { } if (!isCurrency(tx.Asset2)) { - throw new ValidationError('AMMDelete: Asset2 must be an Currency') + throw new ValidationError('AMMDelete: Asset2 must be a Currency') } } From e4636310a75bbffc18d571a6023024e86aad66c3 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Thu, 17 Aug 2023 22:33:38 -0400 Subject: [PATCH 93/93] fix typo in unit test --- packages/xrpl/test/models/AMMDelete.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/xrpl/test/models/AMMDelete.test.ts b/packages/xrpl/test/models/AMMDelete.test.ts index c4121134cd..8c4c9936c8 100644 --- a/packages/xrpl/test/models/AMMDelete.test.ts +++ b/packages/xrpl/test/models/AMMDelete.test.ts @@ -43,9 +43,9 @@ describe('AMMDelete', function () { assert.throws(() => validate(ammDelete), ValidationError, errorMessage) }) - it(`throws w/ Asset must be an Currency`, function () { + it(`throws w/ Asset must be a Currency`, function () { ammDelete.Asset = 1234 - const errorMessage = 'AMMDelete: Asset must be an Currency' + const errorMessage = 'AMMDelete: Asset must be a Currency' assert.throws( () => validateAMMDelete(ammDelete), ValidationError, @@ -65,9 +65,9 @@ describe('AMMDelete', function () { assert.throws(() => validate(ammDelete), ValidationError, errorMessage) }) - it(`throws w/ Asset2 must be an Currency`, function () { + it(`throws w/ Asset2 must be a Currency`, function () { ammDelete.Asset2 = 1234 - const errorMessage = 'AMMDelete: Asset2 must be an Currency' + const errorMessage = 'AMMDelete: Asset2 must be a Currency' assert.throws( () => validateAMMDelete(ammDelete), ValidationError,