Skip to content

Bug: positionPda mismatch in initializePositionByOperator #283

@VladDunaev

Description

@VladDunaev

Description

initializePositionByOperator derives positionPda with one positionWidth value but invokes the program with another, causing a PDA mismatch and transaction failure.

Details

The initializePositionByOperator function derives positionPda using the provided positionWidth:

const [positionPda, _bump] = derivePosition(
this.pubkey,
base,
lowerBinId,
positionWidth,
this.program.programId
);

However, when calling the program method initializePositionByOperator, it uses DEFAULT_BIN_PER_POSITION instead of the provided positionWidth:

const initializePositionByOperatorTx = await this.program.methods
.initializePositionByOperator(
lowerBinId.toNumber(),
DEFAULT_BIN_PER_POSITION.toNumber(),
feeOwner,
lockReleasePoint
)

As a result, the on-chain program derives a different positionPda, leading to a transaction failure:

{
  "transactionMessage": "Transaction simulation failed: Error processing Instruction 0: custom program error: 0x7d6",
  "transactionLogs": [
    "Program LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo invoke [1]",
    "Program log: Instruction: InitializePositionByOperator",
    "Program log: AnchorError caused by account: position. Error Code: ConstraintSeeds. Error Number: 2006. Error Message: A seeds constraint was violated.",
    "Program log: Left:",
    "Program log: 77Vr1EQF9TQZbTrGK9PRFZNz1ULUE1s4c1Bs5XHbcYXB",
    "Program log: Right:",
    "Program log: GkCgxJfRsH6Xhf84UB6QwDqizYnzkMeuEd8fsWPfPvhY",
    "Program LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo consumed 11701 of 200000 compute units",
    "Program LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo failed: custom program error: 0x7d6"
  ]
}

This indicates a mismatch between the client-side PDA derivation and the program’s expectation.

Suggested fix

Replace usage of DEFAULT_BIN_PER_POSITION with the provided positionWidth parameter when invoking the program method.

Metadata

Metadata

Assignees

No one assigned

    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