> For the complete documentation index, see [llms.txt](https://jpydf.gitbook.io/jpy-defi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jpydf.gitbook.io/jpy-defi/collateral-and-pricing/oracle.md).

# How Prices Are Determined (Oracle)

JPY DeFi values all collateral in yen, because collateral ratios, redemption amounts, and branch-shutdown checks are calculated in yen. Market feeds are quoted in USD, so the protocol converts the collateral's USD price through JPY/USD and then multiplies it by the dToken backing ratio.

## Calculating the yen price

The basic formula is:

`collateral price in ¥ = (collateral / USD) ÷ (JPY / USD) × dToken backing ratio`

JPY/USD is the USD price of one yen, so division converts the USD price into yen. Each branch has its own collateral USD price, but every branch uses the same JPY/USD feed.

| Branch  | Collateral USD price                                                                                                                                            |
| ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| dwstETH | Borrowing and liquidation multiply the stETH/USD price by stETH per wstETH (the amount of stETH per wstETH). Normal and urgent redemption use the formula below |
| dUSDC   | USDC/USD                                                                                                                                                        |

Normal and urgent redemption for dwstETH use this formula:

```
max(direct stETH/USD, ETH/USD × stETH/ETH)
× stETH per wstETH
÷ JPY/USD
× dToken backing ratio
```

`direct stETH/USD` is the price read directly from the stETH/USD feed, and `ETH/USD × stETH/ETH` is a price calculated from two feeds. Borrowing and liquidation use only the former, so a fall in stETH is reflected in collateral value. Redemption uses the higher of the two, which prevents an outdated low price from paying out too much collateral. On the other hand, if a price above the market remains within its allowed age, the redeemer receives less collateral.

## Price checks and stops

Each Chainlink feed is checked on every read: the data must be complete, the update time must be valid and not too old, and the price must be positive. What happens when a check fails depends on how the price is used.

1. **Collateral price, conversion rate, and backing ratio**: If any of them fails, the branch enters a pause. The branch also pauses if a normal dwstETH redemption is attempted while the ETH/USD (valid for 2 hours) or stETH/ETH (valid for 25 hours) price it uses has expired.
2. **JPY/USD for normal redemption**: Once the JPY/USD price in use is 30 hours old or more, only normal redemption stops. It resumes automatically when a new price arrives. This stop alone does not pause the whole branch.
3. **JPY/USD for borrowing, liquidation, urgent redemption, and other operations**: A price less than 72 hours old is used as is. After the feed fails, the last saved price may be used for up to 24 hours. If, during that grace period, the protocol obtains data that is newer than before but already 72 hours old or more, the grace period is counted again starting 72 hours after that data's update time. An outage therefore does not always stop operations within 96 hours of when it began. When the grace period runs out, the branch pauses, and even after a new price arrives, normal operations stay stopped until the governance multisig checks and resumes the branch.
4. **Urgent redemption**: Can execute only when the price source returns a valid urgent-redemption price; prices saved in the PriceFeedProxy are not used. For dwstETH, the ETH/USD and stETH/ETH prices must also be available.

On weekends and holidays when currency markets are closed, the JPY/USD update time can advance while the price stays the same, so the 30-hour cutoff does not apply. Redemptions can therefore execute at a price that differs from the exchange rate when the market reopens, to the disadvantage of the redeemed borrowers. Because JPY/USD is shared by all branches, a delay or stop can also affect several branches at once.

## Pause and permanent shutdown

When a price feed fails, the branch enters a pause from which it can resume. The failed price is not used to check the branch-wide collateral ratio, so that price alone cannot cause a permanent shutdown. During the pause, opening Troves, withdrawing collateral, borrowing more, changing rates or delegation, and normal redemption are not possible. The governance multisig that manages the price source resumes the branch without a waiting period after confirming that prices can be obtained for all three uses: borrowing and liquidation, normal redemption, and urgent redemption. Once market prices can be obtained again, risk-reducing operations such as liquidation, adding collateral, repayment, and closing may be available before the resume.

Separately, if a healthy price shows the branch-wide collateral ratio below the SCR, anyone can permanently shut down the branch. This mechanism is inherited from Liquity v2, and once prices recover it can be executed even before the pause is lifted.

## Replacing the price source

The Core references a PriceFeedProxy at a fixed address. The governance multisig can change the actual price source the PriceFeedProxy uses.

* A normal change waits 12 hours after the proposal, then checks that the three prices for borrowing and liquidation, normal redemption, and urgent redemption are within 1% of the reference prices and that all three can be obtained from the new source. If the old source has failed, the previously confirmed prices serve as the reference.
* When, for example, a new price is more than 1% away from the reference, the governance multisig can at its discretion use an emergency procedure that skips this comparison. The emergency procedure cannot skip the 12-hour wait or the check that all three prices can be obtained from the new source.

With the emergency procedure, prices after the switch can differ significantly from the previous source or the market. New dToken deposits may be stopped in that case, but borrowing against existing collateral does not stop.

## dToken backing ratio

The collateral's yen price is multiplied by the dToken backing ratio (capped at 1.0). It is normally 1.0; if it falls below 1.0, the collateral's yen value falls by the same proportion, so an under-backed dToken is not counted as full collateral. The definition of the backing ratio and the conditions under which it falls are in [dToken](/jpy-defi/collateral-and-pricing/dtoken.md).
