@morpho-org/blue-sdk
TypeScript icon, indicating that this package has built-in type declarations

1.2.3 • Public • Published

@morpho-org/blue-sdk

npm package Downloads

Framework-agnostic SDK foundational to Morpho Blue's offchain ecosystem, useful to fetch and interact with Morpho Blue and MetaMorpho.

Install

npm install @morpho-org/blue-sdk
yarn add @morpho-org/blue-sdk

Getting Started

Instance of the immutable configuration of a specific market

Leverage the MarketConfig class to manipulate a given market's immutable configuration:

import { MarketConfig } from "@morpho-org/blue-sdk";

const config = new MarketConfig({
  loanToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",       // WETH
  collateralToken: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0", // wstETH
  oracle: "0x2a01EB9496094dA03c4E364Def50f5aD1280AD72",
  irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",             // AdaptiveCurveIrm
  lltv: 94_5000000000000000n,                                    // 94.5%
});

config.liquidationIncentiveFactor; // e.g. 1_090000000000000000n (109%).

Instance of a specific market

Leverage the Market class to manipulate a specific market:

import { Market } from "@morpho-org/blue-sdk";
import { Time } from "@morpho-org/morpho-ts";

const market = new Market({
  config: new MarketConfig({
    loanToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",       // WETH
    collateralToken: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0", // wstETH
    oracle: "0x2a01EB9496094dA03c4E364Def50f5aD1280AD72",
    irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",             // AdaptiveCurveIrm
    lltv: 94_5000000000000000n,                                    // 94.5%
  }),
  totalSupplyAssets: 1000_000000000000000000n,
  totalBorrowAssets: 920_000000000000000000n,
  totalSupplyShares: 1000_000000000000000000000000n,
  totalBorrowShares: 920_000000000000000000000000n,
  lastUpdate: 1721000000n,
  fee: 0n,
  price: 1_100000000000000000000000000000000000n,
  rateAtTarget: 94850992095n
});

market.utilization; // e.g. 92_0000000000000000n (92%).
market.liquidity; // e.g. 80_000000000000000000n (in loan assets).
market.apyAtTarget; // e.g. 3_0000000000000000n (3%).

const accruedMarket = market.accrueInterest(Time.timestamp()); // Accrue interest to the latest's timestamp.

accruedMarket.toSupplyAssets(shares); // Convert supply shares to assets.

Instance of the position of a specific user on a specific market

Leverage the Position class to manipulate the position of a user on a given market:

import { Position } from "@morpho-org/blue-sdk";
import { Time } from "@morpho-org/morpho-ts";

const position = new AccrualPosition(
  new Position({
    user,
    marketId: market.id,
    supplyShares: 0n,
    borrowShares: 20_000000000000000000000000n,
    collateral: 27_000000000000000000n
  }),
  market
);

position.borrowAssets; // e.g. 20_000000000000000000n (in loan assets).
position.isHealthy; // e.g. true.
position.maxBorrowableAssets; // e.g. 2100_000000000000000000n (in loan assets).

const accruedPosition = position.accrueInterest(Time.timestamp()); // Accrue interest to the latest's timestamp.

position.borrowAssets; // e.g. 20_400000000000000000n (in loan assets).

Readme

Keywords

none

Package Sidebar

Install

npm i @morpho-org/blue-sdk

Weekly Downloads

522

Version

1.2.3

License

MIT

Unpacked Size

215 kB

Total Files

80

Last publish

Collaborators

  • gabin53
  • rubilmax
  • merlin-egalite
  • mathisgd
  • julien-devatom