Skip to content

Add TS-SDK feature parity: readers, write methods, and utilities#18

Open
gregnazario wants to merge 3 commits into
mainfrom
feature/ts-sdk-parity
Open

Add TS-SDK feature parity: readers, write methods, and utilities#18
gregnazario wants to merge 3 commits into
mainfrom
feature/ts-sdk-parity

Conversation

@gregnazario

Copy link
Copy Markdown
Collaborator

Context

Brings the Python SDK to feature parity with the reference TypeScript SDK (@decibeltrade/sdk), which had moved ahead. Gaps were confirmed by diffing the reference API surface (write.ts, read/index.ts, read/*/*.reader.ts, index.ts) against src/decibel/.

Changes

Phase 1a — Write-client parity (DecibelWriteDex + DecibelWriteDexSync)

  • update_order (update_order_to_subaccount) + UpdateOrderArgs
  • withdraw_non_collateral (withdraw_from_non_collateral)
  • admin_create_subaccount (admin_create_new_subaccount)
  • claim_campaign_reward (campaign_manager::claim_by_id) — adds a campaign_package field to Deployment + get_campaign_package() helper, populated for mainnet/testnet

Phase 1b — Read-client on-chain view helpers (DecibelReadDex)

global_perp_engine_state, collateral_balance_decimals, usdc_decimals (cached), usdc_balance, token_balance, account_balance, position_size, get_crossed_position

Phase 2 — 9 new read namespaces

campaigns, points_leaderboard, streaks, trading_amps, tier, global_points_stats, referrals, user_fees, withdraw_queue. Each has pydantic models, registration on DecibelReadDex, tests, and an example. withdraw_queue also ports the WS subscribe_by_addr, the on-chain get_pending_withdrawals fallback, and the merge_withdraw_queue_entries / is_known_cancel_reason helpers.

Phase 3 — Utility modules

  • calculate_liquidation_price — concentrated margin buffer strategy (all 10 golden values from the reference test suite match)
  • to_checksum_address — EIP-55 with a zero-dependency Keccak-256 (verified against spec vectors)
  • derive_aptos_from_eth / derive_aptos_from_solana — derivable-account derivation (scheme byte 0x05)

Out of scope (deferred)

The 4 testnet-only USDC mint view helpers and the ~7 expanded admin methods (chainlink-blended oracle, allowlist/mode-guardian, open-interest getters/setters).

Testing

  • ruff check, ruff format --check, pyright (0 errors) all pass
  • pytest -k "not testnet": 1087 passed
  • Coverage: 96% total, all new modules ≥98%

Note: the derivable-account derivation follows the Aptos DAA spec (BCS FunctionInfo + SHA3-256 + scheme 0x05) and satisfies every invariant in the reference test, but its exact output wasn't byte-compared against the running TS SDK — worth a one-time cross-check against a known ETH→Aptos pair.

Closes gaps relative to @decibeltrade/sdk (TypeScript reference).

Write client (DecibelWriteDex + Sync):
- update_order, withdraw_non_collateral, admin_create_subaccount,
  claim_campaign_reward (+ campaign_package added to Deployment/configs)

Read client (DecibelReadDex):
- On-chain view helpers: global_perp_engine_state, collateral_balance_decimals,
  usdc_decimals, usdc_balance, token_balance, account_balance, position_size,
  get_crossed_position
- 9 new read namespaces: campaigns, points_leaderboard, streaks, trading_amps,
  tier, global_points_stats, referrals, user_fees, withdraw_queue
  (withdraw_queue includes WS subscribe, on-chain pending view, and merge helpers)

Utilities:
- calculate_liquidation_price (concentrated margin buffer strategy)
- EIP-55 checksums (zero-dep keccak-256) + derivable-account address derivation

Includes tests (96% total coverage) and examples for each new reader.
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
4363 4204 96% 0% 🟢

New Files

File Coverage Status
src/decibel/_calculations.py 98% 🟢
src/decibel/_derivable_account.py 100% 🟢
src/decibel/_eip55.py 100% 🟢
src/decibel/read/_campaigns.py 100% 🟢
src/decibel/read/_global_points_stats.py 100% 🟢
src/decibel/read/_points_leaderboard.py 100% 🟢
src/decibel/read/_referrals.py 99% 🟢
src/decibel/read/_streaks.py 100% 🟢
src/decibel/read/_tier.py 100% 🟢
src/decibel/read/_trading_amps.py 100% 🟢
src/decibel/read/_user_fees.py 100% 🟢
src/decibel/read/_withdraw_queue.py 99% 🟢
TOTAL 100% 🟢

Modified Files

File Coverage Status
src/decibel/_init_.py 100% 🟢
src/decibel/_constants.py 100% 🟢
src/decibel/read/_init_.py 100% 🟢
src/decibel/write/_init_.py 93% 🟢
src/decibel/write/_types.py 100% 🟢
TOTAL 99% 🟢

updated for commit: d1d5ba3 by action🐍

…ties

Update the README API reference with the new read namespaces, on-chain view
helpers, write methods, and a Utilities section (liquidation price, EIP-55,
derivable accounts). Add a CHANGELOG Unreleased entry.
…e methods

Document every new reader class/method (porting the reference JSDoc where it
existed), the read-client on-chain view helpers, and the four new write methods
so generated API docs (Sphinx/pdoc) surface them.
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