Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle ether fi market initialization #144

Merged
merged 2 commits into from
Nov 26, 2024
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
28 changes: 26 additions & 2 deletions src/mapping/proxy-price-provider/v3.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { PriceOracle, PriceOracleAsset } from '../../../generated/schema';
import { Pool, PriceOracle, PriceOracleAsset } from '../../../generated/schema';
import {
AaveOracle,
AssetSourceUpdated,
BaseCurrencySet,
FallbackOracleUpdated,
} from '../../../generated/AaveOracle/AaveOracle';
import { Address, ethereum, log, Bytes } from '@graphprotocol/graph-ts';
import { Address, ethereum, log, BigInt } from '@graphprotocol/graph-ts';
import {
formatUsdEthChainlinkPrice,
getPriceOracleAssetType,
Expand All @@ -20,13 +20,15 @@ import {
getChainlinkAggregator,
getOrInitPriceOracle,
getPriceOracleAsset,
getProtocol,
} from '../../helpers/v3/initializers';
import { genericPriceUpdate, usdEthPriceUpdate } from '../../helpers/v3/price-updates';

import { PriceOracle as FallbackPriceOracle } from '../../../generated/AaveOracle/PriceOracle';

import { FallbackPriceOracle as FallbackPriceOracleContract } from '../../../generated/templates';
import { MOCK_USD_ADDRESS, ZERO_ADDRESS } from '../../utils/constants';
import { PoolAddressesProvider } from '../../../generated/templates';

export function handleFallbackOracleUpdated(event: FallbackOracleUpdated): void {
let priceOracle = getOrInitPriceOracle();
Expand Down Expand Up @@ -76,6 +78,28 @@ export function handleFallbackOracleUpdated(event: FallbackOracleUpdated): void
usdEthPriceUpdate(priceOracle, ethUsdPrice, event);
}
}

// ================== ETHER FI MARKET ONLY ==================
// This is a workaround only for the Ether Fi market, due to the order in which the market was initialized.
// This event handler will fire in the constructor of the Aave Price Oracle, at which point the address provider
// has been initialized, so we can create the Pool.

// Check if this is the price oracle on Ether Fi
if (address == Address.fromString('0x43b64f28A678944E0655404B0B98E443851cC34F')) {
let protocol = getProtocol();
let poolAddressesProvider = Address.fromString('0xeBa440B438Ad808101d1c451C1C5322c90BEFCdA'); // Ether Fi Address Provider
if (Pool.load(poolAddressesProvider.toHexString()) == null) {
let pool = new Pool(poolAddressesProvider.toHexString());
pool.protocol = protocol.id;
pool.addressProviderId = BigInt.fromI32(45); // Id of the Ether Fi market in the address provider registry
pool.active = true;
pool.paused = false;
pool.lastUpdateTimestamp = event.block.timestamp.toI32();
pool.save();

PoolAddressesProvider.create(poolAddressesProvider);
}
}
}

export function priceFeedUpdated(
Expand Down