diff --git a/src/account.ts b/src/account.ts index 80922972..4001937d 100644 --- a/src/account.ts +++ b/src/account.ts @@ -1083,8 +1083,22 @@ export async function checkOwnedOrders( orderDetails.flat().forEach((v) => { v.takeOrders.forEach((order) => { if ( + // owner check order.takeOrder.order.owner.toLowerCase() === config.mainAccount.account.address.toLowerCase() && + // self fund config check + !!(config.selfFundOrders ?? []).find( + (e) => + e.token.toLowerCase() === + order.takeOrder.order.validOutputs[ + order.takeOrder.outputIOIndex + ].token.toLowerCase() && + BigNumber.from( + order.takeOrder.order.validOutputs[order.takeOrder.outputIOIndex] + .vaultId, + ).eq(e.vaultId), + ) && + // repetition check !ownedOrders.find( (e) => e.orderbook.toLowerCase() === v.orderbook.toLowerCase() && diff --git a/src/modes/index.ts b/src/modes/index.ts index 07f023ea..433d8dfd 100644 --- a/src/modes/index.ts +++ b/src/modes/index.ts @@ -2,11 +2,11 @@ import { Contract } from "ethers"; import { PublicClient } from "viem"; import { DataFetcher } from "sushi"; import { Token } from "sushi/currency"; +import { extendSpanAttributes } from "../utils"; import { findOpp as findInterObOpp } from "./interOrderbook"; import { findOpp as findIntraObOpp } from "./intraOrderbook"; import { findOppWithRetries as findRpOpp } from "./routeProcessor"; import { BotConfig, BundledOrders, ViemClient, DryrunResult, SpanAttrs } from "../types"; -import { extendSpanAttributes } from "../utils"; /** * The main entrypoint for the main logic to find opps. diff --git a/test/orders.test.js b/test/orders.test.js index 5ccd5308..51b15daf 100644 --- a/test/orders.test.js +++ b/test/orders.test.js @@ -844,9 +844,17 @@ describe("Test order", async function () { viemClient: { multicall: async () => [0n, 10n], }, + selfFundOrders: [ + { + token: order1.sellToken, + vaultId: order1.takeOrders[0].takeOrder.order.validOutputs[0].vaultId, + threshold: "1", + topupAmount: "1", + }, + ], }; const result = await checkOwnedOrders(config, orders, hexlify(randomBytes(20))); - const expected = orders.map((v, i) => ({ + const expected = orders.slice(0, 1).map((v, i) => ({ id: v.takeOrders[0].id, vaultId: v.takeOrders[0].takeOrder.order.validOutputs[