Skip to content

Commit 8143935

Browse files
init draft
1 parent 0c89766 commit 8143935

File tree

11 files changed

+525
-0
lines changed

11 files changed

+525
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@ export default interface AccountRoot extends BaseLedgerEntry, HasPreviousTxnID {
7878
MintedNFTokens?: number
7979
/** Another account that can mint NFTokens on behalf of this account. */
8080
NFTokenMinter?: string
81+
/**
82+
* The address of the account sponsoring this account's reserve. Only present
83+
* if this account was created via a sponsored Payment transaction.
84+
*/
85+
Sponsor?: string
86+
/**
87+
* The number of ledger objects whose reserves are being sponsored by other
88+
* accounts on behalf of this account. This count does not contribute to the
89+
* owner reserve.
90+
*/
91+
SponsoredOwnerCount?: number
92+
/**
93+
* The number of ledger objects for which this account is sponsoring reserves
94+
* on behalf of other accounts.
95+
*/
96+
SponsoringOwnerCount?: number
97+
/**
98+
* The number of accounts for which this account is sponsoring the account
99+
* reserve (i.e., accounts created via sponsored Payment transactions where
100+
* this account was the sponsor).
101+
*/
102+
SponsoringAccountCount?: number
81103
}
82104

83105
/**

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import PayChannel from './PayChannel'
1919
import PermissionedDomain from './PermissionedDomain'
2020
import RippleState from './RippleState'
2121
import SignerList from './SignerList'
22+
import Sponsorship from './Sponsorship'
2223
import Ticket from './Ticket'
2324
import Vault from './Vault'
2425
import XChainOwnedClaimID from './XChainOwnedClaimID'
@@ -46,6 +47,7 @@ type LedgerEntry =
4647
| PermissionedDomain
4748
| RippleState
4849
| SignerList
50+
| Sponsorship
4951
| Ticket
5052
| Vault
5153
| XChainOwnedClaimID
@@ -76,6 +78,7 @@ type LedgerEntryFilter =
7678
| 'payment_channel'
7779
| 'permissioned_domain'
7880
| 'signer_list'
81+
| 'sponsorship'
7982
| 'state'
8083
| 'ticket'
8184
| 'vault'

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ export default interface RippleState extends BaseLedgerEntry, HasPreviousTxnID {
6161
* equivalent to 1 billion, or face value.
6262
*/
6363
HighQualityOut?: number
64+
/**
65+
* The address of the account sponsoring the reserve for the high account's
66+
* side of this trust line. Only present if the high account's reserve is
67+
* being sponsored.
68+
*/
69+
HighSponsor?: string
70+
/**
71+
* The address of the account sponsoring the reserve for the low account's
72+
* side of this trust line. Only present if the low account's reserve is
73+
* being sponsored.
74+
*/
75+
LowSponsor?: string
6476
}
6577

