testing
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
357710dc24
commit
f273129b59
|
@ -2,7 +2,7 @@ import { BN } from '@project-serum/anchor';
|
||||||
import { utf8 } from '@project-serum/anchor/dist/cjs/utils/bytes';
|
import { utf8 } from '@project-serum/anchor/dist/cjs/utils/bytes';
|
||||||
import { PublicKey } from '@solana/web3.js';
|
import { PublicKey } from '@solana/web3.js';
|
||||||
import { MangoClient } from '../client';
|
import { MangoClient } from '../client';
|
||||||
import { nativeI80F48ToUi } from '../utils';
|
import { nativeI80F48ToUi, toUiDecimals } from '../utils';
|
||||||
import { Bank } from './bank';
|
import { Bank } from './bank';
|
||||||
import { Group } from './group';
|
import { Group } from './group';
|
||||||
import { HealthCache, HealthCacheDto } from './healthCache';
|
import { HealthCache, HealthCacheDto } from './healthCache';
|
||||||
|
@ -262,7 +262,16 @@ export class MangoAccount {
|
||||||
const maxBorrowNativeWithoutFees = maxBorrowNative.div(
|
const maxBorrowNativeWithoutFees = maxBorrowNative.div(
|
||||||
ONE_I80F48.add(bank.loanOriginationFeeRate),
|
ONE_I80F48.add(bank.loanOriginationFeeRate),
|
||||||
);
|
);
|
||||||
return maxBorrowNativeWithoutFees.add(this.getTokenBalance(bank));
|
return maxBorrowNativeWithoutFees
|
||||||
|
.add(this.getTokenBalance(bank))
|
||||||
|
.mul(I80F48.fromString('0.99'));
|
||||||
|
}
|
||||||
|
|
||||||
|
getMaxWithdrawWithBorrowForTokenUi(group: Group, mintPk: PublicKey): number {
|
||||||
|
return toUiDecimals(
|
||||||
|
this.getMaxWithdrawWithBorrowForToken(group, mintPk),
|
||||||
|
group.getMintDecimals(mintPk),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
import { AnchorProvider, Wallet } from '@project-serum/anchor';
|
import { AnchorProvider, Wallet } from '@project-serum/anchor';
|
||||||
import { Connection, Keypair } from '@solana/web3.js';
|
import { Connection, Keypair } from '@solana/web3.js';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import { Group } from '../accounts/group';
|
||||||
import { I80F48 } from '../accounts/I80F48';
|
import { I80F48 } from '../accounts/I80F48';
|
||||||
import { HealthType } from '../accounts/mangoAccount';
|
import { HealthType, MangoAccount } from '../accounts/mangoAccount';
|
||||||
import { MangoClient } from '../client';
|
import { MangoClient } from '../client';
|
||||||
import { MANGO_V4_ID } from '../constants';
|
import { MANGO_V4_ID } from '../constants';
|
||||||
import { toUiDecimalsForQuote } from '../utils';
|
import { toUiDecimalsForQuote } from '../utils';
|
||||||
|
|
||||||
async function debugUser(client, group, mangoAccount) {
|
async function debugUser(
|
||||||
|
client: MangoClient,
|
||||||
|
group: Group,
|
||||||
|
mangoAccount: MangoAccount,
|
||||||
|
) {
|
||||||
console.log(mangoAccount.toString(group));
|
console.log(mangoAccount.toString(group));
|
||||||
await mangoAccount.reload(client, group);
|
await mangoAccount.reload(client, group);
|
||||||
|
|
||||||
|
@ -64,17 +69,33 @@ async function debugUser(client, group, mangoAccount) {
|
||||||
|
|
||||||
console.log(group.banksMapByName.get('SOL')[0].mint.toBase58());
|
console.log(group.banksMapByName.get('SOL')[0].mint.toBase58());
|
||||||
|
|
||||||
|
async function getMaxWithdrawWithBorrowForTokenUiWrapper(token) {
|
||||||
console.log(
|
console.log(
|
||||||
"mangoAccount.getMaxWithdrawWithBorrowForToken(group, 'SOL') " +
|
`mangoAccount.getMaxWithdrawWithBorrowForTokenUi(group, ${token}) ` +
|
||||||
toUiDecimalsForQuote(
|
mangoAccount.getMaxWithdrawWithBorrowForTokenUi(
|
||||||
(
|
|
||||||
await mangoAccount.getMaxWithdrawWithBorrowForToken(
|
|
||||||
group,
|
group,
|
||||||
group.banksMapByName.get('SOL')[0].mint,
|
group.banksMapByName.get(token)[0].mint,
|
||||||
)
|
|
||||||
).toNumber(),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
try {
|
||||||
|
await client.tokenWithdraw(
|
||||||
|
group,
|
||||||
|
mangoAccount,
|
||||||
|
group.banksMapByName.get(token)[0].mint,
|
||||||
|
mangoAccount.getMaxWithdrawWithBorrowForTokenUi(
|
||||||
|
group,
|
||||||
|
group.banksMapByName.get(token)[0].mint,
|
||||||
|
),
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await getMaxWithdrawWithBorrowForTokenUiWrapper('SOL');
|
||||||
|
await getMaxWithdrawWithBorrowForTokenUiWrapper('MSOL');
|
||||||
|
await getMaxWithdrawWithBorrowForTokenUiWrapper('USDC');
|
||||||
|
await getMaxWithdrawWithBorrowForTokenUiWrapper('BTC');
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
'mangoAccount.simHealthRatioWithTokenPositionChanges ' +
|
'mangoAccount.simHealthRatioWithTokenPositionChanges ' +
|
||||||
|
@ -138,7 +159,7 @@ async function main() {
|
||||||
);
|
);
|
||||||
|
|
||||||
const group = await client.getGroupForCreator(admin.publicKey, 2);
|
const group = await client.getGroupForCreator(admin.publicKey, 2);
|
||||||
console.log(`${group.toString()}`);
|
// console.log(`${group.toString()}`);
|
||||||
|
|
||||||
for (const keypair of [
|
for (const keypair of [
|
||||||
process.env.MB_PAYER_KEYPAIR,
|
process.env.MB_PAYER_KEYPAIR,
|
||||||
|
@ -155,10 +176,15 @@ async function main() {
|
||||||
user.publicKey,
|
user.publicKey,
|
||||||
);
|
);
|
||||||
for (const mangoAccount of mangoAccounts) {
|
for (const mangoAccount of mangoAccounts) {
|
||||||
|
if (
|
||||||
|
'9B8uwqH8FJqLn9kvGPVb5GEksLvmyXb3B8UKCFtRs5cq' ===
|
||||||
|
mangoAccount.publicKey.toBase58()
|
||||||
|
) {
|
||||||
console.log(`MangoAccount ${mangoAccount.publicKey}`);
|
console.log(`MangoAccount ${mangoAccount.publicKey}`);
|
||||||
await debugUser(client, group, mangoAccount);
|
await debugUser(client, group, mangoAccount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue