Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't check if its not due yet #24

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions actions/checkForAndPlaceOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,36 @@ const _checkForAndPlaceOrder: ActionFn = async (
for (const conditionalOrder of conditionalOrders) {
orderCounter++;
const logPrefix = `[checkForAndPlaceOrder::${ownerCounter}.${orderCounter}]`;
console.log(
`${logPrefix} Check conditional order created in TX ${conditionalOrder.tx} with params:`,
conditionalOrder.params
);
const logOrderDetails = `Order created in TX ${conditionalOrder.tx} with params:`;

const { result: lastResult } = conditionalOrder.pollResult || {};

// Check if the order is due (by epoch)
if (
lastResult?.result === PollResultCode.TRY_AT_EPOCH &&
lastResult.epoch < blockTimestamp
) {
console.log(
`${logPrefix} Skipping conditional. Reason: Not due yet (TRY_AT_EPOCH=${lastResult.epoch}). ${logOrderDetails}`,
conditionalOrder.params
);
continue;
}

// Check if the order is due (by blockNumber)
if (
lastResult?.result === PollResultCode.TRY_ON_BLOCK &&
lastResult.blockNumber < blockNumber
) {
console.log(
`${logPrefix} Skipping conditional. Reason: Not due yet (TRY_ON_BLOCK=${lastResult.blockNumber}). ${logOrderDetails}`,
conditionalOrder.params
);
continue;
}

// Proceed with the normal check
console.log(`${logPrefix} ${logOrderDetails}`, conditionalOrder.params);
const contract = ComposableCoW__factory.connect(
conditionalOrder.composableCow,
chainContext.provider
Expand Down Expand Up @@ -140,7 +166,7 @@ const _checkForAndPlaceOrder: ActionFn = async (

// Save the latest poll result
conditionalOrder.pollResult = {
lastExecutionTime: blockTimestamp,
lastExecutionTimestamp: blockTimestamp,
blockNumber: blockNumber,

result: pollResult,
Expand Down
2 changes: 1 addition & 1 deletion actions/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export type ConditionalOrder = {
* The result of the last poll
*/
pollResult?: {
lastExecutionTime: number;
lastExecutionTimestamp: number;
blockNumber: number;
result: PollResult;
};
Expand Down