ts: fallback contexts are keyed on string for reliable equality checks

This commit is contained in:
Lou-Kamades 2024-03-27 10:10:23 -05:00
parent ac8439d3fa
commit 5320cec60a
No known key found for this signature in database
GPG Key ID: 87A166E4D7C01F30
2 changed files with 11 additions and 10 deletions

View File

@ -268,17 +268,17 @@ export async function createFallbackOracleMap(
conn: Connection, conn: Connection,
oracles: PublicKey[], oracles: PublicKey[],
fallbacks: PublicKey[], fallbacks: PublicKey[],
): Promise<Map<PublicKey, [PublicKey, PublicKey]>> { ): Promise<Map<string, [PublicKey, PublicKey]>> {
const map: Map<PublicKey, [PublicKey, PublicKey]> = new Map(); const map: Map<string, [PublicKey, PublicKey]> = new Map();
const accounts = await conn.getMultipleAccountsInfo(fallbacks); const accounts = await conn.getMultipleAccountsInfo(fallbacks);
for (let i = 0; i < oracles.length; i++) { for (let i = 0; i < oracles.length; i++) {
if (accounts[i] === null) { if (accounts[i] === null) {
map.set(oracles[i], [fallbacks[i], PublicKey.default]); map.set(oracles[i].toBase58(), [fallbacks[i], PublicKey.default]);
} else if (!isClmmOracle(accounts[i]!)) { } else if (!isClmmOracle(accounts[i]!)) {
map.set(oracles[i], [fallbacks[i], PublicKey.default]); map.set(oracles[i].toBase58(), [fallbacks[i], PublicKey.default]);
} else { } else {
const quoteKey = deriveFallbackOracleQuoteKey(accounts[i]!); const quoteKey = deriveFallbackOracleQuoteKey(accounts[i]!);
map.set(oracles[i], [fallbacks[i], quoteKey]); map.set(oracles[i].toBase58(), [fallbacks[i], quoteKey]);
} }
} }
return map; return map;

View File

@ -141,7 +141,7 @@ export class MangoClient {
private openbookFeesToDao: boolean; private openbookFeesToDao: boolean;
private prependedGlobalAdditionalInstructions: TransactionInstruction[] = []; private prependedGlobalAdditionalInstructions: TransactionInstruction[] = [];
private fallbackOracleConfig: FallbackOracleConfig = 'never'; private fallbackOracleConfig: FallbackOracleConfig = 'never';
private fixedFallbacks: Map<PublicKey, [PublicKey, PublicKey]> = new Map(); private fixedFallbacks: Map<string, [PublicKey, PublicKey]> = new Map();
multipleConnections: Connection[] = []; multipleConnections: Connection[] = [];
constructor( constructor(
@ -5035,6 +5035,7 @@ export class MangoClient {
opts?: MangoClientOptions, opts?: MangoClientOptions,
): MangoClient { ): MangoClient {
const idl = IDL; const idl = IDL;
console.log(opts);
return new MangoClient( return new MangoClient(
new Program<MangoV4>(idl as MangoV4, programId, provider), new Program<MangoV4>(idl as MangoV4, programId, provider),
@ -5226,8 +5227,8 @@ export class MangoClient {
const fallbacks: PublicKey[] = []; const fallbacks: PublicKey[] = [];
for (const oracle of mintInfos.map((mintInfo) => mintInfo.oracle)) { for (const oracle of mintInfos.map((mintInfo) => mintInfo.oracle)) {
if (fallbackMap.has(oracle)) { if (fallbackMap.has(oracle.toBase58())) {
fallbacks.push(...fallbackMap.get(oracle)!); fallbacks.push(...fallbackMap.get(oracle.toBase58())!);
} }
} }
@ -5245,10 +5246,10 @@ export class MangoClient {
/**This function assumes that the provided group has loaded banks*/ /**This function assumes that the provided group has loaded banks*/
public async deriveFallbackOracleContexts( public async deriveFallbackOracleContexts(
group: Group, group: Group,
): Promise<Map<PublicKey, [PublicKey, PublicKey]>> { ): Promise<Map<string, [PublicKey, PublicKey]>> {
// fixed // fixed
if (typeof this.fallbackOracleConfig !== 'string') { if (typeof this.fallbackOracleConfig !== 'string') {
if (this.fixedFallbacks.size == 0) { if (this.fixedFallbacks.size === 0) {
const oracles: PublicKey[] = this.fallbackOracleConfig; const oracles: PublicKey[] = this.fallbackOracleConfig;
const fallbacks: PublicKey[] = []; const fallbacks: PublicKey[] = [];
Array.from(group.banksMapByTokenIndex.values()).forEach((b) => { Array.from(group.banksMapByTokenIndex.values()).forEach((b) => {