defi collateral issue - #5
Merged
Merged
Conversation
Implements core oracle with spot rate calculation using (total-stx * 1_000_000) / total-bstx-supply at 6 decimal precision. Includes circular observation buffer (10 slots), halted state flag, and authorized-updater mechanism.
Implements cumulative price accumulator pattern (Uniswap V2-style). TWAP = delta(cumulative_price) / delta(block_height) over any window. Supports up to 20 checkpoints in circular buffer for flexible window queries.
Implements deviation check (per-update), velocity check (rolling window), and manual admin trip/reset. Configurable thresholds (default 5% deviation, 10% velocity over 100 blocks). Emits structured print events on every trip.
… listing Records bSTX listing proposal on-chain: 75% LTV, 80% liquidation threshold, 5% liquidation bonus. Full lifecycle (DRAFT→SUBMITTED→ACTIVE→PASSED/REJECTED), signalling vote tally, and duplicate-vote prevention. Seeds default proposal at deploy.
…flow Implements add/remove liquidity, STX→bSTX swap with 0.05% fee tier, and price-range enforcement (0.95–1.05 tick bounds). Records provider positions, accrued fees, and pool reserves. Seeded with Bitflow-compatible pool structure.
…n Clarinet.toml Adds deployment entries for: - bitstake-bstx-oracle - bitstake-bstx-oracle-twap - bitstake-oracle-circuit-breaker - bitstake-alex-governance - bitstake-bitflow-pool
Covers: correct 1:1 rate, premium calculation, zero-supply error, observation recording, frequency guard, non-owner rejection, authorized-updater delegation, TWAP after multiple observations, circuit breaker read-only state, and get-rates snapshot.
…esholds Tests: initial state, price within/outside deviation threshold, breaker open/close state, manual trip, invalid threshold params, non-owner rejections, and last-price read-only.
Covers: default proposal seeding, LTV params, proposal creation, non-owner rejection, invalid LTV params, full status lifecycle, voting (for/against/duplicate), and invalid transition guard.
Covers: initial stats, liquidity add/remove, reserve accounting, position recording, slippage guard, pool-paused rejection, non-owner removal, STX→bSTX swap, quote helper, tick-range price update guard.
…only functions Exposes per-pool and cross-pool total stacked STX so the bSTX oracle can compute the exchange rate purely from on-chain data without off-chain inputs.
…e feed Covers: initial zero state, push-price success, non-owner rejection, zero-supply rejection, cumulative price growth, TWAP window queries, checkpoint slot population, and write-index advancement.
…cked Verifies oracle data-feed helpers: fresh pool returns 0, unknown pool errors, aggregate of 0 before deposits, single-pool deposit reflection, and cross-pool sum correctness.
Covers oracle interface (spot + TWAP), circuit breaker integration pattern, ALEX governance proposal steps, Bitflow pool parameters and usage, deployment order, and security considerations (TWAP manipulation, depeg risk, liquidation cascade, oracle freshness).
Includes: summary, motivation, proposed LTV/liquidation parameters, oracle design rationale, risk analysis (depeg, liquidation cascade, oracle freshness, smart contract risk), and implementation checklist.
Documents Phase 1 DeFi integrations (ALEX, Bitflow, Velar), oracle usage, Bitflow pool interaction, and links to the full integration guide. Updates roadmap to mark oracle and DeFi contracts as complete.
Renames workflow to 'Contract Tests', adds oracle-tests job that runs after clarinet-test, covering all 5 new test files: oracle spot/TWAP, circuit breaker, ALEX governance, and Bitflow pool.
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.
closes #2