Skip to content

Latest commit

 

History

History

simulation-sdk-wagmi

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

@morpho-org/simulation-sdk-wagmi

Version MIT License Downloads per month

Wagmi-based package that exports Wagmi (React) hooks to fetch Morpho-related entities.

Installation

npm install @morpho-org/simulation-sdk-wagmi
yarn add @morpho-org/simulation-sdk-wagmi

Getting Started

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>;
}