Oracle report arbitrage
On a YieldBasis Curve pool that runs the oracle-report policy (YBOraclizedPolicy), the policy prices each swap against a price report. A price report is a signed Pyth Pro (Pyth Lazer) USD price of the pool's asset. A corrective swap moves the pool's marginal price toward the price report and does not pass it. Such a swap can pay less than the fallback fee, the fee without a discount. The discount also needs a fresh price report.
In this guide, you deliver a price report and swap against it in one transaction. The guide is for arbitrageurs, searchers, and solvers who trade such a pool. It includes a ReportSwap contract and a Python script. The script swaps a fixed amount and does not search the trade size or hedge the output. For the fee rules and the profit and age tables, read How oracle-report swaps are priced.
Arbitrage against the LEVAMM, the market's leveraged AMM, through the VirtualPool is a different trade that works on every market. For that trade, read Arbitrage.
Prerequisites
A pool policy is a contract that the Curve pool asks for its swap fee and its price_scale target. price_scale is the pool's internal price. Check that you have each of these before you start:
- A Curve pool that runs
YBOraclizedPolicy. Each such pool has its own policy contract. To see which policy a pool runs, callPOLICY()on the pool. You can also read the pool policy table in Contract addresses. - A Pyth Pro access token. Access token and request fields gives the values of the request.
- ETH for the verification fee of each delivery. Verification fee gives the amount.
- The coin that you sell: crvUSD or the pool's asset.
- A deployed contract that delivers the price report and swaps in the same transaction, approved for the coin that you sell. The ReportSwap contract is one such contract.
- A mainnet fork, to test the contract and the script before you use mainnet.
- For the Python example: web3.py 7 or later and
requests.
Contracts
This table shows how to find each contract that the procedure uses:
| Contract | How to find it |
|---|---|
| Curve pool (Twocrypto v3.0.0) | The market's cryptopool, from Factory.markets(i), or the market tables in Contract addresses |
Pool policy (YBOraclizedPolicy) | pool.POLICY(). To read its owner and emergency admin, call owner() and EMERGENCY_ADMIN() on the policy |
| LEVAMM | policy.AMM(). It holds the pool LP as collateral |
| Pyth Lazer verifier | policy.oracle().verifier, an upgradeable ERC-1967 proxy. Its address is in the pool policies section of Contract addresses. To read its version, call version() |
| Coins | pool.coins(0) is crvUSD 0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E. pool.coins(1) is the asset |
Access token and request fields
To request a price report, send your Pyth Pro access token with these values:
| Request field | Value | Why |
|---|---|---|
| Feed id | policy.FEED_ID() | The Pyth Lazer feed of the pool's asset. For example, feed 2 is Crypto.ETH/USD, for a WETH pool |
| Channel | The channel in oracle().channel | The policy source maps channel 4 to fixed_rate@1000ms |
| Properties | price, exponent, feedUpdateTimestamp, in this order | The policy reads property ids 0, 4 and 12 at fixed offsets |
| Format | evm | The 112-byte signed update |
Decode one live price report before you automate. The policy rejects a payload whose properties are in a different order. The Pyth documentation does not say that the server always keeps the requested order.
The Pyth Pro documentation has an overview and pages on how to get an API key, the REST API, and the WebSocket feed.
Verification fee
Send exactly verification_fee() wei with each delivery. With verifier 0.2.0, an overpayment reverts the delivery.
The policy forwards the whole msg.value to verifier.verifyUpdate. The verifier reverts with "Insufficient fee provided" if msg.value is less than its fee. To read the fee, call verification_fee() on the policy.
The deployed verifier implementation is PythLazer 0.2.0 (PythLazer 0.2.0 source on GitHub). Version 0.2.0 refunds an overpayment to the policy with transfer. The policy has no payable default function, so the refund fails. The whole delivery then reverts without a reason string.
The verifier is an upgradeable proxy. A later Pyth version (0.3.0 on the main branch) keeps the excess and does not revert. To check the version, call version() on the verifier before you rely on either behavior.
Before you send
Read these values in the block that you build against:
| Read | Expected | If not |
|---|---|---|
pool.POLICY() | The policy address that you quote against | The views revert "not attached". The pool uses another fee |
policy.is_killed() | false | Deliveries revert "killed". The pool charges its native fee |
policy.config() | The fee values that your thresholds use | Compute the thresholds again with the live values |
policy.oracle() | A channel that matches your request, and windows and bounds that fit your price report | Change the price report request or the timing |
policy.report() | observation_us older than your price report | Your delivery reverts "observation not newer" |
policy.verification_fee() | The value to send | Send this exact amount |
pool.D() and policy.state().D | Equal | No discount (check 6). Call policy.sync() if a removal callback failed |
Value crvUSD at its market price in your profit check. The policy counts 1 crvUSD as $1.
Deliver and swap in one transaction
After a delivery stores a price report, any trader can swap against it. A delivery in a separate transaction gives the discount to the next trader. Anyone can deliver a price report, and arbitrageurs deliver one with their swap. Do not depend on another party for a fresh price report. Deliver your own price report in the same transaction as your swap.
Deploy and test ReportSwap on a mainnet fork before you use it on mainnet. The Python example sends a real transaction, so run it against a mainnet fork first.
Do not let your node estimate the gas limit. The estimate runs at the most recent block, and its timestamp can be older than a fresh price report. The time check can then fail in the estimate only.
If a rival stores an equal or newer price report before you, your delivery reverts with "observation not newer". The ReportSwap contract in this guide catches only that reason and swaps against the stored price report. Your min_dy then decides whether the swap executes.
To deliver a price report and swap, follow these steps in order:
- Read the policy state listed in Before you send.
- Get the newest price report from Pyth Pro.
- Decode the price and the observation time. For their byte offsets, read Byte layout.
- Compare the pool's marginal price with the price report price.
pool.last_prices()is an approximation, which the Python example uses. - Decide from the gap:
- If the gap is
base_fee(the lowest fee of a discounted swap) or less, stop. - If the pool's marginal price is above the price report, sell the asset (
i = 1). - If the pool's marginal price is below the price report, sell crvUSD (
i = 0).
- If the gap is
- Quote sizes with
get_dy_with_reportat the target block timestamp. For what a quote does not check, read Quote views. - Select the size with the largest profit after gas and the hedge cost, as in Size of the trade.
- Set
min_dyfrom the quote at the target block timestamp. - Set the delivery value to exactly
verification_fee()wei. - Set the gas limit explicitly.
- Send
deliver_oracle_reportandexchangein the same transaction, for example throughReportSwap. - Hedge the output at your external venue.
Size of the trade
The edge is the gain of the whole swap at the price report, before the fee (Edge). The edge is an average over the whole swap. Each extra unit of size trades at a smaller gap, so it lowers the average edge.
The results in this subsection use the example settings in Fee settings: base_fee 50 bp, capture 67.5%, and fallback_fee 175 bp, the cap. With these settings, the fee reaches the cap at an edge of about 235.2 bp. For the profit formula, read Profit at a fresh price report.
The results in this subsection assume that the gap between the pool's marginal price and the price report falls linearly with trade size. Real Twocrypto curves are not linear. Use the results as a guide, and search the size numerically with get_dy_with_report.
Let g₀ be the starting gap and g the gap at which you stop. The average edge is (g₀ + g) / 2. Below the cap, profit is proportional to this expression:
(g₀ − g) × ((g₀ + g) / 2 − base_fee)
This value is largest at g = base_fee. So stop when the pool's marginal price is about base_fee (50 bp) short of the price report. A trade to the price report is still corrective, but it earns less. For g₀ = 200 bp, a stop at 0 bp earns 88.9% of the best result.
Above the cap, the fee is fallback_fee, and profit is proportional to (g₀ − g) × ((g₀ + g) / 2 − fallback_fee). This value is largest at g = fallback_fee. The example settings give these start-gap thresholds:
- About 340.8 bp: the discount stops paying. The best discounted trade earns
0.325 × (g₀ − 50)² / 2. A capped trade that stops at a 175 bp gap earns(g₀ − 175)² / 2. The two are equal whereg₀ − 175 = √0.325 × (g₀ − 50), at about 340.8 bp. Above this start gap, the capped trade earns more. - About 420.4 bp: the discounted optimum ends. The stop at
base_feegives an average edge of(g₀ + 50) / 2. This reaches 235.2 bp atg₀≈ 420.4 bp. Above this start gap, the best discounted trade is not available. - About 470.4 bp: no discount at all. A trade to the price report gives the smallest average edge of a corrective swap,
g₀ / 2. This reaches 235.2 bp atg₀≈ 470.4 bp. Above this start gap, every corrective swap paysfallback_fee.
Compare the discounted case and the capped case with get_dy_with_report, and keep the larger profit. A small trade at a large gap has an edge close to the gap. At a gap above 235.2 bp, a small trade pays fallback_fee.
If the swap moves the marginal price past the price report, the swap is not corrective. The fee then jumps to fallback_fee.
ReportSwap contract
ReportSwap delivers a signed price report and then swaps, in one transaction. Its constructor takes the address of the Curve pool of a YieldBasis market. To find the pool address, read the market's cryptopool from Factory.markets(i), or use the pool policy table in Contract addresses. The pool must run YBOraclizedPolicy: pool.POLICY() must return a YBOraclizedPolicy contract.
At each call, ReportSwap reads the policy from pool.POLICY(). So the contract follows the pool if its policy changes. If POLICY() returns the zero address, the call reverts with "pool has no policy".
The callable example is a complete contract. It assumes that you approve it for dx of the input coin and send verification_fee() wei with each call:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
interface IERC20 {
function transferFrom(address from, address to, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
}
interface IPolicy {
function deliver_oracle_report(bytes calldata report) external payable;
function verification_fee() external view returns (uint256);
}
interface IPool {
function POLICY() external view returns (address);
function coins(uint256 i) external view returns (address);
function exchange(uint256 i, uint256 j, uint256 dx, uint256 minDy, address receiver)
external
returns (uint256);
}
/// Deliver a signed Pyth price report, then swap, in one transaction.
contract ReportSwap {
// Curve pool of a YieldBasis market. pool.POLICY() must be a YBOraclizedPolicy.
IPool public immutable POOL;
/// @param pool Address of the Curve pool: the market's cryptopool in Factory.markets(i).
constructor(address pool) {
POOL = IPool(pool);
}
/// @param report The 112-byte signed price report from Pyth Pro (evm format).
/// @param i Index of the coin you sell: 0 crvUSD, 1 the asset.
/// @param dx Amount you sell. Approve this contract for it before the call.
/// @param minDy Smallest output you accept, from get_dy_with_report.
function swapWithReport(bytes calldata report, uint256 i, uint256 dx, uint256 minDy)
external
payable
returns (uint256 dy)
{
// Read the policy at each call, so the contract follows a policy change.
IPolicy policy = IPolicy(POOL.POLICY());
require(address(policy) != address(0), "pool has no policy");
// Pays exactly verification_fee() from this contract's ETH balance.
// Send verification_fee() wei as msg.value.
try policy.deliver_oracle_report{value: policy.verification_fee()}(report) {}
catch Error(string memory reason) {
// A price report at least as recent is already stored: swap on that one.
require(keccak256(bytes(reason)) == keccak256("observation not newer"), reason);
}
IERC20 coinIn = IERC20(POOL.coins(i));
coinIn.transferFrom(msg.sender, address(this), dx);
coinIn.approve(address(POOL), dx);
dy = POOL.exchange(i, 1 - i, dx, minDy, msg.sender);
}
}
To use the contract, follow these steps in order:
- Deploy
ReportSwapwith the address of the Curve pool. - Approve
ReportSwapfordxof the input coin. - Quote
get_dy_with_report(i, 1 - i, dx, report, block_timestamp)for the target block. - Call
swapWithReport(report, i, dx, minDy)withverification_fee()wei as value.
Result: swapWithReport returns dy, the output of coin 1 - i, and the pool pays it to the caller.
ETH that you send to the contract stays in it. The contract has no withdrawal function, so send exactly verification_fee().
For a single-transaction arbitrage, add a flash loan for the input. Sell the output on an external venue before you repay.
A contract can also ignore every delivery failure and let min_dy decide. With that rule, the contract also swaps when your price report fails admission. The swap then uses the stored price report.
Python example
This script gets the newest price report, picks the direction, quotes for the next block, and sends one transaction to ReportSwap. It needs web3.py 7 or later and requests.
Set these environment variables: ETH_RPC_URL, PYTH_API_KEY, PRIVATE_KEY, POOL (the Curve pool address that you deployed ReportSwap with), and REPORT_SWAP (your deployed ReportSwap address). The script reads the policy from pool.POLICY().
The script uses the base URL, the path, and the Authorization: Bearer header from the Pyth REST reference. The jsonBinaryEncoding field and the ["evm"]["data"] response path come from a YieldBasis team guide, not from the Pyth reference pages. So the decode step accepts hex with or without a 0x prefix.
The callable example is a complete script. It sends a real transaction:
"""Fetch a signed Pyth price report and swap through ReportSwap in one transaction.
Before running: deploy ReportSwap with the pool address, approve it for the coin
you sell, set DX_ASSET and DX_CRVUSD for the pool's coins, and set ETH_RPC_URL,
PYTH_API_KEY, PRIVATE_KEY, POOL and REPORT_SWAP.
"""
import json
import os
import requests
from eth_account import Account
from web3 import Web3
PYTH_URL = "https://pyth-lazer.dourolabs.app/v1/latest_price" # check against Pyth Pro docs
# Amounts to sell, in raw units (amount x 10**decimals of the coin). Set them for
# the pool's coins: the decimals of the asset depend on the pool.
DX_ASSET = 2 * 10**15 # coin 1, the asset: 0.002 of an 18-decimal asset
DX_CRVUSD = 5 * 10**18 # coin 0, crvUSD (18 decimals): 5 crvUSD
ABI = json.loads("""[
{"type":"function","name":"POLICY","stateMutability":"view","inputs":[],
"outputs":[{"name":"","type":"address"}]},
{"type":"function","name":"get_dy_with_report","stateMutability":"view","inputs":[
{"name":"i","type":"uint256"},{"name":"j","type":"uint256"},{"name":"dx","type":"uint256"},
{"name":"report_data","type":"bytes"},{"name":"block_timestamp","type":"uint256"}],
"outputs":[{"name":"","type":"uint256"}]},
{"type":"function","name":"FEED_ID","stateMutability":"view","inputs":[],
"outputs":[{"name":"","type":"uint32"}]},
{"type":"function","name":"verification_fee","stateMutability":"view","inputs":[],
"outputs":[{"name":"","type":"uint256"}]},
{"type":"function","name":"last_prices","stateMutability":"view","inputs":[],
"outputs":[{"name":"","type":"uint256"}]},
{"type":"function","name":"swapWithReport","stateMutability":"payable","inputs":[
{"name":"report","type":"bytes"},{"name":"i","type":"uint256"},{"name":"dx","type":"uint256"},
{"name":"minDy","type":"uint256"}],"outputs":[{"name":"dy","type":"uint256"}]}
]""")
w3 = Web3(Web3.HTTPProvider(os.environ["ETH_RPC_URL"]))
me = Account.from_key(os.environ["PRIVATE_KEY"])
pool = w3.eth.contract(Web3.to_checksum_address(os.environ["POOL"]), abi=ABI)
policy = w3.eth.contract(pool.functions.POLICY().call(), abi=ABI) # YBOraclizedPolicy
swapper = w3.eth.contract(Web3.to_checksum_address(os.environ["REPORT_SWAP"]), abi=ABI)
def fetch_report():
"""The newest signed price report of the policy's feed, in the 112-byte format it reads."""
response = requests.post(
PYTH_URL,
json={
"priceFeedIds": [policy.functions.FEED_ID().call()],
"properties": ["price", "exponent", "feedUpdateTimestamp"], # this order
"formats": ["evm"],
"channel": "fixed_rate@1000ms",
"jsonBinaryEncoding": "hex", # from the team's guide
},
headers={"Authorization": f"Bearer {os.environ['PYTH_API_KEY']}"},
timeout=5,
)
response.raise_for_status()
data = response.json()["evm"]["data"] # response path from the team's guide
report = bytes.fromhex(data.removeprefix("0x"))
assert len(report) == 112, "unexpected report length"
return report
def report_price(report):
"""Price in 18 decimals (1e18 = $1), from payload bytes 20-28 and 29-31."""
mantissa = int.from_bytes(report[91:99], "big", signed=True)
exponent = int.from_bytes(report[100:102], "big", signed=True)
return mantissa * 10 ** (18 + exponent)
report = fetch_report()
price = report_price(report)
# last_prices is the pool spot after its last trade: an approximation of the
# marginal price. Pool price above the report: sell the asset. Below it: sell crvUSD.
i = 1 if pool.functions.last_prices().call() > price else 0
dx = DX_ASSET if i == 1 else DX_CRVUSD
# Quote for the next block. A later block ages the report: the transaction can
# then fail report admission or the min_dy check.
next_block_time = w3.eth.get_block("latest").timestamp + 12
min_dy = policy.functions.get_dy_with_report(i, 1 - i, dx, report, next_block_time).call()
print(f"report ${price / 1e18:,.2f}; sell {dx} of coin {i}; expect at least {min_dy} of coin {1 - i}")
tx = swapper.functions.swapWithReport(report, i, dx, min_dy).build_transaction(
{
"from": me.address,
"value": policy.functions.verification_fee().call(), # exactly this amount
"nonce": w3.eth.get_transaction_count(me.address),
# Set explicitly: estimation runs at the most recent block, whose timestamp
# can trail a fresh report enough to fail the policy's time check.
"gas": 500_000,
}
)
tx_hash = w3.eth.send_raw_transaction(me.sign_transaction(tx).raw_transaction)
receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print(f"status {receipt.status}; tx 0x{bytes(tx_hash).hex()}")
In report_price, the docstring counts bytes from the start of the payload (report byte 71), and the slices count from the start of the report. So payload bytes 20–28 are report bytes 91–99.
Expected output: two lines. The first line gives the price report price in USD, what you sell, and the smallest output that you accept. The second line gives the receipt status and the transaction hash. A status of 1 means that swapWithReport succeeded.
The script uses fixed sizes. A production bot must search the size, as in Size of the trade, and score the full route with the hedge.
If the delivery or the swap reverts
A delivery can revert on a price report check, and the swap can revert on a pool check. Use these sources to find the cause:
- Delivery reverts. The
YBOraclizedPolicytable in Error codes lists each policy string with its cause. The same section lists the Pyth verifier strings and the overpayment revert without a reason string. For the checks in the order that a delivery runs them, read Admission rules. - Verifier strings.
input too shortandinvalid evm magicmean that the update is not in EVM format.invalid signatureandinvalid signermean that the signature does not recover to a trusted Pyth signer. - Swap reverts. For
slippageand!balanceon the swap, read the Curve pool table in Error codes.
To recover, compare your reads with the Before you send table, and quote again for the target block.
Risks for integrators
These risks apply to a trade on a pool that runs the oracle-report policy:
- crvUSD valued at $1. The policy values crvUSD at exactly $1. If crvUSD is off peg, the edge that the policy sees differs from your real edge. Value your profit at the market price of crvUSD.
- Competition. The earliest corrective swap in a block takes the gap. A rival's newer price report makes your delivery revert with "observation not newer". The next swap then trades against the rival's price report.
- Price report selection. The policy accepts any price report that passes admission. The newest observation wins, not the most accurate price. Pick the price report and size by net profit after the hedge.
- Owner changes. A YB DAO vote can replace
config()andoracle()within the owner limits. This change needs no Curve DAO vote.set_oracle_configdrops the stored price report price.relax_timeis the price report age at which the fee discount ends.report_lifetimeis the age below which the price report steers theprice_scaletarget. A change torelax_timeorreport_lifetimecan revive a stored price report. - Verifier trust. The owner chooses the verifier. The verifier decides which prices are authentic. If Pyth signs a wrong price, any trader can deliver it.
- Kill switch. The owner or
EMERGENCY_ADMINcan kill the policy at any time. While the policy is killed, the pool uses its native fee and nativeprice_scaletarget. Deliveries revert. Killing drops the stored price report price. Revival callssync(). - Detachment. A Curve DAO vote can detach or replace the policy (
pool.set_policy_contract). The quote views then revert "not attached". - Liquidity operations pay half the fallback fee on the imbalanced part. Adds and removals are not swaps, so
get_feereturnsfallback_fee. An LT deposit or withdrawal pays half of it on the imbalanced part.preview_depositandpreview_withdrawinclude this fee. For the rule, the spam penalty, and a one-coin example, readget_feein Pool policy. - LT deviation check. LT, the market's vault contract, mints yb-LP shares. An LT deposit whose debt is more than
ratio_toleranceoff the LEVAMM debt ratio reverts with "LT deviation". This check affects routers that deposit into the market, not swaps. - Balanced removal gas. A balanced
remove_liquiditycalls the policy with 300,000 gas. If that call fails and less than 500,000 gas remained before it, the pool reverts. A failed call leaves a stale snapshot, the pool state that the policy compares each operation with. Until the next pool operation stores a fresh snapshot, swaps payfallback_fee. To restore the discount sooner, callsync().
Owner limits
The YB DAO can change the settings only within fixed limits in the code. set_policy_config and set_oracle_config revert outside those limits. For both bound tables and their revert strings, read Pool policy.
Price report and quote reference
This section gives the byte layout of a price report, the rules that admit it, and the quote views that price a swap against it.
Byte layout
A price report is exactly 112 bytes. The verifier checks the 71-byte header and the signature. The policy decodes the 41-byte payload at bytes 71 to 112. Ranges are big-endian and exclude the end byte. This table gives each field and the contract that checks it:
| Bytes | Field | Required value | Checked by |
|---|---|---|---|
| 0–4 | EVM format magic | 0x2a22999a | Verifier |
| 4–69 | Signature r, s, v | Recovers to a trusted Pyth signer | Verifier |
| 69–71 | Payload length | 41 | Policy (the verifier reads it) |
| 71–75 | Payload magic | 0x93c7d375 | Policy |
| 75–83 | Message time, µs | ≤ block time + future_window_us | Policy |
| 83 | Channel | oracle().channel | Policy |
| 84 | Feed count | 1 | Policy |
| 85–89 | Feed id | FEED_ID | Policy |
| 89 | Property count | 3 | Policy |
| 90 | Property id | 0 (price) | Policy |
| 91–99 | Price mantissa, int64 | > 0 | Policy |
| 99 | Property id | 4 (exponent) | Policy |
| 100–102 | Price exponent, int16 | −18 to 0 | Policy |
| 102 | Property id | 12 (feed update time) | Policy |
| 103 | Value present | 1 | Policy |
| 104–112 | Observation time, µs | See the admission rules | Policy |
The policy converts the price to 18 decimals: report_price = mantissa × 10^(18 + exponent). For the payload fields with the revert string of each check, read Price report admission in Pool policy.
Admission rules
deliver_oracle_report(report_data: Bytes[112]) is permissionless and payable. It stores the price report only if all of these conditions hold, in this order:
- The policy is not killed.
- The pool has a
price_scaleabove 0. The call must not come from inside a pool operation. report_datais 112 bytes.- The verifier accepts the update and returns a non-zero signer and a 41-byte payload.
- The payload passes the format checks in the byte layout table.
0 < observation ≤ message ≤ block time + future_window_us.observation + past_window_us ≥ block time.- The observation is strictly newer than
report().observation_us. - The price is within
[min_price, max_price].
To read the windows and the price bounds, call policy.oracle(). The windows are at most 12 s (past_window_us) and 6 s (future_window_us). The observation time decides admission and age. A fresh message can carry an old observation.
Quote views
The policy has three quote views. The contract source in YBOraclizedPolicy.vy gives their signatures:
get_dy_with_report(i: uint256, j: uint256, dx: uint256, report_data: Bytes[112], block_timestamp: uint256) -> uint256
get_dy_with_report_age(i: uint256, j: uint256, dx: uint256, report_price: uint256, report_age_us: uint256) -> uint256
get_fee_with_report(xp: uint256[2], report_price: uint256, report_age_us: uint256) -> uint256
This table gives what each view returns, next to the pool's own quote:
| View | Returns |
|---|---|
get_dy_with_report | pool.get_dy(i, j, dx) as if this price report were stored. The view computes the age at block_timestamp |
get_dy_with_report_age | pool.get_dy(i, j, dx) as if a price report of this price (1e18 = $1) and age (µs) were stored |
get_fee_with_report | The fee for post-swap, pre-fee balances xp (the asset scaled by price_scale) |
pool.get_dy(i, j, dx) | The quote against the stored price report, at its age in the block of the call |
For get_dy_with_report, pass the target block timestamp. For the next block, this is usually the timestamp of the most recent block plus 12.
Know these limits before you use a quote:
- No signature check. The views do not call the verifier. They do not apply the time window, the price bounds or the "newer" rule. So a quote can succeed for a price report that
deliver_oracle_reportrejects. - Format checks apply.
get_dy_with_reportdecodes bytes 71 to 112 with the same format checks. A malformed payload reverts with the decode reason, for example "payload magic". - Pool state is this block's. Reserves,
price_scaleandAcome from the block of the call. Only the price report age moves withblock_timestamp. - A ramp. During an
Aramp, a quote can show a discount that the swap does not get (check 6 in the check order). - Wrong pool.
get_dy_with_reportandget_dy_with_report_agerevert with "not attached" ifpool.POLICY()is not this policy. - Killed. If the policy is killed, the views quote with the pool's native fee (
pool.fee_calc).
_quote repeats the arithmetic of the pool's _exchange. So a quote equals the exchange output if the pool state and the stored price report do not change and no A ramp is active. For the revert strings of the quote views, read Quote views in Pool policy.
Related
- How oracle-report swaps are priced: the fee checks and the profit and age tables.
- Arbitrage: the LEVAMM trade through the VirtualPool, which a
price_scalemove can open. - Pool policy: the policy source behind the fee rules, the structs, and the deployment configuration.
- Quote and route: quotes for the other pool policies and for deposits and withdrawals.
- Error codes: the policy strings next to the revert strings of the rest of the protocol.