fix(globe-wallet): disambiguate spend limits by full AssetInfo and enforce UserAssets registration (#82) - #108
Draft
s6pa1rta3n-lab wants to merge 1 commit into
Draft
Conversation
…lidate against UserAssets (Orbit-Wal#82)
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.
Summary
Resolves #82. Disambiguates spend limits and daily spent tracking in
globe-walletby scoping storage keys (DataKey::SpendLimitandDataKey::DailySpent) by full asset identity (AssetInfocontaining both code and issuer) rather than plainStringasset code. Also enforces thatset_spend_limitandrecord_spendrequire the target asset to already be registered in the caller'sUserAssetslist (returningWalletError::AssetNotFoundif missing).Key Changes
DataKey::SpendLimit(Address, AssetInfo)andDataKey::DailySpent(Address, AssetInfo).assets_matchandfind_user_assetto ensure case-insensitive code comparison with strict issuer matching.set_spend_limit(env, user, asset, limit): Authenticates user, verifies asset exists in caller'sUserAssets, validates against existing daily spend, updatesDataKey::SpendLimit(user, asset), and removes any legacy key.get_spend_limit(env, user, asset) -> i128: Resolves canonical asset info, readsDataKey::SpendLimit, and falls back to legacy(Symbol("SpendLimit"), user, code)if present.record_spend(env, user, asset, amount): Validates positive amount, verifies asset exists inUserAssets, checks daily limit, records spent underDataKey::DailySpent(user, asset), extends TTL, and removes legacy keys.send(env, user, token_id, asset, to, amount): Updated to acceptAssetInfo.migrate_spend_limits(env, user) -> Result<u32, WalletError>to batch-migrate all legacy(Symbol, Address, String)keys for registered assets of a user to newAssetInfokeys.test_same_code_different_issuer_independent_spend_limitsinglobe-walletto prove two same-code, different-issuer assets maintain independent daily budgets.test_spend_limit_and_record_spend_reject_unregistered_asset.test_case_variant_asset_shares_same_spend_limit_bucket.test_migrate_spend_limits_and_legacy_fallback.AssetInfo.Verification:
cargo test --workspacePayout Routing
0xF46C9F6d70C50BF81ef3588AB523a90a594a2F89GCL6OXAMLD75BMTINA6EMRUDWK5THQUSHMYNLSNBCJAPZJHNYJTUNIBC