Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/index public allocator #12

Merged
merged 13 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
579 changes: 579 additions & 0 deletions abis/PublicAllocator.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"MetaMorphoFactory": {
"address": "0xa9c3d3a366466fa809d1ae982fb2c46e5fc41101",
"startBlock": 18925584
},
"PublicAllocator": {
"address": "0xfd32fA2ca22c76dD6E550706Ad913FC6CE91c75D",
"startBlock": 19375099
}
},
"base": {
Expand All @@ -19,6 +23,10 @@
"MetaMorphoFactory": {
"address": "0xa9c3d3a366466fa809d1ae982fb2c46e5fc41101",
"startBlock": 13978134
},
"PublicAllocator": {
"address": "0xA090dD1a701408Df1d4d0B85b716c87565f90467",
"startBlock": 13979545
}
}
}
246 changes: 245 additions & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,11 @@ type Account @entity @regularPolling {
metaMorphoTransferFrom: [MetaMorphoTransfer!]! @derivedFrom(field: "from")
metaMorphoTransferTo: [MetaMorphoTransfer!]! @derivedFrom(field: "to")

publicAllocatorAdmin: [MetaMorphoPublicAllocator!]! @derivedFrom(field: "admin")
publicAllocatorReallocateToAuthor: [PublicAllocatorReallocationToEvent!]! @derivedFrom(field: "author")
publicAllocatorWithdrawalAuthor: [PublicAllocatorWithdrawalEvent!]! @derivedFrom(field: "author")
publicAllocatorSetFlowCapsAuthor: [SetFlowCapsEvent!]! @derivedFrom(field: "author")


}

