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 . Oracles resolve to a 256-bit unsigned integer, therefore
startRanges and endRanges should also be 256-bit unsigned integers.
Instead of , endRange should be set to .
startRange | endRange | Values an oracle can resolve to |
|---|---|---|
| 0 | 3 | |
| 4 | 5 | |
| 3 | 0 |
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)]>`);