Skip to content

Commit e514de7

Browse files
Add single asset vault (XLS-65d) (XRPLF#5224)
- Specification: XRPLF/XRPL-Standards#239 - Amendment: `SingleAssetVault` - Implements a vault feature used to store a fungible asset (XRP, IOU, or MPT, but not NFT) and to receive shares in the vault (an MPT) in exchange. - A vault can be private or public. - A private vault can use permissioned domains, subject to the `PermissionedDomains` amendment. - Shares can be exchanged back into asset with `VaultWithdraw`. - Permissions on the asset in the vault are transitively applied on shares in the vault. - Issuer of the asset in the vault can clawback with `VaultClawback`. - Extended `MPTokenIssuance` with `DomainID`, used by the permissioned domain on the vault shares. Co-authored-by: John Freeman <jfreeman08@gmail.com>
1 parent dd62cfc commit e514de7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+7257
-385
lines changed

include/xrpl/json/json_value.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
#ifndef RIPPLE_JSON_JSON_VALUE_H_INCLUDED
2121
#define RIPPLE_JSON_JSON_VALUE_H_INCLUDED
2222

23+
#include <xrpl/basics/Number.h>
2324
#include <xrpl/json/json_forwards.h>
2425

2526
#include <cstring>
2627
#include <map>
2728
#include <string>
29+
#include <utility>
2830
#include <vector>
2931

3032
/** \brief JSON (JavaScript Object Notation).
@@ -216,6 +218,7 @@ class Value
216218
Value(UInt value);
217219
Value(double value);
218220
Value(char const* value);
221+
Value(ripple::Number const& value);
219222
/** \brief Constructs a value from a static string.
220223
221224
* Like other value string constructor but do not duplicate the string for
@@ -365,6 +368,8 @@ class Value
365368
*/
366369
Value&
367370
operator[](StaticString const& key);
371+
Value const&
372+
operator[](StaticString const& key) const;
368373

369374
/// Return the member named key if it exist, defaultValue otherwise.
370375
Value
@@ -436,6 +441,12 @@ class Value
436441
int allocated_ : 1; // Notes: if declared as bool, bitfield is useless.
437442
};
438443

444+
inline Value
445+
to_json(ripple::Number const& number)
446+
{
447+
return to_string(number);
448+
}
449+
439450
bool
440451
operator==(Value const&, Value const&);
441452

include/xrpl/protocol/AMMCore.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,6 @@ class STObject;
4848
class STAmount;
4949
class Rules;
5050

51-
/** Calculate AMM account ID.
52-
*/
53-
AccountID
54-
ammAccountID(
55-
std::uint16_t prefix,
56-
uint256 const& parentHash,
57-
uint256 const& ammID);
58-
5951
/** Calculate Liquidity Provider Token (LPT) Currency.
6052
*/
6153
Currency

include/xrpl/protocol/Asset.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
#ifndef RIPPLE_PROTOCOL_ASSET_H_INCLUDED
2121
#define RIPPLE_PROTOCOL_ASSET_H_INCLUDED
2222

23+
#include <xrpl/basics/Number.h>
2324
#include <xrpl/basics/base_uint.h>
2425
#include <xrpl/protocol/Issue.h>
2526
#include <xrpl/protocol/MPTIssue.h>
2627

2728
namespace ripple {
2829

2930
class Asset;
31+
class STAmount;
3032

3133
template <typename TIss>
3234
concept ValidIssueType =
@@ -92,6 +94,9 @@ class Asset
9294
void
9395
setJson(Json::Value& jv) const;
9496

97+
STAmount
98+
operator()(Number const&) const;
99+
95100
bool
96101
native() const
97102
{
@@ -114,6 +119,14 @@ class Asset
114119
equalTokens(Asset const& lhs, Asset const& rhs);
115120
};
116121

122+
inline Json::Value
123+
to_json(Asset const& asset)
124+
{
125+
Json::Value jv;
126+
asset.setJson(jv);
127+
return jv;
128+
}
129+
117130
template <ValidIssueType TIss>
118131
constexpr bool
119132
Asset::holds() const
@@ -219,9 +232,6 @@ validJSONAsset(Json::Value const& jv);
219232
Asset
220233
assetFromJson(Json::Value const& jv);
221234

222-
Json::Value
223-
to_json(Asset const& asset);
224-
225235
} // namespace ripple
226236

227237
#endif // RIPPLE_PROTOCOL_ASSET_H_INCLUDED

include/xrpl/protocol/IOUAmount.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
#include <cstdint>
3030
#include <string>
31-
#include <utility>
3231

3332
namespace ripple {
3433

include/xrpl/protocol/Indexes.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,15 @@ mptoken(uint256 const& mptokenKey)
334334
Keylet
335335
mptoken(uint256 const& issuanceKey, AccountID const& holder) noexcept;
336336

337+
Keylet
338+
vault(AccountID const& owner, std::uint32_t seq) noexcept;
339+
340+
inline Keylet
341+
vault(uint256 const& vaultKey)
342+
{
343+
return {ltVAULT, vaultKey};
344+
}
345+
337346
Keylet
338347
permissionedDomain(AccountID const& account, std::uint32_t seq) noexcept;
339348

include/xrpl/protocol/LedgerFormats.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ enum LedgerSpecificFlags {
191191

192192
// ltCREDENTIAL
193193
lsfAccepted = 0x00010000,
194+
195+
// ltVAULT
196+
lsfVaultPrivate = 0x00010000,
194197
};
195198

196199
//------------------------------------------------------------------------------

include/xrpl/protocol/MPTAmount.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,12 @@
2424
#include <xrpl/basics/contract.h>
2525
#include <xrpl/basics/safe_cast.h>
2626
#include <xrpl/beast/utility/Zero.h>
27-
#include <xrpl/json/json_value.h>
2827

2928
#include <boost/multiprecision/cpp_int.hpp>
3029
#include <boost/operators.hpp>
3130

3231
#include <cstdint>
33-
#include <optional>
3432
#include <string>
35-
#include <type_traits>
3633

3734
namespace ripple {
3835

include/xrpl/protocol/MPTIssue.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ class MPTIssue
4242
AccountID const&
4343
getIssuer() const;
4444

45-
MPTID const&
46-
getMptID() const;
45+
constexpr MPTID const&
46+
getMptID() const
47+
{
48+
return mptID_;
49+
}
4750

4851
std::string
4952
getText() const;

include/xrpl/protocol/Protocol.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ std::size_t constexpr maxMPTokenMetadataLength = 1024;
116116
/** The maximum amount of MPTokenIssuance */
117117
std::uint64_t constexpr maxMPTokenAmount = 0x7FFF'FFFF'FFFF'FFFFull;
118118

119+
/** The maximum length of Data payload */
120+
std::size_t constexpr maxDataPayloadLength = 256;
121+
122+
/** Vault withdrawal policies */
123+
std::uint8_t constexpr vaultStrategyFirstComeFirstServe = 1;
124+
125+
/** Maximum recursion depth for vault shares being put as an asset inside
126+
* another vault; counted from 0 */
127+
std::uint8_t constexpr maxAssetCheckDepth = 5;
128+
119129
/** A ledger index. */
120130
using LedgerIndex = std::uint32_t;
121131

include/xrpl/protocol/SField.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
#include <cstdint>
2727
#include <map>
28-
#include <utility>
2928

3029
namespace ripple {
3130

0 commit comments

Comments
 (0)