# PriceAuthority Methods
We rely on PriceAuthority oracles. A PriceAuthority
gives reliable quotes for prices. The quotes might be based on broad surveys
of prices across the ecosystem, or might come directly from an AMM (Automatic
Market Maker) like our
AutoSwap. A PriceAuthority can either give a quote for the current price
across any pair of currencies it knows about, or can immediately return a
Promise resolved when a condition is true. For example, a price
crossing some threshold, or at a particular time. It can also provide a
price feed that updates with every price change.
A PriceQuote represents a statement from the PriceAuthority as to the
current price level at a particular time. The significant content (prices
and time) is packaged in the amount, and repeated in the payment for veracity.
A PriceQuote is an amount-payment pair, where the amount is also the current
balance of the payment.
const { quoteAmount, quotePayment } = priceQuote;
PriceQuotes are returned in two forms:
PriceDescription- Always includes
amountIn,amountOut, the quote'sTimestamp, and theTimerServicetheTimeStampis relative to.
- Always includes
PriceDescriptionwrapped as aQuoteAuthorityissued payment.- This lets quotes be shared in a format letting others verify the time and values.
# getQuoteIssuer(brandIn, brandOut)
brandIn:{ Brand }brandOut:{ Brand }- Returns:
{ Issuer | Promise<Issuer> } - Gets the ERTP
IssuerofPriceQuotesfor a givenbrandIn/brandOutpair.
const quoteIssuer = await E(pAuthority).getQuoteIssuer(
collateralKit.brand,
loanKit.brand,
);
# getTimerService(brandIn, brandOut)
brandIn:{ Brand }brandOut:{ Brand }- Returns:
{ TimerService | Promise<TimerService> } - Gets the timer used in
PriceQuotesfor a givenbrandIn/brandOutpair.
const myTimer = E(pAuthority).getTimerService(collateral.brand, loanKit.brand);
# makeQuoteNotifier(amountIn, brandOut)
amountIn:{ Amount }brandOut:{ Brand }- Returns:
{ ERef<Notifier<PriceQuote>> } - Be notified of the latest
PriceQuotesfor a givenamountIn. The issuing rate may be very different betweenpriceAuthorities.
const myNotifier = E(pAuthority).makeQuoteNotifier(quatloos100, usdBrand);
# quoteAtTime(deadline, amountIn, brandOut)
deadline:{ Timestamp }amountIn:{ Amount }brandOut:{ Brand }- Returns:
{ Promise<PriceQuote> } - Resolves after
deadlinepasses on thepriceAuthority’stimerServicewith the price quote ofamountInat that time. Note thatdeadline's value is aBigInt.
const priceQuoteOnThisAtTime = E(pAuthority).quoteAtTime(7n, quatloosAmount34, usdBrand);
# quoteGiven(amountIn, brandOut)
amountIn:{ Amount }brandOut:{ Brand }- Returns:
{ Promise<PriceQuote> } - Get a quote on demand corresponding to
amountIn.
const quote = await E(pAuthority).quoteGiven(moola500, quatloosBrand);
# quoteWanted(brandIn, amountOut)
brandIn:{ Brand }amountOut:{ Amount }- Returns:
{ Promise<PriceQuote> } - Get a quote on demand corresponding to
amountOut.
const quote = await E(pAuthority).quoteWanted(quatloosBrand, moola500;
# quoteWhenGT(amountIn, amountOutLimit)
amountIn:{ Amount }amountOutLimit:{ Amount }- Returns:
{ Promise<PriceQuote> } - Resolves when a price quote of
amountInexceedsamountOutLimit.
const quote = E(pAuthority).quoteWhenGT(
AmountMath.make(brands.In, 29n),
AmountMath.make(brands.Out, 974n),
);
# quoteWhenGTE(amountIn, amountOutLimit)
amountIn:{ Amount }amountOutLimit:{ Amount }- Returns:
{ Promise<PriceQuote> } - Resolves when a price quote of
amountInreaches or exceedsamountOutLimit.
const quote = E(pAuthority).quoteWhenGTE(
AmountMath.make(brands.In, 29n),
AmountMath.make(brands.Out, 974n),
);
# quoteWhenLT(amountIn, amountOutLimit)
amountIn:{ Amount }amountOutLimit:{ Amount }- Returns:
{ Promise<PriceQuote> } - Resolves when a price quote of
amountIndrops belowamountOutLimit.
const quote = E(pAuthority).quoteWhenLT(
AmountMath.make(brands.In, 29n),
AmountMath.make(brands.Out, 974n),
);
# quoteWhenLTE(amountIn, amountOutLimit)
amountIn:{ Amount }amountOutLimit:{ Amount }- Returns:
{ Promise<PriceQuote> } - Resolves when a price quote of
amountInreaches or drops belowamountOutLimit.
const quote = E(pAuthority).quoteWhenLTE(
AmountMath.make(brands.In, 29n),
AmountMath.make(brands.Out, 974n),
);
# MutableQuote object
Use a MutableQuote when you expect to make multiple calls, replacing the trigger
value. If you just need a single quote, and won't change the trigger level, then use
a non-mutable quote.
There are four mutable quote methods, which return a MutableQuote object with the methods:
cancel(e)e``{ String }- Causes the
Promiseto reject with the messagee. When the promise is used with aE.when()the message is part of the rejection notification.
getPromise()- Returns:
{ Promise<PriceQuote> }
- Returns:
updateLevel(newAmountIn, newAmountOutLimit)newAmountIn{ Amount }newAmountOutLimit{ Amount }- Changes the
MutableQuote's trigger levels to the specified values without requiring a secondPromise.newAmountInandnewAmountOutLimit's brands must match the originalamountInandnewAmountOutLimitbrands respectively.
# mutableQuoteWhenGT(amountIn, amountOutLimit)
amountIn:{ Amount }amountOutLimit:{ Amount }- Returns:
{ Promise<MutableQuote> } - Resolves when a price quote of
amountInexceedsamountOutLimit
const quote = E(pAuthority).mutableQuoteWhenGT(
AmountMath.make(brands.In, 29n),
AmountMath.make(brands.Out, 974n),
);
# mutableQuoteWhenGTE(amountIn, amountOutLimit)
amountIn:{ Amount }amountOutLimit:{ Amount }- Returns:
{ Promise<MutableQuote> } - Resolves when a price quote of
amountInreaches or exceedsamountOutLimit
const quote = E(pAuthority).mutableQuoteWhenGTE(
AmountMath.make(brands.In, 29n),
AmountMath.make(brands.Out, 974n),
);
# mutableQuoteWhenLT(amountIn, amountOutLimit)
amountIn:{ Amount }amountOutLimit:{ Amount }- Returns:
{ Promise<MutableQuote> } - Resolves when a price quote of
amountIndrops belowamountOutLimit
const quote = E(pAuthority).mutableQuoteWhenLT(
AmountMath.make(brands.In, 29n),
AmountMath.make(brands.Out, 974n),
);
# mutableQuoteWhenLTE(amountIn, amountOutLimit)
amountIn:{ Amount }amountOutLimit:{ Amount }- Returns:
{ Promise<MutableQuote> } - Resolves when a price quote of
amountInreaches or drops belowamountOutLimit
const quote = E(pAuthority).mutableQuoteWhenLTE(
AmountMath.make(brands.In, 29n),
AmountMath.make(brands.Out, 974n),
);