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