UNPKG

@nextrope/xrpl

Version:

A TypeScript/JavaScript API for interacting with the XRP Ledger in Node.js and the browser

176 lines (148 loc) 4.84 kB
import { Amount, MPTAmount, Signer } from '../common' import { Account, BaseTransaction, isAmount, isNumber, isString, validateBaseTransaction, validateOptionalField, validateRequiredField, XRPLNumber, } from './common' /** * Sequester XRP until the escrow process either finishes or is canceled. * * @category Transaction Models */ export interface LoanSet extends BaseTransaction { TransactionType: 'LoanSet' /** * The Loan Broker ID associated with the loan. */ LoanBrokerID: string /** * Arbitrary metadata in hex format. The field is limited to 256 bytes. */ Data?: string Counterparty?: Account CounterpartySignature?: { TxnSignature: string SigningPubKey: string Signers?: Signer[] } /** * The address of the account that is the borrower. */ // ! https://github.com/XRPLF/rippled/blob/5d2a7d651e5fd3b1c1a49b0d417670f049813b91/include/xrpl/protocol/detail/transactions.macro#L884 - not found in code // Borrower: Account /** * A nominal funds amount paid to the LoanBroker.Owner when the Loan is created. */ LoanOriginationFee?: XRPLNumber /** * A nominal amount paid to the LoanBroker.Owner with every Loan payment. */ LoanServiceFee?: XRPLNumber /** * A nominal funds amount paid to the LoanBroker.Owner when a payment is late. */ LatePaymentFee?: XRPLNumber ClosePaymentFee?: XRPLNumber OverpaymentFee?: XRPLNumber /** * A nominal funds amount paid to the LoanBroker.Owner when an early full repayment is made. */ // FullPaymentFee?: XRPLNumber /** * Annualized interest rate of the Loan in basis points. */ InterestRate?: XRPLNumber /** * A premium added to the interest rate for late payments in basis points. Valid values are between 0 and 10000 inclusive. (0 - 100%) */ LateInterestRate?: XRPLNumber /** * A Fee Rate charged for repaying the Loan early in 1/10th basis points. Valid values are between 0 and 100000 inclusive. (0 - 100%) */ CloseInterestRate?: XRPLNumber OverpaymentInterestRate?: XRPLNumber /** * The principal amount requested by the Borrower. */ PrincipalRequested: Amount | MPTAmount /** * The timestamp of when the Loan starts Ripple Epoch. */ // StartDate: XRPLNumber /** * The total number of payments to be made against the Loan. */ PaymentTotal?: XRPLNumber /** * Number of seconds between Loan payments. */ PaymentInterval?: XRPLNumber /** * The number of seconds after the Loan's Payment Due Date can be Defaulted. */ GracePeriod?: XRPLNumber // /** // * An inner object that contains the signature of the Lender over the transaction. // */ // Lender?: { // /** // * The Public Key to be used to verify the validity of the signature. // */ // SigningPubKey: string // /** // * The signature of over all signing fields, including the Signature of the Borrower. // */ // Signature?: string // /** // * An array of transaction signatures from the LoanBroker.Owner signers to indicate their approval of this transaction. // */ // Signers?: Signer[] // } } /** * Verify the form and type of an EscrowCreate at runtime. * * @param tx - An EscrowCreate Transaction. * @throws When the EscrowCreate is Malformed. */ export function validateLoanSet(tx: Record<string, unknown>): void { validateBaseTransaction(tx) validateRequiredField(tx, 'LoanBrokerID', isString) // validateRequiredField(tx, 'Borrower', isAccount) validateRequiredField(tx, 'PrincipalRequested', isAmount) // validateRequiredField(tx, 'StartDate', isString) validateOptionalField(tx, 'Data', isString) validateOptionalField(tx, 'LoanOriginationFee', isNumber) validateOptionalField(tx, 'LoanServiceFee', isNumber) validateOptionalField(tx, 'LatePaymentFee', isNumber) validateOptionalField(tx, 'FullPaymentFee', isNumber) validateOptionalField(tx, 'InterestRate', isNumber) validateOptionalField(tx, 'LateInterestRate', isNumber) validateOptionalField(tx, 'CloseInterestRate', isNumber) validateOptionalField(tx, 'OverpaymentInterestRate', isNumber) validateOptionalField(tx, 'PaymentTotal', isNumber) validateOptionalField(tx, 'PaymentInterval', isNumber) validateOptionalField(tx, 'GracePeriod', isNumber) // if (tx.Lender) { // const lender = tx.Lender as Record<string, unknown> // if (typeof lender.SigningPubKey !== 'string') { // throw new ValidationError( // 'LoanSet: Lender.SigningPubKey must be a string', // ) // } // if ( // typeof lender.Signature !== 'string' && // !Array.isArray(lender.Signers) // ) { // throw new ValidationError( // 'LoanSet: Lender.Signature or Lender.Signers required', // ) // } // } }