Skip to content

Commit

Permalink
refactor: support underlying UpdatedImplementation events
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Jan 4, 2025
1 parent d59ff7b commit 2c1b003
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
13 changes: 13 additions & 0 deletions packages/isolated-pools-abis/Bep20.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,18 @@
],
"name": "Transfer",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "implementation",
"type": "address"
}
],
"name": "Upgraded",
"type": "event"
}
]
2 changes: 1 addition & 1 deletion subgraphs/isolated-pools/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions subgraphs/isolated-pools/src/mappings/underlying.ts
Original file line number Diff line number Diff line change
@@ -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();
}
6 changes: 5 additions & 1 deletion subgraphs/isolated-pools/src/operations/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down
18 changes: 18 additions & 0 deletions subgraphs/isolated-pools/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down

0 comments on commit 2c1b003

Please sign in to comment.