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

View File

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