Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/vaultv1-deposit-forward-accrual.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@morpho-org/morpho-sdk": patch
---

Fix `MorphoVaultV1.deposit` deriving `maxSharePrice` from pre-accrue vault state. MetaMorpho's `deposit` calls `_accrueInterest()`, so the execution-time share price is `>=` the build-time one; without a forward-accrual buffer the slippage bound could be too tight and revert GeneralAdapter1's check with `SlippageExceeded`. VaultV1 deposit now forward-accrues interest by 2h before computing shares, mirroring `MorphoVaultV2.deposit` and blue repay.
15 changes: 14 additions & 1 deletion packages/morpho-sdk/src/entities/vaultV1/vaultV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,20 @@ export class MorphoVaultV1 implements VaultV1Actions {

const totalAssets = amount + (nativeAmount ?? 0n);

const shares = vaultData.toShares(totalAssets);
// Forward-accrue 2h so maxSharePrice bounds the execution-time price, like
// VaultV2 deposit and blue repay. MetaMorpho has no vault-level lastUpdate,
// so accrue to the latest of now and every allocated market's lastUpdate
// (accrueInterest throws below any market's lastUpdate).
const accrualTimestamp =
vaultData.allocations
.values()
.reduce(
(max, { position }) => MathLib.max(max, position.market.lastUpdate),
Time.timestamp(),
) + Time.s.from.h(2n);
const accruedVault = vaultData.accrueInterest(accrualTimestamp);

const shares = accruedVault.toShares(totalAssets);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Round deposited shares down for the price bound

For deposits where the exact share amount is fractional, AccrualVault.toShares defaults to rounding up (packages/blue-sdk/src/vault/Vault.ts:190), while an ERC-4626 deposit mints the rounded-down share amount and the existing MetaMorpho operation path uses vault.toShares(assets, "Down") (packages/bundler-sdk-viem/src/actions.ts:841). This makes maxSharePrice use a larger denominator than the shares GA1 will actually observe, so with slippageTolerance: 0n or small/fractional deposits the transaction can still revert with the slippage check despite the forward accrual; pass "Down" here and keep the zero-share guard on that rounded-down value.

Useful? React with 👍 / 👎.

Comment on lines +237 to +239

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add regression coverage for VaultV1 forward accrual

Root AGENTS.md §2.10 says behavior-affecting package source changes must land with tests, but this commit changes the VaultV1 deposit maxSharePrice calculation and adds only source plus a changeset. Without an entity or fork regression test asserting the bound is computed from a forward-accrued VaultV1 state, the specific slippage regression this patch fixes can be reintroduced without any test failing.

Useful? React with 👍 / 👎.

if (shares <= 0n) {
throw new NonPositiveSharesAmountError(this.vault);
}
Expand Down