Skip to main content
added 19 characters in body
Source Link

I am having the same issue. but I am using js.

I am having the same issue.

I am having the same issue. but I am using js.

Source Link

I am having the same issue.

You can try deserialize sample transactions as below but I am facing the same issue with more complex transactions.

#1 - Compute Budget: SetComputeUnitLimit --- v1 (with bytes)

const hexToBytes = (hex) => {
  let bytes = [];
  for (let c = 0; c < hex.length; c += 2) {
    bytes.push(parseInt(hex.substr(c, 2), 16));
  }
  return bytes;
};

const decodeInstruction = (hexData) => {
  const bytes = hexToBytes(hexData);
  console.log(bytes.length);

  return {
    discriminator: bytes.slice(0, 1).reduce((acc, byte, index) => acc + (byte << (8 * index)), 0),
    units: bytes.slice(1, 5).reduce((acc, byte, index) => acc + (byte << (8 * index)), 0)
  }
};

const hexData = "0290d00300"; // hex data !!!
const decodedData = decodeInstruction(hexData);
console.log(JSON.stringify(decodedData, null, 2));

#1 - Compute Budget: SetComputeUnitLimit --- v2 (with borsh)

const borsh = require('borsh');
const bs58 = require('bs58');
const schema = { 'struct': { 
  'discriminator': 'u8', 
  'units': 'u32' 
} };
const data = "HnkkG7"; // encoded data !!!

const decoded = borsh.deserialize(schema, Buffer.from(bs58.decode(data)));
console.log(decoded);

#6 - Pump: Buy --- mixed

const borsh = require('borsh');
const bs58 = require('bs58');

const hexToBytes = (hex) => {
  let bytes = [];
  for (let c = 0; c < hex.length; c += 2) {
    bytes.push(parseInt(hex.substr(c, 2), 16));
  }
  return bytes;
};

function encodedToHex(encodedData) {
  // Decode the base58 encoded data into a buffer
  const buffer = Buffer.from(bs58.decode(encodedData));
  
  return buffer.toString('hex');
}

const decodeInstruction = (hexData) => {
  const bytes = hexToBytes(hexData);
  console.log(bytes.length);

  return {   
    amount: bytes.slice(0, 16).reduce((acc, byte, index) => acc + (byte << (8 * index)), 0),
    maxSolCost: bytes.slice(16, 23).reduce((acc, byte, index) => acc + (byte << (8 * index)), 0)
  }
};

const schema = { 'struct': { 'amount': 'u64', 
  'maxSolCost': 'u64' 
} };
const encodeddata = "AJTQ2h9DXrBiiXimcEJkmSTSbrNoMJQs9";

const hexData = encodedToHex(encodeddata);
const decodedData = decodeInstruction(hexData);
console.log(JSON.stringify(decodedData, null, 2));

// RESULTS
// { amount": -2034364355, "maxSolCost": 303000000 } // v1 (with bytes)
// { amount: 16927863322537952870n, maxSolCost: 10623762376237n } // v2 (with borsh)

#6 - Pump: Buy RESULTS | | amount | maxSolCost | | -------------- | --------------------- | ---------------------- | | v1 (bytes) | -2034364355 | 303000000 - Ok | | v2 (borsh) | 16927863322537952870n | 10623762376237n - Ok (BUT it should be the amount) | | solscan | 10623762376237 | 303000000 |

I do not know why it the same logic do not work well on instructions #6 and #6.4. Only what I found out that there is a little more bytes than it used to be regarding to the "Input Args"/"Events" data structures. Maybe there is a step what needs to be implemented on those instructions.

With #6.4. it is even worse as it also includes publicKey types andit is even more complicated.