Skip to content

Commit

Permalink
feat: spoke pool client queries old and new event names
Browse files Browse the repository at this point in the history
Signed-off-by: bennett <[email protected]>
  • Loading branch information
bmzig committed Jan 17, 2025
1 parent db244fb commit f3e975a
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"dependencies": {
"@across-protocol/across-token": "^1.0.0",
"@across-protocol/constants": "^3.1.30",
"@across-protocol/contracts": "^3.0.25",
"@across-protocol/contracts": "3.1.0-beta.3",
"@eth-optimism/sdk": "^3.3.1",
"@ethersproject/bignumber": "^5.7.0",
"@pinata/sdk": "^2.1.0",
Expand Down
77 changes: 62 additions & 15 deletions src/clients/SpokePoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
spreadEventWithBlockNumber,
} from "../utils/EventUtils";
import { validateFillForDeposit } from "../utils/FlowUtils";
import { ZERO_ADDRESS } from "../constants";
import { ZERO_ADDRESS, ZERO_BYTES } from "../constants";
import {
Deposit,
DepositWithBlock,
Expand Down Expand Up @@ -115,6 +115,12 @@ export class SpokePoolClient extends BaseAbstractClient {
"RequestedSpeedUpV3Deposit",
"RequestedV3SlowFill",
"FilledV3Relay",

// Upgrade-only events
"FundsDeposited",
"RequestedSpeedUpDeposit",
"RequestedSlowFill",
"FilledRelay",
];
return Object.fromEntries(
this.spokePool.interface.fragments
Expand Down Expand Up @@ -541,12 +547,17 @@ export class SpokePoolClient extends BaseAbstractClient {
}
}

if (eventsToQuery.includes("V3FundsDeposited")) {
const depositEvents = queryResults[eventsToQuery.indexOf("V3FundsDeposited")] ?? [];
// Performs the indexing of a deposit-like spoke pool event.
const queryDepositEvents = async (eventName: string) => {
const depositEvents = queryResults[eventsToQuery.indexOf(eventName)] ?? [];
if (depositEvents.length > 0) {
this.log("debug", `Using ${depositEvents.length} newly queried deposit events for chain ${this.chainId}`, {
earliestEvent: depositEvents[0].blockNumber,
});
this.log(
"debug",
`Using ${depositEvents.length} newly queried ${eventName} deposit events for chain ${this.chainId}`,
{
earliestEvent: depositEvents[0].blockNumber,
}
);
}

// For each deposit, resolve its quoteTimestamp to a block number on the HubPool.
Expand All @@ -570,7 +581,7 @@ export class SpokePoolClient extends BaseAbstractClient {
deposit.fromLiteChain = this.isOriginLiteChain(deposit);
deposit.toLiteChain = this.isDestinationLiteChain(deposit);

if (deposit.outputToken === ZERO_ADDRESS) {
if (deposit.outputToken === ZERO_ADDRESS || deposit.outputToken === ZERO_BYTES) {
deposit.outputToken = this.getDestinationTokenForDeposit(deposit);
}

Expand All @@ -586,11 +597,21 @@ export class SpokePoolClient extends BaseAbstractClient {
this.latestDepositIdQueried = deposit.depositId;
}
}
};

// Query "legacy" V3FundsDeposited events.
if (eventsToQuery.includes("V3FundsDeposited")) {
await queryDepositEvents("V3FundsDeposited");
}

// Update deposits with speed up requests from depositor.
if (eventsToQuery.includes("RequestedSpeedUpV3Deposit")) {
const speedUpEvents = queryResults[eventsToQuery.indexOf("RequestedSpeedUpV3Deposit")] ?? [];
// Additionally query the newer FundsDeposited spoke pool events.
if (eventsToQuery.includes("FundsDeposited")) {
await queryDepositEvents("FundsDeposited");
}

// Performs indexing of a "speed up deposit"-like event.
const querySpeedUpDepositEvents = (eventName: string) => {
const speedUpEvents = queryResults[eventsToQuery.indexOf(eventName)] ?? [];

for (const event of speedUpEvents) {
const speedUp = { ...spreadEventWithBlockNumber(event), originChainId: this.chainId } as SpeedUpWithBlock;
Expand All @@ -607,10 +628,19 @@ export class SpokePoolClient extends BaseAbstractClient {
this.depositHashes[depositHash] = this.appendMaxSpeedUpSignatureToDeposit(depositDataAssociatedWithSpeedUp);
}
}
};

// Update deposits with speed up requests from depositor.
if (eventsToQuery.includes("RequestedSpeedUpV3Deposit")) {
querySpeedUpDepositEvents("RequestedSpeedUpV3Deposit");
}
if (eventsToQuery.includes("RequestedSpeedUpDeposit")) {
querySpeedUpDepositEvents("RequestedSpeedUpDeposit");
}

if (eventsToQuery.includes("RequestedV3SlowFill")) {
const slowFillRequests = queryResults[eventsToQuery.indexOf("RequestedV3SlowFill")];
// Performs indexing of "requested slow fill"-like events.
const queryRequestedSlowFillEvents = (eventName: string) => {
const slowFillRequests = queryResults[eventsToQuery.indexOf(eventName)];
for (const event of slowFillRequests) {
const slowFillRequest = {
...spreadEventWithBlockNumber(event),
Expand All @@ -623,13 +653,22 @@ export class SpokePoolClient extends BaseAbstractClient {
}
this.slowFillRequests[relayDataHash] = slowFillRequest;
}
};

// Update slow fill requests with ingested event data.
if (eventsToQuery.includes("RequestedV3SlowFill")) {
queryRequestedSlowFillEvents("RequestedV3SlowFill");
}
if (eventsToQuery.includes("RequestedSlowFill")) {
queryRequestedSlowFillEvents("RequestedSlowFill");
}

if (eventsToQuery.includes("FilledV3Relay")) {
const fillEvents = queryResults[eventsToQuery.indexOf("FilledV3Relay")] ?? [];
// Performs indexing of filled relay-like events.
const queryFilledRelayEvents = (eventName: string) => {
const fillEvents = queryResults[eventsToQuery.indexOf(eventName)] ?? [];

if (fillEvents.length > 0) {
this.log("debug", `Using ${fillEvents.length} newly queried fill events for chain ${this.chainId}`, {
this.log("debug", `Using ${fillEvents.length} newly queried ${eventName} events for chain ${this.chainId}`, {
earliestEvent: fillEvents[0].blockNumber,
});
}
Expand All @@ -645,6 +684,14 @@ export class SpokePoolClient extends BaseAbstractClient {
assign(this.fills, [fill.originChainId], [fill]);
assign(this.depositHashesToFills, [this.getDepositHash(fill)], [fill]);
}
};

// Update observed fills with ingested event data.
if (eventsToQuery.includes("FilledV3Relay")) {
queryFilledRelayEvents("FilledV3Relay");
}
if (eventsToQuery.includes("FilledRelay")) {
queryFilledRelayEvents("FilledRelay");
}

if (eventsToQuery.includes("EnabledDepositRoute")) {
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export {
TOKEN_SYMBOLS_MAP,
} from "@across-protocol/constants";

export const { AddressZero: ZERO_ADDRESS } = ethersConstants;
export const { AddressZero: ZERO_ADDRESS, HashZero: ZERO_BYTES } = ethersConstants;

// 2^96 - 1 is a conservative erc20 max allowance.
export const MAX_SAFE_ALLOWANCE = "79228162514264337593543950335";
Expand Down
30 changes: 15 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,17 @@
"@uma/common" "^2.17.0"
hardhat "^2.9.3"

"@across-protocol/constants@^3.1.30":
"@across-protocol/constants@^3.1.27", "@across-protocol/constants@^3.1.30":
version "3.1.30"
resolved "https://registry.yarnpkg.com/@across-protocol/constants/-/constants-3.1.30.tgz#b5bb82b5efcf3f63658332eece240ecdb645c0bc"
integrity sha512-1lEhQmYiqcMKg05fnPfSeCk9QTRaHdVykD+Wcr5tcsyPYgOMtXOXvxxvtSOe9FK+ckpRypp4ab2WUN2iitnzpw==

"@across-protocol/contracts@^0.1.4":
version "0.1.4"
resolved "https://registry.yarnpkg.com/@across-protocol/contracts/-/contracts-0.1.4.tgz#64b3d91e639d2bb120ea94ddef3d160967047fa5"
integrity sha512-y9FVRSFdPgEdGWBcf8rUmmzdYhzGdy0752HwpaAFtMJ1pn+HFgNaI0EZc/UudMKIPOkk+/BxPIHYPy7tKad5/A==
dependencies:
"@eth-optimism/contracts" "^0.5.5"
"@openzeppelin/contracts" "4.1.0"
"@uma/core" "^2.18.0"

"@across-protocol/contracts@^3.0.25":
version "3.0.25"
resolved "https://registry.yarnpkg.com/@across-protocol/contracts/-/contracts-3.0.25.tgz#733771bb3d40e111bd14b8be9b4526595ccba0a7"
integrity sha512-OwBxylXAzujUJCGbENyBki0yUryJJAb4v7i69nri+psyJr8MA8LhiiOIVhw+jIUeukBeY8uKF+AI7fzlewwFvA==
"@across-protocol/[email protected]":
version "3.1.0-beta.3"
resolved "https://registry.yarnpkg.com/@across-protocol/contracts/-/contracts-3.1.0-beta.3.tgz#f8d7bd7c6748bd71ac20a8f8f93367b966f1c7d2"
integrity sha512-IRtLn9paX+nYhwzz5P3x/JWycTKbCur7CM7iVqFPcZwW8ZrmugDjKcolH5rzkIOP3OwYKKS67Rh2fHTq9O9q8g==
dependencies:
"@across-protocol/constants" "^3.1.30"
"@across-protocol/constants" "^3.1.27"
"@coral-xyz/anchor" "^0.30.1"
"@defi-wonderland/smock" "^2.3.4"
"@eth-optimism/contracts" "^0.5.40"
Expand All @@ -58,6 +49,15 @@
yargs "^17.7.2"
zksync-web3 "^0.14.3"

"@across-protocol/contracts@^0.1.4":
version "0.1.4"
resolved "https://registry.yarnpkg.com/@across-protocol/contracts/-/contracts-0.1.4.tgz#64b3d91e639d2bb120ea94ddef3d160967047fa5"
integrity sha512-y9FVRSFdPgEdGWBcf8rUmmzdYhzGdy0752HwpaAFtMJ1pn+HFgNaI0EZc/UudMKIPOkk+/BxPIHYPy7tKad5/A==
dependencies:
"@eth-optimism/contracts" "^0.5.5"
"@openzeppelin/contracts" "4.1.0"
"@uma/core" "^2.18.0"

"@adraffy/[email protected]":
version "1.10.0"
resolved "https://registry.yarnpkg.com/@adraffy/ens-normalize/-/ens-normalize-1.10.0.tgz#d2a39395c587e092d77cbbc80acf956a54f38bf7"
Expand Down

0 comments on commit f3e975a

Please sign in to comment.