Please help to find out a possible solutions to the following problem:

For a dedicated "Minimal Balance" service one would need to know a number of account entries among which there are Offers ((2 + # of entries) × base reserve). How is it possible to get a full list of Offers, given that some offer-effecting-transactions are "in-flight" and not yet visible via the Horizon API. Such a "Minimal Balance" service has:

  1. All transactions for an account, where some of them might not be submitted to the network yet (with unique ids attached to each transaction as a Memo)
  2. Access to the Horizon API, including a list of open orders.

How is it possible to correlate transaction ids from 1) with offers from 2) in order not to count them twice?

  • If I understand what you are asking, it would have to be implemented client-side, since there's no way for Stellar to know about transactions that have not been submitted yet. I think the real answer is the base reserve is cheap so people just overestimate. If the price of lumens appreciates significantly validators would probably vote to lower the base reserve. – user3188445 Sep 13 at 15:51
up vote 2 down vote accepted

If you manage those "in-flight" transactions on your side, it won't be a problem.

  1. Call horizon.loadAccount('GD...QZ').
  2. Check the subentry_count field. It shows the total number of trustlines/offers/data entries for the account. Here you can calculate a minimum required balance for that account. As you mentioned, (2 + subentry_count) × base reserve.
  3. Iterate through the "pending" transactions on your side, parse them (let tx = new Transaction(txEnvelopeXdr)), and check operations included into each tx. You can easily count MANAGE_OFFER operations and estimate required minimal balance.

To make things easier, you can listen to trades stream and recalculate the required min balance only when the offer is fully executed (therefore, it is removed from active account orders), or when you receive new pending transaction.

Bear in mind that some offers will be executed immediately once they are submitted, so the total calculated amount of reserved funds may be greater than actual reserve.

  • As you say, there is a gotcha with the orders that are executed as they are submitted and its tough to infer a correct number of open orders just by analyzing operations in the transaction stream (one would need to fully reproduce DEX logic for it?). This is exactly the problem I am trying to brainstorm - if it possible to precisely infer the amount of open orders. Its noteworthy that such problem doesn't exist for trustlines, as its pretty straightforward to count creation/removal operations because there is no "implicit removal via matching" as with orders. – Yuriy Lazaryev Sep 14 at 13:37
  • You can't to calculate the required balance precisely, and nobody can, due to the nature of multi-user trading platform. But you can estimate a safe min balance, that allows to place offers scheduled in "pending" transactions. – Orbit Lens Sep 14 at 16:56

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.