Merge branch 'main' into dev
This commit is contained in:
commit
5e617feb8a
|
@ -200,6 +200,23 @@ export class HealthCache {
|
|||
const sourceBank: Bank = group.getFirstBankByMint(sourceMintPk);
|
||||
const targetBank: Bank = group.getFirstBankByMint(targetMintPk);
|
||||
|
||||
if (sourceMintPk.equals(targetMintPk)) {
|
||||
return ZERO_I80F48;
|
||||
}
|
||||
|
||||
if (!sourceBank.price || sourceBank.price.lte(ZERO_I80F48)) {
|
||||
return ZERO_I80F48;
|
||||
}
|
||||
|
||||
if (
|
||||
sourceBank.initLiabWeight
|
||||
.sub(targetBank.initAssetWeight)
|
||||
.abs()
|
||||
.lte(ZERO_I80F48)
|
||||
) {
|
||||
return ZERO_I80F48;
|
||||
}
|
||||
|
||||
// The health_ratio is a nonlinear based on swap amount.
|
||||
// For large swap amounts the slope is guaranteed to be negative, but small amounts
|
||||
// can have positive slope (e.g. using source deposits to pay back target borrows).
|
||||
|
|
|
@ -541,14 +541,22 @@ export class MangoClient {
|
|||
accountNumber?: number,
|
||||
name?: string,
|
||||
): Promise<TransactionSignature> {
|
||||
return await this.program.methods
|
||||
const transaction = await this.program.methods
|
||||
.accountCreate(accountNumber ?? 0, 8, 0, 0, 0, name ?? '')
|
||||
.accounts({
|
||||
group: group.publicKey,
|
||||
owner: (this.program.provider as AnchorProvider).wallet.publicKey,
|
||||
payer: (this.program.provider as AnchorProvider).wallet.publicKey,
|
||||
})
|
||||
.rpc({ skipPreflight: true });
|
||||
.transaction();
|
||||
|
||||
return await sendTransaction(
|
||||
this.program.provider as AnchorProvider,
|
||||
transaction,
|
||||
{
|
||||
postSendTxCallback: this.postSendTxCallback,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
public async expandMangoAccount(
|
||||
|
@ -576,14 +584,22 @@ export class MangoClient {
|
|||
name?: string,
|
||||
delegate?: PublicKey,
|
||||
): Promise<TransactionSignature> {
|
||||
return await this.program.methods
|
||||
const transaction = await this.program.methods
|
||||
.accountEdit(name ?? null, delegate ?? null)
|
||||
.accounts({
|
||||
group: group.publicKey,
|
||||
account: mangoAccount.publicKey,
|
||||
owner: (this.program.provider as AnchorProvider).wallet.publicKey,
|
||||
})
|
||||
.rpc({ skipPreflight: true });
|
||||
.transaction();
|
||||
|
||||
return await sendTransaction(
|
||||
this.program.provider as AnchorProvider,
|
||||
transaction,
|
||||
{
|
||||
postSendTxCallback: this.postSendTxCallback,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
public async getMangoAccount(mangoAccount: MangoAccount) {
|
||||
|
@ -768,7 +784,7 @@ export class MangoClient {
|
|||
[bank],
|
||||
);
|
||||
|
||||
return await this.program.methods
|
||||
const transaction = await this.program.methods
|
||||
.tokenDeposit(new BN(nativeAmount))
|
||||
.accounts({
|
||||
group: group.publicKey,
|
||||
|
@ -787,7 +803,16 @@ export class MangoClient {
|
|||
.preInstructions(preInstructions)
|
||||
.postInstructions(postInstructions)
|
||||
.signers(additionalSigners)
|
||||
.rpc({ skipPreflight: true });
|
||||
.transaction();
|
||||
|
||||
return await sendTransaction(
|
||||
this.program.provider as AnchorProvider,
|
||||
transaction,
|
||||
{
|
||||
additionalSigners,
|
||||
postSendTxCallback: this.postSendTxCallback,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
public async tokenWithdraw(
|
||||
|
|
|
@ -2,7 +2,7 @@ import { AnchorProvider, Wallet } from '@project-serum/anchor';
|
|||
import { coder } from '@project-serum/anchor/dist/cjs/spl/token';
|
||||
import { Connection, Keypair } from '@solana/web3.js';
|
||||
import fs from 'fs';
|
||||
import { ZERO_I80F48 } from '../accounts/I80F48';
|
||||
import { I80F48, ZERO_I80F48 } from '../accounts/I80F48';
|
||||
import { MangoClient } from '../client';
|
||||
import { MANGO_V4_ID } from '../constants';
|
||||
|
||||
|
@ -69,6 +69,24 @@ async function main() {
|
|||
for (const bank of await Array.from(banksMapUsingTokenIndex.values()).sort(
|
||||
(a, b) => a.tokenIndex - b.tokenIndex,
|
||||
)) {
|
||||
const vault = I80F48.fromNumber(
|
||||
coder()
|
||||
.accounts.decode(
|
||||
'token',
|
||||
await (
|
||||
await client.program.provider.connection.getAccountInfo(bank.vault)
|
||||
).data,
|
||||
)
|
||||
.amount.toNumber(),
|
||||
);
|
||||
|
||||
const error = vault.sub(
|
||||
(bank as any).indexedDepositsByMangoAccounts
|
||||
.sub((bank as any).indexedBorrowsByMangoAccounts)
|
||||
.add(bank.collectedFeesNative)
|
||||
.add(bank.dust),
|
||||
);
|
||||
|
||||
let res = `${bank.name}`;
|
||||
res =
|
||||
res +
|
||||
|
@ -76,6 +94,7 @@ async function main() {
|
|||
`\n ${'bank'.padEnd(40)} ${bank.publicKey}` +
|
||||
`\n ${'vault'.padEnd(40)} ${bank.vault}` +
|
||||
`\n ${'mint'.padEnd(40)} ${bank.mint}` +
|
||||
`\n ${'error'.padEnd(40)} ${error}` +
|
||||
`\n ${'collectedFeesNative'.padEnd(40)} ${bank.collectedFeesNative}` +
|
||||
`\n ${'dust'.padEnd(40)} ${bank.dust}` +
|
||||
`\n ${'deposits'.padEnd(40)} ${bank.indexedDeposits.mul(
|
||||
|
|
|
@ -91,6 +91,7 @@ async function debugUser(client, group, mangoAccount) {
|
|||
);
|
||||
}
|
||||
getMaxSourceForTokenSwapWrapper('SOL', 'BTC');
|
||||
getMaxSourceForTokenSwapWrapper('USDC', 'USDC');
|
||||
}
|
||||
|
||||
async function main() {
|
||||
|
|
|
@ -12,6 +12,9 @@ export async function sendTransaction(
|
|||
await connection.getLatestBlockhash(opts.preflightCommitment)
|
||||
).blockhash;
|
||||
transaction.feePayer = payer.publicKey;
|
||||
if (opts.additionalSigners?.length > 0) {
|
||||
transaction.partialSign(...opts.additionalSigners);
|
||||
}
|
||||
|
||||
await payer.signTransaction(transaction);
|
||||
const rawTransaction = transaction.serialize();
|
||||
|
|
Loading…
Reference in New Issue