Skip to content

Commit 365bc7d

Browse files
committed
fix: broken tests and PR cleanup
1 parent 6e49e0c commit 365bc7d

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

sdk/src/driftClient.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4279,19 +4279,21 @@ export class DriftClient {
42794279
perpMarketIndex: number,
42804280
subAccountId?: number,
42814281
txParams?: TxParams,
4282-
trySettle?: boolean
4282+
trySettle?: boolean,
4283+
noBuffer?: boolean
42834284
): Promise<TransactionSignature> {
42844285
const ixs = [];
42854286
const tokenAmountDeposited =
42864287
this.getIsolatedPerpPositionTokenAmount(perpMarketIndex);
42874288
const transferIx = await this.getTransferIsolatedPerpPositionDepositIx(
42884289
amount,
42894290
perpMarketIndex,
4290-
subAccountId
4291+
subAccountId,
4292+
noBuffer
42914293
);
42924294

42934295
const needsToSettle =
4294-
amount.gt(tokenAmountDeposited) || amount.eq(MIN_I64) || trySettle;
4296+
amount.lt(tokenAmountDeposited.neg()) || amount.eq(MIN_I64) || trySettle;
42954297
if (needsToSettle) {
42964298
const settleIx = await this.settleMultiplePNLsIx(
42974299
await getUserAccountPublicKey(
@@ -4320,7 +4322,8 @@ export class DriftClient {
43204322
amount: BN,
43214323
perpMarketIndex: number,
43224324
subAccountId?: number,
4323-
noAmountBuffer?: boolean
4325+
noAmountBuffer?: boolean,
4326+
signingAuthority?: PublicKey
43244327
): Promise<TransactionInstruction> {
43254328
const userAccountPublicKey = await getUserAccountPublicKey(
43264329
this.program.programId,
@@ -4337,7 +4340,7 @@ export class DriftClient {
43374340
writableSpotMarketIndexes: [spotMarketIndex],
43384341
readablePerpMarketIndex: [perpMarketIndex],
43394342
});
4340-
4343+
43414344
const amountWithBuffer =
43424345
noAmountBuffer || amount.eq(MIN_I64)
43434346
? amount
@@ -4353,7 +4356,7 @@ export class DriftClient {
43534356
spotMarketVault: spotMarketAccount.vault,
43544357
user: userAccountPublicKey,
43554358
userStats: this.getUserStatsAccountPublicKey(),
4356-
authority: this.wallet.publicKey,
4359+
authority: signingAuthority ?? this.wallet.publicKey,
43574360
},
43584361
remainingAccounts,
43594362
}

sdk/src/math/margin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export function calculateWorstCasePerpLiabilityValue(
176176
worstCaseLiabilityValue: calculatePerpLiabilityValue(
177177
perpPosition.baseAssetAmount,
178178
oraclePrice,
179-
isVariant(perpMarket.contractType, 'prediction')
179+
isPredictionMarket
180180
),
181181
};
182182
}

sdk/src/types.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,10 +1317,6 @@ export type OptionalOrderParams = {
13171317
[Property in keyof OrderParams]?: OrderParams[Property];
13181318
} & NecessaryOrderParams;
13191319

1320-
export type PerpOrderIsolatedExtras = {
1321-
isolatedPositionDepositAmount?: BN;
1322-
};
1323-
13241320
export type ModifyOrderParams = {
13251321
[Property in keyof OrderParams]?: OrderParams[Property] | null;
13261322
} & { policy?: ModifyOrderPolicy };

tests/isolatedPositionDriftClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ describe('drift client', () => {
164164
});
165165

166166
it('Transfer isolated perp position deposit', async () => {
167-
await driftClient.transferIsolatedPerpPositionDeposit(usdcAmount.neg(), 0);
167+
await driftClient.transferIsolatedPerpPositionDeposit(usdcAmount.neg(), 0, undefined, undefined, undefined, true);
168168

169169
const quoteAssetTokenAmount =
170170
driftClient.getIsolatedPerpPositionTokenAmount(0);
@@ -173,7 +173,7 @@ describe('drift client', () => {
173173
const quoteTokenAmount = driftClient.getQuoteAssetTokenAmount();
174174
assert(quoteTokenAmount.eq(usdcAmount));
175175

176-
await driftClient.transferIsolatedPerpPositionDeposit(usdcAmount, 0);
176+
await driftClient.transferIsolatedPerpPositionDeposit(usdcAmount, 0, undefined, undefined, undefined, true);
177177

178178
const quoteAssetTokenAmount2 =
179179
driftClient.getIsolatedPerpPositionTokenAmount(0);
@@ -514,7 +514,7 @@ describe('drift client', () => {
514514

515515
it('Open short position', async () => {
516516
// Re-Deposit USDC, assuming we have 0 balance here
517-
await driftClient.transferIsolatedPerpPositionDeposit(new BN(9855998), 0);
517+
await driftClient.transferIsolatedPerpPositionDeposit(new BN(9855998), 0, undefined, undefined, undefined, true);
518518

519519
const baseAssetAmount = new BN(48000000000);
520520
await driftClient.openPosition(PositionDirection.SHORT, baseAssetAmount, 0);

0 commit comments

Comments
 (0)