Compare commits

..

5 Commits

Author SHA1 Message Date
Denis Angell
05bea18d66 Publish
- @transia/ripple-address-codec@4.2.6-alpha.0
 - @transia/ripple-binary-codec@1.4.4-alpha.0
 - @transia/ripple-keypairs@1.1.6-alpha.0
 - @transia/xrpl@2.7.1-alpha.0
2023-03-28 20:41:46 +00:00
Denis Angell
a2576ab74a package.json public access 2023-03-28 20:41:00 +00:00
Denis Angell
ef3f95475e update package.json for @transia 2023-03-28 20:38:36 +00:00
Denis Angell
25f267b81f Hooks (#12)
* feature `Hooks`

update definitions

add network id to base transaction

add set hook

update required

update definitions

make network id required

* update hook

update hook

add test and validation

add estimate fee func

fix estimated fee error

add hook utils

* update hookon transaction types

* add invoke tx

* ledger entry objects

* remove sugar export

* update definitions

* remove network id

* export transaction type map from definitions

* lint

* fix error

* fixup unit test

* update hook on calcaulator

* update tests

* update definitions

update definitions

update definitions
2023-03-28 20:33:42 +00:00
Denis Angell
4447a7af09 NetworkID (#11)
* update definitions

* add network id to base transaction

* update server info

* update base tx

* add network id to autofill

* update tests and fixtures

* network id option 3

fixup

add network id to server info fixture

fixup!

Revert "update tests and fixtures"

This reverts commit a5deee1274.

* update autofill

* update getNetworkID

* remove set network func

* fixup!

remove autoset network id

remove my mistake

fixup!
2023-03-28 20:27:38 +00:00
35 changed files with 93 additions and 2224 deletions

8
package-lock.json generated
View File

@@ -17141,7 +17141,7 @@
},
"packages/ripple-address-codec": {
"name": "@transia/ripple-address-codec",
"version": "4.2.6-tbeta.0",
"version": "4.2.6-alpha.0",
"license": "ISC",
"dependencies": {
"base-x": "^3.0.9",
@@ -17153,7 +17153,7 @@
},
"packages/ripple-binary-codec": {
"name": "@transia/ripple-binary-codec",
"version": "1.4.4-tbeta.0",
"version": "1.4.4-alpha.0",
"license": "ISC",
"dependencies": {
"assert": "^2.0.0",
@@ -17189,7 +17189,7 @@
},
"packages/ripple-keypairs": {
"name": "@transia/ripple-keypairs",
"version": "1.1.6-tbeta.0",
"version": "1.1.6-alpha.0",
"license": "ISC",
"dependencies": {
"bn.js": "^5.1.1",
@@ -17216,7 +17216,7 @@
},
"packages/xrpl": {
"name": "@transia/xrpl",
"version": "2.7.1-tbeta.0",
"version": "2.7.1-alpha.0",
"license": "ISC",
"dependencies": {
"bignumber.js": "^9.0.0",

View File

@@ -1,12 +1,12 @@
{
"name": "ripple-address-codec",
"version": "4.2.6-tbeta.0",
"version": "4.2.6-alpha.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "ripple-address-codec",
"version": "4.2.6-tbeta.0",
"version": "4.2.6-alpha.0",
"license": "ISC",
"dependencies": {
"base-x": "^3.0.9",

View File

@@ -1,6 +1,9 @@
{
"name": "@transia/ripple-address-codec",
"version": "4.2.6-tbeta.0",
"publishConfig": {
"access": "public"
},
"version": "4.2.6-alpha.0",
"description": "encodes/decodes base58 encoded XRP Ledger identifiers",
"files": [
"dist/*",
@@ -15,7 +18,7 @@
},
"repository": {
"type": "git",
"url": "git@github.com:Transia-RnD/xrpl.js/tree/transia-beta"
"url": "git@github.com/Transia-RnD/xrpl.js/tree/beta"
},
"prepublish": "tsc -b",
"prepublishOnly": "tslint -b ./ && jest",

View File

@@ -1,6 +1,9 @@
{
"name": "@transia/ripple-binary-codec",
"version": "1.4.4-tbeta.0",
"publishConfig": {
"access": "public"
},
"version": "1.4.4-alpha.0",
"description": "XRP Ledger binary codec",
"files": [
"dist/*",
@@ -28,7 +31,7 @@
},
"repository": {
"type": "git",
"url": "git@github.com:Transia-RnD/xrpl.js/tree/transia-beta"
"url": "git@github.com/Transia-RnD/xrpl.js/tree/beta"
},
"bugs": {
"url": "https://github.com/XRPLF/xrpl.js/issues"

View File

@@ -779,7 +779,7 @@
[
"LockCount",
{
"nth": 47,
"nth": 49,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
@@ -2315,10 +2315,10 @@
"temSEQ_AND_TICKET": -263,
"temBAD_NFTOKEN_TRANSFER_FEE": -262,
"temAMM_BAD_TOKENS": -261,
"temEQUAL_DOOR_ACCOUNTS": -260,
"temBAD_XCHAIN_PROOF": -259,
"temSIDECHAIN_BAD_ISSUES": -258,
"temSIDECHAIN_NONDOOR_OWNER": -257,
"temXCHAIN_EQUAL_DOOR_ACCOUNTS": -260,
"temXCHAIN_BAD_PROOF": -259,
"temXCHAIN_BRIDGE_BAD_ISSUES": -258,
"temXCHAIN_BRIDGE_NONDOOR_OWNER": -257,
"temXCHAIN_BRIDGE_BAD_MIN_ACCOUNT_CREATE_AMOUNT": -256,
"temXCHAIN_BRIDGE_BAD_REWARD_AMOUNT": -255,
"temXCHAIN_TOO_MANY_ATTESTATIONS": -254,
@@ -2359,7 +2359,8 @@
"terNO_RIPPLE": -90,
"terQUEUED": -89,
"terPRE_TICKET": -88,
"terNO_HOOK": -87,
"terNO_AMM": -87,
"terNO_HOOK": -86,
"tesSUCCESS": 0,

View File

@@ -5,7 +5,6 @@ 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'
@@ -25,7 +24,6 @@ const coreTypes: Record<string, typeof SerializedType> = {
Hash128,
Hash160,
Hash256,
Issue,
PathSet,
STArray,
STObject,

View File

@@ -1,96 +0,0 @@
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<T extends Issue | IssueObject>(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 }

View File

@@ -4448,213 +4448,6 @@
"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",
@@ -4670,4 +4463,4 @@
"transaction_hash": "DD33F6F0990754C962A7CCE62F332FF9C13939B03B864117F0BDA86B6E9B4F87"
}
}]
}
}

View File

@@ -1,6 +1,9 @@
{
"name": "@transia/ripple-keypairs",
"version": "1.1.6-tbeta.0",
"publishConfig": {
"access": "public"
},
"version": "1.1.6-alpha.0",
"description": "Cryptographic key pairs for the XRP Ledger",
"scripts": {
"build": "tsc -b",
@@ -25,7 +28,7 @@
},
"repository": {
"type": "git",
"url": "git@github.com:Transia-RnD/xrpl.js/tree/transia-beta"
"url": "git@github.com/Transia-RnD/xrpl.js/tree/beta"
},
"license": "ISC",
"prettier": "@xrplf/prettier-config",

View File

@@ -59,9 +59,6 @@ Wallet.fromMmnemonic()
* `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) transactions and requests as defined in XLS-30.
## 2.3.1 (2022-06-27)
### Fixed
* Signing tx with standard currency codes with lowercase and allowed symbols causing an error on decode.

View File

@@ -1,6 +1,9 @@
{
"name": "@transia/xrpl",
"version": "2.7.1-tbeta.0",
"publishConfig": {
"access": "public"
},
"version": "2.7.1-alpha.0",
"license": "ISC",
"description": "A TypeScript/JavaScript API for interacting with the XRP Ledger in Node.js and the browser",
"files": [
@@ -75,7 +78,7 @@
"prettier": "@xrplf/prettier-config",
"repository": {
"type": "git",
"url": "git@github.com:Transia-RnD/xrpl.js/tree/transia-beta"
"url": "git@github.com/Transia-RnD/xrpl.js/tree/beta"
},
"readmeFilename": "README.md",
"engines": {

View File

@@ -25,9 +25,6 @@ import {
AccountOffersResponse,
AccountTxRequest,
AccountTxResponse,
// AMM methods
AMMInfoRequest,
AMMInfoResponse,
GatewayBalancesRequest,
GatewayBalancesResponse,
NoRippleCheckRequest,
@@ -311,7 +308,6 @@ class Client extends EventEmitter {
): Promise<AccountObjectsResponse>
public async request(r: AccountOffersRequest): Promise<AccountOffersResponse>
public async request(r: AccountTxRequest): Promise<AccountTxResponse>
public async request(r: AMMInfoRequest): Promise<AMMInfoResponse>
public async request(r: BookOffersRequest): Promise<BookOffersResponse>
public async request(r: ChannelVerifyRequest): Promise<ChannelVerifyResponse>
public async request(

View File

@@ -4,7 +4,7 @@ interface XRP {
currency: 'XRP'
}
export interface IssuedCurrency {
interface IssuedCurrency {
currency: string
issuer: string
}

View File

@@ -1,147 +0,0 @@
import { Amount, Currency, 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'
/**
* 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
/**
* Specifies the other pool asset of the AMM instance.
* Both asset and asset2 must be defined to specify an AMM instance.
*/
asset2: Currency
}
interface AuthAccount {
account: string
}
interface VoteEntry {
account: string
trading_fee: number
vote_weight: number
}
/**
* Response expected from an {@link AMMInfoRequest}.
*
* @category Responses
*/
export interface AMMInfoResponse extends BaseResponse {
result: {
amm: {
/**
* The account that tracks the balance of LPTokens between the AMM instance via Trustline.
*/
amm_account: string
/**
* One of the pool assets (XRP or token) of the AMM instance.
*/
amount: Amount
/**
* The other pool asset of the AMM instance.
*/
amount2: Amount
/**
* (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
/**
* Details of the current owner of the auction slot.
*/
auction_slot?: {
/**
* 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.
*/
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.
*/
discounted_fee: 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
/**
* Total slot time of 24-hours is divided into 20 equal time intervals.
*/
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.
*/
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.
*/
trading_fee: number
/**
* Keeps a track of up to eight active votes for the instance.
*/
vote_slots?: VoteEntry[]
}
/**
* 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
}
}

View File

@@ -16,7 +16,6 @@ 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'
@@ -88,7 +87,6 @@ type Request =
| AccountObjectsRequest
| AccountOffersRequest
| AccountTxRequest
| AMMInfoRequest
| GatewayBalancesRequest
| NoRippleCheckRequest
// ledger methods
@@ -139,7 +137,6 @@ type Response =
| AccountObjectsResponse
| AccountOffersResponse
| AccountTxResponse
| AMMInfoResponse
| GatewayBalancesResponse
| NoRippleCheckResponse
// ledger methods
@@ -198,8 +195,6 @@ export {
AccountOffersResponse,
AccountTxRequest,
AccountTxResponse,
AMMInfoRequest,
AMMInfoResponse,
GatewayBalancesRequest,
GatewayBalancesResponse,
NoRippleCheckRequest,

View File

@@ -1,106 +0,0 @@
/* eslint-disable complexity -- required for validateAMMBid */
import { ValidationError } from '../../errors'
import { Amount, Currency } from '../common'
import {
BaseTransaction,
isAmount,
isCurrency,
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.
*
* 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'
/**
* Specifies one of the pool assets (XRP or token) of the AMM instance.
*/
Asset: Currency
/**
* Specifies the other pool asset of the AMM instance.
*/
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).
*/
BidMin?: Amount
/**
* This field represents the maximum price that the bidder wants to pay for the slot.
* It is specified in units of LPToken.
*/
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.
*/
AuthAccounts?: AuthAccount[]
}
/**
* 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<string, unknown>): void {
validateBaseTransaction(tx)
if (tx.Asset == null) {
throw new ValidationError('AMMBid: missing field Asset')
}
if (!isCurrency(tx.Asset)) {
throw new ValidationError('AMMBid: Asset must be an Issue')
}
if (tx.Asset2 == null) {
throw new ValidationError('AMMBid: missing field Asset2')
}
if (!isCurrency(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')
}
if (tx.BidMax != null && !isAmount(tx.BidMax)) {
throw new ValidationError('AMMBid: BidMax must be an Amount')
}
if (tx.AuthAccounts != null) {
if (!Array.isArray(tx.AuthAccounts)) {
throw new ValidationError(
`AMMBid: AuthAccounts must be an AuthAccount array`,
)
}
if (tx.AuthAccounts.length > MAX_AUTH_ACCOUNTS) {
throw new ValidationError(
`AMMBid: AuthAccounts length must not be greater than ${MAX_AUTH_ACCOUNTS}`,
)
}
}
}

View File

@@ -1,76 +0,0 @@
import { ValidationError } from '../../errors'
import { Amount } from '../common'
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.
*
* This allows for the creation of only one AMM instance per unique asset pair.
*/
export interface AMMCreate extends BaseTransaction {
TransactionType: 'AMMCreate'
/**
* Specifies one of the pool assets (XRP or token) of the AMM instance.
*/
Amount: Amount
/**
* Specifies the other pool asset of the AMM instance.
*/
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%.
*/
TradingFee: number
}
/**
* Verify the form and type of an AMMCreate at runtime.
*
* @param tx - An AMMCreate Transaction.
* @throws When the AMMCreate is Malformed.
*/
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}`,
)
}
}

View File

@@ -1,135 +0,0 @@
/* eslint-disable complexity -- required for validateAMMDeposit */
import { ValidationError } from '../../errors'
import { Amount, Currency, IssuedCurrencyAmount } from '../common'
import {
BaseTransaction,
GlobalFlags,
isAmount,
isCurrency,
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.
*
* The following are the recommended valid combinations:
* - LPTokenOut
* - Amount
* - Amount and Amount2
* - Amount and LPTokenOut
* - Amount and EPrice
*/
export interface AMMDeposit extends BaseTransaction {
TransactionType: 'AMMDeposit'
/**
* Specifies one of the pool assets (XRP or token) of the AMM instance.
*/
Asset: Currency
/**
* Specifies the other pool asset of the AMM instance.
*/
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.
*/
Amount?: Amount
/**
* Specifies the other pool asset of the AMM instance to deposit more of
* its value.
*/
Amount2?: Amount
/**
* Specifies the maximum effective-price that LPTokenOut can be traded out.
*/
EPrice?: Amount
}
/**
* 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<string, unknown>): void {
validateBaseTransaction(tx)
if (tx.Asset == null) {
throw new ValidationError('AMMDeposit: missing field Asset')
}
if (!isCurrency(tx.Asset)) {
throw new ValidationError('AMMDeposit: Asset must be an Issue')
}
if (tx.Asset2 == null) {
throw new ValidationError('AMMDeposit: missing field Asset2')
}
if (!isCurrency(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) {
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 LPTokenOut or Amount',
)
}
if (tx.LPTokenOut != null && !isIssuedCurrency(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')
}
}

View File

@@ -1,73 +0,0 @@
import { ValidationError } from '../../errors'
import { Currency } from '../common'
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.
*
* 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'
/**
* Specifies one of the pool assets (XRP or token) of the AMM instance.
*/
Asset: Currency
/**
* Specifies the other pool asset of the AMM instance.
*/
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.
*/
TradingFee: 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.Asset == null) {
throw new ValidationError('AMMVote: missing field Asset')
}
if (!isCurrency(tx.Asset)) {
throw new ValidationError('AMMVote: Asset must be an Issue')
}
if (tx.Asset2 == null) {
throw new ValidationError('AMMVote: missing field Asset2')
}
if (!isCurrency(tx.Asset2)) {
throw new ValidationError('AMMVote: Asset2 must be an Issue')
}
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}`,
)
}
}

View File

@@ -1,137 +0,0 @@
/* eslint-disable complexity -- required for validateAMMWithdraw */
import { ValidationError } from '../../errors'
import { Amount, Currency, IssuedCurrencyAmount } from '../common'
import {
BaseTransaction,
GlobalFlags,
isAmount,
isCurrency,
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
* of LPTokenIn.
*
* The following are the recommended valid combinations:
* - LPTokenIn
* - Amount
* - Amount and Amount2
* - Amount and LPTokenIn
* - Amount and EPrice
*/
export interface AMMWithdraw extends BaseTransaction {
TransactionType: 'AMMWithdraw'
/**
* Specifies one of the pool assets (XRP or token) of the AMM instance.
*/
Asset: Currency
/**
* Specifies the other pool asset of the AMM instance.
*/
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.
*/
Amount?: Amount
/**
* Specifies the other pool asset that the trader wants to remove.
*/
Amount2?: Amount
/**
* Specifies the effective-price of the token out after successful execution of
* the transaction.
*/
EPrice?: Amount
}
/**
* 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<string, unknown>): void {
validateBaseTransaction(tx)
if (tx.Asset == null) {
throw new ValidationError('AMMWithdraw: missing field Asset')
}
if (!isCurrency(tx.Asset)) {
throw new ValidationError('AMMWithdraw: Asset must be an Issue')
}
if (tx.Asset2 == null) {
throw new ValidationError('AMMWithdraw: missing field Asset2')
}
if (!isCurrency(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) {
throw new ValidationError('AMMWithdraw: must set Amount with EPrice')
}
if (tx.LPTokenIn != null && !isIssuedCurrency(tx.LPTokenIn)) {
throw new ValidationError(
'AMMWithdraw: LPTokenIn must be an IssuedCurrencyAmount',
)
}
if (tx.Amount != null && !isAmount(tx.Amount)) {
throw new ValidationError('AMMWithdraw: Amount 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)) {
throw new ValidationError('AMMWithdraw: EPrice must be an Amount')
}
}

View File

@@ -4,7 +4,7 @@
import { TRANSACTION_TYPES } from 'ripple-binary-codec'
import { ValidationError } from '../../errors'
import { Amount, Currency, IssuedCurrencyAmount, Memo, Signer } from '../common'
import { Amount, IssuedCurrencyAmount, Memo, Signer } from '../common'
import { onlyHasFields } from '../utils'
const MEMO_SIZE = 3
@@ -50,36 +50,17 @@ 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<string, unknown> {
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 isCurrency(input: unknown): input is Currency {
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 properly formed.
* @returns Whether the IssuedCurrencyAmount is malformed.
*/
export function isIssuedCurrency(
input: unknown,
@@ -97,7 +78,7 @@ 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 properly formed.
* @returns Whether the Amount is malformed.
*/
export function isAmount(amount: unknown): amount is Amount {
return typeof amount === 'string' || isIssuedCurrency(amount)
@@ -178,6 +159,9 @@ export interface BaseTransaction {
* account it says it is from.
*/
TxnSignature?: string
/**
* The network id of the transaction.
*/
NetworkID?: number
}

View File

@@ -7,19 +7,6 @@ export {
AccountSet,
} from './accountSet'
export { AccountDelete } from './accountDelete'
export { AMMBid } from './AMMBid'
export {
AMMDepositFlags,
AMMDepositFlagsInterface,
AMMDeposit,
} from './AMMDeposit'
export { AMMCreate } from './AMMCreate'
export { AMMVote } from './AMMVote'
export {
AMMWithdrawFlags,
AMMWithdrawFlagsInterface,
AMMWithdraw,
} from './AMMWithdraw'
export { CheckCancel } from './checkCancel'
export { CheckCash } from './checkCash'
export { CheckCreate } from './checkCreate'
@@ -60,12 +47,3 @@ export { SetHook } from './setHook'
export { SignerListSet } from './signerListSet'
export { TicketCreate } from './ticketCreate'
export { TrustSetFlagsInterface, TrustSetFlags, TrustSet } from './trustSet'
export {
URITokenMintFlagsInterface,
URITokenMintFlags,
URITokenMint,
} from './uriTokenMint'
export { URITokenBurn } from './uriTokenBurn'
export { URITokenCreateSellOffer } from './uriTokenCreateSellOffer'
export { URITokenBuy } from './uriTokenBuy'
export { URITokenCancelSellOffer } from './uriTokenCancelSellOffer'

View File

@@ -6,11 +6,6 @@ import { setTransactionFlagsToNumber } from '../utils/flags'
import { AccountDelete, validateAccountDelete } from './accountDelete'
import { AccountSet, validateAccountSet } from './accountSet'
import { AMMBid, validateAMMBid } from './AMMBid'
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'
import { CheckCash, validateCheckCash } from './checkCash'
import { CheckCreate, validateCheckCreate } from './checkCreate'
@@ -53,17 +48,6 @@ import { SetRegularKey, validateSetRegularKey } from './setRegularKey'
import { SignerListSet, validateSignerListSet } from './signerListSet'
import { TicketCreate, validateTicketCreate } from './ticketCreate'
import { TrustSet, validateTrustSet } from './trustSet'
import { URITokenBurn, validateURITokenBurn } from './uriTokenBurn'
import { URITokenBuy, validateURITokenBuy } from './uriTokenBuy'
import {
URITokenCancelSellOffer,
validateURITokenCancelSellOffer,
} from './uriTokenCancelSellOffer'
import {
URITokenCreateSellOffer,
validateURITokenCreateSellOffer,
} from './uriTokenCreateSellOffer'
import { URITokenMint, validateURITokenMint } from './uriTokenMint'
/**
* @category Transaction Models
@@ -71,11 +55,6 @@ import { URITokenMint, validateURITokenMint } from './uriTokenMint'
export type Transaction =
| AccountDelete
| AccountSet
| AMMBid
| AMMDeposit
| AMMCreate
| AMMVote
| AMMWithdraw
| CheckCancel
| CheckCash
| CheckCreate
@@ -99,11 +78,6 @@ export type Transaction =
| SignerListSet
| TicketCreate
| TrustSet
| URITokenBurn
| URITokenBuy
| URITokenCancelSellOffer
| URITokenMint
| URITokenCreateSellOffer
/**
* @category Transaction Models
@@ -140,26 +114,6 @@ export function validate(transaction: Record<string, unknown>): void {
validateAccountSet(tx)
break
case 'AMMBid':
validateAMMBid(tx)
break
case 'AMMDeposit':
validateAMMDeposit(tx)
break
case 'AMMCreate':
validateAMMCreate(tx)
break
case 'AMMVote':
validateAMMVote(tx)
break
case 'AMMWithdraw':
validateAMMWithdraw(tx)
break
case 'CheckCancel':
validateCheckCancel(tx)
break
@@ -252,26 +206,6 @@ export function validate(transaction: Record<string, unknown>): void {
validateTrustSet(tx)
break
case 'URITokenMint':
validateURITokenMint(tx)
break
case 'URITokenBurn':
validateURITokenBurn(tx)
break
case 'URITokenCreateSellOffer':
validateURITokenCreateSellOffer(tx)
break
case 'URITokenBuy':
validateURITokenBuy(tx)
break
case 'URITokenCancelSellOffer':
validateURITokenCancelSellOffer(tx)
break
default:
throw new ValidationError(
`Invalid field TransactionType: ${tx.TransactionType}`,

View File

@@ -1,60 +0,0 @@
import { ValidationError } from '../../errors'
import { BaseTransaction, validateBaseTransaction } from './common'
/**
* Map of flags to boolean values representing {@link URITokenBurn} transaction
* flags.
*
* @category Transaction Flags
*
* @example
* ```typescript
* const tx: URITokenBurn = {
* Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
* URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
* TransactionType: 'URITokenBurn',
* }
*
* // Autofill the tx to see how flags actually look compared to the interface usage.
* const autofilledTx = await client.autofill(tx)
* console.log(autofilledTx)
* // {
* // Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
* // URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
* // TransactionType: 'URITokenBurn',
* // Sequence: 21970384,
* // Fee: '12',
* // LastLedgerSequence: 21970404
* // }
* ```
*/
/**
* An URITokenBurn transaction is effectively a limit order . It defines an
* intent to exchange currencies, and creates an Offer object if not completely.
* Fulfilled when placed. Offers can be partially fulfilled.
*
* @category Transaction Models
*/
export interface URITokenBurn extends BaseTransaction {
TransactionType: 'URITokenBurn'
/**
* Identifies the URIToken object to be removed by the transaction.
*/
URITokenID: string
}
/**
* Verify the form and type of an URITokenBurn at runtime.
*
* @param tx - An URITokenBurn Transaction.
* @throws When the URITokenBurn is Malformed.
*/
export function validateURITokenBurn(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)
if (tx.URITokenID == null) {
throw new ValidationError('NFTokenBurn: missing field URITokenID')
}
}

View File

@@ -1,83 +0,0 @@
import { ValidationError } from '../../errors'
import { Amount } from '../common'
import { BaseTransaction, isAmount, validateBaseTransaction } from './common'
/**
* Map of flags to boolean values representing {@link URITokenBuy} transaction
* flags.
*
* @category Transaction Flags
*
* @example
* ```typescript
* const tx: URITokenBuy = {
* Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
* URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
* Amount: '1000000',
* TransactionType: 'URITokenBuy',
* }
*
* // Autofill the tx to see how flags actually look compared to the interface usage.
* const autofilledTx = await client.autofill(tx)
* console.log(autofilledTx)
* // {
* // Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
* // URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
* // Amount: '1000000',
* // TransactionType: 'URITokenBuy',
* // Sequence: 21970384,
* // Fee: '12',
* // LastLedgerSequence: 21970404
* // }
* ```
*/
/**
* An URITokenBuy transaction is effectively a limit order . It defines an
* intent to exchange currencies, and creates an Offer object if not completely.
* Fulfilled when placed. Offers can be partially fulfilled.
*
* @category Transaction Models
*/
export interface URITokenBuy extends BaseTransaction {
TransactionType: 'URITokenBuy'
/**
* Identifies the URITokenID of the NFToken object that the
* offer references.
*/
URITokenID: string
/**
* Indicates the amount expected or offered for the Token.
*
* The amount must be non-zero, except when this is a sell
* offer and the asset is XRP. This would indicate that the current
* owner of the token is giving it away free, either to anyone at all,
* or to the account identified by the Destination field.
*/
Amount: Amount
}
/**
* Verify the form and type of an URITokenBuy at runtime.
*
* @param tx - An URITokenBuy Transaction.
* @throws When the URITokenBuy is Malformed.
*/
export function validateURITokenBuy(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)
if (tx.Account === tx.Destination) {
throw new ValidationError(
'URITokenBuy: Destination and Account must not be equal',
)
}
if (tx.URITokenID == null) {
throw new ValidationError('URITokenBuy: missing field URITokenID')
}
if (!isAmount(tx.Amount)) {
throw new ValidationError('URITokenBuy: invalid Amount')
}
}

View File

@@ -1,65 +0,0 @@
import { ValidationError } from '../../errors'
import { BaseTransaction, validateBaseTransaction } from './common'
/**
* Map of flags to boolean values representing {@link URITokenCancelSellOffer} transaction
* flags.
*
* @category Transaction Flags
*
* @example
* ```typescript
* const tx: URITokenCancelSellOffer = {
* Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
* URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
* TransactionType: 'URITokenCancelSellOffer',
* }
*
* // Autofill the tx to see how flags actually look compared to the interface usage.
* const autofilledTx = await client.autofill(tx)
* console.log(autofilledTx)
* // {
* // Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
* // URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
* // TransactionType: 'URITokenCancelSellOffer',
* // Sequence: 21970384,
* // Fee: '12',
* // LastLedgerSequence: 21970404
* // }
* ```
*/
/**
* An URITokenCancelSellOffer transaction is effectively a limit order . It defines an
* intent to exchange currencies, and creates an Offer object if not completely.
* Fulfilled when placed. Offers can be partially fulfilled.
*
* @category Transaction Models
*/
export interface URITokenCancelSellOffer extends BaseTransaction {
TransactionType: 'URITokenCancelSellOffer'
/**
* Identifies the URITokenID of the NFToken object that the
* offer references.
*/
URITokenID: string
}
/**
* Verify the form and type of an URITokenCancelSellOffer at runtime.
*
* @param tx - An URITokenCancelSellOffer Transaction.
* @throws When the URITokenCancelSellOffer is Malformed.
*/
export function validateURITokenCancelSellOffer(
tx: Record<string, unknown>,
): void {
validateBaseTransaction(tx)
if (tx.URITokenID == null) {
throw new ValidationError(
'URITokenCancelSellOffer: missing field URITokenID',
)
}
}

View File

@@ -1,93 +0,0 @@
import { ValidationError } from '../../errors'
import { Amount } from '../common'
import { BaseTransaction, isAmount, validateBaseTransaction } from './common'
/**
* Map of flags to boolean values representing {@link URITokenCreateSellOffer} transaction
* flags.
*
* @category Transaction Flags
*
* @example
* ```typescript
* const tx: URITokenCreateSellOffer = {
* Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
* URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
* Amount: '1000000',
* TransactionType: 'URITokenCreateSellOffer',
* }
*
* // Autofill the tx to see how flags actually look compared to the interface usage.
* const autofilledTx = await client.autofill(tx)
* console.log(autofilledTx)
* // {
* // Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
* // URITokenID: '7AFCE32EBA8BD310CC2D00BE10B76E2183337EA20444D4580E4DBDB396C101FB',
* // Amount: '1000000',
* // TransactionType: 'URITokenCreateSellOffer',
* // Sequence: 21970384,
* // Fee: '12',
* // LastLedgerSequence: 21970404
* // }
* ```
*/
/**
* An URITokenCreateSellOffer transaction is effectively a limit order . It defines an
* intent to exchange currencies, and creates an Offer object if not completely.
* Fulfilled when placed. Offers can be partially fulfilled.
*
* @category Transaction Models
*/
export interface URITokenCreateSellOffer extends BaseTransaction {
TransactionType: 'URITokenCreateSellOffer'
/**
* Identifies the URITokenID of the NFToken object that the
* offer references.
*/
URITokenID: string
/**
* Indicates the amount expected or offered for the Token.
*
* The amount must be non-zero, except when this is a sell
* offer and the asset is XRP. This would indicate that the current
* owner of the token is giving it away free, either to anyone at all,
* or to the account identified by the Destination field.
*/
Amount: Amount
/**
* If present, indicates that this offer may only be
* accepted by the specified account. Attempts by other
* accounts to accept this offer MUST fail.
*/
Destination?: string
}
/**
* Verify the form and type of an URITokenCreateSellOffer at runtime.
*
* @param tx - An URITokenCreateSellOffer Transaction.
* @throws When the URITokenCreateSellOffer is Malformed.
*/
export function validateURITokenCreateSellOffer(
tx: Record<string, unknown>,
): void {
validateBaseTransaction(tx)
if (tx.Account === tx.Destination) {
throw new ValidationError(
'URITokenCreateSellOffer: Destination and Account must not be equal',
)
}
if (tx.URITokenID == null) {
throw new ValidationError(
'URITokenCreateSellOffer: missing field URITokenID',
)
}
if (!isAmount(tx.Amount)) {
throw new ValidationError('URITokenCreateSellOffer: invalid Amount')
}
}

View File

@@ -1,92 +0,0 @@
import { ValidationError } from '../../errors'
import { isHex } from '../utils'
import { BaseTransaction, GlobalFlags, validateBaseTransaction } from './common'
/**
* Transaction Flags for an URITokenMint Transaction.
*
* @category Transaction Flags
*/
export enum URITokenMintFlags {
/**
* If set, indicates that the minted token may be burned by the issuer even
* if the issuer does not currently hold the token. The current holder of
* the token may always burn it.
*/
tfBurnable = 0x00000001,
}
/**
* Map of flags to boolean values representing {@link URITokenMint} transaction
* flags.
*
* @category Transaction Flags
*
* @example
* ```typescript
* const tx: URITokenMint = {
* Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
* URI: '697066733A2F2F434944',
* TransactionType: 'URITokenMint',
* Flags: {
* tfBurnable: true,
* },
* }
*
* // Autofill the tx to see how flags actually look compared to the interface usage.
* const autofilledTx = await client.autofill(tx)
* console.log(autofilledTx)
* // {
* // Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
* // URI: '697066733A2F2F434944',
* // TransactionType: 'URITokenMint',
* // Flags: 0,
* // Sequence: 21970384,
* // Fee: '12',
* // LastLedgerSequence: 21970404
* // }
* ```
*/
export interface URITokenMintFlagsInterface extends GlobalFlags {
tfBurnable?: boolean
}
/**
* An URITokenMint transaction is effectively a limit order . It defines an
* intent to exchange currencies, and creates an Offer object if not completely.
* Fulfilled when placed. Offers can be partially fulfilled.
*
* @category Transaction Models
*/
export interface URITokenMint extends BaseTransaction {
TransactionType: 'URITokenMint'
Flags?: number | URITokenMintFlagsInterface
/**
* URI that points to the data and/or metadata associated with the NFT.
* This field need not be an HTTP or HTTPS URL; it could be an IPFS URI, a
* magnet link, immediate data encoded as an RFC2379 "data" URL, or even an
* opaque issuer-specific encoding. The URI is NOT checked for validity, but
* the field is limited to a maximum length of 256 bytes.
*
* This field must be hex-encoded. You can use `convertStringToHex` to
* convert this field to the proper encoding.
*/
URI: string
Digest?: string
}
/**
* Verify the form and type of an URITokenMint at runtime.
*
* @param tx - An URITokenMint Transaction.
* @throws When the URITokenMint is Malformed.
*/
export function validateURITokenMint(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)
if (typeof tx.URI === 'string' && !isHex(tx.URI)) {
throw new ValidationError('URITokenMint: URI must be in hex format')
}
}

View File

@@ -6,15 +6,22 @@ import {
AccountRootFlagsInterface,
AccountRootFlags,
} from '../ledger/AccountRoot'
import { AccountSetTfFlags } from '../transactions/accountSet'
import { AMMDepositFlags } from '../transactions/AMMDeposit'
import { AMMWithdrawFlags } from '../transactions/AMMWithdraw'
import {
AccountSetFlagsInterface,
AccountSetTfFlags,
} from '../transactions/accountSet'
import { GlobalFlags } from '../transactions/common'
import { OfferCreateFlags } from '../transactions/offerCreate'
import { PaymentFlags } from '../transactions/payment'
import { PaymentChannelClaimFlags } from '../transactions/paymentChannelClaim'
import {
OfferCreateFlagsInterface,
OfferCreateFlags,
} from '../transactions/offerCreate'
import { PaymentFlagsInterface, PaymentFlags } from '../transactions/payment'
import {
PaymentChannelClaimFlagsInterface,
PaymentChannelClaimFlags,
} from '../transactions/paymentChannelClaim'
import type { Transaction } from '../transactions/transaction'
import { TrustSetFlags } from '../transactions/trustSet'
import { TrustSetFlagsInterface, TrustSetFlags } from '../transactions/trustSet'
import { isFlagEnabled } from '.'
@@ -54,33 +61,55 @@ export function setTransactionFlagsToNumber(tx: Transaction): void {
switch (tx.TransactionType) {
case 'AccountSet':
tx.Flags = convertFlagsToNumber(tx.Flags, AccountSetTfFlags)
return
case 'AMMDeposit':
tx.Flags = convertFlagsToNumber(tx.Flags, AMMDepositFlags)
return
case 'AMMWithdraw':
tx.Flags = convertFlagsToNumber(tx.Flags, AMMWithdrawFlags)
tx.Flags = convertAccountSetFlagsToNumber(tx.Flags)
return
case 'OfferCreate':
tx.Flags = convertFlagsToNumber(tx.Flags, OfferCreateFlags)
tx.Flags = convertOfferCreateFlagsToNumber(tx.Flags)
return
case 'PaymentChannelClaim':
tx.Flags = convertFlagsToNumber(tx.Flags, PaymentChannelClaimFlags)
tx.Flags = convertPaymentChannelClaimFlagsToNumber(tx.Flags)
return
case 'Payment':
tx.Flags = convertFlagsToNumber(tx.Flags, PaymentFlags)
tx.Flags = convertPaymentTransactionFlagsToNumber(tx.Flags)
return
case 'TrustSet':
tx.Flags = convertFlagsToNumber(tx.Flags, TrustSetFlags)
tx.Flags = convertTrustSetFlagsToNumber(tx.Flags)
return
default:
tx.Flags = 0
}
}
function convertAccountSetFlagsToNumber(
flags: AccountSetFlagsInterface,
): number {
return reduceFlags(flags, AccountSetTfFlags)
}
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 convertFlagsToNumber(flags: GlobalFlags, flagEnum: any): number {
function reduceFlags(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) {

View File

@@ -143,7 +143,7 @@ async function setNextValidSequenceNumber(
tx.Sequence = data.result.account_data.Sequence
}
async function fetchOwnerReserveFee(client: Client): Promise<BigNumber> {
async function fetchAccountDeleteFee(client: Client): Promise<BigNumber> {
const response = await client.request({ command: 'server_state' })
const fee = response.result.state.validated_ledger?.reserve_inc
@@ -175,11 +175,9 @@ async function calculateFeePerTransactionType(
baseFee = product.dp(0, BigNumber.ROUND_CEIL)
}
if (
tx.TransactionType === 'AccountDelete' ||
tx.TransactionType === 'AMMCreate'
) {
baseFee = await fetchOwnerReserveFee(client)
// AccountDelete Transaction
if (tx.TransactionType === 'AccountDelete') {
baseFee = await fetchAccountDeleteFee(client)
}
/*

View File

@@ -1,123 +0,0 @@
import { assert } from 'chai'
import { validate, ValidationError } from '../../src'
/**
* 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',
Asset: {
currency: 'XRP',
},
Asset2: {
currency: 'ETH',
issuer: 'rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd',
},
BidMin: '5',
BidMax: '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 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(
() => validate(bid),
ValidationError,
'AMMBid: BidMin must be an Amount',
)
})
it(`throws w/ BidMax must be an Amount`, function () {
bid.BidMax = 10
assert.throws(
() => validate(bid),
ValidationError,
'AMMBid: BidMax 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',
)
})
})

View File

@@ -1,103 +0,0 @@
import { assert } from 'chai'
import { validate, ValidationError } from '../../src'
/**
* 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 1000`, function () {
ammCreate.TradingFee = 1001
assert.throws(
() => validate(ammCreate),
ValidationError,
`AMMCreate: TradingFee must be between 0 and 1000`,
)
})
it(`throws when TradingFee is a negative number`, function () {
ammCreate.TradingFee = -1
assert.throws(
() => validate(ammCreate),
ValidationError,
`AMMCreate: TradingFee must be between 0 and 1000`,
)
})
})

View File

@@ -1,175 +0,0 @@
/* eslint-disable no-bitwise -- bitwise necessary for enabling flags */
import { assert } from 'chai'
import { AMMDepositFlags, validate, ValidationError } from '../../src'
/**
* AMMDeposit Transaction Verification Testing.
*
* Providing runtime verification testing for each specific transaction type.
*/
describe('AMMDeposit', function () {
const LPTokenOut = {
currency: 'B3813FCAB4EE68B3D0D735D6849465A9113EE048',
issuer: 'rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg',
value: '1000',
}
let deposit
beforeEach(function () {
deposit = {
TransactionType: 'AMMDeposit',
Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
Asset: {
currency: 'XRP',
},
Asset2: {
currency: 'ETH',
issuer: 'rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd',
},
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 = {
currency: 'ETH',
issuer: 'rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd',
value: '2.5',
}
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))
})
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),
ValidationError,
'AMMDeposit: must set at least LPTokenOut or Amount',
)
})
it(`throws w/ must set Amount with Amount2`, function () {
deposit.Amount2 = {
currency: 'ETH',
issuer: 'rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd',
value: '2.5',
}
assert.throws(
() => validate(deposit),
ValidationError,
'AMMDeposit: must set Amount with Amount2',
)
})
it(`throws w/ must set Amount with EPrice`, function () {
deposit.EPrice = '25'
assert.throws(
() => validate(deposit),
ValidationError,
'AMMDeposit: must set Amount with EPrice',
)
})
it(`throws w/ LPTokenOut must be an IssuedCurrencyAmount`, function () {
deposit.LPTokenOut = 1234
assert.throws(
() => validate(deposit),
ValidationError,
'AMMDeposit: LPTokenOut must be an IssuedCurrencyAmount',
)
})
it(`throws w/ Amount must be an Amount`, function () {
deposit.Amount = 1234
assert.throws(
() => validate(deposit),
ValidationError,
'AMMDeposit: Amount must be an Amount',
)
})
it(`throws w/ Amount2 must be an Amount`, function () {
deposit.Amount = '1000'
deposit.Amount2 = 1234
assert.throws(
() => validate(deposit),
ValidationError,
'AMMDeposit: Amount2 must be an Amount',
)
})
it(`throws w/ EPrice must be an Amount`, function () {
deposit.Amount = '1000'
deposit.EPrice = 1234
assert.throws(
() => validate(deposit),
ValidationError,
'AMMDeposit: EPrice must be an Amount',
)
})
})