Expand Down Expand Up @@ -2047,6 +2052,7 @@ type MetaMorpho @entity {
owner: Account!
curator: Account
allocators: [MetaMorphoAllocator!]! @derivedFrom(field: "metaMorpho")
hasPublicAllocator: Boolean!
guardian: Account

timelock: BigInt!
Expand Down Expand Up @@ -2082,6 +2088,9 @@ type MetaMorpho @entity {
deposits: [MetaMorphoDeposit!]! @derivedFrom(field: "metaMorpho")
withdraws: [MetaMorphoWithdraw!]! @derivedFrom(field: "metaMorpho")
transfers: [MetaMorphoTransfer!]! @derivedFrom(field: "metaMorpho")

publicAllocator: MetaMorphoPublicAllocator @derivedFrom(field: "metaMorpho")

}
type FeeRecipient @entity {
id: Bytes!
Expand All @@ -2103,6 +2112,9 @@ type MetaMorphoMarket @entity {
isInSupplyQueue: Boolean!
isInWithdrawQueue: Boolean!
pendingCaps: [PendingCap!]! @derivedFrom(field: "metaMorphoMarket")

publicAllocatorMarket: MetaMorphoPublicAllocatorMarket @derivedFrom(field: "market")

# TODO: add position
}

Expand Down Expand Up @@ -2177,6 +2189,9 @@ type MetaMorphoAllocator @entity {
account: Account!
metaMorpho: MetaMorpho!
isCurrentAllocator: Boolean!
isPublicAllocator: Boolean!

publicAllocatorConfig: MetaMorphoPublicAllocator @derivedFrom(field: "allocator")
}


Expand Down Expand Up @@ -2373,4 +2388,233 @@ type MetaMorphoTransfer @entity(immutable: true) {

rate: InterestRate!

}
}

type MetaMorphoPublicAllocator @entity {
" { MetaMorpho ID } "
id: Bytes!

" The MetaMorpho associated with this public allocator vault configuration "
metaMorpho: MetaMorpho!

" The allocator associated with this public allocator vault configuration"
allocator: MetaMorphoAllocator

" The current fee per public reallocation "
fee: BigInt!
" The fee accrued by the admin "
accruedFee: BigInt!
" The fee that can be claimed by the admin "
claimableFee: BigInt!
" The fee claimed by the admin "
claimedFee: BigInt!

" The current admin of the public allocator. Value is optional & fallbacks on the vault owner "
admin: Account

" All the markets public allocator configurations. Values contained are the latest values "
markets: [MetaMorphoPublicAllocatorMarket!]! @derivedFrom(field: "metaMorphoPublicAllocator")

" All the public flow caps changes for this MetaMorpho (on all markets) "
setFlowCapsEvents: [SetFlowCapsEvent!]! @derivedFrom(field: "metaMorphoPublicAllocator")

" All the public flowIn modifications for this MetaMorpho (on all markets) "
reallocationToEvents: [PublicAllocatorReallocationToEvent!]! @derivedFrom(field: "metaMorphoPublicAllocator")

" All the public flowOut modifications for this MetaMorpho (on all markets) "
withdrawalEvents: [PublicAllocatorWithdrawalEvent!]! @derivedFrom(field: "metaMorphoPublicAllocator")

" All the flow caps changes for this MetaMorpho (on all markets) "
flowCapsChanges: [MarketFlowCapsSet!]! @derivedFrom(field: "metaMorphoPublicAllocator")

}

type MetaMorphoPublicAllocatorMarket @entity {
" { MetaMorpho ID }-{ Market ID } "
id: Bytes!

" The MetaMorpho public allocator configuration. Values contained are the latest values "
metaMorphoPublicAllocator: MetaMorphoPublicAllocator!
" The MetaMorpho market associated with the public allocator "
market: MetaMorphoMarket!

" The current flow cap in for this market for the given MetaMorpho "
flowCapIn: BigInt!
" The current flow cap out for this market for the given MetaMorpho "
flowCapOut: BigInt!

" All the public flowIn modifications for this market for the given MetaMorpho "
reallocationToEvents: [PublicAllocatorReallocationToEvent!]! @derivedFrom(field: "marketPublicAllocator")

" All the public flowOut modifications for this market for the given MetaMorpho "
withdrawalEvents: [PublicAllocatorWithdrawalEvent!]! @derivedFrom(field: "marketPublicAllocator")

" All the flow caps changes for this market for the given MetaMorpho "
flowCapsChanges: [MarketFlowCapsSet!]! @derivedFrom(field: "marketPublicAllocator")

}

" The event emitted when the flow caps are set by the public allocator admin "
type SetFlowCapsEvent @entity(immutable: true) @transaction {

" { Transaction hash }{ Log index } "
id: Bytes!

" Transaction hash of the transaction that emitted this event "
hash: Bytes!

" Nonce of the transaction that emitted this event "
nonce: BigInt!

" Event log index. For transactions that don't emit event, create arbitrary index starting from 0 "
logIndex: Int!

" Price of gas in this transaction "
gasPrice: BigInt

" Gas used in this transaction. (Optional because not every chain will support this) "
gasUsed: BigInt

" Gas limit of this transaction. e.g. the amount of gas the sender will pay "
gasLimit: BigInt

" Block number of this event "
blockNumber: BigInt!

" Timestamp of this event "
timestamp: BigInt!

" Author of the Public allocator call "
author: Account!

" The metaMorpho public allocator configuration. Values contained are the latest values "
metaMorphoPublicAllocator: MetaMorphoPublicAllocator!

" The different flow caps set by this event. "
flowCaps: [MarketFlowCapsSet!]! @derivedFrom(field: "setFlowCapsEvent")
}

" The event emitted when the public allocator reallocates assets to a market. This function is publicly accessible "
type PublicAllocatorReallocationToEvent @entity(immutable: true) @transaction {

" { Transaction hash }{ Log index } "
id: Bytes!

" Transaction hash of the transaction that emitted this event "
hash: Bytes!

" Nonce of the transaction that emitted this event "
nonce: BigInt!

" Event log index. For transactions that don't emit event, create arbitrary index starting from 0 "
logIndex: Int!

" Price of gas in this transaction "
gasPrice: BigInt

" Gas used in this transaction. (Optional because not every chain will support this) "
gasUsed: BigInt

" Gas limit of this transaction. e.g. the amount of gas the sender will pay "
gasLimit: BigInt

" Block number of this event "
blockNumber: BigInt!

" Timestamp of this event "
timestamp: BigInt!

" Author of the Public allocator call "
author: Account!

" The metaMorpho public allocator configuration. Values contained are the latest values "
metaMorphoPublicAllocator: MetaMorphoPublicAllocator!

" The latest market public allocator configuration. Values contained are the latest values "
marketPublicAllocator: MetaMorphoPublicAllocatorMarket!

" The amount of assets supplied "
suppliedAssets: BigInt!

" The flow caps modification set by this event "
flowCaps: MarketFlowCapsSet! @derivedFrom(field: "publicReallocationEvent")
}

" The event emitted when the public allocator withdraws assets from a market. This function is publicly accessible "
type PublicAllocatorWithdrawalEvent @entity(immutable: true) @transaction {

" { Transaction hash }{ Log index } "
id: Bytes!

" Transaction hash of the transaction that emitted this event "
hash: Bytes!

" Nonce of the transaction that emitted this event "
nonce: BigInt!

" Event log index. For transactions that don't emit event, create arbitrary index starting from 0 "
logIndex: Int!

" Price of gas in this transaction "
gasPrice: BigInt

" Gas used in this transaction. (Optional because not every chain will support this) "
gasUsed: BigInt

" Gas limit of this transaction. e.g. the amount of gas the sender will pay "
gasLimit: BigInt

" Block number of this event "
blockNumber: BigInt!

" Timestamp of this event "
timestamp: BigInt!

" Author of the Public allocator call "
author: Account!

" The metaMorpho public allocator configuration. Values contained are the latest values "
metaMorphoPublicAllocator: MetaMorphoPublicAllocator

" The latest market public allocator configuration. Values contained are the latest values "
marketPublicAllocator: MetaMorphoPublicAllocatorMarket

" The amount of assets withdrawn "
withdrawnAssets: BigInt!

" The flow caps modification set by this event "
flowCaps: MarketFlowCapsSet! @derivedFrom(field: "publicWithdrawalEvent")
}

" Register of any change of the flow caps, either if it comes from a public call or an admin call (FlowCapSetEvent) "
type MarketFlowCapsSet @entity(immutable: true) {
" { Transaction hash }{ Log index }{ markedId if applicable } "
id: Bytes!

" The metaMorpho public allocator configuration. Values contained are the latest values "
metaMorphoPublicAllocator: MetaMorphoPublicAllocator!

" The latest market public allocator configuration. Values contained are the latest values "
marketPublicAllocator: MetaMorphoPublicAllocatorMarket!

" The previous flow cap in value "
prevFlowCapIn: BigInt!
" The new flow cap in value "
flowCapIn: BigInt!

" The previous flow cap out value "
prevFlowCapOut: BigInt!
" The new flow cap out value "
flowCapOut: BigInt!


" The set flow caps event that has set this flow caps. null if this is not set by a set flow caps event "
setFlowCapsEvent: SetFlowCapsEvent

" The public reallocation event that has set this flow caps. null if this is not set by a reallocation event "
publicReallocationEvent: PublicAllocatorReallocationToEvent

" The public withdrawal event that has set this flow caps. null if this is not set by a withdrawal event "
publicWithdrawalEvent: PublicAllocatorWithdrawalEvent

}
2 changes: 2 additions & 0 deletions src/meta-morpho-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,7 @@ export function handleCreateMetaMorpho(event: CreateMetaMorphoEvent): void {
event.params.metaMorpho
).getAccount().id;

metaMorpho.hasPublicAllocator = false;

metaMorpho.save();
}
19 changes: 19 additions & 0 deletions src/meta-morpho.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
ReallocateWithdraw as ReallocateWithdrawEvent,
} from "../generated/templates/MetaMorpho/MetaMorpho";

