Fix ids api (#371)
* Fix ids api Signed-off-by: microwavedcola1 <microwavedcola@gmail.com> * Fixes from review Signed-off-by: microwavedcola1 <microwavedcola@gmail.com> Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
a7a5c740c9
commit
60d3f8d403
|
@ -12,49 +12,56 @@
|
|||
"publicKey": "8Z8ypSDDbC2UWqapP4AqDGbTbxYgh5AKtv1682UYc74o",
|
||||
"mint": "So11111111111111111111111111111111111111112",
|
||||
"tokenIndex": 5,
|
||||
"bankNum": 0
|
||||
"bankNum": 0,
|
||||
"active": true
|
||||
},
|
||||
{
|
||||
"name": "USDT",
|
||||
"publicKey": "Bid15jgtr5Ppftj7BZdEJbiWFN3R1U3i2PUELA2ZDU1N",
|
||||
"mint": "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
|
||||
"tokenIndex": 1,
|
||||
"bankNum": 0
|
||||
"bankNum": 0,
|
||||
"active": true
|
||||
},
|
||||
{
|
||||
"name": "USDC",
|
||||
"publicKey": "MZSA6xDJFieoMbydmjWv7FkPCcipmtDC2bxE1qYGvaY",
|
||||
"mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
||||
"tokenIndex": 0,
|
||||
"bankNum": 0
|
||||
"bankNum": 0,
|
||||
"active": true
|
||||
},
|
||||
{
|
||||
"name": "BTC",
|
||||
"publicKey": "JfS9mG5Sonm6eyhQis2DdFSkfFmtoP8kW5UAaXcEWa4",
|
||||
"mint": "9n4nbM75f5Ui33ZbPYXn59EwSgE8CGsHtAeTH5YFeJ9E",
|
||||
"tokenIndex": 2,
|
||||
"bankNum": 0
|
||||
"bankNum": 0,
|
||||
"active": true
|
||||
},
|
||||
{
|
||||
"name": "soETH",
|
||||
"publicKey": "549bGbirHQSQ5mnFQNT5zBUs8XMFyK9hNAWRWcpCJzBn",
|
||||
"mint": "2FPyTwcZLUg1MDrwsyoP4D6s1tM7hAkHYRjkNb5w6Pxk",
|
||||
"tokenIndex": 4,
|
||||
"bankNum": 0
|
||||
"bankNum": 0,
|
||||
"active": true
|
||||
},
|
||||
{
|
||||
"name": "ETH",
|
||||
"publicKey": "2emCTQgGDubaZEdstGXbf9cL4sTgCiSBvWjwk925F4Bd",
|
||||
"mint": "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs",
|
||||
"tokenIndex": 3,
|
||||
"bankNum": 0
|
||||
"bankNum": 0,
|
||||
"active": true
|
||||
},
|
||||
{
|
||||
"name": "MSOL",
|
||||
"publicKey": "2uL6J4aUqpDerWoXejAZQ585SVYLjhBhgQvpBEHeLybb",
|
||||
"mint": "mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So",
|
||||
"tokenIndex": 6,
|
||||
"bankNum": 0
|
||||
"bankNum": 0,
|
||||
"active": true
|
||||
}
|
||||
],
|
||||
"stubOracles": [
|
||||
|
|
|
@ -97,7 +97,9 @@ export class Group {
|
|||
return this.halted === 0;
|
||||
}
|
||||
|
||||
public async reloadAll(client: MangoClient, ids?: Id): Promise<void> {
|
||||
public async reloadAll(client: MangoClient): Promise<void> {
|
||||
const ids: Id | undefined = await client.getIds(this.publicKey);
|
||||
|
||||
// console.time('group.reload');
|
||||
await Promise.all([
|
||||
this.reloadAlts(client),
|
||||
|
@ -315,22 +317,24 @@ export class Group {
|
|||
await client.program.provider.connection.getMultipleAccountsInfo(oracles);
|
||||
|
||||
const coder = new BorshAccountsCoder(client.program.idl);
|
||||
ais.forEach(async (ai, i) => {
|
||||
const perpMarket = perpMarkets[i];
|
||||
if (!ai)
|
||||
throw new Error(
|
||||
`Undefined ai object in reloadPerpMarketOraclePrices for ${perpMarket.oracle}!`,
|
||||
await Promise.all(
|
||||
Array.from(ais.entries()).map(async ([i, ai]) => {
|
||||
const perpMarket = perpMarkets[i];
|
||||
if (!ai)
|
||||
throw new Error(
|
||||
`Undefined ai object in reloadPerpMarketOraclePrices for ${perpMarket.oracle}!`,
|
||||
);
|
||||
const { price, uiPrice } = await this.decodePriceFromOracleAi(
|
||||
coder,
|
||||
perpMarket.oracle,
|
||||
ai,
|
||||
perpMarket.baseDecimals,
|
||||
client,
|
||||
);
|
||||
const { price, uiPrice } = await this.decodePriceFromOracleAi(
|
||||
coder,
|
||||
perpMarket.oracle,
|
||||
ai,
|
||||
perpMarket.baseDecimals,
|
||||
client,
|
||||
);
|
||||
perpMarket._price = price;
|
||||
perpMarket._uiPrice = uiPrice;
|
||||
});
|
||||
perpMarket._price = price;
|
||||
perpMarket._uiPrice = uiPrice;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
private async decodePriceFromOracleAi(
|
||||
|
|
|
@ -178,8 +178,7 @@ export class MangoClient {
|
|||
public async getGroup(groupPk: PublicKey): Promise<Group> {
|
||||
const groupAccount = await this.program.account.group.fetch(groupPk);
|
||||
const group = Group.from(groupPk, groupAccount);
|
||||
const ids: Id | undefined = await this.getIds(groupPk);
|
||||
await group.reloadAll(this, ids);
|
||||
await group.reloadAll(this);
|
||||
return group;
|
||||
}
|
||||
|
||||
|
|
|
@ -223,7 +223,7 @@ async function main(): Promise<void> {
|
|||
CLUSTER,
|
||||
MANGO_V4_ID[CLUSTER],
|
||||
{
|
||||
idsSource: 'get-program-accounts',
|
||||
idsSource: 'api',
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
@ -8,19 +8,24 @@ export class Id {
|
|||
public publicKey: string,
|
||||
public serum3ProgramId: string,
|
||||
public mangoProgramId: string,
|
||||
public banks: { name: string; publicKey: string }[],
|
||||
public banks: { name: string; publicKey: string; active: boolean }[],
|
||||
public stubOracles: { name: string; publicKey: string }[],
|
||||
public mintInfos: { name: string; publicKey: string }[],
|
||||
public serum3Markets: {
|
||||
name: string;
|
||||
publicKey: string;
|
||||
active: boolean;
|
||||
marketExternal: string;
|
||||
}[],
|
||||
public perpMarkets: { name: string; publicKey: string }[],
|
||||
public perpMarkets: { name: string; publicKey: string; active: boolean }[],
|
||||
) {}
|
||||
|
||||
public getBanks(): PublicKey[] {
|
||||
return Array.from(this.banks.map((bank) => new PublicKey(bank.publicKey)));
|
||||
return Array.from(
|
||||
this.banks
|
||||
.filter((perpMarket) => perpMarket.active)
|
||||
.map((bank) => new PublicKey(bank.publicKey)),
|
||||
);
|
||||
}
|
||||
|
||||
public getStubOracles(): PublicKey[] {
|
||||
|
@ -37,15 +42,17 @@ export class Id {
|
|||
|
||||
public getSerum3Markets(): PublicKey[] {
|
||||
return Array.from(
|
||||
this.serum3Markets.map(
|
||||
(serum3Market) => new PublicKey(serum3Market.publicKey),
|
||||
),
|
||||
this.serum3Markets
|
||||
.filter((perpMarket) => perpMarket.active)
|
||||
.map((serum3Market) => new PublicKey(serum3Market.publicKey)),
|
||||
);
|
||||
}
|
||||
|
||||
public getPerpMarkets(): PublicKey[] {
|
||||
return Array.from(
|
||||
this.perpMarkets.map((perpMarket) => new PublicKey(perpMarket.publicKey)),
|
||||
this.perpMarkets
|
||||
.filter((perpMarket) => perpMarket.active)
|
||||
.map((perpMarket) => new PublicKey(perpMarket.publicKey)),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue