forked from solana-foundation/explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add titles for token lending instructions (#15217)
* feat: add lending instruction names * chore: capitalize words
- Loading branch information
1 parent
9af912a
commit 3adc87e
Showing
7 changed files
with
154 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
|
||
# production | ||
/build | ||
/wasm/target | ||
|
||
# misc | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from "react"; | ||
import { TransactionInstruction, SignatureResult } from "@solana/web3.js"; | ||
import { InstructionCard } from "./InstructionCard"; | ||
import { useCluster } from "providers/cluster"; | ||
import { reportError } from "utils/sentry"; | ||
import { parseTokenLendingInstructionTitle } from "./token-lending/types"; | ||
|
||
export function TokenLendingDetailsCard({ | ||
ix, | ||
index, | ||
result, | ||
signature, | ||
innerCards, | ||
childIndex, | ||
}: { | ||
ix: TransactionInstruction; | ||
index: number; | ||
result: SignatureResult; | ||
signature: string; | ||
innerCards?: JSX.Element[]; | ||
childIndex?: number; | ||
}) { | ||
const { url } = useCluster(); | ||
|
||
let title; | ||
try { | ||
title = parseTokenLendingInstructionTitle(ix); | ||
} catch (error) { | ||
reportError(error, { | ||
url: url, | ||
signature: signature, | ||
}); | ||
} | ||
|
||
return ( | ||
<InstructionCard | ||
ix={ix} | ||
index={index} | ||
result={result} | ||
title={`Token Lending: ${title || "Unknown"}`} | ||
innerCards={innerCards} | ||
childIndex={childIndex} | ||
defaultRaw | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { TransactionInstruction } from "@solana/web3.js"; | ||
|
||
export const PROGRAM_IDS: string[] = [ | ||
"LendZqTs7gn5CTSJU1jWKhKuVpjJGom45nnwPb2AMTi", // mainnet / testnet / devnet | ||
]; | ||
|
||
const INSTRUCTION_LOOKUP: { [key: number]: string } = { | ||
0: "Initialize Lending Market", | ||
1: "Initialize Reserve", | ||
2: "Initialize Obligation", | ||
3: "Reserve Deposit", | ||
4: "Reserve Withdraw", | ||
5: "Borrow", | ||
6: "Repay Loan", | ||
7: "Liquidate Loan", | ||
8: "Accrue Interest", | ||
}; | ||
|
||
export function isTokenLendingInstruction( | ||
instruction: TransactionInstruction | ||
): boolean { | ||
return PROGRAM_IDS.includes(instruction.programId.toBase58()); | ||
} | ||
|
||
export function parseTokenLendingInstructionTitle( | ||
instruction: TransactionInstruction | ||
): string { | ||
const code = instruction.data[0]; | ||
|
||
if (!(code in INSTRUCTION_LOOKUP)) { | ||
throw new Error(`Unrecognized Token Swap instruction code: ${code}`); | ||
} | ||
|
||
return INSTRUCTION_LOOKUP[code]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters