Skip to content

Commit

Permalink
add updateUserReduceOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
lowkeynicc committed Mar 19, 2024
1 parent 2d32320 commit 240b436
Showing 1 changed file with 43 additions and 9 deletions.
52 changes: 43 additions & 9 deletions sdk/src/driftClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,43 @@ export class DriftClient {
return ix;
}

public async updateUserReduceOnly(
updates: { reduceOnly: boolean; subAccountId: number }[]
): Promise<TransactionSignature> {
const ixs = await Promise.all(
updates.map(async ({ reduceOnly, subAccountId }) => {
return await this.getUpdateUserReduceOnlyIx(reduceOnly, subAccountId);
})
);

const tx = await this.buildTransaction(ixs, this.txParams);

const { txSig } = await this.sendTransaction(tx, [], this.opts);
return txSig;
}

public async getUpdateUserReduceOnlyIx(
reduceOnly: boolean,
subAccountId: number
) {
const ix = await this.program.instruction.updateUserReduceOnly(
subAccountId,
reduceOnly,
{
accounts: {
user: getUserAccountPublicKeySync(
this.program.programId,
this.wallet.publicKey,
subAccountId
),
authority: this.wallet.publicKey,
},
}
);

return ix;
}

public async fetchAllUserAccounts(
includeIdle = true
): Promise<ProgramAccount<UserAccount>[]> {
Expand Down Expand Up @@ -3413,9 +3450,8 @@ export class DriftClient {
subAccountId?: number
): Promise<TransactionInstruction> {
orderParams = getOrderParams(orderParams, { marketType: MarketType.SPOT });
const userAccountPublicKey = await this.getUserAccountPublicKey(
subAccountId
);
const userAccountPublicKey =
await this.getUserAccountPublicKey(subAccountId);

const remainingAccounts = this.getRemainingAccounts({
userAccounts: [this.getUserAccount(subAccountId)],
Expand Down Expand Up @@ -4535,9 +4571,8 @@ export class DriftClient {
/* Settle PnL after fill if requested */
let settlePnlTx: Transaction;
if (settlePnl && isVariant(orderParams.marketType, 'perp')) {
const userAccountPublicKey = await this.getUserAccountPublicKey(
subAccountId
);
const userAccountPublicKey =
await this.getUserAccountPublicKey(subAccountId);

const settlePnlIx = await this.settlePNLIx(
userAccountPublicKey,
Expand Down Expand Up @@ -6074,9 +6109,8 @@ export class DriftClient {
}

if (initializeStakeAccount) {
const initializeIx = await this.getInitializeInsuranceFundStakeIx(
marketIndex
);
const initializeIx =
await this.getInitializeInsuranceFundStakeIx(marketIndex);
addIfStakeIxs.push(initializeIx);
}

Expand Down

0 comments on commit 240b436

Please sign in to comment.