Skip to content

Commit

Permalink
register trustless oracle decode mango (#1886)
Browse files Browse the repository at this point in the history
  • Loading branch information
abrzezinski94 authored Oct 20, 2023
1 parent d22e45b commit a38c412
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
33 changes: 28 additions & 5 deletions components/instructions/programs/mangoV4.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ const instructions = () => ({
])

const oracleData = await decodePriceFromOracleAi(
oracle,
oracleAi!,
connection,
proposedOracle.type
Expand Down Expand Up @@ -668,12 +667,36 @@ const instructions = () => ({
],
getDataUI: async (
connection: Connection,
data: Uint8Array
//accounts: AccountMetaData[]
data: Uint8Array,
accounts: AccountMetaData[]
) => {
const info = await displayArgs(connection, data)
const oracle = accounts[6].pubkey

const [info, proposedOracle, oracleAi] = await Promise.all([
displayArgs(connection, data),
getOracle(connection, oracle),
connection.getAccountInfo(oracle),
])

const oracleData = await decodePriceFromOracleAi(
oracleAi!,
connection,
proposedOracle.type
)
try {
return <div>{info}</div>
return (
<div>
{oracleData.uiPrice ? (
<div className="py-4 space-y-2">
<div>Oracle Price: ${oracleData.uiPrice}</div>
<div>Oracle Last known confidence: {oracleData.deviation}%</div>
</div>
) : (
<div className="py-4">No Oracle Data</div>
)}
<div>{info}</div>
</div>
)
} catch (e) {
console.log(e)
return <div>{JSON.stringify(data)}</div>
Expand Down
1 change: 0 additions & 1 deletion utils/Mango/listingTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ export const getBestMarket = async ({
}

export const decodePriceFromOracleAi = async (
oracle: PublicKey,
ai: AccountInfo<Buffer>,
connection: Connection,
type: string
Expand Down

1 comment on commit a38c412

@vercel
Copy link

@vercel vercel bot commented on a38c412 Oct 20, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.