stellar / stellar-docs

Documentation for Stellar
https://developers.stellar.org
Apache License 2.0
58 stars 125 forks source link

Build a GUI tool for fee simulation #598

Open briwylde08 opened 4 months ago

briwylde08 commented 4 months ago

Get awarded: up to $750 worth of XLM Section: Tools - Developer Tools: https://github.com/stellar/stellar-docs/blob/main/docs/tools/developer-tools.mdx - link to the tool in this section, feel free to post a link to the tool in this issue as well

The GUI could include the following features:

Myestery commented 3 months ago

@briwylde08 I'll like to work on this

Myestery commented 2 months ago

@briwylde08 I built this tool for this issue https://stellar-indexed.web.app/fee-estimation

briwylde08 commented 2 months ago

Thank you! We have it in review. I gave reviewers a three-week window to check things out, but hopefully we'll be a little faster. Much appreciated!

rahul-soshte commented 2 months ago

Assign me this issue @briwylde08 I will be taking this head-on

rahul-soshte commented 2 months ago

Hi @kalepail @briwylde08 I am doing the work on this issue, had just a update and some doubts. For fee estimation I get the UX, I just need to create a flow where the user can toggle with the resource limits and fees, get the latest inclusion fee from getFeeStats() using the SDK, add them up, and estimate the fees which @kalepail also mentions it in the stellar laboratory issue here https://github.com/stellar/laboratory/issues/747#issue-2162459272

What I was confused was the fee simulation part, I mean if a transaction is already built and signed and simulated by sending it to the simulateTransaction endpoint, you cant really toggle with the fees of the signed transaction right? So it might make sense to change the contract code, and upload it as WASM and then do the transaction simulation to check the fees, with all the incurred resource fees and inclusion fees, posted in the UI after simulation. Just if you could more clarity on that part, that would be great. Maybe the doubt is that, what custom parameters that can be toggled with are good for transaction simulation(are they the same as fee estimation ones?), which depend on the flow of the transaction simulation in the tool, which is unclear from the description

For Fee History Tracking, I guess I can track various different things, like the inclusion Fee overtime, or the averge transaction fee during the day, and then record it everyday. I don't know how many different categories to take for that,

I wanted to ask these doubts, so to clear out what is expected here, and make it more easier on the reviewers, so they don't think the complete UX was wrong at the end.

Guess the fidelity of this tool will be not that high. Maybe I can create a small SCF project out of this as well later.

EDIT: Oh I think I don't need to sign the transaction to simulate it.

rahul-soshte commented 2 months ago

I think I might have a okay idea what is to be done in Fee Simulation.

In the UX, You provide a input to mention a Contract Address, then create a Input Field for Transaction XDR, which will be the transaction that can be simulated considering the contract. Then do what sorobill does, show this data as a response

{
  cpu_insns: 130351778,
  mem_bytes: 47448018,
  entry_reads: 43,
  entry_writes: 21,
  read_bytes: 143508,
  write_bytes: 68452,
  events_and_return_bytes: 8272,
  min_txn_bytes: 76132,
  max_entry_bytes: 66920,
  max_key_bytes: 352,
}

and also along with that also show the breakdown of fees for the tx somehow from the response of simulateTransaction (if it is present, ofcourse) or the fee calculation algorithm used in the fee estimation. This overall idea looks okay for fee simulation and feasible, and usable.

briwylde08 commented 2 months ago

Heya! Sorry for the lack of response here. I don't know the answer and kalepail is ooo right now. Maybe @Julian-dev28 or @ElliotFriend have some insight?

rahul-soshte commented 1 month ago

Hi @briwylde08 @Julian-dev28 @ElliotFriend @kalepail,

So I wanted to ask about some problems I am facing while implementing the historical fee tracking feature. One of the problem is that, to keep archival fee data I have to store the data in a postgres database server, which will cost some money. So I mean unless I am charging the user some money (which is out of scope for this bounty) I wont be able to store it in a database server and do analytics on it ( Seems to be a much bigger problem, since it concerns business viability of the tool).

Another problem is I didn't find data sources by people building on Stellar which will provide me the required data to do the analytics on it to show the trends. So at the end of the day someone has to index that fee data from the RPC, maybe it's me or someone else. Even if I buy some service which will provide it, I have to pay and that will cost money for keeping the product.

There is also a option I am considering which seems to be feasible, where I could create a fee indexer API and make it open source, so user can set up themselves on their own server, and then add it as data source on the GUI, and pull data from their own server into the GUI I am making. But the con is, the user cant get old data, if they are installing the API today. Also some people might find self hosting challenging as well.

Hypothetically I could make another product, where I could sell these data sources/analytics to companies (there might be few competitors there), and use the same infrastructure for this tool as well, that will make the solution financially viable for everyone.

If you could help me with some clarity on this, that will be great, because this bounty requires some discussion as well on the requirements. I have already implemented the Fee Estimation and Fee Simulation in my GUI code, stuck on this.

briwylde08 commented 1 month ago

Sorry for the lack of response here. Going to see if I can find someone to help.

kalepail commented 1 month ago

I am on leave so won't be very responsive but I'd strongly suggest you implement Mercury/Zephyr for indexing here. It's currently free and even if/when they add paid tiers it will be simple to share indexing programs for other folks to run/host.

https://www.mercurydata.app/ https://www.mercurydata.app/products/zephyr-vm

There are some really good examples here https://github.com/xycloo/zephyr-examples and I personally have built one for the passkey-kit https://github.com/kalepail/passkey-kit/tree/main/zephyr

heytdep commented 1 month ago

Thanks @kalepail for the mention (I'm the lead dev on Mercury). Yeah we do offer quite a lot of options for building custom indexes, including for instance fee analytics metrics (you can even go much further than just the fee itself). Using Mercury is currently free and as kalepail mentions is reusable and once the paid tiers are out they'll be cheaper than hosting your own infra. One thing to take into account is that since we work mostly with soroban protocols, our catchup infra is focused on event catchups and other forms of catchups are not supported by the cloud infra. That said, we internally index all transaction results (including fees) of txs that emitted Soroban events (which on mainnet are probably most if not all meaningful contract invocations). But in general I'd recommend using a zephyr program to start indexing historical fees from the instant of deployment since it allows for lots of customization.

rahul-soshte commented 1 month ago

I understand @heytdep , thanks, I am going through the zephyr docs.

heytdep commented 1 month ago

@rahul-soshte great, if you have any questions feels free to reach out on discord (my username is heytdep) either through dm or on the stellar dev server (please tag me so I can see the notif).