Grouping Transaction Design Question

This may fit a common pattern, but I am not sure how to do it. My use case is:

  • Alice wants to fund a problem using Algos. The problem is verified solved using an offchain oracle. The receiver does not exist yet when Alice opts-in to fund the problem. If the problem is solved, the funds go to the receiver less the arbiter fee. If the problem is not solved within a period of time or Alice opts-out at any point, the funds are returned to Alice less the arbiter fee. Whether the problem is solved or not, the arbiter fee is sent once to a third account.

I think I could do this using a stateful smart contract that groups transactions with an escrow account. The creator of the stateful smart contract can communicate with the oracle and they would update global state for the contract. Is this the correct way to do it? Is there a close example using pyteal?

Thank you!

You could do it as you describe. Most of the logic required in the escrow is very similar to an htlc contract. If you did not have the requirement that the oracle be on chain, you could probably do it all in the escrow. Take a look at the htlc contract for more details on how your escrow should look. Algorand Developer Docs
That contract is only for version 1 of TEAL so if you plan on using version 2 of TEAL it should be updated with the guidelines described here: Algorand Developer Docs or just look at the sample shown here: Algorand Developer Docs.

For a reference of grouping escrow payments with stateful contract calls, look at the crowdfunding example described here: Algorand Developer Portal

Here is an example htlc with PyTeal btw: pyteal/ at master · algorand/pyteal · GitHub