Skip to content

Commit a1dd179

Browse files
committed
Upcoming changes to Single Asset Vault (DGE-7974)
Adds support for the pending XLS-65 updates in XRPL-Standards#469 and XRPL-Standards#470, matching the rippled implementation: - VaultDelete gains an optional MemoData field (rippled uses sfMemoData, gated behind fixLendingProtocolV1_1) so the vault owner can record why the vault is being deleted. - VaultFlags gains lsfVaultDepositBlocked (0x00020000) and lsfVaultOwnerCanBlockDeposit (0x00040000). - VaultCreateFlags gains tfVaultOwnerCanBlockDeposit (0x00040000), which may only be set at vault creation. - New VaultSetFlags with tfVaultDepositBlock (0x00010000) and tfVaultDepositUnblock (0x00020000); VaultSet#flags() now returns it instead of the generic TransactionFlags. - New VaultDepositFlags with tfVaultDonate (0x00010000); VaultDeposit#flags() now returns it instead of the generic TransactionFlags.
1 parent 1a964ed commit a1dd179

14 files changed

Lines changed: 730 additions & 22 deletions

File tree

xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/flags/VaultCreateFlags.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public class VaultCreateFlags extends TransactionFlags {
2222
*/
2323
public static final VaultCreateFlags VAULT_SHARE_NON_TRANSFERABLE = new VaultCreateFlags(0x00020000L);
2424

25+
/**
26+
* Constant {@link VaultCreateFlags} for the {@code tfVaultOwnerCanBlockDeposit} flag.
27+
*/
28+
public static final VaultCreateFlags VAULT_OWNER_CAN_BLOCK_DEPOSIT = new VaultCreateFlags(0x00040000L);
29+
2530
private VaultCreateFlags(long value) {
2631
super(value);
2732
}
@@ -52,12 +57,14 @@ public static VaultCreateFlags of(long value) {
5257
private static VaultCreateFlags of(
5358
boolean tfFullyCanonicalSig,
5459
boolean tfVaultPrivate,
55-
boolean tfVaultShareNonTransferable
60+
boolean tfVaultShareNonTransferable,
61+
boolean tfVaultOwnerCanBlockDeposit
5662
) {
5763
long value = Flags.of(
5864
tfFullyCanonicalSig ? TransactionFlags.FULLY_CANONICAL_SIG : UNSET,
5965
tfVaultPrivate ? VAULT_PRIVATE : UNSET,
60-
tfVaultShareNonTransferable ? VAULT_SHARE_NON_TRANSFERABLE : UNSET
66+
tfVaultShareNonTransferable ? VAULT_SHARE_NON_TRANSFERABLE : UNSET,
67+
tfVaultOwnerCanBlockDeposit ? VAULT_OWNER_CAN_BLOCK_DEPOSIT : UNSET
6168
).getValue();
6269
return new VaultCreateFlags(value);
6370
}
@@ -90,13 +97,25 @@ public boolean tfVaultShareNonTransferable() {
9097
return this.isSet(VaultCreateFlags.VAULT_SHARE_NON_TRANSFERABLE);
9198
}
9299

100+
/**
101+
* If enabled, the vault owner may block and unblock deposits into the vault via a
102+
* {@link org.xrpl.xrpl4j.model.transactions.VaultSet} transaction. This flag can only be set when the vault is
103+
* created.
104+
*
105+
* @return {@code true} if {@code tfVaultOwnerCanBlockDeposit} is set, otherwise {@code false}.
106+
*/
107+
public boolean tfVaultOwnerCanBlockDeposit() {
108+
return this.isSet(VaultCreateFlags.VAULT_OWNER_CAN_BLOCK_DEPOSIT);
109+
}
110+
93111
/**
94112
* A builder class for {@link VaultCreateFlags} flags.
95113
*/
96114
public static class Builder {
97115

98116
private boolean tfVaultPrivate = false;
99117
private boolean tfVaultShareNonTransferable = false;
118+
private boolean tfVaultOwnerCanBlockDeposit = false;
100119

101120
/**
102121
* Set {@code tfVaultPrivate} to the given value.
@@ -122,6 +141,18 @@ public Builder tfVaultShareNonTransferable(boolean tfVaultShareNonTransferable)
122141
return this;
123142
}
124143

144+
/**
145+
* Set {@code tfVaultOwnerCanBlockDeposit} to the given value.
146+
*
147+
* @param tfVaultOwnerCanBlockDeposit A boolean value.
148+
*
149+
* @return The same {@link Builder}.
150+
*/
151+
public Builder tfVaultOwnerCanBlockDeposit(boolean tfVaultOwnerCanBlockDeposit) {
152+
this.tfVaultOwnerCanBlockDeposit = tfVaultOwnerCanBlockDeposit;
153+
return this;
154+
}
155+
125156
/**
126157
* Build a new {@link VaultCreateFlags} from the current boolean values.
127158
*
@@ -131,7 +162,8 @@ public VaultCreateFlags build() {
131162
return VaultCreateFlags.of(
132163
true,
133164
tfVaultPrivate,
134-
tfVaultShareNonTransferable
165+
tfVaultShareNonTransferable,
166+
tfVaultOwnerCanBlockDeposit
135167
);
136168
}
137169
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package org.xrpl.xrpl4j.model.flags;
2+
3+
import com.google.common.annotations.Beta;
4+
import org.xrpl.xrpl4j.model.transactions.VaultDeposit;
5+
6+
/**
7+
* A set of static {@link TransactionFlags} which can be set on {@link VaultDeposit} transactions.
8+
*
9+
* <p>This class will be marked {@link Beta} until the SingleAssetVault amendment is enabled on mainnet. Its API is
10+
* subject to change.</p>
11+
*/
12+
@Beta
13+
public class VaultDepositFlags extends TransactionFlags {
14+
15+
/**
16+
* Constant {@link VaultDepositFlags} for the {@code tfVaultDonate} flag.
17+
*/
18+
public static final VaultDepositFlags VAULT_DONATE = new VaultDepositFlags(0x00010000L);
19+
20+
private VaultDepositFlags(long value) {
21+
super(value);
22+
}
23+
24+
private VaultDepositFlags() {
25+
}
26+
27+
/**
28+
* Create a new {@link Builder}.
29+
*
30+
* @return A new {@link Builder}.
31+
*/
32+
public static Builder builder() {
33+
return new Builder();
34+
}
35+
36+
/**
37+
* Construct {@link VaultDepositFlags} with a given value.
38+
*
39+
* @param value The long-number encoded flags value of this {@link VaultDepositFlags}.
40+
*
41+
* @return New {@link VaultDepositFlags}.
42+
*/
43+
public static VaultDepositFlags of(long value) {
44+
return new VaultDepositFlags(value);
45+
}
46+
47+
private static VaultDepositFlags of(boolean tfFullyCanonicalSig, boolean tfVaultDonate) {
48+
long value = Flags.of(
49+
tfFullyCanonicalSig ? TransactionFlags.FULLY_CANONICAL_SIG : UNSET,
50+
tfVaultDonate ? VAULT_DONATE : UNSET
51+
).getValue();
52+
return new VaultDepositFlags(value);
53+
}
54+
55+
/**
56+
* Construct an empty instance of {@link VaultDepositFlags}. Transactions with empty flags will not be serialized
57+
* with a {@code Flags} field.
58+
*
59+
* @return An empty {@link VaultDepositFlags}.
60+
*/
61+
public static VaultDepositFlags empty() {
62+
return new VaultDepositFlags();
63+
}
64+
65+
/**
66+
* If enabled, the deposited assets are donated to the vault, meaning the depositor receives no shares in return.
67+
* Only the vault owner may donate to a vault.
68+
*
69+
* @return {@code true} if {@code tfVaultDonate} is set, otherwise {@code false}.
70+
*/
71+
public boolean tfVaultDonate() {
72+
return this.isSet(VaultDepositFlags.VAULT_DONATE);
73+
}
74+
75+
/**
76+
* A builder class for {@link VaultDepositFlags} flags.
77+
*/
78+
public static class Builder {
79+
80+
private boolean tfVaultDonate = false;
81+
82+
/**
83+
* Set {@code tfVaultDonate} to the given value.
84+
*
85+
* @param tfVaultDonate A boolean value.
86+
*
87+
* @return The same {@link Builder}.
88+
*/
89+
public Builder tfVaultDonate(boolean tfVaultDonate) {
90+
this.tfVaultDonate = tfVaultDonate;
91+
return this;
92+
}
93+
94+
/**
95+
* Build a new {@link VaultDepositFlags} from the current boolean values.
96+
*
97+
* @return A new {@link VaultDepositFlags}.
98+
*/
99+
public VaultDepositFlags build() {
100+
return VaultDepositFlags.of(true, tfVaultDonate);
101+
}
102+
}
103+
}

xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/flags/VaultFlags.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ public class VaultFlags extends Flags {
2121
*/
2222
public static final VaultFlags VAULT_PRIVATE = new VaultFlags(0x00010000);
2323

24+
/**
25+
* Constant {@link VaultFlags} for the {@code lsfVaultDepositBlocked} flag.
26+
*/
27+
public static final VaultFlags VAULT_DEPOSIT_BLOCKED = new VaultFlags(0x00020000);
28+
29+
/**
30+
* Constant {@link VaultFlags} for the {@code lsfVaultOwnerCanBlockDeposit} flag.
31+
*/
32+
public static final VaultFlags VAULT_OWNER_CAN_BLOCK_DEPOSIT = new VaultFlags(0x00040000);
33+
2434
/**
2535
* Required-args Constructor.
2636
*
@@ -50,4 +60,22 @@ public boolean lsfVaultPrivate() {
5060
return this.isSet(VaultFlags.VAULT_PRIVATE);
5161
}
5262

63+
/**
64+
* If set, indicates that deposits into the vault are blocked.
65+
*
66+
* @return {@code true} if {@code lsfVaultDepositBlocked} is set, otherwise {@code false}.
67+
*/
68+
public boolean lsfVaultDepositBlocked() {
69+
return this.isSet(VaultFlags.VAULT_DEPOSIT_BLOCKED);
70+
}
71+
72+
/**
73+
* If set, indicates that the vault owner can block and unblock deposits into the vault.
74+
*
75+
* @return {@code true} if {@code lsfVaultOwnerCanBlockDeposit} is set, otherwise {@code false}.
76+
*/
77+
public boolean lsfVaultOwnerCanBlockDeposit() {
78+
return this.isSet(VaultFlags.VAULT_OWNER_CAN_BLOCK_DEPOSIT);
79+
}
80+
5381
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
package org.xrpl.xrpl4j.model.flags;
2+
3+
import com.google.common.annotations.Beta;
4+
import org.xrpl.xrpl4j.model.transactions.VaultSet;
5+
6+
/**
7+
* A set of static {@link TransactionFlags} which can be set on {@link VaultSet} transactions.
8+
*
9+
* <p>This class will be marked {@link Beta} until the SingleAssetVault amendment is enabled on mainnet. Its API is
10+
* subject to change.</p>
11+
*/
12+
@Beta
13+
public class VaultSetFlags extends TransactionFlags {
14+
15+
/**
16+
* Constant {@link VaultSetFlags} for the {@code tfVaultDepositBlock} flag.
17+
*/
18+
public static final VaultSetFlags VAULT_DEPOSIT_BLOCK = new VaultSetFlags(0x00010000L);
19+
20+
/**
21+
* Constant {@link VaultSetFlags} for the {@code tfVaultDepositUnblock} flag.
22+
*/
23+
public static final VaultSetFlags VAULT_DEPOSIT_UNBLOCK = new VaultSetFlags(0x00020000L);
24+
25+
private VaultSetFlags(long value) {
26+
super(value);
27+
}
28+
29+
private VaultSetFlags() {
30+
}
31+
32+
/**
33+
* Create a new {@link Builder}.
34+
*
35+
* @return A new {@link Builder}.
36+
*/
37+
public static Builder builder() {
38+
return new Builder();
39+
}
40+
41+
/**
42+
* Construct {@link VaultSetFlags} with a given value.
43+
*
44+
* @param value The long-number encoded flags value of this {@link VaultSetFlags}.
45+
*
46+
* @return New {@link VaultSetFlags}.
47+
*/
48+
public static VaultSetFlags of(long value) {
49+
return new VaultSetFlags(value);
50+
}
51+
52+
private static VaultSetFlags of(
53+
boolean tfFullyCanonicalSig,
54+
boolean tfVaultDepositBlock,
55+
boolean tfVaultDepositUnblock
56+
) {
57+
long value = Flags.of(
58+
tfFullyCanonicalSig ? TransactionFlags.FULLY_CANONICAL_SIG : UNSET,
59+
tfVaultDepositBlock ? VAULT_DEPOSIT_BLOCK : UNSET,
60+
tfVaultDepositUnblock ? VAULT_DEPOSIT_UNBLOCK : UNSET
61+
).getValue();
62+
return new VaultSetFlags(value);
63+
}
64+
65+
/**
66+
* Construct an empty instance of {@link VaultSetFlags}. Transactions with empty flags will not be serialized with a
67+
* {@code Flags} field.
68+
*
69+
* @return An empty {@link VaultSetFlags}.
70+
*/
71+
public static VaultSetFlags empty() {
72+
return new VaultSetFlags();
73+
}
74+
75+
/**
76+
* If enabled, deposits into the vault are blocked. This flag may only be used if the vault has the
77+
* {@code lsfVaultOwnerCanBlockDeposit} flag set, and may not be combined with {@code tfVaultDepositUnblock}.
78+
*
79+
* @return {@code true} if {@code tfVaultDepositBlock} is set, otherwise {@code false}.
80+
*/
81+
public boolean tfVaultDepositBlock() {
82+
return this.isSet(VaultSetFlags.VAULT_DEPOSIT_BLOCK);
83+
}
84+
85+
/**
86+
* If enabled, deposits into the vault are unblocked. This flag may only be used if the vault has the
87+
* {@code lsfVaultOwnerCanBlockDeposit} flag set, and may not be combined with {@code tfVaultDepositBlock}.
88+
*
89+
* @return {@code true} if {@code tfVaultDepositUnblock} is set, otherwise {@code false}.
90+
*/
91+
public boolean tfVaultDepositUnblock() {
92+
return this.isSet(VaultSetFlags.VAULT_DEPOSIT_UNBLOCK);
93+
}
94+
95+
/**
96+
* A builder class for {@link VaultSetFlags} flags.
97+
*/
98+
public static class Builder {
99+
100+
private boolean tfVaultDepositBlock = false;
101+
private boolean tfVaultDepositUnblock = false;
102+
103+
/**
104+
* Set {@code tfVaultDepositBlock} to the given value.
105+
*
106+
* @param tfVaultDepositBlock A boolean value.
107+
*
108+
* @return The same {@link Builder}.
109+
*/
110+
public Builder tfVaultDepositBlock(boolean tfVaultDepositBlock) {
111+
this.tfVaultDepositBlock = tfVaultDepositBlock;
112+
return this;
113+
}
114+
115+
/**
116+
* Set {@code tfVaultDepositUnblock} to the given value.
117+
*
118+
* @param tfVaultDepositUnblock A boolean value.
119+
*
120+
* @return The same {@link Builder}.
121+
*/
122+
public Builder tfVaultDepositUnblock(boolean tfVaultDepositUnblock) {
123+
this.tfVaultDepositUnblock = tfVaultDepositUnblock;
124+
return this;
125+
}
126+
127+
/**
128+
* Build a new {@link VaultSetFlags} from the current boolean values.
129+
*
130+
* @return A new {@link VaultSetFlags}.
131+
*/
132+
public VaultSetFlags build() {
133+
return VaultSetFlags.of(
134+
true,
135+
tfVaultDepositBlock,
136+
tfVaultDepositUnblock
137+
);
138+
}
139+
}
140+
}

xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/VaultDelete.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.immutables.value.Value;
88
import org.xrpl.xrpl4j.model.flags.TransactionFlags;
99

10+
import java.util.Optional;
11+
1012
/**
1113
* Delete a single asset vault. The vault must have no remaining assets or outstanding shares.
1214
*
@@ -47,4 +49,13 @@ default TransactionFlags flags() {
4749
@JsonProperty("VaultID")
4850
Hash256 vaultId();
4951

52+
/**
53+
* Arbitrary metadata recording why the vault is being deleted, limited to 256 bytes, in hex format. This field
54+
* requires the {@code fixLendingProtocolV1_1} amendment.
55+
*
56+
* @return An optionally-present {@link VaultData}.
57+
*/
58+
@JsonProperty("MemoData")
59+
Optional<VaultData> memoData();
60+
5061
}

0 commit comments

Comments
 (0)