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 <map>
#include <utility>
namespace ripple {

View File

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

View File

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

View File

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

View File

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