Skip to content

Commit

Permalink
feat(metamorpho): handle metamorpho v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-devatom committed Jan 14, 2025
1 parent 6c9ad74 commit cb8747e
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 14 deletions.
84 changes: 81 additions & 3 deletions abis/MetaMorpho.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
},
{
"internalType": "string",
"name": "_name",
"name": "__name",
"type": "string"
},
{
"internalType": "string",
"name": "_symbol",
"name": "__symbol",
"type": "string"
}
],
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -1575,6 +1614,19 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "lostAssets",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -2116,6 +2168,19 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "newName",
"type": "string"
}
],
"name": "setName",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand All @@ -2142,6 +2207,19 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "newSymbol",
"type": "string"
}
],
"name": "setSymbol",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -2343,7 +2421,7 @@
"outputs": [
{
"internalType": "uint256",
"name": "assets",
"name": "",
"type": "uint256"
}
],
Expand Down
8 changes: 8 additions & 0 deletions networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"address": "0xa9c3d3a366466fa809d1ae982fb2c46e5fc41101",
"startBlock": 18925584
},
"MetaMorphoFactoryV11": {
"address": "0x1897A8997241C1cD4bD0698647e4EB7213535c24",
"startBlock": 21439510
},
"PublicAllocator": {
"address": "0xfd32fA2ca22c76dD6E550706Ad913FC6CE91c75D",
"startBlock": 19375099
Expand All @@ -24,6 +28,10 @@
"address": "0xa9c3d3a366466fa809d1ae982fb2c46e5fc41101",
"startBlock": 13978134
},
"MetaMorphoFactoryV11": {
"address": "0xFf62A7c278C62eD665133147129245053Bbf5918",
"startBlock": 23928808
},
"PublicAllocator": {
"address": "0xA090dD1a701408Df1d4d0B85b716c87565f90467",
"startBlock": 13979545
Expand Down
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,7 @@ type BadDebtRealization @entity {

type MetaMorpho @entity {
id: Bytes!
version: String!
name: String!
symbol: String!
decimals: Int!
Expand Down
55 changes: 55 additions & 0 deletions src/meta-morpho-factory-v1.1.ts
Original file line number Diff line number Diff line change
@@ -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();
}
1 change: 1 addition & 0 deletions src/meta-morpho-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
31 changes: 30 additions & 1 deletion src/meta-morpho.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 {
Expand Down Expand Up @@ -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(),
Expand Down
Loading

0 comments on commit cb8747e

Please sign in to comment.