drift-labs / protocol-v2

On-chain perpetuals dex with multiple liquidity mechanisms
Apache License 2.0
201 stars 100 forks source link

Program log: AnchorError occurred. Error Code: MathError. Error Number: 6019. Error Message: Math Error. #1171

Closed wkshare closed 5 days ago

wkshare commented 1 month ago

I am using the SDK to call a transaction, but it always fails with the following error message. I don't understand what this error means. What exactly am I doing wrong? Could you please advise, or is this a bug? Logs: [ "Program log: 4DRDR8LtbQHairBmAAAAAAAAAAABAAAAAAAAAAAAAAGrpfMVs91ZutsZv7Rfru4PQspJgI9+ATOHP60wxgVYZwF4AAAAAQABAMqaOwAAAAABAAAAAAAAAAABAAAAAAAAAAAAAAAAAADHMkoHAAAAAA==", "Program log: aBNAOFkVAlrairBmAAAAAKul8xWz3Vm62xm/tF+u7g9CykmAj34BM4c/rTDGBVhnvvzJEAAAAAAAAAAAAAAAAADKmjsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaKE/BwAAAACYyGUHAAAAAD6LsGYAAAAAAAAAAHgAAAAAAAEAAQABAAAAAAC0AAAA", "Program dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH consumed 78694 of 799850 compute units", "Program dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH success", "Program dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH invoke [1]", "Program log: Instruction: BeginSwap", "Program log: Math error thrown at programs/drift/src/math/spot_balance.rs:167", "Program log: AnchorError occurred. Error Code: MathError. Error Number: 6019. Error Message: Math Error.", "Program dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH consumed 32338 of 721156 compute units", "Program dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH failed: custom program error: 0x1783" ].

my codes: ` const swapIx = await driftClient.getJupiterSwapIxV6({ jupiterClient: jupiterClient, inMarketIndex: 1, outMarketIndex: 0, amount: new BN(100_000_000) })

  if (swapIx) {
    swapIx.ixs.unshift(
      ComputeBudgetProgram.setComputeUnitPrice({
        microLamports: Math.floor(
          priorityFeeSubscriber!.getCustomStrategyResult()
        ),
      })
    );
    const driftLookupTables =
      await driftClient.fetchMarketLookupTableAccount();
    const lookupTables = [...swapIx.lookupTables, driftLookupTables!];

    const vtx = await driftClient.txSender.getVersionedTransaction(
      swapIx.ixs,
      lookupTables,
      undefined,
      driftClient.opts,
      await driftClient.connection.getLatestBlockhash()
    );

    const resp = await driftClient.txSender.sendVersionedTransaction(
      vtx,
      undefined,
      driftClient.opts
    );

    logger.info(`send completed: ${resp.txSig} `);

`

crispheaney commented 2 weeks ago

I think this commit might have fixed this: https://github.com/drift-labs/protocol-v2/commit/a5be8aae86c13840242bbff3e95682f41840bddd