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

perf(blue-sdk-ethers): remove useless, delayed fetch from config #226

Merged
merged 2 commits into from
Jan 6, 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
4 changes: 1 addition & 3 deletions packages/blue-sdk-ethers/src/augment/Vault.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { AccrualVault, Vault } from "@morpho-org/blue-sdk";

import { fetchAccrualVault, fetchVault, fetchVaultFromConfig } from "../fetch";
import { fetchAccrualVault, fetchVault } from "../fetch";

declare module "@morpho-org/blue-sdk" {
namespace Vault {
let fetch: typeof fetchVault;
let fetchFromConfig: typeof fetchVaultFromConfig;
}

namespace AccrualVault {
Expand All @@ -14,7 +13,6 @@ declare module "@morpho-org/blue-sdk" {
}

Vault.fetch = fetchVault;
Vault.fetchFromConfig = fetchVaultFromConfig;
AccrualVault.fetch = fetchAccrualVault;

export { Vault, AccrualVault };
22 changes: 5 additions & 17 deletions packages/blue-sdk-ethers/src/fetch/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
ChainUtils,
type MarketId,
Vault,
type VaultConfig,
type VaultPublicAllocatorConfig,
getChainAddresses,
} from "@morpho-org/blue-sdk";
Expand All @@ -24,25 +23,13 @@ export async function fetchVault(
options.chainId ?? (await runner.provider.getNetwork()).chainId,
);

const config = await fetchVaultConfig(address, runner, options);

return fetchVaultFromConfig(address, config, runner, options);
}

export async function fetchVaultFromConfig(
address: Address,
config: VaultConfig,
runner: { provider: Provider },
{ chainId, overrides = {} }: FetchOptions = {},
) {
chainId = ChainUtils.parseSupportedChainId(
chainId ?? (await runner.provider.getNetwork()).chainId,
);

const chainAddresses = getChainAddresses(chainId);
const chainAddresses = getChainAddresses(options.chainId);
const mm = MetaMorpho__factory.connect(address, runner);

const { overrides = {} } = options;

const [
config,
curator,
owner,
guardian,
Expand All @@ -60,6 +47,7 @@ export async function fetchVaultFromConfig(
withdrawQueueSize,
hasPublicAllocator,
] = await Promise.all([
fetchVaultConfig(address, runner, options),
mm.curator(overrides) as Promise<Address>,
mm.owner(overrides) as Promise<Address>,
mm.guardian(overrides) as Promise<Address>,
Expand Down
2 changes: 1 addition & 1 deletion packages/blue-sdk-ethers/src/fetch/VaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function fetchVaultConfig(
const { overrides = {} } = options;

const [token, asset, decimalsOffset] = await Promise.all([
fetchToken(address, runner, options),
fetchToken(address, runner, options), // TODO: avoid fetching decimals
mm.asset() as Promise<Address>,
mm.DECIMALS_OFFSET(overrides),
]);
Expand Down
2 changes: 1 addition & 1 deletion packages/blue-sdk-viem/src/fetch/VaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function fetchVaultConfig(
);

const [token, asset, decimalsOffset] = await Promise.all([
fetchToken(address, client, parameters),
fetchToken(address, client, parameters), // TODO: avoid fetching decimals
readContract(client, {
...parameters,
address,
Expand Down
Loading