Skip to content

Commit

Permalink
feat(protocol): use "cardinalityNext" for TWAP criteria logic instead…
Browse files Browse the repository at this point in the history
… of "cardinality"

chore(protocol): re-generate types
  • Loading branch information
scorpion9979 committed Oct 12, 2023
1 parent 8d65cae commit 6a01de9
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/protocol/contracts/oracles/UniswapV3PriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ contract UniswapV3PriceFeed is
pool = pool_;

// Fetch the pool cardinality and most recent observation index.
(, , uint16 index, uint16 cardinality, , , ) = pool.slot0();
(, , uint16 index, uint16 cardinality, uint16 cardinalityNext, , ) = pool.slot0();

// Ensure the oldest pool observation is initialized and satisfies the TWAP interval.
// The next observation at index + 1 is the oldest observation in the ring buffer.
Expand All @@ -92,7 +92,7 @@ contract UniswapV3PriceFeed is
uint16 minimumCardinality = uint16((twapInterval_ * 10) / 125);

// Ensure the available TWAP interval and cardinality satisfy the TWAP criteria.
if (availableTwapInterval < twapInterval_ || cardinality < minimumCardinality) {
if (availableTwapInterval < twapInterval_ || cardinalityNext < minimumCardinality) {
revert IUniswapV3PriceFeed__TwapCriteriaNotSatisfied();
}

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/protocol/test/shared/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export async function unitFixtureUniswapV3PriceFeed(signers: Signer[]): Promise<
await pool.mock.token1.returns(wbtc.address);

const currentIndex: number = 0;
await pool.mock.slot0.returns(0, 0, currentIndex, DEFAULT_CARDINALITY, 0, 0, 0);
await pool.mock.slot0.returns(0, 0, currentIndex, DEFAULT_CARDINALITY, DEFAULT_CARDINALITY, 0, 0);

const oldestIndex: number = (currentIndex + 1) % DEFAULT_CARDINALITY;
const { timestamp }: { timestamp: number } = await ethers.provider.getBlock("latest");
Expand Down

0 comments on commit 6a01de9

Please sign in to comment.