Skip to content

Commit

Permalink
Merge pull request #226 from morpho-org/perf/ethers-vault
Browse files Browse the repository at this point in the history
perf(blue-sdk-ethers): remove useless, delayed fetch from config
  • Loading branch information
Rubilmax authored Jan 6, 2025
2 parents 07b5c30 + e96f26f commit db34ca8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 22 deletions.
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

0 comments on commit db34ca8

Please sign in to comment.