Skip to content

Commit c45be38

Browse files
committed
chore: post rebase cleaner upper
1 parent 9294340 commit c45be38

File tree

4 files changed

+38
-134
lines changed

4 files changed

+38
-134
lines changed

sdk/src/decode/user.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export function decodeUser(buffer: Buffer): UserAccount {
8686
const openOrders = buffer.readUInt8(offset + 94);
8787
const positionFlag = buffer.readUInt8(offset + 95);
8888
const isolatedPositionScaledBalance = readUnsignedBigInt64LE(buffer, offset + 96);
89-
const customMarginRatio = buffer.readUInt32LE(offset + 97);
9089

9190
if (
9291
baseAssetAmount.eq(ZERO) &&
@@ -139,7 +138,6 @@ export function decodeUser(buffer: Buffer): UserAccount {
139138
maxMarginRatio,
140139
positionFlag,
141140
isolatedPositionScaledBalance,
142-
customMarginRatio,
143141
});
144142
}
145143

sdk/src/driftClient.ts

Lines changed: 34 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -264,103 +264,6 @@ export class DriftClient {
264264
return this._isSubscribed && this.accountSubscriber.isSubscribed;
265265
}
266266

267-
public async getDepositIntoIsolatedPerpPositionIx({
268-
perpMarketIndex,
269-
amount,
270-
spotMarketIndex,
271-
subAccountId,
272-
userTokenAccount,
273-
}: {
274-
perpMarketIndex: number;
275-
amount: BN;
276-
spotMarketIndex?: number; // defaults to perp.quoteSpotMarketIndex
277-
subAccountId?: number;
278-
userTokenAccount?: PublicKey; // defaults ATA for spot market mint
279-
}): Promise<TransactionInstruction> {
280-
const user = await this.getUserAccountPublicKey(subAccountId);
281-
const userStats = this.getUserStatsAccountPublicKey();
282-
const statePk = await this.getStatePublicKey();
283-
const perp = this.getPerpMarketAccount(perpMarketIndex);
284-
const spotIndex = spotMarketIndex ?? perp.quoteSpotMarketIndex;
285-
const spot = this.getSpotMarketAccount(spotIndex);
286-
287-
const remainingAccounts = this.getRemainingAccounts({
288-
userAccounts: [this.getUserAccount(subAccountId)],
289-
readablePerpMarketIndex: perpMarketIndex,
290-
writableSpotMarketIndexes: [spotIndex],
291-
});
292-
293-
// token program and transfer hook mints need to be present for deposit
294-
this.addTokenMintToRemainingAccounts(spot, remainingAccounts);
295-
if (this.isTransferHook(spot)) {
296-
await this.addExtraAccountMetasToRemainingAccounts(
297-
spot.mint,
298-
remainingAccounts
299-
);
300-
}
301-
302-
const tokenProgram = this.getTokenProgramForSpotMarket(spot);
303-
const ata =
304-
userTokenAccount ??
305-
(await this.getAssociatedTokenAccount(
306-
spotIndex,
307-
false,
308-
tokenProgram
309-
));
310-
311-
return await this.program.instruction.depositIntoIsolatedPerpPosition(
312-
spotIndex,
313-
perpMarketIndex,
314-
amount,
315-
{
316-
accounts: {
317-
state: statePk,
318-
user,
319-
userStats,
320-
authority: this.wallet.publicKey,
321-
spotMarketVault: spot.vault,
322-
userTokenAccount: ata,
323-
tokenProgram,
324-
},
325-
remainingAccounts,
326-
}
327-
);
328-
}
329-
330-
public async getTransferIsolatedPerpPositionDepositIx({
331-
perpMarketIndex,
332-
amount,
333-
spotMarketIndex,
334-
subAccountId,
335-
}: {
336-
perpMarketIndex: number;
337-
amount: BN;
338-
spotMarketIndex?: number; // defaults to perp.quoteSpotMarketIndex
339-
subAccountId?: number;
340-
}): Promise<TransactionInstruction> {
341-
const user = await this.getUserAccountPublicKey(subAccountId);
342-
const userStats = this.getUserStatsAccountPublicKey();
343-
const statePk = await this.getStatePublicKey();
344-
const perp = this.getPerpMarketAccount(perpMarketIndex);
345-
const spotIndex = spotMarketIndex ?? perp.quoteSpotMarketIndex;
346-
const spot = this.getSpotMarketAccount(spotIndex);
347-
348-
return await this.program.instruction.transferIsolatedPerpPositionDeposit(
349-
spotIndex,
350-
perpMarketIndex,
351-
amount,
352-
{
353-
accounts: {
354-
user,
355-
userStats,
356-
authority: this.wallet.publicKey,
357-
state: statePk,
358-
spotMarketVault: spot.vault,
359-
},
360-
}
361-
);
362-
}
363-
364267
public set isSubscribed(val: boolean) {
365268
this._isSubscribed = val;
366269
}
@@ -4384,29 +4287,27 @@ export class DriftClient {
43844287

43854288
const txKeys = Object.keys(ixPromisesForTxs);
43864289

4387-
43884290
const preIxs: TransactionInstruction[] = [];
4389-
if (isVariant(orderParams.marketType, 'perp') && isolatedPositionDepositAmount?.gt?.(ZERO)) {
4291+
if (
4292+
isVariant(orderParams.marketType, 'perp') &&
4293+
isolatedPositionDepositAmount?.gt?.(ZERO)
4294+
) {
43904295
preIxs.push(
4391-
await this.getTransferIsolatedPerpPositionDepositIx({
4392-
perpMarketIndex: orderParams.marketIndex,
4393-
amount: isolatedPositionDepositAmount as BN,
4394-
subAccountId: userAccount.subAccountId,
4395-
})
4296+
await this.getTransferIsolatedPerpPositionDepositIx(
4297+
isolatedPositionDepositAmount as BN,
4298+
orderParams.marketIndex,
4299+
userAccount.subAccountId
4300+
)
43964301
);
43974302
}
43984303

4399-
44004304
ixPromisesForTxs.marketOrderTx = (async () => {
44014305
const placeOrdersIx = await this.getPlaceOrdersIx(
44024306
[orderParams, ...bracketOrdersParams],
44034307
userAccount.subAccountId
44044308
);
44054309
if (preIxs.length) {
4406-
return [
4407-
...preIxs,
4408-
placeOrdersIx,
4409-
] as unknown as TransactionInstruction;
4310+
return [...preIxs, placeOrdersIx] as unknown as TransactionInstruction;
44104311
}
44114312
return placeOrdersIx;
44124313
})();
@@ -4530,11 +4431,11 @@ export class DriftClient {
45304431
const preIxs: TransactionInstruction[] = [];
45314432
if (isolatedPositionDepositAmount?.gt?.(ZERO)) {
45324433
preIxs.push(
4533-
await this.getTransferIsolatedPerpPositionDepositIx({
4534-
perpMarketIndex: orderParams.marketIndex,
4535-
amount: isolatedPositionDepositAmount as BN,
4536-
subAccountId,
4537-
})
4434+
await this.getTransferIsolatedPerpPositionDepositIx(
4435+
isolatedPositionDepositAmount as BN,
4436+
orderParams.marketIndex,
4437+
subAccountId
4438+
)
45384439
);
45394440
}
45404441

@@ -4918,7 +4819,6 @@ export class DriftClient {
49184819
useMarketLastSlotCache: true,
49194820
});
49204821

4921-
49224822
return await this.program.instruction.cancelOrders(
49234823
marketType ?? null,
49244824
marketIndex ?? null,
@@ -4993,13 +4893,16 @@ export class DriftClient {
49934893
const preIxs: TransactionInstruction[] = [];
49944894
if (params?.length === 1) {
49954895
const p = params[0];
4996-
if (isVariant(p.marketType, 'perp') && isolatedPositionDepositAmount?.gt?.(ZERO)) {
4896+
if (
4897+
isVariant(p.marketType, 'perp') &&
4898+
isolatedPositionDepositAmount?.gt?.(ZERO)
4899+
) {
49974900
preIxs.push(
4998-
await this.getTransferIsolatedPerpPositionDepositIx({
4999-
perpMarketIndex: p.marketIndex,
5000-
amount: isolatedPositionDepositAmount as BN,
5001-
subAccountId,
5002-
})
4901+
await this.getTransferIsolatedPerpPositionDepositIx(
4902+
isolatedPositionDepositAmount as BN,
4903+
p.marketIndex,
4904+
subAccountId
4905+
)
50034906
);
50044907
}
50054908
}
@@ -6470,13 +6373,16 @@ export class DriftClient {
64706373
subAccountId
64716374
);
64726375

6473-
if (isVariant(orderParams.marketType, 'perp') && isolatedPositionDepositAmount?.gt?.(ZERO)) {
6376+
if (
6377+
isVariant(orderParams.marketType, 'perp') &&
6378+
isolatedPositionDepositAmount?.gt?.(ZERO)
6379+
) {
64746380
placeAndTakeIxs.push(
6475-
await this.getTransferIsolatedPerpPositionDepositIx({
6476-
perpMarketIndex: orderParams.marketIndex,
6477-
amount: isolatedPositionDepositAmount as BN,
6478-
subAccountId,
6479-
})
6381+
await this.getTransferIsolatedPerpPositionDepositIx(
6382+
isolatedPositionDepositAmount as BN,
6383+
orderParams.marketIndex,
6384+
subAccountId
6385+
)
64806386
);
64816387
}
64826388

@@ -10758,4 +10664,4 @@ export class DriftClient {
1075810664
forceVersionedTransaction,
1075910665
});
1076010666
}
10761-
}
10667+
}

sdk/src/user.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,14 @@ export class User {
287287
);
288288

289289
// margin ratio for this perp
290-
const customMarginRatio = Math.max(this.getUserAccount().maxMarginRatio, marketPosition.customMarginRatio);
290+
const customMarginRatio = Math.max(this.getUserAccount().maxMarginRatio, marketPosition.maxMarginRatio);
291291
let marginRatio = new BN(
292292
calculateMarketMarginRatio(
293293
market,
294294
worstCaseBaseAssetAmount.abs(),
295295
marginCategory,
296296
customMarginRatio,
297-
this.isHighLeverageMode() || enteringHighLeverage
297+
this.isHighLeverageMode(marginCategory) || enteringHighLeverage
298298
)
299299
);
300300
if (isVariant(market.status, 'settlement')) {
@@ -616,7 +616,6 @@ export class User {
616616
maxMarginRatio: 0,
617617
positionFlag: 0,
618618
isolatedPositionScaledBalance: ZERO,
619-
customMarginRatio: 0,
620619
};
621620
}
622621

sdk/tests/dlob/helpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export const mockPerpPosition: PerpPosition = {
4747
lastQuoteAssetAmountPerLp: new BN(0),
4848
perLpBase: 0,
4949
positionFlag: 0,
50+
isolatedPositionScaledBalance: new BN(0),
51+
maxMarginRatio: 0,
5052
};
5153

5254
export const mockAMM: AMM = {
@@ -663,7 +665,6 @@ export class MockUserMap implements UserMapInterface {
663665
private userMap = new Map<string, User>();
664666
private userAccountToAuthority = new Map<string, string>();
665667
private driftClient: DriftClient;
666-
eventEmitter: StrictEventEmitter<EventEmitter, UserEvents>;
667668

668669
constructor() {
669670
this.userMap = new Map();

0 commit comments

Comments
 (0)