ts: fallback contexts are keyed on string for reliable equality checks
This commit is contained in:
parent
ac8439d3fa
commit
5320cec60a
|
@ -268,17 +268,17 @@ export async function createFallbackOracleMap(
|
|||
conn: Connection,
|
||||
oracles: PublicKey[],
|
||||
fallbacks: PublicKey[],
|
||||
): Promise<Map<PublicKey, [PublicKey, PublicKey]>> {
|
||||
const map: Map<PublicKey, [PublicKey, PublicKey]> = new Map();
|
||||
): Promise<Map<string, [PublicKey, PublicKey]>> {
|
||||
const map: Map<string, [PublicKey, PublicKey]> = new Map();
|
||||
const accounts = await conn.getMultipleAccountsInfo(fallbacks);
|
||||
for (let i = 0; i < oracles.length; i++) {
|
||||
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]!)) {
|
||||
map.set(oracles[i], [fallbacks[i], PublicKey.default]);
|
||||
map.set(oracles[i].toBase58(), [fallbacks[i], PublicKey.default]);
|
||||
} else {
|
||||
const quoteKey = deriveFallbackOracleQuoteKey(accounts[i]!);
|
||||
map.set(oracles[i], [fallbacks[i], quoteKey]);
|
||||
map.set(oracles[i].toBase58(), [fallbacks[i], quoteKey]);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
|
|
|
@ -141,7 +141,7 @@ export class MangoClient {
|
|||
private openbookFeesToDao: boolean;
|
||||
private prependedGlobalAdditionalInstructions: TransactionInstruction[] = [];
|
||||
private fallbackOracleConfig: FallbackOracleConfig = 'never';
|
||||
private fixedFallbacks: Map<PublicKey, [PublicKey, PublicKey]> = new Map();
|
||||
private fixedFallbacks: Map<string, [PublicKey, PublicKey]> = new Map();
|
||||
multipleConnections: Connection[] = [];
|
||||
|
||||
constructor(
|
||||
|
@ -5035,6 +5035,7 @@ export class MangoClient {
|
|||
opts?: MangoClientOptions,
|
||||
): MangoClient {
|
||||
const idl = IDL;
|
||||
console.log(opts);
|
||||
|
||||
return new MangoClient(
|
||||
new Program<MangoV4>(idl as MangoV4, programId, provider),
|
||||
|
@ -5226,8 +5227,8 @@ export class MangoClient {
|
|||
const fallbacks: PublicKey[] = [];
|
||||
|
||||
for (const oracle of mintInfos.map((mintInfo) => mintInfo.oracle)) {
|
||||
if (fallbackMap.has(oracle)) {
|
||||
fallbacks.push(...fallbackMap.get(oracle)!);
|
||||
if (fallbackMap.has(oracle.toBase58())) {
|
||||
fallbacks.push(...fallbackMap.get(oracle.toBase58())!);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5245,10 +5246,10 @@ export class MangoClient {
|
|||
/**This function assumes that the provided group has loaded banks*/
|
||||
public async deriveFallbackOracleContexts(
|
||||
group: Group,
|
||||
): Promise<Map<PublicKey, [PublicKey, PublicKey]>> {
|
||||
): Promise<Map<string, [PublicKey, PublicKey]>> {
|
||||
// fixed
|
||||
if (typeof this.fallbackOracleConfig !== 'string') {
|
||||
if (this.fixedFallbacks.size == 0) {
|
||||
if (this.fixedFallbacks.size === 0) {
|
||||
const oracles: PublicKey[] = this.fallbackOracleConfig;
|
||||
const fallbacks: PublicKey[] = [];
|
||||
Array.from(group.banksMapByTokenIndex.values()).forEach((b) => {
|
||||
|
|
Loading…
Reference in New Issue