Merge branch 'main' into dev
This commit is contained in:
commit
4d61bb76a4
|
@ -5,7 +5,7 @@ import Big from 'big.js';
|
|||
import { MangoClient } from '../client';
|
||||
import { I80F48, I80F48Dto, ZERO_I80F48 } from '../numbers/I80F48';
|
||||
import { Modify } from '../types';
|
||||
import { As, toNative, toUiDecimals, U64_MAX_BN } from '../utils';
|
||||
import { As, U64_MAX_BN, toNative, toUiDecimals } from '../utils';
|
||||
import {
|
||||
OracleConfig,
|
||||
OracleConfigDto,
|
||||
|
@ -242,6 +242,15 @@ export class PerpMarket {
|
|||
return this.priceLotsToUiConverter;
|
||||
}
|
||||
|
||||
insidePriceLimit(side: PerpOrderSide, orderPrice: number): boolean {
|
||||
return (
|
||||
(side === PerpOrderSide.bid &&
|
||||
orderPrice <= this.maintLiabWeight.toNumber() * this.uiPrice) ||
|
||||
(side === PerpOrderSide.ask &&
|
||||
orderPrice >= this.maintAssetWeight.toNumber() * this.uiPrice)
|
||||
);
|
||||
}
|
||||
|
||||
public async loadAsks(
|
||||
client: MangoClient,
|
||||
forceReload = false,
|
||||
|
|
|
@ -17,7 +17,7 @@ const PAYER_KEYPAIR =
|
|||
const USER_KEYPAIR =
|
||||
process.env.USER_KEYPAIR_OVERRIDE || process.env.MB_PAYER_KEYPAIR;
|
||||
const GROUP_NUM = Number(process.env.GROUP_NUM || 0);
|
||||
const MANGO_ACCOUNT = process.env.MANGO_ACCOUNT_PK;
|
||||
const MANGO_ACCOUNT_PK = process.env.MANGO_ACCOUNT_PK;
|
||||
const CLUSTER: Cluster =
|
||||
(process.env.CLUSTER_OVERRIDE as Cluster) || 'mainnet-beta';
|
||||
|
||||
|
@ -257,8 +257,8 @@ async function main(): Promise<void> {
|
|||
|
||||
for (const mangoAccount of mangoAccounts) {
|
||||
if (
|
||||
!MANGO_ACCOUNT ||
|
||||
mangoAccount.publicKey.equals(new PublicKey(MANGO_ACCOUNT))
|
||||
!MANGO_ACCOUNT_PK ||
|
||||
mangoAccount.publicKey.equals(new PublicKey(MANGO_ACCOUNT_PK))
|
||||
) {
|
||||
console.log();
|
||||
console.log(`MangoAccount ${mangoAccount.publicKey}`);
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
import { AnchorProvider, Wallet } from '@project-serum/anchor';
|
||||
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
||||
import * as dotenv from 'dotenv';
|
||||
import fs from 'fs';
|
||||
import { MangoClient } from '../client';
|
||||
import { MANGO_V4_ID } from '../constants';
|
||||
dotenv.config();
|
||||
|
||||
//
|
||||
// (untested?) script which closes a mango account cleanly, first closes all positions, withdraws all tokens and then closes it
|
||||
//
|
||||
async function addSpotMarket() {
|
||||
const options = AnchorProvider.defaultOptions();
|
||||
const connection = new Connection(process.env.MB_CLUSTER_URL!, options);
|
||||
|
||||
// admin
|
||||
const admin = Keypair.fromSecretKey(
|
||||
Buffer.from(
|
||||
JSON.parse(fs.readFileSync(process.env.MB_PAYER_KEYPAIR!, 'utf-8')),
|
||||
),
|
||||
);
|
||||
const adminWallet = new Wallet(admin);
|
||||
const adminProvider = new AnchorProvider(connection, adminWallet, options);
|
||||
const client = await MangoClient.connect(
|
||||
adminProvider,
|
||||
'mainnet-beta',
|
||||
MANGO_V4_ID['mainnet-beta'],
|
||||
);
|
||||
console.log(`Admin ${admin.publicKey.toBase58()}`);
|
||||
|
||||
// fetch group
|
||||
const groupPk = '78b8f4cGCwmZ9ysPFMWLaLTkkaYnUjwMJYStWe5RTSSX';
|
||||
const group = await client.getGroup(new PublicKey(groupPk));
|
||||
console.log(`Found group ${group.publicKey.toBase58()}`);
|
||||
|
||||
const eth_openbook_mkt = 'FZxi3yWkE5mMjyaZj6utmYL54QQYfMCKMcLaQZq4UwnA';
|
||||
const eth_mint = '7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs';
|
||||
const usdc_mint = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';
|
||||
|
||||
const signature = await client.serum3RegisterMarket(
|
||||
group,
|
||||
new PublicKey(eth_openbook_mkt),
|
||||
group.getFirstBankByMint(new PublicKey(eth_mint)),
|
||||
group.getFirstBankByMint(new PublicKey(usdc_mint)),
|
||||
1, // market index
|
||||
'ETH/USDC',
|
||||
);
|
||||
|
||||
console.log('Tx Successful:', signature);
|
||||
|
||||
process.exit();
|
||||
}
|
||||
|
||||
async function main() {
|
||||
await addSpotMarket();
|
||||
}
|
||||
|
||||
main();
|
|
@ -0,0 +1,54 @@
|
|||
import { AnchorProvider, Wallet } from '@project-serum/anchor';
|
||||
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
||||
import fs from 'fs';
|
||||
import { Group } from '../accounts/group';
|
||||
import { MangoClient } from '../client';
|
||||
import { MANGO_V4_ID } from '../constants';
|
||||
|
||||
const GROUP_NUM = Number(process.env.GROUP_NUM || 0);
|
||||
const MANGO_ACCOUNT_PK = process.env.MANGO_ACCOUNT_PK;
|
||||
const { MB_CLUSTER_URL, MB_PAYER_KEYPAIR, MB_USER_KEYPAIR, MB_USER4_KEYPAIR } =
|
||||
process.env;
|
||||
|
||||
async function buildUserClient(
|
||||
userKeypair: string,
|
||||
): Promise<[MangoClient, Group, Keypair]> {
|
||||
const options = AnchorProvider.defaultOptions();
|
||||
const connection = new Connection(MB_CLUSTER_URL!, options);
|
||||
|
||||
const user = Keypair.fromSecretKey(
|
||||
Buffer.from(JSON.parse(fs.readFileSync(userKeypair, 'utf-8'))),
|
||||
);
|
||||
const userWallet = new Wallet(user);
|
||||
const userProvider = new AnchorProvider(connection, userWallet, options);
|
||||
|
||||
const client = await MangoClient.connect(
|
||||
userProvider,
|
||||
'mainnet-beta',
|
||||
MANGO_V4_ID['mainnet-beta'],
|
||||
);
|
||||
|
||||
const admin = Keypair.fromSecretKey(
|
||||
Buffer.from(JSON.parse(fs.readFileSync(MB_PAYER_KEYPAIR!, 'utf-8'))),
|
||||
);
|
||||
console.log(`Admin ${admin.publicKey.toBase58()}`);
|
||||
const group = await client.getGroupForCreator(admin.publicKey, GROUP_NUM);
|
||||
return [client, group, user];
|
||||
}
|
||||
|
||||
async function forceCloseUserAccount() {
|
||||
const result = await buildUserClient(MB_PAYER_KEYPAIR!);
|
||||
const client = result[0];
|
||||
const group = result[1];
|
||||
const mangoAccount = await client.getMangoAccount(
|
||||
new PublicKey(MANGO_ACCOUNT_PK!),
|
||||
);
|
||||
await client.closeMangoAccount(group, mangoAccount, true);
|
||||
process.exit();
|
||||
}
|
||||
|
||||
async function main() {
|
||||
await forceCloseUserAccount();
|
||||
}
|
||||
|
||||
main();
|
Loading…
Reference in New Issue