Conditional Shipment

Conditional On-Chain Package Shipment

As an example, we can create a wrapper contract that will only allow users to ship a package if more than 1,000,000 USDC is included.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

import "./PostOffice.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract MillionDollarShipmentService {
    using SafeERC20 for IERC20;

    PostOffice public postOffice;
    IERC20 public usdcToken;

    uint8 public constant USDC_DECIMALS = 6;
    uint256 public constant MIN_PACKAGE_VALUE = 1_000_000 * 10 ** USDC_DECIMALS;

    constructor(address _postOfficeAddress, address _usdcTokenAddress) {
        postOffice = PostOffice(_postOfficeAddress);
        usdcToken = IERC20(_usdcTokenAddress);
    }

    function createMillionDollarPackage(
        CapsuleData.CapsuleContent calldata packageContent_,
        PostOffice.SecurityInfo calldata securityInfo_,
        address receiver_,
        uint256 usdcAmount_
    ) external returns (uint256) {
        require(usdcAmount_ >= MIN_PACKAGE_VALUE, "Package value is below 1 million USDC");

        usdcToken.safeTransferFrom(msg.sender, address(this), usdcAmount_);

        return postOffice.shipPackage(packageContent_, securityInfo_, receiver_);
    }

    function pickup(
        uint256 packageId_,
        string calldata rawPassword_,
        string calldata salt_,
        bool shouldRedeem_
    ) external {
        postOffice.pickup(packageId_, rawPassword_, salt_, shouldRedeem_);
    }
}

MillionDollarShipmentService allows users to create a unique shipment by providing more than 1,000,000 USDC tokens. The createMillionDollarPackage method creates the package by transferring the USDC tokens from the sender to the contract if the million dollar criteria is met, and then invokes the shipPackage method from the PostOffice contract to initiate the shipment process.

Last updated