Skip to content

fix: align SDK with perpcity-contracts v0.0.1#2

Open
koko1123 wants to merge 2 commits intomainfrom
fix/align-contracts-v001
Open

fix: align SDK with perpcity-contracts v0.0.1#2
koko1123 wants to merge 2 commits intomainfrom
fix/align-contracts-v001

Conversation

@koko1123
Copy link
Contributor

@koko1123 koko1123 commented Mar 9, 2026

Summary

  • Update quoteClosePosition return type: netMargin changed from uint256 to int256, added notional (uint256) as 6th return value
  • Remove startingSqrtPriceX96 from createPerp params (now auto-derived from beacon index in contract)
  • Replace per-module registration with generic registerModule/isModuleRegistered
  • Add quoteSwap function, ModuleRegistered event
  • Update PositionClosed event fields and adjustNotional field names

Test plan

  • Lint passes (ruff check)
  • All 138 unit tests pass
  • Integration tests against v0.0.1 contracts

Summary by CodeRabbit

  • Refactor

    • Unified module registration interface and generalized module-related APIs
    • Removed the starting price parameter from perpetual creation flows
    • Extended PositionClosed events with additional financial metrics (notional, funding, fees, etc.)
    • Renamed AdjustNotionalParams fields for consistent naming
  • Chores

    • CI now skips integration tests when required secrets are absent (non-fatal)

@coderabbitai
Copy link

coderabbitai bot commented Mar 9, 2026

📝 Walkthrough

Walkthrough

Module registration and perp creation APIs were consolidated: multiple module-specific events/functions unified into a generic ModuleRegistered/registerModule model; starting_price was removed from perp creation; Position and Perp events/returns were extended; create_perp call sites and related types/ABI updated accordingly.

Changes

Cohort / File(s) Summary
ABI: Module & Events Consolidation
src/perpcity_sdk/abis/perp_manager.json
Replaced multiple module-specific events (FeesModuleRegistered, LockupPeriodModuleRegistered, MarginRatiosModuleRegistered, SqrtPriceImpactLimitModuleRegistered) with a unified ModuleRegistered(moduleType uint8, module address). Renamed/merged module registration functions and adjusted event/field names and signatures across the ABI (PositionClosed, PerpCreated, quoteSwap outputs, CreatePerpParams, AdjustNotionalParams).
Type changes: CreatePerpParams
src/perpcity_sdk/types.py
Removed starting_price: float from CreatePerpParams dataclass (struct shape changed to match ABI; related sqrt price fields removed).
Function changes: create_perp usage
src/perpcity_sdk/functions/perp_manager.py, examples/create_perp.py
Removed import/usage of price_to_sqrt_price_x96 and omitted passing starting sqrt price in create_perp call; example updated to no longer provide starting_price.
Context: position parsing
src/perpcity_sdk/context.py
_fetch_position_live_details updated to unpack an additional (unused) _notional element from quoteClosePosition result to match extended return tuple.
CI workflow: conditional integration tests
.github/workflows/ci.yml
Integration-tests job made secrets-aware: checks for BASE_SEPOLIA_RPC_URL and skips integration steps when missing (emits warning instead of failing), conditional installs and test runs based on secret presence.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Poem

🐰 I hopped through ABIs, fields, and types,

Modules united, trimmed old gripes.
No starting price to set or bind,
Events grew fuller, details aligned.
A tiny rabbit cheers this tidy find! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: align SDK with perpcity-contracts v0.0.1' clearly and directly describes the main objective of the changeset, which is to align the SDK with the perpcity-contracts v0.0.1 release.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/align-contracts-v001

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/perpcity_sdk/context.py (1)

160-177: Consider exposing notional in LiveDetails for future completeness.

The _notional value is now captured from quoteClosePosition but discarded. Since the contract now returns this as a sixth value, consider adding it to the LiveDetails dataclass if SDK consumers may need it for displaying position sizing or calculations. This remains optional if notional is not currently required by users.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/perpcity_sdk/context.py` around lines 160 - 177, The code discards the
sixth return value (_notional) from quoteClosePosition in
_fetch_position_live_details/_fetch; add a notional field to the LiveDetails
dataclass and populate it from _notional (convert to the same units as
pnl/funding/net_margin, e.g., int(_notional)/1e6) so SDK consumers can access
position notional; update any constructors/usages of LiveDetails to accept the
new notional attribute and include it in returned instances.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/perpcity_sdk/context.py`:
- Around line 160-177: The code discards the sixth return value (_notional) from
quoteClosePosition in _fetch_position_live_details/_fetch; add a notional field
to the LiveDetails dataclass and populate it from _notional (convert to the same
units as pnl/funding/net_margin, e.g., int(_notional)/1e6) so SDK consumers can
access position notional; update any constructors/usages of LiveDetails to
accept the new notional attribute and include it in returned instances.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8624a8ea-3420-4b9a-9ecb-40e2c6d56eb1

