Skip to content

Commit

Permalink
Merge branch 'next' of https://github.com/morpho-org/sdks into feat/s…
Browse files Browse the repository at this point in the history
…ky-additional-liquidity
  • Loading branch information
0x666c6f committed Oct 24, 2024
2 parents 003aa8f + 39a2c08 commit 65bed1a
Show file tree
Hide file tree
Showing 104 changed files with 1,503 additions and 1,538 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,18 @@ jobs:
run: node ../../scripts/release/release.js
working-directory: packages/${{ matrix.package }}

# First, set version of each package to the most recent so they are referenced correctly in dependencies.
# Set version of each package to the most recent so they are referenced correctly in dependencies.
- run: |
pnpm -r -c exec 'node ../../scripts/release/version.js'
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
if: steps.release.outputs.version
- run: pnpm version ${{ steps.release.outputs.version }} --no-git-tag-version
working-directory: packages/${{ matrix.package }}
echo "${{ steps.release.outputs.changelog }}" > CHANGELOG.md
if: steps.release.outputs.version
- run: pnpm publish --no-git-checks --access public --tag ${{ steps.release.outputs.channel }}
working-directory: packages/${{ matrix.package }}
if: steps.release.outputs.version

- run: gh release create ${{ steps.release.outputs.tag }} --notes '${{ steps.release.outputs.changelog }}' --title '${{ steps.release.outputs.tag }}' ${{ steps.release.outputs.channel == 'latest' && '--latest' || '--prerelease' }}
- run: gh release create ${{ steps.release.outputs.tag }} --target ${{ steps.release.outputs.branch }} --notes-file CHANGELOG.md --title '${{ steps.release.outputs.tag }}' ${{ steps.release.outputs.channel == 'latest' && '--latest' || '--prerelease' }}
if: steps.release.outputs.version
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
publish:
if: github.ref_name == 'main' || github.ref_name == 'next'

# needs:
# - lint
# - build
# - test
needs:
- lint
- build
- test

uses: ./.github/workflows/publish.yml
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
node-version-file: .nvmrc
cache: pnpm

- uses: foundry-rs/foundry-toolchain@v1
- uses: foundry-rs/foundry-toolchain@v1.2.0

- run: pnpm install

Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
},
"[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "biomejs.biome"
}
}
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Morpho SDKs