6678
export enum RippleStateFlags {
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { BaseLedgerEntry, HasPreviousTxnID } from './BaseLedgerEntry'
2+
3+
/**
4+
* Enum representing flags for a Sponsorship ledger entry.
5+
*
6+
* @category Ledger Entry Flags
7+
*/
8+
export enum SponsorshipFlags {
9+
/**
10+
* If set, each sponsored fee transaction requires a signature from the sponsor.
11+
*/
12+
lsfRequireSignForFee = 0x00010000,
13+
/**
14+
* If set, each sponsored reserve transaction requires a signature from the sponsor.
15+
*/
16+
lsfRequireSignForReserve = 0x00020000,
17+
}
18+
19+
/**
20+
* A boolean map of SponsorshipFlags for simplified code checking Sponsorship settings.
21+
*
22+
* @category Ledger Entry Flags
23+
*/
24+
export interface SponsorshipFlagsInterface {
25+
/**
26+
* If set, each sponsored fee transaction requires a signature from the sponsor.
27+
*/
28+
lsfRequireSignForFee?: boolean
29+
/**
30+
* If set, each sponsored reserve transaction requires a signature from the sponsor.
31+
*/
32+
lsfRequireSignForReserve?: boolean
33+
}
34+
35+
/**
36+
* The Sponsorship object represents a pre-funded sponsorship relationship
37+
* between a sponsor and a sponsee. It allows the sponsor to pay transaction
38+
* fees and/or reserves on behalf of the sponsee.
39+
*
40+
* @category Ledger Entries
41+
*/
42+
export default interface Sponsorship extends BaseLedgerEntry, HasPreviousTxnID {
43+
LedgerEntryType: 'Sponsorship'
44+
/** A bit-map of boolean flags enabled for this sponsorship. */
45+
Flags: number
46+
/**
47+
* The address of the sponsor account. This account pays for the reserve
48+
* of this ledger entry.
49+
*/
50+
Owner: string
51+
/**
52+
* The address of the sponsee account (the account being sponsored).
53+
*/
54+
Sponsee: string
55+
/**
56+
* The remaining amount of XRP (in drops) that the sponsor has provided
57+
* for the sponsee to use for transaction fees.
58+
*/
59+
FeeAmount: string
60+
/**
61+
* The maximum fee per transaction that will be sponsored. This is to
62+
* prevent abuse/excessive draining of the sponsored fee pool.
63+
*/
64+
MaxFee?: string
65+
/**
66+
* The remaining number of reserves that the sponsor has provided for the
67+
* sponsee to use. Each unit represents one object reserve.
68+
*/
69+
ReserveCount: number
70+
/**
71+
* A hint indicating which page of the sponsor's (owner's) directory links
72+
* to this object, in case the directory consists of multiple pages.
73+
*/
74+
OwnerNode: string
75+
/**
76+
* A hint indicating which page of the sponsee's directory links to this
77+
* object, in case the directory consists of multiple pages.
78+
*/
79+
SponseeNode: string
80+
}
81+

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ import Oracle from './Oracle'
3232
import PayChannel from './PayChannel'
3333
import RippleState, { RippleStateFlags } from './RippleState'
3434
import SignerList, { SignerListFlags } from './SignerList'
35+
import Sponsorship, {
36+
SponsorshipFlags,
37+
SponsorshipFlagsInterface,
38+
} from './Sponsorship'
3539
import Ticket from './Ticket'
3640
import Vault, { VaultFlags } from './Vault'
3741
import XChainOwnedClaimID from './XChainOwnedClaimID'
@@ -80,6 +84,9 @@ export {
8084
RippleStateFlags,
8185
SignerList,
8286
SignerListFlags,
87+
Sponsorship,
88+
SponsorshipFlags,
89+
SponsorshipFlagsInterface,
8390
Ticket,
8491
Vault,
8592
VaultFlags,

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

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,45 @@ export interface GlobalFlagsInterface {
456456
tfInnerBatchTxn?: boolean
457457
}
458458

459+
/**
460+
* Enum representing sponsor flags for transaction sponsorship.
461+
* These flags indicate what type of sponsorship is being applied to a transaction.
462+
*
463+
* @category Transaction Flags
464+
*/
465+
export enum SponsorFlags {
466+
/**
467+
* Indicates that the sponsor is paying the transaction fee.
468+
*/
469+
tfSponsorFee = 0x00000001,
470+
/**
471+
* Indicates that the sponsor is paying for the reserve of any objects
472+
* created in the transaction.
473+
*/
474+
tfSponsorReserve = 0x00000002,
475+
}
476+
477+
/**
478+
* The SponsorSignature object contains signing information for sponsored
479+
* transactions. It holds the sponsor's signature to authorize the sponsorship.
480+
*/
481+
export interface SponsorSignature {
482+
/**
483+
* The public key for the sponsor's account, if single-signing.
484+
*/
485+
SigningPubKey?: string
486+
/**
487+
* A signature from the sponsor to indicate their approval of the transaction,
488+
* if single-signing.
489+
*/
490+
TxnSignature?: string
491+
/**
492+
* An array of signatures from the sponsor's signers to indicate their approval
493+
* of the transaction, if the sponsor is multi-signing.
494+
*/
495+
Signers?: Signer[]
496+
}
497+
459498
/**
460499
* Every transaction has the same set of common fields.
461500
*/
@@ -534,6 +573,23 @@ export interface BaseTransaction extends Record<string, unknown> {
534573
* The delegate account that is sending the transaction.
535574
*/
536575
Delegate?: Account
576+
/**
577+
* The account ID of the sponsor for this transaction. If this field is
578+
* included, the sponsor is co-signing the transaction to pay for the fee
579+
* and/or reserve on behalf of the transaction sender.
580+
*/
581+
Sponsor?: Account
582+
/**
583+
* Flags indicating what type of sponsorship this is. Must be included if
584+
* Sponsor is included. Valid values are tfSponsorFee (1) and/or
585+
* tfSponsorReserve (2).
586+
*/
587+
SponsorFlags?: number
588+
/**
589+
* An object containing the sponsor's signature information to authorize
590+
* the sponsorship. Must be included if Sponsor is included.
591+
*/
592+
SponsorSignature?: SponsorSignature
537593
}
538594

539595
/**
@@ -610,6 +666,69 @@ export function validateBaseTransaction(
610666
'BaseTransaction: Account and Delegate addresses cannot be the same',
611667
)
612668
}
669+
670+
// Sponsor fields validation
671+
validateOptionalField(common, 'Sponsor', isAccount)
672+
validateOptionalField(common, 'SponsorFlags', isNumber)
673+
674+
// Validate SponsorSignature if present
675+
if (common.SponsorSignature !== undefined) {
676+
if (!isRecord(common.SponsorSignature)) {
677+
throw new ValidationError('BaseTransaction: invalid SponsorSignature')
678+
}
679+
const sponsorSig = common.SponsorSignature
680+
if (
681+
sponsorSig.SigningPubKey !== undefined &&
682+
!isString(sponsorSig.SigningPubKey)
683+
) {
684+
throw new ValidationError(
685+
'BaseTransaction: invalid SponsorSignature.SigningPubKey',
686+
)
687+
}
688+
if (
689+
sponsorSig.TxnSignature !== undefined &&
690+
!isString(sponsorSig.TxnSignature)
691+
) {
692+
throw new ValidationError(
693+
'BaseTransaction: invalid SponsorSignature.TxnSignature',
694+
)
695+
}
696+
if (
697+
sponsorSig.Signers !== undefined &&
698+
(!isArray(sponsorSig.Signers) ||
699+
sponsorSig.Signers.length === 0 ||
700+
!sponsorSig.Signers.every(isSigner))
701+
) {
702+
throw new ValidationError(
703+
'BaseTransaction: invalid SponsorSignature.Signers',
704+
)
705+
}
706+
}
707+
708+
// Validate that Sponsor, SponsorFlags, and SponsorSignature are all present or all absent
709+
const hasSponsor = common.Sponsor !== undefined
710+
const hasSponsorFlags = common.SponsorFlags !== undefined
711+
const hasSponsorSignature = common.SponsorSignature !== undefined
712+
713+
if (hasSponsor || hasSponsorFlags || hasSponsorSignature) {
714+
if (!hasSponsor || !hasSponsorFlags) {
715+
throw new ValidationError(
716+
'BaseTransaction: Sponsor and SponsorFlags must both be included if either is present',
717+
)
718+
}
719+
// SponsorSignature may be omitted if using pre-funded sponsorship without signature requirement
720+
}
721+
722+
// Validate SponsorFlags has valid values
723+
if (hasSponsorFlags) {
724+
const validFlags = SponsorFlags.tfSponsorFee | SponsorFlags.tfSponsorReserve
725+
const flags = common.SponsorFlags as number
726+
if ((flags & ~validFlags) !== 0 || flags === 0) {
727+
throw new ValidationError(
728+
'BaseTransaction: invalid SponsorFlags - must include tfSponsorFee and/or tfSponsorReserve',
729+
)
730+
}
731+
}
613732
}
614733

615734
/**

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ export {
33
GlobalFlags,
44
GlobalFlagsInterface,
55
isMPTAmount,
6+
SponsorFlags,
7+
SponsorSignature,
68
} from './common'
79
export {
810
validate,
@@ -118,6 +120,12 @@ export { PermissionedDomainDelete } from './permissionedDomainDelete'
118120
export { SetFee, SetFeePreAmendment, SetFeePostAmendment } from './setFee'
119121
export { SetRegularKey } from './setRegularKey'
120122
export { SignerListSet } from './signerListSet'
123+
export {
124+
SponsorshipSet,
125+
SponsorshipSetFlags,
126+
SponsorshipSetFlagsInterface,
127+
} from './sponsorshipSet'
128+
export { SponsorshipTransfer } from './sponsorshipTransfer'
121129
export { TicketCreate } from './ticketCreate'
122130
export { TrustSetFlagsInterface, TrustSetFlags, TrustSet } from './trustSet'
123131
export { UNLModify } from './UNLModify'

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ export enum PaymentFlags {
4343
* details.
4444
*/
4545
tfLimitQuality = 0x00040000,
46+
/**
47+
* If the Payment is used to create an account, the created account will be
48+
* sponsored by the transaction sender (Account). When this flag is enabled,
49+
* the XRP amount does not need to be greater than or equal to the account
50+
* reserve requirement.
51+
*/
52+
tfSponsorCreatedAccount = 0x00080000,
4653
}
4754

4855
/**
@@ -105,6 +112,13 @@ export interface PaymentFlagsInterface extends GlobalFlagsInterface {
105112
* details.
106113
*/
107114
tfLimitQuality?: boolean
115+
/**
116+
* If the Payment is used to create an account, the created account will be
117+
* sponsored by the transaction sender (Account). When this flag is enabled,
118+
* the XRP amount does not need to be greater than or equal to the account
119+
* reserve requirement.
120+
*/
121+
tfSponsorCreatedAccount?: boolean
108122
}
109123

110124
/**

0 commit comments

Comments
 (0)