Update Ids class so the array filters in the getters work

Also add placeholder values in ids.json so types work; Deprecate ids.json
This commit is contained in:
tjs 2023-09-04 21:04:42 -04:00
parent 2110cf7f55
commit 3715a9a7f2
2 changed files with 40 additions and 11 deletions

View File

@ -13,7 +13,8 @@
"mint": "So11111111111111111111111111111111111111112",
"tokenIndex": 5,
"bankNum": 0,
"active": true
"active": true,
"decimals": 99999
},
{
"name": "USDT",
@ -21,7 +22,8 @@
"mint": "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
"tokenIndex": 1,
"bankNum": 0,
"active": true
"active": true,
"decimals": 99999
},
{
"name": "USDC",
@ -29,7 +31,8 @@
"mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"tokenIndex": 0,
"bankNum": 0,
"active": true
"active": true,
"decimals": 99999
},
{
"name": "BTC",
@ -37,7 +40,8 @@
"mint": "9n4nbM75f5Ui33ZbPYXn59EwSgE8CGsHtAeTH5YFeJ9E",
"tokenIndex": 2,
"bankNum": 0,
"active": true
"active": true,
"decimals": 99999
},
{
"name": "soETH",
@ -45,7 +49,8 @@
"mint": "2FPyTwcZLUg1MDrwsyoP4D6s1tM7hAkHYRjkNb5w6Pxk",
"tokenIndex": 4,
"bankNum": 0,
"active": true
"active": true,
"decimals": 99999
},
{
"name": "ETH",
@ -53,7 +58,8 @@
"mint": "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs",
"tokenIndex": 3,
"bankNum": 0,
"active": true
"active": true,
"decimals": 99999
},
{
"name": "MSOL",
@ -61,7 +67,8 @@
"mint": "mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So",
"tokenIndex": 6,
"bankNum": 0,
"active": true
"active": true,
"decimals": 99999
}
],
"stubOracles": [

View File

@ -8,7 +8,14 @@ export class Id {
public publicKey: string,
public serum3ProgramId: string,
public mangoProgramId: string,
public banks: { name: string; publicKey: string; active: boolean }[],
public banks: {
name: string;
mint: string;
tokenIndex: number;
publicKey: string;
active: boolean;
decimals: number;
}[],
public stubOracles: { name: string; publicKey: string }[],
public mintInfos: { name: string; publicKey: string }[],
public serum3Markets: {
@ -23,7 +30,7 @@ export class Id {
public getBanks(): PublicKey[] {
return Array.from(
this.banks
.filter((perpMarket) => perpMarket.active)
.filter((bank) => bank.active)
.map((bank) => new PublicKey(bank.publicKey)),
);
}
@ -43,11 +50,19 @@ export class Id {
public getSerum3Markets(): PublicKey[] {
return Array.from(
this.serum3Markets
.filter((perpMarket) => perpMarket.active)
.filter((serum3Market) => serum3Market.active)
.map((serum3Market) => new PublicKey(serum3Market.publicKey)),
);
}
public getSerum3ExternalMarkets(): PublicKey[] {
return Array.from(
this.serum3Markets
.filter((serum3Market) => serum3Market.active)
.map((serum3Market) => new PublicKey(serum3Market.marketExternal)),
);
}
public getPerpMarkets(): PublicKey[] {
return Array.from(
this.perpMarkets
@ -56,6 +71,7 @@ export class Id {
);
}
// DEPRECATED
static fromIdsByName(name: string): Id {
const groupConfig = ids.groups.find((id) => id['name'] === name);
if (!groupConfig) throw new Error(`No group config ${name} found in Ids!`);
@ -73,6 +89,7 @@ export class Id {
);
}
// DEPRECATED
static fromIdsByPk(groupPk: PublicKey): Id {
const groupConfig = ids.groups.find(
(id) => id['publicKey'] === groupPk.toString(),
@ -115,6 +132,8 @@ export class Id {
tokenIndex: t.tokenIndex,
bankNum: b.bankNum,
publicKey: b.publicKey,
active: t.active,
decimals: t.decimals,
})),
),
groupConfig.stubOracles.map((s) => ({
@ -126,15 +145,18 @@ export class Id {
mint: t.mint,
tokenIndex: t.tokenIndex,
publicKey: t.mintInfo,
active: t.active,
})),
groupConfig.serum3Markets.map((s) => ({
name: s.name,
publicKey: s.publicKey,
marketExternal: s.marketExternal,
marketExternal: s.serumMarketExternal,
active: s.active,
})),
groupConfig.perpMarkets.map((p) => ({
name: p.name,
publicKey: p.publicKey,
active: p.active,
})),
);
}