SmartPiggies and Oracles
How SmartPiggies uses oracles
SmartPiggies use off-chain data to settle a piggy. Although SmartPiggies recommends selling a piggy back to the writer, as are typically done for traditional options, there are many reasons why the counterparties may need to execute a piggy, and this will involve a call to an oracle to retrieve off-chain data.
Off-chain data, here prices, are requested by a resolver, which is a smart contract that receives requests and relays results. A resolver contract address is associated with a piggy, this is, for all intents and purposes, the underlying that the piggy will execute against. When a piggy makes a request for a price, which can happen during the bidding process or the settlement process, SmartPiggies will execute a fetchData() function on the resolver. When the function is executed on the resolver, an external process (on following the blockchain, but not on it) will pick up the request being made on the resolver.
This external process is the oracle and is responsible for sending the desired data back to the resolver.
There will be a unique resolver for each underlying. The contract address of this specific resolver is saved into the piggy. This is the contract address used to fetch the price data, if the piggy is executed. For example, if a piggy's underlying is ETHUSD, a unique contract address, referencing the ETHUSD resolver, will be saved as the underlying of the piggy.
With this approach underlyings can be added or removed to the app. When interacting directly with the SmartPiggies contract, any address can be provided, but there are strict requirements for the resolver to execute correctly, and SmartPiggies recommends only using approved resolvers.

1 The technical sequence of events begins by the SmartPiggies contract calling a specific resolver. That resolver will call a DataProvider contract. The DataProvider will create a request event, which an external process will catch. The external process (the oracle) will fetch the data, and then make an on-chain call to the DataProvider including the data. The DataProvider will callback the resolver with the data, and the resolver will callback the SmartPiggies contract, updating the piggy with the requested data.
Copy link