Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
rouzwelt committed Jan 25, 2025
1 parent 8cd790c commit 176f2c5
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 34 deletions.
6 changes: 3 additions & 3 deletions src/modes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,21 @@ export async function findOpp({
if ((allResults[0] as any)?.reason?.spanAttributes) {
extendSpanAttributes(
spanAttributes,
(allResults[0] as any).reason.spanAttributes,
JSON.stringify((allResults[0] as any).reason.spanAttributes),
"routeProcessor",
);
}
if ((allResults[1] as any)?.reason?.spanAttributes) {
extendSpanAttributes(
spanAttributes,
(allResults[1] as any).reason.spanAttributes,
JSON.stringify((allResults[1] as any).reason.spanAttributes),
"intraOrderbook",
);
}
if ((allResults[2] as any)?.reason?.spanAttributes) {
extendSpanAttributes(
spanAttributes,
(allResults[2] as any).reason.spanAttributes,
JSON.stringify((allResults[2] as any).reason.spanAttributes),
"interOrderbook",
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/modes/interOrderbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export async function findOpp({
for (let i = 0; i < e.errors.length; i++) {
extendSpanAttributes(
spanAttributes,
e.errors[i].spanAttributes,
JSON.stringify(e.errors[i].spanAttributes),
"againstOrderbooks." + opposingOrderbookOrders[i].orderbook,
);
}
Expand Down
6 changes: 5 additions & 1 deletion src/modes/intraOrderbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,11 @@ export async function findOpp({
});
} catch (e: any) {
allNoneNodeErrors.push(e?.value?.noneNodeError);
extendSpanAttributes(spanAttributes, e.spanAttributes, "intraOrderbook." + i);
extendSpanAttributes(
spanAttributes,
JSON.stringify(e.spanAttributes),
"intraOrderbook." + i,
);
}
}
const noneNodeErrors = allNoneNodeErrors.filter((v) => !!v);
Expand Down
4 changes: 2 additions & 2 deletions src/modes/routeProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ export async function findOpp({
// the fail reason can only be no route in case all hops fail reasons are no route
if (e.reason !== RouteProcessorDryrunHaltReason.NoRoute) noRoute = false;
allNoneNodeErrors.push(e?.value?.noneNodeError);
extendSpanAttributes(spanAttributes, e.spanAttributes, "full");
extendSpanAttributes(spanAttributes, JSON.stringify(e.spanAttributes), "full");
}
if (!hasPriceMatch.value) {
const maxTradeSize = findMaxInput({
Expand Down Expand Up @@ -398,7 +398,7 @@ export async function findOpp({
// the fail reason can only be no route in case all hops fail reasons are no route
if (e.reason !== RouteProcessorDryrunHaltReason.NoRoute) noRoute = false;
allNoneNodeErrors.push(e?.value?.noneNodeError);
extendSpanAttributes(spanAttributes, e.spanAttributes, "partial");
extendSpanAttributes(spanAttributes, JSON.stringify(e.spanAttributes), "partial");
}
}
}
Expand Down
50 changes: 27 additions & 23 deletions src/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,20 @@ export function prepareOrdersForRound(
const orderbookBundledOrders: BundledOrders[] = [];
for (const [, ownerProfile] of ownersProfileMap) {
let remainingLimit = ownerProfile.limit;
const activeOrdersProfiles = Array.from(ownerProfile.orders);
const activeOrdersProfiles = Array.from(ownerProfile.orders).filter((v) => v[1].active);
let remainingOrdersPairs = activeOrdersProfiles.filter(
(v) => v[1].takeOrders.length > 0,
);
// reset if all orders are already consumed
if (remainingOrdersPairs.length === 0) {
for (const [, orderProfile] of activeOrdersProfiles) {
orderProfile.takeOrders.push(...orderProfile.consumedTakeOrders.splice(0));
}
remainingOrdersPairs = activeOrdersProfiles;
}
// consume orders limits
for (const [orderHash, orderProfile] of activeOrdersProfiles) {
if (
remainingLimit > 0 &&
orderProfile.active &&
orderProfile.takeOrders.length > 0
) {
for (const [orderHash, orderProfile] of remainingOrdersPairs) {
if (remainingLimit > 0) {
const consumingOrderPairs = orderProfile.takeOrders.splice(0, remainingLimit);
remainingLimit -= consumingOrderPairs.length;
orderProfile.consumedTakeOrders.push(...consumingOrderPairs);
Expand All @@ -320,22 +326,20 @@ export function prepareOrdersForRound(
// reset and start consuming again from top until limit is reached
if (remainingLimit > 0) {
for (const [orderHash, orderProfile] of activeOrdersProfiles) {
if (orderProfile.active) {
orderProfile.takeOrders.push(...orderProfile.consumedTakeOrders.splice(0));
if (remainingLimit > 0) {
const consumingOrderPairs = orderProfile.takeOrders.splice(
0,
remainingLimit,
);
remainingLimit -= consumingOrderPairs.length;
orderProfile.consumedTakeOrders.push(...consumingOrderPairs);
gatherPairs(
orderbook,
orderHash,
consumingOrderPairs,
orderbookBundledOrders,
);
}
orderProfile.takeOrders.push(...orderProfile.consumedTakeOrders.splice(0));
if (remainingLimit > 0) {
const consumingOrderPairs = orderProfile.takeOrders.splice(
0,
remainingLimit,
);
remainingLimit -= consumingOrderPairs.length;
orderProfile.consumedTakeOrders.push(...consumingOrderPairs);
gatherPairs(
orderbook,
orderHash,
consumingOrderPairs,
orderbookBundledOrders,
);
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1405,15 +1405,16 @@ export function scale18To(value: BigNumberish, targetDecimals: BigNumberish): Bi
*/
export function extendSpanAttributes(
spanAttributes: Record<string, any>,
newAttributes: Record<string, any>,
newAttributes: string,
header: string,
excludeHeaderForKeys: string[] = [],
) {
for (const attrKey in newAttributes) {
const attrs = JSON.parse(newAttributes);
for (const attrKey in attrs) {
if (!excludeHeaderForKeys.includes(attrKey)) {
spanAttributes[header + "." + attrKey] = newAttributes[attrKey];
spanAttributes[header + "." + attrKey] = attrs[attrKey];
} else {
spanAttributes[attrKey] = newAttributes[attrKey];
spanAttributes[attrKey] = attrs[attrKey];
}
}
}

0 comments on commit 176f2c5

Please sign in to comment.