A collection of Software Development Kits to ease interactions with the Morpho protocol and Morpho Vaults.
![image](https://github.com/user-attachments/assets/c77d5054-5342-4c1b-81ae-b8c002c2fd8d)

<p align="center"><i>A collection of Software Development Kits to ease interactions with the Morpho protocol and Morpho Vaults.</i></p>
<br />

## Getting Started

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"devDependencies": {
"@actions/core": "^1.11.1",
"@biomejs/biome": "^1.9.3",
"@biomejs/biome": "^1.9.4",
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@vitest/coverage-v8": "^2.1.3",
Expand Down
6 changes: 3 additions & 3 deletions packages/blue-api-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@morpho-org/blue-api-sdk",
"description": "GraphQL SDK that exports types from the [API's GraphQL schema](https://blue-api.morpho.org/graphql) and a useful Apollo cache controller.",
"version": "1.12.4",
"version": "2.0.0",
"author": "Morpho Association <contact@morpho.org>",
"contributors": ["Rubilmax <rmilon@gmail.com>"],
"repository": "github:morpho-org/sdks",
Expand All @@ -23,8 +23,8 @@
"@morpho-org/morpho-ts": "workspace:^"
},
"devDependencies": {
"@graphql-codegen/cli": "^5.0.0",
"@graphql-codegen/typescript": "^4.0.1",
"@graphql-codegen/cli": "^5.0.3",
"@graphql-codegen/typescript": "^4.1.0",
"@morpho-org/blue-sdk": "workspace:^",
"@morpho-org/morpho-ts": "workspace:^",
"graphql": "^16.9.0",
Expand Down
30 changes: 14 additions & 16 deletions packages/blue-api-sdk/src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {
AccrualVault,
type Address,
Market,
MarketConfig,
MarketParams,
MathLib,
Position,
TokenWithPrice,
Token,
VaultConfig,
VaultMarketAllocation,
VaultMarketConfig,
Expand Down Expand Up @@ -41,14 +41,14 @@ export interface PartialBlueApiToken
name?: BlueApiToken["name"];
}

export interface PartialBlueApiMarketConfig
export interface PartialBlueApiMarketParams
extends Pick<BlueApiMarket, "oracleAddress" | "irmAddress" | "lltv"> {
collateralAsset: Maybe<Pick<BlueApiToken, "address">>;
loanAsset: Pick<BlueApiToken, "address">;
}

export interface PartialBlueApiMarket
extends PartialBlueApiMarketConfig,
extends PartialBlueApiMarketParams,
Pick<BlueApiMarket, "collateralPrice"> {
state: Maybe<
Pick<
Expand Down Expand Up @@ -160,21 +160,19 @@ export class BlueSdkConverter {
return price;
}

public getTokenWithPrice(
public getToken(
dto: PartialBlueApiToken,
ethPriceUsd?: BlueApiToken["priceUsd"],
) {
return new TokenWithPrice(
{
...dto,
address: this.options.parseAddress(dto.address),
},
this.getPriceUsd(dto, ethPriceUsd),
);
return new Token({
...dto,
address: this.options.parseAddress(dto.address),
price: this.getPriceUsd(dto, ethPriceUsd),
});
}

public getMarketConfig(dto: PartialBlueApiMarketConfig) {
return new MarketConfig({
public getMarketParams(dto: PartialBlueApiMarketParams) {
return new MarketParams({
collateralToken: this.options.parseAddress(
dto.collateralAsset?.address ?? ZERO_ADDRESS,
),
Expand All @@ -188,7 +186,7 @@ export class BlueSdkConverter {
public getMarket(dto: PartialBlueApiMarket) {
if (dto.state == null) return null;

const config = this.getMarketConfig(dto);
const params = this.getMarketParams(dto);
const fee = this.options.parseNumber(dto.state.fee, 18);
const price = dto.collateralPrice ?? 1n;

Expand All @@ -201,7 +199,7 @@ export class BlueSdkConverter {
: undefined;

return new Market({
config,
params,
totalSupplyAssets: dto.state.supplyAssets,
totalBorrowAssets: dto.state.borrowAssets,
totalSupplyShares: dto.state.supplyShares,
Expand Down
10 changes: 5 additions & 5 deletions packages/blue-sdk-ethers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Opt in classes augmentation to easily fetch an entire entity of the Morpho Blue
import "@morpho-org/blue-sdk-ethers/lib/augment/AccrualPosition";
import "@morpho-org/blue-sdk-ethers/lib/augment/Holding";
import "@morpho-org/blue-sdk-ethers/lib/augment/Market";
import "@morpho-org/blue-sdk-ethers/lib/augment/MarketConfig";
import "@morpho-org/blue-sdk-ethers/lib/augment/MarketParams";
import "@morpho-org/blue-sdk-ethers/lib/augment/Position";
import "@morpho-org/blue-sdk-ethers/lib/augment/Token";
import "@morpho-org/blue-sdk-ethers/lib/augment/VaultConfig";
Expand All @@ -60,14 +60,14 @@ import "@morpho-org/blue-sdk-ethers/lib/augment";

### Fetch the config of a specific market

Leverage the [`MarketConfig`](./src/market/MarketConfig.ts) class to fetch information on a given market's immutable configuration:
Leverage the [`MarketParams`](./src/market/MarketParams.ts) class to fetch information on a given market's immutable configuration:

```typescript
import { MarketId } from "@morpho-org/blue-sdk";
// /!\ Import MarketConfig from the augmentation file (or simply import the file)
import { MarketConfig } from "@morpho-org/blue-sdk-ethers/lib/augment/MarketConfig";
// /!\ Import MarketParams from the augmentation file (or simply import the file)
import { MarketParams } from "@morpho-org/blue-sdk-ethers/lib/augment/MarketParams";

const config = await MarketConfig.fetch(
const config = await MarketParams.fetch(
"0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc" as MarketId,
provider // Ethers provider.
);
Expand Down
10 changes: 5 additions & 5 deletions packages/blue-sdk-ethers/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@morpho-org/blue-sdk-ethers",
"description": "Ethers-based augmentation of `@morpho-org/blue-sdk` that exports (and optionally injects) ethers-based fetch methods.",
"version": "1.12.4",
"version": "2.0.0",
"author": "Morpho Association <contact@morpho.org>",
"license": "MIT",
"type": "module",
Expand All @@ -20,11 +20,11 @@
"@morpho-org/morpho-ts": "workspace:^",
"@morpho-org/test": "workspace:^",
"@morpho-org/test-ethers": "workspace:^",
"@types/node": "^22.1.0",
"ethers": "^6.13.3",
"ethers-types": "^3.17.0",
"@types/node": "^22.7.8",
"ethers": "^6.13.4",
"ethers-types": "^3.17.2",
"typescript": "^5.6.3",
"viem": "^2.21.19",
"viem": "^2.21.32",
"vitest": "^2.1.3"
},
"peerDependencies": {
Expand Down
12 changes: 0 additions & 12 deletions packages/blue-sdk-ethers/src/augment/MarketConfig.ts

This file was deleted.

12 changes: 12 additions & 0 deletions packages/blue-sdk-ethers/src/augment/MarketParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { MarketParams } from "@morpho-org/blue-sdk";
import { fetchMarketParams } from "../fetch/index.js";

declare module "@morpho-org/blue-sdk" {
namespace MarketParams {
let fetch: typeof fetchMarketParams;
}
}

MarketParams.fetch = fetchMarketParams;

export { MarketParams };
2 changes: 1 addition & 1 deletion packages/blue-sdk-ethers/src/augment/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from "./Holding.js";
export * from "./Position.js";
export * from "./MarketConfig.js";
export * from "./MarketParams.js";
export * from "./Market.js";
export * from "./Token.js";
export * from "./User.js";
Expand Down
28 changes: 15 additions & 13 deletions packages/blue-sdk-ethers/src/fetch/Market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import {
import {
ChainUtils,
Market,
type MarketConfig,
type MarketId,
type MarketParams,
getChainAddresses,
} from "@morpho-org/blue-sdk";
import type { FetchOptions } from "../types.js";
import { fetchMarketConfig } from "./MarketConfig.js";
import { fetchMarketParams } from "./MarketParams.js";

export async function fetchMarket(
id: MarketId,
Expand All @@ -24,13 +24,13 @@ export async function fetchMarket(
chainId ?? (await runner.provider.getNetwork()).chainId,
);

const config = await fetchMarketConfig(id, runner, { chainId });
const config = await fetchMarketParams(id, runner, { chainId });

return fetchMarketFromConfig(config, runner, { chainId, overrides });
}

export async function fetchMarketFromConfig(
config: MarketConfig,
params: MarketParams,
runner: { provider: Provider },
{ chainId, overrides = {} }: FetchOptions = {},
) {
Expand All @@ -56,25 +56,27 @@ export async function fetchMarketFromConfig(
morpho,
// @ts-ignore incompatible commonjs type
runner,
).market(config.id, overrides),
config.oracle !== ZeroAddress
).market(params.id, overrides),
params.oracle !== ZeroAddress
? BlueOracle__factory.connect(
config.oracle,
params.oracle,
// @ts-ignore incompatible commonjs type
runner,
).price(overrides)
: 0n,
config.irm === adaptiveCurveIrm
)
.price(overrides)
.catch(() => undefined)
: undefined,
params.irm === adaptiveCurveIrm
? await AdaptiveCurveIrm__factory.connect(
config.irm,
params.irm,
// @ts-ignore incompatible commonjs type
runner,
).rateAtTarget(config.id, overrides)
).rateAtTarget(params.id, overrides)
: undefined,
]);

return new Market({
config,
params,
totalSupplyAssets,
totalBorrowAssets,
totalSupplyShares,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import {
type Address,
type ChainId,
ChainUtils,
MarketConfig,
type MarketId,
UnknownMarketConfigError,
MarketParams,
UnknownMarketParamsError,
_try,
getChainAddresses,
} from "@morpho-org/blue-sdk";

export async function fetchMarketConfig(
export async function fetchMarketParams(
id: MarketId,
runner: { provider: Provider },
{ chainId }: { chainId?: ChainId } = {},
) {
let config = _try(() => MarketConfig.get(id), UnknownMarketConfigError);
let config = _try(() => MarketParams.get(id), UnknownMarketParamsError);

if (!config) {
chainId = ChainUtils.parseSupportedChainId(
Expand All @@ -35,7 +35,7 @@ export async function fetchMarketConfig(
blockTag: "latest",
});

config = new MarketConfig({
config = new MarketParams({
lltv: marketParams.lltv,
loanToken: marketParams.loanToken as Address,
collateralToken: marketParams.collateralToken as Address,
Expand Down
4 changes: 2 additions & 2 deletions packages/blue-sdk-ethers/src/fetch/Position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
AccrualPosition,
type Address,
ChainUtils,
type MarketConfig,
type MarketId,
type MarketParams,
Position,
getChainAddresses,
} from "@morpho-org/blue-sdk";
Expand Down Expand Up @@ -61,7 +61,7 @@ export async function fetchAccrualPosition(

export async function fetchAccrualPositionFromConfig(
user: Address,
config: MarketConfig,
config: MarketParams,
runner: { provider: Provider },
options: FetchOptions = {},
) {
Expand Down
Loading

0 comments on commit 65bed1a

Please sign in to comment.