make market members private and added getters

This commit is contained in:
Sayantan Karmakar 2022-06-06 13:13:56 +05:30
parent c7d06336c7
commit b844766d2b
3 changed files with 44 additions and 14 deletions

View File

@ -6,7 +6,6 @@ import {
ParsedAccountData,
PublicKey,
} from "@solana/web3.js";
import BN from "bn.js";
import { Dex, DexMarket, FileKeypair } from "../src";
const main = async () => {
@ -44,8 +43,6 @@ const main = async () => {
const market = await dex.initDexMarket(owner.keypair, baseCoin, quoteCoin, {
lotSize: 1e-3,
tickSize: 1e-2,
feeRate: 10,
quoteDustThreshold: new BN(100),
});
console.log(

View File

@ -32,7 +32,7 @@ export type MarketParams = {
* @param baseGeckoSymbol The symbol used by CoinGecko for the base coin.
* @param quoteGeckoSymbol The symbol used by CoinGecko for the quote coin.
*/
type MarketMakerOpts = {
export type MarketMakerOpts = {
// unref: boolean;
durationInSecs: number;
orderCount: number;

View File

@ -38,15 +38,15 @@ export interface MarketAccounts {
* A wrapper class around `serum-ts`'s `Market` class.
*/
export class DexMarket {
public address: PublicKey;
private _address: PublicKey;
public serumMarket: Market;
private _serumMarket: Market;
public baseCoin: Coin;
private _baseCoin: Coin;
public quoteCoin: Coin;
private _quoteCoin: Coin;
public marketSymbol: string;
private _marketSymbol: string;
constructor(
address: PublicKey,
@ -54,11 +54,31 @@ export class DexMarket {
baseCoin: Coin,
quoteCoin: Coin,
) {
this.address = address;
this.serumMarket = serumMarket;
this.baseCoin = baseCoin;
this.quoteCoin = quoteCoin;
this.marketSymbol = `${baseCoin.symbol}/${quoteCoin.symbol}`;
this._address = address;
this._serumMarket = serumMarket;
this._baseCoin = baseCoin;
this._quoteCoin = quoteCoin;
this._marketSymbol = `${baseCoin.symbol}/${quoteCoin.symbol}`;
}
public get address() {
return this._address;
}
public get serumMarket() {
return this._serumMarket;
}
public get baseCoin() {
return this._baseCoin;
}
public get quoteCoin() {
return this._quoteCoin;
}
public get marketSymbol() {
return this._marketSymbol;
}
/**
@ -427,6 +447,19 @@ export class DexMarket {
return txSig;
}
static async getOrdersForOwner(
owner: Keypair,
serumMarket: SerumMarket,
connection: Connection,
): Promise<Order[]> {
const orders = await serumMarket.loadOrdersForOwner(
connection,
owner.publicKey,
);
return orders;
}
static async getOrCreateOpenOrderAccount(
owner: Keypair,
serumMarket: SerumMarket,