xrpl 2.10.0 → 2.12.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/xrpl-latest-min.js +1 -1
- package/build/xrpl-latest-min.js.map +1 -1
- package/build/xrpl-latest.js +1308 -33
- package/build/xrpl-latest.js.map +1 -1
- package/dist/npm/Wallet/walletFromSecretNumbers.d.ts +7 -0
- package/dist/npm/Wallet/walletFromSecretNumbers.d.ts.map +1 -0
- package/dist/npm/Wallet/walletFromSecretNumbers.js +27 -0
- package/dist/npm/Wallet/walletFromSecretNumbers.js.map +1 -0
- package/dist/npm/client/index.d.ts +2 -1
- package/dist/npm/client/index.d.ts.map +1 -1
- package/dist/npm/client/index.js.map +1 -1
- package/dist/npm/index.d.ts +1 -0
- package/dist/npm/index.d.ts.map +1 -1
- package/dist/npm/index.js +3 -1
- package/dist/npm/index.js.map +1 -1
- package/dist/npm/models/common/index.d.ts +11 -0
- package/dist/npm/models/common/index.d.ts.map +1 -1
- package/dist/npm/models/ledger/AMM.d.ts +27 -0
- package/dist/npm/models/ledger/AMM.d.ts.map +1 -0
- package/dist/npm/models/ledger/AMM.js +3 -0
- package/dist/npm/models/ledger/AMM.js.map +1 -0
- package/dist/npm/models/ledger/AccountRoot.d.ts +2 -0
- package/dist/npm/models/ledger/AccountRoot.d.ts.map +1 -1
- package/dist/npm/models/ledger/AccountRoot.js +1 -0
- package/dist/npm/models/ledger/AccountRoot.js.map +1 -1
- package/dist/npm/models/ledger/Bridge.d.ts +17 -0
- package/dist/npm/models/ledger/Bridge.d.ts.map +1 -0
- package/dist/npm/models/ledger/Bridge.js +3 -0
- package/dist/npm/models/ledger/Bridge.js.map +1 -0
- package/dist/npm/models/ledger/LedgerEntry.d.ts +5 -1
- package/dist/npm/models/ledger/LedgerEntry.d.ts.map +1 -1
- package/dist/npm/models/ledger/XChainOwnedClaimID.d.ts +16 -0
- package/dist/npm/models/ledger/XChainOwnedClaimID.d.ts.map +1 -0
- package/dist/npm/models/ledger/XChainOwnedClaimID.js +3 -0
- package/dist/npm/models/ledger/XChainOwnedClaimID.js.map +1 -0
- package/dist/npm/models/ledger/XChainOwnedCreateAccountClaimID.d.ts +14 -0
- package/dist/npm/models/ledger/XChainOwnedCreateAccountClaimID.d.ts.map +1 -0
- package/dist/npm/models/ledger/XChainOwnedCreateAccountClaimID.js +3 -0
- package/dist/npm/models/ledger/XChainOwnedCreateAccountClaimID.js.map +1 -0
- package/dist/npm/models/ledger/index.d.ts +4 -1
- package/dist/npm/models/ledger/index.d.ts.map +1 -1
- package/dist/npm/models/ledger/index.js.map +1 -1
- package/dist/npm/models/methods/accountObjects.d.ts +3 -3
- package/dist/npm/models/methods/accountObjects.d.ts.map +1 -1
- package/dist/npm/models/methods/ammInfo.d.ts +39 -0
- package/dist/npm/models/methods/ammInfo.d.ts.map +1 -0
- package/dist/npm/models/methods/ammInfo.js +3 -0
- package/dist/npm/models/methods/ammInfo.js.map +1 -0
- package/dist/npm/models/methods/index.d.ts +4 -3
- package/dist/npm/models/methods/index.d.ts.map +1 -1
- package/dist/npm/models/methods/ledgerEntry.d.ts +27 -0
- package/dist/npm/models/methods/ledgerEntry.d.ts.map +1 -1
- package/dist/npm/models/transactions/AMMBid.d.ts +12 -0
- package/dist/npm/models/transactions/AMMBid.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMBid.js +56 -0
- package/dist/npm/models/transactions/AMMBid.js.map +1 -0
- package/dist/npm/models/transactions/AMMCreate.d.ts +11 -0
- package/dist/npm/models/transactions/AMMCreate.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMCreate.js +32 -0
- package/dist/npm/models/transactions/AMMCreate.js.map +1 -0
- package/dist/npm/models/transactions/AMMDelete.d.ts +9 -0
- package/dist/npm/models/transactions/AMMDelete.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMDelete.js +22 -0
- package/dist/npm/models/transactions/AMMDelete.js.map +1 -0
- package/dist/npm/models/transactions/AMMDeposit.d.ts +27 -0
- package/dist/npm/models/transactions/AMMDeposit.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMDeposit.js +51 -0
- package/dist/npm/models/transactions/AMMDeposit.js.map +1 -0
- package/dist/npm/models/transactions/AMMVote.d.ts +10 -0
- package/dist/npm/models/transactions/AMMVote.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMVote.js +32 -0
- package/dist/npm/models/transactions/AMMVote.js.map +1 -0
- package/dist/npm/models/transactions/AMMWithdraw.d.ts +31 -0
- package/dist/npm/models/transactions/AMMWithdraw.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMWithdraw.js +50 -0
- package/dist/npm/models/transactions/AMMWithdraw.js.map +1 -0
- package/dist/npm/models/transactions/XChainAccountCreateCommit.d.ts +11 -0
- package/dist/npm/models/transactions/XChainAccountCreateCommit.d.ts.map +1 -0
- package/dist/npm/models/transactions/XChainAccountCreateCommit.js +35 -0
- package/dist/npm/models/transactions/XChainAccountCreateCommit.js.map +1 -0
- package/dist/npm/models/transactions/XChainAddAccountCreateAttestation.d.ts +18 -0
- package/dist/npm/models/transactions/XChainAddAccountCreateAttestation.d.ts.map +1 -0
- package/dist/npm/models/transactions/XChainAddAccountCreateAttestation.js +77 -0
- package/dist/npm/models/transactions/XChainAddAccountCreateAttestation.js.map +1 -0
- package/dist/npm/models/transactions/XChainAddClaimAttestation.d.ts +17 -0
- package/dist/npm/models/transactions/XChainAddClaimAttestation.d.ts.map +1 -0
- package/dist/npm/models/transactions/XChainAddClaimAttestation.js +68 -0
- package/dist/npm/models/transactions/XChainAddClaimAttestation.js.map +1 -0
- package/dist/npm/models/transactions/XChainClaim.d.ts +12 -0
- package/dist/npm/models/transactions/XChainClaim.d.ts.map +1 -0
- package/dist/npm/models/transactions/XChainClaim.js +39 -0
- package/dist/npm/models/transactions/XChainClaim.js.map +1 -0
- package/dist/npm/models/transactions/XChainCommit.d.ts +11 -0
- package/dist/npm/models/transactions/XChainCommit.d.ts.map +1 -0
- package/dist/npm/models/transactions/XChainCommit.js +33 -0
- package/dist/npm/models/transactions/XChainCommit.js.map +1 -0
- package/dist/npm/models/transactions/XChainCreateBridge.d.ts +10 -0
- package/dist/npm/models/transactions/XChainCreateBridge.d.ts.map +1 -0
- package/dist/npm/models/transactions/XChainCreateBridge.js +26 -0
- package/dist/npm/models/transactions/XChainCreateBridge.js.map +1 -0
- package/dist/npm/models/transactions/XChainCreateClaimID.d.ts +10 -0
- package/dist/npm/models/transactions/XChainCreateClaimID.d.ts.map +1 -0
- package/dist/npm/models/transactions/XChainCreateClaimID.js +28 -0
- package/dist/npm/models/transactions/XChainCreateClaimID.js.map +1 -0
- package/dist/npm/models/transactions/XChainModifyBridge.d.ts +17 -0
- package/dist/npm/models/transactions/XChainModifyBridge.d.ts.map +1 -0
- package/dist/npm/models/transactions/XChainModifyBridge.js +27 -0
- package/dist/npm/models/transactions/XChainModifyBridge.js.map +1 -0
- package/dist/npm/models/transactions/common.d.ts +3 -1
- package/dist/npm/models/transactions/common.d.ts.map +1 -1
- package/dist/npm/models/transactions/common.js +22 -1
- package/dist/npm/models/transactions/common.js.map +1 -1
- package/dist/npm/models/transactions/index.d.ts +15 -1
- package/dist/npm/models/transactions/index.d.ts.map +1 -1
- package/dist/npm/models/transactions/index.js +7 -1
- package/dist/npm/models/transactions/index.js.map +1 -1
- package/dist/npm/models/transactions/transaction.d.ts +15 -1
- package/dist/npm/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/models/transactions/transaction.js +56 -0
- package/dist/npm/models/transactions/transaction.js.map +1 -1
- package/dist/npm/models/utils/flags.d.ts.map +1 -1
- package/dist/npm/models/utils/flags.js +18 -21
- package/dist/npm/models/utils/flags.js.map +1 -1
- package/dist/npm/snippets/src/bridgeTransfer.d.ts +2 -0
- package/dist/npm/snippets/src/bridgeTransfer.d.ts.map +1 -0
- package/dist/npm/snippets/src/bridgeTransfer.js +124 -0
- package/dist/npm/snippets/src/bridgeTransfer.js.map +1 -0
- package/dist/npm/snippets/tsconfig.tsbuildinfo +1 -1
- package/dist/npm/src/Wallet/walletFromSecretNumbers.d.ts +7 -0
- package/dist/npm/src/Wallet/walletFromSecretNumbers.d.ts.map +1 -0
- package/dist/npm/src/Wallet/walletFromSecretNumbers.js +27 -0
- package/dist/npm/src/Wallet/walletFromSecretNumbers.js.map +1 -0
- package/dist/npm/src/client/index.d.ts +2 -1
- package/dist/npm/src/client/index.d.ts.map +1 -1
- package/dist/npm/src/client/index.js.map +1 -1
- package/dist/npm/src/index.d.ts +1 -0
- package/dist/npm/src/index.d.ts.map +1 -1
- package/dist/npm/src/index.js +3 -1
- package/dist/npm/src/index.js.map +1 -1
- package/dist/npm/src/models/common/index.d.ts +11 -0
- package/dist/npm/src/models/common/index.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/AMM.d.ts +27 -0
- package/dist/npm/src/models/ledger/AMM.d.ts.map +1 -0
- package/dist/npm/src/models/ledger/AMM.js +3 -0
- package/dist/npm/src/models/ledger/AMM.js.map +1 -0
- package/dist/npm/src/models/ledger/AccountRoot.d.ts +2 -0
- package/dist/npm/src/models/ledger/AccountRoot.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/AccountRoot.js +1 -0
- package/dist/npm/src/models/ledger/AccountRoot.js.map +1 -1
- package/dist/npm/src/models/ledger/Bridge.d.ts +17 -0
- package/dist/npm/src/models/ledger/Bridge.d.ts.map +1 -0
- package/dist/npm/src/models/ledger/Bridge.js +3 -0
- package/dist/npm/src/models/ledger/Bridge.js.map +1 -0
- package/dist/npm/src/models/ledger/LedgerEntry.d.ts +5 -1
- package/dist/npm/src/models/ledger/LedgerEntry.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/XChainOwnedClaimID.d.ts +16 -0
- package/dist/npm/src/models/ledger/XChainOwnedClaimID.d.ts.map +1 -0
- package/dist/npm/src/models/ledger/XChainOwnedClaimID.js +3 -0
- package/dist/npm/src/models/ledger/XChainOwnedClaimID.js.map +1 -0
- package/dist/npm/src/models/ledger/XChainOwnedCreateAccountClaimID.d.ts +14 -0
- package/dist/npm/src/models/ledger/XChainOwnedCreateAccountClaimID.d.ts.map +1 -0
- package/dist/npm/src/models/ledger/XChainOwnedCreateAccountClaimID.js +3 -0
- package/dist/npm/src/models/ledger/XChainOwnedCreateAccountClaimID.js.map +1 -0
- package/dist/npm/src/models/ledger/index.d.ts +4 -1
- package/dist/npm/src/models/ledger/index.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/index.js.map +1 -1
- package/dist/npm/src/models/methods/accountObjects.d.ts +3 -3
- package/dist/npm/src/models/methods/accountObjects.d.ts.map +1 -1
- package/dist/npm/src/models/methods/ammInfo.d.ts +39 -0
- package/dist/npm/src/models/methods/ammInfo.d.ts.map +1 -0
- package/dist/npm/src/models/methods/ammInfo.js +3 -0
- package/dist/npm/src/models/methods/ammInfo.js.map +1 -0
- package/dist/npm/src/models/methods/index.d.ts +4 -3
- package/dist/npm/src/models/methods/index.d.ts.map +1 -1
- package/dist/npm/src/models/methods/ledgerEntry.d.ts +27 -0
- package/dist/npm/src/models/methods/ledgerEntry.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/AMMBid.d.ts +12 -0
- package/dist/npm/src/models/transactions/AMMBid.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMBid.js +56 -0
- package/dist/npm/src/models/transactions/AMMBid.js.map +1 -0
- package/dist/npm/src/models/transactions/AMMCreate.d.ts +11 -0
- package/dist/npm/src/models/transactions/AMMCreate.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMCreate.js +32 -0
- package/dist/npm/src/models/transactions/AMMCreate.js.map +1 -0
- package/dist/npm/src/models/transactions/AMMDelete.d.ts +9 -0
- package/dist/npm/src/models/transactions/AMMDelete.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMDelete.js +22 -0
- package/dist/npm/src/models/transactions/AMMDelete.js.map +1 -0
- package/dist/npm/src/models/transactions/AMMDeposit.d.ts +27 -0
- package/dist/npm/src/models/transactions/AMMDeposit.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMDeposit.js +51 -0
- package/dist/npm/src/models/transactions/AMMDeposit.js.map +1 -0
- package/dist/npm/src/models/transactions/AMMVote.d.ts +10 -0
- package/dist/npm/src/models/transactions/AMMVote.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMVote.js +32 -0
- package/dist/npm/src/models/transactions/AMMVote.js.map +1 -0
- package/dist/npm/src/models/transactions/AMMWithdraw.d.ts +31 -0
- package/dist/npm/src/models/transactions/AMMWithdraw.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMWithdraw.js +50 -0
- package/dist/npm/src/models/transactions/AMMWithdraw.js.map +1 -0
- package/dist/npm/src/models/transactions/XChainAccountCreateCommit.d.ts +11 -0
- package/dist/npm/src/models/transactions/XChainAccountCreateCommit.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/XChainAccountCreateCommit.js +35 -0
- package/dist/npm/src/models/transactions/XChainAccountCreateCommit.js.map +1 -0
- package/dist/npm/src/models/transactions/XChainAddAccountCreateAttestation.d.ts +18 -0
- package/dist/npm/src/models/transactions/XChainAddAccountCreateAttestation.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/XChainAddAccountCreateAttestation.js +77 -0
- package/dist/npm/src/models/transactions/XChainAddAccountCreateAttestation.js.map +1 -0
- package/dist/npm/src/models/transactions/XChainAddClaimAttestation.d.ts +17 -0
- package/dist/npm/src/models/transactions/XChainAddClaimAttestation.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/XChainAddClaimAttestation.js +68 -0
- package/dist/npm/src/models/transactions/XChainAddClaimAttestation.js.map +1 -0
- package/dist/npm/src/models/transactions/XChainClaim.d.ts +12 -0
- package/dist/npm/src/models/transactions/XChainClaim.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/XChainClaim.js +39 -0
- package/dist/npm/src/models/transactions/XChainClaim.js.map +1 -0
- package/dist/npm/src/models/transactions/XChainCommit.d.ts +11 -0
- package/dist/npm/src/models/transactions/XChainCommit.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/XChainCommit.js +33 -0
- package/dist/npm/src/models/transactions/XChainCommit.js.map +1 -0
- package/dist/npm/src/models/transactions/XChainCreateBridge.d.ts +10 -0
- package/dist/npm/src/models/transactions/XChainCreateBridge.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/XChainCreateBridge.js +26 -0
- package/dist/npm/src/models/transactions/XChainCreateBridge.js.map +1 -0
- package/dist/npm/src/models/transactions/XChainCreateClaimID.d.ts +10 -0
- package/dist/npm/src/models/transactions/XChainCreateClaimID.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/XChainCreateClaimID.js +28 -0
- package/dist/npm/src/models/transactions/XChainCreateClaimID.js.map +1 -0
- package/dist/npm/src/models/transactions/XChainModifyBridge.d.ts +17 -0
- package/dist/npm/src/models/transactions/XChainModifyBridge.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/XChainModifyBridge.js +27 -0
- package/dist/npm/src/models/transactions/XChainModifyBridge.js.map +1 -0
- package/dist/npm/src/models/transactions/common.d.ts +3 -1
- package/dist/npm/src/models/transactions/common.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/common.js +22 -1
- package/dist/npm/src/models/transactions/common.js.map +1 -1
- package/dist/npm/src/models/transactions/index.d.ts +15 -1
- package/dist/npm/src/models/transactions/index.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/index.js +7 -1
- package/dist/npm/src/models/transactions/index.js.map +1 -1
- package/dist/npm/src/models/transactions/transaction.d.ts +15 -1
- package/dist/npm/src/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/transaction.js +56 -0
- package/dist/npm/src/models/transactions/transaction.js.map +1 -1
- package/dist/npm/src/models/utils/flags.d.ts.map +1 -1
- package/dist/npm/src/models/utils/flags.js +18 -21
- package/dist/npm/src/models/utils/flags.js.map +1 -1
- package/dist/npm/src/sugar/autofill.d.ts.map +1 -1
- package/dist/npm/src/sugar/autofill.js +4 -3
- package/dist/npm/src/sugar/autofill.js.map +1 -1
- package/dist/npm/sugar/autofill.d.ts.map +1 -1
- package/dist/npm/sugar/autofill.js +4 -3
- package/dist/npm/sugar/autofill.js.map +1 -1
- package/package.json +8 -6
- package/src/ECDSA.ts +6 -0
- package/src/Wallet/defaultFaucets.ts +82 -0
- package/src/Wallet/fundWallet.ts +344 -0
- package/src/Wallet/index.ts +504 -0
- package/src/Wallet/rfc1751.ts +190 -0
- package/src/Wallet/rfc1751Words.json +243 -0
- package/src/Wallet/signer.ts +173 -0
- package/src/Wallet/walletFromSecretNumbers.ts +37 -0
- package/src/client/BroadcastClient.ts +84 -0
- package/src/client/ConnectionManager.ts +40 -0
- package/src/client/ExponentialBackoff.ts +71 -0
- package/src/client/RequestManager.ts +194 -0
- package/src/client/WSWrapper.ts +106 -0
- package/src/client/connection.ts +593 -0
- package/src/client/index.ts +712 -0
- package/src/client/partialPayment.ts +153 -0
- package/src/errors.ts +161 -0
- package/src/index.ts +20 -0
- package/src/models/common/index.ts +156 -0
- package/src/models/index.ts +16 -0
- package/src/models/ledger/AMM.ts +78 -0
- package/src/models/ledger/AccountRoot.ts +217 -0
- package/src/models/ledger/Amendments.ts +45 -0
- package/src/models/ledger/BaseLedgerEntry.ts +3 -0
- package/src/models/ledger/Bridge.ts +84 -0
- package/src/models/ledger/Check.ts +70 -0
- package/src/models/ledger/DepositPreauth.ts +35 -0
- package/src/models/ledger/DirectoryNode.ts +46 -0
- package/src/models/ledger/Escrow.ts +74 -0
- package/src/models/ledger/FeeSettings.ts +52 -0
- package/src/models/ledger/Ledger.ts +65 -0
- package/src/models/ledger/LedgerEntry.ts +40 -0
- package/src/models/ledger/LedgerHashes.ts +24 -0
- package/src/models/ledger/NFTokenOffer.ts +16 -0
- package/src/models/ledger/NFTokenPage.ts +20 -0
- package/src/models/ledger/NegativeUNL.ts +34 -0
- package/src/models/ledger/Offer.ts +52 -0
- package/src/models/ledger/PayChannel.ts +107 -0
- package/src/models/ledger/RippleState.ts +88 -0
- package/src/models/ledger/SignerList.ts +56 -0
- package/src/models/ledger/Ticket.ts +36 -0
- package/src/models/ledger/XChainOwnedClaimID.ts +73 -0
- package/src/models/ledger/XChainOwnedCreateAccountClaimID.ts +60 -0
- package/src/models/ledger/index.ts +64 -0
- package/src/models/methods/accountChannels.ts +93 -0
- package/src/models/methods/accountCurrencies.ts +45 -0
- package/src/models/methods/accountInfo.ts +182 -0
- package/src/models/methods/accountLines.ts +137 -0
- package/src/models/methods/accountNFTs.ts +72 -0
- package/src/models/methods/accountObjects.ts +129 -0
- package/src/models/methods/accountOffers.ts +100 -0
- package/src/models/methods/accountTx.ts +109 -0
- package/src/models/methods/ammInfo.ts +145 -0
- package/src/models/methods/baseMethod.ts +58 -0
- package/src/models/methods/bookOffers.ts +96 -0
- package/src/models/methods/channelVerify.ts +41 -0
- package/src/models/methods/depositAuthorized.ts +56 -0
- package/src/models/methods/fee.ts +91 -0
- package/src/models/methods/gatewayBalances.ts +85 -0
- package/src/models/methods/index.ts +391 -0
- package/src/models/methods/ledger.ts +125 -0
- package/src/models/methods/ledgerClosed.ts +32 -0
- package/src/models/methods/ledgerCurrent.ts +31 -0
- package/src/models/methods/ledgerData.ts +78 -0
- package/src/models/methods/ledgerEntry.ts +202 -0
- package/src/models/methods/manifest.ts +54 -0
- package/src/models/methods/nftBuyOffers.ts +37 -0
- package/src/models/methods/nftHistory.ts +113 -0
- package/src/models/methods/nftInfo.ts +25 -0
- package/src/models/methods/nftSellOffers.ts +37 -0
- package/src/models/methods/norippleCheck.ts +82 -0
- package/src/models/methods/pathFind.ts +116 -0
- package/src/models/methods/ping.ts +21 -0
- package/src/models/methods/random.ts +23 -0
- package/src/models/methods/ripplePathFind.ts +81 -0
- package/src/models/methods/serverInfo.ts +257 -0
- package/src/models/methods/serverState.ts +77 -0
- package/src/models/methods/submit.ts +94 -0
- package/src/models/methods/submitMultisigned.ts +51 -0
- package/src/models/methods/subscribe.ts +435 -0
- package/src/models/methods/transactionEntry.ts +47 -0
- package/src/models/methods/tx.ts +69 -0
- package/src/models/methods/unsubscribe.ts +49 -0
- package/src/models/transactions/AMMBid.ts +140 -0
- package/src/models/transactions/AMMCreate.ts +80 -0
- package/src/models/transactions/AMMDelete.ts +55 -0
- package/src/models/transactions/AMMDeposit.ts +130 -0
- package/src/models/transactions/AMMVote.ts +71 -0
- package/src/models/transactions/AMMWithdraw.ts +126 -0
- package/src/models/transactions/NFTokenAcceptOffer.ts +104 -0
- package/src/models/transactions/NFTokenBurn.ts +48 -0
- package/src/models/transactions/NFTokenCancelOffer.ts +45 -0
- package/src/models/transactions/NFTokenCreateOffer.ts +145 -0
- package/src/models/transactions/NFTokenMint.ts +123 -0
- package/src/models/transactions/UNLModify.ts +20 -0
- package/src/models/transactions/XChainAccountCreateCommit.ts +107 -0
- package/src/models/transactions/XChainAddAccountCreateAttestation.ts +225 -0
- package/src/models/transactions/XChainAddClaimAttestation.ts +198 -0
- package/src/models/transactions/XChainClaim.ts +103 -0
- package/src/models/transactions/XChainCommit.ts +95 -0
- package/src/models/transactions/XChainCreateBridge.ts +78 -0
- package/src/models/transactions/XChainCreateClaimID.ts +78 -0
- package/src/models/transactions/XChainModifyBridge.ts +93 -0
- package/src/models/transactions/accountDelete.ts +50 -0
- package/src/models/transactions/accountSet.ts +228 -0
- package/src/models/transactions/checkCancel.ts +34 -0
- package/src/models/transactions/checkCash.ts +73 -0
- package/src/models/transactions/checkCreate.ts +90 -0
- package/src/models/transactions/clawback.ts +49 -0
- package/src/models/transactions/common.ts +320 -0
- package/src/models/transactions/depositPreauth.ts +68 -0
- package/src/models/transactions/enableAmendment.ts +26 -0
- package/src/models/transactions/escrowCancel.ts +45 -0
- package/src/models/transactions/escrowCreate.ts +100 -0
- package/src/models/transactions/escrowFinish.ts +63 -0
- package/src/models/transactions/index.ts +78 -0
- package/src/models/transactions/metadata.ts +69 -0
- package/src/models/transactions/offerCancel.ts +37 -0
- package/src/models/transactions/offerCreate.ts +144 -0
- package/src/models/transactions/payment.ts +278 -0
- package/src/models/transactions/paymentChannelClaim.ts +165 -0
- package/src/models/transactions/paymentChannelCreate.ts +116 -0
- package/src/models/transactions/paymentChannelFund.ts +65 -0
- package/src/models/transactions/setFee.ts +48 -0
- package/src/models/transactions/setRegularKey.ts +33 -0
- package/src/models/transactions/signerListSet.ts +89 -0
- package/src/models/transactions/ticketCreate.ts +50 -0
- package/src/models/transactions/transaction.ts +370 -0
- package/src/models/transactions/trustSet.ts +146 -0
- package/src/models/utils/flags.ts +103 -0
- package/src/models/utils/index.ts +37 -0
- package/src/sugar/autofill.ts +373 -0
- package/src/sugar/balances.ts +123 -0
- package/src/sugar/getFeeXrp.ts +45 -0
- package/src/sugar/getLedgerIndex.ts +15 -0
- package/src/sugar/getOrderbook.ts +152 -0
- package/src/sugar/index.ts +11 -0
- package/src/sugar/submit.ts +305 -0
- package/src/sugar/utils.ts +29 -0
- package/src/utils/derive.ts +23 -0
- package/src/utils/getBalanceChanges.ts +186 -0
- package/src/utils/getNFTokenID.ts +97 -0
- package/src/utils/hashes/HashPrefix.ts +40 -0
- package/src/utils/hashes/README.md +65 -0
- package/src/utils/hashes/SHAMap/InnerNode.ts +124 -0
- package/src/utils/hashes/SHAMap/LeafNode.ts +69 -0
- package/src/utils/hashes/SHAMap/index.ts +41 -0
- package/src/utils/hashes/SHAMap/node.ts +14 -0
- package/src/utils/hashes/hashLedger.ts +236 -0
- package/src/utils/hashes/index.ts +187 -0
- package/src/utils/hashes/ledgerSpaces.ts +34 -0
- package/src/utils/hashes/sha512Half.ts +19 -0
- package/src/utils/index.ts +223 -0
- package/src/utils/parseNFTokenID.ts +84 -0
- package/src/utils/quality.ts +169 -0
- package/src/utils/signPaymentChannelClaim.ts +27 -0
- package/src/utils/stringConversion.ts +27 -0
- package/src/utils/timeConversion.ts +53 -0
- package/src/utils/verifyPaymentChannelClaim.ts +30 -0
- package/src/utils/xrpConversion.ts +104 -0
@@ -0,0 +1,373 @@
|
|
1
|
+
import BigNumber from 'bignumber.js'
|
2
|
+
import { xAddressToClassicAddress, isValidXAddress } from 'ripple-address-codec'
|
3
|
+
|
4
|
+
import type { Client } from '..'
|
5
|
+
import { ValidationError, XrplError } from '../errors'
|
6
|
+
import { AccountInfoRequest, AccountObjectsRequest } from '../models/methods'
|
7
|
+
import { Transaction } from '../models/transactions'
|
8
|
+
import { setTransactionFlagsToNumber } from '../models/utils/flags'
|
9
|
+
import { xrpToDrops } from '../utils'
|
10
|
+
|
11
|
+
import getFeeXrp from './getFeeXrp'
|
12
|
+
|
13
|
+
// Expire unconfirmed transactions after 20 ledger versions, approximately 1 minute, by default
|
14
|
+
const LEDGER_OFFSET = 20
|
15
|
+
// Sidechains are expected to have network IDs above this.
|
16
|
+
// Networks with ID above this restricted number are expected specify an accurate NetworkID field
|
17
|
+
// in every transaction to that chain to prevent replay attacks.
|
18
|
+
// Mainnet and testnet are exceptions. More context: https://github.com/XRPLF/rippled/pull/4370
|
19
|
+
const RESTRICTED_NETWORKS = 1024
|
20
|
+
const REQUIRED_NETWORKID_VERSION = '1.11.0'
|
21
|
+
const HOOKS_TESTNET_ID = 21338
|
22
|
+
interface ClassicAccountAndTag {
|
23
|
+
classicAccount: string
|
24
|
+
tag: number | false | undefined
|
25
|
+
}
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Autofills fields in a transaction. This will set `Sequence`, `Fee`,
|
29
|
+
* `lastLedgerSequence` according to the current state of the server this Client
|
30
|
+
* is connected to. It also converts all X-Addresses to classic addresses and
|
31
|
+
* flags interfaces into numbers.
|
32
|
+
*
|
33
|
+
* @example
|
34
|
+
*
|
35
|
+
* ```ts
|
36
|
+
* const { Client } = require('xrpl')
|
37
|
+
*
|
38
|
+
* const client = new Client('wss://s.altnet.rippletest.net:51233')
|
39
|
+
*
|
40
|
+
* async function createAndAutofillTransaction() {
|
41
|
+
* const transaction = {
|
42
|
+
* TransactionType: 'Payment',
|
43
|
+
* Account: 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh',
|
44
|
+
* Destination: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
|
45
|
+
* Amount: '10000000' // 10 XRP in drops (1/1,000,000th of an XRP)
|
46
|
+
* }
|
47
|
+
*
|
48
|
+
* try {
|
49
|
+
* const autofilledTransaction = await client.autofill(transaction)
|
50
|
+
* console.log(autofilledTransaction)
|
51
|
+
* } catch (error) {
|
52
|
+
* console.error(`Failed to autofill transaction: ${error}`)
|
53
|
+
* }
|
54
|
+
* }
|
55
|
+
*
|
56
|
+
* createAndAutofillTransaction()
|
57
|
+
* ```
|
58
|
+
*
|
59
|
+
* Autofill helps fill in fields which should be included in a transaction, but can be determined automatically
|
60
|
+
* such as `LastLedgerSequence` and `Fee`. If you override one of the fields `autofill` changes, your explicit
|
61
|
+
* values will be used instead. By default, this is done as part of `submit` and `submitAndWait` when you pass
|
62
|
+
* in an unsigned transaction along with your wallet to be submitted.
|
63
|
+
*
|
64
|
+
* @param this - A client.
|
65
|
+
* @param transaction - A {@link Transaction} in JSON format
|
66
|
+
* @param signersCount - The expected number of signers for this transaction.
|
67
|
+
* Only used for multisigned transactions.
|
68
|
+
* @returns The autofilled transaction.
|
69
|
+
*/
|
70
|
+
async function autofill<T extends Transaction>(
|
71
|
+
this: Client,
|
72
|
+
transaction: T,
|
73
|
+
signersCount?: number,
|
74
|
+
): Promise<T> {
|
75
|
+
const tx = { ...transaction }
|
76
|
+
|
77
|
+
setValidAddresses(tx)
|
78
|
+
|
79
|
+
setTransactionFlagsToNumber(tx)
|
80
|
+
const promises: Array<Promise<void>> = []
|
81
|
+
if (tx.NetworkID == null) {
|
82
|
+
tx.NetworkID = txNeedsNetworkID(this) ? this.networkID : undefined
|
83
|
+
}
|
84
|
+
if (tx.Sequence == null) {
|
85
|
+
promises.push(setNextValidSequenceNumber(this, tx))
|
86
|
+
}
|
87
|
+
if (tx.Fee == null) {
|
88
|
+
promises.push(calculateFeePerTransactionType(this, tx, signersCount))
|
89
|
+
}
|
90
|
+
if (tx.LastLedgerSequence == null) {
|
91
|
+
promises.push(setLatestValidatedLedgerSequence(this, tx))
|
92
|
+
}
|
93
|
+
if (tx.TransactionType === 'AccountDelete') {
|
94
|
+
promises.push(checkAccountDeleteBlockers(this, tx))
|
95
|
+
}
|
96
|
+
|
97
|
+
return Promise.all(promises).then(() => tx)
|
98
|
+
}
|
99
|
+
|
100
|
+
/**
|
101
|
+
* Determines whether the source rippled version is not later than the target rippled version.
|
102
|
+
* Example usage: isNotLaterRippledVersion('1.10.0', '1.11.0') returns true.
|
103
|
+
* isNotLaterRippledVersion('1.10.0', '1.10.0-b1') returns false.
|
104
|
+
*
|
105
|
+
* @param source -- The source rippled version.
|
106
|
+
* @param target -- The target rippled version.
|
107
|
+
* @returns True if source is earlier than target, false otherwise.
|
108
|
+
*/
|
109
|
+
// eslint-disable-next-line max-lines-per-function, max-statements -- Disable for this helper functions.
|
110
|
+
function isNotLaterRippledVersion(source: string, target: string): boolean {
|
111
|
+
if (source === target) {
|
112
|
+
return true
|
113
|
+
}
|
114
|
+
const sourceDecomp = source.split('.')
|
115
|
+
const targetDecomp = target.split('.')
|
116
|
+
const sourceMajor = parseInt(sourceDecomp[0], 10)
|
117
|
+
const sourceMinor = parseInt(sourceDecomp[1], 10)
|
118
|
+
const targetMajor = parseInt(targetDecomp[0], 10)
|
119
|
+
const targetMinor = parseInt(targetDecomp[1], 10)
|
120
|
+
// Compare major version
|
121
|
+
if (sourceMajor !== targetMajor) {
|
122
|
+
return sourceMajor < targetMajor
|
123
|
+
}
|
124
|
+
// Compare minor version
|
125
|
+
if (sourceMinor !== targetMinor) {
|
126
|
+
return sourceMinor < targetMinor
|
127
|
+
}
|
128
|
+
const sourcePatch = sourceDecomp[2].split('-')
|
129
|
+
const targetPatch = targetDecomp[2].split('-')
|
130
|
+
|
131
|
+
const sourcePatchVersion = parseInt(sourcePatch[0], 10)
|
132
|
+
const targetPatchVersion = parseInt(targetPatch[0], 10)
|
133
|
+
|
134
|
+
// Compare patch version
|
135
|
+
if (sourcePatchVersion !== targetPatchVersion) {
|
136
|
+
return sourcePatchVersion < targetPatchVersion
|
137
|
+
}
|
138
|
+
|
139
|
+
// Compare release version
|
140
|
+
if (sourcePatch.length !== targetPatch.length) {
|
141
|
+
return sourcePatch.length > targetPatch.length
|
142
|
+
}
|
143
|
+
|
144
|
+
if (sourcePatch.length === 2) {
|
145
|
+
// Compare different release types
|
146
|
+
if (!sourcePatch[1][0].startsWith(targetPatch[1][0])) {
|
147
|
+
return sourcePatch[1] < targetPatch[1]
|
148
|
+
}
|
149
|
+
// Compare beta version
|
150
|
+
if (sourcePatch[1].startsWith('b')) {
|
151
|
+
return (
|
152
|
+
parseInt(sourcePatch[1].slice(1), 10) <
|
153
|
+
parseInt(targetPatch[1].slice(1), 10)
|
154
|
+
)
|
155
|
+
}
|
156
|
+
// Compare rc version
|
157
|
+
return (
|
158
|
+
parseInt(sourcePatch[1].slice(2), 10) <
|
159
|
+
parseInt(targetPatch[1].slice(2), 10)
|
160
|
+
)
|
161
|
+
}
|
162
|
+
|
163
|
+
return false
|
164
|
+
}
|
165
|
+
|
166
|
+
/**
|
167
|
+
* Determine if the transaction required a networkID to be valid.
|
168
|
+
* Transaction needs networkID if later than restricted ID and either the network is hooks testnet
|
169
|
+
* or build version is >= 1.11.0
|
170
|
+
*
|
171
|
+
* @param client -- The connected client.
|
172
|
+
* @returns True if required networkID, false otherwise.
|
173
|
+
*/
|
174
|
+
function txNeedsNetworkID(client: Client): boolean {
|
175
|
+
if (
|
176
|
+
client.networkID !== undefined &&
|
177
|
+
client.networkID > RESTRICTED_NETWORKS
|
178
|
+
) {
|
179
|
+
// TODO: remove the buildVersion logic when 1.11.0 is out and widely used.
|
180
|
+
// Issue: https://github.com/XRPLF/xrpl.js/issues/2339
|
181
|
+
if (
|
182
|
+
(client.buildVersion &&
|
183
|
+
isNotLaterRippledVersion(
|
184
|
+
REQUIRED_NETWORKID_VERSION,
|
185
|
+
client.buildVersion,
|
186
|
+
)) ||
|
187
|
+
client.networkID === HOOKS_TESTNET_ID
|
188
|
+
) {
|
189
|
+
return true
|
190
|
+
}
|
191
|
+
}
|
192
|
+
return false
|
193
|
+
}
|
194
|
+
|
195
|
+
function setValidAddresses(tx: Transaction): void {
|
196
|
+
validateAccountAddress(tx, 'Account', 'SourceTag')
|
197
|
+
// eslint-disable-next-line @typescript-eslint/dot-notation -- Destination can exist on Transaction
|
198
|
+
if (tx['Destination'] != null) {
|
199
|
+
validateAccountAddress(tx, 'Destination', 'DestinationTag')
|
200
|
+
}
|
201
|
+
|
202
|
+
// DepositPreauth:
|
203
|
+
convertToClassicAddress(tx, 'Authorize')
|
204
|
+
convertToClassicAddress(tx, 'Unauthorize')
|
205
|
+
// EscrowCancel, EscrowFinish:
|
206
|
+
convertToClassicAddress(tx, 'Owner')
|
207
|
+
// SetRegularKey:
|
208
|
+
convertToClassicAddress(tx, 'RegularKey')
|
209
|
+
}
|
210
|
+
|
211
|
+
function validateAccountAddress(
|
212
|
+
tx: Transaction,
|
213
|
+
accountField: string,
|
214
|
+
tagField: string,
|
215
|
+
): void {
|
216
|
+
// if X-address is given, convert it to classic address
|
217
|
+
const { classicAccount, tag } = getClassicAccountAndTag(tx[accountField])
|
218
|
+
// eslint-disable-next-line no-param-reassign -- param reassign is safe
|
219
|
+
tx[accountField] = classicAccount
|
220
|
+
|
221
|
+
if (tag != null && tag !== false) {
|
222
|
+
if (tx[tagField] && tx[tagField] !== tag) {
|
223
|
+
throw new ValidationError(
|
224
|
+
`The ${tagField}, if present, must match the tag of the ${accountField} X-address`,
|
225
|
+
)
|
226
|
+
}
|
227
|
+
// eslint-disable-next-line no-param-reassign -- param reassign is safe
|
228
|
+
tx[tagField] = tag
|
229
|
+
}
|
230
|
+
}
|
231
|
+
|
232
|
+
function getClassicAccountAndTag(
|
233
|
+
Account: string,
|
234
|
+
expectedTag?: number,
|
235
|
+
): ClassicAccountAndTag {
|
236
|
+
if (isValidXAddress(Account)) {
|
237
|
+
const classic = xAddressToClassicAddress(Account)
|
238
|
+
if (expectedTag != null && classic.tag !== expectedTag) {
|
239
|
+
throw new ValidationError(
|
240
|
+
'address includes a tag that does not match the tag specified in the transaction',
|
241
|
+
)
|
242
|
+
}
|
243
|
+
return {
|
244
|
+
classicAccount: classic.classicAddress,
|
245
|
+
tag: classic.tag,
|
246
|
+
}
|
247
|
+
}
|
248
|
+
return {
|
249
|
+
classicAccount: Account,
|
250
|
+
tag: expectedTag,
|
251
|
+
}
|
252
|
+
}
|
253
|
+
|
254
|
+
function convertToClassicAddress(tx: Transaction, fieldName: string): void {
|
255
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- assignment is safe
|
256
|
+
const account = tx[fieldName]
|
257
|
+
if (typeof account === 'string') {
|
258
|
+
const { classicAccount } = getClassicAccountAndTag(account)
|
259
|
+
// eslint-disable-next-line no-param-reassign -- param reassign is safe
|
260
|
+
tx[fieldName] = classicAccount
|
261
|
+
}
|
262
|
+
}
|
263
|
+
|
264
|
+
async function setNextValidSequenceNumber(
|
265
|
+
client: Client,
|
266
|
+
tx: Transaction,
|
267
|
+
): Promise<void> {
|
268
|
+
const request: AccountInfoRequest = {
|
269
|
+
command: 'account_info',
|
270
|
+
account: tx.Account,
|
271
|
+
ledger_index: 'current',
|
272
|
+
}
|
273
|
+
const data = await client.request(request)
|
274
|
+
// eslint-disable-next-line no-param-reassign, require-atomic-updates -- param reassign is safe with no race condition
|
275
|
+
tx.Sequence = data.result.account_data.Sequence
|
276
|
+
}
|
277
|
+
|
278
|
+
async function fetchOwnerReserveFee(client: Client): Promise<BigNumber> {
|
279
|
+
const response = await client.request({ command: 'server_state' })
|
280
|
+
const fee = response.result.state.validated_ledger?.reserve_inc
|
281
|
+
|
282
|
+
if (fee == null) {
|
283
|
+
return Promise.reject(new Error('Could not fetch Owner Reserve.'))
|
284
|
+
}
|
285
|
+
|
286
|
+
return new BigNumber(fee)
|
287
|
+
}
|
288
|
+
|
289
|
+
async function calculateFeePerTransactionType(
|
290
|
+
client: Client,
|
291
|
+
tx: Transaction,
|
292
|
+
signersCount = 0,
|
293
|
+
): Promise<void> {
|
294
|
+
// netFee is usually 0.00001 XRP (10 drops)
|
295
|
+
const netFeeXRP = await getFeeXrp(client)
|
296
|
+
const netFeeDrops = xrpToDrops(netFeeXRP)
|
297
|
+
let baseFee = new BigNumber(netFeeDrops)
|
298
|
+
|
299
|
+
// EscrowFinish Transaction with Fulfillment
|
300
|
+
if (tx.TransactionType === 'EscrowFinish' && tx.Fulfillment != null) {
|
301
|
+
const fulfillmentBytesSize: number = Math.ceil(tx.Fulfillment.length / 2)
|
302
|
+
// 10 drops × (33 + (Fulfillment size in bytes / 16))
|
303
|
+
const product = new BigNumber(
|
304
|
+
// eslint-disable-next-line @typescript-eslint/no-magic-numbers -- expected use of magic numbers
|
305
|
+
scaleValue(netFeeDrops, 33 + fulfillmentBytesSize / 16),
|
306
|
+
)
|
307
|
+
baseFee = product.dp(0, BigNumber.ROUND_CEIL)
|
308
|
+
}
|
309
|
+
|
310
|
+
if (
|
311
|
+
tx.TransactionType === 'AccountDelete' ||
|
312
|
+
tx.TransactionType === 'AMMCreate'
|
313
|
+
) {
|
314
|
+
baseFee = await fetchOwnerReserveFee(client)
|
315
|
+
}
|
316
|
+
|
317
|
+
/*
|
318
|
+
* Multi-signed Transaction
|
319
|
+
* 10 drops × (1 + Number of Signatures Provided)
|
320
|
+
*/
|
321
|
+
if (signersCount > 0) {
|
322
|
+
baseFee = BigNumber.sum(baseFee, scaleValue(netFeeDrops, 1 + signersCount))
|
323
|
+
}
|
324
|
+
|
325
|
+
const maxFeeDrops = xrpToDrops(client.maxFeeXRP)
|
326
|
+
const totalFee =
|
327
|
+
tx.TransactionType === 'AccountDelete'
|
328
|
+
? baseFee
|
329
|
+
: BigNumber.min(baseFee, maxFeeDrops)
|
330
|
+
|
331
|
+
// Round up baseFee and return it as a string
|
332
|
+
// eslint-disable-next-line no-param-reassign, @typescript-eslint/no-magic-numbers -- param reassign is safe, base 10 magic num
|
333
|
+
tx.Fee = totalFee.dp(0, BigNumber.ROUND_CEIL).toString(10)
|
334
|
+
}
|
335
|
+
|
336
|
+
function scaleValue(value, multiplier): string {
|
337
|
+
return new BigNumber(value).times(multiplier).toString()
|
338
|
+
}
|
339
|
+
|
340
|
+
async function setLatestValidatedLedgerSequence(
|
341
|
+
client: Client,
|
342
|
+
tx: Transaction,
|
343
|
+
): Promise<void> {
|
344
|
+
const ledgerSequence = await client.getLedgerIndex()
|
345
|
+
// eslint-disable-next-line no-param-reassign -- param reassign is safe
|
346
|
+
tx.LastLedgerSequence = ledgerSequence + LEDGER_OFFSET
|
347
|
+
}
|
348
|
+
|
349
|
+
async function checkAccountDeleteBlockers(
|
350
|
+
client: Client,
|
351
|
+
tx: Transaction,
|
352
|
+
): Promise<void> {
|
353
|
+
const request: AccountObjectsRequest = {
|
354
|
+
command: 'account_objects',
|
355
|
+
account: tx.Account,
|
356
|
+
ledger_index: 'validated',
|
357
|
+
deletion_blockers_only: true,
|
358
|
+
}
|
359
|
+
const response = await client.request(request)
|
360
|
+
return new Promise((resolve, reject) => {
|
361
|
+
if (response.result.account_objects.length > 0) {
|
362
|
+
reject(
|
363
|
+
new XrplError(
|
364
|
+
`Account ${tx.Account} cannot be deleted; there are Escrows, PayChannels, RippleStates, or Checks associated with the account.`,
|
365
|
+
response.result.account_objects,
|
366
|
+
),
|
367
|
+
)
|
368
|
+
}
|
369
|
+
resolve()
|
370
|
+
})
|
371
|
+
}
|
372
|
+
|
373
|
+
export default autofill
|
@@ -0,0 +1,123 @@
|
|
1
|
+
import flatMap from 'lodash/flatMap'
|
2
|
+
|
3
|
+
import type { Balance, Client } from '..'
|
4
|
+
import {
|
5
|
+
AccountLinesRequest,
|
6
|
+
AccountLinesTrustline,
|
7
|
+
LedgerIndex,
|
8
|
+
AccountInfoRequest,
|
9
|
+
} from '../models'
|
10
|
+
import { dropsToXrp } from '../utils'
|
11
|
+
|
12
|
+
function formatBalances(trustlines: AccountLinesTrustline[]): Balance[] {
|
13
|
+
return trustlines.map((trustline) => ({
|
14
|
+
value: trustline.balance,
|
15
|
+
currency: trustline.currency,
|
16
|
+
issuer: trustline.account,
|
17
|
+
}))
|
18
|
+
}
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Get the XRP balance for an account.
|
22
|
+
*
|
23
|
+
* @example
|
24
|
+
* ```ts
|
25
|
+
* const client = new Client(wss://s.altnet.rippletest.net:51233)
|
26
|
+
* const balance = await client.getXrpBalance('rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn')
|
27
|
+
* console.log(balance)
|
28
|
+
* /// '200'
|
29
|
+
* ```
|
30
|
+
*
|
31
|
+
* @param this - Client.
|
32
|
+
* @param address - Address of the account to retrieve XRP balance.
|
33
|
+
* @param options - Options to include for getting the XRP balance.
|
34
|
+
* @param options.ledger_index - Retrieve the account balances at a given
|
35
|
+
* ledger_index.
|
36
|
+
* @param options.ledger_hash - Retrieve the account balances at the ledger with
|
37
|
+
* a given ledger_hash.
|
38
|
+
* @returns The XRP balance of the account (as a string).
|
39
|
+
*/
|
40
|
+
async function getXrpBalance(
|
41
|
+
this: Client,
|
42
|
+
address: string,
|
43
|
+
options: {
|
44
|
+
ledger_hash?: string
|
45
|
+
ledger_index?: LedgerIndex
|
46
|
+
} = {},
|
47
|
+
): Promise<string> {
|
48
|
+
const xrpRequest: AccountInfoRequest = {
|
49
|
+
command: 'account_info',
|
50
|
+
account: address,
|
51
|
+
ledger_index: options.ledger_index ?? 'validated',
|
52
|
+
ledger_hash: options.ledger_hash,
|
53
|
+
}
|
54
|
+
const response = await this.request(xrpRequest)
|
55
|
+
return dropsToXrp(response.result.account_data.Balance)
|
56
|
+
}
|
57
|
+
|
58
|
+
/**
|
59
|
+
* Get XRP/non-XRP balances for an account.
|
60
|
+
*
|
61
|
+
* @param this - Client.
|
62
|
+
* @param address - Address of the account to retrieve balances for.
|
63
|
+
* @param options - Allows the client to specify a ledger_hash, ledger_index,
|
64
|
+
* filter by peer, and/or limit number of balances.
|
65
|
+
* @param options.ledger_index - Retrieve the account balances at a given
|
66
|
+
* ledger_index.
|
67
|
+
* @param options.ledger_hash - Retrieve the account balances at the ledger with
|
68
|
+
* a given ledger_hash.
|
69
|
+
* @param options.peer - Filter balances by peer.
|
70
|
+
* @param options.limit - Limit number of balances to return.
|
71
|
+
* @returns An array of XRP/non-XRP balances for the given account.
|
72
|
+
*/
|
73
|
+
// eslint-disable-next-line max-lines-per-function -- Longer definition is required for end users to see the definition.
|
74
|
+
async function getBalances(
|
75
|
+
this: Client,
|
76
|
+
address: string,
|
77
|
+
options: {
|
78
|
+
ledger_hash?: string
|
79
|
+
ledger_index?: LedgerIndex
|
80
|
+
peer?: string
|
81
|
+
limit?: number
|
82
|
+
} = {},
|
83
|
+
): Promise<
|
84
|
+
Array<{ value: string; currency: string; issuer?: string | undefined }>
|
85
|
+
> {
|
86
|
+
const balances: Balance[] = []
|
87
|
+
|
88
|
+
// get XRP balance
|
89
|
+
let xrpPromise: Promise<string> = Promise.resolve('')
|
90
|
+
if (!options.peer) {
|
91
|
+
xrpPromise = this.getXrpBalance(address, {
|
92
|
+
ledger_hash: options.ledger_hash,
|
93
|
+
ledger_index: options.ledger_index,
|
94
|
+
})
|
95
|
+
}
|
96
|
+
|
97
|
+
// get non-XRP balances
|
98
|
+
const linesRequest: AccountLinesRequest = {
|
99
|
+
command: 'account_lines',
|
100
|
+
account: address,
|
101
|
+
ledger_index: options.ledger_index ?? 'validated',
|
102
|
+
ledger_hash: options.ledger_hash,
|
103
|
+
peer: options.peer,
|
104
|
+
limit: options.limit,
|
105
|
+
}
|
106
|
+
const linesPromise = this.requestAll(linesRequest)
|
107
|
+
|
108
|
+
// combine results
|
109
|
+
await Promise.all([xrpPromise, linesPromise]).then(
|
110
|
+
([xrpBalance, linesResponses]) => {
|
111
|
+
const accountLinesBalance = flatMap(linesResponses, (response) =>
|
112
|
+
formatBalances(response.result.lines),
|
113
|
+
)
|
114
|
+
if (xrpBalance !== '') {
|
115
|
+
balances.push({ currency: 'XRP', value: xrpBalance })
|
116
|
+
}
|
117
|
+
balances.push(...accountLinesBalance)
|
118
|
+
},
|
119
|
+
)
|
120
|
+
return balances.slice(0, options.limit)
|
121
|
+
}
|
122
|
+
|
123
|
+
export { getXrpBalance, getBalances }
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import BigNumber from 'bignumber.js'
|
2
|
+
|
3
|
+
import type { Client } from '..'
|
4
|
+
import { XrplError } from '../errors'
|
5
|
+
|
6
|
+
const NUM_DECIMAL_PLACES = 6
|
7
|
+
const BASE_10 = 10
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Calculates the current transaction fee for the ledger.
|
11
|
+
* Note: This is a public API that can be called directly.
|
12
|
+
*
|
13
|
+
* @param client - The Client used to connect to the ledger.
|
14
|
+
* @param cushion - The fee cushion to use.
|
15
|
+
* @returns The transaction fee.
|
16
|
+
*/
|
17
|
+
export default async function getFeeXrp(
|
18
|
+
client: Client,
|
19
|
+
cushion?: number,
|
20
|
+
): Promise<string> {
|
21
|
+
const feeCushion = cushion ?? client.feeCushion
|
22
|
+
|
23
|
+
const serverInfo = (await client.request({ command: 'server_info' })).result
|
24
|
+
.info
|
25
|
+
|
26
|
+
const baseFee = serverInfo.validated_ledger?.base_fee_xrp
|
27
|
+
|
28
|
+
if (baseFee == null) {
|
29
|
+
throw new XrplError(
|
30
|
+
'getFeeXrp: Could not get base_fee_xrp from server_info',
|
31
|
+
)
|
32
|
+
}
|
33
|
+
|
34
|
+
const baseFeeXrp = new BigNumber(baseFee)
|
35
|
+
if (serverInfo.load_factor == null) {
|
36
|
+
// https://github.com/ripple/rippled/issues/3812#issuecomment-816871100
|
37
|
+
serverInfo.load_factor = 1
|
38
|
+
}
|
39
|
+
let fee = baseFeeXrp.times(serverInfo.load_factor).times(feeCushion)
|
40
|
+
|
41
|
+
// Cap fee to `client.maxFeeXRP`
|
42
|
+
fee = BigNumber.min(fee, client.maxFeeXRP)
|
43
|
+
// Round fee to 6 decimal places
|
44
|
+
return new BigNumber(fee.toFixed(NUM_DECIMAL_PLACES)).toString(BASE_10)
|
45
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import type { Client } from '..'
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Returns the index of the most recently validated ledger.
|
5
|
+
*
|
6
|
+
* @param this - The Client used to connect to the ledger.
|
7
|
+
* @returns The most recently validated ledger index.
|
8
|
+
*/
|
9
|
+
export default async function getLedgerIndex(this: Client): Promise<number> {
|
10
|
+
const ledgerResponse = await this.request({
|
11
|
+
command: 'ledger',
|
12
|
+
ledger_index: 'validated',
|
13
|
+
})
|
14
|
+
return ledgerResponse.result.ledger_index
|
15
|
+
}
|
@@ -0,0 +1,152 @@
|
|
1
|
+
/* eslint-disable max-lines-per-function -- Needs to process orderbooks. */
|
2
|
+
import BigNumber from 'bignumber.js'
|
3
|
+
import flatMap from 'lodash/flatMap'
|
4
|
+
|
5
|
+
import type { Client } from '../client'
|
6
|
+
import { ValidationError } from '../errors'
|
7
|
+
import { LedgerIndex } from '../models/common'
|
8
|
+
import { OfferFlags } from '../models/ledger/Offer'
|
9
|
+
import {
|
10
|
+
BookOffer,
|
11
|
+
BookOfferCurrency,
|
12
|
+
BookOffersRequest,
|
13
|
+
} from '../models/methods/bookOffers'
|
14
|
+
|
15
|
+
const DEFAULT_LIMIT = 20
|
16
|
+
|
17
|
+
function sortOffers(offers: BookOffer[]): BookOffer[] {
|
18
|
+
return offers.sort((offerA, offerB) => {
|
19
|
+
const qualityA = offerA.quality ?? 0
|
20
|
+
const qualityB = offerB.quality ?? 0
|
21
|
+
|
22
|
+
return new BigNumber(qualityA).comparedTo(qualityB)
|
23
|
+
})
|
24
|
+
}
|
25
|
+
|
26
|
+
const getOrderbookOptionsSet = new Set([
|
27
|
+
'limit',
|
28
|
+
'ledger_index',
|
29
|
+
'ledger_hash',
|
30
|
+
'taker',
|
31
|
+
])
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Fetch orderbook (buy/sell orders) between two currency pairs. This checks both sides of the orderbook
|
35
|
+
* by making two `order_book` requests (with the second reversing takerPays and takerGets). Returned offers are
|
36
|
+
* not normalized in this function, so either currency could be takerGets or takerPays.
|
37
|
+
*
|
38
|
+
* @param this - Client.
|
39
|
+
* @param currency1 - Specification of one currency involved. (With a currency code and optionally an issuer)
|
40
|
+
* @param currency2 - Specification of a second currency involved. (With a currency code and optionally an issuer)
|
41
|
+
* @param options - Options allowing the client to specify ledger_index,
|
42
|
+
* ledger_hash, filter by taker, and/or limit number of orders.
|
43
|
+
* @param options.ledger_index - Retrieve the orderbook at a given ledger_index.
|
44
|
+
* @param options.ledger_hash - Retrieve the orderbook at the ledger with a
|
45
|
+
* given ledger_hash.
|
46
|
+
* @param options.taker - Filter orders by taker.
|
47
|
+
* @param options.limit - The limit passed into each book_offers request.
|
48
|
+
* Can return more than this due to two calls being made. Defaults to 20.
|
49
|
+
* @returns An object containing buy and sell objects.
|
50
|
+
*/
|
51
|
+
// eslint-disable-next-line max-params, complexity -- Once bound to Client, getOrderbook only has 3 parameters.
|
52
|
+
async function getOrderbook(
|
53
|
+
this: Client,
|
54
|
+
currency1: BookOfferCurrency,
|
55
|
+
currency2: BookOfferCurrency,
|
56
|
+
options: {
|
57
|
+
limit?: number
|
58
|
+
ledger_index?: LedgerIndex
|
59
|
+
ledger_hash?: string | null
|
60
|
+
taker?: string | null
|
61
|
+
} = {},
|
62
|
+
): Promise<{
|
63
|
+
buy: BookOffer[]
|
64
|
+
sell: BookOffer[]
|
65
|
+
}> {
|
66
|
+
Object.keys(options).forEach((key) => {
|
67
|
+
if (!getOrderbookOptionsSet.has(key)) {
|
68
|
+
throw new ValidationError(`Unexpected option: ${key}`, options)
|
69
|
+
}
|
70
|
+
})
|
71
|
+
|
72
|
+
if (options.limit && typeof options.limit !== 'number') {
|
73
|
+
throw new ValidationError('limit must be a number', options.limit)
|
74
|
+
}
|
75
|
+
|
76
|
+
if (
|
77
|
+
options.ledger_index &&
|
78
|
+
!(
|
79
|
+
typeof options.ledger_index === 'number' ||
|
80
|
+
(typeof options.ledger_index === 'string' &&
|
81
|
+
['validated', 'closed', 'current'].includes(options.ledger_index))
|
82
|
+
)
|
83
|
+
) {
|
84
|
+
throw new ValidationError(
|
85
|
+
'ledger_index must be a number or a string of "validated", "closed", or "current"',
|
86
|
+
options.ledger_index,
|
87
|
+
)
|
88
|
+
}
|
89
|
+
|
90
|
+
if (
|
91
|
+
options.ledger_hash !== undefined &&
|
92
|
+
options.ledger_hash !== null &&
|
93
|
+
typeof options.ledger_hash !== 'string'
|
94
|
+
) {
|
95
|
+
throw new ValidationError(
|
96
|
+
'ledger_hash must be a string',
|
97
|
+
options.ledger_hash,
|
98
|
+
)
|
99
|
+
}
|
100
|
+
|
101
|
+
if (options.taker !== undefined && typeof options.taker !== 'string') {
|
102
|
+
throw new ValidationError('taker must be a string', options.taker)
|
103
|
+
}
|
104
|
+
|
105
|
+
const request: BookOffersRequest = {
|
106
|
+
command: 'book_offers',
|
107
|
+
taker_pays: currency1,
|
108
|
+
taker_gets: currency2,
|
109
|
+
ledger_index: options.ledger_index ?? 'validated',
|
110
|
+
ledger_hash: options.ledger_hash === null ? undefined : options.ledger_hash,
|
111
|
+
limit: options.limit ?? DEFAULT_LIMIT,
|
112
|
+
taker: options.taker ? options.taker : undefined,
|
113
|
+
}
|
114
|
+
// 2. Make Request
|
115
|
+
const directOfferResults = await this.requestAll(request)
|
116
|
+
request.taker_gets = currency1
|
117
|
+
request.taker_pays = currency2
|
118
|
+
const reverseOfferResults = await this.requestAll(request)
|
119
|
+
// 3. Return Formatted Response
|
120
|
+
const directOffers = flatMap(
|
121
|
+
directOfferResults,
|
122
|
+
(directOfferResult) => directOfferResult.result.offers,
|
123
|
+
)
|
124
|
+
const reverseOffers = flatMap(
|
125
|
+
reverseOfferResults,
|
126
|
+
(reverseOfferResult) => reverseOfferResult.result.offers,
|
127
|
+
)
|
128
|
+
|
129
|
+
const orders = [...directOffers, ...reverseOffers]
|
130
|
+
// separate out the buy and sell orders
|
131
|
+
const buy: BookOffer[] = []
|
132
|
+
const sell: BookOffer[] = []
|
133
|
+
orders.forEach((order) => {
|
134
|
+
// eslint-disable-next-line no-bitwise -- necessary for flags check
|
135
|
+
if ((order.Flags & OfferFlags.lsfSell) === 0) {
|
136
|
+
buy.push(order)
|
137
|
+
} else {
|
138
|
+
sell.push(order)
|
139
|
+
}
|
140
|
+
})
|
141
|
+
/*
|
142
|
+
* Sort the orders
|
143
|
+
* for both buys and sells, lowest quality is closest to mid-market
|
144
|
+
* we sort the orders so that earlier orders are closer to mid-market
|
145
|
+
*/
|
146
|
+
return {
|
147
|
+
buy: sortOffers(buy).slice(0, options.limit),
|
148
|
+
sell: sortOffers(sell).slice(0, options.limit),
|
149
|
+
}
|
150
|
+
}
|
151
|
+
|
152
|
+
export default getOrderbook
|