Skip to content

Commit

Permalink
Mango instruction decoding: use generic helper from mango-client (whi…
Browse files Browse the repository at this point in the history
…ch is often auto updated by dependabot) instead of relying on a manual instruction lookup table (#21985)

Signed-off-by: microwavedcola1 <[email protected]>
  • Loading branch information
microwavedcola1 authored Dec 17, 2021
1 parent 0f6e8d3 commit 94aa9e5
Showing 1 changed file with 2 additions and 47 deletions.
49 changes: 2 additions & 47 deletions explorer/src/components/instruction/mango/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,56 +51,11 @@ export const isMangoInstruction = (instruction: TransactionInstruction) => {
.includes(instruction.programId.toBase58());
};

export const INSTRUCTION_LOOKUP: { [key: number]: string } = {
0: "InitMangoGroup",
1: "InitMangoAccount",
2: "Deposit",
3: "Withdraw",
4: "AddSpotMarket",
5: "AddToBasket",
6: "Borrow",
7: "CachePrices",
8: "CacheRootBanks",
9: "PlaceSpotOrder",
10: "AddOracle",
11: "AddPerpMarket",
12: "PlacePerpOrder",
13: "CancelPerpOrderByClientId",
14: "CancelPerpOrder",
15: "ConsumeEvents",
16: "CachePerpMarkets",
17: "UpdateFunding",
18: "SetOracle",
19: "SettleFunds",
20: "CancelSpotOrder",
21: "UpdateRootBank",
22: "SettlePnl",
23: "SettleBorrow",
24: "ForceCancelSpotOrders",
25: "ForceCancelPerpOrders",
26: "LiquidateTokenAndToken",
27: "LiquidateTokenAndPerp",
28: "LiquidatePerpMarket",
29: "SettleFees",
30: "ResolvePerpBankruptcy",
31: "ResolveTokenBankruptcy",
32: "InitSpotOpenOrders",
33: "RedeemMngo",
34: "AddMangoAccountInfo",
35: "DepositMsrm",
36: "WithdrawMsrm",
37: "ChangePerpMarketParams",
};

export const parseMangoInstructionTitle = (
instruction: TransactionInstruction
): string => {
const code = instruction.data[0];

if (!(code in INSTRUCTION_LOOKUP)) {
throw new Error(`Unrecognized Mango instruction code: ${code}`);
}
return INSTRUCTION_LOOKUP[code];
let decodedInstruction = MangoInstructionLayout.decode(instruction.data, 0);
return Object.keys(decodedInstruction)[0];
};

export type Deposit = {
Expand Down

1 comment on commit 94aa9e5

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for explorer ready!

✅ Preview
https://explorer-7ociz1h34-solana-labs.vercel.app

Built with commit 94aa9e5.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.