moved functions to utils

This commit is contained in:
dd 2021-02-26 16:31:09 -05:00
parent f63473a2b9
commit d928ec70ca
2 changed files with 26 additions and 31 deletions

View File

@ -1,6 +1,5 @@
import {
Account,
AccountInfo,
Connection,
PublicKey,
sendAndConfirmRawTransaction,
@ -77,9 +76,6 @@ export class MangoGroup {
return aggs.map((agg) => (agg.answer.median.toNumber() / Math.pow(10, agg.config.decimals))).concat(1.0)
// const oracleAccs = await getMultipleAccounts(connection, this.oracles);
// return oracleAccs.map((oa) => decodeAggregatorInfo(oa.accountInfo).submissionValue).concat(1.0)
}
getMarketIndex(spotMarket: Market): number {
@ -1069,29 +1065,3 @@ export class MangoClient {
}
}
async function getMultipleAccounts(
connection: Connection,
publicKeys: PublicKey[]
): Promise<{ publicKey: PublicKey; accountInfo: AccountInfo<Buffer> }[]> {
const publickKeyStrs = publicKeys.map((pk) => (pk.toBase58()));
// @ts-ignore
const resp = await connection._rpcRequest('getMultipleAccounts', [publickKeyStrs]);
if (resp.error) {
throw new Error(resp.error.message);
}
return resp.result.value.map(
({ data, executable, lamports, owner } , i) => ({
publicKey: publicKeys[i],
accountInfo: {
data: Buffer.from(data[0], 'base64'),
executable,
owner: new PublicKey(owner),
lamports,
},
}),
);
}

View File

@ -190,4 +190,29 @@ export function parseTokenAccountData(
owner: new PublicKey(owner),
amount,
};
}
}
export async function getMultipleAccounts(
connection: Connection,
publicKeys: PublicKey[]
): Promise<{ publicKey: PublicKey; accountInfo: AccountInfo<Buffer> }[]> {
const publickKeyStrs = publicKeys.map((pk) => (pk.toBase58()));
// @ts-ignore
const resp = await connection._rpcRequest('getMultipleAccounts', [publickKeyStrs]);
if (resp.error) {
throw new Error(resp.error.message);
}
return resp.result.value.map(
({ data, executable, lamports, owner } , i) => ({
publicKey: publicKeys[i],
accountInfo: {
data: Buffer.from(data[0], 'base64'),
executable,
owner: new PublicKey(owner),
lamports,
},
}),
);
}