fix(deepbook-v3): repay_base/repay_quote no longer drain balance on amount=0#1032
Open
Danny-Devs wants to merge 1 commit intoMystenLabs:mainfrom
Open
fix(deepbook-v3): repay_base/repay_quote no longer drain balance on amount=0#1032Danny-Devs wants to merge 1 commit intoMystenLabs:mainfrom
Danny-Devs wants to merge 1 commit intoMystenLabs:mainfrom
Conversation
…mount=0 The previous truthy guard (`amount ? … : null`) collapsed `0` onto the Option::None branch. In Move, None means 'repay as much as possible using the available balance of the asset in the balance manager', capped at the full outstanding debt — so `repayBase(mgr, 0)` / `repayQuote(mgr, 0)` silently triggered a full-debt repayment instead of a no-op. The guard now uses `amount !== undefined`, so `0` serializes as Option::Some(0) and only an omitted argument becomes None. Also switches the Option<u64> argument from `tx.object.option` to `tx.pure.option`, matching marginLiquidations.ts and marginPool.ts and avoiding an extra 0x1::option::some/none PTB command. Adds unit tests that inspect the emitted Option<u64> input bytes for all three cases (Some(0), Some(n), None) on both repay methods.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
MarginManagerContract.repayBaseandrepayQuoteused a truthy guard (amount ? … : null) that collapsedamount = 0onto theOption::Nonebranch of theOption<u64>argument.On the Move side,
margin_manager::repayusesamount.destroy_with_default(available_balance)and clamps to the outstanding debt.Nonemeans "repay as much as possible using the asset balance held in the balance manager." SorepayBase(mgr, 0)andrepayQuote(mgr, 0)silently triggered a full-debt repayment instead of a no-op, which is the behavior the numeric argument suggests.The guard now checks
amount !== undefined, matching the pattern inmarginLiquidations.tsandmarginPool.ts:amount = 0→Option::Some(0)→ no-op repayamount = n→Option::Some(n_scaled)→ partial repayamountomitted →Option::None→ repay-all (unchanged)The
Option<u64>argument also switches fromtx.object.optiontotx.pure.option, again matching the sibling files and avoiding an extra0x1::option::some/nonePTB command per repay.Test plan
Added
test/unit/transactions/marginManager.test.tscovering all three cases on both methods. Each test inspects the emittedOption<u64>input bytes and decodes them withbcs.option(bcs.u64()):repayBase(mgr, 0)→Some("0")repayBase(mgr, 1.5)→Some("1500000000")(scaled by base scalar)repayBase(mgr)→NonerepayQuote.Ran
pnpm --filter @mysten/deepbook-v3 exec vitest run— 19/19 passing. Rantsc --noEmit,oxlint, andprettier --check— all clean.AI Assistance Notice