0

I want to get Sol reserves and token reserves for a newly create pump.fun token. On Solscan, I can see these values in the inner instructions of the tokens creation signature. Heres an example:

https://solscan.io/tx/aGU881DDvgpeezs9mUFJWv3KYkwEggWEQtcxTCupovLhLfgZ3fpwLWyGmA8bbzaQ4JxW39uA29zxHvx5LSBG3Qu

Under instruction "#6.4 - Pump.Fun: Unknown" you can see "virtualSolReserves" and "virtualTokenReserves" in the Events section. My question is how do I get the value of these fields.

When I use getTransaction(), I can get the "Instruction Data Raw". For example, using the same solscan transaction above I can get the Raw Instruction Data in encoded form, which looks like: 2K7nL28PxCW8ejnyCeuMpbXf8Xj7ysXeidJ55TJtZ8PzmG6NLHutyvhym8DqCYcg92aNSXYc4zw6BTJH2matHQR2vqYABBozk3wQJnArhbuCarwm6a1rdvkWiQS8JzqX5citcf3Hf8VMppEpJHtxDQ7J6FJHdnvUG7tyfqG6iU2wpqKR9MZS8515ZAXq

(on the solscan link provided, you can see this by control-f "e445a52e51cb9a1dbddb7fd34ee661eec5c7cc3d63eb826f29ed1c13ed12b623b18dc813f9f0068ae959561c0ed153ef00a3e111000000002d269589a90900000102d9b0c8ef65efba9ce4f49d239deb27e0b90af8432c7f91726f4f185f2a7a971803656600000000004f050e07000000d3e942be39c6030000a3e11100000000d3513072a8c70200" and then hitting the little wheel next to it to the encoded form)

Ultimately, I am wondering how decode this raw instruction data to get its information and values. How would I create a program in PYTHON to decode this? Any guidance would be greatly appreciated :)

2 Answers 2

0

You can use the deserialize method from the Transaction class of solana.py to acheive this.

Refer to the documentation here: https://michaelhly.com/solana-py/core/transaction/

0

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.