Conditional Redemption
Conditional On-Chain Package Redemption
As an example, we can create a wrapper contract that will only allow users to redeem a package if the price of Ethereum has reached $3,000.
We do so by using a Chainlink price oracle to fetch the last recorded price of ETH/USDC.
Here's what the ConditionalDeliveryService
contract does:
shipPackage: This function simply wraps the
shipPackage
function from thePostOffice
.redeemPackageIfEthAbove3k: This function allows a package to be redeemed only if the price of ETH is above 3000 USDC. It fetches the latest ETH/USDC pair data from a Chainlink price oracle, and then compares it with the target price. If the returned price is above 3000, the package will be redeemed.
The ConditionalDeliveryService
contract allows users to create packages that can only be redeemed if the price of ETH is above a certain threshold ($3,000).
Last updated