consistent naming to get serum markets

This commit is contained in:
tjs 2022-09-25 21:11:38 -04:00
parent 92a33a0bf5
commit 3b1ea91903
6 changed files with 21 additions and 13 deletions

View File

@ -381,13 +381,19 @@ export class Group {
return I80F48.fromNumber(totalAmount);
}
public findSerum3Market(marketIndex: number): Serum3Market | undefined {
public getSerum3MarketByPk(pk: PublicKey): Serum3Market | undefined {
return Array.from(this.serum3MarketsMapByExternal.values()).find(
(serum3Market) => serum3Market.serumMarketExternal.equals(pk),
);
}
public getSerum3MarketByIndex(marketIndex: number): Serum3Market | undefined {
return Array.from(this.serum3MarketsMapByExternal.values()).find(
(serum3Market) => serum3Market.marketIndex === marketIndex,
);
}
public findSerum3MarketByName(name: string): Serum3Market | undefined {
public getSerum3MarketByName(name: string): Serum3Market | undefined {
return Array.from(this.serum3MarketsMapByExternal.values()).find(
(serum3Market) => serum3Market.name === name,
);

View File

@ -61,7 +61,7 @@ async function main() {
for (const serum3Account of mangoAccount.serum3Active()) {
let orders = await client.getSerum3Orders(
group,
group.findSerum3Market(serum3Account.marketIndex)!.name,
group.getSerum3MarketByIndex(serum3Account.marketIndex)!.name,
);
for (const order of orders) {
console.log(
@ -80,12 +80,12 @@ async function main() {
await client.serum3SettleFunds(
group,
mangoAccount,
group.findSerum3Market(serum3Account.marketIndex)!.name,
group.getSerum3MarketByIndex(serum3Account.marketIndex)!.name,
);
await client.serum3CloseOpenOrders(
group,
mangoAccount,
group.findSerum3Market(serum3Account.marketIndex)!.name,
group.getSerum3MarketByIndex(serum3Account.marketIndex)!.name,
);
}

View File

@ -61,7 +61,7 @@ async function main() {
for (const serum3Account of mangoAccount.serum3Active()) {
let orders = await client.getSerum3Orders(
group,
group.findSerum3Market(serum3Account.marketIndex)!.name,
group.getSerum3MarketByIndex(serum3Account.marketIndex)!.name,
);
for (const order of orders) {
console.log(
@ -80,12 +80,12 @@ async function main() {
await client.serum3SettleFunds(
group,
mangoAccount,
group.findSerum3Market(serum3Account.marketIndex)!.name,
group.getSerum3MarketByIndex(serum3Account.marketIndex)!.name,
);
await client.serum3CloseOpenOrders(
group,
mangoAccount,
group.findSerum3Market(serum3Account.marketIndex)!.name,
group.getSerum3MarketByIndex(serum3Account.marketIndex)!.name,
);
}

View File

@ -49,7 +49,7 @@ async function closeUserAccount(userKeypairFile: string) {
for (const serum3Account of mangoAccount.serum3Active()) {
let orders = await client.getSerum3Orders(
group,
group.findSerum3Market(serum3Account.marketIndex)!.name,
group.getSerum3MarketByIndex(serum3Account.marketIndex)!.name,
);
for (const order of orders) {
console.log(
@ -69,12 +69,12 @@ async function closeUserAccount(userKeypairFile: string) {
await client.serum3SettleFunds(
group,
mangoAccount,
group.findSerum3Market(serum3Account.marketIndex)!.name,
group.getSerum3MarketByIndex(serum3Account.marketIndex)!.name,
);
await client.serum3CloseOpenOrders(
group,
mangoAccount,
group.findSerum3Market(serum3Account.marketIndex)!.name,
group.getSerum3MarketByIndex(serum3Account.marketIndex)!.name,
);
}

View File

@ -130,7 +130,7 @@ async function main() {
`...created mangoAccount ${mangoAccount.publicKey} for ${name}`,
);
const market = group.findSerum3MarketByName('SOL/USDC')!;
const market = group.getSerum3MarketByIndexByName('SOL/USDC')!;
const sellMint = new PublicKey(MAINNET_MINTS.get('USDC')!);
const buyMint = new PublicKey(MAINNET_MINTS.get('SOL')!);

View File

@ -48,7 +48,9 @@ async function main() {
let accounts = await client.getMangoAccountsForOwner(group, admin.publicKey);
for (let account of accounts) {
for (let serumOrders of account.serum3Active()) {
const serumMarket = group.findSerum3Market(serumOrders.marketIndex)!;
const serumMarket = group.getSerum3MarketByIndex(
serumOrders.marketIndex,
)!;
const serumExternal = serumMarket.serumMarketExternal;
console.log(
`closing serum orders on: ${account} for market ${serumMarket.name}`,