Skip to content

feat: delegate withdrawal — position owner specifies a separate recipient address #274

Description

@abayomicornelius

Summary

Currently, collateral and PnL from a closed position are always sent to the original position owner (env.invoker()). Add a recipient: Option<Address> field to decrease and withdrawal orders so traders can direct funds to a different wallet (e.g., a cold storage address or a multi-sig vault).

Proposed Design

  • Add recipient: Option<Address> to CreateOrderParams and CreateWithdrawalParams
  • If Some(addr), final token transfer goes to addr instead of env.invoker()
  • If None, behaviour unchanged
  • recipient address is not auth-checked — position owner has full discretion

Security Note

The recipient cannot use this to steal funds from a different owner. The position auth check still applies to the invoker, not the recipient.

Acceptance Criteria

  • CreateOrderParams and CreateWithdrawalParams include recipient: Option<Address>
  • Token transfer uses recipient when set
  • Integration test: close position with recipient = cold_wallet, assert cold_wallet receives PnL
  • Integration test: None recipient sends to invoker (no regression)

Affected Contracts

exchange_router, order_handler, withdrawal_handler

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions