The very simple approach to stablecoin would be as follows:
- there’s a bank box holding stablecoin tokens (e.g. sJPY)
- there’s also a trusted oracle with JPY/ERG data
The bank’s box is protected with such script that:
- to get 100 JPY out of the bank, one needs to re-create bank box in the outputs of a spending transaction with 100 JPY deducted, and create swap buy order for 100 JPY according to current price (got from the oracle via a read-only box). Other outputs are not fixed, presumably, they will pay 100 JPY to receivers.
Then it is always possible to sell 100 JPY back. However, sometimes price for swapping back can be terrible even if price is not going down, as someone else can use your box to swap back leaving you with a worse option. This problem can be relaxed with using more complicated DEX orders I guess.