Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replicate OfferCreate functionality in Payments to Self #5090

Open
donovanhide opened this issue Aug 2, 2024 · 2 comments
Open

Replicate OfferCreate functionality in Payments to Self #5090

donovanhide opened this issue Aug 2, 2024 · 2 comments
Labels
Feature Request Used to indicate requests to add new features

Comments

@donovanhide
Copy link
Contributor

donovanhide commented Aug 2, 2024

Summary

I want to use Payments to condense multiple OfferCreates into a single Payment to self, i.e. a Payment where Account and Destination are the same. To do this I need to have a LimitAmount which exceeds the Amount of the Payment. If I were to consume the same chain of offers using OfferCreate no such LimitAmount would be required and in fact, no existing TrustLine/RippleState is required.

Motivation

To reduce transaction counts for arbitrage, by using fewer Payment transactions than OfferCreate transactions and to avoid unnecessary TrustSet transactions.

Solution

Remove the check for a LimitAmount exceeding Amount for Payments to self.

@donovanhide donovanhide added the Feature Request Used to indicate requests to add new features label Aug 2, 2024
@donovanhide
Copy link
Contributor Author

donovanhide commented Aug 2, 2024

Relevant code is here:

TER
DirectIPaymentStep::check(
StrandContext const& ctx,
std::shared_ptr<const SLE> const& sleSrc) const
{
// Since this is a payment a trust line must be present. Perform all
// trust line related checks.
{
auto const sleLine = ctx.view.read(keylet::line(src_, dst_, currency_));
if (!sleLine)
{
JLOG(j_.trace()) << "DirectStepI: No credit line. " << *this;
return terNO_LINE;
}
auto const authField = (src_ > dst_) ? lsfHighAuth : lsfLowAuth;
if (((*sleSrc)[sfFlags] & lsfRequireAuth) &&
!((*sleLine)[sfFlags] & authField) &&
(*sleLine)[sfBalance] == beast::zero)
{
JLOG(j_.warn())
<< "DirectStepI: can't receive IOUs from issuer without auth."
<< " src: " << src_;
return terNO_AUTH;
}
if (ctx.prevStep)
{
if (ctx.prevStep->bookStepBook())
{
auto const noRippleSrcToDst =
((*sleLine)[sfFlags] &
((src_ > dst_) ? lsfHighNoRipple : lsfLowNoRipple));
if (noRippleSrcToDst)
return terNO_RIPPLE;
}
}
}
{
auto const owed = creditBalance(ctx.view, dst_, src_, currency_);
if (owed <= beast::zero)
{
auto const limit = creditLimit(ctx.view, dst_, src_, currency_);
if (-owed >= limit)
{
JLOG(j_.debug()) << "DirectStepI: dry: owed: " << owed
<< " limit: " << limit;
return tecPATH_DRY;
}
}
}
return tesSUCCESS;
}

I'd argue, once the Auth and NoRipple checks are passed, if Payment's Account is equal to Destination, the line should be created, if it does not exist, and the LimitAmount ignored.

@tequdev
Copy link
Contributor

tequdev commented Aug 19, 2024

I have previously written code that allows a Payment transaction (to self) to create a trustline automatically in the same way as OfferCreate.
If necessary, you can use this code.

https://github.com/tequdev/rippled/pull/3/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Used to indicate requests to add new features
Projects
None yet
Development

No branches or pull requests

2 participants