0

Hey guys anchor noob back at it with another noob question!

Alright so I have a program that accepts deposits to a user pda (tx1), based on certain events the user might instantly get a payout from the pool pda in a settlement tx (tx2). I have a bot with the authority to execute tx2 and i want it to be able to do that as fast as possible, ( in the next slot or the one after that ).

To be able to be fast the bot accepts "processed" transactions to execute the second one.

I am scared that using processed might not be safe if the first tx gets reverted somehow (?)

but considering that the second tx is dependent on there being funds in the user pda, wouldn't that tx also revert if the first one failed? or would it just be able to transfer the funds from the pool pda and not the user pda, effectively creating an exploit in my app?

Please refer to the image to understand the flow of funds better

If anyone can help me understand I would be very grateful!

enter image description here

2 Answers 2

0

The best possibility is definitely to do all of the instructions in one transaction if you can fit it all in.

If not, then you can send them in series, but you must use at least the confirmed commitment to be sure that it won't get reverted. This takes slightly longer than processed, but it guarantees that the network has seen the transaction. If you use processed, then you have no guarantees.

1
  • the problem is that tx2 will only happen in certain conditions in a game based on off-chain data. So making it in 1 tx would be exploitable as the player could make the tx fail if user wallet doesnt receive a payout Dec 4, 2023 at 15:42
0

I think it is the best option to merge these 2 txs into one to let the user instantly get paid as soon as he/she deposited.

Or, if it was really meant to be separated into 2 txs for some reason I would rather recommend you to transfer deposited funds to pool's PDA (token account) directly and just keep track of deposited amount in user's PDA (not a token account).

  • You should emit kinda' user's deposited event so that you can listen and catch it as soon as it succeeded in your offchain logic.
  • Then you execute tx2 checking user's PDA to validate his deposit amount and settle & payout from pools PDA (token account).
  • Make sure you're fetching tx1 history in certain intervals (i.e. in every 10s) in case event listener did not work catch the event due to the network issue and/or downtime.
2
  • the problem is that tx2 will only happen in certain conditions in a game based on off-chain data. So making it in 1 tx would be exploitable as the player could make the tx fail if user wallet doesnt recieve a payout Dec 4, 2023 at 15:41
  • got it - updated my answer. Dec 4, 2023 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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