update to crank and decoding
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
e218055344
commit
33fc12b78e
|
@ -36,6 +36,9 @@ const USER_KEYPAIR =
|
|||
const GROUP = process.env.GROUP_OVERRIDE || MANGO_V4_MAIN_GROUP.toBase58();
|
||||
const SLEEP_MS = Number(process.env.SLEEP_MS) || 50_000; // 100s
|
||||
|
||||
console.log(`Starting with ${SLEEP_MS}`);
|
||||
console.log(`${CLUSTER_URL}`);
|
||||
|
||||
// TODO use mangolana to send txs
|
||||
|
||||
interface OracleInterface {
|
||||
|
@ -104,6 +107,23 @@ interface OracleInterface {
|
|||
.join(', ')}`,
|
||||
);
|
||||
|
||||
// todo use chunk
|
||||
// todo use luts
|
||||
|
||||
// const [pullIxs, luts] = await PullFeed.fetchUpdateManyIx(
|
||||
// sbOnDemandProgram,
|
||||
// {
|
||||
// feeds: oraclesToCrank.map((o) => new PublicKey(o.oracle.oraclePk)),
|
||||
// numSignatures: 3,
|
||||
// },
|
||||
// );
|
||||
|
||||
// console.log(
|
||||
// oraclesToCrank
|
||||
// .map((o) => new PublicKey(o.oracle.oraclePk))
|
||||
// .toString(),
|
||||
// );
|
||||
|
||||
const pullIxs: TransactionInstruction[] = [];
|
||||
const lutOwners: (PublicKey | Oracle)[] = [];
|
||||
for (const oracle of oraclesToCrank) {
|
||||
|
@ -143,7 +163,7 @@ interface OracleInterface {
|
|||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(`Error in sending tx, ${error}`);
|
||||
console.log(`Error in sending tx, ${JSON.stringify(error)}`);
|
||||
}
|
||||
|
||||
await new Promise((r) => setTimeout(r, SLEEP_MS));
|
||||
|
@ -167,7 +187,7 @@ async function preparePullIx(
|
|||
);
|
||||
|
||||
const conf = {
|
||||
numSignatures: 3,
|
||||
numSignatures: 2,
|
||||
feed: oracle.oracle.oraclePk,
|
||||
};
|
||||
// TODO use fetchUpdateMany
|
||||
|
@ -214,14 +234,18 @@ async function filterForVarianceThresholdOracles(
|
|||
|
||||
const changePct = (Math.abs(res.price - simPrice) * 100) / res.price;
|
||||
const changeBps = changePct * 100;
|
||||
if (changePct > item.decodedPullFeed.maxVariance) {
|
||||
if (changePct > item.decodedPullFeed.maxVariance / 1000000000) {
|
||||
console.log(
|
||||
`- ${item.oracle.name}, variance threshold, candidate, simPrice ${simPrice}, res.price ${res.price}, change ${changeBps} bps`,
|
||||
`- ${item.oracle.name}, candidate, ${
|
||||
item.decodedPullFeed.maxVariance / 1000000000
|
||||
}, ${simPrice}, ${res.price}, ${changePct}`,
|
||||
);
|
||||
varianceThresholdCrossedOracles.push(item);
|
||||
} else {
|
||||
console.log(
|
||||
`- ${item.oracle.name}, variance threshold, non-candidate, simPrice ${simPrice}, res.price ${res.price}, change ${changeBps} bps`,
|
||||
`- ${item.oracle.name}, non-candidate, ${
|
||||
item.decodedPullFeed.maxVariance / 1000000000
|
||||
}, ${simPrice}, ${res.price}, ${changePct}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -247,12 +271,12 @@ async function filterForStaleOracles(
|
|||
slot - res.lastUpdatedSlot > item.decodedPullFeed.maxStaleness
|
||||
) {
|
||||
console.log(
|
||||
`- ${item.oracle.name}, stale oracle, candidate, maxStaleness ${item.decodedPullFeed.maxStaleness}, slot ${slot}, res.lastUpdatedSlot ${res.lastUpdatedSlot}, diff ${diff}`,
|
||||
`- ${item.oracle.name}, candidate, ${item.decodedPullFeed.maxStaleness}, ${slot}, ${res.lastUpdatedSlot}, ${diff}`,
|
||||
);
|
||||
staleOracles.push(item);
|
||||
} else {
|
||||
console.log(
|
||||
`- ${item.oracle.name}, stale oracle, non-candidate, maxStaleness ${item.decodedPullFeed.maxStaleness}, slot ${slot}, res.lastUpdatedSlot ${res.lastUpdatedSlot}, diff ${diff}`,
|
||||
`- ${item.oracle.name}, non-candidate, ${item.decodedPullFeed.maxStaleness}, ${slot}, ${res.lastUpdatedSlot}, ${diff}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { AnchorProvider, Wallet } from '@coral-xyz/anchor';
|
||||
import { Magic as PythMagic } from '@pythnetwork/client';
|
||||
import { AccountInfo, Connection, Keypair, PublicKey } from '@solana/web3.js';
|
||||
import { SB_ON_DEMAND_PID, toFeedValue } from '@switchboard-xyz/on-demand';
|
||||
import { SB_ON_DEMAND_PID } from '@switchboard-xyz/on-demand';
|
||||
import SwitchboardProgram from '@switchboard-xyz/sbv2-lite';
|
||||
import Big from 'big.js';
|
||||
import BN from 'bn.js';
|
||||
|
@ -131,12 +131,23 @@ export function parseSwitchboardOnDemandOracle(
|
|||
);
|
||||
|
||||
// useful for development
|
||||
// console.log(decodedPullFeed.result);
|
||||
// console.log(decodedPullFeed);
|
||||
// console.log(decodedPullFeed.submissions);
|
||||
|
||||
const feedValue = toFeedValue(decodedPullFeed.submissions, new BN(0));
|
||||
const price = new Big(feedValue?.value.toString()).div(1e18);
|
||||
const lastUpdatedSlot = feedValue!.slot!.toNumber(); // TODO the !
|
||||
// Use custom code instead of toFeedValue from sb on demand sdk
|
||||
// Custom code which has uses min sample size
|
||||
// const feedValue = toFeedValue(decodedPullFeed.submissions, new BN(0));
|
||||
let values = decodedPullFeed.submissions.slice(
|
||||
0,
|
||||
decodedPullFeed.minSampleSize,
|
||||
);
|
||||
if (values.length === 0) {
|
||||
return { price: 0, lastUpdatedSlot: 0, uiDeviation: 0 };
|
||||
}
|
||||
values = values.sort((x, y) => (x.value.lt(y.value) ? -1 : 1));
|
||||
const feedValue = values[Math.floor(values.length / 2)];
|
||||
const price = new Big(feedValue.value.toString()).div(1e18);
|
||||
const lastUpdatedSlot = feedValue.slot.toNumber();
|
||||
const stdDeviation = 0; // TODO the 0
|
||||
return { price, lastUpdatedSlot, uiDeviation: stdDeviation };
|
||||
|
||||
|
|
Loading…
Reference in New Issue