📥 Commits

Reviewing files that changed from the base of the PR and between 9d741ec and 883cdfa.

📒 Files selected for processing (9)
  • .github/ISSUE_TEMPLATE/bug_report.md
  • .github/ISSUE_TEMPLATE/feature_request.md
  • CHANGELOG.md
  • CONTRIBUTING.md
  • examples/create_perp.py
  • src/perpcity_sdk/abis/perp_manager.json
  • src/perpcity_sdk/context.py
  • src/perpcity_sdk/functions/perp_manager.py
  • src/perpcity_sdk/types.py
💤 Files with no reviewable changes (2)
  • src/perpcity_sdk/types.py
  • examples/create_perp.py

- Update quoteClosePosition: netMargin uint256->int256, add notional return value
- Remove startingSqrtPriceX96 from createPerp (now auto-derived from beacon)
- Replace per-module registration with generic registerModule/isModuleRegistered
- Add quoteSwap function
- Update PositionClosed event with new fields
- Update adjustNotional field names (perpDelta->usdDelta, usdLimit->perpLimit)
@koko1123 koko1123 force-pushed the fix/align-contracts-v001 branch from 883cdfa to 31f461e Compare March 9, 2026 22:51
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/perpcity_sdk/abis/perp_manager.json (1)

1604-1652: New quoteSwap function added - consider exposing in SDK.

The new quoteSwap function provides quote functionality for swap operations. If this is part of the public contract API intended for SDK users, consider adding a Python wrapper function (similar to the pattern used for other quote functions).


ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 324e5c6e-ae9a-4a37-bd03-3324d1caf05d

📥 Commits

Reviewing files that changed from the base of the PR and between 883cdfa and 31f461e.

📒 Files selected for processing (5)
  • examples/create_perp.py
  • src/perpcity_sdk/abis/perp_manager.json
  • src/perpcity_sdk/context.py
  • src/perpcity_sdk/functions/perp_manager.py
  • src/perpcity_sdk/types.py
💤 Files with no reviewable changes (2)
  • src/perpcity_sdk/types.py
  • examples/create_perp.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/perpcity_sdk/context.py

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
.github/workflows/ci.yml (1)

71-82: Consider checking both required secrets for robustness.

The check only validates BASE_SEPOLIA_RPC_URL, but line 102 also requires TEST_PRIVATE_KEY. If only one secret is configured, the job will proceed and likely fail during test execution.

♻️ Suggested improvement to check both secrets
      - name: Check if secrets are available
        id: secrets-check
        env:
          RPC_SECRET: ${{ secrets.BASE_SEPOLIA_RPC_URL }}
+         KEY_SECRET: ${{ secrets.TEST_PRIVATE_KEY }}
        run: |
-         if [ -z "$RPC_SECRET" ]; then
+         if [ -z "$RPC_SECRET" ] || [ -z "$KEY_SECRET" ]; then
            echo "::warning::Integration test secrets not configured - skipping"
            echo "has_secrets=false" >> "$GITHUB_OUTPUT"
          else
            echo "Integration test configuration found - running tests"
            echo "has_secrets=true" >> "$GITHUB_OUTPUT"
          fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/ci.yml around lines 71 - 82, The current CI step only
checks BASE_SEPOLIA_RPC_URL, so modify the "secrets-check" job to validate both
required secrets: BASE_SEPOLIA_RPC_URL and TEST_PRIVATE_KEY (check both
$RPC_SECRET and $PRIVATE_KEY or similar env names used in the workflow). Update
the env block to expose both secrets, change the run script to test that neither
variable is empty (e.g., if either is missing set has_secrets=false and emit a
warning; only set has_secrets=true when both are present), and keep the existing
informative echo messages so downstream steps only run when both secrets exist.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.github/workflows/ci.yml:
- Around line 71-82: The current CI step only checks BASE_SEPOLIA_RPC_URL, so
modify the "secrets-check" job to validate both required secrets:
BASE_SEPOLIA_RPC_URL and TEST_PRIVATE_KEY (check both $RPC_SECRET and
$PRIVATE_KEY or similar env names used in the workflow). Update the env block to
expose both secrets, change the run script to test that neither variable is
empty (e.g., if either is missing set has_secrets=false and emit a warning; only
set has_secrets=true when both are present), and keep the existing informative
echo messages so downstream steps only run when both secrets exist.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c24a1c20-95fd-4302-8926-ef569205a909

📥 Commits

Reviewing files that changed from the base of the PR and between 31f461e and 0aa4426.

📒 Files selected for processing (1)
  • .github/workflows/ci.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant