Skip to content

Instantly share code, notes, and snippets.

@devDesu
Created July 18, 2022 10:43
Show Gist options
  • Save devDesu/85df02c8178768755d6f44a3033c8ca8 to your computer and use it in GitHub Desktop.
Save devDesu/85df02c8178768755d6f44a3033c8ca8 to your computer and use it in GitHub Desktop.
function orcaParser(instruction: TransactionInstruction): ParsedCustomInstruction {
let name: string;
let args: unknown;
let accounts: ParsedAccount[];
switch (instruction.data[0]) {
case 1:
name = "Orca Swap";
args = { inAmount: instruction.data.readBigInt64LE(1), outAmount: instruction.data.readBigInt64LE(9) };
accounts = [
{ name: "swap", ...instruction.keys[0] },
{ name: "authority", ...instruction.keys[1] },
{ name: "userTransferAuthority", ...instruction.keys[2] },
{ name: "source", ...instruction.keys[3] },
{ name: "swapSource", ...instruction.keys[4] },
{ name: "swapDestination", ...instruction.keys[5] },
{ name: "destination", ...instruction.keys[6] },
{ name: "poolMint", ...instruction.keys[7] },
{ name: "poolFee", ...instruction.keys[8] },
{ name: "tokenProgram", ...instruction.keys[9] },
];
break;
default:
name = "unknown";
args = { unknown: instruction.data };
accounts = instruction.keys;
break;
}
return {
programId: instruction.programId,
name,
accounts,
args,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment