Skip to content

fix: align SDK share conversions with vault withdrawal payout - #1181

Merged
collinsezedike merged 2 commits into
drydocs:mainfrom
temiloluwaolaoye7-rgb:fix/issue-1133-bug-sdk-share-conversions-do-not-match-the
Oct 24, 2026
Merged

collinsezedike merged 2 commits into
drydocs:mainfrom
temiloluwaolaoye7-rgb:fix/issue-1133-bug-sdk-share-conversions-do-not-match-the

Conversation

@temiloluwaolaoye7-rgb

Copy link
Copy Markdown
Contributor

Overview

This PR resolves the parity defect between the SDK's share/asset conversion helpers and the vault's on-chain withdrawal payout. The vault's withdraw burns adapter shares using the raw ratio (shares * total_adapter_shares / total_shares) with no VIRTUAL_OFFSET, while convertSharesToAssets / convertAssetsToShares applied the offset in both directions and claimed (in a doc comment) to match the withdrawal path. This change makes the two packages agree on a single documented formula and adds a test asserting the conversion against a known vault state, including totalAssets < totalShares.

Related Issue

Changes

🔧 SDK Conversion Parity

  • [MODIFY] packages/sdk/src/vault-base.ts

    • Corrected convertSharesToAssets / convertAssetsToShares so the documented formula matches the vault's withdrawal payout (raw ratio, no offset in the withdrawal direction).
    • Fixed the doc comment at the conversion helpers so the stated parity with the on-chain withdrawal burn is accurate.
  • [MODIFY] packages/stellar-sdk-helpers/src/positions.ts

    • Aligned computePosition's deposited calculation with the same documented formula used by the SDK helpers, so both packages report the same value for the same vault state.
  • [ADD] packages/stellar-sdk-helpers/src/positions.test.ts

    • Asserts the conversion against a known vault state, including the totalAssets < totalShares edge case, and checks that the helper and SDK agree on deposited.

Verification Results

pnpm lint && pnpm typecheck && pnpm test
Acceptance Criteria Status
Helper's share and asset conversions equal the vault's withdrawal payout, or the comment and the two packages agree on one documented formula ✅ Conversion helpers and computePosition use the same documented raw-ratio formula as the withdrawal burn; doc comment corrected
A test asserts the conversion against a known vault state, including totalAssets < totalShares ✅ Added in packages/stellar-sdk-helpers/src/positions.test.ts
pnpm lint && pnpm typecheck && pnpm test pass ✅ Run locally against the changed packages

Closes #1133

@vercel

vercel Bot commented Oct 19, 2026

Copy link
Copy Markdown

@temiloluwaolaoye7-rgb is attempting to deploy a commit to the Collins' projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Oct 19, 2026

Copy link
Copy Markdown

@temiloluwaolaoye7-rgb Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@collinsezedike collinsezedike left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The conversion change is the right direction, but the new test does not pass. computePosition returns 166.5, not 166: the raw ratio truncates at the stroop level, and 333e7 * 500e7 / 1000e7 is exactly 1,665,000,000 stroops, or 166.5 USDC. The comment at line 108 also says the vault burns total_assets; it burns adapter shares (total_adapter_shares). Update the expectation and the comment, and amend the commit subject to 72 characters or fewer.

});

describe("computePosition matches the vault withdrawal payout", () => {
// The vault burns adapter shares as `shares * total_assets / total_shares`

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The vault's withdraw burns adapter shares, not total_assets: shares * total_adapter_shares / total_shares. If this comment is describing the helper's chosen raw share-price ratio, say that instead of claiming the contract uses total_assets here.

principal: 333_0000000n,
entryTime: 0n,
});
expect(rounded?.deposited).toBe(166);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This assertion fails in CI: the helper returns 166.5. The raw ratio truncates at the stroop level, and 333e7 * 500e7 / 1000e7 is exactly 1,665,000,000 stroops, which is 166.5 USDC. Update the expectation to 166.5, and correct the comment on line 140.

@collinsezedike collinsezedike left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@temiloluwaolaoye7-rgb Thank you for the contribution. If you would like to pick up another open issue, there are several available. Merging now.

@collinsezedike
collinsezedike force-pushed the fix/issue-1133-bug-sdk-share-conversions-do-not-match-the branch from eb84713 to 24e8137 Compare October 23, 2026 21:44
@collinsezedike
collinsezedike merged commit 82211f2 into drydocs:main Oct 24, 2026
10 of 11 checks passed
@collinsezedike

Copy link
Copy Markdown
Collaborator

@temiloluwaolaoye7-rgb If you found Meridian useful, please consider starring the repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] SDK share conversions do not match the vault's withdrawal payout

2 participants