Skip to content

Commit

Permalink
Merge pull request #20 from morpho-org/feat/getters-to-utilization
Browse files Browse the repository at this point in the history
feat(market): add liquidity to utilization getters
  • Loading branch information
Rubilmax authored Aug 2, 2024
2 parents ca98ff8 + e110ef6 commit 412442f
Show file tree
Hide file tree
Showing 20 changed files with 273 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/npm-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

- run: yarn install --immutable

- run: yarn lerna version --no-private --conventional-commits --create-release github --generate-release-notes --force-publish --y
- run: yarn lerna version --no-private --conventional-commits --create-release github --generate-release-notes --y

- run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## 1.4.1 (2024-08-02)

### Bug Fixes

* **package:** move local dependencies to peer dependencies ([1553663](https://github.com/morpho-org/sdks/commit/15536638c4564743b9d96de17b34739346b3b3e0))

# 1.4.0 (2024-08-01)

**Note:** Version bump only for package @morpho-org/sdks
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "node_modules/@lerna-lite/cli/schemas/lerna-schema.json",
"version": "1.4.0",
"version": "1.4.1",
"npmClient": "yarn",
"useWorkspaces": true
}
6 changes: 6 additions & 0 deletions packages/blue-api-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## 1.4.1 (2024-08-02)

### Bug Fixes

* **package:** move local dependencies to peer dependencies ([1553663](https://github.com/morpho-org/sdks/commit/15536638c4564743b9d96de17b34739346b3b3e0))

# 1.4.0 (2024-08-01)

**Note:** Version bump only for package @morpho-org/blue-api-sdk
21 changes: 12 additions & 9 deletions packages/blue-api-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@morpho-org/blue-api-sdk",
"version": "1.4.0",
"version": "1.4.1",
"author": "Morpho Association <[email protected]>",
"main": "lib/index.js",
"main": "src/index.ts",
"files": [
"lib"
],
Expand All @@ -11,11 +11,6 @@
"codegen": "graphql-codegen --config codegen.ts",
"build": "tsc --build tsconfig.build.json"
},
"dependencies": {
"@morpho-org/blue-sdk": "workspace:^",
"@morpho-org/blue-sdk-ethers": "workspace:^",
"@morpho-org/morpho-ts": "workspace:^"
},
"devDependencies": {
"@apollo/client": "^3.11.1",
"@graphql-codegen/cli": "^5.0.0",
Expand All @@ -24,12 +19,20 @@
"@graphql-codegen/typescript": "^4.0.1",
"@graphql-codegen/typescript-operations": "^4.0.1",
"@graphql-codegen/typescript-resolvers": "^4.1.0",
"@morpho-org/blue-sdk": "workspace:^",
"@morpho-org/blue-sdk-ethers": "workspace:^",
"@morpho-org/morpho-ts": "workspace:^",
"graphql": "^16.8.1",
"graphql-tag": "^2.12.6",
"typescript": "^5.4.5"
},
"peerDependencies": {
"@morpho-org/blue-sdk": "workspace:^",
"@morpho-org/blue-sdk-ethers": "workspace:^",
"@morpho-org/morpho-ts": "workspace:^"
},
"publishConfig": {
"main": "lib/index.js",
"access": "public"
},
"gitHead": "17b1a46190f11620ae969927aec1c891f9752ca0"
}
}
6 changes: 6 additions & 0 deletions packages/blue-sdk-ethers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## 1.4.1 (2024-08-02)

### Bug Fixes

* **package:** move local dependencies to peer dependencies ([1553663](https://github.com/morpho-org/sdks/commit/15536638c4564743b9d96de17b34739346b3b3e0))

# 1.4.0 (2024-08-01)

**Note:** Version bump only for package @morpho-org/blue-sdk-ethers
12 changes: 6 additions & 6 deletions packages/blue-sdk-ethers/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@morpho-org/blue-sdk-ethers",
"version": "1.4.0",
"version": "1.4.1",
"author": "Morpho Association <[email protected]>",
"license": "MIT",
"main": "lib/index.js",
"main": "src/index.ts",
"files": [
"lib"
],
Expand All @@ -14,15 +14,15 @@
"test-hardhat": "hardhat test"
},
"dependencies": {
"@morpho-org/blue-sdk": "workspace:^",
"@morpho-org/morpho-ts": "workspace:^",
"ethers": "^6.12.1",
"ethers-multicall-provider": "^6.3.0",
"ethers-types": "^3.17.1",
"rxjs": "^7.8.1"
},
"devDependencies": {
"@morpho-org/blue-sdk": "workspace:^",
"@morpho-org/morpho-test": "workspace:^",
"@morpho-org/morpho-ts": "workspace:^",
"@nomicfoundation/hardhat-ethers": "^3.0.6",
"@nomicfoundation/hardhat-network-helpers": "^1.0.11",
"@types/chai": "^4.3.14",
Expand All @@ -47,6 +47,7 @@
"@morpho-org/morpho-ts": "workspace:^"
},
"publishConfig": {
"main": "lib/index.js",
"access": "public"
},
"jest": {
Expand All @@ -67,6 +68,5 @@
"ts"
],
"preset": "ts-jest"
},
"gitHead": "17b1a46190f11620ae969927aec1c891f9752ca0"
}
}
6 changes: 6 additions & 0 deletions packages/blue-sdk-viem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## 1.4.1 (2024-08-02)

