Skip to content

Commit 1a9e62d

Browse files
authored
Merge pull request #344 from drift-labs/fix/spot_filler_multi_maker
spotfiller: dont pass maker info with fallback liquidity
2 parents 88ef780 + ef058dd commit 1a9e62d

File tree

4 files changed

+53
-64
lines changed

4 files changed

+53
-64
lines changed

src/bots/spotFiller.ts

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ import { selectMakers } from '../makerSelection';
9898
import { LRUCache } from 'lru-cache';
9999
import { bs58 } from '@project-serum/anchor/dist/cjs/utils/bytes';
100100
import { PythPriceFeedSubscriber } from '../pythPriceFeedSubscriber';
101+
import { FallbackLiquiditySource } from '../experimental-bots/filler-common/types';
101102

102103
const THROTTLED_NODE_SIZE_TO_PRUNE = 10; // Size of throttled nodes to get to before pruning the map
103104
const FILL_ORDER_THROTTLE_BACKOFF = 1000; // the time to wait before trying to fill a throttled (error filling) node again
@@ -162,8 +163,6 @@ function getMakerNodeFromNodeToFill(
162163
return nodeToFill.makerNodes[0];
163164
}
164165

165-
export type FallbackLiquiditySource = 'phoenix' | 'openbook';
166-
167166
export type NodesToFillWithContext = {
168167
nodesToFill: NodeToFill[];
169168
fallbackAskSource?: FallbackLiquiditySource;
@@ -1760,6 +1759,7 @@ export class SpotFillerBot implements Bot {
17601759
'multiMakerSpotFill',
17611760
this.revertOnFailure ?? false,
17621761
false,
1762+
undefined,
17631763
spotPrecision
17641764
);
17651765

@@ -1965,7 +1965,7 @@ export class SpotFillerBot implements Bot {
19651965
)!;
19661966
const spotMarketPrecision = TEN.pow(new BN(spotMarket.decimals));
19671967

1968-
if (nodeToFill.makerNodes.length > 1) {
1968+
if (nodeToFill.makerNodes.length > 0) {
19691969
// do multi maker fills in a separate tx since they're larger
19701970
return this.tryFillMultiMakerSpotNode(
19711971
fillTxId,
@@ -1979,55 +1979,48 @@ export class SpotFillerBot implements Bot {
19791979
? fallbackBidSource
19801980
: fallbackAskSource;
19811981

1982-
const {
1983-
makerInfos,
1984-
takerUser,
1985-
takerUserPubKey,
1986-
takerUserSlot,
1987-
marketType,
1988-
} = await this.getNodeFillInfo(nodeToFill);
1982+
const { takerUser, takerUserPubKey, takerUserSlot, marketType } =
1983+
await this.getNodeFillInfo(nodeToFill);
19891984

19901985
if (!isVariant(marketType, 'spot')) {
19911986
throw new Error('expected spot market type');
19921987
}
19931988

1994-
const makerInfo = makerInfos.length > 0 ? makerInfos[0].data : undefined;
19951989
let fulfillmentConfig:
19961990
| PhoenixV1FulfillmentConfigAccount
19971991
| OpenbookV2FulfillmentConfigAccount
19981992
| undefined = undefined;
1999-
if (makerInfo === undefined) {
2000-
if (fallbackSource === 'phoenix') {
2001-
const cfg = this.phoenixFulfillmentConfigMap.get(
2002-
nodeToFill.node.order!.marketIndex
2003-
);
2004-
if (cfg && isVariant(cfg.status, 'enabled')) {
2005-
fulfillmentConfig = cfg;
2006-
}
2007-
} else if (fallbackSource === 'openbook') {
2008-
const cfg = this.openbookFulfillmentConfigMap.get(
2009-
nodeToFill.node.order!.marketIndex
2010-
);
2011-
if (cfg && isVariant(cfg.status, 'enabled')) {
2012-
fulfillmentConfig = cfg;
2013-
}
2014-
} else {
2015-
logger.error(
2016-
`makerInfo doesnt exist and unknown fallback source: ${fallbackSource} (fillTxId: ${fillTxId})`
2017-
);
1993+
if (fallbackSource === 'phoenix') {
1994+
const cfg = this.phoenixFulfillmentConfigMap.get(
1995+
nodeToFill.node.order!.marketIndex
1996+
);
1997+
if (cfg && isVariant(cfg.status, 'enabled')) {
1998+
fulfillmentConfig = cfg;
1999+
}
2000+
} else if (fallbackSource === 'openbook') {
2001+
const cfg = this.openbookFulfillmentConfigMap.get(
2002+
nodeToFill.node.order!.marketIndex
2003+
);
2004+
if (cfg && isVariant(cfg.status, 'enabled')) {
2005+
fulfillmentConfig = cfg;
20182006
}
2007+
} else {
2008+
logger.error(
2009+
`unknown fallback source: ${fallbackSource} (fillTxId: ${fillTxId})`
2010+
);
20192011
}
20202012

20212013
logMessageForNodeToFill(
20222014
nodeToFill,
20232015
takerUserPubKey,
20242016
takerUserSlot,
2025-
makerInfos,
2017+
[],
20262018
this.getMaxSlot(),
20272019
fillTxId,
20282020
'fillSpotNode',
20292021
this.revertOnFailure ?? false,
20302022
false,
2023+
fallbackSource,
20312024
spotMarketPrecision
20322025
);
20332026

@@ -2055,8 +2048,7 @@ export class SpotFillerBot implements Bot {
20552048
new PublicKey(takerUserPubKey),
20562049
takerUser,
20572050
nodeToFill.node.order,
2058-
fulfillmentConfig,
2059-
makerInfo
2051+
fulfillmentConfig
20602052
)
20612053
);
20622054

src/experimental-bots/filler-common/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export type SerializedDLOBNode = {
128128
isUserProtectedMaker: boolean;
129129
};
130130

131-
export type FallbackLiquiditySource = 'serum' | 'phoenix' | 'openbook';
131+
export type FallbackLiquiditySource = 'phoenix' | 'openbook';
132132
export type NodeToFillWithContext = NodeToFill & {
133133
fallbackAskSource?: FallbackLiquiditySource;
134134
fallbackBidSource?: FallbackLiquiditySource;

src/experimental-bots/spotFiller/spotFillerMultithreaded.ts

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ export class SpotFillerMultithreaded {
907907
continue;
908908
}
909909
this.seenFillableOrders.add(getNodeToFillSignature(node));
910-
if (node.makerNodes.length > 1) {
910+
if (node.makerNodes.length > 0) {
911911
this.tryFillMultiMakerSpotNodes(node, !!buildForBundle);
912912
} else {
913913
this.tryFillSpotNode(node, !!buildForBundle);
@@ -985,6 +985,7 @@ export class SpotFillerMultithreaded {
985985
'multiMakerSpotFill',
986986
this.revertOnFailure ?? false,
987987
false,
988+
undefined,
988989
spotPrecision
989990
);
990991

@@ -1182,13 +1183,8 @@ export class SpotFillerMultithreaded {
11821183
)!;
11831184
const spotMarketPrecision = TEN.pow(new BN(spotMarket.decimals));
11841185

1185-
const {
1186-
makerInfos,
1187-
takerUser,
1188-
takerUserPubKey,
1189-
takerUserSlot,
1190-
marketType,
1191-
} = await this.getNodeFillInfo(nodeToFill);
1186+
const { takerUser, takerUserPubKey, takerUserSlot, marketType } =
1187+
await this.getNodeFillInfo(nodeToFill);
11921188

11931189
if (!isVariant(marketType, 'spot')) {
11941190
throw new Error('expected spot market type');
@@ -1198,43 +1194,41 @@ export class SpotFillerMultithreaded {
11981194
? nodeToFill.fallbackBidSource
11991195
: nodeToFill.fallbackAskSource;
12001196

1201-
const makerInfo = makerInfos.length > 0 ? makerInfos[0].data : undefined;
12021197
let fulfillmentConfig:
12031198
| PhoenixV1FulfillmentConfigAccount
12041199
| OpenbookV2FulfillmentConfigAccount
12051200
| undefined = undefined;
1206-
if (makerInfo === undefined) {
1207-
if (fallbackSource === 'phoenix') {
1208-
const cfg = this.phoenixFulfillmentConfigMap.get(
1209-
nodeToFill.node.order!.marketIndex
1210-
);
1211-
if (cfg && isVariant(cfg.status, 'enabled')) {
1212-
fulfillmentConfig = cfg;
1213-
}
1214-
} else if (fallbackSource === 'openbook') {
1215-
const cfg = this.openbookFulfillmentConfigMap.get(
1216-
nodeToFill.node.order!.marketIndex
1217-
);
1218-
if (cfg && isVariant(cfg.status, 'enabled')) {
1219-
fulfillmentConfig = cfg;
1220-
}
1221-
} else {
1222-
logger.error(
1223-
`makerInfo doesnt exist and unknown fallback source: ${fallbackSource} (fillTxId: ${fillTxId})`
1224-
);
1201+
if (fallbackSource === 'phoenix') {
1202+
const cfg = this.phoenixFulfillmentConfigMap.get(
1203+
nodeToFill.node.order!.marketIndex
1204+
);
1205+
if (cfg && isVariant(cfg.status, 'enabled')) {
1206+
fulfillmentConfig = cfg;
1207+
}
1208+
} else if (fallbackSource === 'openbook') {
1209+
const cfg = this.openbookFulfillmentConfigMap.get(
1210+
nodeToFill.node.order!.marketIndex
1211+
);
1212+
if (cfg && isVariant(cfg.status, 'enabled')) {
1213+
fulfillmentConfig = cfg;
12251214
}
1215+
} else {
1216+
logger.error(
1217+
`makerInfo doesnt exist and unknown fallback source: ${fallbackSource} (fillTxId: ${fillTxId})`
1218+
);
12261219
}
12271220

12281221
logMessageForNodeToFill(
12291222
nodeToFill,
12301223
takerUserPubKey,
12311224
takerUserSlot,
1232-
makerInfos,
1225+
[],
12331226
this.slotSubscriber.getSlot(),
12341227
fillTxId,
12351228
'fillSpotNode',
12361229
this.revertOnFailure ?? false,
12371230
false,
1231+
fallbackSource,
12381232
spotMarketPrecision
12391233
);
12401234

@@ -1267,7 +1261,7 @@ export class SpotFillerMultithreaded {
12671261
takerUser,
12681262
nodeToFill.node.order,
12691263
fulfillmentConfig,
1270-
makerInfo,
1264+
undefined,
12711265
undefined,
12721266
user.userAccountPublicKey
12731267
)

src/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import {
6565
} from '@solana/web3.js';
6666
import { webhookMessage } from './webhook';
6767
import { PythPriceFeedSubscriber } from './pythPriceFeedSubscriber';
68+
import { FallbackLiquiditySource } from './experimental-bots/filler-common/types';
6869

6970
// devnet only
7071
export const TOKEN_FAUCET_PROGRAM_ID = new PublicKey(
@@ -707,6 +708,7 @@ export function logMessageForNodeToFill(
707708
fillType: string,
708709
revertOnFailure: boolean,
709710
removeLastIxPreSim: boolean,
711+
fallbackSource?: FallbackLiquiditySource,
710712
basePrecision: BN = BASE_PRECISION
711713
) {
712714
const takerNode = node.node;
@@ -750,6 +752,7 @@ export function logMessageForNodeToFill(
750752
revertOnFailure,
751753
removeLastIxPreSim,
752754
isSwift: node.node.isSwift,
755+
fallbackSource,
753756
})
754757
);
755758

0 commit comments

Comments
 (0)