Skip to content

Commit bc7fc4b

Browse files
ckeshavamvadariachowdhry-ripplekhancode
authored
XLS 85d: Token Escrow (XRPLF#3027)
* XLS-85d: Token Escrow -- Implementation for xrpl.js; This commit includes models, unit-tests and integ-tests for the associated transactions * specify TokenEscrow in the rippled.cfg file * variable renaming in the escrowCreate integ tests * remove references to wallet1 in escrowCreate integ tests * rename useBase10 function as isBase10 method --------- Co-authored-by: Mayukha Vadari <mvadari@gmail.com> Co-authored-by: achowdhry-ripple <achowdhry@ripple.com> Co-authored-by: Omar Khan <khancodegt@gmail.com>
1 parent a12cd02 commit bc7fc4b

File tree

11 files changed

+343
-24
lines changed

11 files changed

+343
-24
lines changed

.ci-config/rippled.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ fixInvalidTxFlags
190190
# 2.5.0 Amendments
191191
PermissionDelegation
192192
Batch
193+
TokenEscrow
193194
SingleAssetVault
194195

195196
# This section can be used to simulate various FeeSettings scenarios for rippled node in standalone mode

packages/ripple-binary-codec/src/types/uint-64.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ const HEX_REGEX = /^[a-fA-F0-9]{1,16}$/
88
const BASE10_REGEX = /^[0-9]{1,20}$/
99
const mask = BigInt(0x00000000ffffffff)
1010

11-
function useBase10(fieldName: string): boolean {
12-
return (
13-
fieldName === 'MaximumAmount' ||
14-
fieldName === 'OutstandingAmount' ||
15-
fieldName === 'MPTAmount'
16-
)
11+
const BASE10_AMOUNT_FIELDS = new Set([
12+
'MaximumAmount',
13+
'OutstandingAmount',
14+
'MPTAmount',
15+
'LockedAmount',
16+
])
17+
18+
function isBase10(fieldName: string): boolean {
19+
return BASE10_AMOUNT_FIELDS.has(fieldName)
1720
}
1821

1922
/**
@@ -64,7 +67,7 @@ class UInt64 extends UInt {
6467
}
6568

6669
if (typeof val === 'string') {
67-
if (useBase10(fieldName)) {
70+
if (isBase10(fieldName)) {
6871
if (!BASE10_REGEX.test(val)) {
6972
throw new Error(`${fieldName} ${val} is not a valid base 10 string`)
7073
}
@@ -101,7 +104,7 @@ class UInt64 extends UInt {
101104
fieldName = '',
102105
): string {
103106
const hexString = bytesToHex(this.bytes)
104-
if (useBase10(fieldName)) {
107+
if (isBase10(fieldName)) {
105108
return BigInt('0x' + hexString).toString(10)
106109
}
107110

packages/xrpl/HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr
55
## Unreleased
66

77
### Added
8+
* Support for `Token Escrow` (XLS-85)
89
* Support for `Single Asset Vault` (XLS-65)
910
* Adds `XRPLNumber` amount type used in Vault transactions. This supports integer, decimal, or scientific notation strings.
1011
* Adds `ClawbackAmount` amount type used in transactions related to Clawback.

packages/xrpl/src/models/ledger/AccountRoot.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ export interface AccountRootFlagsInterface {
146146
* This address can claw back issued IOUs. Once enabled, cannot be disabled.
147147
*/
148148
lsfAllowTrustLineClawback?: boolean
149+
150+
/**
151+
* Allow IOUs to be used as escrow amounts for an issuer
152+
*/
153+
lsfAllowTrustLineLocking?: boolean
149154
}
150155

151156
export enum AccountRootFlags {
@@ -210,4 +215,9 @@ export enum AccountRootFlags {
210215
* This address can claw back issued IOUs. Once enabled, cannot be disabled.
211216
*/
212217
lsfAllowTrustLineClawback = 0x80000000,
218+
/**
219+
* If the issuer's account does not have the lsfAllowTrustLineLocking flag set,
220+
* then Escrow ledger-objects cannot be created with such IOUs.
221+
*/
222+
lsfAllowTrustLineLocking = 0x40000000,
213223
}

packages/xrpl/src/models/ledger/Escrow.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export default interface Escrow extends BaseLedgerEntry, HasPreviousTxnID {
1919
* successful.
2020
*/
2121
Destination: string
22-
/** The amount of XRP, in drops, to be delivered by the held payment. */
22+
/** The amount to be delivered by the held payment. Can represent XRP, an IOU token, or an MPT.
23+
* Must always be a positive value. */
2324
Amount: string
2425
/**
2526
* A PREIMAGE-SHA-256 crypto-condition, as hexadecimal. If present, the
@@ -61,4 +62,16 @@ export default interface Escrow extends BaseLedgerEntry, HasPreviousTxnID {
6162
* this object, in case the directory consists of multiple pages.
6263
*/
6364
DestinationNode?: string
65+
66+
/**
67+
* The transfer rate or fee at which the funds are escrowed, stored at creation
68+
* and used during settlement. Applicable to both IOUs and MPTs.
69+
*/
70+
TransferRate?: number
71+
72+
/**
73+
* The ledger index of the issuer's directory node associated with the Escrow.
74+
* Used when the issuer is neither the source nor destination account.
75+
*/
76+
IssuerNode?: number
6477
}

packages/xrpl/src/models/ledger/MPToken.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export interface MPToken extends BaseLedgerEntry, HasPreviousTxnID {
88
MPTAmount?: MPTAmount
99
Flags: number
1010
OwnerNode?: string
11+
LockedAmount?: string
1112
}

packages/xrpl/src/models/ledger/MPTokenIssuance.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export interface MPTokenIssuance extends BaseLedgerEntry, HasPreviousTxnID {
1010
TransferFee?: number
1111
MPTokenMetadata?: string
1212
OwnerNode?: string
13+
LockedAmount?: string
1314
}

packages/xrpl/src/models/transactions/accountSet.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export enum AccountSetAsfFlags {
6161
asfDisallowIncomingTrustline = 15,
6262
/** Permanently gain the ability to claw back issued IOUs */
6363
asfAllowTrustLineClawback = 16,
64+
/** Issuers allow their IOUs to be used as escrow amounts */
65+
asfAllowTrustLineLocking = 17,
6466
}
6567

6668
/**

packages/xrpl/src/models/transactions/escrowCreate.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { ValidationError } from '../../errors'
2+
import { Amount, MPTAmount } from '../common'
23

34
import {
45
Account,
56
BaseTransaction,
67
isAccount,
8+
isAmount,
79
isNumber,
810
validateBaseTransaction,
911
validateOptionalField,
@@ -18,11 +20,12 @@ import {
1820
export interface EscrowCreate extends BaseTransaction {
1921
TransactionType: 'EscrowCreate'
2022
/**
21-
* Amount of XRP, in drops, to deduct from the sender's balance and escrow.
22-
* Once escrowed, the XRP can either go to the Destination address (after the.
23-
* FinishAfter time) or returned to the sender (after the CancelAfter time).
23+
* The amount to deduct from the sender's balance and and set aside in escrow.
24+
* Once escrowed, this amount can either go to the Destination address (after any Finish times/conditions)
25+
* or returned to the sender (after any cancellation times/conditions). Can represent XRP, in drops,
26+
* an IOU token, or an MPT. Must always be a positive value.
2427
*/
25-
Amount: string
28+
Amount: Amount | MPTAmount
2629
/** Address to receive escrowed XRP. */
2730
Destination: Account
2831
/**
@@ -58,14 +61,7 @@ export interface EscrowCreate extends BaseTransaction {
5861
export function validateEscrowCreate(tx: Record<string, unknown>): void {
5962
validateBaseTransaction(tx)
6063

61-
if (tx.Amount === undefined) {
62-
throw new ValidationError('EscrowCreate: missing field Amount')
63-
}
64-
65-
if (typeof tx.Amount !== 'string') {
66-
throw new ValidationError('EscrowCreate: Amount must be a string')
67-
}
68-
64+
validateRequiredField(tx, 'Amount', isAmount)
6965
validateRequiredField(tx, 'Destination', isAccount)
7066
validateOptionalField(tx, 'DestinationTag', isNumber)
7167

0 commit comments

Comments
 (0)