Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions yarn-project/ethereum/src/contracts/fee_asset_price_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,25 @@ export class FeeAssetPriceOracle {

@memoize
async getUniswapOracle(): Promise<UniswapPriceOracle | undefined> {
if ((await this.client.getCode({ address: STATE_VIEW_ADDRESS.toString() })) === '0x') {
const code = await this.client.getCode({ address: STATE_VIEW_ADDRESS.toString() });
if (code === undefined || code === '0x') {
this.log.warn('Uniswap V4 StateView contract not found, skipping fee asset price oracle');
return undefined;
}
this.log.info('Uniswap V4 StateView contract found, initializing fee asset price oracle');
return new UniswapPriceOracle(this.client, this.log);
const oracle = new UniswapPriceOracle(this.client, this.log);

try {
if (!(await oracle.isPoolInitialized())) {
this.log.warn('Uniswap V4 pool not initialized, skipping fee asset price oracle');
return undefined;
}
} catch (err) {
this.log.warn(`Failed to check if Uniswap V4 pool is initialized: ${err}`);
return undefined;
}

return oracle;
}

/**
Expand Down Expand Up @@ -210,6 +223,11 @@ class UniswapPriceOracle {
return keccak256(encoded);
}

async isPoolInitialized(): Promise<boolean> {
const [sqrtPriceX96] = await this.stateView.read.getSlot0([this.poolId], undefined);
return sqrtPriceX96 !== 0n;
}

/**
* Gets the price as ETH per FeeAsset, scaled by 1e12.
* This is the format expected by the rollup contract.
Expand Down
Loading