Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(liquidity-loader): add parameters to loader #252

Merged
merged 6 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
key: ${{ runner.os }}-foundry-chain-fork-${{ github.job }}-${{ github.sha }}
restore-keys: ${{ runner.os }}-foundry-chain-fork-${{ github.job }}-

- uses: foundry-rs/foundry-toolchain@v1.2.0
- uses: foundry-rs/foundry-toolchain@v1
with:
cache: false

Expand Down
31 changes: 22 additions & 9 deletions packages/liquidity-sdk-viem/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,17 @@ import { getBlock } from "viem/actions";
import { apiSdk } from "./api";

export interface LiquidityParameters {
/* The delay to consider between the moment reallocations are calculated and the moment they are committed onchain. Defaults to 1h. */
/** The delay to consider between the moment reallocations are calculated and the moment they are committed onchain. Defaults to 1h. */
delay?: bigint;

/** The default maximum utilization allowed to reach to find shared liquidity (scaled by WAD). */
defaultMaxWithdrawalUtilization?: bigint;

/**
* If provided, defines the maximum utilization allowed to reach for each market, defaulting to `defaultMaxWithdrawalUtilization`.
* If not, these values are fetched from Morpho API.
*/
maxWithdrawalUtilization?: Record<MarketId, bigint>;
}

export class LiquidityLoader<chain extends Chain = Chain> {
Expand Down Expand Up @@ -196,14 +205,16 @@ export class LiquidityLoader<chain extends Chain = Chain> {
),
});

const maxWithdrawalUtilization = fromEntries(
allVaultsMarkets.flatMap(([, markets]) =>
markets.map((market) => [
market.uniqueKey,
market.targetWithdrawUtilization,
]),
),
);
const maxWithdrawalUtilization =
this.parameters.maxWithdrawalUtilization ??
fromEntries(
allVaultsMarkets.flatMap(([, markets]) =>
markets.map((market) => [
market.uniqueKey,
market.targetWithdrawUtilization,
]),
),
);

return apiMarkets.map(({ uniqueKey, targetBorrowUtilization }) => {
try {
Expand All @@ -212,6 +223,8 @@ export class LiquidityLoader<chain extends Chain = Chain> {
enabled: true,
maxWithdrawalUtilization,
delay: parameters.delay,
defaultMaxWithdrawalUtilization:
this.parameters.defaultMaxWithdrawalUtilization,
});

return {
Expand Down
Loading