View File

@@ -1,104 +0,0 @@
import { assert } from 'chai'
import { validate, ValidationError } from '../../src'
/**
* AMMVote Transaction Verification Testing.
*
* Providing runtime verification testing for each specific transaction type.
*/
describe('AMMVote', function () {
let vote
beforeEach(function () {
vote = {
TransactionType: 'AMMVote',
Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
Asset: {
currency: 'XRP',
},
Asset2: {
currency: 'ETH',
issuer: 'rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd',
},
TradingFee: 25,
Sequence: 1337,
} as any
})
it(`verifies valid 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(
() => validate(vote),
ValidationError,
'AMMVote: missing field TradingFee',
)
})
it(`throws w/ TradingFee must be a number`, function () {
vote.TradingFee = '25'
assert.throws(
() => validate(vote),
ValidationError,
'AMMVote: TradingFee must be a number',
)
})
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',
)
})
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',
)
})
})

View File

@@ -1,178 +0,0 @@
/* eslint-disable no-bitwise -- bitwise necessary for enabling flags */
import { assert } from 'chai'
import { AMMWithdrawFlags, validate, ValidationError } from '../../src'
/**
* AMMWithdraw Transaction Verification Testing.
*
* Providing runtime verification testing for each specific transaction type.
*/
describe('AMMWithdraw', function () {
const LPTokenIn = {
currency: 'B3813FCAB4EE68B3D0D735D6849465A9113EE048',
issuer: 'rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg',
value: '1000',
}
let withdraw
beforeEach(function () {
withdraw = {
TransactionType: 'AMMWithdraw',
Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
Asset: {
currency: 'XRP',
},
Asset2: {
currency: 'ETH',
issuer: 'rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd',
},
Sequence: 1337,
Flags: 0,
} as any
})
it(`verifies valid AMMWithdraw with LPTokenIn`, function () {
withdraw.LPTokenIn = LPTokenIn
withdraw.Flags |= AMMWithdrawFlags.tfLPToken
assert.doesNotThrow(() => validate(withdraw))
})
it(`verifies valid AMMWithdraw with Amount`, function () {
withdraw.Amount = '1000'
withdraw.Flags |= AMMWithdrawFlags.tfSingleAsset
assert.doesNotThrow(() => validate(withdraw))
})
it(`verifies valid AMMWithdraw with Amount and Amount2`, function () {
withdraw.Amount = '1000'
withdraw.Amount2 = {
currency: 'ETH',
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))
})
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(
() => 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 Amount with Amount2`, function () {
withdraw.Amount2 = {
currency: 'ETH',
issuer: 'rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd',
value: '2.5',
}
assert.throws(
() => validate(withdraw),
ValidationError,
'AMMWithdraw: must set Amount with Amount2',
)
})
it(`throws w/ must set Amount with EPrice`, function () {
withdraw.EPrice = '25'
assert.throws(
() => validate(withdraw),
ValidationError,
'AMMWithdraw: must set Amount with EPrice',
)
})
it(`throws w/ LPTokenIn must be an IssuedCurrencyAmount`, function () {
withdraw.LPTokenIn = 1234
assert.throws(
() => validate(withdraw),
ValidationError,
'AMMWithdraw: LPTokenIn must be an IssuedCurrencyAmount',
)
})
it(`throws w/ Amount must be an Amount`, function () {
withdraw.Amount = 1234
assert.throws(
() => validate(withdraw),
ValidationError,
'AMMWithdraw: Amount must be an Amount',
)
})
it(`throws w/ Amount2 must be an Amount`, function () {
withdraw.Amount = '1000'
withdraw.Amount2 = 1234
assert.throws(
() => validate(withdraw),
ValidationError,
'AMMWithdraw: Amount2 must be an Amount',
)
})
it(`throws w/ EPrice must be an Amount`, function () {
withdraw.Amount = '1000'
withdraw.EPrice = 1234
assert.throws(
() => validate(withdraw),
ValidationError,
'AMMWithdraw: EPrice must be an Amount',
)
})
})