Skip to content
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
2 changes: 2 additions & 0 deletions packages/monitor-v2/src/bot-oo-v3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ All the configuration should be provided with following environment variables:
Defaults to 72h if not provided.
- `MAX_BLOCK_LOOKBACK` (Optional) is the maximum number of blocks to look back per query.
See default values in blockDefaults in index.ts
- `SETTLE_DELAY`: Lookback period in seconds to detect settleable assertions (default `300`).
- `SETTLE_TIMEOUT`: Timeout in seconds for submitting settlement transactions in serverless mode (default `240`).
15 changes: 13 additions & 2 deletions packages/monitor-v2/src/bot-oo-v3/SettleAssertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export async function settleAssertions(logger: typeof Logger, params: Monitoring

const setteableAssertionsPromises = assertionsToSettle.map(async (assertion) => {
try {
await oo.callStatic.settleAndGetAssertionResult(assertion.args.assertionId);
await oo.callStatic.settleAndGetAssertionResult(assertion.args.assertionId, {
blockTag: params.settleableCheckBlock,
});
logger.debug({
at: "OOv3Bot",
message: "Assertion is settleable",
Expand All @@ -59,7 +61,16 @@ export async function settleAssertions(logger: typeof Logger, params: Monitoring

const ooWithSigner = oo.connect(params.signer);

for (const assertion of setteableAssertions) {
for (const [i, assertion] of setteableAssertions.entries()) {
if (params.executionDeadline && Date.now() / 1000 >= params.executionDeadline) {
logger.warn({
at: "OOv3Bot",
message: "Execution deadline reached, skipping settlement",
remainingAssertions: setteableAssertions.length - i,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: For observability, we might want to add some more info to this log:

executionDeadline: params.executionDeadline,
now: Math.floor(Date.now() / 1000),
timeoutSec: Number(process.env.SETTLE_TIMEOUT) || 240,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if that adds much, since executionDeadline and now are going to be pretty close and also we have current timestamp in the logs

});
break;
}

try {
const estimatedGas = await oo.estimateGas.settleAssertion(assertion.args.assertionId);
const gasLimitOverride = estimatedGas.mul(params.gasLimitMultiplier).div(100);
Expand Down
11 changes: 11 additions & 0 deletions packages/monitor-v2/src/bot-oo-v3/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export interface MonitoringParams {
blockFinder: BaseMonitoringParams["blockFinder"];
pollingDelay: number;
gasLimitMultiplier: number;
settleableCheckBlock: number; // Block number to check for settleable assertions, defaults to 5 minutes ago
executionDeadline?: number; // Timestamp in sec for when to stop settling, defaults to 4 minutes from now in serverless
}

export const initMonitoringParams = async (env: NodeJS.ProcessEnv): Promise<MonitoringParams> => {
Expand All @@ -29,6 +31,13 @@ export const initMonitoringParams = async (env: NodeJS.ProcessEnv): Promise<Moni
settleAssertionsEnabled: env.SETTLEMENTS_ENABLED === "true",
};

const settleDelay = Number(env.SETTLE_DELAY) || 5 * 60; // Default to 5 minutes ago
const currentTimestamp = Math.floor(Date.now() / 1000);
const settleableCheckBlock = (await base.blockFinder.getBlockForTimestamp(currentTimestamp - settleDelay)).number;

const settleTimeout = Number(env.SETTLE_TIMEOUT) || 4 * 60; // Default to 4 minutes from now in serverless
const executionDeadline = base.pollingDelay === 0 ? currentTimestamp + settleTimeout : undefined;

return {
provider: base.provider,
chainId: base.chainId,
Expand All @@ -39,6 +48,8 @@ export const initMonitoringParams = async (env: NodeJS.ProcessEnv): Promise<Moni
blockFinder: base.blockFinder,
pollingDelay: base.pollingDelay,
gasLimitMultiplier: base.gasLimitMultiplier,
settleableCheckBlock,
executionDeadline,
};
};

Expand Down
6 changes: 4 additions & 2 deletions packages/monitor-v2/src/bot-oo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ node ./packages/monitor-v2/dist/bot-oo/index.js
- `TIME_LOOKBACK`: Seconds to look back for events (default 72h).
- `MAX_BLOCK_LOOKBACK`: Max block span per query (see `blockDefaults`).
- `GAS_LIMIT_MULTIPLIER`: Percent multiplier on estimated gas (default `150`).
- `SETTLE_DELAY`: Lookback period in seconds to detect settleable requests (default `300`).
- `SETTLE_TIMEOUT`: Timeout in seconds for submitting settlement transactions in serverless mode (default `240`).

## Behavior

Expand All @@ -48,5 +50,5 @@ For each Oracle type:

1. Scans `RequestPrice` events within the lookback window.
2. Filters out already settled requests (`Settle` events).
3. Uses Oracle-specific logic to detect settleable requests.
4. Submits settlement transactions when requests are ready.
3. Uses Oracle-specific logic to detect settleable requests at historical state (using `SETTLE_DELAY`).
4. Submits settlement transactions when requests are ready, stopping when `SETTLE_TIMEOUT` passes in serverless mode.
14 changes: 12 additions & 2 deletions packages/monitor-v2/src/bot-oo/SettleOOv1Requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export async function settleOOv1Requests(
req.args.requester,
req.args.identifier,
req.args.timestamp,
req.args.ancillaryData
req.args.ancillaryData,
{ blockTag: params.settleableCheckBlock }
);
logger.debug({
at: "OOv1Bot",
Expand Down Expand Up @@ -93,7 +94,16 @@ export async function settleOOv1Requests(

const oov1WithSigner = oov1WithAddress.connect(params.signer);

for (const req of settleableRequests) {
for (const [i, req] of settleableRequests.entries()) {
if (params.executionDeadline && Date.now() / 1000 >= params.executionDeadline) {
logger.warn({
at: "OOv1Bot",
message: "Execution deadline reached, skipping settlement",
remainingRequests: settleableRequests.length - i,
});
break;
}

try {
const estimatedGas = await oov1WithAddress.estimateGas.settle(
req.args.requester,
Expand Down
15 changes: 13 additions & 2 deletions packages/monitor-v2/src/bot-oo/SettleOOv2Requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export async function settleOOv2Requests(

const settleableRequestsPromises = requestsToSettle.map(async (req) => {
try {
await oo.callStatic.settle(req.args.requester, req.args.identifier, req.args.timestamp, req.args.ancillaryData);
await oo.callStatic.settle(req.args.requester, req.args.identifier, req.args.timestamp, req.args.ancillaryData, {
blockTag: params.settleableCheckBlock,
});
logger.debug({
at: "OOv2Bot",
message: "Request is settleable",
Expand Down Expand Up @@ -67,7 +69,16 @@ export async function settleOOv2Requests(

const ooWithSigner = oo.connect(params.signer);

for (const req of settleableRequests) {
for (const [i, req] of settleableRequests.entries()) {
if (params.executionDeadline && Date.now() / 1000 >= params.executionDeadline) {
logger.warn({
at: "OOv2Bot",
message: "Execution deadline reached, skipping settlement",
remainingRequests: settleableRequests.length - i,
});
break;
}

try {
const estimatedGas = await oo.estimateGas.settle(
req.args.requester,
Expand Down
14 changes: 12 additions & 2 deletions packages/monitor-v2/src/bot-oo/SettleSkinnyOORequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ export async function settleSkinnyOORequests(
finalFee: request.finalFee,
bond: request.bond,
customLiveness: request.customLiveness,
}
},
{ blockTag: params.settleableCheckBlock }
);

logger.debug({
Expand Down Expand Up @@ -151,7 +152,16 @@ export async function settleSkinnyOORequests(

const skinnyOOWithSigner = skinnyOOWithAddress.connect(params.signer);

for (const settleableRequest of settleableRequests) {
for (const [i, settleableRequest] of settleableRequests.entries()) {
if (params.executionDeadline && Date.now() / 1000 >= params.executionDeadline) {
logger.warn({
at: "SkinnyOOBot",
message: "Execution deadline reached, skipping settlement",
remainingRequests: settleableRequests.length - i,
});
break;
}

if (!settleableRequest) continue;
const { event: req, request } = settleableRequest;

Expand Down
11 changes: 11 additions & 0 deletions packages/monitor-v2/src/bot-oo/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export interface MonitoringParams extends BaseMonitoringParams {
botModes: BotModes;
oracleType: OracleType;
contractAddress: string;
settleableCheckBlock: number; // Block number to check for settleable requests, defaults to 5 minutes ago
executionDeadline?: number; // Timestamp in sec for when to stop settling, defaults to 4 minutes from now in serverless
}

export const initMonitoringParams = async (env: NodeJS.ProcessEnv): Promise<MonitoringParams> => {
Expand All @@ -38,11 +40,20 @@ export const initMonitoringParams = async (env: NodeJS.ProcessEnv): Promise<Moni
);
}

const settleDelay = Number(env.SETTLE_DELAY) || 5 * 60; // Default to 5 minutes ago
const currentTimestamp = Math.floor(Date.now() / 1000);
const settleableCheckBlock = (await base.blockFinder.getBlockForTimestamp(currentTimestamp - settleDelay)).number;

const settleTimeout = Number(env.SETTLE_TIMEOUT) || 4 * 60; // Default to 4 minutes from now in serverless
const executionDeadline = base.pollingDelay === 0 ? currentTimestamp + settleTimeout : undefined;

return {
...base,
botModes,
oracleType,
contractAddress,
settleableCheckBlock,
executionDeadline,
};
};

Expand Down