Repository navigation
refactor(contracts): use typed contracttype storage keys in flash loan and yield farming - #1986
Open
Mukhtar5527 wants to merge 1 commit into
Open
Mukhtar5527 wants to merge 1 commit into
Mukhtar5527 wants to merge 1 commit into
Conversation
…n and yield farming
- flash_loan_provider: replace the ("admin"), ("token") and ("fee_bps") string keys with a private #[contracttype] DataKey enum (Admin, Token, FeeBps).
- yield_farming: replace the ("admin"), ("staking_token"), ("reward_token"), ("reward_rate") and ("total_staked") string keys with a private #[contracttype] DataKey enum.
- Reason: string-keyed instance storage can collide across modules and across upgrade iterations (SC-073). Enum variants XDR-encode to distinct keys, so collisions are ruled out by the type system.
- No logic change: initialize, flash_loan, stake and get_reward_per_token keep the same checks, defaults (fee_bps 10, reward_rate 1) and return values. Public function signatures are unchanged.
- Consequence: the storage key layout changes. Instance entries written by previously deployed versions under the old string keys are not read by this code. flash_loan_provider initialize guards on DataKey::Admin, so an upgraded deployed instance reports as uninitialized and can be initialized again, which would overwrite its admin. Upgrading a live instance in place requires a migration, or redeployment with fresh state.
- Not changed: access_control (its lib.rs holds no storage keys; the plain symbol key remains in access_control/src/roles.rs PAUSED_KEY and is listed as remaining work).
|
@Mukhtar5527 is attempting to deploy a commit to the Ayomide Adeniran's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@Mukhtar5527 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! 🚀 |
This branch has not been deployed
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
Replaces plain string-tuple storage keys with private
#[contracttype]enums in two of the three contracts named in #1870:contracts/flash_loan_provider/src/lib.rs:("admin"),("token"),("fee_bps")becomeDataKey::Admin,DataKey::Token,DataKey::FeeBps.contracts/yield_farming/src/lib.rs:("admin"),("staking_token"),("reward_token"),("reward_rate"),("total_staked")becomeDataKey::Admin,DataKey::StakingToken,DataKey::RewardToken,DataKey::RewardRate,DataKey::TotalStaked.No logic, signature, or event changes. Each enum is private to its module.
What breaks if this is wrong
flash_loan_provider::initializeguards onDataKey::Admin. On an upgraded instance that guard reads nothing, soinitializecan run again and overwrite the admin, token, and fee.yield_farming::initializehas no guard at all, so this was already true there.total_stakedreads as 0 andreward_rateas the default 1, which misprices rewards until state is migrated.contracts/deployments.mdcontains no entries for these two contracts on a grep offlash,yield, andaccess.Scope
Done (2 of the 3 named files):
contracts/flash_loan_provider/src/lib.rscontracts/yield_farming/src/lib.rsNot changed, and why:
contracts/access_control/src/lib.rsholds no storage keys of its own. Its keys live incontracts/access_control/src/roles.rsandcontracts/access_control/src/timelock.rs.roles.rsalready uses aStorageKeyenum, butPAUSED_KEYis stillsymbol_short!("AC_PAUSED"). Fixing that is a one-line change inroles.rs, which is outside the three named files, so it is left for a follow-up. Note thatStorageKey::Pausedalready exists but is unused. Switching to it changes the stored paused flag key, so existing paused state would read as not paused after upgrade.Remaining work
Issue #1870 asks for 100% of workspace contracts. That is not done by this PR. The workspace has 41 crates under
contracts/. Files with storage calls that still use symbol constants,Symbol::new, or literal keys (found by a pattern scan, not a per-call audit):contracts/access_control/src/roles.rs(PAUSED_KEY)contracts/amm/src/circuit_breaker.rscontracts/commit_reveal_rng/src/lib.rscontracts/hello_world/src/freelance_platform.rscontracts/hello_world/src/reputation_system.rscontracts/lending_pool/src/flash_loan.rscontracts/lending_pool/src/lib.rscontracts/multisig_wallet_timelock/src/lib.rscontracts/payment_gateway/src/lib.rscontracts/payment_streaming/src/lib.rscontracts/quadratic_funding/src/lib.rscontracts/smart_vault/src/circuit_breaker.rscontracts/smart_vault/src/lib.rscontracts/smart_vault/src/reentrancy_guard.rscontracts/src/passkey_wallet.rsOther crates with storage calls (for example
contracts/freelance-platform,contracts/dao_governance,contracts/amm,contracts/proxy) were not individually checked and are also open. Full inventory needs a per-call review in each crate.Verification
Verified by reading only:
bd9921de, and the diff was checked line by line. Every storage call in the two files now uses aDataKeyvariant. No string keys remain.set,get, andhascall type-checks by inspection: keys are passed by reference, and value types match the original code.build.rs. Neither has a dependency on the other or onaccess_control. Manifests were not changed.NOT run:
cargo build,cargo test,cargo clippy, and the wasm build were not run. This PR has not been compiled.Closes #1870