import { loadPublicAllocatorVault } from "./public-allocator";
import { AccountManager } from "./sdk/account";
import {
loadMetaMorpho,
Expand All @@ -58,6 +59,7 @@ import {
} from "./sdk/metamorpho";
import { TokenManager } from "./sdk/token";
import { toMetaMorphoAssetsUp } from "./utils/metaMorphoUtils";
import { getPublicAllocatorAddress } from "./utils/publicAllocator";
import { cloneRate } from "./utils/rate";

export function handleSubmitMarketRemoval(
Expand Down Expand Up @@ -394,8 +396,24 @@ export function handleSetIsAllocator(event: SetIsAllocatorEvent): void {
allocator.metaMorpho = mm.id;
}
allocator.isCurrentAllocator = event.params.isAllocator;
allocator.isPublicAllocator = getPublicAllocatorAddress().equals(
event.params.allocator
);

allocator.save();

if (allocator.isPublicAllocator && event.params.isAllocator) {
mm.hasPublicAllocator = true;

// Update the public allocator vault. It can be created before the allocator is set, so we need to update it here.
const publicAllocatorVault = loadPublicAllocatorVault(event.address);
publicAllocatorVault.allocator = allocator.id;
publicAllocatorVault.save();
} else {
mm.hasPublicAllocator = false;
}
mm.save();

const allocatorSet = new AllocatorSet(
event.transaction.hash.concat(Bytes.fromI32(event.logIndex.toI32()))
);
Expand All @@ -420,6 +438,7 @@ export function handleSetSkimRecipient(event: SetSkimRecipientEvent): void {}
export function handleSetSupplyQueue(event: SetSupplyQueueEvent): void {
// Supply queue on subgraph is a list of MetaMorphoMarket ids, not Market ids.
const mm = loadMetaMorpho(event.address);

const newSupplyQueue: Array<Bytes> = [];
const addedMarkets: Array<Bytes> = [];
const seen = new Map<Bytes, boolean>();
Expand Down
Loading
Loading