diff --git a/abis/MetaMorpho.json b/abis/MetaMorpho.json index 333a0b9..494c528 100644 --- a/abis/MetaMorpho.json +++ b/abis/MetaMorpho.json @@ -23,12 +23,12 @@ }, { "internalType": "string", - "name": "_name", + "name": "__name", "type": "string" }, { "internalType": "string", - "name": "_symbol", + "name": "__symbol", "type": "string" } ], @@ -924,6 +924,19 @@ "name": "SetIsAllocator", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "name", + "type": "string" + } + ], + "name": "SetName", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -956,6 +969,19 @@ "name": "SetSupplyQueue", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "symbol", + "type": "string" + } + ], + "name": "SetSymbol", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -1127,6 +1153,19 @@ "name": "UpdateLastTotalAssets", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "newLostAssets", + "type": "uint256" + } + ], + "name": "UpdateLostAssets", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -1575,6 +1614,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "lostAssets", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -2116,6 +2168,19 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "string", + "name": "newName", + "type": "string" + } + ], + "name": "setName", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -2142,6 +2207,19 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "string", + "name": "newSymbol", + "type": "string" + } + ], + "name": "setSymbol", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -2343,7 +2421,7 @@ "outputs": [ { "internalType": "uint256", - "name": "assets", + "name": "", "type": "uint256" } ], diff --git a/networks.json b/networks.json index 32b220b..cabbb52 100644 --- a/networks.json +++ b/networks.json @@ -9,6 +9,10 @@ "address": "0xa9c3d3a366466fa809d1ae982fb2c46e5fc41101", "startBlock": 18925584 }, + "MetaMorphoFactoryV11": { + "address": "0x1897A8997241C1cD4bD0698647e4EB7213535c24", + "startBlock": 21439510 + }, "PublicAllocator": { "address": "0xfd32fA2ca22c76dD6E550706Ad913FC6CE91c75D", "startBlock": 19375099 @@ -24,6 +28,10 @@ "address": "0xa9c3d3a366466fa809d1ae982fb2c46e5fc41101", "startBlock": 13978134 }, + "MetaMorphoFactoryV11": { + "address": "0xFf62A7c278C62eD665133147129245053Bbf5918", + "startBlock": 23928808 + }, "PublicAllocator": { "address": "0xA090dD1a701408Df1d4d0B85b716c87565f90467", "startBlock": 13979545 diff --git a/schema.graphql b/schema.graphql index e198ff4..c09d481 100644 --- a/schema.graphql +++ b/schema.graphql @@ -2043,6 +2043,7 @@ type BadDebtRealization @entity { type MetaMorpho @entity { id: Bytes! + version: String! name: String! symbol: String! decimals: Int! diff --git a/src/meta-morpho-factory-v1.1.ts b/src/meta-morpho-factory-v1.1.ts new file mode 100644 index 0000000..cb75459 --- /dev/null +++ b/src/meta-morpho-factory-v1.1.ts @@ -0,0 +1,55 @@ +import { BigDecimal, BigInt } from "@graphprotocol/graph-ts"; + +import { CreateMetaMorpho as CreateMetaMorphoEvent } from "../generated/MetaMorphoFactory/MetaMorphoFactory"; +import { InterestRate, MetaMorpho } from "../generated/schema"; +import { MetaMorpho as MetaMorphoTemplate } from "../generated/templates"; + +import { getZeroMarket } from "./initializers/markets"; +import { AccountManager } from "./sdk/account"; +import { InterestRateSide, InterestRateType } from "./sdk/constants"; +import { TokenManager } from "./sdk/token"; + +export function handleCreateMetaMorpho(event: CreateMetaMorphoEvent): void { + MetaMorphoTemplate.create(event.params.metaMorpho); + const metaMorpho = new MetaMorpho(event.params.metaMorpho); + + metaMorpho.name = event.params.name; + metaMorpho.symbol = event.params.symbol; + metaMorpho.decimals = 18; + metaMorpho.version = "1.1"; + metaMorpho.asset = new TokenManager(event.params.asset, event).getToken().id; + + metaMorpho.owner = new AccountManager( + event.params.initialOwner + ).getAccount().id; + + metaMorpho.timelock = event.params.initialTimelock; + + metaMorpho.fee = BigInt.zero(); + metaMorpho.feeAccrued = BigInt.zero(); + metaMorpho.feeAccruedAssets = BigInt.zero(); + + metaMorpho.lastTotalAssets = BigInt.zero(); + metaMorpho.totalShares = BigInt.zero(); + metaMorpho.idle = BigInt.zero(); + + metaMorpho.supplyQueue = []; + metaMorpho.withdrawQueue = []; + + const rate = new InterestRate(metaMorpho.id.toHexString() + "-supply"); + rate.rate = BigDecimal.zero(); + rate.market = getZeroMarket(event).id; + rate.type = InterestRateType.VARIABLE; + rate.side = InterestRateSide.LENDER; + rate.save(); + + metaMorpho.rate = rate.id; + + metaMorpho.account = new AccountManager( + event.params.metaMorpho + ).getAccount().id; + + metaMorpho.hasPublicAllocator = false; + + metaMorpho.save(); +} diff --git a/src/meta-morpho-factory.ts b/src/meta-morpho-factory.ts index ac322bb..028876a 100644 --- a/src/meta-morpho-factory.ts +++ b/src/meta-morpho-factory.ts @@ -16,6 +16,7 @@ export function handleCreateMetaMorpho(event: CreateMetaMorphoEvent): void { metaMorpho.name = event.params.name; metaMorpho.symbol = event.params.symbol; metaMorpho.decimals = 18; + metaMorpho.version = "1.0"; metaMorpho.asset = new TokenManager(event.params.asset, event).getToken().id; metaMorpho.owner = new AccountManager( diff --git a/src/meta-morpho.ts b/src/meta-morpho.ts index 095b9af..304e2e5 100644 --- a/src/meta-morpho.ts +++ b/src/meta-morpho.ts @@ -45,6 +45,8 @@ import { RevokePendingTimelock as RevokePendingTimelockEvent, ReallocateSupply as ReallocateSupplyEvent, ReallocateWithdraw as ReallocateWithdrawEvent, + SetName as SetNameEvent, + SetSymbol as SetSymbolEvent, } from "../generated/templates/MetaMorpho/MetaMorpho"; import { loadPublicAllocatorVault } from "./public-allocator"; @@ -62,6 +64,33 @@ import { toMetaMorphoAssetsUp } from "./utils/metaMorphoUtils"; import { getPublicAllocatorAddress } from "./utils/publicAllocator"; import { cloneRate } from "./utils/rate"; +export function handleSetName(event: SetNameEvent): void { + const mm = loadMetaMorpho(event.address); + + if (mm.version !== "1.1") { + log.critical("MetaMorpho {} has a name set on a non 1.1 version", [ + event.address.toHexString(), + ]); + return; + } + mm.name = event.params.name; + mm.save(); +} + +export function handleSetSymbol(event: SetSymbolEvent): void { + const mm = loadMetaMorpho(event.address); + mm.symbol = event.params.symbol; + + if (mm.version !== "1.1") { + log.critical("MetaMorpho {} has a symbol set on a non 1.1 version", [ + event.address.toHexString(), + ]); + return; + } + + mm.save(); +} + export function handleSubmitMarketRemoval( event: SubmitMarketRemovalEvent ): void { @@ -214,7 +243,7 @@ export function handleOwnershipTransferred( export function handleRevokePendingCap(event: RevokePendingCapEvent): void { const mmMarket = MetaMorphoMarket.load(event.address.concat(event.params.id)); - if(!mmMarket) { + if (!mmMarket) { log.warning("MetaMorphoMarket {} not found", [ event.address.toHexString(), event.params.id.toString(), diff --git a/subgraph.yaml b/subgraph.yaml index 3ab1457..3b1e410 100644 --- a/subgraph.yaml +++ b/subgraph.yaml @@ -4,11 +4,11 @@ schema: dataSources: - kind: ethereum name: MorphoBlue - network: mainnet + network: base source: abi: MorphoBlue address: "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb" - startBlock: 18883124 + startBlock: 13977148 mapping: kind: ethereum/events apiVersion: 0.0.7 @@ -94,11 +94,11 @@ dataSources: file: ./src/morpho-blue.ts - kind: ethereum name: MetaMorphoFactory - network: mainnet + network: base source: abi: MetaMorphoFactory address: "0xa9c3d3a366466fa809d1ae982fb2c46e5fc41101" - startBlock: 18925584 + startBlock: 13978134 mapping: kind: ethereum/events apiVersion: 0.0.7 @@ -133,13 +133,55 @@ dataSources: address,string,string,bytes32) handler: handleCreateMetaMorpho file: ./src/meta-morpho-factory.ts + + - kind: ethereum + name: MetaMorphoFactoryV11 + network: base + source: + abi: MetaMorphoFactory + address: "0x1897A8997241C1cD4bD0698647e4EB7213535c24" + startBlock: 21439510 + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + entities: + - CreateMetaMorpho + abis: + - name: MetaMorphoFactory + file: ./abis/MetaMorphoFactory.json + - name: MorphoBlue + file: ./abis/MorphoBlue.json + - name: ERC20 + file: ./abis/ERC20.json + - name: ERC4626 + file: ./abis/ERC4626.json + - name: ERC20SymbolBytes + file: ./abis/ERC20SymbolBytes.json + - name: ERC20NameBytes + file: ./abis/ERC20NameBytes.json + - name: IRM + file: ./abis/IRM.json + - name: Oracle + file: ./abis/Oracle.json + - name: ChainlinkPriceFeed + file: ./abis/chainlink/ChainlinkPriceFeed.json + - name: WstEth + file: ./abis/WstEth.json + - name: REth + file: ./abis/REth.json + eventHandlers: + - event: CreateMetaMorpho(indexed address,indexed address,address,uint256,indexed + address,string,string,bytes32) + handler: handleCreateMetaMorpho + file: ./src/meta-morpho-factory-v1.1.ts - kind: ethereum name: PublicAllocator - network: mainnet + network: base source: abi: PublicAllocator - address: "0xfd32fA2ca22c76dD6E550706Ad913FC6CE91c75D" - startBlock: 19375099 + address: "0xA090dD1a701408Df1d4d0B85b716c87565f90467" + startBlock: 13979545 mapping: kind: ethereum/events apiVersion: 0.0.7 @@ -173,7 +215,7 @@ dataSources: templates: - kind: ethereum name: MetaMorpho - network: mainnet + network: base source: abi: MetaMorpho mapping: @@ -281,12 +323,16 @@ templates: handler: handleTransfer - event: UpdateLastTotalAssets(uint256) handler: handleUpdateLastTotalAssets + - event: SetName(string) + handler: handleSetName + - event: SetSymbol(string) + handler: handleSetSymbol - event: Withdraw(indexed address,indexed address,indexed address,uint256,uint256) handler: handleWithdraw file: ./src/meta-morpho.ts - kind: ethereum name: ChainlinkAggregatorProxy - network: mainnet + network: base source: abi: ChainlinkAggregatorProxy mapping: @@ -318,7 +364,7 @@ templates: file: ./src/chainlink.ts - kind: ethereum name: ChainlinkPriceFeed - network: mainnet + network: base source: abi: ChainlinkPriceFeed mapping: