mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-29 00:25:48 +00:00
add AMMVote
This commit is contained in:
55
packages/xrpl/src/models/transactions/AMMVote.ts
Normal file
55
packages/xrpl/src/models/transactions/AMMVote.ts
Normal file
@@ -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<string, unknown>): 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')
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ export {
|
|||||||
export { AccountDelete } from './accountDelete'
|
export { AccountDelete } from './accountDelete'
|
||||||
export { AMMDeposit } from './AMMDeposit'
|
export { AMMDeposit } from './AMMDeposit'
|
||||||
export { AMMInstanceCreate } from './AMMInstanceCreate'
|
export { AMMInstanceCreate } from './AMMInstanceCreate'
|
||||||
|
export { AMMVote } from './AMMVote'
|
||||||
export { AMMWithdraw } from './AMMWithdraw'
|
export { AMMWithdraw } from './AMMWithdraw'
|
||||||
export { CheckCancel } from './checkCancel'
|
export { CheckCancel } from './checkCancel'
|
||||||
export { CheckCash } from './checkCash'
|
export { CheckCash } from './checkCash'
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
AMMInstanceCreate,
|
AMMInstanceCreate,
|
||||||
validateAMMInstanceCreate,
|
validateAMMInstanceCreate,
|
||||||
} from './AMMInstanceCreate'
|
} from './AMMInstanceCreate'
|
||||||
|
import { AMMVote, validateAMMVote } from './AMMVote'
|
||||||
import { AMMWithdraw, validateAMMWithdraw } from './AMMWithdraw'
|
import { AMMWithdraw, validateAMMWithdraw } from './AMMWithdraw'
|
||||||
import { CheckCancel, validateCheckCancel } from './checkCancel'
|
import { CheckCancel, validateCheckCancel } from './checkCancel'
|
||||||
import { CheckCash, validateCheckCash } from './checkCash'
|
import { CheckCash, validateCheckCash } from './checkCash'
|
||||||
@@ -65,6 +66,7 @@ export type Transaction =
|
|||||||
| AccountSet
|
| AccountSet
|
||||||
| AMMDeposit
|
| AMMDeposit
|
||||||
| AMMInstanceCreate
|
| AMMInstanceCreate
|
||||||
|
| AMMVote
|
||||||
| AMMWithdraw
|
| AMMWithdraw
|
||||||
| CheckCancel
|
| CheckCancel
|
||||||
| CheckCash
|
| CheckCash
|
||||||
@@ -132,6 +134,10 @@ export function validate(transaction: Record<string, unknown>): void {
|
|||||||
validateAMMInstanceCreate(tx)
|
validateAMMInstanceCreate(tx)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
case 'AMMVote':
|
||||||
|
validateAMMVote(tx)
|
||||||
|
break
|
||||||
|
|
||||||
case 'AMMWithdraw':
|
case 'AMMWithdraw':
|
||||||
validateAMMWithdraw(tx)
|
validateAMMWithdraw(tx)
|
||||||
break
|
break
|
||||||
|
|||||||
83
packages/xrpl/test/models/AMMVote.ts
Normal file
83
packages/xrpl/test/models/AMMVote.ts
Normal file
@@ -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',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user