Skip to content

Expose stablecoin openPosition transaction through stablecoin_module #344

Description

@3esmit

Goal

Expose the fee-aware open_position instruction rebuilt by #341 as an
openPosition transaction method in stablecoin_module.

Scope

  • Add a typed stablecoin_ffi planner for
    Instruction::OpenPosition { position_nonce, initial_collateral_amount }.

  • Add openPosition(request) to StablecoinModuleImpl, accepting:

    • ownerId
    • exact decimal-string positionNonce
    • exact decimal-string initialCollateralAmount
    • userCollateralHoldingId
  • Derive Position and Vault PDAs internally from the stablecoin program ID,
    owner, and nonce, reusing Expose stablecoin position resolution and decoding #325.

  • Derive/read ProtocolParameters, obtain its configured collateral definition,
    and supply canonical CLOCK_01 internally.

  • Preserve the seven IDL accounts in exact order:

    1. owner
    2. Position
    3. Vault
    4. user collateral holding
    5. collateral definition
    6. protocol parameters
    7. CLOCK_01
  • Preserve all IDL signer/writable/init metadata. Owner and user collateral
    holding are the two signers.

  • Verify both signer accounts are public and controlled by the active wallet
    before submission.

  • Preflight protocol initialization/frozen state, configured collateral
    definition, source-holding definition/program ownership, and absence of
    initialized Position/Vault state when the wallet/indexer surface permits it.

  • Submit through the shared transaction path introduced for Expose permissionless stablecoin poke transactions #328 and return the
    same stable {status,error,transactionId} result shape.

  • Reject fractional, negative, floating-point, malformed, and out-of-range
    nonce/amount inputs without submitting.

Acceptance criteria

  • Planner output decodes exactly to
    Instruction::OpenPosition { position_nonce, initial_collateral_amount }.
  • Fixed-vector tests pin Position/Vault derivation, seven-account order,
    signer/writable/init flags, program ID, and instruction encoding.
  • Tests prove both required signer accounts are authorized and use the correct
    wallet nonces.
  • Tests cover missing/malformed protocol parameters, frozen protocol, wrong
    configured collateral definition, wrong source-holding definition/program,
    existing Position/Vault state, missing signer control, transport failure,
    transaction rejection, and successful transaction ID mapping.
  • Full-range u64 nonce and u128 collateral values cross the
    Rust/C++/Logos boundary without precision loss.
  • No legacy five-account or collateral_amount encoding remains in the new
    planner or public method.
  • Relevant Rust/module tests, module inspection, headless logoscore smoke
    tests, and nix build .#stablecoin-module pass.

Activity

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions