feat(contracts): add timelock controller, NFT certificate validation,…#693
Open
teefeh-07 wants to merge 1 commit into
Open
feat(contracts): add timelock controller, NFT certificate validation,…#693teefeh-07 wants to merge 1 commit into
teefeh-07 wants to merge 1 commit into
Conversation
… and storage optimization - platform-governance: implement timelock controller with queue/execute/cancel and 48h minimum delay enforcement (Farm-credit#657) - nft-certificate: create SEP-41 NFT contract with on-chain metadata validation for treeCount, co2OffsetKg, and plantingDate (Farm-credit#654) - tree-token: optimize storage keys via typed DataKey enum and Config struct, reducing instance entries and downsizing indices to u32 (Farm-credit#656) - harvesta-errors: add NFT certificate error codes - contracts/Cargo.toml: add nft-certificate workspace member Closes Farm-credit#657, closes Farm-credit#654, closes Farm-credit#656
|
@teefeh-07 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! 🚀 |
Contributor
|
Fix merge conflict and dont forget to Offramp your USDC on https://fundable.finance when you receive your rewards |
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
This PR resolves three contract-side issues:
Closes #657 — Add a timelock controller to platform-governance
Closes #654 — On-chain validation of certificate metadata in nft-certificate
Closes #656 — Optimize balance/storage keys in tree-token
#657 — platform-governance timelock controller
Tasks & fixes:
Added Queued and Canceled variants to ProposalStatus.
Added a QueuedProposal record (proposal id, queued_at, executable_at, canceled flag) and persistent storage key.
Added queue(proposal_id) to move a Passed proposal into the timelock queue; executable_at is computed as now + timelock_seconds.
Added cancel_queued_proposal(proposal_id) — admin-only emergency cancel.
Modified execute(proposal_id) to require Queued status and enforce the queued executable_at.
Enforced a 48-hour minimum timelock in update_timelock.
Added set_paused(paused) admin function and is_paused() getter (the pause flag was previously read but never set).
Added get_queued_proposal() getter.
Updated and expanded unit tests to cover queue → execute, early-execute rejection, admin cancel, and minimum-timelock enforcement.
#654 — nft-certificate metadata validation
Tasks & fixes:
Created new workspace member contracts/nft-certificate with a SEP-41 style NFT contract.
Implemented initialize, mint, owner_of, token_uri, approve, get_approved, transfer, transfer_from, name, and symbol.
mint performs on-chain validation of certificate metadata:
tree_count > 0 → HarvestaError::TreeCountMustBePositive
co2_offset_kg > 0 → HarvestaError::Co2MustBePositive
planting_date <= env.ledger().timestamp() → HarvestaError::InvalidPlantingDate
Enforces unique token_id; duplicates panic with HarvestaError::TokenAlreadyMinted.
Added NFT-specific error codes to harvesta-errors.
Added unit tests for valid mint, duplicate-token rejection, zero tree count, zero CO₂ offset, and future planting date.
Note: because on-chain JSON parsing of a metadata URI is impractical on Soroban, the contract accepts the structured metadata fields directly as arguments alongside metadata_uri. This keeps validation enforceable on-chain.
#656 — tree-token storage optimization
Tasks & fixes:
Collapsed four instance-storage entries (ADMIN, TOKEN, PAUSED, BURNCOUNT) into a single Config struct keyed by DataKey::Config.
Replaced persistent keys (Symbol("BURN"), u64) with typed DataKey::BurnRecord(u32).
Downsized burn index / count from u64 to u32.
Profiling / footprint comparison:
Instance ledger entries: 4 → 1 (-75%)
Persistent key encoding: Symbol + u64 → enum discriminant + u32
Burn index size: 8 bytes → 4 bytes
WASM build remains healthy (~30 KB)
Note: tree-token does not hold token balances itself (balances live in the Stellar Asset Contract). The optimization therefore targets the wrapper state and the ESG audit-log keys that the issue maps to as on-chain storage.
Workspace changes
contracts/Cargo.toml: added nft-certificate as a workspace member.
contracts/Cargo.lock: regenerated to include the new member.
Verification
✅ cargo check -p platform-governance -p nft-certificate -p tree-token
✅ cargo build --release --target wasm32-unknown-unknown -p platform-governance -p nft-certificate -p tree-token
Closes #657
Closes #654
Closes #656