Merge branch 'main' into dev
This commit is contained in:
commit
1ee1c2e114
|
@ -455,16 +455,6 @@ export class Group {
|
|||
return serum3Market;
|
||||
}
|
||||
|
||||
public getSerum3MarketByPk(pk: PublicKey): Serum3Market | undefined {
|
||||
const serum3Market = Array.from(
|
||||
this.serum3MarketsMapByExternal.values(),
|
||||
).find((serum3Market) => serum3Market.serumMarketExternal.equals(pk));
|
||||
if (!serum3Market) {
|
||||
throw new Error(`No serum3Market found by public key ${pk}!`);
|
||||
}
|
||||
return serum3Market;
|
||||
}
|
||||
|
||||
public getSerum3MarketByExternalMarket(
|
||||
externalMarketPk: PublicKey,
|
||||
): Serum3Market {
|
||||
|
|
|
@ -359,15 +359,10 @@ export class MangoAccount {
|
|||
* The amount of given native token you can withdraw including borrows, considering all existing assets as collateral.
|
||||
* @returns amount of given native token you can borrow, considering all existing assets as collateral, in native token
|
||||
*/
|
||||
getMaxWithdrawWithBorrowForToken(
|
||||
group: Group,
|
||||
mintPk: PublicKey,
|
||||
): I80F48 | undefined {
|
||||
getMaxWithdrawWithBorrowForToken(group: Group, mintPk: PublicKey): I80F48 {
|
||||
const tokenBank: Bank = group.getFirstBankByMint(mintPk);
|
||||
const initHealth = this.getHealth(group, HealthType.init);
|
||||
|
||||
if (!initHealth) return undefined;
|
||||
|
||||
// Case 1:
|
||||
// Cannot withdraw if init health is below 0
|
||||
if (initHealth.lte(ZERO_I80F48())) {
|
||||
|
@ -408,19 +403,12 @@ export class MangoAccount {
|
|||
return maxBorrowNativeWithoutFees.add(existingTokenDeposits);
|
||||
}
|
||||
|
||||
getMaxWithdrawWithBorrowForTokenUi(
|
||||
group: Group,
|
||||
mintPk: PublicKey,
|
||||
): number | undefined {
|
||||
getMaxWithdrawWithBorrowForTokenUi(group: Group, mintPk: PublicKey): number {
|
||||
const maxWithdrawWithBorrow = this.getMaxWithdrawWithBorrowForToken(
|
||||
group,
|
||||
mintPk,
|
||||
);
|
||||
if (maxWithdrawWithBorrow) {
|
||||
return toUiDecimals(maxWithdrawWithBorrow, group.getMintDecimals(mintPk));
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
return toUiDecimals(maxWithdrawWithBorrow, group.getMintDecimals(mintPk));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -438,7 +426,7 @@ export class MangoAccount {
|
|||
sourceMintPk: PublicKey,
|
||||
targetMintPk: PublicKey,
|
||||
priceFactor: number,
|
||||
): number | undefined {
|
||||
): number {
|
||||
if (sourceMintPk.equals(targetMintPk)) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -454,9 +442,7 @@ export class MangoAccount {
|
|||
group.getFirstBankByMint(sourceMintPk).loanOriginationFeeRate,
|
||||
),
|
||||
);
|
||||
if (maxSource) {
|
||||
return toUiDecimals(maxSource, group.getMintDecimals(sourceMintPk));
|
||||
}
|
||||
return toUiDecimals(maxSource, group.getMintDecimals(sourceMintPk));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -474,7 +460,7 @@ export class MangoAccount {
|
|||
mintPk: PublicKey;
|
||||
}[],
|
||||
healthType: HealthType = HealthType.init,
|
||||
): number | undefined {
|
||||
): number {
|
||||
const nativeTokenChanges = uiTokenChanges.map((tokenChange) => {
|
||||
return {
|
||||
nativeTokenAmount: toNativeI80F48(
|
||||
|
|
|
@ -6,6 +6,7 @@ import { MANGO_V4_ID } from './constants';
|
|||
export * from './accounts/bank';
|
||||
export * from './numbers/I80F48';
|
||||
export * from './accounts/mangoAccount';
|
||||
export * from './accounts/perp';
|
||||
export {
|
||||
Serum3Market,
|
||||
Serum3OrderType,
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
import { AnchorProvider, Wallet } from '@project-serum/anchor';
|
||||
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
||||
import fs from 'fs';
|
||||
import { Serum3Side } from '../accounts/serum3';
|
||||
import { MangoClient } from '../client';
|
||||
import { MANGO_V4_ID } from '../constants';
|
||||
|
||||
const MAINNET_ORACLES = new Map([
|
||||
['USDT', '3vxLXJqLqF3JG5TCbYycbKWRBbCJQLxQmBGCkyqEEefL'],
|
||||
['BTC', 'GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU'],
|
||||
['ETH', 'JBu1AL4obBcCMqKBBxhpWCNUt136ijcuMZLFvTP7iWdB'],
|
||||
['soETH', 'JBu1AL4obBcCMqKBBxhpWCNUt136ijcuMZLFvTP7iWdB'],
|
||||
['SOL', 'H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG'],
|
||||
['MSOL', 'E4v1BBgoso9s64TQvmyownAVJbhbEPGyzA3qn4n46qj9'],
|
||||
['MNGO', '79wm3jjcPr6RaNQ4DGvP5KxG1mNd3gEBsg6FsNVFezK4'],
|
||||
]);
|
||||
|
||||
const PAYER_KEYPAIR = process.env.MB_PAYER_KEYPAIR || '';
|
||||
|
||||
//
|
||||
// (untested?) script which closes a mango account cleanly, first closes all positions, withdraws all tokens and then closes it
|
||||
//
|
||||
async function viewUnownedAccount(userKeypairFile: string) {
|
||||
const options = AnchorProvider.defaultOptions();
|
||||
const connection = new Connection(
|
||||
'https://mango.rpcpool.com/0f9acc0d45173b51bf7d7e09c1e5',
|
||||
options,
|
||||
);
|
||||
|
||||
// user
|
||||
// const userWallet = new Wallet(Keypair.generate());
|
||||
// const userProvider = new AnchorProvider(connection, userWallet, options);
|
||||
// console.log(`User ${userWallet.publicKey.toBase58()}`);
|
||||
|
||||
// admin
|
||||
const admin = Keypair.fromSecretKey(
|
||||
Buffer.from(JSON.parse(fs.readFileSync(PAYER_KEYPAIR, 'utf-8'))),
|
||||
);
|
||||
const adminWallet = new Wallet(admin);
|
||||
const adminProvider = new AnchorProvider(connection, adminWallet, options);
|
||||
console.log(`Admin ${admin.publicKey.toBase58()}`);
|
||||
|
||||
const client = await MangoClient.connect(
|
||||
adminProvider,
|
||||
'mainnet-beta',
|
||||
MANGO_V4_ID['mainnet-beta'],
|
||||
);
|
||||
|
||||
// fetch group
|
||||
const group = await client.getGroupForCreator(admin.publicKey, 2);
|
||||
console.log(`Found group ${group.publicKey.toBase58()}`);
|
||||
|
||||
const btcMainnetOracle = new PublicKey(MAINNET_ORACLES.get('BTC')!);
|
||||
console.log(`Registering perp market...`);
|
||||
try {
|
||||
await client.perpCreateMarket(
|
||||
group,
|
||||
btcMainnetOracle,
|
||||
0,
|
||||
'BTC-PERP',
|
||||
0.1,
|
||||
6,
|
||||
0,
|
||||
1,
|
||||
10,
|
||||
0.975,
|
||||
0.95,
|
||||
1.025,
|
||||
1.05,
|
||||
0.012,
|
||||
0.0002,
|
||||
0.0,
|
||||
0.05,
|
||||
0.05,
|
||||
100,
|
||||
false,
|
||||
true,
|
||||
);
|
||||
console.log('done');
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
process.exit();
|
||||
}
|
||||
|
||||
async function main() {
|
||||
await viewUnownedAccount(process.env.MB_USER2_KEYPAIR || '');
|
||||
}
|
||||
|
||||
main();
|
Loading…
Reference in New Issue