Skip to content

fix: convert builder_fee bps to chain units before sending to contract#16

Merged
WGB5445 merged 1 commit intomainfrom
fix/builder-fee-bps-precision
Apr 15, 2026
Merged

fix: convert builder_fee bps to chain units before sending to contract#16
WGB5445 merged 1 commit intomainfrom
fix/builder-fee-bps-precision

Conversation

@WGB5445
Copy link
Copy Markdown
Collaborator

@WGB5445 WGB5445 commented Apr 15, 2026

Summary

Convert builder fee basis points (bps) to chain units before sending to the contract, aligning with TypeScript SDK implementation.

  • Add bps_to_chain_units() utility function to convert basis points to chain units (multiply by 100)
  • Applies to place_order(), place_twap_order(), and approve_max_builder_fee() methods
  • Synced both async and sync versions
  • Matches contract's FEE_PRECISION = 10000 (1% = 10000)

Changes

  • Added bps_to_chain_units(bps) in _utils.py that converts bps to chain units
  • Updated method signatures to accept int | float for builder_fee parameters
  • Convert bps values before passing to contract entry functions
  • Updated type definitions in _types.py

Example

# User passes bps value (10 = 0.1%)
await exchange.place_order(
    market_name="BTC-PERP",
    price=50000.0,
    size=0.1,
    is_buy=True,
    time_in_force=TimeInForce.GoodTillCanceled,
    is_reduce_only=False,
    builder_addr="0x...",
    builder_fee=10,  # 0.1% - SDK converts to 1000 chain units
)

# Set max builder fee
await exchange.approve_max_builder_fee(
    builder_addr="0x...",
    max_fee=100,  # 1% - SDK converts to 10000 chain units
)

Copilot AI review requested due to automatic review settings April 15, 2026 16:39
@WGB5445 WGB5445 force-pushed the fix/builder-fee-bps-precision branch from 50401c1 to 8972a58 Compare April 15, 2026 16:41
@WGB5445 WGB5445 requested a review from gregnazario April 15, 2026 16:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the Python SDK to convert builder fee inputs from basis points (bps) into on-chain fee units before submitting transactions, and removes the legacy “netna” network/ABI configuration in favor of testnet/mainnet defaults.

Changes:

  • Added bps_to_chain_units() and applied conversion in place_order(), place_twap_order(), and approve_max_builder_fee() (async + sync).
  • Removed NETNA config/ABI handling and updated ABI registry/generator behavior and associated tests.
  • Updated docs and examples to use TESTNET_CONFIG and added a market-maker bot example.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/abi/test_registry.py Updates ABI registry tests for new default/fallback behavior and removes netna-specific assertions.
