Merge branch 'main' into dev

This commit is contained in:
microwavedcola1 2022-08-31 11:35:19 +02:00
commit 4a1865be6c
4 changed files with 49 additions and 55 deletions

View File

@ -304,15 +304,11 @@ export class Group {
/**
*
* @param client
* @param mintPk
* @returns sum of native balances of vaults for all banks for a token (fetched from vaultAmountsMap cache)
*/
public async getTokenVaultBalanceByMint(
client: MangoClient,
mintPk: PublicKey,
): Promise<I80F48> {
const banks = this.banksMapByMint.get(mintPk.toString());
public getTokenVaultBalanceByMint(mintPk: PublicKey): I80F48 {
const banks = this.banksMapByMint.get(mintPk.toBase58());
let amount = 0;
for (const bank of banks) {
amount += this.vaultAmountsMap.get(bank.vault.toBase58());
@ -322,16 +318,12 @@ export class Group {
/**
*
* @param client
* @param mintPk
* @returns sum of ui balances of vaults for all banks for a token
*/
public async getTokenVaultBalanceByMintUi(
client: MangoClient,
mintPk: PublicKey,
): Promise<number> {
public getTokenVaultBalanceByMintUi(mintPk: PublicKey): number {
return toUiDecimals(
await this.getTokenVaultBalanceByMint(client, mintPk),
this.getTokenVaultBalanceByMint(mintPk),
this.getMintDecimals(mintPk),
);
}

View File

@ -76,13 +76,17 @@ export class MangoAccount {
this.perps = perps.map((dto) => PerpPosition.from(dto));
}
async reload(client: MangoClient, group: Group) {
async reload(client: MangoClient, group: Group): Promise<MangoAccount> {
Object.assign(this, await client.getMangoAccount(this));
await this.reloadAccountData(client, group);
return await this.reloadAccountData(client, group);
}
async reloadAccountData(client: MangoClient, group: Group) {
async reloadAccountData(
client: MangoClient,
group: Group,
): Promise<MangoAccount> {
this.accountData = await client.computeAccountData(group, this);
return this;
}
findToken(tokenIndex: number): TokenPosition | undefined {

View File

@ -685,31 +685,27 @@ export class MangoClient {
// Use our custom simulate fn in utils/anchor.ts so signing the tx is not required
this.program.provider.simulate = simulate;
let res;
try {
res = await this.program.methods
.computeAccountData()
.accounts({
group: group.publicKey,
account: mangoAccount.publicKey,
})
.remainingAccounts(
healthRemainingAccounts.map(
(pk) =>
({
pubkey: pk,
isWritable: false,
isSigner: false,
} as AccountMeta),
),
)
.simulate();
} catch (error) {
console.log(error);
}
const res = await this.program.methods
.computeAccountData()
.accounts({
group: group.publicKey,
account: mangoAccount.publicKey,
})
.remainingAccounts(
healthRemainingAccounts.map(
(pk) =>
({
pubkey: pk,
isWritable: false,
isSigner: false,
} as AccountMeta),
),
)
.simulate();
return MangoAccountData.from(
res.events.find((event) => (event.name = 'MangoAccountData')).data as any,
res?.events.find((event) => (event.name = 'MangoAccountData'))
.data as any,
);
}

View File

@ -31,25 +31,27 @@ export async function sendTransaction(
}
}
const status =
let status: any;
if (
transaction.recentBlockhash != null &&
transaction.lastValidBlockHeight != null
? (
await connection.confirmTransaction(
{
signature: signature,
blockhash: transaction.recentBlockhash,
lastValidBlockHeight: transaction.lastValidBlockHeight,
},
// options && options.commitment,
)
).value
: (
await connection.confirmTransaction(
signature,
// options && options.commitment,
)
).value;
) {
console.log('confirming via blockhash');
status = (
await connection.confirmTransaction(
{
signature: signature,
blockhash: transaction.recentBlockhash,
lastValidBlockHeight: transaction.lastValidBlockHeight,
},
'processed',
)
).value;
} else {
console.log('confirming via timeout');
status = (await connection.confirmTransaction(signature, 'processed'))
.value;
}
if (status.err) {
throw new MangoError({