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", "name": "@blockworks-foundation/mango-v4",
"version": "0.9.8", "version": "0.9.12",
"description": "Typescript Client for mango-v4 program.", "description": "Typescript Client for mango-v4 program.",
"repository": "https://github.com/blockworks-foundation/mango-v4", "repository": "https://github.com/blockworks-foundation/mango-v4",
"author": { "author": {

View File

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

View File

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