ComposablePrediction

ComposablePrediction expresses binary payoffs. For example, pays out 1 USDC if an oracle reporting the ETH price at a specific time responds with a value greater than $2000.

ComposablePrediction tokens may be also created using yesToken and noToken helper functions.

Parameters

import type { Blueprint, Oracle } from "@blueprintsfi/blueprints.js";

type Params = {
    collateral: Blueprint<any>;
    constraints: {
        oracle: Oracle<any>;
        startRange: bigint;
        endRange: bigint;
    }[];
}

ComposablePrediction token can be exchanged for the underlying collateral if all oracles resolve to a value in their respective ranges [startRange,endRange)[\textrm{startRange}, \textrm{endRange}). Oracles resolve to a 256-bit unsigned integer, therefore startRanges and endRanges should also be 256-bit unsigned integers.

Warning

Instead of 22562^{256}, endRange should be set to 00.

startRangeendRangeValues an oracle can resolve to
030,1,20, 1, 2
4544
303,4,,225613, 4, \dots, 2^{256} - 1

An error is thrown if both startRange and endRange are set to 0 for some constraint.

Note that internally oracles are wrapped in ConstantOracle, which means that the value a feed resolves to is read only once and can't change afterwards.

After any constraint's oracle resolves within the specified range, the blueprint enables removing the constraint. If all constraints are removed, the underlying is redeemable.

Multiplying the collateral by a factor has the same result as multiplying the number of ComposablePrediction positions by that factor – the final onchain token id and wei amounts don't change.

For more information on this model, see Multiverse Finance.

Examples

import {
    ComposablePrediction,
    HashedBytes,
    MapBytes,
    MultisigOracle,
    NativeToken,
} from "@blueprintsfi/blueprints.js";
import assert from "node:assert";

const eth = new NativeToken(5n, {
    decimals: 18n,
});

const oracle = new MultisigOracle({
    addresses: ["0xCA2421bE4AA793c9F95faef57811F4eD360f54e1"],
    threshold: 1n,
    feedId: new HashedBytes(new MapBytes({
        market: "BTC",
        condition: "above 100000",
        time: "2027-01-01 00:00:00 UTC",
    })),
});

const prediction = new ComposablePrediction(1n, {
    collateral: eth,
    constraints: [{
        oracle,
        startRange: 0n,
        endRange: 1n,
    }],
});
assert.strictEqual(prediction.toString(), `1 ComposablePrediction<5 NativeToken<18>, [(MultisigOracle<[0xCA2421bE4AA793c9F95faef57811F4eD360f54e1], 1, keccak256({"market":"BTC","condition":"above 100000","time":"2027-01-01 00:00:00 UTC"})>, 0, 1)]>`);

See also

On this page
ParametersExamplesSee also