Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
7d9dffc
Add AssetScale to VaultCreate
Bronek Aug 4, 2025
b17b167
Add AssetScale to VaultDeposit
Bronek Aug 4, 2025
a38d7bf
Add round-trip calculation to VaultWithdraw and VaultClawback
Bronek Aug 6, 2025
622ef6e
Merge branch 'develop' into Bronek/Vault_add_AssetScale
Bronek Aug 6, 2025
f374d5a
Enable IOU permission test again
Bronek Aug 7, 2025
87a9558
Implement Number::truncate()
Bronek Aug 7, 2025
b302670
Fixes for truncation and unit tests
Bronek Aug 7, 2025
76fd2e8
Merge branch 'develop' into Bronek/Vault_add_AssetScale
Bronek Aug 8, 2025
6c31556
Merge branch 'develop' into Bronek/Vault_add_AssetScale
Bronek Aug 11, 2025
c788564
Only apply AssetScale to IOU
Bronek Aug 8, 2025
ff48d67
Rounding in DepositWithdraw
Bronek Aug 11, 2025
2b75960
Merge branch 'develop' into Bronek/Vault_add_AssetScale
Bronek Aug 12, 2025
a484b6e
More unit tests
Bronek Aug 15, 2025
44b60fe
Disallow zero shares withdraw or deposit
Bronek Aug 15, 2025
09190db
Withdraw/clawback last of shares
Bronek Aug 15, 2025
97e44c7
Fix handling of AssetsAvailable in Clawback
Bronek Aug 15, 2025
35671ff
Remve redundant check
Bronek Aug 15, 2025
65dce68
Merge branch 'develop' into Bronek/Vault_add_AssetScale
Bronek Aug 18, 2025
2047661
Rename AssetScale to Scale, more tests
Bronek Aug 18, 2025
d365a2d
Merge branch 'develop' into Bronek/Vault_add_AssetScale
Bronek Aug 19, 2025
f0e83dc
Fix unit tests
Bronek Aug 19, 2025
e9354a2
Return tecPATH_DRY on overflow when converting shares/assets
Bronek Aug 19, 2025
6d5389f
Remove empty shares MPToken in clawback or withdraw
Bronek Aug 19, 2025
cf2536b
More unit tests
Bronek Aug 19, 2025
5e92e5b
Merge branch 'develop' into Bronek/Vault_add_AssetScale
Bronek Aug 19, 2025
3d88043
Review feedback
Bronek Aug 20, 2025
3fe388a
Use tecPRECISION_LOSS for zero shares
Bronek Aug 20, 2025
7938612
More review feedback
Bronek Aug 20, 2025
97c4578
Implicitly create shares MPToken for vault owner
Bronek Aug 20, 2025
b288d24
Do not store scale=0 in soeDEFAULT field
Bronek Aug 20, 2025
93df6ce
Merge branch 'develop' into Bronek/Vault_add_AssetScale
ximinez Aug 26, 2025
1d7992b
Merge branch 'develop' into Bronek/Vault_add_AssetScale
Bronek Aug 28, 2025
8c8e027
Review feedback: do not ignore error from removeEmptyHolding
Bronek Aug 28, 2025
d24632d
Review feedback: add !isTesSuccess(ter)
Bronek Aug 28, 2025
0d046da
Review feedback: use lsfVaultPrivate as appropriate, remove redundant…
Bronek Aug 28, 2025
d145666
Review feedback: defensive checks in shares/assets calculations
Bronek Aug 28, 2025
37196b7
Review feedback: comment update
Bronek Aug 28, 2025
c9e4b4a
Merge branch 'develop' into Bronek/Vault_add_AssetScale
Bronek Aug 29, 2025
76c3cff
Review feedback: logging
Bronek Aug 29, 2025
3689246
Merge branch 'develop' into Bronek/Vault_add_AssetScale
Bronek Sep 3, 2025
a763642
Review feedback
Bronek Sep 3, 2025
6893015
Minor improvements from review
Bronek Sep 3, 2025
011c3c6
Merge branch 'develop' into Bronek/Vault_add_AssetScale
Bronek Sep 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions include/xrpl/basics/Number.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,24 @@ class Number
return (mantissa_ < 0) ? -1 : (mantissa_ ? 1 : 0);
}

Number
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can simplify or maybe just use combination of towards_zero rounding and static_cast since truncate() usage is limited.

inline Number
Number::truncate() const noexcept
{
    if (exponent_ >= 0 || mantissa_ == 0)
        return *this;

    NumberRoundModeGuard mg(Number::towards_zero);
    return static_cast<rep>(*this);
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if that would be an improvement, given the complexity of operator rep(). On the other hand, normalize() is also quite complex. However with the current implementation we can guarantee noexcept and I am not sure how this would look like if we used operator rep()

I will add a comment about noexcept and leave it like this for now.

truncate() const noexcept
{
if (exponent_ >= 0 || mantissa_ == 0)
return *this;

Number ret = *this;
while (ret.exponent_ < 0 && ret.mantissa_ != 0)
{
ret.exponent_ += 1;
ret.mantissa_ /= rep(10);
}
// We are guaranteed that normalize() will never throw an exception
// because exponent is either negative or zero at this point.
ret.normalize();
return ret;
}

friend constexpr bool
operator>(Number const& x, Number const& y) noexcept
{
Expand Down
7 changes: 7 additions & 0 deletions include/xrpl/protocol/Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ std::size_t constexpr maxDataPayloadLength = 256;
/** Vault withdrawal policies */
std::uint8_t constexpr vaultStrategyFirstComeFirstServe = 1;

/** Default IOU scale factor for a Vault */
std::uint8_t constexpr vaultDefaultIOUScale = 6;
/** Maximum scale factor for a Vault. The number is chosen to ensure that
1 IOU can be always converted to shares.
10^19 > maxMPTokenAmount (2^64-1) > 10^18 */
std::uint8_t constexpr vaultMaximumIOUScale = 18;

/** Maximum recursion depth for vault shares being put as an asset inside
* another vault; counted from 0 */
std::uint8_t constexpr maxAssetCheckDepth = 5;
Expand Down
1 change: 1 addition & 0 deletions include/xrpl/protocol/detail/ledger_entries.macro
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ LEDGER_ENTRY(ltVAULT, 0x0084, Vault, vault, ({
{sfLossUnrealized, soeREQUIRED},
{sfShareMPTID, soeREQUIRED},
{sfWithdrawalPolicy, soeREQUIRED},
{sfScale, soeDEFAULT},
// no SharesTotal ever (use MPTIssuance.sfOutstandingAmount)
// no PermissionedDomainID ever (use MPTIssuance.sfDomainID)
}))
Expand Down
1 change: 1 addition & 0 deletions include/xrpl/protocol/detail/transactions.macro
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ TRANSACTION(ttVAULT_CREATE, 65, VaultCreate, Delegation::delegatable, ({
{sfDomainID, soeOPTIONAL},
{sfWithdrawalPolicy, soeOPTIONAL},
{sfData, soeOPTIONAL},
{sfScale, soeOPTIONAL},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be sfShareScale to stress that it applies to the shares?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sfScale is used to similar effect elsewhere already; I think it's better to stick to this name.

}))

/** This transaction updates a single asset vault. */
Expand Down
Loading