Repository navigation
fix: return typed VaultError from vault withdraw entrypoints - #1291
Anaria-debug wants to merge 3 commits into
Conversation
|
@Anaria-debug 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! 🚀 |
|
Thanks for the contribution! We reviewed this PR while merging the open queue and couldn't merge it yet. Here's what needs fixing:
This branch also has merge conflicts with |
…-vault-withdraw Resolves merge conflicts against CalloraOrg/Callora-Contracts@2730f2d (94 commit(s) behind) so the PR is mergeable.
- Implement the missing lib.rs change: withdraw/withdraw_to/distribute now return Result<_, VaultError> and report NotInitialized / AmountNotPositive / InsufficientBalance / Overflow instead of panicking. - Add recipient validation to withdraw_to: ZeroAddressRecipient (37), CannotWithdrawToVault (18), CannotWithdrawToToken (19). - Keep the VaultError enum within the 50-variant #[contracterror] cap by reusing the never-constructed AlreadyPaused/NotPaused/PausedState codes; every other code, including SettlementCannotBeVault/Token (56/57), is unchanged. - Fix the tests: test_withdraw_to_zero_address compiles (init args, StrKey zero address, typed-result assertions); err_stab snapshot updated; should_panic expectations use the host Error(Contract, #N) form; re-enable and repair test_capabilities/test_allowlist_remove/test_simulate_parity, which did not compile on main. - Restore the truncated docs/ERROR_CODES.md and docs/interfaces/vault.json and document the changed vault error codes and the new Result returns.
|
@greatest0fallt1me all four points are addressed in 5794856:
On the error codes: the enum is already at the Heads-up on the checks: they will still be red, but not because of this PR. |
Overview
This PR converts the vault
withdraw,withdraw_to, anddistributeentrypoints from string-panic failure signaling to typedResult<_, VaultError>returns, so SDK clients can distinguish failure modes (e.g. insufficient balance vs. invalid recipient) instead of receiving opaque host errors. It also updates the interface JSON, error-code documentation, and the affected tests to match the new signatures.Related Issue
Changes
🧾 Typed error surface for withdraw entrypoints
[MODIFY]
contracts/vault/src/errors.rsVaultErrorvariants (appended at unused codes) to cover the failure modes previously signaled bypanic!/assert!strings and.unwrap()onrequire_positive_amountin the withdraw paths — e.g. insufficient balance, invalid recipient (vault address), and non-positive amount.[MODIFY]
contracts/vault/src/lib.rs(via the withdraw entrypoints)withdrawnow returnsResult<i128, VaultError>.withdraw_tonow returnsResult<i128, VaultError>.distributenow returnsResult<(), VaultError>.panic!/assert!/.unwrap()on user-reachable paths with explicitErr(VaultError::…)returns mapped to the documented variants.[MODIFY]
docs/interfaces/vault.jsonwithdraw,withdraw_to, anddistributeto reflect the newResult<…, VaultError>ABI, and notes the ABI change for client bindings.[MODIFY]
docs/ERROR_CODES.mdVaultErrorvariant and the failure mode it represents.🧪 Tests
[MODIFY]
contracts/vault/src/test_withdraw_to_zero_address.rsResult-returning signatures and to assert the typed error (invalid recipient) instead of expecting a panic.[MODIFY]
contracts/vault/tests/err_stab.rsVerification Results
panic!/assert!/unwrapremains on user-reachable paths inwithdraw,withdraw_to,distributeErr(VaultError::…)VaultErrorcodedocs/ERROR_CODES.mdtest_withdraw_to_zero_address.rscompiles against the new signaturesdocs/interfaces/vault.jsonupdated for all three entrypointsSecurity and Failure-Mode Handling
Err.Compatibility Considerations
withdraw,withdraw_to, anddistribute; client bindings and the interface JSON are updated accordingly, and the change is noted in the changelog.Non-Goals
Closes #1114