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,
|
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';
|
||||||
|
@ -2348,6 +2348,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(
|
||||||
|
@ -2358,7 +2376,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,
|
||||||
|
@ -2379,16 +2397,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(
|
||||||
|
@ -2399,8 +2431,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,
|
||||||
|
@ -2416,8 +2450,6 @@ export class MangoClient {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.instruction();
|
.instruction();
|
||||||
|
|
||||||
return await this.sendAndConfirmTransactionForGroup(group, [ix]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async perpConsumeEvents(
|
public async perpConsumeEvents(
|
||||||
|
|
Loading…
Reference in New Issue