Wagmi-based package that exports Wagmi (React) hooks to fetch Morpho-related entities.
npm install @morpho-org/simulation-sdk-wagmi
yarn add @morpho-org/simulation-sdk-wagmi
import { useMemo } from "react";
import { Address, MarketId } from "@morpho-org/blue-sdk";
import { simulateOperation } from "@morpho-org/simulation-sdk";
import { useSimulationState } from "@morpho-org/simulation-sdk-wagmi";
export function Component({
user,
marketId,
}: {
user?: Address;
marketId?: MarketId;
}) {
const { data } = useSimulationState({ marketIds: [marketId], users: [user] });
const simulated = useMemo(() => {
if (data == null) return;
return simulateOperation(
{
type: "Blue_Supply",
sender: user,
args: {
id: marketId,
onBehalf: user,
assets: 1_000000n,
},
},
data
);
}, [data, user, marketId]);
return <h1>{simulated.getPosition(user, marketId).supplyShares}</h1>;
}