Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
69cbf97
round 1
mvadari Feb 6, 2025
acfddee
round 2
mvadari Feb 6, 2025
284e51b
round 3
mvadari Feb 12, 2025
cf40d2a
fixing tests round 1
mvadari Feb 12, 2025
2e1ff66
fix all tests
mvadari Feb 12, 2025
30fe6e0
update history
mvadari Feb 12, 2025
8216446
Merge branch 'main' into model-cleanup
mvadari Feb 12, 2025
6073427
fix build issues
mvadari Feb 12, 2025
6dd9b2c
refactor tests to use a helper function
mvadari Feb 12, 2025
5ff418f
fix tests
mvadari Feb 12, 2025
2bcdf22
clean up
mvadari Feb 12, 2025
5b74906
add flag validation tests
mvadari Feb 12, 2025
5b89567
clean up
mvadari Feb 12, 2025
92c50ec
update models
mvadari Feb 12, 2025
870c965
fix build/test issues
mvadari Feb 12, 2025
22b6a1f
more cleanup
mvadari Feb 13, 2025
89b9000
Merge branch 'main' into model-cleanup
mvadari Feb 14, 2025
3ac297b
isNumberWithBounds
mvadari Feb 14, 2025
fa25caf
fix linting
mvadari Feb 14, 2025
ecf26e4
fix linter error
mvadari Feb 18, 2025
cbbcdab
more test updates - more specific helpers, better error messages
mvadari Feb 27, 2025
aa6dcac
[WIP] start fixing tests based on previous commit
mvadari Feb 27, 2025
79f82d6
fix rest of tests
mvadari Feb 27, 2025
74555e9
Merge branch 'main' into model-cleanup
mvadari Feb 27, 2025
e92244d
fix dupe
mvadari Feb 27, 2025
16b5128
add docs
mvadari Feb 27, 2025
01900b0
more cleanup
mvadari Feb 27, 2025
b3e0007
more cleanup
mvadari Feb 27, 2025
7e9d563
undo bad change
mvadari Feb 27, 2025
edda9dd
Merge branch 'main' into model-cleanup
mvadari Mar 18, 2025
2d92bd7
Merge branch 'main' into model-cleanup
mvadari Mar 26, 2025
0486d78
Merge branch 'main' into model-cleanup
mvadari Apr 10, 2025
52edce3
minor cleanup
mvadari Apr 10, 2025
8ac77a7
fix tests
mvadari Apr 10, 2025
556b55c
improve type-checking
mvadari Apr 16, 2025
fd9a882
fix errors
mvadari Apr 16, 2025
df2e235
fix ts issues
mvadari Apr 16, 2025
20f8a71
more fixes
mvadari Apr 16, 2025
c48bc9c
Merge branch 'main' into model-cleanup
mvadari Apr 16, 2025
85514c6
more cleanup
mvadari Apr 16, 2025
1dac581
Merge branch 'main' into model-cleanup
mvadari Apr 17, 2025
acb7bfd
consolidate code
mvadari Apr 17, 2025
d8e8fc8
Merge branch 'main' into model-cleanup
mvadari Apr 18, 2025
ac43592
respond to comments
mvadari Apr 18, 2025
3b25438
fix tests
mvadari Apr 18, 2025
6b662a5
Merge branch 'main' into model-cleanup
mvadari Apr 29, 2025
362bc61
simplify generics
mvadari May 8, 2025
4bec30b
more generics
mvadari May 8, 2025
ac2796b
not a valid -> invalid
mvadari May 8, 2025
3d03c6e
clean up types
mvadari May 8, 2025
39b64e8
respond to comments
mvadari May 8, 2025
4be6ff2
clean up DeliverMax typing
mvadari May 8, 2025
c17d40d
Merge branch 'main' into model-cleanup
mvadari Jul 3, 2025
0d54755
fix tests
mvadari Jul 3, 2025
bee3328
fix history
mvadari Jul 3, 2025
0059534
more cleanup
mvadari Jul 3, 2025
217f72a
Merge branch 'main' into model-cleanup
mvadari Jul 8, 2025
33a98b5
fix tests
mvadari Jul 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
"multisign",
"multisigned",
"multisigning",
"Permissioned",
"nftoken",
"permissioned",
"preauthorization",
"rippletest",
"secp256k1",
"Setf",
"Sidechains",
"Trustlines",
"xchain",
"xrplf"
],
Expand Down
1 change: 1 addition & 0 deletions packages/ripple-binary-codec/src/types/st-array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function isObjects(args): args is Array<JsonObject> {
Array.isArray(args) &&
args.every(
(arg) =>
arg != null &&
typeof arg === 'object' &&
Object.keys(arg).length === 1 &&
typeof Object.values(arg)[0] === 'object',
Expand Down
4 changes: 3 additions & 1 deletion packages/xrpl/src/models/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export interface MPTCurrency {

export type Currency = IssuedCurrency | MPTCurrency | XRP

export type XRPAmount = string

export interface IssuedCurrencyAmount extends IssuedCurrency {
value: string
}
Expand All @@ -29,7 +31,7 @@ export interface MPTAmount {
value: string
}

export type Amount = IssuedCurrencyAmount | string
export type Amount = IssuedCurrencyAmount | XRPAmount

export type ClawbackAmount = IssuedCurrencyAmount | MPTAmount

Expand Down
59 changes: 24 additions & 35 deletions packages/xrpl/src/models/transactions/AMMBid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { ValidationError } from '../../errors'
import { AuthAccount, Currency, IssuedCurrencyAmount } from '../common'

import {
Account,
BaseTransaction,
isAccount,
isAmount,
isArray,
isIssuedCurrency,
isCurrency,
isRecord,
validateBaseTransaction,
validateOptionalField,
validateRequiredField,
} from './common'

const MAX_AUTH_ACCOUNTS = 4
Expand Down Expand Up @@ -63,29 +67,10 @@ export interface AMMBid extends BaseTransaction {
export function validateAMMBid(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)

if (tx.Asset == null) {
throw new ValidationError('AMMBid: missing field Asset')
}

if (!isIssuedCurrency(tx.Asset)) {
throw new ValidationError('AMMBid: Asset must be a Currency')
}

if (tx.Asset2 == null) {
throw new ValidationError('AMMBid: missing field Asset2')
}

if (!isIssuedCurrency(tx.Asset2)) {
throw new ValidationError('AMMBid: Asset2 must be a Currency')
}

if (tx.BidMin != null && !isAmount(tx.BidMin)) {
throw new ValidationError('AMMBid: BidMin must be an Amount')
}

if (tx.BidMax != null && !isAmount(tx.BidMax)) {
throw new ValidationError('AMMBid: BidMax must be an Amount')
}
validateRequiredField(tx, 'Asset', isCurrency)
validateRequiredField(tx, 'Asset2', isCurrency)
validateOptionalField(tx, 'BidMin', isAmount)
validateOptionalField(tx, 'BidMax', isAmount)

if (tx.AuthAccounts != null) {
if (!isArray(tx.AuthAccounts)) {
Expand All @@ -103,28 +88,32 @@ export function validateAMMBid(tx: Record<string, unknown>): void {
}

function validateAuthAccounts(
senderAddress: string,
senderAddress: Account,
authAccounts: unknown[],
): boolean {
for (const authAccount of authAccounts) {
authAccounts.forEach((authAccount, index) => {
if (!isRecord(authAccount)) {
throw new ValidationError(`AMMBid: invalid AuthAccounts`)
throw new ValidationError(
`AMMBid: invalid field AuthAccounts[0], expected a valid Record`,
)
}
const paramName = `AuthAccounts[${index}].AuthAccount`
if (!isRecord(authAccount.AuthAccount)) {
throw new ValidationError(`AMMBid: invalid AuthAccounts`)
}
if (authAccount.AuthAccount.Account == null) {
throw new ValidationError(`AMMBid: invalid AuthAccounts`)
}
if (typeof authAccount.AuthAccount.Account !== 'string') {
throw new ValidationError(`AMMBid: invalid AuthAccounts`)
throw new ValidationError(
`AMMBid: invalid field ${paramName}, expected a valid Record`,
)
}
const authAccountInner = authAccount.AuthAccount
validateRequiredField(authAccountInner, 'Account', isAccount, {
paramName,
txType: 'AMMBid',
})
if (authAccount.AuthAccount.Account === senderAddress) {
throw new ValidationError(
`AMMBid: AuthAccounts must not include sender's address`,
)
}
}
})

return true
}
3 changes: 2 additions & 1 deletion packages/xrpl/src/models/transactions/AMMClawback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
BaseTransaction,
GlobalFlagsInterface,
isAccount,
isCurrency,
isIssuedCurrency,
isIssuedCurrencyAmount,
validateBaseTransaction,
Expand Down Expand Up @@ -97,7 +98,7 @@ export function validateAMMClawback(tx: Record<string, unknown>): void {
)
}

validateRequiredField(tx, 'Asset2', isIssuedCurrency)
validateRequiredField(tx, 'Asset2', isCurrency)

validateOptionalField(tx, 'Amount', isIssuedCurrencyAmount)

Expand Down
45 changes: 14 additions & 31 deletions packages/xrpl/src/models/transactions/AMMCreate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { ValidationError } from '../../errors'
import { Amount } from '../common'

import { BaseTransaction, isAmount, validateBaseTransaction } from './common'
import {
BaseTransaction,
isAmount,
isNumberWithBounds,
validateBaseTransaction,
validateRequiredField,
} from './common'

export const AMM_MAX_TRADING_FEE = 1000

Expand Down Expand Up @@ -48,33 +53,11 @@ export interface AMMCreate extends BaseTransaction {
export function validateAMMCreate(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)

if (tx.Amount == null) {
throw new ValidationError('AMMCreate: missing field Amount')
}

if (!isAmount(tx.Amount)) {
throw new ValidationError('AMMCreate: Amount must be an Amount')
}

if (tx.Amount2 == null) {
throw new ValidationError('AMMCreate: missing field Amount2')
}

if (!isAmount(tx.Amount2)) {
throw new ValidationError('AMMCreate: Amount2 must be an Amount')
}

if (tx.TradingFee == null) {
throw new ValidationError('AMMCreate: missing field TradingFee')
}

if (typeof tx.TradingFee !== 'number') {
throw new ValidationError('AMMCreate: TradingFee must be a number')
}

if (tx.TradingFee < 0 || tx.TradingFee > AMM_MAX_TRADING_FEE) {
throw new ValidationError(
`AMMCreate: TradingFee must be between 0 and ${AMM_MAX_TRADING_FEE}`,
)
}
validateRequiredField(tx, 'Amount', isAmount)
validateRequiredField(tx, 'Amount2', isAmount)
validateRequiredField(
tx,
'TradingFee',
isNumberWithBounds(0, AMM_MAX_TRADING_FEE),
)
}
21 changes: 4 additions & 17 deletions packages/xrpl/src/models/transactions/AMMDelete.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ValidationError } from '../../errors'
import { Currency } from '../common'

import {
BaseTransaction,
isIssuedCurrency,
isCurrency,
validateBaseTransaction,
validateRequiredField,
} from './common'

/**
Expand Down Expand Up @@ -41,19 +41,6 @@ export interface AMMDelete extends BaseTransaction {
export function validateAMMDelete(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)

if (tx.Asset == null) {
throw new ValidationError('AMMDelete: missing field Asset')
}

if (!isIssuedCurrency(tx.Asset)) {
throw new ValidationError('AMMDelete: Asset must be a Currency')
}

if (tx.Asset2 == null) {
throw new ValidationError('AMMDelete: missing field Asset2')
}

if (!isIssuedCurrency(tx.Asset2)) {
throw new ValidationError('AMMDelete: Asset2 must be a Currency')
}
validateRequiredField(tx, 'Asset', isCurrency)
validateRequiredField(tx, 'Asset2', isCurrency)
}
43 changes: 9 additions & 34 deletions packages/xrpl/src/models/transactions/AMMDeposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import {
BaseTransaction,
GlobalFlagsInterface,
isAmount,
isIssuedCurrency,
isCurrency,
isIssuedCurrencyAmount,
validateBaseTransaction,
validateOptionalField,
validateRequiredField,
} from './common'

/**
Expand Down Expand Up @@ -85,21 +87,12 @@ export interface AMMDeposit extends BaseTransaction {
export function validateAMMDeposit(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)

if (tx.Asset == null) {
throw new ValidationError('AMMDeposit: missing field Asset')
}

if (!isIssuedCurrency(tx.Asset)) {
throw new ValidationError('AMMDeposit: Asset must be a Currency')
}

if (tx.Asset2 == null) {
throw new ValidationError('AMMDeposit: missing field Asset2')
}

if (!isIssuedCurrency(tx.Asset2)) {
throw new ValidationError('AMMDeposit: Asset2 must be a Currency')
}
validateRequiredField(tx, 'Asset', isCurrency)
validateRequiredField(tx, 'Asset2', isCurrency)
validateOptionalField(tx, 'LPTokenOut', isIssuedCurrencyAmount)
validateOptionalField(tx, 'Amount', isAmount)
validateOptionalField(tx, 'Amount2', isAmount)
validateOptionalField(tx, 'EPrice', isAmount)

if (tx.Amount2 != null && tx.Amount == null) {
throw new ValidationError('AMMDeposit: must set Amount with Amount2')
Expand All @@ -110,22 +103,4 @@ export function validateAMMDeposit(tx: Record<string, unknown>): void {
'AMMDeposit: must set at least LPTokenOut or Amount',
)
}

if (tx.LPTokenOut != null && !isIssuedCurrencyAmount(tx.LPTokenOut)) {
throw new ValidationError(
'AMMDeposit: LPTokenOut must be an IssuedCurrencyAmount',
)
}

if (tx.Amount != null && !isAmount(tx.Amount)) {
throw new ValidationError('AMMDeposit: Amount 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)) {
throw new ValidationError('AMMDeposit: EPrice must be an Amount')
}
}
43 changes: 12 additions & 31 deletions packages/xrpl/src/models/transactions/AMMVote.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { ValidationError } from '../../errors'
import { Currency } from '../common'

import { AMM_MAX_TRADING_FEE } from './AMMCreate'
import {
BaseTransaction,
isIssuedCurrency,
isCurrency,
isNumber,
isNumberWithBounds,
validateBaseTransaction,
validateRequiredField,
} from './common'

/**
Expand Down Expand Up @@ -43,33 +45,12 @@ export interface AMMVote extends BaseTransaction {
export function validateAMMVote(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)

if (tx.Asset == null) {
throw new ValidationError('AMMVote: missing field Asset')
}

if (!isIssuedCurrency(tx.Asset)) {
throw new ValidationError('AMMVote: Asset must be a Currency')
}

if (tx.Asset2 == null) {
throw new ValidationError('AMMVote: missing field Asset2')
}

if (!isIssuedCurrency(tx.Asset2)) {
throw new ValidationError('AMMVote: Asset2 must be a Currency')
}

if (tx.TradingFee == null) {
throw new ValidationError('AMMVote: missing field TradingFee')
}

if (typeof tx.TradingFee !== 'number') {
throw new ValidationError('AMMVote: TradingFee must be a number')
}

if (tx.TradingFee < 0 || tx.TradingFee > AMM_MAX_TRADING_FEE) {
throw new ValidationError(
`AMMVote: TradingFee must be between 0 and ${AMM_MAX_TRADING_FEE}`,
)
}
validateRequiredField(tx, 'Asset', isCurrency)
validateRequiredField(tx, 'Asset2', isCurrency)
validateRequiredField(tx, 'TradingFee', isNumber)
validateRequiredField(
tx,
'TradingFee',
isNumberWithBounds(0, AMM_MAX_TRADING_FEE),
)
}
Loading
Loading