Revert "remove unused"

This reverts commit 6d008d2cea.
This commit is contained in:
microwavedcola1 2022-04-07 15:06:26 +02:00
parent 6d008d2cea
commit 04977dd742
2 changed files with 12 additions and 73 deletions

View File

@ -7,9 +7,12 @@ export const MANGO_V4_ID = new PublicKey(
);
export class MangoClient {
constructor(public program: Program<MangoV4>) {}
constructor(public program: Program<MangoV4>, public devnet?: boolean) {}
static async connect(provider: Provider): Promise<MangoClient> {
static async connect(
provider: Provider,
devnet?: boolean,
): Promise<MangoClient> {
// TODO: use IDL on chain or in repository? decide...
// Alternatively we could fetch IDL from chain.
// const idl = await Program.fetchIdl(MANGO_V4_ID, provider);
@ -41,6 +44,7 @@ export class MangoClient {
return new MangoClient(
new Program<MangoV4>(idl as MangoV4, MANGO_V4_ID, provider),
devnet,
);
}
}

View File

@ -55,7 +55,7 @@ async function main() {
const adminWallet = new Wallet(admin);
console.log(`Admin ${adminWallet.publicKey.toBase58()}`);
const adminProvider = new Provider(connection, adminWallet, options);
const adminClient = await MangoClient.connect(adminProvider);
const adminClient = await MangoClient.connect(adminProvider, true);
const payer = Keypair.fromSecretKey(
Buffer.from(
@ -63,7 +63,6 @@ async function main() {
),
);
console.log(`Payer ${payer.publicKey.toBase58()}`);
//
// Find existing or create a new group
//
@ -148,7 +147,7 @@ async function main() {
);
const userWallet = new Wallet(user);
const userProvider = new Provider(connection, userWallet, options);
const userClient = await MangoClient.connect(userProvider);
const userClient = await MangoClient.connect(userProvider, true);
console.log(`User ${userWallet.publicKey.toBase58()}`);
//
@ -325,17 +324,7 @@ async function main() {
],
serumProgramId,
);
let ordersForOwner = await serum3MarketExternal.loadOrdersForOwner(
userClient.program.provider.connection,
group.publicKey,
);
for (const order of ordersForOwner) {
console.log(
`- Existing serum3 order orderId ${order.orderId}, side ${order.side}, price ${order.price}, size ${order.size}`,
);
}
let clientOrderId = Date.now();
const clientOrderId = Date.now();
await serum3PlaceOrder(
userClient,
group.publicKey,
@ -367,68 +356,14 @@ async function main() {
10,
);
ordersForOwner = await serum3MarketExternal.loadOrdersForOwner(
const ordersForOwner = await serum3MarketExternal.loadOrdersForOwner(
userClient.program.provider.connection,
group.publicKey,
);
let orderJustPlaced = ordersForOwner.filter(
const orderJustPlaced = ordersForOwner.filter(
(order) => order.clientId?.toNumber() === clientOrderId,
)[0];
console.log(
`- New Serum3 order orderId ${orderJustPlaced.orderId}, side ${orderJustPlaced.side}, price ${orderJustPlaced.price}, size ${orderJustPlaced.size}`,
);
clientOrderId = Date.now();
await serum3PlaceOrder(
userClient,
group.publicKey,
mangoAccount.publicKey,
user.publicKey,
mangoAccount.serum3[0].openOrders,
serum3Market.publicKey,
serumProgramId,
serumMarketExternalPk,
serum3MarketExternal.bidsAddress,
serum3MarketExternal.asksAddress,
serum3MarketExternal.decoded.eventQueue,
serum3MarketExternal.decoded.requestQueue,
serum3MarketExternal.decoded.baseVault,
serum3MarketExternal.decoded.quoteVault,
serum3MarketExternalVaultSigner,
usdcBank.publicKey,
usdcBank.vault,
btcBank.publicKey,
btcBank.vault,
healthRemainingAccounts,
Serum3Side.ask,
40000,
6,
1000000,
Serum3SelfTradeBehavior.decrementTake,
Serum3OrderType.limit,
clientOrderId,
10,
);
ordersForOwner = await serum3MarketExternal.loadOrdersForOwner(
userClient.program.provider.connection,
group.publicKey,
);
orderJustPlaced = ordersForOwner.filter(
(order) => order.clientId?.toNumber() === clientOrderId,
)[0];
console.log(
`- New Serum3 order orderId ${orderJustPlaced.orderId}, side ${orderJustPlaced.side}, price ${orderJustPlaced.price}, size ${orderJustPlaced.size}`,
);
ordersForOwner = await serum3MarketExternal.loadOrdersForOwner(
userClient.program.provider.connection,
group.publicKey,
);
for (const order of ordersForOwner) {
console.log(
`- serum3 order orderId ${order.orderId}, side ${orderJustPlaced.side}, price ${order.price}, size ${order.size}`,
);
}
console.log(`- Serum3 order orderId ${orderJustPlaced.orderId}`);
process.exit(0);
}