### Bug Fixes

* **package:** move local dependencies to peer dependencies ([1553663](https://github.com/morpho-org/sdks/commit/15536638c4564743b9d96de17b34739346b3b3e0))

# 1.4.0 (2024-08-01)

**Note:** Version bump only for package @morpho-org/blue-sdk-viem
12 changes: 6 additions & 6 deletions packages/blue-sdk-viem/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@morpho-org/blue-sdk-viem",
"version": "1.4.0",
"version": "1.4.1",
"author": "Morpho Association <[email protected]>",
"license": "MIT",
"main": "lib/index.js",
"main": "src/index.ts",
"files": [
"lib"
],
Expand All @@ -13,12 +13,12 @@
"test": "hardhat test"
},
"dependencies": {
"@morpho-org/blue-sdk": "workspace:^",
"@morpho-org/morpho-ts": "workspace:^",
"viem": "^2.17.4"
},
"devDependencies": {
"@morpho-org/blue-sdk": "workspace:^",
"@morpho-org/morpho-test": "workspace:^",
"@morpho-org/morpho-ts": "workspace:^",
"@nomicfoundation/hardhat-network-helpers": "^1.0.11",
"@nomicfoundation/hardhat-viem": "^2.0.3",
"@types/chai": "^4.3.14",
Expand All @@ -41,7 +41,7 @@
"@morpho-org/morpho-ts": "workspace:^"
},
"publishConfig": {
"main": "lib/index.js",
"access": "public"
},
"gitHead": "17b1a46190f11620ae969927aec1c891f9752ca0"
}
}
6 changes: 6 additions & 0 deletions packages/blue-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## 1.4.1 (2024-08-02)

### Bug Fixes

