Skip to content

Commit

Permalink
refactor: add price oracle address
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Nov 26, 2024
1 parent e42f4ae commit 9c1bc29
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
8 changes: 8 additions & 0 deletions subgraphs/protocol-reserve/src/mappings/tokenConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ConversionResumed,
ConverterNetworkAddressUpdated,
DestinationAddressUpdated,
PriceOracleUpdated,
} from '../../generated/BTCBPrimeConverter/TokenConverter';
import {
btcbPrimeConverterAddress,
Expand All @@ -18,6 +19,7 @@ import {
wethPrimeConverterAddress,
xvsVaultConverterAddress,
} from '../constants/addresses';
import { getTokenConverter } from '../operations/get';
import { getOrCreateTokenConverter } from '../operations/getOrCreate';
import { updateOrCreateTokenConverterConfig } from '../operations/updateOrCreate';
import { getConverterNetworkId } from '../utilities/ids';
Expand Down Expand Up @@ -91,3 +93,9 @@ export function handleBaseAssetUpdated(event: BaseAssetUpdated): void {
tokenConverter.baseAsset = event.params.newBaseAsset;
tokenConverter.save();
}

export function handlePriceOracleUpdated(event: PriceOracleUpdated): void {
const tokenConverter = getTokenConverter(event.address)!;
tokenConverter.priceOracleAddress = event.params.priceOracle;
tokenConverter.save();
}
3 changes: 3 additions & 0 deletions subgraphs/protocol-reserve/src/operations/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export function createTokenConverter(tokenConverterAddress: Address): TokenConve
tokenConverterContract.try_baseAsset(),
);
}
tokenConverter.priceOracleAddress = valueOrNotAvailableAddressIfReverted(
tokenConverterContract.try_priceOracle(),
);
tokenConverter.paused = false;
tokenConverter.save();
return tokenConverter;
Expand Down
12 changes: 11 additions & 1 deletion subgraphs/protocol-reserve/template-eth.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ dataSources:
handler: handleDestinationAddressUpdated
- event: BaseAssetUpdated(indexed address,indexed address)
handler: handleDestinationAddressUpdated
- event: PriceOracleUpdated(indexed address,indexed address)
handler: handlePriceOracleUpdated
blockHandlers:
- handler: handleInitializationWbtcPrimeConverter
filter:
Expand Down Expand Up @@ -101,6 +103,8 @@ dataSources:
handler: handleDestinationAddressUpdated
- event: BaseAssetUpdated(indexed address,indexed address)
handler: handleDestinationAddressUpdated
- event: PriceOracleUpdated(indexed address,indexed address)
handler: handlePriceOracleUpdated
blockHandlers:
- handler: handleInitializationWethPrimeConverter
filter:
Expand Down Expand Up @@ -139,6 +143,8 @@ dataSources:
handler: handleDestinationAddressUpdated
- event: BaseAssetUpdated(indexed address,indexed address)
handler: handleDestinationAddressUpdated
- event: PriceOracleUpdated(indexed address,indexed address)
handler: handlePriceOracleUpdated
blockHandlers:
- handler: handleInitializationUsdcPrimeConverter
filter:
Expand Down Expand Up @@ -177,6 +183,8 @@ dataSources:
handler: handleDestinationAddressUpdated
- event: BaseAssetUpdated(indexed address,indexed address)
handler: handleDestinationAddressUpdated
- event: PriceOracleUpdated(indexed address,indexed address)
handler: handlePriceOracleUpdated
blockHandlers:
- handler: handleInitializationUsdtPrimeConverter
filter:
Expand Down Expand Up @@ -219,6 +227,8 @@ dataSources:
- handler: handleInitializationXvsVaultConverter
filter:
kind: once
- event: PriceOracleUpdated(indexed address,indexed address)
handler: handlePriceOracleUpdated
templates:
- name: ERC20
kind: ethereum/contract
Expand All @@ -242,4 +252,4 @@ templates:
topic1: ["{{ wbtcPrimeConverterAddress }}", "{{ wethPrimeConverterAddress }}", "{{ usdcPrimeConverterAddress }}", "{{ usdtPrimeConverterAddress }}", "{{ xvsVaultConverterAddress }}"]
- event: Transfer(indexed address,indexed address,uint256)
handler: handleTransferIn
topic2: ["{{ wbtcPrimeConverterAddress }}", "{{ wethPrimeConverterAddress }}", "{{ usdcPrimeConverterAddress }}", "{{ usdtPrimeConverterAddress }}", "{{ xvsVaultConverterAddress }}"]
topic2: ["{{ wbtcPrimeConverterAddress }}", "{{ wethPrimeConverterAddress }}", "{{ usdcPrimeConverterAddress }}", "{{ usdtPrimeConverterAddress }}", "{{ xvsVaultConverterAddress }}"]
12 changes: 12 additions & 0 deletions subgraphs/protocol-reserve/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ dataSources:
handler: handleDestinationAddressUpdated
- event: BaseAssetUpdated(indexed address,indexed address)
handler: handleDestinationAddressUpdated
- event: PriceOracleUpdated(indexed address,indexed address)
handler: handlePriceOracleUpdated
blockHandlers:
- handler: handleInitializationBtcbPrimeConverter
filter:
Expand Down Expand Up @@ -100,6 +102,8 @@ dataSources:
handler: handleDestinationAddressUpdated
- event: BaseAssetUpdated(indexed address,indexed address)
handler: handleDestinationAddressUpdated
- event: PriceOracleUpdated(indexed address,indexed address)
handler: handlePriceOracleUpdated
blockHandlers:
- handler: handleInitializationEthPrimeConverter
filter:
Expand Down Expand Up @@ -136,6 +140,8 @@ dataSources:
handler: handleConverterNetworkAddressUpdated
- event: DestinationAddressUpdated(indexed address,indexed address)
handler: handleDestinationAddressUpdated
- event: PriceOracleUpdated(indexed address,indexed address)
handler: handlePriceOracleUpdated
blockHandlers:
- handler: handleInitializationRiskFundConverter
filter:
Expand Down Expand Up @@ -174,6 +180,8 @@ dataSources:
handler: handleDestinationAddressUpdated
- event: BaseAssetUpdated(indexed address,indexed address)
handler: handleDestinationAddressUpdated
- event: PriceOracleUpdated(indexed address,indexed address)
handler: handlePriceOracleUpdated
blockHandlers:
- handler: handleInitializationUsdcPrimeConverter
filter:
Expand Down Expand Up @@ -212,6 +220,8 @@ dataSources:
handler: handleDestinationAddressUpdated
- event: BaseAssetUpdated(indexed address,indexed address)
handler: handleDestinationAddressUpdated
- event: PriceOracleUpdated(indexed address,indexed address)
handler: handlePriceOracleUpdated
blockHandlers:
- handler: handleInitializationUsdtPrimeConverter
filter:
Expand Down Expand Up @@ -250,6 +260,8 @@ dataSources:
handler: handleDestinationAddressUpdated
- event: BaseAssetUpdated(indexed address,indexed address)
handler: handleBaseAssetUpdated
- event: PriceOracleUpdated(indexed address,indexed address)
handler: handlePriceOracleUpdated
blockHandlers:
- handler: handleInitializationXvsVaultConverter
filter:
Expand Down

0 comments on commit 9c1bc29

Please sign in to comment.