src/decibel/write/_types.py Updates typed args to allow max_fee as `int
src/decibel/write/init.py Converts builder fee bps inputs to contract fee units before calling entry functions (async + sync).
src/decibel/abi/json/netna.json Removes the netna ABI JSON artifact.
src/decibel/abi/generate.py Drops netna-specific filename selection logic for ABI generation.
src/decibel/abi/_registry.py Removes netna chain id support; defaults/unknown-chain fallback now use testnet ABIs.
src/decibel/_utils.py Adds bps_to_chain_units() utility and exports it via __all__.
src/decibel/_fee_pay.py Removes netna-specific gas station URL fallback.
src/decibel/_constants.py Removes NETNA_CONFIG and the netna entry from NAMED_CONFIGS.
src/decibel/init.py Removes NETNA_CONFIG from the public package exports.
examples/write/withdraw_from_vault.py Switches example config from NETNA to TESTNET.
examples/write/withdraw.py Switches example config from NETNA to TESTNET.
examples/write/update_tp_sl_order.py Switches example config from NETNA to TESTNET and updates derived addresses accordingly.
examples/write/trigger_matching.py Switches example config from NETNA to TESTNET and updates derived addresses accordingly.
examples/write/revoke_delegation.py Switches example config from NETNA to TESTNET.
examples/write/revoke_builder_fee.py Switches example config from NETNA to TESTNET.
examples/write/place_twap_order.py Switches example config from NETNA to TESTNET.
examples/write/place_tp_sl_for_position.py Switches example config from NETNA to TESTNET and updates derived addresses accordingly.
examples/write/place_stop_order.py Switches example config from NETNA to TESTNET.
examples/write/place_order_with_tp_sl.py Switches example config from NETNA to TESTNET.
examples/write/place_market_order.py Switches example config from NETNA to TESTNET.
examples/write/place_limit_order.py Switches example config from NETNA to TESTNET.
examples/write/place_bulk_orders.py Switches example config from NETNA to TESTNET.
examples/write/market_maker_bot.py Adds a new end-to-end example bot demonstrating quoting/canceling using the SDK.
examples/write/deposit_to_vault.py Switches example config from NETNA to TESTNET and updates derived addresses accordingly.
examples/write/deposit.py Switches example config from NETNA to TESTNET.
examples/write/delegate_vault_actions.py Switches example config from NETNA to TESTNET.
examples/write/delegate_trading.py Switches example config from NETNA to TESTNET and updates derived addresses accordingly.
examples/write/deactivate_subaccount.py Switches example config from NETNA to TESTNET.
examples/write/create_vault.py Switches example config from NETNA to TESTNET.
examples/write/create_subaccount.py Switches example config from NETNA to TESTNET.
examples/write/configure_market_settings.py Switches example config from NETNA to TESTNET and updates derived addresses accordingly.
examples/write/cancel_twap_order.py Switches example config from NETNA to TESTNET and updates derived addresses accordingly.
examples/write/cancel_tp_sl_order.py Switches example config from NETNA to TESTNET and updates derived addresses accordingly.
examples/write/cancel_order_by_client_id.py Switches example config from NETNA to TESTNET.
examples/write/cancel_order.py Switches example config from NETNA to TESTNET.
examples/write/cancel_bulk_order.py Switches example config from NETNA to TESTNET.
examples/write/approve_builder_fee.py Switches example config from NETNA to TESTNET.
examples/write/activate_vault.py Switches example config from NETNA to TESTNET.
examples/read/ws/subscribe_user_trade_history.py Switches example config from NETNA to TESTNET.
examples/read/ws/subscribe_user_positions.py Switches example config from NETNA to TESTNET.
examples/read/ws/subscribe_user_order_history.py Switches example config from NETNA to TESTNET.
examples/read/ws/subscribe_user_open_orders.py Switches example config from NETNA to TESTNET.
examples/read/ws/subscribe_user_notifications.py Switches example config from NETNA to TESTNET.
examples/read/ws/subscribe_user_bulk_orders.py Switches example config from NETNA to TESTNET.
examples/read/ws/subscribe_user_active_twaps.py Switches example config from NETNA to TESTNET.
examples/read/ws/subscribe_market_trades.py Switches example config from NETNA to TESTNET.
examples/read/ws/subscribe_market_price.py Switches example config from NETNA to TESTNET.
examples/read/ws/subscribe_market_depth.py Switches example config from NETNA to TESTNET.
examples/read/ws/subscribe_candlesticks.py Switches example config from NETNA to TESTNET.
examples/read/ws/subscribe_all_market_prices.py Switches example config from NETNA to TESTNET.
examples/read/ws/subscribe_account_overview.py Switches example config from NETNA to TESTNET.
examples/read/list_market_addresses.py Switches example config from NETNA to TESTNET.
examples/read/get_user_twap_history.py Switches example config from NETNA to TESTNET.
examples/read/get_user_trade_history.py Switches example config from NETNA to TESTNET.
examples/read/get_user_subaccounts.py Switches example config from NETNA to TESTNET.
examples/read/get_user_positions.py Switches example config from NETNA to TESTNET.
examples/read/get_user_order_history.py Switches example config from NETNA to TESTNET.
examples/read/get_user_open_orders.py Switches example config from NETNA to TESTNET.
examples/read/get_user_funding_history.py Switches example config from NETNA to TESTNET.
examples/read/get_user_fund_history.py Switches example config from NETNA to TESTNET.
examples/read/get_user_bulk_orders.py Switches example config from NETNA to TESTNET.
examples/read/get_user_active_twaps.py Switches example config from NETNA to TESTNET.
examples/read/get_trading_points.py Switches example config from NETNA to TESTNET.
examples/read/get_portfolio_chart.py Switches example config from NETNA to TESTNET.
examples/read/get_market_trades.py Switches example config from NETNA to TESTNET.
examples/read/get_market_price.py Switches example config from NETNA to TESTNET.
examples/read/get_market_depth.py Switches example config from NETNA to TESTNET.
examples/read/get_market_contexts.py Switches example config from NETNA to TESTNET.
examples/read/get_leaderboard.py Switches example config from NETNA to TESTNET.
examples/read/get_delegations.py Switches example config from NETNA to TESTNET.
examples/read/get_candlesticks.py Switches example config from NETNA to TESTNET.
examples/read/get_all_markets.py Switches example config from NETNA to TESTNET.
examples/read/get_all_market_prices.py Switches example config from NETNA to TESTNET.
examples/read/get_account_overview.py Switches example config from NETNA to TESTNET.
README.md Updates documentation examples and “Network Configs” section to remove NETNA and reference TESTNET.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/decibel/_utils.py
Comment thread src/decibel/write/__init__.py Outdated
Comment thread src/decibel/write/__init__.py Outdated
- Add bps_to_chain_units() utility function to convert basis points to chain units
  (multiply by 100, aligning with FEE_PRECISION = 10000 in contract)
- Update place_order() and place_twap_order() to convert builder_fee/builder_fees
- Update approve_max_builder_fee() to accept int|float and convert to chain units
- Sync both async and sync versions of these methods
- Update ApproveBuilderFeeArgs type definition to accept int|float

This matches the TypeScript SDK implementation and fixes precision issues.
@WGB5445 WGB5445 force-pushed the fix/builder-fee-bps-precision branch from 8972a58 to e8f8f4c Compare April 15, 2026 16:47
@WGB5445 WGB5445 merged commit 3d4d264 into main Apr 15, 2026
3 checks passed
@WGB5445 WGB5445 deleted the fix/builder-fee-bps-precision branch April 15, 2026 16:49
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.

4 participants