* **package:** move local dependencies to peer dependencies ([1553663](https://github.com/morpho-org/sdks/commit/15536638c4564743b9d96de17b34739346b3b3e0))

# 1.4.0 (2024-08-01)

**Note:** Version bump only for package @morpho-org/blue-sdk
13 changes: 8 additions & 5 deletions packages/blue-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@morpho-org/blue-sdk",
"version": "1.4.0",
"version": "1.4.1",
"author": "Morpho Association <[email protected]>",
"license": "MIT",
"main": "lib/index.js",
"main": "src/index.ts",
"files": [
"lib"
],
Expand All @@ -13,18 +13,22 @@
"test": "jest"
},
"dependencies": {
"@morpho-org/morpho-ts": "workspace:^",
"keccak256": "^1.0.6"
},
"devDependencies": {
"@morpho-org/morpho-test": "workspace:^",
"@morpho-org/morpho-ts": "workspace:^",
"@types/jest": "^29.5.12",
"@types/node": "^22.0.0",
"jest": "^29.7.0",
"ts-jest": "^29.2.2",
"typescript": "^5.4.5"
},
"peerDependencies": {
"@morpho-org/morpho-ts": "workspace:^"
},
"publishConfig": {
"main": "lib/index.js",
"access": "public"
},
"jest": {
Expand All @@ -45,6 +49,5 @@
"ts"
],
"preset": "ts-jest"
},
"gitHead": "17b1a46190f11620ae969927aec1c891f9752ca0"
}
}
32 changes: 24 additions & 8 deletions packages/blue-sdk/src/market/Market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ export class Market implements InputMarket {

let borrowRate = 0n;
let { rateAtTarget } = this;
if (this.rateAtTarget != null) {
if (rateAtTarget != null) {
const { avgBorrowRate, endRateAtTarget } =
AdaptiveCurveIrmLib.getBorrowRate(
this.utilization,
this.rateAtTarget,
rateAtTarget,
elapsed,
);

Expand Down Expand Up @@ -351,19 +351,35 @@ export class Market implements InputMarket {
}

/**
* Returns the liquidity available to borrow until the market reach the given utilization rate.
* Returns the volume to supply until the market gets the closest to the given utilization rate.
* @param utilization The target utilization rate (scaled by WAD).
*/
public getSupplyLiquidityToUtilization(utilization: bigint) {
return MarketUtils.getSupplyLiquidityToUtilization(this, utilization);
public getSupplyToUtilization(utilization: bigint) {
return MarketUtils.getSupplyToUtilization(this, utilization);
}

/**
* Returns the liquidity available to borrow until the market reach the given utilization rate.
* Returns the liquidity available to withdraw until the market gets the closest to the given utilization rate.
* @param utilization The target utilization rate (scaled by WAD).
*/
public getBorrowLiquidityToUtilization(utilization: bigint) {
return MarketUtils.getBorrowLiquidityToUtilization(this, utilization);
public getWithdrawToUtilization(utilization: bigint) {
return MarketUtils.getWithdrawToUtilization(this, utilization);
}

/**
* Returns the liquidity available to borrow until the market gets the closest to the given utilization rate.
* @param utilization The target utilization rate (scaled by WAD).
*/
public getBorrowToUtilization(utilization: bigint) {
return MarketUtils.getBorrowToUtilization(this, utilization);
}

/**
* Returns the volume to repay until the market gets the closest to the given utilization rate.
* @param utilization The target utilization rate (scaled by WAD).
*/
public getRepayToUtilization(utilization: bigint) {
return MarketUtils.getRepayToUtilization(this, utilization);
}

/**
Expand Down
72 changes: 72 additions & 0 deletions packages/blue-sdk/src/market/MarketUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MathLib } from "../maths";
import { MarketUtils } from "./MarketUtils";

const market = {
Expand All @@ -20,4 +21,75 @@ describe("MarketUtils", () => {
1043841336116910229n,
);
});

it("should calculate the supply volume to reach utilization", () => {
expect(
MarketUtils.getSupplyToUtilization(
{ totalSupplyAssets: MathLib.WAD, totalBorrowAssets: MathLib.WAD },
90_0000000000000000n,
),
).toEqual(11_1111111111111112n);

expect(
MarketUtils.getSupplyToUtilization(
{ totalSupplyAssets: MathLib.WAD, totalBorrowAssets: 0n },
90_0000000000000000n,
),
).toEqual(0n);
});

it("should calculate the withdraw volume to reach utilization", () => {
expect(
MarketUtils.getWithdrawToUtilization(
{ totalSupplyAssets: MathLib.WAD, totalBorrowAssets: MathLib.WAD },
90_0000000000000000n,
),
).toEqual(0n);

expect(
MarketUtils.getWithdrawToUtilization(
{ totalSupplyAssets: 2n * MathLib.WAD, totalBorrowAssets: MathLib.WAD },
90_0000000000000000n,
),
).toEqual(88_8888888888888888n);

expect(
MarketUtils.getWithdrawToUtilization(
{ totalSupplyAssets: MathLib.WAD, totalBorrowAssets: 0n },
90_0000000000000000n,
),
).toEqual(MathLib.WAD);
});

it("should calculate the borrow volume to reach utilization", () => {
expect(
MarketUtils.getBorrowToUtilization(
{ totalSupplyAssets: MathLib.WAD, totalBorrowAssets: MathLib.WAD },
90_0000000000000000n,
),
).toEqual(0n);

expect(
MarketUtils.getBorrowToUtilization(
{ totalSupplyAssets: MathLib.WAD, totalBorrowAssets: 0n },
90_0000000000000000n,
),
).toEqual(90_0000000000000000n);
});

it("should calculate the repay volume to reach utilization", () => {
expect(
MarketUtils.getRepayToUtilization(
{ totalSupplyAssets: MathLib.WAD, totalBorrowAssets: MathLib.WAD },
90_0000000000000000n,
),
).toEqual(10_0000000000000000n);

expect(
MarketUtils.getRepayToUtilization(
{ totalSupplyAssets: MathLib.WAD, totalBorrowAssets: 0n },
90_0000000000000000n,
),
).toEqual(0n);
});
});
Loading

0 comments on commit 412442f

Please sign in to comment.