Regarding the way Algorand distributes rewards, see https://www.algorand.com/resources/blog/rewards-technical-overview
Regarding the second solution, here is how I was thinking of it.
You create a stateless smart contract C_x that does the following:
accept any transaction as long as it’s called in a group with an application call to your application App. The application App will be responsible to only allow the transactions described below.
The stateless smart contract also contains an ID x that it just discards, just to distinguish between each bond. The application App contains a counter X in global storage used to initialize x.
Instead of using a counter, you may use other values such as the hash of the calling account A and a byte chosen by A.
Then, to issue the bond to an account A, you do the following:
- First, you need to create the new smart contract account C_x and store in local storage of A that it should receive this NFT from C_x. You do that using the following group of transactions:
a. Opt-in application call of App by A that will make A opt-in to App and store in A’s local storage that it is allowed to get the bond with ID X. (X is then incremented.)
b. Payment from A to buy the bond
c. Payment from A to the stateless smart contract C_x of 1 Algo to be able to issue transactions from C_x
d. Creation of a bond NFT by C_x
e. Opt-in application call of App by C_x to store in C_x’s local state the bond parameters. - Second, the account A can opt-in to the NFT created by C_x
- Third, the account A can get the NFT by doing the following group of transactions:
a. Close-out application call of App by A that will see that A is still owed the NFT created by C_x.
b. Asset transfer from C_x to A
The reason that you need to do the process in 3 steps rather than a big transaction is that you cannot know the asset ID created by C_x until the transaction is executed. So you cannot do the asset transfer of the NFT bond immediately. Instead, you need to store in local storage of A that A is meant to receive this NFT. And then make the asset transfer.