Skip to content

Commit

Permalink
feat: add burn operation for solana tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhd committed Jan 15, 2024
1 parent 839d95c commit 0ed3598
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const iconsComponent = {
STAKE: IconDelegate,
UNSTAKE: IconUndelegate,
WITHDRAW_UNSTAKED: IconCoins,
BURN: IconTrash,
};
class ConfirmationCheck extends PureComponent<{
marketColor: string;
Expand Down
3 changes: 2 additions & 1 deletion apps/ledger-live-desktop/static/i18n/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@
"STAKE": "Staked",
"UNSTAKE": "Unstaked",
"WITHDRAW_UNSTAKED": "Withdrawn",
"SENDING": "Sending"
"SENDING": "Sending",
"BURN": "Burned"
},
"edit": {
"title": "Speed up or Cancel",
Expand Down
1 change: 1 addition & 0 deletions libs/coin-framework/src/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export function getOperationAmountNumber(op: Operation): BigNumber {
case "OPT_OUT":
case "SLASH":
case "LOCK":
case "BURN":
return op.value.negated();

case "FREEZE":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export const PARSED_PROGRAMS = {
STAKE: "stake",
SYSTEM: "system",
SPL_TOKEN: "spl-token",
COMPUTE_BUDGET: "compute-budget",
VOTE: "vote",
} as const;
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { ParsedInstruction, PartiallyDecodedInstruction } from "@solana/web3.js";
import {
ParsedInstruction,
PartiallyDecodedInstruction,
ComputeBudgetProgram,
} from "@solana/web3.js";
import { parseSplTokenInstruction, TokenInstructionDescriptor } from "../instruction/token";
import { PARSED_PROGRAMS } from "./constants";
import {
Expand Down Expand Up @@ -35,6 +39,11 @@ type ParsedProgram =
title: string;
instruction: TokenInstructionDescriptor;
}
| {
program: "compute-budget";
title: string;
instruction: undefined;
}
| {
program: "unknown";
title: "Unknown";
Expand Down Expand Up @@ -96,6 +105,13 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,20 @@ function getTokenAccOperationType({
tx: ParsedTransaction;
delta: BigNumber;
}): OperationType {
const [mainIx, ...otherIxs] = parseTxInstructions(tx);
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) {
Expand Down
4 changes: 3 additions & 1 deletion libs/ledgerjs/packages/types-live/src/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export type OperationType =
// NEAR
| "STAKE"
| "UNSTAKE"
| "WITHDRAW_UNSTAKED";
| "WITHDRAW_UNSTAKED"
// SOLANA
| "BURN";

/**
* An Operation is the Ledger Live abstraction of a transaction for any blockchain
Expand Down

0 comments on commit 0ed3598

Please sign in to comment.