Skip to content

Commit

Permalink
Merge branch 'master' into luke/dpe-1738-priority-fee-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
lukecaan committed Dec 28, 2023
2 parents a0138ba + 21f7d0f commit 9fddc2e
Show file tree
Hide file tree
Showing 18 changed files with 569 additions and 318 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixes

- sdk: use tx params passed into deposit function

### Breaking

## [2.52.0] - 2023-12-22
Expand Down
3 changes: 2 additions & 1 deletion programs/drift/src/controller/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1829,7 +1829,8 @@ pub fn fulfill_perp_order_with_amm(
// if is an actual swap (and not amm jit order) then msg!
if override_base_asset_amount.is_none() {
msg!(
"Amm cant fulfill order. base asset amount {} market.amm.min_order_size {}",
"Amm cant fulfill order. market index {} base asset amount {} market.amm.min_order_size {}",
market.market_index,
base_asset_amount,
market.amm.min_order_size
);
Expand Down
2 changes: 1 addition & 1 deletion sdk/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.53.0-beta.0
2.53.0-beta.8
Binary file modified sdk/bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@drift-labs/sdk",
"version": "2.53.0-beta.0",
"version": "2.53.0-beta.8",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"author": "crispheaney",
Expand Down
64 changes: 39 additions & 25 deletions sdk/src/dlob/DLOB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ export class DLOB {
for (const user of userMap.values()) {
const userAccount = user.getUserAccount();
const userAccountPubkey = user.getUserAccountPublicKey();
const userAccountPubkeyString = userAccountPubkey.toString();

for (const order of userAccount.orders) {
this.insertOrder(order, userAccountPubkey, slot);
this.insertOrder(order, userAccountPubkeyString, slot);
}
}

Expand All @@ -173,15 +174,15 @@ export class DLOB {
}

for (const { user, order } of dlobOrders) {
this.insertOrder(order, user, slot);
this.insertOrder(order, user.toString(), slot);
}

this.initialized = true;
return true;
}

public handleOrderRecord(record: OrderRecord, slot: number): void {
this.insertOrder(record.order, record.user, slot);
this.insertOrder(record.order, record.user.toString(), slot);
}

public handleOrderActionRecord(
Expand Down Expand Up @@ -249,7 +250,7 @@ export class DLOB {

public insertOrder(
order: Order,
userAccount: PublicKey,
userAccount: string,
slot: number,
onInsert?: OrderBookCallback
): void {
Expand Down Expand Up @@ -327,7 +328,7 @@ export class DLOB {
};
newOrder.baseAssetAmountFilled = cumulativeBaseAssetAmountFilled;

this.getListForOrder(order, slot)?.update(newOrder, userAccount);
this.getListForOrder(order, slot)?.update(newOrder, userAccount.toString());

if (onUpdate) {
onUpdate();
Expand All @@ -354,9 +355,13 @@ export class DLOB {

const triggerList = this.orderLists.get(marketType).get(order.marketIndex)
.trigger[isVariant(order.triggerCondition, 'above') ? 'above' : 'below'];
triggerList.remove(order, userAccount);
triggerList.remove(order, userAccount.toString());

this.getListForOrder(order, slot)?.insert(order, marketType, userAccount);
this.getListForOrder(order, slot)?.insert(
order,
marketType,
userAccount.toString()
);
if (onTrigger) {
onTrigger();
}
Expand All @@ -374,7 +379,7 @@ export class DLOB {

this.updateRestingLimitOrders(slot);

this.getListForOrder(order, slot)?.remove(order, userAccount);
this.getListForOrder(order, slot)?.remove(order, userAccount.toString());
if (onDelete) {
onDelete();
}
Expand Down Expand Up @@ -472,7 +477,7 @@ export class DLOB {
}

public getOrder(orderId: number, userAccount: PublicKey): Order | undefined {
const orderSignature = getOrderSignature(orderId, userAccount);
const orderSignature = getOrderSignature(orderId, userAccount.toString());
for (const nodeList of this.getNodeLists()) {
const node = nodeList.get(orderSignature);
if (node) {
Expand Down Expand Up @@ -852,7 +857,7 @@ export class DLOB {

for (const makerNode of makerNodeGenerator) {
// Can't match orders from the same user
const sameUser = takerNode.userAccount.equals(makerNode.userAccount);
const sameUser = takerNode.userAccount === makerNode.userAccount;
if (sameUser) {
continue;
}
Expand Down Expand Up @@ -1377,7 +1382,7 @@ export class DLOB {
const askOrder = askNode.order;

// Can't match orders from the same user
const sameUser = bidNode.userAccount.equals(askNode.userAccount);
const sameUser = bidNode.userAccount === askNode.userAccount;
if (sameUser) {
continue;
}
Expand Down Expand Up @@ -1472,31 +1477,37 @@ export class DLOB {
slot: number,
marketType: MarketType,
oraclePriceData: OraclePriceData
): BN {
return this.getRestingLimitAsks(
): BN | undefined {
const bestAsk = this.getRestingLimitAsks(
marketIndex,
slot,
marketType,
oraclePriceData
)
.next()
.value.getPrice(oraclePriceData, slot);
).next().value;

if (bestAsk) {
return bestAsk.getPrice(oraclePriceData, slot);
}
return undefined;
}

public getBestBid(
marketIndex: number,
slot: number,
marketType: MarketType,
oraclePriceData: OraclePriceData
): BN {
return this.getRestingLimitBids(
): BN | undefined {
const bestBid = this.getRestingLimitBids(
marketIndex,
slot,
marketType,
oraclePriceData
)
.next()
.value.getPrice(oraclePriceData, slot);
).next().value;

if (bestBid) {
return bestBid.getPrice(oraclePriceData, slot);
}
return undefined;
}

public *getStopLosses(
Expand Down Expand Up @@ -1754,7 +1765,7 @@ export class DLOB {
for (const nodeList of this.getNodeLists()) {
for (const node of nodeList.getGenerator()) {
dlobOrders.push({
user: node.userAccount,
user: new PublicKey(node.userAccount),
order: node.order,
});
}
Expand Down Expand Up @@ -1896,7 +1907,7 @@ export class DLOB {
asks.push({
price: ask.getPrice(oraclePriceData, slot),
size: ask.order.baseAssetAmount.sub(ask.order.baseAssetAmountFilled),
maker: ask.userAccount,
maker: new PublicKey(ask.userAccount),
orderId: ask.order.orderId,
});
}
Expand All @@ -1912,7 +1923,7 @@ export class DLOB {
bids.push({
price: bid.getPrice(oraclePriceData, slot),
size: bid.order.baseAssetAmount.sub(bid.order.baseAssetAmountFilled),
maker: bid.userAccount,
maker: new PublicKey(bid.userAccount),
orderId: bid.order.orderId,
});
}
Expand Down Expand Up @@ -2022,7 +2033,10 @@ export class DLOB {

for (const node of generator) {
if (!makers.has(node.userAccount.toString())) {
makers.set(node.userAccount.toString(), node.userAccount);
makers.set(
node.userAccount.toString(),
new PublicKey(node.userAccount)
);
}

if (makers.size === numMakers) {
Expand Down
10 changes: 5 additions & 5 deletions sdk/src/dlob/DLOBNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Order,
ZERO,
} from '..';
import { PublicKey } from '@solana/web3.js';
// import { PublicKey } from '@solana/web3.js';
import { getOrderSignature } from './NodeList';

export interface DLOBNode {
Expand All @@ -18,17 +18,17 @@ export interface DLOBNode {
order: Order | undefined;
isBaseFilled(): boolean;
haveFilled: boolean;
userAccount: PublicKey | undefined;
userAccount: string | undefined;
}

export abstract class OrderNode implements DLOBNode {
order: Order;
userAccount: PublicKey;
userAccount: string;
sortValue: BN;
haveFilled = false;
haveTrigger = false;

constructor(order: Order, userAccount: PublicKey) {
constructor(order: Order, userAccount: string) {
// Copy the order over to the node
this.order = { ...order };
this.userAccount = userAccount;
Expand Down Expand Up @@ -140,7 +140,7 @@ export type DLOBNodeType =
export function createNode<T extends DLOBNodeType>(
nodeType: T,
order: Order,
userAccount: PublicKey
userAccount: string
): DLOBNodeMap[T] {
switch (nodeType) {
case 'floatingLimit':
Expand Down
12 changes: 6 additions & 6 deletions sdk/src/dlob/NodeList.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { BN, isVariant, MarketTypeStr, Order } from '..';
import { PublicKey } from '@solana/web3.js';
// import { PublicKey } from '@solana/web3.js';
import { createNode, DLOBNode, DLOBNodeMap } from './DLOBNode';

export type SortDirection = 'asc' | 'desc';

export function getOrderSignature(
orderId: number,
userAccount: PublicKey
userAccount: string
): string {
return `${userAccount.toString()}-${orderId.toString()}`;
}
Expand Down Expand Up @@ -36,7 +36,7 @@ export class NodeList<NodeType extends keyof DLOBNodeMap>
public insert(
order: Order,
marketType: MarketTypeStr,
userAccount: PublicKey
userAccount: string
): void {
if (isVariant(order.status, 'init')) {
return;
Expand Down Expand Up @@ -101,7 +101,7 @@ export class NodeList<NodeType extends keyof DLOBNodeMap>
}
}

public update(order: Order, userAccount: PublicKey): void {
public update(order: Order, userAccount: string): void {
const orderId = getOrderSignature(order.orderId, userAccount);
if (this.nodeMap.has(orderId)) {
const node = this.nodeMap.get(orderId);
Expand All @@ -110,7 +110,7 @@ export class NodeList<NodeType extends keyof DLOBNodeMap>
}
}

public remove(order: Order, userAccount: PublicKey): void {
public remove(order: Order, userAccount: string): void {
const orderId = getOrderSignature(order.orderId, userAccount);
if (this.nodeMap.has(orderId)) {
const node = this.nodeMap.get(orderId);
Expand Down Expand Up @@ -142,7 +142,7 @@ export class NodeList<NodeType extends keyof DLOBNodeMap>
}
}

public has(order: Order, userAccount: PublicKey): boolean {
public has(order: Order, userAccount: string): boolean {
return this.nodeMap.has(getOrderSignature(order.orderId, userAccount));
}

Expand Down
6 changes: 4 additions & 2 deletions sdk/src/driftClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1652,7 +1652,8 @@ export class DriftClient {
marketIndex: number,
associatedTokenAccount: PublicKey,
subAccountId?: number,
reduceOnly = false
reduceOnly = false,
txParams?: TxParams
): Promise<TransactionSignature> {
const additionalSigners: Array<Signer> = [];

Expand Down Expand Up @@ -1701,7 +1702,7 @@ export class DriftClient {
);
}

const txParams = { ...this.txParams, computeUnits: 600_000 };
txParams = { ...(txParams ?? this.txParams), computeUnits: 600_000 };

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

Expand Down Expand Up @@ -3865,6 +3866,7 @@ export class DriftClient {
slippageBps,
swapMode,
onlyDirectRoutes,
excludeDexes: ['Raydium CLMM'], // temp exclude to workaround bug with raydium clmm
});

quote = fetchedQuote;
Expand Down
Loading

0 comments on commit 9fddc2e

Please sign in to comment.