Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

register trustless oracle decode mango #1886

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading