Skip to content

Commit

Permalink
refactor: redundant code in solana tokens integration
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhd committed May 6, 2024
1 parent 521bac4 commit fc18e3b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ export const PARSED_PROGRAMS = {
STAKE: "stake",
SYSTEM: "system",
SPL_TOKEN: "spl-token",
COMPUTE_BUDGET: "compute-budget",
VOTE: "vote",
} as const;
18 changes: 1 addition & 17 deletions libs/coin-modules/coin-solana/src/api/chain/program/parser.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
ParsedInstruction,
PartiallyDecodedInstruction,
ComputeBudgetProgram,
} from "@solana/web3.js";
import { ParsedInstruction, PartiallyDecodedInstruction } from "@solana/web3.js";
import { parseSplTokenInstruction, TokenInstructionDescriptor } from "../instruction/token";
import { PARSED_PROGRAMS } from "./constants";
import {
Expand Down Expand Up @@ -39,11 +35,6 @@ type ParsedProgram =
title: string;
instruction: TokenInstructionDescriptor;
}
| {
program: "compute-budget";
title: string;
instruction: undefined;
}
| {
program: "unknown";
title: "Unknown";
Expand Down Expand Up @@ -105,13 +96,6 @@ export const parse = (ix: ParsedInstruction | PartiallyDecodedInstruction): Pars
}
}

if (ComputeBudgetProgram.programId.equals(ix.programId)) {
return {
program: PARSED_PROGRAMS["COMPUTE_BUDGET"],
title: "Compute Budget",
instruction: undefined, // system instruction, doesn't make sense to parse in LL
};
}
return unknown();
};

Expand Down
16 changes: 3 additions & 13 deletions libs/coin-modules/coin-solana/src/js-synchronization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,18 +667,6 @@ function getTokenAccOperationType({
const parsedIxs = parseTxInstructions(tx);
const [mainIx, ...otherIxs] = parsedIxs;

if (parsedIxs.length === 3) {
const [first, second, third] = parsedIxs;
if (
first.program === "compute-budget" &&
second.program === "compute-budget" &&
third.program === "spl-token" &&
third.instruction.type === "burn"
) {
return "BURN";
}
}

if (mainIx !== undefined && otherIxs.length === 0) {
switch (mainIx.program) {
case "spl-associated-token-account":
Expand All @@ -693,6 +681,8 @@ function getTokenAccOperationType({
return "FREEZE";
case "thawAccount":
return "UNFREEZE";
case "burn":
return "BURN";
}
}
}
Expand All @@ -704,7 +694,7 @@ function getTokenAccOperationType({
function parseTxInstructions(tx: ParsedTransaction) {
return tx.message.instructions
.map(ix => parseQuiet(ix))
.filter(({ program }) => program !== "spl-memo");
.filter(({ program }) => program !== "spl-memo" && program !== "unknown");
}

function dropMemoLengthPrefixIfAny(memo: string) {
Expand Down
1 change: 0 additions & 1 deletion libs/ledgerjs/packages/cryptoassets/src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ function convertElrondESDTTokens([
};
}

/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
function convertSplTokens([
chainId,
name,
Expand Down

0 comments on commit fc18e3b

Please sign in to comment.