This commit is contained in:
John Freeman
2024-11-12 12:23:21 -06:00
committed by Bronek Kozicki
parent d09e74e548
commit 1680477e39
5 changed files with 19 additions and 13 deletions

View File

@@ -25,7 +25,6 @@
#include <cstdint> #include <cstdint>
#include <map> #include <map>
#include <utility>
namespace ripple { namespace ripple {

View File

@@ -198,6 +198,7 @@ class Vault_test : public beast::unit_test::suite
SUBCASE("MPT cannot transfer") SUBCASE("MPT cannot transfer")
{ {
MPTTester mptt{env, issuer, {.fund = false}}; MPTTester mptt{env, issuer, {.fund = false}};
// Locked because that is the default flag.
mptt.create(); mptt.create();
Asset asset = mptt.issuanceID(); Asset asset = mptt.issuanceID();
auto [tx, keylet] = vault.create({.owner = owner, .asset = asset}); auto [tx, keylet] = vault.create({.owner = owner, .asset = asset});

View File

@@ -82,14 +82,19 @@ VaultDeposit::doApply()
if (vault->getFlags() & lsfVaultPrivate) if (vault->getFlags() & lsfVaultPrivate)
; ;
// TODO: transfer amount from account_ to vault.PseudoAccount. auto const& vaultAccount = vault->at(sfAccount);
// - handles balance of account_ and vault.PseudoAccount // Transfer amount from sender to vault.
// TODO: increase vault.AssetTotal if (auto ter = accountSend(view(), account_, vaultAccount, amount, j_))
// TODO: increase vault.AssetAvailable return ter;
// TODO: calculate shares to give account_.
// TODO: grant shares from issuance to account_. vault->at(sfAssetTotal) += amount;
// - handles increasing account_.balance(vault.Asset) vault->at(sfAssetAvailable) += amount;
// - handles increasing mptIssuance.OutstandingAmount
auto shares = assetsToSharesDeposit(view(), vault, amount);
if (!shares)
return shares.error();
if (auto ter = accountSend(view(), vaultAccount, account_, *shares, j_))
return ter;
// TODO: copy mptIssuance.OutstandingAmount to vault.ShareTotal? // TODO: copy mptIssuance.OutstandingAmount to vault.ShareTotal?
return tesSUCCESS; return tesSUCCESS;

View File

@@ -621,7 +621,7 @@ deleteAMMTrustLine(
// From the perspective of a vault, // From the perspective of a vault,
// return the number of shares to give the depositor // return the number of shares to give the depositor
// when they deposit a fixed amount of assets. // when they deposit a fixed amount of assets.
[[nodiscard]] Expected<Number, TER> [[nodiscard]] Expected<STAmount, TER>
assetsToSharesDeposit( assetsToSharesDeposit(
ReadView const& view, ReadView const& view,
std::shared_ptr<SLE> const& vault, std::shared_ptr<SLE> const& vault,

View File

@@ -2227,7 +2227,7 @@ rippleCredit(
saAmount.asset().value()); saAmount.asset().value());
} }
Number static Number
getShareTotal(ReadView const& view, std::shared_ptr<SLE> const& vault) getShareTotal(ReadView const& view, std::shared_ptr<SLE> const& vault)
{ {
auto issuance = auto issuance =
@@ -2235,7 +2235,7 @@ getShareTotal(ReadView const& view, std::shared_ptr<SLE> const& vault)
return issuance->at(sfOutstandingAmount); return issuance->at(sfOutstandingAmount);
} }
[[nodiscard]] Expected<Number, TER> [[nodiscard]] Expected<STAmount, TER>
assetsToSharesDeposit( assetsToSharesDeposit(
ReadView const& view, ReadView const& view,
std::shared_ptr<SLE> const& vault, std::shared_ptr<SLE> const& vault,
@@ -2247,7 +2247,8 @@ assetsToSharesDeposit(
return assets; return assets;
Number shareTotal = getShareTotal(view, vault); Number shareTotal = getShareTotal(view, vault);
auto shares = shareTotal * (assets / assetTotal); auto shares = shareTotal * (assets / assetTotal);
return shares; STAmount amount{MPTAmount{shares}, MPTIssue{vault->at(sfMPTokenIssuanceID)}};
return amount;
} }
[[nodiscard]] Expected<Number, TER> [[nodiscard]] Expected<Number, TER>