Merge branch 'ts-client' into dev

This commit is contained in:
microwavedcola1 2023-03-30 10:37:25 +02:00
commit f89a7b03a1
3 changed files with 69 additions and 11 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@blockworks-foundation/mango-v4",
"version": "0.9.8",
"version": "0.9.12",
"description": "Typescript Client for mango-v4 program.",
"repository": "https://github.com/blockworks-foundation/mango-v4",
"author": {

View File

@ -384,7 +384,7 @@ export class Group {
);
}
private async decodePriceFromOracleAi(
public async decodePriceFromOracleAi(
coder: BorshAccountsCoder<string>,
oracle: PublicKey,
ai: AccountInfo<Buffer>,

View File

@ -51,7 +51,7 @@ import {
TokenEditParams,
buildIxGate,
} from './clientIxParamBuilder';
import { OPENBOOK_PROGRAM_ID } from './constants';
import { OPENBOOK_PROGRAM_ID, RUST_U64_MAX } from './constants';
import { Id } from './ids';
import { IDL, MangoV4 } from './mango_v4';
import { I80F48 } from './numbers/I80F48';
@ -2351,6 +2351,32 @@ export class MangoClient {
.instruction();
}
async perpSettlePnlAndFees(
group: Group,
profitableAccount: MangoAccount,
unprofitableAccount: MangoAccount,
accountToSettleFeesFor: MangoAccount,
settler: MangoAccount,
perpMarketIndex: PerpMarketIndex,
maxSettleAmount?: number,
): Promise<TransactionSignature> {
return await this.sendAndConfirmTransactionForGroup(group, [
await this.perpSettlePnlIx(
group,
profitableAccount,
unprofitableAccount,
settler,
perpMarketIndex,
),
await this.perpSettleFeesIx(
group,
accountToSettleFeesFor,
perpMarketIndex,
maxSettleAmount,
),
]);
}
async perpSettlePnl(
group: Group,
profitableAccount: MangoAccount,
@ -2358,6 +2384,24 @@ export class MangoClient {
settler: MangoAccount,
perpMarketIndex: PerpMarketIndex,
): Promise<TransactionSignature> {
return await this.sendAndConfirmTransactionForGroup(group, [
await this.perpSettlePnlIx(
group,
profitableAccount,
unprofitableAccount,
settler,
perpMarketIndex,
),
]);
}
async perpSettlePnlIx(
group: Group,
profitableAccount: MangoAccount,
unprofitableAccount: MangoAccount,
settler: MangoAccount,
perpMarketIndex: PerpMarketIndex,
): Promise<TransactionInstruction> {
const perpMarket = group.getPerpMarketByMarketIndex(perpMarketIndex);
const healthRemainingAccounts: PublicKey[] =
this.buildHealthRemainingAccounts(
@ -2368,7 +2412,7 @@ export class MangoClient {
[perpMarket],
);
const bank = group.banksMapByTokenIndex.get(0 as TokenIndex)![0];
const ix = await this.program.methods
return await this.program.methods
.perpSettlePnl()
.accounts({
group: group.publicKey,
@ -2389,16 +2433,30 @@ export class MangoClient {
),
)
.instruction();
return await this.sendAndConfirmTransactionForGroup(group, [ix]);
}
async perpSettleFees(
group: Group,
account: MangoAccount,
perpMarketIndex: PerpMarketIndex,
maxSettleAmount: BN,
maxSettleAmount?: number,
): Promise<TransactionSignature> {
return await this.sendAndConfirmTransactionForGroup(group, [
await this.perpSettleFeesIx(
group,
account,
perpMarketIndex,
maxSettleAmount,
),
]);
}
async perpSettleFeesIx(
group: Group,
account: MangoAccount,
perpMarketIndex: PerpMarketIndex,
maxSettleAmount?: number,
): Promise<TransactionInstruction> {
const perpMarket = group.getPerpMarketByMarketIndex(perpMarketIndex);
const healthRemainingAccounts: PublicKey[] =
this.buildHealthRemainingAccounts(
@ -2409,8 +2467,10 @@ export class MangoClient {
[perpMarket],
);
const bank = group.banksMapByTokenIndex.get(0 as TokenIndex)![0];
const ix = await this.program.methods
.perpSettleFees(maxSettleAmount)
return await this.program.methods
.perpSettleFees(
maxSettleAmount ? toNative(maxSettleAmount, 6) : RUST_U64_MAX(),
)
.accounts({
group: group.publicKey,
account: account.publicKey,
@ -2426,8 +2486,6 @@ export class MangoClient {
),
)
.instruction();
return await this.sendAndConfirmTransactionForGroup(group, [ix]);
}
public async perpConsumeEvents(