rippled
Loading...
Searching...
No Matches
AMMUtils.cpp
1#include <xrpld/app/misc/AMMHelpers.h>
2#include <xrpld/app/misc/AMMUtils.h>
3
4#include <xrpl/basics/Log.h>
5#include <xrpl/ledger/Sandbox.h>
6#include <xrpl/protocol/AMMCore.h>
7#include <xrpl/protocol/STObject.h>
8
9namespace xrpl {
10
13 ReadView const& view,
14 AccountID const& ammAccountID,
15 Issue const& issue1,
16 Issue const& issue2,
17 FreezeHandling freezeHandling,
18 beast::Journal const j)
19{
20 auto const assetInBalance = accountHolds(view, ammAccountID, issue1, freezeHandling, j);
21 auto const assetOutBalance = accountHolds(view, ammAccountID, issue2, freezeHandling, j);
22 return std::make_pair(assetInBalance, assetOutBalance);
23}
24
25Expected<std::tuple<STAmount, STAmount, STAmount>, TER>
27 ReadView const& view,
28 SLE const& ammSle,
29 std::optional<Issue> const& optIssue1,
30 std::optional<Issue> const& optIssue2,
31 FreezeHandling freezeHandling,
32 beast::Journal const j)
33{
34 auto const issues = [&]() -> std::optional<std::pair<Issue, Issue>> {
35 auto const issue1 = ammSle[sfAsset].get<Issue>();
36 auto const issue2 = ammSle[sfAsset2].get<Issue>();
37 if (optIssue1 && optIssue2)
38 {
39 if (invalidAMMAssetPair(*optIssue1, *optIssue2, std::make_optional(std::make_pair(issue1, issue2))))
40 {
41 // This error can only be hit if the AMM is corrupted
42 // LCOV_EXCL_START
43 JLOG(j.debug()) << "ammHolds: Invalid optIssue1 or optIssue2 " << *optIssue1 << " " << *optIssue2;
44 return std::nullopt;
45 // LCOV_EXCL_STOP
46 }
47 return std::make_optional(std::make_pair(*optIssue1, *optIssue2));
48 }
49 auto const singleIssue = [&issue1, &issue2, &j](
50 Issue checkIssue, char const* label) -> std::optional<std::pair<Issue, Issue>> {
51 if (checkIssue == issue1)
52 return std::make_optional(std::make_pair(issue1, issue2));
53 else if (checkIssue == issue2)
54 return std::make_optional(std::make_pair(issue2, issue1));
55 // Unreachable unless AMM corrupted.
56 // LCOV_EXCL_START
57 JLOG(j.debug()) << "ammHolds: Invalid " << label << " " << checkIssue;
58 return std::nullopt;
59 // LCOV_EXCL_STOP
60 };
61 if (optIssue1)
62 {
63 return singleIssue(*optIssue1, "optIssue1");
64 }
65 else if (optIssue2)
66 {
67 // Cannot have Amount2 without Amount.
68 return singleIssue(*optIssue2, "optIssue2"); // LCOV_EXCL_LINE
69 }
70 return std::make_optional(std::make_pair(issue1, issue2));
71 }();
72 if (!issues)
74 auto const [asset1, asset2] =
75 ammPoolHolds(view, ammSle.getAccountID(sfAccount), issues->first, issues->second, freezeHandling, j);
76 return std::make_tuple(asset1, asset2, ammSle[sfLPTokenBalance]);
77}
78
79STAmount
81 ReadView const& view,
82 Currency const& cur1,
83 Currency const& cur2,
84 AccountID const& ammAccount,
85 AccountID const& lpAccount,
86 beast::Journal const j)
87{
88 // This function looks similar to `accountHolds`. However, it only checks if
89 // a LPToken holder has enough balance. On the other hand, `accountHolds`
90 // checks if the underlying assets of LPToken are frozen with the
91 // fixFrozenLPTokenTransfer amendment
92
93 auto const currency = ammLPTCurrency(cur1, cur2);
94 STAmount amount;
95
96 auto const sle = view.read(keylet::line(lpAccount, ammAccount, currency));
97 if (!sle)
98 {
99 amount.clear(Issue{currency, ammAccount});
100 JLOG(j.trace()) << "ammLPHolds: no SLE "
101 << " lpAccount=" << to_string(lpAccount) << " amount=" << amount.getFullText();
102 }
103 else if (isFrozen(view, lpAccount, currency, ammAccount))
104 {
105 amount.clear(Issue{currency, ammAccount});
106 JLOG(j.trace()) << "ammLPHolds: frozen currency "
107 << " lpAccount=" << to_string(lpAccount) << " amount=" << amount.getFullText();
108 }
109 else
110 {
111 amount = sle->getFieldAmount(sfBalance);
112 if (lpAccount > ammAccount)
113 {
114 // Put balance in account terms.
115 amount.negate();
116 }
117 amount.setIssuer(ammAccount);
118
119 JLOG(j.trace()) << "ammLPHolds:"
120 << " lpAccount=" << to_string(lpAccount) << " amount=" << amount.getFullText();
121 }
122
123 return view.balanceHook(lpAccount, ammAccount, amount);
124}
125
126STAmount
127ammLPHolds(ReadView const& view, SLE const& ammSle, AccountID const& lpAccount, beast::Journal const j)
128{
129 return ammLPHolds(
130 view,
131 ammSle[sfAsset].get<Issue>().currency,
132 ammSle[sfAsset2].get<Issue>().currency,
133 ammSle[sfAccount],
134 lpAccount,
135 j);
136}
137
139getTradingFee(ReadView const& view, SLE const& ammSle, AccountID const& account)
140{
141 using namespace std::chrono;
142 XRPL_ASSERT(
143 !view.rules().enabled(fixInnerObjTemplate) || ammSle.isFieldPresent(sfAuctionSlot),
144 "xrpl::getTradingFee : auction present");
145 if (ammSle.isFieldPresent(sfAuctionSlot))
146 {
147 auto const& auctionSlot = static_cast<STObject const&>(ammSle.peekAtField(sfAuctionSlot));
148 // Not expired
149 if (auto const expiration = auctionSlot[~sfExpiration];
150 duration_cast<seconds>(view.header().parentCloseTime.time_since_epoch()).count() < expiration)
151 {
152 if (auctionSlot[~sfAccount] == account)
153 return auctionSlot[sfDiscountedFee];
154 if (auctionSlot.isFieldPresent(sfAuthAccounts))
155 {
156 for (auto const& acct : auctionSlot.getFieldArray(sfAuthAccounts))
157 if (acct[~sfAccount] == account)
158 return auctionSlot[sfDiscountedFee];
159 }
160 }
161 }
162 return ammSle[sfTradingFee];
163}
164
165STAmount
166ammAccountHolds(ReadView const& view, AccountID const& ammAccountID, Issue const& issue)
167{
168 if (isXRP(issue))
169 {
170 if (auto const sle = view.read(keylet::account(ammAccountID)))
171 return (*sle)[sfBalance];
172 }
173 else if (auto const sle = view.read(keylet::line(ammAccountID, issue.account, issue.currency));
174 sle && !isFrozen(view, ammAccountID, issue.currency, issue.account))
175 {
176 auto amount = (*sle)[sfBalance];
177 if (ammAccountID > issue.account)
178 amount.negate();
179 amount.setIssuer(issue.account);
180 return amount;
181 }
182
183 return STAmount{issue};
184}
185
186static TER
187deleteAMMTrustLines(Sandbox& sb, AccountID const& ammAccountID, std::uint16_t maxTrustlinesToDelete, beast::Journal j)
188{
190 sb,
191 keylet::ownerDir(ammAccountID),
192 [&](LedgerEntryType nodeType, uint256 const&, std::shared_ptr<SLE>& sleItem) -> std::pair<TER, SkipEntry> {
193 // Skip AMM
194 if (nodeType == LedgerEntryType::ltAMM)
195 return {tesSUCCESS, SkipEntry::Yes};
196 // Should only have the trustlines
197 if (nodeType != LedgerEntryType::ltRIPPLE_STATE)
198 {
199 // LCOV_EXCL_START
200 JLOG(j.error()) << "deleteAMMTrustLines: deleting non-trustline " << nodeType;
201 return {tecINTERNAL, SkipEntry::No};
202 // LCOV_EXCL_STOP
203 }
204
205 // Trustlines must have zero balance
206 if (sleItem->getFieldAmount(sfBalance) != beast::zero)
207 {
208 // LCOV_EXCL_START
209 JLOG(j.error()) << "deleteAMMTrustLines: deleting trustline with "
210 "non-zero balance.";
211 return {tecINTERNAL, SkipEntry::No};
212 // LCOV_EXCL_STOP
213 }
214
215 return {deleteAMMTrustLine(sb, sleItem, ammAccountID, j), SkipEntry::No};
216 },
217 j,
218 maxTrustlinesToDelete);
219}
220
221TER
222deleteAMMAccount(Sandbox& sb, Issue const& asset, Issue const& asset2, beast::Journal j)
223{
224 auto ammSle = sb.peek(keylet::amm(asset, asset2));
225 if (!ammSle)
226 {
227 // LCOV_EXCL_START
228 JLOG(j.error()) << "deleteAMMAccount: AMM object does not exist " << asset << " " << asset2;
229 return tecINTERNAL;
230 // LCOV_EXCL_STOP
231 }
232
233 auto const ammAccountID = (*ammSle)[sfAccount];
234 auto sleAMMRoot = sb.peek(keylet::account(ammAccountID));
235 if (!sleAMMRoot)
236 {
237 // LCOV_EXCL_START
238 JLOG(j.error()) << "deleteAMMAccount: AMM account does not exist " << to_string(ammAccountID);
239 return tecINTERNAL;
240 // LCOV_EXCL_STOP
241 }
242
243 if (auto const ter = deleteAMMTrustLines(sb, ammAccountID, maxDeletableAMMTrustLines, j); ter != tesSUCCESS)
244 return ter;
245
246 auto const ownerDirKeylet = keylet::ownerDir(ammAccountID);
247 if (!sb.dirRemove(ownerDirKeylet, (*ammSle)[sfOwnerNode], ammSle->key(), false))
248 {
249 // LCOV_EXCL_START
250 JLOG(j.error()) << "deleteAMMAccount: failed to remove dir link";
251 return tecINTERNAL;
252 // LCOV_EXCL_STOP
253 }
254 if (sb.exists(ownerDirKeylet) && !sb.emptyDirDelete(ownerDirKeylet))
255 {
256 // LCOV_EXCL_START
257 JLOG(j.error()) << "deleteAMMAccount: cannot delete root dir node of " << toBase58(ammAccountID);
258 return tecINTERNAL;
259 // LCOV_EXCL_STOP
260 }
261
262 sb.erase(ammSle);
263 sb.erase(sleAMMRoot);
264
265 return tesSUCCESS;
266}
267
268void
270 ApplyView& view,
271 std::shared_ptr<SLE>& ammSle,
272 AccountID const& account,
273 Issue const& lptIssue,
274 std::uint16_t tfee)
275{
276 auto const& rules = view.rules();
277 // AMM creator gets the voting slot.
278 STArray voteSlots;
279 STObject voteEntry = STObject::makeInnerObject(sfVoteEntry);
280 if (tfee != 0)
281 voteEntry.setFieldU16(sfTradingFee, tfee);
282 voteEntry.setFieldU32(sfVoteWeight, VOTE_WEIGHT_SCALE_FACTOR);
283 voteEntry.setAccountID(sfAccount, account);
284 voteSlots.push_back(voteEntry);
285 ammSle->setFieldArray(sfVoteSlots, voteSlots);
286 // AMM creator gets the auction slot for free.
287 // AuctionSlot is created on AMMCreate and updated on AMMDeposit
288 // when AMM is in an empty state
289 if (rules.enabled(fixInnerObjTemplate) && !ammSle->isFieldPresent(sfAuctionSlot))
290 {
291 STObject auctionSlot = STObject::makeInnerObject(sfAuctionSlot);
292 ammSle->set(std::move(auctionSlot));
293 }
294 STObject& auctionSlot = ammSle->peekFieldObject(sfAuctionSlot);
295 auctionSlot.setAccountID(sfAccount, account);
296 // current + sec in 24h
297 auto const expiration =
298 std::chrono::duration_cast<std::chrono::seconds>(view.header().parentCloseTime.time_since_epoch()).count() +
300 auctionSlot.setFieldU32(sfExpiration, expiration);
301 auctionSlot.setFieldAmount(sfPrice, STAmount{lptIssue, 0});
302 // Set the fee
303 if (tfee != 0)
304 ammSle->setFieldU16(sfTradingFee, tfee);
305 else if (ammSle->isFieldPresent(sfTradingFee))
306 ammSle->makeFieldAbsent(sfTradingFee); // LCOV_EXCL_LINE
307 if (auto const dfee = tfee / AUCTION_SLOT_DISCOUNTED_FEE_FRACTION)
308 auctionSlot.setFieldU16(sfDiscountedFee, dfee);
309 else if (auctionSlot.isFieldPresent(sfDiscountedFee))
310 auctionSlot.makeFieldAbsent(sfDiscountedFee); // LCOV_EXCL_LINE
311}
312
313Expected<bool, TER>
314isOnlyLiquidityProvider(ReadView const& view, Issue const& ammIssue, AccountID const& lpAccount)
315{
316 // Liquidity Provider (LP) must have one LPToken trustline
317 std::uint8_t nLPTokenTrustLines = 0;
318 // There are at most two IOU trustlines. One or both could be to the LP
319 // if LP is the issuer, or a different account if LP is not an issuer.
320 // For instance, if AMM has two tokens USD and EUR and LP is not the issuer
321 // of the tokens then the trustlines are between AMM account and the issuer.
322 std::uint8_t nIOUTrustLines = 0;
323 // There is only one AMM object
324 bool hasAMM = false;
325 // AMM LP has at most three trustlines and only one AMM object must exist.
326 // If there are more than five objects then it's either an error or
327 // there are more than one LP. Ten pages should be sufficient to include
328 // five objects.
329 std::uint8_t limit = 10;
330 auto const root = keylet::ownerDir(ammIssue.account);
331 auto currentIndex = root;
332
333 // Iterate over AMM owner directory objects.
334 while (limit-- >= 1)
335 {
336 auto const ownerDir = view.read(currentIndex);
337 if (!ownerDir)
338 return Unexpected<TER>(tecINTERNAL); // LCOV_EXCL_LINE
339 for (auto const& key : ownerDir->getFieldV256(sfIndexes))
340 {
341 auto const sle = view.read(keylet::child(key));
342 if (!sle)
343 return Unexpected<TER>(tecINTERNAL); // LCOV_EXCL_LINE
344 // Only one AMM object
345 if (sle->getFieldU16(sfLedgerEntryType) == ltAMM)
346 {
347 if (hasAMM)
348 return Unexpected<TER>(tecINTERNAL); // LCOV_EXCL_LINE
349 hasAMM = true;
350 continue;
351 }
352 if (sle->getFieldU16(sfLedgerEntryType) != ltRIPPLE_STATE)
353 return Unexpected<TER>(tecINTERNAL); // LCOV_EXCL_LINE
354 auto const lowLimit = sle->getFieldAmount(sfLowLimit);
355 auto const highLimit = sle->getFieldAmount(sfHighLimit);
356 auto const isLPTrustline = lowLimit.getIssuer() == lpAccount || highLimit.getIssuer() == lpAccount;
357 auto const isLPTokenTrustline = lowLimit.issue() == ammIssue || highLimit.issue() == ammIssue;
358
359 // Liquidity Provider trustline
360 if (isLPTrustline)
361 {
362 // LPToken trustline
363 if (isLPTokenTrustline)
364 {
365 if (++nLPTokenTrustLines > 1)
366 return Unexpected<TER>(tecINTERNAL); // LCOV_EXCL_LINE
367 }
368 else if (++nIOUTrustLines > 2)
369 return Unexpected<TER>(tecINTERNAL); // LCOV_EXCL_LINE
370 }
371 // Another Liquidity Provider LPToken trustline
372 else if (isLPTokenTrustline)
373 return false;
374 else if (++nIOUTrustLines > 2)
375 return Unexpected<TER>(tecINTERNAL); // LCOV_EXCL_LINE
376 }
377 auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext);
378 if (uNodeNext == 0)
379 {
380 if (nLPTokenTrustLines != 1 || nIOUTrustLines == 0 || nIOUTrustLines > 2)
381 return Unexpected<TER>(tecINTERNAL); // LCOV_EXCL_LINE
382 return true;
383 }
384 currentIndex = keylet::page(root, uNodeNext);
385 }
386 return Unexpected<TER>(tecINTERNAL); // LCOV_EXCL_LINE
387}
388
389Expected<bool, TER>
391 Sandbox& sb,
392 STAmount const& lpTokens,
393 std::shared_ptr<SLE>& ammSle,
394 AccountID const& account)
395{
396 if (auto const res = isOnlyLiquidityProvider(sb, lpTokens.issue(), account); !res)
397 return Unexpected<TER>(res.error());
398 else if (res.value())
399 {
400 if (withinRelativeDistance(lpTokens, ammSle->getFieldAmount(sfLPTokenBalance), Number{1, -3}))
401 {
402 ammSle->setFieldAmount(sfLPTokenBalance, lpTokens);
403 sb.update(ammSle);
404 }
405 else
406 {
408 }
409 }
410 return true;
411}
412
413} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:41
Stream error() const
Definition Journal.h:319
Stream debug() const
Definition Journal.h:301
Stream trace() const
Severity stream access functions.
Definition Journal.h:295
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:115
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
bool emptyDirDelete(Keylet const &directory)
Remove the specified directory, if it is empty.
A currency issued by an account.
Definition Issue.h:14
Currency currency
Definition Issue.h:16
AccountID account
Definition Issue.h:17
Number is a floating point type that can represent a wide range of values.
Definition Number.h:208
A view into a ledger.
Definition ReadView.h:32
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual LedgerHeader const & header() const =0
Returns information about the ledger.
virtual STAmount balanceHook(AccountID const &account, AccountID const &issuer, STAmount const &amount) const
Definition ReadView.h:156
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Definition Rules.cpp:118
Issue const & issue() const
Definition STAmount.h:455
void push_back(STObject const &object)
Definition STArray.h:188
void setFieldU32(SField const &field, std::uint32_t)
Definition STObject.cpp:718
void setFieldAmount(SField const &field, STAmount const &)
Definition STObject.cpp:772
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:439
void setFieldU16(SField const &field, std::uint16_t)
Definition STObject.cpp:712
static STObject makeInnerObject(SField const &name)
Definition STObject.cpp:72
STBase const & peekAtField(SField const &field) const
Definition STObject.cpp:384
void setAccountID(SField const &field, AccountID const &)
Definition STObject.cpp:754
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:618
void makeFieldAbsent(SField const &field)
Definition STObject.cpp:525
Discardable, editable view to a ledger.
Definition Sandbox.h:16
void update(std::shared_ptr< SLE > const &sle) override
Indicate changes to a peeked SLE.
void erase(std::shared_ptr< SLE > const &sle) override
Remove a peeked SLE.
std::shared_ptr< SLE > peek(Keylet const &k) override
Prepare to modify the SLE associated with key.
bool exists(Keylet const &k) const override
Determine if a state item exists.
T is_same_v
T make_optional(T... args)
T make_pair(T... args)
T make_tuple(T... args)
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:325
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Definition Indexes.cpp:393
Keylet child(uint256 const &key) noexcept
Any item that can be in an owner dir.
Definition Indexes.cpp:166
Keylet line(AccountID const &id0, AccountID const &id1, Currency const &currency) noexcept
The index of a trust line for a given currency.
Definition Indexes.cpp:214
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:160
Keylet page(uint256 const &root, std::uint64_t index=0) noexcept
A page in a directory.
Definition Indexes.cpp:331
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
static TER deleteAMMTrustLines(Sandbox &sb, AccountID const &ammAccountID, std::uint16_t maxTrustlinesToDelete, beast::Journal j)
Definition AMMUtils.cpp:187
STAmount ammAccountHolds(ReadView const &view, AccountID const &ammAccountID, Issue const &issue)
Returns total amount held by AMM for the given token.
Definition AMMUtils.cpp:166
FreezeHandling
Controls the treatment of frozen account balances.
Definition View.h:59
TER deleteAMMAccount(Sandbox &view, Issue const &asset, Issue const &asset2, beast::Journal j)
Delete trustlines to AMM.
Definition AMMUtils.cpp:222
bool isXRP(AccountID const &c)
Definition AccountID.h:71
std::uint32_t constexpr VOTE_WEIGHT_SCALE_FACTOR
Definition AMMCore.h:25
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:598
std::uint32_t constexpr TOTAL_TIME_SLOT_SECS
Definition AMMCore.h:15
NotTEC invalidAMMAssetPair(Issue const &issue1, Issue const &issue2, std::optional< std::pair< Issue, Issue > > const &pair=std::nullopt)
Definition AMMCore.cpp:55
std::uint32_t constexpr AUCTION_SLOT_DISCOUNTED_FEE_FRACTION
Definition AMMCore.h:19
std::uint16_t constexpr maxDeletableAMMTrustLines
The maximum number of trustlines to delete as part of AMM account deletion cleanup.
Definition Protocol.h:266
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:92
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j, SpendableHandling includeFullBalance=shSIMPLE_BALANCE)
Definition View.cpp:392
Number root(Number f, unsigned d)
Definition Number.cpp:938
TER deleteAMMTrustLine(ApplyView &view, std::shared_ptr< SLE > sleState, std::optional< AccountID > const &ammAccountID, beast::Journal j)
Delete trustline to AMM.
Definition View.cpp:3036
Expected< bool, TER > isOnlyLiquidityProvider(ReadView const &view, Issue const &ammIssue, AccountID const &lpAccount)
Return true if the Liquidity Provider is the only AMM provider, false otherwise.
Definition AMMUtils.cpp:314
Expected< std::tuple< STAmount, STAmount, STAmount >, TER > ammHolds(ReadView const &view, SLE const &ammSle, std::optional< Issue > const &optIssue1, std::optional< Issue > const &optIssue2, FreezeHandling freezeHandling, beast::Journal const j)
Get AMM pool and LP token balances.
Definition AMMUtils.cpp:26
TERSubset< CanCvtToTER > TER
Definition TER.h:621
bool isFrozen(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer)
Definition View.cpp:194
void initializeFeeAuctionVote(ApplyView &view, std::shared_ptr< SLE > &ammSle, AccountID const &account, Issue const &lptIssue, std::uint16_t tfee)
Initialize Auction and Voting slots and set the trading/discounted fee.
Definition AMMUtils.cpp:269
std::pair< STAmount, STAmount > ammPoolHolds(ReadView const &view, AccountID const &ammAccountID, Issue const &issue1, Issue const &issue2, FreezeHandling freezeHandling, beast::Journal const j)
Get AMM pool balances.
Definition AMMUtils.cpp:12
LedgerEntryType
Identifiers for on-ledger objects.
bool withinRelativeDistance(Quality const &calcQuality, Quality const &reqQuality, Number const &dist)
Check if the relative distance between the qualities is within the requested distance.
Definition AMMHelpers.h:99
@ tecAMM_INVALID_TOKENS
Definition TER.h:313
@ tecINTERNAL
Definition TER.h:292
std::uint16_t getTradingFee(ReadView const &view, SLE const &ammSle, AccountID const &account)
Get AMM trading fee for the given account.
Definition AMMUtils.cpp:139
@ tesSUCCESS
Definition TER.h:226
TER cleanupOnAccountDelete(ApplyView &view, Keylet const &ownerDirKeylet, EntryDeleter const &deleter, beast::Journal j, std::optional< std::uint16_t > maxNodesToDelete=std::nullopt)
Cleanup owner directory entries on account delete.
STAmount ammLPHolds(ReadView const &view, Currency const &cur1, Currency const &cur2, AccountID const &ammAccount, AccountID const &lpAccount, beast::Journal const j)
Get the balance of LP tokens.
Definition AMMUtils.cpp:80
Expected< bool, TER > verifyAndAdjustLPTokenBalance(Sandbox &sb, STAmount const &lpTokens, std::shared_ptr< SLE > &ammSle, AccountID const &account)
Due to rounding, the LPTokenBalance of the last LP might not match the LP's trustline balance.
Definition AMMUtils.cpp:390
Currency ammLPTCurrency(Currency const &cur1, Currency const &cur2)
Calculate Liquidity Provider Token (LPT) Currency.
Definition AMMCore.cpp:24
NetClock::time_point parentCloseTime
T time_since_epoch(T... args)