From 2c1b0035e654a06694ce581b43eee79f949ee063 Mon Sep 17 00:00:00 2001 From: Corey Rice Date: Fri, 3 Jan 2025 15:51:29 -0300 Subject: [PATCH] refactor: support underlying UpdatedImplementation events --- packages/isolated-pools-abis/Bep20.json | 13 +++++++++++++ subgraphs/isolated-pools/schema.graphql | 2 +- .../isolated-pools/src/mappings/underlying.ts | 11 +++++++++++ .../isolated-pools/src/operations/create.ts | 6 +++++- subgraphs/isolated-pools/template.yaml | 18 ++++++++++++++++++ 5 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 subgraphs/isolated-pools/src/mappings/underlying.ts diff --git a/packages/isolated-pools-abis/Bep20.json b/packages/isolated-pools-abis/Bep20.json index 405d6b36..6bbf6597 100644 --- a/packages/isolated-pools-abis/Bep20.json +++ b/packages/isolated-pools-abis/Bep20.json @@ -218,5 +218,18 @@ ], "name": "Transfer", "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "implementation", + "type": "address" + } + ], + "name": "Upgraded", + "type": "event" } ] diff --git a/subgraphs/isolated-pools/schema.graphql b/subgraphs/isolated-pools/schema.graphql index c41587a9..e25759e7 100644 --- a/subgraphs/isolated-pools/schema.graphql +++ b/subgraphs/isolated-pools/schema.graphql @@ -38,7 +38,7 @@ type Pool @entity { """ ERC20 Token """ -type Token @entity(immutable: true) { +type Token @entity { "Address of the asset" id: Bytes! "Address of the asset" diff --git a/subgraphs/isolated-pools/src/mappings/underlying.ts b/subgraphs/isolated-pools/src/mappings/underlying.ts new file mode 100644 index 00000000..5c047598 --- /dev/null +++ b/subgraphs/isolated-pools/src/mappings/underlying.ts @@ -0,0 +1,11 @@ +import { Upgraded } from '../../generated/templates/Underlying/BEP20'; +import { BEP20 } from '../../generated/PoolRegistry/BEP20'; +import { getOrCreateToken } from '../operations/getOrCreate'; + +export function handleUpgraded(event: Upgraded): void { + const token = getOrCreateToken(event.address); + const erc20 = BEP20.bind(event.address); + token.name = erc20.name(); + token.symbol = erc20.symbol(); + token.save(); +} diff --git a/subgraphs/isolated-pools/src/operations/create.ts b/subgraphs/isolated-pools/src/operations/create.ts index 3f48495a..15574305 100644 --- a/subgraphs/isolated-pools/src/operations/create.ts +++ b/subgraphs/isolated-pools/src/operations/create.ts @@ -2,7 +2,10 @@ import { Address, BigInt } from '@graphprotocol/graph-ts'; import { Comptroller as ComptrollerContract } from '../../generated/PoolRegistry/Comptroller'; import { PoolRegistry as PoolRegistryContract } from '../../generated/PoolRegistry/PoolRegistry'; -import { VToken as VTokenDataSource } from '../../generated/templates'; +import { + Underlying as UnderlyingDataSource, + VToken as VTokenDataSource, +} from '../../generated/templates'; import { BadDebtIncreased, Borrow, @@ -111,6 +114,7 @@ export function createMarket( const vTokenContract = VTokenContract.bind(vTokenAddress); const poolComptroller = Comptroller.bind(comptroller); const underlyingAddress = vTokenContract.underlying(); + UnderlyingDataSource.create(underlyingAddress); const market = new Market(vTokenAddress); diff --git a/subgraphs/isolated-pools/template.yaml b/subgraphs/isolated-pools/template.yaml index 51e50dc0..116bb7cd 100644 --- a/subgraphs/isolated-pools/template.yaml +++ b/subgraphs/isolated-pools/template.yaml @@ -155,6 +155,24 @@ templates: handler: handleBadDebtRecovered - event: HealBorrow(indexed address,indexed address,uint256) handler: handleHealBorrow + - name: Underlying + kind: ethereum/contract + network: {{ network }} + source: + abi: BEP20 + mapping: + abis: + - name: BEP20 + file: ../../packages/isolated-pools-abis/Bep20.json + kind: ethereum/events + apiVersion: 0.0.9 + language: wasm/assemblyscript + file: ./src/mappings/underlying.ts + entities: + - Token + eventHandlers: + - event: Upgraded(indexed address) + handler: handleUpgraded - name: RewardsDistributor kind: ethereum/contract network: {{ network }}