Skip to content

OfferLibrary

State Variables

OFFER_TYPE

string constant OFFER_TYPE =
    "Offer(uint256 minPrice,uint256 maxPrice,uint64 biddingStart,uint32 rampUpPeriod,uint32 lockTimeout,uint32 timeout,uint256 lockStake)";

OFFER_TYPEHASH

bytes32 constant OFFER_TYPEHASH = keccak256(abi.encodePacked(OFFER_TYPE));

Functions

validate

Validates that price, ramp-up, timeout, and deadline are internally consistent and the offer has not expired.

function validate(Offer memory offer, RequestId requestId)
    internal
    view
    returns (uint64 lockDeadline1, uint64 deadline1);
Parameters
NameTypeDescription
offerOfferThe offer to validate.
requestIdRequestIdThe ID of the request associated with the offer.
Returns
NameTypeDescription
lockDeadline1uint64The deadline for when a lock expires for the offer.
deadline1uint64The deadline for the offer as a whole.

timeAtPrice

Calculates the earliest time at which the offer will be worth at least the given price.

Returned time will always be in the range 0 to offer.biddingStart + offer.rampUpPeriod.

function timeAtPrice(Offer memory offer, uint256 price) internal pure returns (uint64);
Parameters
NameTypeDescription
offerOfferThe offer to calculate for.
priceuint256The price to calculate the time for.
Returns
NameTypeDescription
<none>uint64The earliest time at which the offer will be worth at least the given price.

priceAt

Calculates the price at the given time.

Price increases linearly during the ramp-up period, then remains at the max price until the lock deadline. After the lock deadline, the price goes to zero. As a result, provers are paid no fee from the client for requests that are fulfilled after lock deadline. Note though that there may be a reward of stake available, if a prover failed to deliver on the request.

function priceAt(Offer memory offer, uint64 timestamp) internal pure returns (uint256);
Parameters
NameTypeDescription
offerOfferThe offer to calculate for.
timestampuint64The time to calculate the price for, as a UNIX timestamp.
Returns
NameTypeDescription
<none>uint256The price at the given time.

deadline

Calculates the deadline for the offer.

function deadline(Offer memory offer) internal pure returns (uint64);
Parameters
NameTypeDescription
offerOfferThe offer to calculate the deadline for.
Returns
NameTypeDescription
<none>uint64The deadline for the offer, as a UNIX timestamp.

lockDeadline

Calculates the lock deadline for the offer.

function lockDeadline(Offer memory offer) internal pure returns (uint64);
Parameters
NameTypeDescription
offerOfferThe offer to calculate the lock deadline for.
Returns
NameTypeDescription
<none>uint64The lock deadline for the offer, as a UNIX timestamp.

eip712Digest

Computes the EIP-712 digest for the given offer.

function eip712Digest(Offer memory offer) internal pure returns (bytes32);
Parameters
NameTypeDescription
offerOfferThe offer to compute the digest for.
Returns
NameTypeDescription
<none>bytes32The EIP-712 digest of the offer.