perp settle pnl and fees ix
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
47adfa6540
commit
1bff79f8f9
|
@ -50,7 +50,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';
|
||||
|
@ -2348,6 +2348,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(
|
||||
|
@ -2358,7 +2376,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,
|
||||
|
@ -2379,16 +2397,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(
|
||||
|
@ -2399,8 +2431,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,
|
||||
|
@ -2416,8 +2450,6 @@ export class MangoClient {
|
|||
),
|
||||
)
|
||||
.instruction();
|
||||
|
||||
return await this.sendAndConfirmTransactionForGroup(group, [ix]);
|
||||
}
|
||||
|
||||
public async perpConsumeEvents(
|
||||
|
|
Loading…
Reference in New Issue